From a575a17f6c84a975e7a593cc8092e3bd3ec29951 Mon Sep 17 00:00:00 2001 From: Rick Talbott Date: Thu, 21 Sep 2023 11:34:48 -0600 Subject: [PATCH] modules: hal_silabs: add wiseconnect sdk Origin: Silicon Labs WiSeConnect WIFI BT SDK URL: https://github.com/SiliconLabs/wiseconnect-wifi-bt-sdk Version: 2.8.1 Purpose: Adding WiSeConnect support. License: Apache 2.0 Maintained-by: External The WiseConnect SDK is re-licensed by permission from Silicon Laboratories as commented by a representative on GitHub: https://github.com/zephyrproject-rtos/hal_silabs/pull/43#discussion_r1361083717 Signed-off-by: Rick Talbott --- CMakeLists.txt | 1 + wiseconnect/CMakeLists.txt | 80 + wiseconnect/Kconfig | 108 + wiseconnect/README | 12 + wiseconnect/configs/rsi_ble_config.h | 58 + wiseconnect/configs/rsi_board_configuration.h | 10 + wiseconnect/configs/rsi_bt_config.h | 19 + wiseconnect/configs/rsi_wlan_config.h | 111 + .../certificates/azure_client_cert.pem.h | 1 + .../certificates/azure_client_key.pem.h | 1 + wiseconnect/sapi/bluetooth/rsi_ble_gap_apis.c | 2327 +++++ .../sapi/bluetooth/rsi_ble_gatt_apis.c | 1751 ++++ wiseconnect/sapi/bluetooth/rsi_bt_a2dp_apis.c | 402 + .../sapi/bluetooth/rsi_bt_avrcp_apis.c | 1340 +++ .../sapi/bluetooth/rsi_bt_common_apis.c | 673 ++ wiseconnect/sapi/bluetooth/rsi_bt_gap_apis.c | 1372 +++ wiseconnect/sapi/bluetooth/rsi_bt_sbc_codec.c | 717 ++ wiseconnect/sapi/bluetooth/rsi_bt_spp_apis.c | 147 + wiseconnect/sapi/common/rsi_apis_non_rom.c | 166 + wiseconnect/sapi/common/rsi_apis_rom.c | 83 + wiseconnect/sapi/common/rsi_common_apis.c | 2791 ++++++ .../sapi/common/rsi_device_init_apis.c | 367 + wiseconnect/sapi/crypto/rsi_crypto.c | 3135 +++++++ .../sdio/rsi_sdio_frame_rd_wr.c | 126 + .../sdio/rsi_sdio_iface_init.c | 121 + .../sdio/rsi_sdio_mem_rd_wr.c | 146 + .../sdio/rsi_sdio_reg_rd_wr.c | 72 + .../spi/rsi_spi_frame_rd_wr.c | 405 + .../device_interface/spi/rsi_spi_functs.c | 357 + .../device_interface/spi/rsi_spi_iface_init.c | 125 + .../device_interface/spi/rsi_spi_mem_rd_wr.c | 186 + .../device_interface/spi/rsi_spi_reg_rd_wr.c | 178 + .../driver/device_interface/uart/rsi_uart.c | 134 + wiseconnect/sapi/driver/rsi_bt_ble.c | 4570 ++++++++++ wiseconnect/sapi/driver/rsi_common.c | 1827 ++++ wiseconnect/sapi/driver/rsi_device_init.c | 670 ++ wiseconnect/sapi/driver/rsi_driver.c | 88 + .../sapi/driver/rsi_driver_event_handlers.c | 1080 +++ wiseconnect/sapi/driver/rsi_events.c | 324 + wiseconnect/sapi/driver/rsi_events_rom.c | 256 + wiseconnect/sapi/driver/rsi_iap.c | 221 + wiseconnect/sapi/driver/rsi_nwk.c | 649 ++ wiseconnect/sapi/driver/rsi_nwk_rom.c | 29 + wiseconnect/sapi/driver/rsi_os_none.c | 267 + wiseconnect/sapi/driver/rsi_pkt_mgmt.c | 108 + wiseconnect/sapi/driver/rsi_pkt_mgmt_rom.c | 326 + wiseconnect/sapi/driver/rsi_queue.c | 137 + wiseconnect/sapi/driver/rsi_queue_rom.c | 260 + wiseconnect/sapi/driver/rsi_scheduler.c | 187 + wiseconnect/sapi/driver/rsi_scheduler_rom.c | 134 + .../sapi/driver/rsi_setregion_countryinfo.c | 197 + wiseconnect/sapi/driver/rsi_timer.c | 117 + wiseconnect/sapi/driver/rsi_utils.c | 667 ++ wiseconnect/sapi/driver/rsi_utils_rom.c | 140 + wiseconnect/sapi/driver/rsi_wlan.c | 3442 ++++++++ wiseconnect/sapi/include/debug_auto_gen.h | 4213 +++++++++ wiseconnect/sapi/include/rsi_apis_rom.h | 445 + wiseconnect/sapi/include/rsi_ble.h | 1637 ++++ wiseconnect/sapi/include/rsi_ble_apis.h | 2827 ++++++ .../sapi/include/rsi_ble_common_config.h | 478 + wiseconnect/sapi/include/rsi_bootup_config.h | 116 + wiseconnect/sapi/include/rsi_bt.h | 1174 +++ wiseconnect/sapi/include/rsi_bt_apis.h | 3735 ++++++++ wiseconnect/sapi/include/rsi_bt_common.h | 412 + wiseconnect/sapi/include/rsi_bt_common_apis.h | 170 + .../sapi/include/rsi_bt_common_config.h | 206 + wiseconnect/sapi/include/rsi_bt_sbc_codec.h | 48 + wiseconnect/sapi/include/rsi_bt_sdp.h | 141 + wiseconnect/sapi/include/rsi_common.h | 966 ++ wiseconnect/sapi/include/rsi_common_apis.h | 191 + wiseconnect/sapi/include/rsi_crypto.h | 409 + wiseconnect/sapi/include/rsi_data_types.h | 94 + wiseconnect/sapi/include/rsi_driver.h | 283 + wiseconnect/sapi/include/rsi_error.h | 112 + wiseconnect/sapi/include/rsi_events.h | 129 + wiseconnect/sapi/include/rsi_hal.h | 159 + wiseconnect/sapi/include/rsi_hid.h | 113 + wiseconnect/sapi/include/rsi_mac_api.h | 87 + wiseconnect/sapi/include/rsi_mac_interface.h | 1090 +++ wiseconnect/sapi/include/rsi_nwk.h | 1383 +++ wiseconnect/sapi/include/rsi_os.h | 133 + wiseconnect/sapi/include/rsi_pkt_mgmt.h | 89 + wiseconnect/sapi/include/rsi_prop_protocol.h | 47 + wiseconnect/sapi/include/rsi_qspi_defines.h | 298 + wiseconnect/sapi/include/rsi_queue.h | 73 + wiseconnect/sapi/include/rsi_scheduler.h | 64 + wiseconnect/sapi/include/rsi_sdio.h | 76 + .../sapi/include/rsi_setregion_countryinfo.h | 36 + wiseconnect/sapi/include/rsi_socket.h | 694 ++ wiseconnect/sapi/include/rsi_spi_cmd.h | 260 + wiseconnect/sapi/include/rsi_spi_intf.h | 190 + wiseconnect/sapi/include/rsi_timer.h | 58 + wiseconnect/sapi/include/rsi_uart.h | 162 + wiseconnect/sapi/include/rsi_user.h | 135 + wiseconnect/sapi/include/rsi_utils.h | 86 + wiseconnect/sapi/include/rsi_wlan.h | 1829 ++++ wiseconnect/sapi/include/rsi_wlan_apis.h | 1860 ++++ .../sapi/include/rsi_wlan_common_config.h | 1304 +++ wiseconnect/sapi/include/rsi_wlan_defines.h | 30 + wiseconnect/sapi/include/rsi_wlan_non_rom.h | 638 ++ wiseconnect/sapi/include/sl_app_logging.h | 78 + wiseconnect/sapi/include/sl_fw_logging.h | 128 + .../sapi/include/sleep_wakeup_logging.h | 17 + wiseconnect/sapi/logging/sl_app_logging.c | 283 + wiseconnect/sapi/logging/sl_fw_logging.c | 398 + .../sapi/logging/sleep_wakeup_logging.c | 53 + .../protocols/http_server/rsi_http_server.c | 734 ++ .../protocols/http_server/rsi_json_handlers.c | 481 + .../protocols/http_server/rsi_json_handlers.h | 91 + .../mdnsd_records/rsi_mdnsd_records.c | 167 + .../mdnsd_records/rsi_mdnsd_records.h | 42 + .../network/protocols/rsi_dhcp_user_class.c | 125 + .../network/protocols/rsi_dhcp_user_class.h | 52 + wiseconnect/sapi/network/protocols/rsi_dns.c | 407 + .../network/protocols/rsi_emb_mqtt_client.c | 891 ++ .../network/protocols/rsi_emb_mqtt_client.h | 71 + .../protocols/rsi_firmware_upgradation.c | 162 + .../protocols/rsi_firmware_upgradation.h | 60 + wiseconnect/sapi/network/protocols/rsi_ftp.c | 1399 +++ .../sapi/network/protocols/rsi_http_client.c | 1064 +++ .../sapi/network/protocols/rsi_http_client.h | 139 + .../network/protocols/rsi_http_ota_fw_up.c | 286 + .../network/protocols/rsi_http_otaf_app.h | 30 + .../sapi/network/protocols/rsi_mdnsd.c | 447 + .../sapi/network/protocols/rsi_mdnsd.h | 64 + .../sapi/network/protocols/rsi_mqtt_client.c | 387 + .../sapi/network/protocols/rsi_mqtt_client.h | 119 + .../sapi/network/protocols/rsi_multicast.c | 166 + .../sapi/network/protocols/rsi_multicast.h | 52 + .../sapi/network/protocols/rsi_ota_fw_up.c | 131 + .../sapi/network/protocols/rsi_pop3_client.c | 716 ++ .../sapi/network/protocols/rsi_pop3_client.h | 90 + .../sapi/network/protocols/rsi_raw_data.c | 104 + .../sapi/network/protocols/rsi_smtp_client.c | 488 + .../sapi/network/protocols/rsi_smtp_client.h | 89 + .../sapi/network/protocols/rsi_sntp_client.c | 590 ++ .../sapi/network/protocols/rsi_sntp_client.h | 68 + .../sapi/network/protocols/rsi_web_socket.c | 382 + .../sapi/network/protocols/rsi_web_socket.h | 60 + wiseconnect/sapi/network/socket/rsi_socket.c | 4307 +++++++++ .../sapi/network/socket/rsi_socket_rom.c | 183 + wiseconnect/sapi/rtos/freertos_wrapper/port.c | 17 + .../sapi/rtos/freertos_wrapper/portmacro.h | 25 + .../rtos/freertos_wrapper/rsi_os_wrapper.c | 731 ++ wiseconnect/sapi/sapi.mk | 334 + wiseconnect/sapi/wlan/rsi_wlan_apis.c | 7825 +++++++++++++++++ wiseconnect/zephyr/rsi_hal_mcu_interrupt.c | 156 + wiseconnect/zephyr/rsi_hal_mcu_ioports.c | 176 + .../zephyr/rsi_hal_mcu_platform_init.c | 72 + wiseconnect/zephyr/rsi_hal_mcu_random.c | 54 + wiseconnect/zephyr/rsi_hal_mcu_spi.c | 122 + wiseconnect/zephyr/rsi_hal_mcu_timer.c | 185 + wiseconnect/zephyr/rsi_hal_mcu_uart.c | 67 + wiseconnect/zephyr/rsi_os_wrapper.c | 715 ++ zephyr/Kconfig | 2 + 155 files changed, 87980 insertions(+) create mode 100644 wiseconnect/CMakeLists.txt create mode 100644 wiseconnect/Kconfig create mode 100644 wiseconnect/README create mode 100644 wiseconnect/configs/rsi_ble_config.h create mode 100644 wiseconnect/configs/rsi_board_configuration.h create mode 100644 wiseconnect/configs/rsi_bt_config.h create mode 100644 wiseconnect/configs/rsi_wlan_config.h create mode 100644 wiseconnect/resources/certificates/azure_client_cert.pem.h create mode 100644 wiseconnect/resources/certificates/azure_client_key.pem.h create mode 100644 wiseconnect/sapi/bluetooth/rsi_ble_gap_apis.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_ble_gatt_apis.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_bt_a2dp_apis.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_bt_avrcp_apis.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_bt_common_apis.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_bt_gap_apis.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_bt_sbc_codec.c create mode 100644 wiseconnect/sapi/bluetooth/rsi_bt_spp_apis.c create mode 100644 wiseconnect/sapi/common/rsi_apis_non_rom.c create mode 100644 wiseconnect/sapi/common/rsi_apis_rom.c create mode 100644 wiseconnect/sapi/common/rsi_common_apis.c create mode 100644 wiseconnect/sapi/common/rsi_device_init_apis.c create mode 100644 wiseconnect/sapi/crypto/rsi_crypto.c create mode 100644 wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_frame_rd_wr.c create mode 100644 wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_iface_init.c create mode 100644 wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_mem_rd_wr.c create mode 100644 wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_reg_rd_wr.c create mode 100644 wiseconnect/sapi/driver/device_interface/spi/rsi_spi_frame_rd_wr.c create mode 100644 wiseconnect/sapi/driver/device_interface/spi/rsi_spi_functs.c create mode 100644 wiseconnect/sapi/driver/device_interface/spi/rsi_spi_iface_init.c create mode 100644 wiseconnect/sapi/driver/device_interface/spi/rsi_spi_mem_rd_wr.c create mode 100644 wiseconnect/sapi/driver/device_interface/spi/rsi_spi_reg_rd_wr.c create mode 100644 wiseconnect/sapi/driver/device_interface/uart/rsi_uart.c create mode 100644 wiseconnect/sapi/driver/rsi_bt_ble.c create mode 100644 wiseconnect/sapi/driver/rsi_common.c create mode 100644 wiseconnect/sapi/driver/rsi_device_init.c create mode 100644 wiseconnect/sapi/driver/rsi_driver.c create mode 100644 wiseconnect/sapi/driver/rsi_driver_event_handlers.c create mode 100644 wiseconnect/sapi/driver/rsi_events.c create mode 100644 wiseconnect/sapi/driver/rsi_events_rom.c create mode 100644 wiseconnect/sapi/driver/rsi_iap.c create mode 100644 wiseconnect/sapi/driver/rsi_nwk.c create mode 100644 wiseconnect/sapi/driver/rsi_nwk_rom.c create mode 100644 wiseconnect/sapi/driver/rsi_os_none.c create mode 100644 wiseconnect/sapi/driver/rsi_pkt_mgmt.c create mode 100644 wiseconnect/sapi/driver/rsi_pkt_mgmt_rom.c create mode 100644 wiseconnect/sapi/driver/rsi_queue.c create mode 100644 wiseconnect/sapi/driver/rsi_queue_rom.c create mode 100644 wiseconnect/sapi/driver/rsi_scheduler.c create mode 100644 wiseconnect/sapi/driver/rsi_scheduler_rom.c create mode 100644 wiseconnect/sapi/driver/rsi_setregion_countryinfo.c create mode 100644 wiseconnect/sapi/driver/rsi_timer.c create mode 100644 wiseconnect/sapi/driver/rsi_utils.c create mode 100644 wiseconnect/sapi/driver/rsi_utils_rom.c create mode 100644 wiseconnect/sapi/driver/rsi_wlan.c create mode 100644 wiseconnect/sapi/include/debug_auto_gen.h create mode 100644 wiseconnect/sapi/include/rsi_apis_rom.h create mode 100644 wiseconnect/sapi/include/rsi_ble.h create mode 100644 wiseconnect/sapi/include/rsi_ble_apis.h create mode 100644 wiseconnect/sapi/include/rsi_ble_common_config.h create mode 100644 wiseconnect/sapi/include/rsi_bootup_config.h create mode 100644 wiseconnect/sapi/include/rsi_bt.h create mode 100644 wiseconnect/sapi/include/rsi_bt_apis.h create mode 100644 wiseconnect/sapi/include/rsi_bt_common.h create mode 100644 wiseconnect/sapi/include/rsi_bt_common_apis.h create mode 100644 wiseconnect/sapi/include/rsi_bt_common_config.h create mode 100644 wiseconnect/sapi/include/rsi_bt_sbc_codec.h create mode 100644 wiseconnect/sapi/include/rsi_bt_sdp.h create mode 100644 wiseconnect/sapi/include/rsi_common.h create mode 100644 wiseconnect/sapi/include/rsi_common_apis.h create mode 100644 wiseconnect/sapi/include/rsi_crypto.h create mode 100644 wiseconnect/sapi/include/rsi_data_types.h create mode 100644 wiseconnect/sapi/include/rsi_driver.h create mode 100644 wiseconnect/sapi/include/rsi_error.h create mode 100644 wiseconnect/sapi/include/rsi_events.h create mode 100644 wiseconnect/sapi/include/rsi_hal.h create mode 100644 wiseconnect/sapi/include/rsi_hid.h create mode 100644 wiseconnect/sapi/include/rsi_mac_api.h create mode 100644 wiseconnect/sapi/include/rsi_mac_interface.h create mode 100644 wiseconnect/sapi/include/rsi_nwk.h create mode 100644 wiseconnect/sapi/include/rsi_os.h create mode 100644 wiseconnect/sapi/include/rsi_pkt_mgmt.h create mode 100644 wiseconnect/sapi/include/rsi_prop_protocol.h create mode 100644 wiseconnect/sapi/include/rsi_qspi_defines.h create mode 100644 wiseconnect/sapi/include/rsi_queue.h create mode 100644 wiseconnect/sapi/include/rsi_scheduler.h create mode 100644 wiseconnect/sapi/include/rsi_sdio.h create mode 100644 wiseconnect/sapi/include/rsi_setregion_countryinfo.h create mode 100644 wiseconnect/sapi/include/rsi_socket.h create mode 100644 wiseconnect/sapi/include/rsi_spi_cmd.h create mode 100644 wiseconnect/sapi/include/rsi_spi_intf.h create mode 100644 wiseconnect/sapi/include/rsi_timer.h create mode 100644 wiseconnect/sapi/include/rsi_uart.h create mode 100644 wiseconnect/sapi/include/rsi_user.h create mode 100644 wiseconnect/sapi/include/rsi_utils.h create mode 100644 wiseconnect/sapi/include/rsi_wlan.h create mode 100644 wiseconnect/sapi/include/rsi_wlan_apis.h create mode 100644 wiseconnect/sapi/include/rsi_wlan_common_config.h create mode 100644 wiseconnect/sapi/include/rsi_wlan_defines.h create mode 100644 wiseconnect/sapi/include/rsi_wlan_non_rom.h create mode 100644 wiseconnect/sapi/include/sl_app_logging.h create mode 100644 wiseconnect/sapi/include/sl_fw_logging.h create mode 100644 wiseconnect/sapi/include/sleep_wakeup_logging.h create mode 100644 wiseconnect/sapi/logging/sl_app_logging.c create mode 100644 wiseconnect/sapi/logging/sl_fw_logging.c create mode 100644 wiseconnect/sapi/logging/sleep_wakeup_logging.c create mode 100644 wiseconnect/sapi/network/protocols/http_server/rsi_http_server.c create mode 100644 wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.c create mode 100644 wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.h create mode 100644 wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.c create mode 100644 wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_dns.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_ftp.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_http_client.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_http_client.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_http_ota_fw_up.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_http_otaf_app.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_mdnsd.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_mdnsd.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_mqtt_client.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_mqtt_client.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_multicast.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_multicast.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_ota_fw_up.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_pop3_client.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_pop3_client.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_raw_data.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_smtp_client.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_smtp_client.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_sntp_client.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_sntp_client.h create mode 100644 wiseconnect/sapi/network/protocols/rsi_web_socket.c create mode 100644 wiseconnect/sapi/network/protocols/rsi_web_socket.h create mode 100644 wiseconnect/sapi/network/socket/rsi_socket.c create mode 100644 wiseconnect/sapi/network/socket/rsi_socket_rom.c create mode 100644 wiseconnect/sapi/rtos/freertos_wrapper/port.c create mode 100644 wiseconnect/sapi/rtos/freertos_wrapper/portmacro.h create mode 100644 wiseconnect/sapi/rtos/freertos_wrapper/rsi_os_wrapper.c create mode 100644 wiseconnect/sapi/sapi.mk create mode 100644 wiseconnect/sapi/wlan/rsi_wlan_apis.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_interrupt.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_ioports.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_platform_init.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_random.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_spi.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_timer.c create mode 100644 wiseconnect/zephyr/rsi_hal_mcu_uart.c create mode 100644 wiseconnect/zephyr/rsi_os_wrapper.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d331a36e..17fa8088 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory_ifdef(CONFIG_HAS_SILABS_GECKO gecko) add_subdirectory_ifdef(CONFIG_HAS_SILABS_GECKO zephyr) +add_subdirectory_ifdef(CONFIG_WISECONNECT wiseconnect) diff --git a/wiseconnect/CMakeLists.txt b/wiseconnect/CMakeLists.txt new file mode 100644 index 00000000..3e4b744c --- /dev/null +++ b/wiseconnect/CMakeLists.txt @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_WISECONNECT) + zephyr_include_directories( + sapi/include + ) + zephyr_include_directories( + configs + ) + if (CONFIG_WISECONNECT_USE_OS_BINDINGS) + zephyr_compile_definitions(RSI_WITH_OS) + endif() + zephyr_interface_library_named(RS9116_WISECONNECT) + zephyr_library() + zephyr_compile_definitions(RSI_SAMPLE_HAL) + zephyr_compile_definitions(RSI_SPI_INTERFACE) + if (CONFIG_WISECONNECT_WIFI) + zephyr_compile_definitions(RSI_WLAN_ENABLE) + endif() + if (CONFIG_WISECONNECT_BT) + zephyr_compile_definitions(RSI_BT_ENABLE RSI_BLE_ENABLE) + endif() + zephyr_library_sources( + sapi/crypto/rsi_crypto.c + sapi/driver/rsi_iap.c + sapi/driver/rsi_setregion_countryinfo.c + sapi/driver/rsi_driver_event_handlers.c + sapi/driver/rsi_wlan.c + sapi/driver/rsi_nwk_rom.c + sapi/driver/rsi_nwk.c + sapi/driver/rsi_events.c + sapi/driver/rsi_device_init.c + sapi/driver/rsi_utils_rom.c + sapi/driver/rsi_bt_ble.c + sapi/driver/rsi_pkt_mgmt_rom.c + sapi/driver/rsi_os_none.c + sapi/driver/rsi_queue.c + sapi/driver/rsi_scheduler.c + sapi/driver/rsi_common.c + sapi/driver/rsi_events_rom.c + sapi/driver/rsi_pkt_mgmt.c + sapi/driver/rsi_timer.c + sapi/driver/device_interface/sdio/rsi_sdio_reg_rd_wr.c + sapi/driver/device_interface/sdio/rsi_sdio_frame_rd_wr.c + sapi/driver/device_interface/sdio/rsi_sdio_iface_init.c + sapi/driver/device_interface/sdio/rsi_sdio_mem_rd_wr.c + sapi/driver/device_interface/spi/rsi_spi_reg_rd_wr.c + sapi/driver/device_interface/spi/rsi_spi_functs.c + sapi/driver/device_interface/spi/rsi_spi_iface_init.c + sapi/driver/device_interface/spi/rsi_spi_mem_rd_wr.c + sapi/driver/device_interface/spi/rsi_spi_frame_rd_wr.c + sapi/driver/rsi_queue_rom.c + sapi/driver/rsi_driver.c + sapi/driver/rsi_scheduler_rom.c + sapi/driver/rsi_utils.c + sapi/common/rsi_apis_rom.c + sapi/common/rsi_apis_non_rom.c + sapi/common/rsi_device_init_apis.c + sapi/common/rsi_common_apis.c + sapi/bluetooth/rsi_ble_gatt_apis.c + sapi/bluetooth/rsi_bt_common_apis.c + sapi/bluetooth/rsi_bt_a2dp_apis.c + sapi/bluetooth/rsi_bt_avrcp_apis.c + sapi/bluetooth/rsi_bt_gap_apis.c + sapi/bluetooth/rsi_bt_spp_apis.c + sapi/bluetooth/rsi_ble_gap_apis.c + sapi/wlan/rsi_wlan_apis.c + sapi/network/socket/rsi_socket_rom.c + sapi/network/socket/rsi_socket.c + zephyr/rsi_hal_mcu_ioports.c + zephyr/rsi_hal_mcu_platform_init.c + zephyr/rsi_hal_mcu_timer.c + zephyr/rsi_hal_mcu_interrupt.c + zephyr/rsi_hal_mcu_random.c + zephyr/rsi_hal_mcu_uart.c + zephyr/rsi_hal_mcu_spi.c + zephyr/rsi_os_wrapper.c + ) + zephyr_library_sources_ifdef(CONFIG_WISECONNECT_DNS sapi/network/protocols/rsi_dns.c) +endif() diff --git a/wiseconnect/Kconfig b/wiseconnect/Kconfig new file mode 100644 index 00000000..6b6bd44e --- /dev/null +++ b/wiseconnect/Kconfig @@ -0,0 +1,108 @@ +# SPDX-License-Identifier: Apache-2.0 + +config WISECONNECT + bool "Use WiSeConnect API" + default y + depends on DT_HAS_SILABS_RS9116W_ENABLED + select SPI + +if WISECONNECT + +config HEAP_MEM_POOL_SIZE + int + default 1024 + +config WISECONNECT_WIFI + bool "Compile WiFi APIs" + +config WISECONNECT_BT + bool "Compile bluetooth APIs" + +config WISECONNECT_USE_OS_BINDINGS + bool "Enable OS Bindings" + default y + +endif # WISECONNECT + +if WISECONNECT_WIFI + +config WISECONNECT_SOCKETS_COUNT + int "Number of simultaneous sockets allowed" + range 1 10 + default 10 + +config WISECONNECT_IPV6 + bool "Enable IPV6 features in WiSeConnect" + default y + +config WISECONNECT_TLS + bool "Enable TLS features on the WiSeConnect" + default y + +config WISECONNECT_ICMP + bool "Enable WiSeConnect ICMP/Ping feature" + default n + +config WISECONNECT_DHCP + bool "Enable WiSeConnect DHCP client" + default y + +config WISECONNECT_DNS + bool "Enable WiSeConnect DNS client" + default y + +config WISECONNECT_SOCKETS_LARGE_TRANSACTIONS + bool "Enable large socket send/recv." + default n + +config WISECONNECT_IP_BYPASS_MODE + bool "Enable IP bypass mode (l2 access)" + default n + imply WISECONNECT_IP_DUAL_MODE + +config WISECONNECT_IP_DUAL_MODE + bool "Enable IP bypass alongside non-bypass mode" + depends on WISECONNECT_IP_BYPASS_MODE + +config WISECONNECT_BGSCAN + bool "Enable background scan/scans whilst connected" + default y + +endif # WISECONNECT_WIFI + +if WISECONNECT_BT + +config WISECONNECT_DISABLE_DEFAULT_GAP_GATT + bool "Disable default GAP & GATT services." + default n + +config WISECONNECT_DISABLE_DEFAULT_SCAN_RESPONSE + bool "Device will maintain some default scan reponse data and will be used in the scan_response controller frame. By enabling this we can make the default data as Null(empty)." + default n + +config WISECONNECT_BLE_MAX_CENTRALS + int "Maximum number of BLE masters/centrals." + range 1 2 + default 1 + +config WISECONNECT_BLE_MAX_PERIPHERALS + int "Maximum number of BLE slaves/peripherals." + range 1 8 + default 1 + +config WISECONNECT_BLE_MAX_SERVS + int "Maximum number of BLE GATT services." + range 2 10 + default 10 + +config WISECONNECT_BLE_MAX_CHARS + int "Maximum number of BLE GATT characteristics." + range 10 80 + default 80 + +config WISECONNECT_BLE_MTU + int "Maximum Transfer Unit for BLE." + range 20 232 + default 232 + +endif # BT_RS9116W \ No newline at end of file diff --git a/wiseconnect/README b/wiseconnect/README new file mode 100644 index 00000000..04acf6e3 --- /dev/null +++ b/wiseconnect/README @@ -0,0 +1,12 @@ +This directory contains firmware supporting wiseconnect 2.8.0 provided by SiLabs to T-Mobile under the Apache 2.0 licence. + +* Available firmware images: +https://github.com/SiliconLabs/wiseconnect-wifi-bt-sdk/blob/2.8.0/firmware/RS9116W.2.8.0.0.45.rps +https://github.com/SiliconLabs/wiseconnect-wifi-bt-sdk/blob/2.8.0/firmware/RS916W.2.8.0.0.45.rps + +Please choose the right firmware file (in the package) as per the below guidelines. + 1. Customers using OPN RS9116X-xxx-xxx-Xxx parts (Silicon rev 1.3) or customers using OPN RS9116X-xxx-xxx-Bxx(Silicon rev 1.4) + should use RS9116W.x.x.x.x.x.rps + 2. Customers using the RS9116X-xxx-xxx-Cxx parts(Silicon rev 1.5) should use RS916W.x.x.x.x.x.rps. + Silicon rev 1.5 has some enhancements primarily for BT classic audio A2DP etc + diff --git a/wiseconnect/configs/rsi_ble_config.h b/wiseconnect/configs/rsi_ble_config.h new file mode 100644 index 00000000..8996f0a3 --- /dev/null +++ b/wiseconnect/configs/rsi_ble_config.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#ifndef RSI_BLE_CONFIG_H +#define RSI_BLE_CONFIG_H + +#include +#include + + +#ifdef CONFIG_WISECONNECT_DISABLE_DEFAULT_SCAN_RESPONSE +#undef RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST +#if CONFIG_WISECONNECT_DISABLE_DEFAULT_SCAN_RESPONSE +#define RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST 1 +#else +#define RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST 0 +#endif +#endif + +#ifdef CONFIG_WISECONNECT_DISABLE_DEFAULT_GAP_GATT +#undef BLE_SIMPLE_GATT +#if CONFIG_WISECONNECT_DISABLE_DEFAULT_GAP_GATT +#define BLE_SIMPLE_GATT 1 +#else +#define BLE_SIMPLE_GATT 0 +#endif +#endif + +#ifdef CONFIG_WISECONNECT_BLE_MAX_CENTRALS +#undef RSI_BLE_MAX_NBR_MASTERS +#define RSI_BLE_MAX_NBR_MASTERS CONFIG_WISECONNECT_BLE_MAX_CENTRALS +#endif + +#ifdef CONFIG_WISECONNECT_BLE_MAX_PERIPHERALS +#undef RSI_BLE_MAX_NBR_SLAVES +#define RSI_BLE_MAX_NBR_SLAVES CONFIG_WISECONNECT_BLE_MAX_PERIPHERALS +#endif + +#ifdef CONFIG_WISECONNECT_BLE_MAX_SERVS +#undef RSI_BLE_MAX_NBR_ATT_SERV +#define RSI_BLE_MAX_NBR_ATT_SERV CONFIG_WISECONNECT_BLE_MAX_SERVS +#endif + +#ifdef CONFIG_WISECONNECT_BLE_MAX_CHARS +#undef RSI_BLE_MAX_NBR_ATT_REC +#define RSI_BLE_MAX_NBR_ATT_REC CONFIG_WISECONNECT_BLE_MAX_CHARS +#endif + +#ifdef CONFIG_WISECONNECT_BLE_MTU +#undef RSI_BLE_MTU_SIZE +#define RSI_BLE_MTU_SIZE CONFIG_WISECONNECT_BLE_MTU +#endif + +#endif diff --git a/wiseconnect/configs/rsi_board_configuration.h b/wiseconnect/configs/rsi_board_configuration.h new file mode 100644 index 00000000..8a1b7549 --- /dev/null +++ b/wiseconnect/configs/rsi_board_configuration.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* This eliminates the sscanf warning */ +#if !CONFIG_NEWLIB_LIBC +int sscanf(const char *str, const char *format, ...); +#endif diff --git a/wiseconnect/configs/rsi_bt_config.h b/wiseconnect/configs/rsi_bt_config.h new file mode 100644 index 00000000..9711299a --- /dev/null +++ b/wiseconnect/configs/rsi_bt_config.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#ifndef RSI_BT_CONFIG_H +#define RSI_BT_CONFIG_H + + +#include +#include +#include + +#undef RSI_BT_FEATURE_BITMAP +#define RSI_BT_FEATURE_BITMAP (BT_RF_TYPE | ENABLE_BLE_PROTOCOL) +#endif + diff --git a/wiseconnect/configs/rsi_wlan_config.h b/wiseconnect/configs/rsi_wlan_config.h new file mode 100644 index 00000000..1368faf1 --- /dev/null +++ b/wiseconnect/configs/rsi_wlan_config.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +#ifndef RSI_WLAN_CONFIG_H +#define RSI_WLAN_CONFIG_H + +#include "rsi_wlan_apis.h" +#define is_power_of_two is_power_of_two_z /* Workaround for conflicting "is_power_of_two" types */ +#include +#undef is_power_of_two + + +#if DT_NODE_HAS_PROP(DT_INST(0, silabs_rs9116w), sleep_wake_confirmation_gpios) && DT_NODE_HAS_PROP(DT_INST(0, silabs_rs9116w), sleep_wake_indication_gpios) +#define RSI_HAND_SHAKE_TYPE GPIO_BASED +#define RSI_FEATURE_BIT_MAP FEAT_ULP_GPIO_BASED_HANDSHAKE +#endif + +#if CONFIG_WISECONNECT_WIFI + +#if CONFIG_WISECONNECT_IP_BYPASS_MODE +#define RSI_IPBM_BYPASS_CONFIG TCP_IP_FEAT_BYPASS +#else +#define RSI_IPBM_BYPASS_CONFIG 0 +#endif + +#if CONFIG_WISECONNECT_IP_DUAL_MODE +#define RSI_EIPBM_DM EXT_TCP_IP_DUAL_MODE_ENABLE +#else +#define RSI_EIPBM_DM 0 +#endif + +#if CONFIG_WISECONNECT_SOCKETS_COUNT +#define RSI_IPBM_SOCKET_CONFIG (CONFIG_WISECONNECT_SOCKETS_COUNT << 21) +#else +#define RSI_IPBM_SOCKET_CONFIG 0 +#endif /** CONFIG_WISECONNECT_SOCKETS_COUNT */ + +#if CONFIG_WISECONNECT_TLS +#define RSI_IPBM_TLS_CONFIG (TCP_IP_FEAT_SSL | TCP_IP_FEAT_LOAD_CERTS_INTO_RAM | TCP_IP_FEAT_LOAD_PUBLIC_PRIVATE_CERTS) +#define RSI_ECFBM_TLS_CONFIG (EXT_FEAT_SSL_CERT_WITH_4096_KEY_SUPPORT | EXT_FEAT_SSL_VERSIONS_SUPPORT) +#define RSI_EIPBM_TLS EXT_TCP_IP_SSL_16K_RECORD +// #if CONFIG_WISECONNECT_THREE_TLS_SOCKETS +// #define RSI_EIPBM_TLS3 EXT_TCP_IP_FEAT_SSL_THREE_SOCKETS +// #else +// #define RSI_EIPBM_TLS3 0 +// #endif /** CONFIG_WISECONNECT_THREE_TLS_SOCKETS */ +#else +#define RSI_IPBM_TLS_CONFIG 0 +#define RSI_ECFBM_TLS_CONFIG 0 +#define RSI_EIPBM_TLS 0 +#endif /** CONFIG_WISECONNECT_TLS */ + +#if CONFIG_WISECONNECT_ICMP +#define RSI_IPBM_ICMP_CONFIG TCP_IP_FEAT_ICMP +#else +#define RSI_IPBM_ICMP_CONFIG 0 +#endif /** CONFIG_WISECONNECT_ICMP */ + +#if CONFIG_WISECONNECT_IPV6 +#define RSI_IPBM_IPV6_CONFIG TCP_IP_FEAT_IPV6 +#else +#define RSI_IPBM_IPV6_CONFIG 0 +#endif /** CONFIG_WISECONNECT_IPV6 */ + +#if CONFIG_WISECONNECT_DHCP +#if CONFIG_WISECONNECT_IPV6 +#define RSI_IPBM_DHCP_CONFIG (TCP_IP_FEAT_DHCPV4_CLIENT | TCP_IP_FEAT_DHCPV6_CLIENT) +#else +#define RSI_IPBM_DHCP_CONFIG TCP_IP_FEAT_DHCPV4_CLIENT +#endif +#else +#define RSI_IPBM_DHCP_CONFIG 0 +#endif /** CONFIG_WISECONNECT_DHCP */ + +#if CONFIG_WISECONNECT_DNS +#define RSI_IPBM_DNS_CONFIG TCP_IP_FEAT_DNS_CLIENT +#else +#define RSI_IPBM_DNS_CONFIG 0 +#endif + +#if CONFIG_WISECONNECT_SOCKETS_LARGE_TRANSACTIONS +#define RSI_PROCESS_MAX_RX_DATA +#endif + +#define RSI_TCP_IP_FEATURE_BIT_MAP (RSI_IPBM_SOCKET_CONFIG | \ + RSI_IPBM_TLS_CONFIG | RSI_IPBM_ICMP_CONFIG | RSI_IPBM_IPV6_CONFIG | \ + RSI_IPBM_DHCP_CONFIG | RSI_IPBM_BYPASS_CONFIG | RSI_IPBM_DNS_CONFIG | \ + TCP_IP_FEAT_EXTENSION_VALID) + +#define RSI_EXT_TCPIP_FEATURE_BITMAP ((RSI_IPBM_SOCKET_CONFIG >> (21 - 12)) | RSI_EIPBM_DM | \ + EXT_TCP_IP_WAIT_FOR_SOCKET_CLOSE | RSI_EIPBM_TLS) + +#define TCP_RX_WINDOW_SIZE_CAP 20 + +#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP RSI_ECFBM_TLS_CONFIG + +#ifdef CONFIG_WISECONNECT_BGSCAN +#define RSI_BG_SCAN_SUPPORT RSI_ENABLE +#define RSI_INSTANT_BG RSI_ENABLE +#define RSI_MULTIPROBE RSI_ENABLE +#endif + +#endif /** CONFIG_WISECONNECT_WIFI */ + +#include "rsi_wlan_defines.h" +#include "rsi_wlan_common_config.h" +#endif diff --git a/wiseconnect/resources/certificates/azure_client_cert.pem.h b/wiseconnect/resources/certificates/azure_client_cert.pem.h new file mode 100644 index 00000000..e9f67d8a --- /dev/null +++ b/wiseconnect/resources/certificates/azure_client_cert.pem.h @@ -0,0 +1 @@ +unsigned char azure_client_cert[] = {'-','-','-','-','-','B','E','G','I','N',' ','C','E','R','T','I','F','I','C','A','T','E','-','-','-','-','-','\n','M','I','I','E','G','T','C','C','A','w','G','g','A','w','I','B','A','g','I','J','A','L','0','3','B','T','x','v','U','O','T','K','M','A','0','G','C','S','q','G','S','I','b','3','D','Q','E','B','C','w','U','A','M','I','G','i','M','Q','s','w','C','Q','Y','D','\n','V','Q','Q','G','E','w','J','J','T','j','E','T','M','B','E','G','A','1','U','E','C','A','w','K','V','E','V','M','Q','U','5','H','Q','U','5','H','Q','T','E','S','M','B','A','G','A','1','U','E','B','w','w','J','S','F','l','E','R','V','J','B','Q','k','F','E','\n','M','R','U','w','E','w','Y','D','V','Q','Q','K','D','A','x','T','S','U','x','J','Q','0','9','O','I','E','x','B','Q','l','M','x','G','T','A','X','B','g','N','V','B','A','s','M','E','E','F','Q','U','F','M','g','R','U','5','H','S','U','5','F','R','V','J','J','\n','T','k','c','x','D','j','A','M','B','g','N','V','B','A','M','M','B','U','R','J','V','l','l','B','M','S','g','w','J','g','Y','J','K','o','Z','I','h','v','c','N','A','Q','k','B','F','h','l','E','S','V','Z','Z','Q','S','5','D','S','E','l','M','V','U','t','P','\n','V','E','l','A','R','0','1','B','S','U','w','u','Q','0','9','N','M','B','4','X','D','T','I','z','M','D','M','w','M','T','E','x','N','T','k','x','N','V','o','X','D','T','I','0','M','D','I','y','O','T','E','x','N','T','k','x','N','V','o','w','g','a','I','x','\n','C','z','A','J','B','g','N','V','B','A','Y','T','A','k','l','O','M','R','M','w','E','Q','Y','D','V','Q','Q','I','D','A','p','U','R','U','x','B','T','k','d','B','T','k','d','B','M','R','I','w','E','A','Y','D','V','Q','Q','H','D','A','l','I','W','U','R','F','\n','U','k','F','C','Q','U','Q','x','F','T','A','T','B','g','N','V','B','A','o','M','D','F','N','J','T','E','l','D','T','0','4','g','T','E','F','C','U','z','E','Z','M','B','c','G','A','1','U','E','C','w','w','Q','Q','V','B','Q','U','y','B','F','T','k','d','J','\n','T','k','V','F','U','k','l','O','R','z','E','O','M','A','w','G','A','1','U','E','A','w','w','F','R','E','l','W','W','U','E','x','K','D','A','m','B','g','k','q','h','k','i','G','9','w','0','B','C','Q','E','W','G','U','R','J','V','l','l','B','L','k','N','I','\n','S','U','x','V','S','0','9','U','S','U','B','H','T','U','F','J','T','C','5','D','T','0','0','w','g','g','E','i','M','A','0','G','C','S','q','G','S','I','b','3','D','Q','E','B','A','Q','U','A','A','4','I','B','D','w','A','w','g','g','E','K','A','o','I','B','\n','A','Q','D','z','6','z','s','9','5','I','T','/','x','5','y','m','C','h','r','z','1','6','N','e','Z','s','X','E','k','r','h','p','S','+','9','R','f','x','D','m','U','7','5','P','j','L','6','D','O','x','i','E','P','E','L','+','a','l','a','u','V','f','q','k','\n','z','1','W','D','w','F','h','D','S','C','6','1','m','Y','R','P','z','W','5','f','5','R','6','o','F','o','4','+','R','j','a','k','G','9','s','Z','2','1','K','Z','v','h','z','V','v','p','u','I','E','h','f','H','C','m','9','R','p','S','/','q','R','U','j','R','\n','T','W','e','4','A','X','P','m','4','O','w','w','T','J','j','U','9','w','C','v','E','N','I','F','P','C','3','t','H','g','M','B','u','n','Z','K','x','O','D','S','Z','E','J','H','W','W','X','z','C','X','o','6','A','e','z','H','p','O','K','1','q','m','X','G','\n','6','S','D','i','Q','D','A','W','E','A','2','1','7','i','N','8','m','k','X','m','j','V','4','x','m','o','e','E','e','B','G','I','6','3','H','h','H','t','l','5','m','w','7','C','4','w','V','l','/','8','i','4','B','j','6','S','Y','a','x','J','O','j','3','o','\n','H','v','M','4','k','O','s','d','T','3','B','5','Z','b','m','C','a','F','I','e','R','7','P','p','B','w','Z','U','P','w','A','j','V','r','C','a','U','b','F','X','S','L','F','X','H','O','h','H','3','F','j','O','n','p','y','J','c','l','/','Q','x','9','F','L','\n','Y','A','M','T','S','n','0','F','Q','j','y','A','+','G','A','8','z','T','5','m','R','Z','h','L','A','g','M','B','A','A','G','j','U','D','B','O','M','B','0','G','A','1','U','d','D','g','Q','W','B','B','T','5','B','0','x','I','6','P','Z','D','m','N','V','h','\n','I','g','f','p','1','v','F','p','h','9','H','x','R','z','A','f','B','g','N','V','H','S','M','E','G','D','A','W','g','B','T','5','B','0','x','I','6','P','Z','D','m','N','V','h','I','g','f','p','1','v','F','p','h','9','H','x','R','z','A','M','B','g','N','V','\n','H','R','M','E','B','T','A','D','A','Q','H','/','M','A','0','G','C','S','q','G','S','I','b','3','D','Q','E','B','C','w','U','A','A','4','I','B','A','Q','B','W','C','2','b','j','W','Z','P','N','k','M','4','H','l','V','6','n','D','K','A','R','8','f','0','B','\n','A','6','7','5','q','K','7','r','V','w','y','6','W','n','W','G','L','T','s','G','Q','l','2','K','w','K','p','2','M','1','4','1','N','l','D','v','x','J','+','u','n','k','r','w','W','I','Y','U','o','U','q','0','k','E','8','8','n','m','I','L','L','A','Q','X','\n','+','7','L','x','T','L','u','k','7','6','b','P','H','8','2','w','k','H','v','U','w','V','q','O','d','3','8','0','m','M','1','h','G','b','Y','W','Q','t','D','U','J','R','X','N','x','x','+','q','I','X','T','7','f','r','k','k','E','2','Y','b','u','H','b','D','\n','y','o','p','p','e','X','d','B','O','x','E','Q','k','B','U','b','M','8','M','u','p','E','i','V','Z','T','f','V','7','O','5','K','A','9','2','n','f','Q','8','U','b','w','4','Y','q','v','X','v','A','m','Z','b','5','/','2','K','k','P','P','D','W','b','t','R','\n','t','/','9','2','1','x','P','S','m','c','C','A','A','W','t','y','y','D','V','F','j','4','H','/','7','8','9','j','y','g','r','V','I','l','s','r','I','1','n','g','B','8','K','m','W','Z','O','6','C','3','v','V','x','g','+','v','1','J','X','s','0','d','Z','9','\n','h','r','j','q','n','S','U','j','c','c','F','U','C','3','L','w','H','J','B','v','W','d','Q','D','u','E','P','0','C','5','t','q','Z','0','M','Y','O','Q','K','7','t','e','Z','q','w','t','/','d','z','7','M','L','C','X','V','A','G','p','U','o','\n','-','-','-','-','-','E','N','D',' ','C','E','R','T','I','F','I','C','A','T','E','-','-','-','-','-','\n', 0}; \ No newline at end of file diff --git a/wiseconnect/resources/certificates/azure_client_key.pem.h b/wiseconnect/resources/certificates/azure_client_key.pem.h new file mode 100644 index 00000000..990561b6 --- /dev/null +++ b/wiseconnect/resources/certificates/azure_client_key.pem.h @@ -0,0 +1 @@ +unsigned char azure_client_key[] = {'-','-','-','-','-','B','E','G','I','N',' ','P','R','I','V','A','T','E',' ','K','E','Y','-','-','-','-','-','\n','M','I','I','E','v','w','I','B','A','D','A','N','B','g','k','q','h','k','i','G','9','w','0','B','A','Q','E','F','A','A','S','C','B','K','k','w','g','g','S','l','A','g','E','A','A','o','I','B','A','Q','D','z','6','z','s','9','5','I','T','/','x','5','y','m','\n','C','h','r','z','1','6','N','e','Z','s','X','E','k','r','h','p','S','+','9','R','f','x','D','m','U','7','5','P','j','L','6','D','O','x','i','E','P','E','L','+','a','l','a','u','V','f','q','k','z','1','W','D','w','F','h','D','S','C','6','1','m','Y','R','P','\n','z','W','5','f','5','R','6','o','F','o','4','+','R','j','a','k','G','9','s','Z','2','1','K','Z','v','h','z','V','v','p','u','I','E','h','f','H','C','m','9','R','p','S','/','q','R','U','j','R','T','W','e','4','A','X','P','m','4','O','w','w','T','J','j','U','\n','9','w','C','v','E','N','I','F','P','C','3','t','H','g','M','B','u','n','Z','K','x','O','D','S','Z','E','J','H','W','W','X','z','C','X','o','6','A','e','z','H','p','O','K','1','q','m','X','G','6','S','D','i','Q','D','A','W','E','A','2','1','7','i','N','8','\n','m','k','X','m','j','V','4','x','m','o','e','E','e','B','G','I','6','3','H','h','H','t','l','5','m','w','7','C','4','w','V','l','/','8','i','4','B','j','6','S','Y','a','x','J','O','j','3','o','H','v','M','4','k','O','s','d','T','3','B','5','Z','b','m','C','\n','a','F','I','e','R','7','P','p','B','w','Z','U','P','w','A','j','V','r','C','a','U','b','F','X','S','L','F','X','H','O','h','H','3','F','j','O','n','p','y','J','c','l','/','Q','x','9','F','L','Y','A','M','T','S','n','0','F','Q','j','y','A','+','G','A','8','\n','z','T','5','m','R','Z','h','L','A','g','M','B','A','A','E','C','g','g','E','B','A','M','n','a','w','j','T','v','F','y','2','B','K','F','6','0','A','C','g','J','L','R','Z','j','Y','I','j','T','j','q','7','8','+','z','j','r','O','b','Y','S','W','W','0','F','\n','o','W','e','C','k','U','B','l','i','l','9','2','6','v','L','t','D','j','Y','z','q','q','Y','U','m','D','Z','d','1','u','H','M','A','J','X','2','A','M','B','1','I','N','C','j','k','e','V','x','P','6','j','B','s','K','k','O','O','q','Y','m','k','U','B','F','\n','s','/','q','A','V','p','M','O','T','J','8','5','X','5','S','0','7','5','T','e','R','N','Y','e','x','a','a','s','P','m','m','e','C','e','A','7','5','K','H','7','/','o','H','8','k','l','k','n','O','/','/','D','K','j','+','n','/','B','H','A','j','K','T','z','\n','d','e','7','9','f','y','d','k','z','C','m','B','/','e','S','b','w','p','4','4','p','B','O','v','Q','Q','j','0','H','0','D','S','1','v','4','w','R','6','h','D','Z','J','8','B','c','Z','0','B','j','4','g','t','Z','M','c','q','K','0','h','N','S','x','F','/','\n','M','Y','j','T','Q','V','z','B','z','j','l','O','t','0','m','2','6','u','h','C','R','g','Y','b','5','6','B','b','s','F','E','G','i','/','t','y','c','N','q','Q','2','y','R','u','7','l','l','5','j','/','Q','y','9','Q','C','w','H','M','I','1','0','O','b','f','\n','f','1','N','J','A','6','m','x','X','0','S','t','C','W','y','2','x','8','b','x','y','H','1','5','5','2','r','C','6','g','l','D','E','O','V','z','A','h','n','+','d','R','E','C','g','Y','E','A','/','N','7','5','Q','8','h','v','2','I','N','A','A','y','o','i','\n','S','W','X','u','T','v','m','y','h','A','7','7','G','H','q','0','w','1','P','y','3','t','9','/','c','w','m','u','7','y','J','g','M','X','p','a','3','m','4','M','K','A','n','D','3','U','F','W','L','o','v','n','a','Q','D','l','U','D','3','+','C','8','G','S','\n','d','X','v','t','b','Y','H','r','A','t','b','4','a','d','+','j','Y','8','G','Y','I','r','T','7','F','K','V','F','9','m','S','u','G','C','q','R','c','C','f','p','5','4','e','j','3','l','2','O','F','w','0','u','e','X','2','w','W','N','d','5','R','P','r','l','\n','4','n','v','y','/','5','a','d','V','m','R','e','C','I','/','w','H','4','+','n','t','F','l','J','w','g','M','C','g','Y','E','A','9','u','/','m','X','N','o','3','u','P','V','M','A','8','d','4','b','L','A','5','2','O','0','B','+','W','t','I','E','T','j','t','\n','/','r','I','s','9','h','I','U','n','M','Q','F','j','a','z','2','2','G','9','c','u','s','G','2','N','7','N','i','S','V','W','p','F','u','o','V','Y','W','G','r','K','+','n','e','Z','F','T','H','t','k','0','L','Q','4','Z','o','c','T','A','H','4','j','z','Q','\n','d','5','t','B','3','9','8','I','K','W','e','W','7','R','I','M','K','a','U','f','0','T','e','S','g','3','I','R','Y','i','n','e','A','w','m','s','J','4','g','m','9','E','c','S','w','j','X','P','a','J','G','w','D','X','R','x','R','p','J','X','m','n','C','Y','\n','W','t','e','7','k','9','+','Z','4','h','k','C','g','Y','E','A','p','0','K','B','V','A','F','/','Y','Z','I','n','R','D','C','Z','b','z','0','5','7','Q','k','i','u','F','E','E','a','4','O','2','j','0','C','2','9','A','6','X','S','a','t','N','B','6','Y','Q','\n','R','I','n','v','E','x','N','t','f','Q','p','A','g','N','g','X','v','k','A','R','+','B','V','8','m','J','/','4','q','y','Q','F','0','S','o','A','u','R','9','n','K','I','C','y','3','a','z','s','c','S','5','7','h','/','F','3','5','o','c','P','i','N','O','9','\n','i','A','S','Y','I','L','x','1','7','g','x','9','K','r','d','t','J','f','g','1','F','m','0','5','u','P','o','F','n','8','f','p','S','O','6','9','o','6','u','n','N','J','6','8','y','C','M','V','L','H','s','j','7','Z','n','l','v','K','s','C','g','Y','A','z','\n','k','k','C','j','D','b','P','r','f','d','d','F','R','s','h','g','s','q','E','y','K','7','V','o','2','L','3','x','U','t','l','p','g','t','6','e','+','Y','G','y','h','8','G','9','J','+','1','Z','o','F','B','W','d','J','R','Q','p','7','c','U','J','7','6','r','\n','m','X','G','j','p','9','k','u','z','6','X','x','g','D','9','B','V','G','/','Q','x','2','Z','S','l','T','x','g','R','G','E','p','S','Z','S','F','Y','7','f','5','p','b','f','A','h','S','9','j','F','y','h','A','8','o','E','3','0','H','/','O','5','3','2','F','\n','V','u','T','M','U','M','Q','J','6','j','o','B','s','2','l','A','p','o','S','F','G','t','d','5','b','K','C','9','E','V','z','Q','R','B','P','Z','u','y','4','R','K','Q','K','B','g','Q','D','7','k','i','n','d','4','j','N','C','9','d','W','C','d','m','J','q','\n','9','g','U','U','3','f','2','a','8','P','q','r','k','3','D','P','h','t','m','N','5','Z','j','p','Y','K','/','6','C','g','g','D','H','5','G','i','j','M','M','u','n','J','d','e','m','5','Q','M','Y','V','N','z','7','5','5','Q','+','k','X','u','C','o','r','V','\n','u','P','5','W','v','C','r','z','i','x','8','i','8','r','g','C','h','I','c','V','B','a','E','U','P','x','8','G','Q','I','o','G','d','G','M','c','X','+','l','9','+','g','H','3','U','9','O','3','s','9','K','X','V','B','j','w','O','n','Y','1','d','n','6','g','\n','Y','M','a','P','1','D','m','W','S','J','b','m','r','2','R','6','F','r','I','z','L','u','+','W','1','A','=','=','\n','-','-','-','-','-','E','N','D',' ','P','R','I','V','A','T','E',' ','K','E','Y','-','-','-','-','-','\n', 0}; \ No newline at end of file diff --git a/wiseconnect/sapi/bluetooth/rsi_ble_gap_apis.c b/wiseconnect/sapi/bluetooth/rsi_ble_gap_apis.c new file mode 100644 index 00000000..10b4d8da --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_ble_gap_apis.c @@ -0,0 +1,2327 @@ +/******************************************************************************* +* @file rsi_ble_gap_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +#ifdef RSI_BLE_ENABLE + +#include "rsi_ble.h" +#include "rsi_ble_config.h" +#include "rsi_utils.h" + +/** + * Structure for Power index and corresponding output power in db + * The values are in dBm at Antenna + * index 0 corresponds to -8 dBm , array size is 24 + */ +uint8_t pwr_index_to_db_array[] = { 11, 13, 17, 23, 31, 44, 45, 47, 49, 52, 55, 59, + 63, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78 }; + +/** + * Structure for Power index and corresponding output power in db for WMS module + * The values are in dBm at Antenna + * index 0 corresponds to -8 dBm , array size is 24 + */ +uint8_t wms_pwr_index_to_db_array[] = { 8, 10, 13, 18, 29, 39, 40, 41, 42, 44, 45, 48, + 50, 54, 61, 70, 71, 72, 73, 74, 75, 76, 77, 78 }; + +/** + * @fn uint8_t rsi_convert_db_to_powindex(int8_t tx_power_in_dBm) + * @brief Convert power from dBm to power index. + * @param[in] tx_power_in_dBm - tx power in dBm( -8 dBm to 15 dBm) + * @return power index to controller + * + */ +uint8_t rsi_convert_db_to_powindex(int8_t tx_power_in_dBm) +{ + module_type mod_type_temp; + int16_t status; + SL_PRINTF(SL_RSI_CONVERT_DB_TO_POWERINDEX_TRIGGER, BLE, LOG_INFO); + status = rsi_get_module_type(&mod_type_temp); + if (status == RSI_SUCCESS) { + tx_power_in_dBm += BLE_OUTPUT_POWER_FRONT_END_LOSS; + if ((tx_power_in_dBm < RSI_MIN_OUTPUT_POWER_IN_DBM) || (tx_power_in_dBm > RSI_MAX_OUTPUT_POWER_IN_DBM)) { + return 0; + } + /* Converting At antenna dBm to On screen dBm */ + tx_power_in_dBm -= RSI_MIN_OUTPUT_POWER_IN_DBM; + switch (mod_type_temp) { + case RSI_MODULE_TYPE_WMS: { + return (wms_pwr_index_to_db_array[tx_power_in_dBm]); + //no break + } + case RSI_MODULE_TYPE_Q7: + case RSI_MODULE_TYPE_SB: + case RSI_MODULE_TYPE_M7DB: + case RSI_MODULE_TYPE_M4SB: + default: { + return (pwr_index_to_db_array[tx_power_in_dBm]); + //no break + } + } + } + return 0; +} + +/** @addtogroup BT-LOW-ENERGY1 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_random_address(void) + * @brief Request the local device to set a random address. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_set_random_address(void) +{ + + SL_PRINTF(SL_RSI_SET_RANDOM_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_rand_t ble_rand = { { 0 } }; + + // Send set random address command + return rsi_bt_driver_send_cmd(RSI_BLE_SET_RANDOM_ADDRESS, &ble_rand, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_random_address_with_value(uint8_t *random_addr) + * @brief Request the local device to set a given random address. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] random_addr - random address of the device to be set + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_set_random_address_with_value(uint8_t *random_addr) +{ + + SL_PRINTF(SL_RSI_SET_RANDOM_ADDRESS_WITH_VALUE_TRIGGER, BLE, LOG_INFO, "VALUE_ADDRESS: %1x", *random_addr); + rsi_ble_req_rand_t ble_rand = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_rand.rand_addr, random_addr); +#else + memcpy((int8_t *)&(ble_rand.rand_addr), (int8_t *)random_addr, 6); +#endif + + // Send set random address command + return rsi_bt_driver_send_cmd(RSI_BLE_SET_RANDOM_ADDRESS, &ble_rand, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_start_advertising(void) + * @brief Request the local device to start advertising. This is a Blocking API \n + * A received event \ref rsi_ble_on_enhance_connect_t/ \ref rsi_ble_on_connect_t indicates remote device given ble connect command and got connected + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_start_advertising(void) +{ + + SL_PRINTF(SL_RSI_BLE_START_ADV_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_adv_t ble_adv = { 0 }; + + ble_adv.status = RSI_BLE_START_ADV; + + ble_adv.adv_type = RSI_BLE_ADV_TYPE; + ble_adv.filter_type = RSI_BLE_ADV_FILTER_TYPE; + ble_adv.direct_addr_type = RSI_BLE_ADV_DIR_ADDR_TYPE; + rsi_ascii_dev_address_to_6bytes_rev(ble_adv.direct_addr, (int8_t *)RSI_BLE_ADV_DIR_ADDR); + if (ble_adv.adv_int_min == 0) { + ble_adv.adv_int_min = RSI_BLE_ADV_INT_MIN; + } + if (ble_adv.adv_int_max == 0) { + ble_adv.adv_int_max = RSI_BLE_ADV_INT_MAX; + } + ble_adv.own_addr_type = LE_PUBLIC_ADDRESS; + ble_adv.adv_channel_map = RSI_BLE_ADV_CHANNEL_MAP; + // Send start advertise command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_ADV, &ble_adv, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv) + * @brief Request the local device to start advertising with specified values. This is a Blocking API \n + * A received event \ref rsi_ble_on_enhance_connect_t/ \ref rsi_ble_on_connect_t indicates remote device given ble connect command and got connected + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] rsi_ble_adv - This structure pointer holds the information of advertising values \n + * This variable is the pointer of the \ref rsi_ble_req_adv_s structure + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv) +{ + SL_PRINTF(SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_adv_t ble_adv = { 0 }; + if (rsi_ble_adv != NULL) { + memcpy(&ble_adv, rsi_ble_adv, sizeof(rsi_ble_req_adv_t)); + } + + ble_adv.status = RSI_BLE_START_ADV; + + // Send start advertise command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_ADV, &ble_adv, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_encrypt(uint8_t *key, uint8_t *data, uint8_t *resp) + * @brief Encrypt the plain text data fed by the user using the key provided.\n + * It uses the AES-128 bit block cypher alogo to generate encrypted data. Refer to Bluetooth Spec 5.0 for further details. + * @pre Call \ref rsi_wireless_init() before calling this API. This is a Blocking API + * @param[in] key - 16 Bytes key for Encryption of data. + * @param[in] data - 16 Bytes of Data request to encrypt. + * @param[out] resp - Encrypted data + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_encrypt(uint8_t *key, uint8_t *data, uint8_t *resp) +{ + + SL_PRINTF(SL_RSI_BLE_ENCRYPT_TRIGGER, BLE, LOG_INFO); + rsi_ble_encrypt_t ble_en; + memcpy(ble_en.key, key, 16); + memcpy(ble_en.data, data, 16); + + // Send Encrypt command + return rsi_bt_driver_send_cmd(RSI_BLE_ENCRYPT, &ble_en, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_stop_advertising(void) + * @brief Stop advertising. This is a Blocking API + * @pre Call \ref rsi_ble_start_advertising() before calling this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_stop_advertising(void) +{ + + SL_PRINTF(SL_RSI_BLE_STOP_ADV_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_adv_t ble_adv = { 0 }; + + ble_adv.status = RSI_BLE_STOP_ADV; + + // Send stop advertise command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_ADV, &ble_adv, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len) + * @brief Set the advertising data. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] data - Advertising data. + * @param[in] data_len - Total length of advertising data. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + * @note 1. The maximum length of advertising data payload is 31 bytes. \n + * 2. The basic format of advertising payload record contains length and data. \n + */ +int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len) +{ + + SL_PRINTF(SL_RSI_BLE_SET_ADV_DATA_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_adv_data_t ble_adv_data = { 0 }; + + ble_adv_data.data_len = RSI_MIN(data_len, sizeof(ble_adv_data.adv_data)); + memcpy(ble_adv_data.adv_data, data, ble_adv_data.data_len); + + // Send stop advertise command + return rsi_bt_driver_send_cmd(RSI_BLE_SET_ADVERTISE_DATA, &ble_adv_data, NULL); +} + +/*========================================================*/ +/** + * @fn int32_t rsi_ble_set_scan_response_data(uint8_t *data, uint16_t data_len) + * @brief Request the local device to set the scan response data. This is a Blocking API \n + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] data - Data about to be sent + * @param[in] data_len - Length of data, which is about to be sent + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_set_scan_response_data(uint8_t *data, uint16_t data_len) +{ + + SL_PRINTF(SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_scanrsp_data_t ble_scanrsp_data = { 0 }; + ble_scanrsp_data.data_len = RSI_MIN(data_len, sizeof(ble_scanrsp_data.scanrsp_data)); + memcpy(ble_scanrsp_data.scanrsp_data, data, ble_scanrsp_data.data_len); + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_SCAN_RESPONSE_DATA, &ble_scanrsp_data, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_start_scanning(void) + * @brief Start scanning. This is a Blocking API + * A received event \ref rsi_ble_on_adv_report_event_t indicates advertise report of remote device received. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_start_scanning(void) +{ + + SL_PRINTF(SL_RSI_BLE_START_SCANNING_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_scan_t ble_scan = { 0 }; + + ble_scan.status = RSI_BLE_START_SCAN; + + ble_scan.scan_type = RSI_BLE_SCAN_TYPE; + ble_scan.filter_type = RSI_BLE_SCAN_FILTER_TYPE; + ble_scan.scan_int = LE_SCAN_INTERVAL; + ble_scan.scan_win = LE_SCAN_WINDOW; + ble_scan.own_addr_type = LE_PUBLIC_ADDRESS; + + // Send start scanning command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_SCAN, &ble_scan, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_start_scanning_with_values(void *rsi_ble_scan_params) + * @brief Start scanning with values. This is a Blocking API \n + * A received event \ref rsi_ble_on_adv_report_event_t indicates advertise report of remote device received. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] rsi_ble_scan_params - BLE scan parameters structure + * please refer rsi_ble_req_scan_s structure for more info + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_start_scanning_with_values(void *rsi_ble_scan_params) +{ + + SL_PRINTF(SL_RSI_BLE_START_SCANNING_WITH_VALUES_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_scan_t ble_scan = { 0 }; + + if (rsi_ble_scan_params != NULL) { + memcpy(&ble_scan, (rsi_ble_req_scan_t *)rsi_ble_scan_params, sizeof(rsi_ble_req_scan_t)); + } + + ble_scan.status = RSI_BLE_START_SCAN; + + // Send start scanning command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_SCAN, &ble_scan, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_stop_scanning(void) + * @brief Stop scanning. This is a Blocking API + * @pre \ref rsi_ble_start_scanning() API needs to be called before this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * 0x4E0C - Command disallowed + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_stop_scanning(void) +{ + + SL_PRINTF(SL_RSI_BLE_STOP_SCANNING_TRIGGER, BLE, LOG_INFO); + rsi_ble_req_scan_t ble_scan = { 0 }; + + ble_scan.status = RSI_BLE_STOP_SCAN; + + // Send stop scanning command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_SCAN, &ble_scan, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, + * int8_t *remote_dev_addr, + * uint16_t scan_interval, + * uint16_t scan_window, + * uint16_t conn_interval_max, + * uint16_t conn_interval_min, + * uint16_t conn_latency, + * uint16_t supervision_tout) + * @brief Connect to the remote BLE device with the user configured parameters. This is a blocking API. \n + * A received event \ref rsi_ble_on_enhance_connect_t / \ref rsi_ble_on_connect_t indicates that the connection successful and \n + * a received event \ref rsi_ble_on_disconnect_t indicates that connection failures have occurred. + * @note If a connection can't be established, for example, the remote device has gone out of range, has entered into deep sleep, or is not advertising, \n + * the stack will try to connect forever. In this case, the application will not get an event related to the connection request. \n + * To recover from this situation, the application can implement a timeout and call rsi_ble_connect_cancel() to cancel the connection request. \n + * Subsequent calls of this command have to wait for the ongoing command to complete. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr_type - AddressType - Specifies the type of the address mentioned in BD Address \n + * 0 - Public Address \n + * 1 - Random Address + * @param[in] remote_dev_addr - This parameter describes the device address of remote device + * @param[in] scan_interval - LE Scan Interval : N=0xXXXX \n + * It is defined as the time interval from when the Controller + * started its last LE scan until it \n + * begins the subsequent LE scan. \n + * Range: 0x0004 to 0x4000 \n + * Time = N * 0.625 msec \n + * Time Range: 2.5 msec to 10 . 24 seconds + * @param[in] scan_window - LE Scan Window : N=0xXXXX \n + * Amount of time for the duration of the LE scan. LE_Scan_Window + * must be less than or equal to LE_Scan_Interval \n + * Range: 0x0004 to 0x4000 \n + * Time = N * 0.625 msec \n + * Time Range: 2.5 msec to 10 . 24 seconds + * @param[in] conn_interval_max - Max Connection Interval : N=0xXXXX \n + * Minimum value for the connection event interval, which must \n + * be greater than or equal to Conn_Interval_Min. \n + * Range: 0x0006 to 0x0C80 \n + * Time = N * 1.25 msec \n + * Time Range: 7.5 msec to 4 seconds. \n + * 0x0000 - 0x0005 and 0x0C81 - 0xFFFF - Reserved for future use + * @param[in] conn_interval_min - Min Connection Interval : N=0xXXXX \n + * Minimum value for the connection event interval, which must + * be greater than or equal to Conn_Interval_Max. \n + * Range: 0x0006 to 0x0C80 \n + * Time = N * 1.25 msec \n + * Time Range: 7.5 msec to 4 seconds. \n + * 0x0000 - 0x0005 and 0x0C81 - 0xFFFF - Reserved for future use + * @param[in] conn_latency - Connection Latency : N = 0xXXXX \n + * Slave latency for the connection in number of connection events. \n + * Range: 0x0000 to 0x01F4 + * @param[in] supervision_tout - Supervision Timeout : N = 0xXXXX \n + * Supervision timeout for the LE Link. \n + * Range: 0x000A to 0x0C80 \n + * Time = N * 10 msec \n + * Time Range: 100 msec to 32 seconds \n + * 0x0000 - 0x0009 and 0x0C81 - 0xFFFF - Reserved for future use + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, + int8_t *remote_dev_addr, + uint16_t scan_interval, + uint16_t scan_window, + uint16_t conn_interval_max, + uint16_t conn_interval_min, + uint16_t conn_latency, + uint16_t supervision_tout) +{ + SL_PRINTF(SL_RSI_BLE_CONNECT_WITH_PARAMS_TRIGGER, BLE, LOG_INFO); + + SL_PRINTF(SL_RSI_BLE_CONNECT_PARAMS_SCAN, + BLE, + LOG_INFO, + "SCAN_INTERVAL: %2x, SCAN_WINDOW: %2x", + scan_interval, + scan_window); + + SL_PRINTF(SL_RSI_BLE_CONNECT_PARAMS_CONNECT, + BLE, + LOG_INFO, + "CONN_INTERVAL_MAX: %2x, CONN_INTERVAL_MIN: %2x, CONN_LATENCY: %2x", + conn_interval_max, + conn_interval_min, + conn_latency); + + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(conn_interval_min); + rsi_ble_req_conn_t ble_conn = { 0 }; + + ble_conn.dev_addr_type = remote_dev_addr_type; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_conn.dev_addr, remote_dev_addr); +#else + memcpy(ble_conn.dev_addr, remote_dev_addr, 6); +#endif + ble_conn.le_scan_interval = scan_interval; + ble_conn.le_scan_window = scan_window; + ble_conn.conn_interval_min = conn_interval_max; + ble_conn.conn_interval_max = conn_interval_max; + ble_conn.conn_latency = conn_latency; + ble_conn.supervision_tout = supervision_tout; + + // Send connect command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_CONN, &ble_conn, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, int8_t *remote_dev_addr) + * @brief Connect to the remote BLE device. This is a blocking API. \n + * A received event \ref rsi_ble_on_enhance_connect_t/ \ref rsi_ble_on_connect_t indicates that the connection successful and \n + * a received event \ref rsi_ble_on_disconnect_t indicates that connection failures have occurred. + * @note If a connection can't be established, for example, the remote device has gone out of range, has entered into deep sleep, or is not advertising, \n + * the stack will try to connect forever. In this case, the application will not get an event related to the connection request. \n + * To recover from this situation, the application can implement a timeout and call rsi_ble_connect_cancel() to cancel the connection request. \n + * Subsequent calls of this command have to wait for the ongoing command to complete. + * @pre rsi_wireless_init() API needs to be called before this API. + * @param[in] remote_dev_addr_type - This parameter describes the address type of the remote device + * @param[in] remote_dev_addr - This parameter describes the device address of the remote device + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, int8_t *remote_dev_addr) +{ + + SL_PRINTF(SL_RSI_BLE_CONNECT, BLE, LOG_INFO, "ADDRESS_TYPE: %2x", remote_dev_addr_type); + rsi_ble_req_conn_t ble_conn = { 0 }; + + ble_conn.dev_addr_type = remote_dev_addr_type; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_conn.dev_addr, remote_dev_addr); +#else + memcpy(ble_conn.dev_addr, remote_dev_addr, 6); +#endif + ble_conn.le_scan_interval = LE_SCAN_INTERVAL; + ble_conn.le_scan_window = LE_SCAN_WINDOW; + ble_conn.conn_interval_min = CONNECTION_INTERVAL_MIN; + ble_conn.conn_interval_max = CONNECTION_INTERVAL_MAX; + ble_conn.conn_latency = CONNECTION_LATENCY; + ble_conn.supervision_tout = SUPERVISION_TIMEOUT; + + // Send connect command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_CONN, &ble_conn, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_enhance_connect_with_params(void* ble_enhance_conn_params) + * @brief Connect to the remote BLE device with the user configured parameters. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] ble_enhance_conn_params - BLE enhance connection parameter structure: \n + * dev_addr_type - Address type of the device to connect \n + * 0 - Public Address \n + * 1 - Random Address \n \n + * dev_addr - Address of the device to connect \n \n + * filter_policy - Initiater filter policy is used to determine whether the Filter Accept List is used. \n + * 0 - Filter Accept List is not used to determine which advertiser to connect to. \n + * 1 - Filter Accept List is used to determine which advertiser to connect to. \n \n + * own_addr_type - own address type \n \n + * le_scan_interval - LE Scan Interval : N=0xXXXX \n + * It is defined as the time interval from when the Controller started its last LE scan until it begins the subsequent LE scan. \n + * Range: 0x0004 to 0x4000 \n + * Time = N * 0.625 msec \n + * Time Range: 2.5 msec to 10 . 24 seconds \n \n + * le_scan_window - LE Scan Window : N=0xXXXX \n + * Amount of time for the duration of the LE scan. LE_Scan_Window must be less than or equal to LE_Scan_Interval \n + * Range: 0x0004 to 0x4000 \n + * Time = N * 0.625 msec \n + * Time Range: 2.5 msec to 10 . 24 seconds \n \n + * conn_interval_min - Min Connection Interval : N=0xXXXX \n + * Minimum value for the connection event interval, which must be greater than or equal to Conn_Interval_Max. \n + * Range: 0x0006 to 0x0C80 \n + * Time = N * 1.25 msec \n + * Time Range: 7.5 msec to 4 seconds. \n + * 0x0000 - 0x0005 and 0x0C81 - 0xFFFF - Reserved for future use \n \n + * conn_interval_max - Max Connection Interval : N=0xXXXX \n + * Maximum value for the connection event interval, which must be greater than or equal to Conn_Interval_Min. \n + * Range: 0x0006 to 0x0C80 \n + * Time = N * 1.25 msec \n + * Time Range: 7.5 msec to 4 seconds. \n + * 0x0000 - 0x0005 and 0x0C81 - 0xFFFF - Reserved for future use \n \n + * conn_latency - Connection Latency : N = 0xXXXX \n + * Slave latency for the connection in number of connection events. \n + * Range: 0x0000 to 0x01F4 \n \n + * supervision_tout - Supervision Timeout : N = 0xXXXX \n + * Supervision timeout for the LE Link. \n + * Range: 0x000A to 0x0C80 \n + * Time = N * 10 msec \n + * Time Range: 100 msec to 32 seconds \n + * 0x0000 - 0x0009 and 0x0C81 - 0xFFFF - Reserved for future use \n \n + * min_ce_length - Min Connection Event Length : N=0xXXXX \n + * The minimum length of connection event recommended for this LE connection. \n + * Range: 0x0000 to 0xFFFF \n + * Time = N * 0.625 msec \n \n + * max_ce_length - Max Connection Event Length : N=0xXXXX \n + * The maximum length of connection event recommended for this LE connection. \n + * Range: 0x0000 to 0xFFFF \n + * Time = N * 0.625 msec \n \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_enhance_connect_with_params(void *ble_enhance_conn_params) +{ + rsi_ble_req_enhance_conn_t ble_enhance_conn = { 0 }; + + if (ble_enhance_conn_params != NULL) { + memcpy(&ble_enhance_conn, + (rsi_ble_req_enhance_conn_t *)ble_enhance_conn_params, + sizeof(rsi_ble_req_enhance_conn_t)); + } + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_CONN_ENHANCE, &ble_enhance_conn, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_connect_cancel(int8_t *remote_dev_address) + * @brief Cancel the connection to the remote BLE device. This is a blocking API. \n + * A received event \ref rsi_ble_on_disconnect_t indicates disconnect complete. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This parameter describes the device address of the remote device + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments \n + * 0x4E02 - Unknown Connection Identifier \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_connect_cancel(int8_t *remote_dev_address) +{ + + SL_PRINTF(SL_RSI_BLE_CONNECT_CANCEL, BLE, LOG_INFO); + rsi_ble_req_disconnect_t ble_disconnect = { { 0 } }; + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_disconnect.dev_addr, remote_dev_address); +#else + memcpy(ble_disconnect.dev_addr, remote_dev_address, 6); +#endif + ble_disconnect.type = BLE_CONNECT_CANCEL; + + // Send connect cancel command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_DISCONNECT, &ble_disconnect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_disconnect(int8_t *remote_dev_address) + * @brief Disconnect with the remote BLE device. This is a Blocking API + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This parameter describes the device address of the remote device + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E0C - Command disallowed \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_disconnect(int8_t *remote_dev_address) +{ + SL_PRINTF(SL_RSI_BLE_DISCONNECT, BLE, LOG_INFO, "ADDRESS: %1x", *remote_dev_address); + rsi_ble_req_disconnect_t ble_disconnect = { { 0 } }; + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_disconnect.dev_addr, remote_dev_address); +#else + memcpy(ble_disconnect.dev_addr, remote_dev_address, 6); +#endif + ble_disconnect.type = BLE_DISCONNECT; + // Send disconnect command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_DISCONNECT, &ble_disconnect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_device_state(uint8_t *resp) + * @brief Get the local device state. This is a Blocking API. The state value is filled in "resp". + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[out] resp - This is an output parameter which consists of local device state. \n + * This is a 1-byte value. The possible states are described below \n + * BIT(0) Advertising state \n + * BIT(1) Scanning state \n + * BIT(2) Initiating state \n + * BIT(3) Connected state \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_get_device_state(uint8_t *resp) +{ + SL_PRINTF(SL_RSI_BLE_GET_DEVICE_STATE, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_GET_DEV_STATE, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_smp_pairing_cap_data(rsi_ble_set_smp_pairing_capabilty_data_t *smp_pair_cap_data) + * @brief Set the SMP Pairing Capability of local device. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] smp_pair_cap_data - This structure pointer holds the information of the SMP capability data values \n + * please refer rsi_ble_set_smp_pairing_capabilty_data structure for more info + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_set_smp_pairing_cap_data(rsi_ble_set_smp_pairing_capabilty_data_t *smp_pair_cap_data) +{ + + SL_PRINTF(SL_RSI_BLE_SET_SMP_PAIRING_CAP_DATA, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_SET_SMP_PAIRING_CAPABILITY_DATA, smp_pair_cap_data, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_local_irk_value(uint8_t *l_irk) + * @brief Set the IRK value to the local device. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] l_irk - l_irk Pointer to local_irk + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_set_local_irk_value(uint8_t *l_irk) +{ + + SL_PRINTF(SL_RSI_BLE_SET_LOCAL_IRK_VALUE, BLE, LOG_INFO); + rsi_ble_set_local_irk_t local_device_irk = { 0 }; + + memcpy(local_device_irk.irk, l_irk, 16); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_SET_LOCAL_IRK, &local_device_irk, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_conn_param_resp(uint8_t *remote_dev_address, uint8_t status) + * @brief Give the response for the remote device connection parameter request. This is a Blocking API \n + * A received event \ref rsi_ble_on_conn_update_complete_t indicates connection update procedure is successful. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - remote device address + * @param[in] status - accept or reject the connection parameters update request \n + * 0 - ACCEPT, \n + 1 - REJECT \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4E0C - Command disallowed \n + * 0x4046 - Invalid Arguments \n + * 0x4E02 - Unknown Connection Identifier + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_conn_param_resp(uint8_t *remote_dev_address, uint8_t status) +{ + + SL_PRINTF(SL_RSI_BLE_CONN_PARAM_RESPONSE, BLE, LOG_INFO, "STATUS: %1x", status); + rsi_ble_cmd_conn_param_resp_t conn_param_resp_cmd = { 0 }; + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(conn_param_resp_cmd.dev_addr, remote_dev_address); +#else + memcpy(conn_param_resp_cmd.dev_addr, remote_dev_address, 6); +#endif + conn_param_resp_cmd.status = status; + + // Send connect cancel command + return rsi_bt_driver_send_cmd(RSI_BLE_CONN_PARAM_RESP_CMD, &conn_param_resp_cmd, NULL); +} + +/** @} */ +/** @addtogroup BT-LOW-ENERGY1 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_smp_pair_request(uint8_t *remote_dev_address, uint8_t io_capability, uint8_t mitm_req) + * @brief Request the SMP pairing process with the remote device. This is a Blocking API \n + * A received event \ref rsi_ble_on_smp_request_t indicated remote device is given Security Request and need to respond back with \ref rsi_ble_smp_pair_request \n + * A received event \ref rsi_ble_on_smp_response_t indicated remote device is given SMP Pair Request and need to respond back with \ref rsi_ble_smp_pair_response \n + * A received event \ref rsi_ble_on_smp_failed_t indicated SMP procedure have failed + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This is the remote device address + * @param[in] io_capability - This is the device input output capability \n + * 0x00 - Display Only \n + * 0x01 - Display Yes/No \n + * 0x02 - Keyboard Only \n + * 0x03 - No Input No Output + * @param[in] mitm_req - MITM enable/disable \n + * 0 - Disable \n + * 1 - Enable + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_smp_pair_request(uint8_t *remote_dev_address, uint8_t io_capability, uint8_t mitm_req) +{ + + SL_PRINTF(SL_RSI_BLE_SMP_PAIR_REQUEST, BLE, LOG_INFO, "MITM_REQ: %1x", mitm_req); + rsi_ble_req_smp_pair_t smp_pair_req; + memset(&smp_pair_req, 0, sizeof(smp_pair_req)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(smp_pair_req.dev_addr, remote_dev_address); +#else + memcpy(smp_pair_req.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + smp_pair_req.io_capability = io_capability; + smp_pair_req.mitm_req = mitm_req; + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_SMP_PAIR, &smp_pair_req, NULL); +} + +/** @} */ +/** @addtogroup BT-LOW-ENERGY1 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_smp_pair_failed(uint8_t *remote_dev_address ,uint8_t reason) + * @brief Send SMP pairing failure reason to the remote device. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This is the remote device address + * @param[in] reason - This is the reason for SMP Pairing Failure \n + * 0x05 - Pairing Not Supported \n + * 0x08 - Unspecified Reason \n + * 0x09 - Repeated Attempts \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + */ + +int32_t rsi_ble_smp_pair_failed(uint8_t *remote_dev_address, uint8_t reason) +{ + + rsi_ble_req_smp_pair_failed_t smp_pair_failed; + memset(&smp_pair_failed, 0, sizeof(smp_pair_failed)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(smp_pair_failed.dev_addr, remote_dev_address); +#else + memcpy(smp_pair_failed.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + smp_pair_failed.reason = reason; + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_SMP_PAIRING_FAILED, &smp_pair_failed, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, + * uint8_t reply_type, uint8_t *ltk) + * @brief Send the local long term key of its associated local EDIV and local Rand. This is a Blocking API \n + * A received event \ref rsi_ble_on_encrypt_started_t indicated encrypted event is received from module \n + * A received event \ref rsi_ble_on_smp_failed_t indicated SMP procedure have failed + * @param[in] remote_dev_address - remote device address + * @param[in] reply_type - 0 - Negative reply \n + * BIT(0) - Positive Reply (Encryption Enabled)\n + BIT(1) - Un authenticated LTK or STK based Encyption Enabled \n + BIT(2) - Authenticated LTK or STK based Encyption Enabled \n + BIT(3) - Auntenticated LTK with LE Secure Connections based Encryption Enabled \n + BIT(4) to BIT(6) - Reserved for Future use \n + BIT(7) - LE Secure Connection Enabled \n + * @param[in] ltk - Long Term Key 16 bytes + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, uint8_t reply_type, uint8_t *ltk) +{ + + SL_PRINTF(SL_RSI_BLE_LTK_REQ_REPLY, BLE, LOG_INFO, "REPLY_TYPE: %1x", reply_type); + rsi_ble_set_le_ltkreqreply_t le_ltk_req_reply; + memset(&le_ltk_req_reply, 0, sizeof(le_ltk_req_reply)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(le_ltk_req_reply.dev_addr, remote_dev_address); +#else + memcpy(le_ltk_req_reply.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + le_ltk_req_reply.replytype = reply_type; + if (ltk != NULL) { + memcpy(le_ltk_req_reply.localltk, ltk, 16); + } + + return rsi_bt_driver_send_cmd(RSI_BLE_LE_LTK_REQ_REPLY, &le_ltk_req_reply, NULL); +} +/** @} */ +/** @addtogroup BT-LOW-ENERGY1 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_smp_pair_response(uint8_t *remote_dev_address, uint8_t io_capability, uint8_t mitm_req) + * @brief Send SMP pairing response during the process of pairing with the remote device. This is a Blocking API \n + * A received event \ref rsi_ble_on_smp_passkey_t indicated Legacy SMP passkey is received and need to respond back with \ref rsi_ble_smp_passkey() \n + * A received event \ref rsi_ble_on_sc_passkey_t indicated BLE SC passkey is received and need to respond back with \ref rsi_ble_smp_passkey() \n + * A received event \ref rsi_ble_on_smp_passkey_display_t indicates SMP passkey display is received from the module \n + * A received event \ref rsi_ble_on_smp_failed_t indicated SMP Failed event is received + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This is the remote device address + * @param[in] io_capability - This is the device input output capability \n + * 0x00 - Display Only \n + * 0x01 - Display Yes/No \n + * 0x02 - Keyboard Only \n + * 0x03 - No Input No Output + * @param[in] mitm_req - MITM Request info \n + * 0 - Disable \n + * 1 - Enable + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_smp_pair_response(uint8_t *remote_dev_address, uint8_t io_capability, uint8_t mitm_req) +{ + + SL_PRINTF(SL_RSI_BLE_SMP_PAIR_RESPONSE, BLE, LOG_INFO, "MITM_REQ: %1x", mitm_req); + rsi_ble_smp_response_t smp_pair_resp; + memset(&smp_pair_resp, 0, sizeof(smp_pair_resp)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(smp_pair_resp.dev_addr, remote_dev_address); +#else + memcpy(smp_pair_resp.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + smp_pair_resp.io_capability = io_capability; + smp_pair_resp.mitm_req = mitm_req; + + return rsi_bt_driver_send_cmd(RSI_BLE_SMP_PAIR_RESPONSE, &smp_pair_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_smp_passkey(uint8_t *remote_dev_address, uint32_t passkey) + * @brief Send SMP passkey during SMP pairing process with the remote device. This is a Blocking API \n + * A received event \ref rsi_ble_on_encrypt_started_t indicated encrypted event is received from module \n + * A received event \ref rsi_ble_on_le_security_keys_t indicates exchange of security keys completed after encryption \n + * A received event \ref rsi_ble_on_smp_failed_t indicated SMP procedure have failed + * @pre Call \ref rsi_ble_smp_pair_request and \ref rsi_ble_smp_pair_response + * before calling this API. + * @param[in] remote_dev_address - This is the remote device address + * @param[in] passkey - This is the key required in pairing process + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_smp_passkey(uint8_t *remote_dev_address, uint32_t passkey) +{ + + SL_PRINTF(SL_RSI_BLE_SMP_PASSKEY, BLE, LOG_INFO, "PASSKEY: %4x", passkey); + rsi_ble_smp_passkey_t smp_passkey; + memset(&smp_passkey, 0, sizeof(smp_passkey)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(smp_passkey.dev_addr, remote_dev_address); +#else + memcpy(smp_passkey.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + smp_passkey.passkey = passkey; + return rsi_bt_driver_send_cmd(RSI_BLE_SMP_PASSKEY, &smp_passkey, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_le_ping_timeout(uint8_t *remote_dev_address, uint16_t *time_out) + * @brief Get the timeout value of the LE ping. This is a Blocking API + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This is the remote device address + * @param[out] time_out - This a response parameter which holds timeout value for \n + * authentication payload command. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * @note Currently Get ping is not supported. + */ + +int32_t rsi_ble_get_le_ping_timeout(uint8_t *remote_dev_address, uint16_t *time_out) +{ + uint16_t status; + + SL_PRINTF(SL_RSI_BLE_GET_LE_PING_TIMEOUT, BLE, LOG_INFO); + rsi_ble_get_le_ping_timeout_t leping_cmd; + rsi_ble_rsp_get_le_ping_timeout_t le_ping_rsp; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(leping_cmd.dev_addr, remote_dev_address); +#else + memcpy(leping_cmd.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + status = rsi_bt_driver_send_cmd(RSI_BLE_GET_LE_PING, &leping_cmd, &le_ping_rsp); + if (status == 0) { + *time_out = le_ping_rsp.time_out; + } + + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_le_ping_timeout(uint8_t *remote_dev_address, uint16_t time_out) + * @brief Set the timeout value of the LE ping. This is a Blocking API \n + * A received event of \ref rsi_ble_on_le_ping_payload_timeout_t indicates le ping payload timeout expired + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - This is the remote device address + * @param[out] timeout - This input parameter sets timeout value for authentication \n + * payload command.(in milliseconds) + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_set_le_ping_timeout(uint8_t *remote_dev_address, uint16_t time_out) +{ + + SL_PRINTF(SL_RSI_BLE_SET_LE_PING_TIMEOUT, BLE, LOG_INFO, "TIMEOUT: %2x", time_out); + rsi_ble_set_le_ping_timeout_t leping_cmd; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(leping_cmd.dev_addr, remote_dev_address); +#else + memcpy(leping_cmd.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + leping_cmd.time_out = time_out; + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_LE_PING, &leping_cmd, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_clear_whitelist(void) + * @brief Clear all the BD address present in white list. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_clear_whitelist(void) +{ + SL_PRINTF(SL_RSI_BLE_CLEAR_WHITELIST_TRIGGER, BLE, LOG_INFO); + rsi_ble_white_list_t le_whitelist = { 0 }; + le_whitelist.addordeltowhitlist = CLEAR_WHITELIST; + + return rsi_bt_driver_send_cmd(RSI_BLE_LE_WHITE_LIST, &le_whitelist, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_addto_whitelist(int8_t *dev_address, uint8_t dev_addr_type) + * @brief Add BD address to white list. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] dev_address - Address of the device which is going to add in white list + * @param[in] dev_addr_type - address type of BD address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Maximum number of device address that firmware can store is 10. \n Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_addto_whitelist(int8_t *dev_address, uint8_t dev_addr_type) +{ + + SL_PRINTF(SL_RSI_BLE_ADD_TO_WHITELIST, BLE, LOG_INFO, "DEVICE_ADDRESS_TYPE: %1x", dev_addr_type); + rsi_ble_white_list_t le_whitelist = { 0 }; + le_whitelist.addordeltowhitlist = ADD_DEVICE_TO_WHITELIST; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(le_whitelist.dev_addr, dev_address); +#else + memcpy(le_whitelist.dev_addr, dev_address, 6); +#endif + le_whitelist.bdaddressType = dev_addr_type; + + return rsi_bt_driver_send_cmd(RSI_BLE_LE_WHITE_LIST, &le_whitelist, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_deletefrom_whitelist(int8_t *dev_address, uint8_t dev_addr_type) + * @brief Delete particular BD address from white list. This is a Blocking API + * @pre \ref rsi_ble_addto_whitelist() API needs to be called before this API. + * @param[in] dev_address - Address of the device which is going to delete from white list + * @param[in] dev_addr_type - address type of BD address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_deletefrom_whitelist(int8_t *dev_address, uint8_t dev_addr_type) +{ + + SL_PRINTF(SL_RSI_BLE_DELETEFROM_WHITELIST, BLE, LOG_INFO, "DEVICE_ADDRESS_TYPE: %1x", dev_addr_type); + rsi_ble_white_list_t le_whitelist = { 0 }; + le_whitelist.addordeltowhitlist = DELETE_DEVICE_FROM_WHITELIST; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(le_whitelist.dev_addr, dev_address); +#else + memcpy(le_whitelist.dev_addr, dev_address, 6); +#endif + le_whitelist.bdaddressType = dev_addr_type; + + return rsi_bt_driver_send_cmd(RSI_BLE_LE_WHITE_LIST, &le_whitelist, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_resolvlist(uint8_t process_type, + * uint8_t remote_dev_addr_type, + * uint8_t *remote_dev_address, + * uint8_t *peer_irk, + * uint8_t *local_irk) + * @brief resolvlist api used for multiple purpose based on the process type. It will be used to add/remove/clear a device to/from the list. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] process_type - Indicates which type of process this is, as follows: \n + * 1 - add a device to the resolve list \n + * 2 - remove a device from the resolve list \n + * 3 - clear the entire resolve list + * @param[in] remote_dev_addr_type - typr of the remote device address + * @param[in] remote_dev_address - remote device address \n + 0 - Public identity address \n + 1 - Random (static) identity address \n + * @param[in] peer_irk - 16-byte IRK of the peer device + * @param[in] local_irk - 16-byte IRK of the local device + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_resolvlist(uint8_t process_type, + uint8_t remote_dev_addr_type, + uint8_t *remote_dev_address, + uint8_t *peer_irk, + uint8_t *local_irk) +{ + + SL_PRINTF(SL_RSI_BLE_RESOLVLIST, + BLE, + LOG_INFO, + "PROCESS_TYPE: %1x, REMOTE_DEVICE_ADDRESS_TYPE: %1x", + process_type, + remote_dev_addr_type); + rsi_ble_resolvlist_t resolvlist; + + resolvlist.process_type = process_type; + resolvlist.remote_dev_addr_type = remote_dev_addr_type; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(resolvlist.remote_dev_addr, remote_dev_address); +#else + memcpy(resolvlist.remote_dev_addr, (int8_t *)remote_dev_address, 6); +#endif + memcpy(resolvlist.peer_irk, peer_irk, 16); + memcpy(resolvlist.local_irk, local_irk, 16); + return rsi_bt_driver_send_cmd(RSI_BLE_PROCESS_RESOLV_LIST, &resolvlist, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_resolving_list_size(uint8_t *resp) + * @brief Request to get resolving list size. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[out] resp - output parameter which consists of supported resolving the list size. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 : Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_get_resolving_list_size(uint8_t *resp) +{ + + SL_PRINTF(SL_RSI_BLE_GET_RESOLVING_LIST_SIZE, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_GET_RESOLVING_LIST_SIZE, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_addr_resolution_enable(uint8_t enable, uint16_t tout) + * @brief Request to enable address resolution, and to set resolvable private address timeout. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] enable - value to enable/disable address resolution \n + 1 - enables address resolution \n + * 0 - disables address resolution + * @param[in] tout - the period for changing address of our local device in seconds \n + Value ranges from 0x0001 to 0xA1B8 (1s to approximately 11.5 hours) + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 : Buffer not available to serve the command + */ + +int32_t rsi_ble_set_addr_resolution_enable(uint8_t enable, uint16_t tout) +{ + + SL_PRINTF(SL_RSI_BLE_SET_ADDR_RESOULTION_ENABLE, BLE, LOG_INFO); + rsi_ble_set_addr_resolution_enable_t addr_resolution_enable; + + addr_resolution_enable.enable = enable; + addr_resolution_enable.tout = tout; + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_ADDRESS_RESOLUTION_ENABLE, &addr_resolution_enable, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_privacy_mode(uint8_t remote_dev_addr_type, + * uint8_t *remote_dev_address, uint8_t privacy_mode) + * @brief Request to set privacy mode for particular device. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr_type - type of the remote device address \n + * 0 - Public Identity Address \n + * 1 - Random (static) Identity Address + * @param[in] remote_dev_address - remote device address + * @param[in] privacy_mode - type of the privacy mode \n + 0 - Network privacy mode \n + * 1 - Device privacy mode + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 : Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_set_privacy_mode(uint8_t remote_dev_addr_type, uint8_t *remote_dev_address, uint8_t privacy_mode) +{ + SL_PRINTF(SL_RSI_BLE_SET_PRIVACY_MODE, BLE, LOG_INFO, "REMOTE_DEVICE_ADDRESS_TYPE: %1x", remote_dev_addr_type); + rsi_ble_set_privacy_mode_t set_privacy_mode; + set_privacy_mode.remote_dev_addr_type = remote_dev_addr_type; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_privacy_mode.remote_dev_addr, remote_dev_address); +#else + memcpy(set_privacy_mode.remote_dev_addr, (int8_t *)remote_dev_address, 6); +#endif + set_privacy_mode.privacy_mode = privacy_mode; + return rsi_bt_driver_send_cmd(RSI_BLE_SET_PRIVACY_MODE, &set_privacy_mode, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp) + * @brief Reads the TX and RX PHY rates of the Connection. This is a Blocking API + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - remote device address + * @param[out] resp - pointer to store the response + please refer \ref rsi_ble_resp_read_phy_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp) +{ + + SL_PRINTF(SL_RSI_BLE_READPHY, BLE, LOG_INFO); + rsi_ble_req_read_phy_t ble_read_phy = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_read_phy.dev_addr, remote_dev_address); +#else + memcpy(ble_read_phy.dev_addr, remote_dev_address, 6); +#endif + + // Send connect cancel command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_READ_PHY, &ble_read_phy, resp); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, + * uint16_t coded_phy) + * @brief Set TX and RX PHY. This is a Blocking API \n + * A received event \ref rsi_ble_on_phy_update_complete_t indicates phy rate update complete. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - remote device address \n + * @param[in] tx_phy - transmit phy rate \n + BIT(0) - Host prefers to use the LE 1M transmitter PHY (possibly among others) \n + * BIT(1) - Host prefers to use the LE 2M transmitter PHY (possibly among others) \n + * BIT(2) - Host prefers to use the LE Coded transmitter PHY (possibly among others) \n + * BIT(3) - BIT(7) Reserved for future use \n + * @param[in] rx_phy - receive phy rate \n + BIT(0) - Host prefers to use the LE 1M receiver PHY (possibly among others) \n + * BIT(1) - Host prefers to use the LE 2M receiver PHY (possibly among others) \n + * BIT(2) - Host prefers to use the LE Coded receiver PHY (possibly among others) \n + * BIT(3) - BIT(7) Reserved for future use \n + * @param[in] coded_phy - TX/RX coded phy rate \n + 0 = Host has no preferred coding when transmitting on the LE Coded PHY \n + * 1 = Host prefers that S=2 coding be used when transmitting on the LE Coded PHY \n + * 2 = Host prefers that S=8 coding be used when transmitting on the LE Coded PHY \n + * 3 = Reserved for future use \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, uint16_t coded_phy) +{ + + SL_PRINTF(SL_RSI_SETPHY_TRIGGER, BLE, LOG_INFO); + rsi_ble_set_phy_t set_phy; + memset(&set_phy, 0, sizeof(set_phy)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_phy.dev_addr, remote_dev_address); +#else + memcpy(set_phy.dev_addr, remote_dev_address, 6); +#endif + set_phy.all_phy = ALL_PHYS; + set_phy.tx_phy = tx_phy; + set_phy.rx_phy = rx_phy; + set_phy.phy_options = coded_phy; + + // Send connect cancel command + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_SET_PHY, &set_phy, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_conn_params_update(uint8_t *remote_dev_address, + * uint16_t min_int, + * uint16_t max_int, + * uint16_t latency, + * uint16_t timeout) + * @brief Requests the connection parameters change with the remote device.\n + * When the Silabs device is acting as a master, this API is used to update the connection parameters. \n + * When the Silabs device is acts as a slave, this API is used to request the master to intiate the connection update procedure. This is a Blocking API \n + * A received event \ref rsi_ble_on_conn_update_complete_t indicates connection parameters update complete. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - remote device address + * @param[in] min_int - minimum value for the connection interval. \n + * this shall be less than or equal to max_int . + * @param[in] max_int - maximum value for the connection interval. \n + * this shall be greater than or equal to min_int. + * @param[in] latency - slave latency for the connection in number of connection events.\n + * Ranges from 0 to 499 + * @param[in] timeout - supervision timeout for the LE Link. \n + * Ranges from 10 to 3200 (Time = N * 10 ms, Time Range: 100 ms to 32 s) + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * @note min_int and max_int values ranges from 6 to 3200 (Time = N * 1.25 ms, Time Range: 7.5 ms to 4 s)\n + latency : If latency value is greater than 32 ,Limiting the slave latency value to 32\n + Max supported slave latency is 32 when Device is in Slave Role. + * + */ +int32_t rsi_ble_conn_params_update(uint8_t *remote_dev_address, + uint16_t min_int, + uint16_t max_int, + uint16_t latency, + uint16_t timeout) +{ + + SL_PRINTF(SL_RSI_BLE_CONN_PARMS_UPDATE, + BLE, + LOG_INFO, + "MIN_INTERVAL: %2x, MAX_INTERVAL: %2x, LATENCY: %2x", + min_int, + max_int, + latency); + rsi_ble_cmd_conn_params_update_t conn_params_update_cmd = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(conn_params_update_cmd.dev_addr, remote_dev_address); +#else + memcpy(conn_params_update_cmd.dev_addr, remote_dev_address, 6); +#endif + conn_params_update_cmd.min_interval = min_int; + conn_params_update_cmd.max_interval = max_int; + conn_params_update_cmd.latency = latency; + conn_params_update_cmd.timeout = timeout; + + // Send connect cancel command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_CONN_PARAMS_UPDATE, &conn_params_update_cmd, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_data_len(uint8_t *remote_dev_address, uint16_t tx_octets, uint16_t tx_time) + * @brief Sets the TX octets and the TX time of specified link (remote device connection). This is a Blocking API. \n + * A received event \ref rsi_ble_on_data_length_update_t indicates data length update complete. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] remote_dev_address - remote device device \n + * @param[in] tx_octets - preferred maximum number of payload octets that the local Controller \n + * should include in a single Link Layer packet on this connection. + * @param[in] tx_time - preferred maximum number of microseconds that the local Controller \n + * should use to transmit a single Link Layer packet on this connection. + * @return 0 - LE_Set_Data_Length command succeeded. \n + * Non-Zero Value - Failure \n + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_set_data_len(uint8_t *remote_dev_address, uint16_t tx_octets, uint16_t tx_time) +{ + + SL_PRINTF(SL_RSI_BLE_SET_DATA_LEN, BLE, LOG_INFO); + rsi_ble_setdatalength_t lesetdatalen; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(lesetdatalen.dev_addr, remote_dev_address); +#else + memcpy(lesetdatalen.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + lesetdatalen.txoctets = tx_octets; + lesetdatalen.txtime = tx_time; + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_DATA_LEN, &lesetdatalen, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_read_max_data_len(rsi_ble_read_max_data_length_t *blereaddatalen) + * @brief reads the max supported values of TX octets, TX time, RX octets and Rx time. This is a Blocking API + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[out] blereaddatalen - pointer to structure variable, + Please refer rsi_ble_resp_read_max_data_length_s structure for more info. + * @return 0 - command success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_ble_read_max_data_len(rsi_ble_read_max_data_length_t *blereaddatalen) +{ + + SL_PRINTF(SL_RSI_BLE_READ_MAX_DATA_LEN_TRIGGER, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_READ_MAX_DATA_LEN, NULL, blereaddatalen); +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY6 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_rx_test_mode(uint8_t rx_channel, uint8_t phy, uint8_t modulation) + * @brief Start the BLE RX test mode in controller. This is a Blocking API + * @param[in] rx_channel - Channel in which packet have to be received (0 - 39) + * @param[in] phy - 0x00 Reserved for future use \n + * 0x01 Receiver set to use the LE 1M PHY \n + * 0x02 Receiver set to use the LE 2M PHY \n + * 0x03 Receiver set to use the LE Coded PHY \n + * (0x04 - 0xFF) Reserved for future use. + * @param[in] modulation - 0x00 Assume transmitter will have a standard standard modulation index \n + * 0x01 Assume transmitter will have a stable modulation index \n + * (0x02 - 0xFF) Reserved for future use + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_rx_test_mode(uint8_t rx_channel, uint8_t phy, uint8_t modulation) +{ + + SL_PRINTF(SL_RSI_BLE_RX_TEST_MODE_TRIGGER, BLE, LOG_INFO); + rsi_ble_rx_test_mode_t rx_test_mode; + + rx_test_mode.rx_channel = rx_channel; + rx_test_mode.phy = phy; + rx_test_mode.modulation = modulation; + + return rsi_bt_driver_send_cmd(RSI_BLE_RX_TEST_MODE, &rx_test_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_tx_test_mode(uint8_t tx_channel, uint8_t phy, + * uint8_t tx_len, uint8_t mode) + * @brief Start the BLE TX test mode in controller. This is a Blocking API + * @param[in] tx_channel - RF Channel (0-39). \n + * @param[in] phy - 0x00 Reserved for future use \n + * 0x01 Transmitter set to use the LE 1M PHY \n + * 0x02 Transmitter set to use the LE 2M PHY \n + * 0x03 Transmitter set to use the LE Coded PHY with S=8 data coding \n + * 0x04 Transmitter set to use the LE Coded PHY with S=2 data coding \n + * (0x05 - 0xFF) Reserved for future use. + * @param[in] tx_len - Length in bytes of payload data in each packet ( 1 - 251 bytes). + * @param[in] mode - 0x00 PRBS9 sequence '11111111100000111101...' \n + * 0x01 Repeated '11110000' \n + * 0x02 Repeated '10101010' \n + * 0x03 PRBS15 \n + * 0x04 Repeated '11111111' \n + * 0x05 Repeated '00000000' \n + * 0x06 Repeated '00001111' \n + * 0x07 Repeated '01010101' \n + * 0x08 - 0xFF Reserved for future use \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_tx_test_mode(uint8_t tx_channel, uint8_t phy, uint8_t tx_len, uint8_t mode) +{ + + SL_PRINTF(SL_RSI_BLE_TX_TEST_MODE_TRIGGER, BLE, LOG_INFO); + rsi_ble_tx_test_mode_t tx_test_mode; + + tx_test_mode.tx_channel = tx_channel; + tx_test_mode.phy = phy; + tx_test_mode.tx_len = tx_len; + tx_test_mode.tx_data_mode = mode; + + return rsi_bt_driver_send_cmd(RSI_BLE_TX_TEST_MODE, &tx_test_mode, NULL); +} + +/** + * @fn int32_t rsi_ble_end_test_mode(uint16_t *num_of_pkts) + * @brief Stop the BLE TX / RX test mode in controller. This is a Blocking API + * @param[out] num_of_pkts - Number of RX packets received are displayed when RX test is stopped \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_end_test_mode(uint16_t *num_of_pkts) +{ + SL_PRINTF(SL_RSI_BLE_END_TEST_MODE_TRIGGER, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_END_TEST_MODE, NULL, num_of_pkts); +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY6 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_per_transmit(struct rsi_ble_per_transmit_s *rsi_ble_per_tx) + * @brief Initiate the BLE transmit PER mode in the controller. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] rsi_ble_per_tx - This parameter is the buffer to hold the structure values \n + * This is a structure variable of struct \ref rsi_ble_per_transmit_s + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_per_transmit(struct rsi_ble_per_transmit_s *rsi_ble_per_tx) +{ + SL_PRINTF(SL_RSI_BLE_INIT_PER_TRANSMIT_MODE_TRIGGER, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, rsi_ble_per_tx, NULL); +} + +/** + * @fn int32_t rsi_ble_per_receive(struct rsi_ble_per_receive_s *rsi_ble_per_rx) + * @brief Initiate the BLE receive PER mode in the controller. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] rsi_ble_per_rx - This parameter is the buffer to hold the structure values \n + * This is a structure variable of struct \ref rsi_ble_per_receive_s + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_per_receive(struct rsi_ble_per_receive_s *rsi_ble_per_rx) +{ + + SL_PRINTF(SL_RSI_BLE_PER_RECIEVE_TRIGGER, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, rsi_ble_per_rx, NULL); +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY1 +* @{ +*/ +/** + * @fn int32_t rsi_ble_vendor_rf_type(uint8_t ble_power_index) + * @brief Issue a vendor-specific command to set the RF type in the controller on given inputs. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API + * @param[in] ble_power_index - power index + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_vendor_rf_type(uint8_t ble_power_index) +{ + + SL_PRINTF(SL_RSI_BLE_VENDOR_RF_TRIGGER, BLE, LOG_INFO, "BLE_POWER_INDEX: %1x", ble_power_index); + rsi_ble_vendor_rf_type_t ble_vendor_rf_type; + + ble_vendor_rf_type.opcode[0] = (BLE_VENDOR_RF_TYPE_CMD_OPCODE & 0xFF); + ble_vendor_rf_type.opcode[1] = ((BLE_VENDOR_RF_TYPE_CMD_OPCODE >> 8) & 0xFF); + ble_vendor_rf_type.ble_power_index = ble_power_index; + + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &ble_vendor_rf_type, NULL); +} + +/** + * @fn int32_t rsi_ble_white_list_using_adv_data(uint8_t enable, + * uint8_t data_compare_index, + * uint8_t len_for_compare_data, + * uint8_t *payload) + * @brief Give vendor-specific command to set the whitelist feature based on + * the advertisers advertising payload. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] enable - enable/disable + * @param[in] data_compare_index - From which index onwards compare + * @param[in] len_for_compare_data - total length of data to compare + * @param[in] payload - Payload + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * 0x4E62 Invalid Parameters \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_white_list_using_adv_data(uint8_t enable, + uint8_t data_compare_index, + uint8_t len_for_compare_data, + uint8_t *payload) +{ + + SL_PRINTF(SL_RSI_BLE_WHITELIST_USING_ADV_DATA, BLE, LOG_INFO); + rsi_ble_req_whitelist_using_payload_t whitelist_using_payload; + memset(&whitelist_using_payload, 0, sizeof(whitelist_using_payload)); + + whitelist_using_payload.opcode[0] = (BLE_VENDOR_WHITELIST_USING_ADV_DATA_PAYLOAD & 0xFF); + whitelist_using_payload.opcode[1] = ((BLE_VENDOR_WHITELIST_USING_ADV_DATA_PAYLOAD >> 8) & 0xFF); + + whitelist_using_payload.enable = enable; + whitelist_using_payload.total_len = 31; + whitelist_using_payload.data_compare_index = data_compare_index; + whitelist_using_payload.len_for_compare_data = len_for_compare_data; + + memcpy(whitelist_using_payload.adv_data_payload, payload, 31); + + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &whitelist_using_payload, NULL); +} + +/*==============================================*/ +/** + * @fn void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len) + * @brief Used to extract remote Bluetooth device name from the received advertising report. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_name - device name + * @param[in] pbuf - advertise data packet buffer pointer + * @param[in] buf_len - buffer length + * @return void + */ + +void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len) +{ + + SL_PRINTF(SL_RSI_BLE_AD_PACKET_EXTRACT, BLE, LOG_INFO); + uint8_t adv_len; + uint8_t adv_type; + uint8_t ix; + uint8_t name_len; + + ix = 0; + + while (ix < buf_len) { + adv_len = pbuf[ix]; + ix += sizeof(uint8_t); + adv_type = pbuf[ix]; + + switch (adv_type) { + case 0x08: + case 0x09: { + name_len = adv_len - 1; + memcpy(remote_name, &pbuf[ix + 1], name_len); + remote_name[name_len] = 0; + return; + } + // no break + default: + break; + } + + ix += adv_len; + } +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY1 +* @{ +*/ +/*==============================================*/ +/** + * @fn void rsi_ble_update_directed_address(uint8_t *remote_dev_addr) + * @brief Update the direct address with the remote device address. This is a Blocking API + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr - Remote device BD address + * @return void + */ + +void rsi_ble_update_directed_address(uint8_t *remote_dev_addr) +{ + + SL_PRINTF(SL_RSI_BLE_UPDATE_DIRECTED_ADDRESS_TRIGGER, BLE, LOG_INFO, "REMOTE_DEVICE_ADDRESS: %1x", *remote_dev_addr); + rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(le_cb->directed_addr, remote_dev_addr); +#else + memcpy(le_cb->directed_addr, (int8_t *)remote_dev_addr, 6); +#endif +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, + * uint8_t *rand, uint8_t *ltk) + * @brief Start the encryption process with the remote device. This is a Blocking API \n + * A received event \ref rsi_ble_on_encrypt_started_t indicated encrypted event is received from module \n + * A received event \ref rsi_ble_on_le_security_keys_t indicates exchange of security keys completed after encryption. \n + * A received event \ref rsi_ble_on_smp_failed_t indicated SMP procedure have failed + * @pre Encryption enabled event should come before calling this API for second time SMP connection. + * @param[in] remote_dev_address - Remote BD address in string format + * @param[in] ediv - remote device ediv value. + * @param[in] rand - remote device rand value. + * @param[in] ltk - remote device ltk value. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * -4 - Buffer not available to serve the command + * 0x4D05 BLE socket not available \n + * 0x4E62 Invalid Parameters \n + * 0x4D04 BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, uint8_t *rand, uint8_t *ltk) +{ + + SL_PRINTF(SL_RSI_BLE_ENCRYPTION_TRIGGER, BLE, LOG_INFO); + rsi_ble_strat_encryption_t encrypt; + memset(&encrypt, 0, sizeof(encrypt)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(encrypt.dev_addr, remote_dev_address); +#else + memcpy(encrypt.dev_addr, (int8_t *)remote_dev_address, 6); +#endif + encrypt.ediv = ediv; + memcpy(encrypt.rand, rand, 8); + memcpy(encrypt.ltk, ltk, 16); + + return rsi_bt_driver_send_cmd(RSI_BLE_RSP_START_ENCRYPTION, &encrypt, NULL); +} +/** @} */ + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_ble_tx_power(uint8_t role, uint8_t *remote_dev_address, + * int8_t tx_power) + * @brief Set the TX power value per GAP role. This is a Blocking API + * @note This API is not supported in the current release. + * @param[in] role + * ADV_ROLE 0x01 \n + * SCAN_AND_CENTRAL_ROLE 0x02 \n + * PERIPHERAL_ROLE 0x03 \n + * CONN_ROLE 0x04 \n + * @param[in] remote_dev_address - Remote device address + * @param[in] tx_power - power value + * @note remote_dev_address is valid only on role=CONN_ROLE \n + * #define RSI_BLE_PWR_INX_DBM 0 indicate tx_power in index \n + * Default Value for BLE Tx Power Index is 31, The range for the BLE Tx Power Index is 1 to 75 (0, 32 indexes are invalid) \n + * 1 - 31 BLE - 0DBM Mode. \n + * 33 - 63 BLE - 10DBM Mode. \n + * 64 - 79 BLE - HP Mode. \n + * Currently this API is supports only BLE LP mode . i.e. 1 to 63 BLE LP MODE \n + * #define RSI_BLE_PWR_INX_DBM 1 indicate tx_power in dBm \n + * tx_power in dBm (-8dBm to 15 dBm) \n + * Currently this API is supports only BLE LP mode . i.e. -8 dBm to 4dBm BLE LP MODE \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E02 Unknown Connection Identifier \n + * 0x4E01 Unknown HCI Command \n + * 0x4E0C Command disallowed \n + * 0x4046 Invalid Arguments \n + * 0x4D04 BLE not connected \n + * 0x4D14 BLE parameter out of mandatory range + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_set_ble_tx_power(uint8_t role, uint8_t *remote_dev_address, int8_t tx_power) +{ + + SL_PRINTF(SL_RSI_BLE_SET_BLE_TX_POWER, BLE, LOG_INFO); + rsi_ble_set_ble_tx_power_t ble_tx_power = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(ble_tx_power.dev_addr, remote_dev_address); +#else + memcpy(ble_tx_power.dev_addr, remote_dev_address, RSI_DEV_ADDR_LEN); +#endif + ble_tx_power.role = role; +#if RSI_BLE_PWR_INX_DBM + ble_tx_power.tx_power = rsi_convert_db_to_powindex(tx_power); + if (ble_tx_power.tx_power == 0) { + + SL_PRINTF(SL_RSI_ERROR_INVALID_PARAMETER, BLE, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } +#else + ble_tx_power.tx_power = tx_power; +#endif + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_SET_BLE_TX_POWER, &ble_tx_power, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_prop_protocol_ble_bandedge_tx_power(uint8_t protocol, int8_t bandedge_tx_power) + * @brief Set the Proprietary Protocol and BLE protocol bandedge tx power + * @param[in] protocol + * BLE_PROTOCOL 0x01 \n + * PROP_PROTOCOL_PROTOCOL 0x02 \n + * @param[in] tx-power - power value ( -8 dBm to 15 dBm) + * @note #define RSI_BLE_PWR_INX_DBM 0 indicate tx_power in index \n + * Default Value for BLE Tx Power Index is 31, The range for the BLE Tx Power Index is 1 to 75 (0, 32 indexes are invalid) \n + * 1 - 31 BLE - 0DBM Mode. \n + * 33 - 63 BLE - 10DBM Mode. \n + * 64 - 79 BLE - HP Mode. \n + * Currently this API is supports only BLE LP mode . i.e. 1 to 63 BLE LP MODE \n + * #define RSI_BLE_PWR_INX_DBM 1 indicate tx_power in dBm \n + * tx_power in dBm (-8dBm to 15 dBm) \n + * Currently this API is supports only BLE LP mode . i.e. -8 dBm to 4dBm BLE LP MODE \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 Invalid Arguments \n + * 0x4D14 BLE parameter out of mandatory range + * @note Refer Error Codes section for above error codes \ref error-codes. + * + */ + +int32_t rsi_ble_set_prop_protocol_ble_bandedge_tx_power(uint8_t protocol, int8_t bandedge_tx_power) +{ + rsi_ble_set_prop_protocol_ble_bandedge_tx_power_t prop_protocol_ble_bandedge_tx_power = { 0 }; + + prop_protocol_ble_bandedge_tx_power.protocol = protocol; +#if RSI_BLE_PWR_INX_DBM + prop_protocol_ble_bandedge_tx_power.tx_power = rsi_convert_db_to_powindex(bandedge_tx_power); + if (prop_protocol_ble_bandedge_tx_power.tx_power == 0) { + return RSI_ERROR_INVALID_PARAM; + } +#else + prop_protocol_ble_bandedge_tx_power.tx_power = bandedge_tx_power; +#endif + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_SET_PROP_PROTOCOL_BLE_BANDEDGE_TXPOWER, + &prop_protocol_ble_bandedge_tx_power, + NULL); +} +/** @addtogroup BT-LOW-ENERGY5 +* @{ +*/ + +/*========================================================*/ +/** + * @fn int32_t rsi_ble_get_max_no_of_supp_adv_sets(uint8_t *resp) + * @brief request to the controller to know the maximum no.of supporting advertising sets + * @param[in] none + * @param[out] resp - Number of Advertising sets supported ,filled by the controller. \n Possible values of Number of Advertising sets supported : 0x01 to 0xF0 + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the controller to know the maximum no.of supporting advertising sets + * @note : The number of advertising sets that can be supported is not fixed and it can be configured through the Opermodes + */ +int32_t rsi_ble_get_max_no_of_supp_adv_sets(uint8_t *resp) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_GET_AE_MAX_NO_OF_ADV_SETS; + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, resp); +} + +/*========================================================*/ +/** + * @fn int32_t rsi_ble_get_max_adv_data_len(uint8_t *resp) + * @brief request to the controller to know the maximum supporting advertising data length + * @param[in] none + * @param[out] resp - filled by the controller \n + * Possible values of Maximum Advertising Data Length : 0x001F to 0x0672 \n + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the controller to know the maximum supporting advertising data length + */ +int32_t rsi_ble_get_max_adv_data_len(uint8_t *resp) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_GET_AE_MAX_ADV_DATA_LEN; + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, resp); +} + +/*==============================================*/ +/** + * @fn rsi_ble_set_ae_set_random_address(uint8_t handle, uint8_t *rand_addr) + * @brief sets the ae set random address + * @param[in] handle - Advertising_Handle : Used to identify an advertising set + * @param[in] rand_addr - Random_Address : Random device address , may be either of static address or Private address + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function is used by the host to set the random device address specified by the Random_Address_parameter + */ +int32_t rsi_ble_set_ae_set_random_address(uint8_t handle, uint8_t *rand_addr) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_SET_RANDOM_ADDR; + + ae_pdu.pdu_type.ae_random_address.adv_handle = handle; + memcpy(&ae_pdu.pdu_type.ae_random_address.addr, rand_addr, RSI_DEV_ADDR_LEN); + + //! Send set ae set random address command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*========================================================*/ +/** + * @fn int32_t rsi_ble_set_ae_params(void *ble_ae_params, int8_t *sel_tx_pwr) + * @brief request the local device to set the extended advertising parameters + * @param[in] ble_ae_params - Extended Advertising Parameters command data to be sent is filled in this + * @param[out] sel_tx_power - Selected_TX_Power, selected output tx power, Its units are in dBm and Range : -127 to +20 + * @ @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the local device to set Extended Advertising Parameters + */ +int32_t rsi_ble_set_ae_params(void *ble_ae_params, int8_t *sel_tx_pwr) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_PARAMS; + memcpy(&ae_pdu.pdu_type.ae_adv_params, (rsi_ble_ae_adv_params_t *)ble_ae_params, sizeof(rsi_ble_ae_adv_params_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, sel_tx_pwr); +} + +/*========================================================*/ +/** + * @fn int32_t rsi_ble_set_ae_data(void *ble_ae_data) + * @brief request the local device to set the AE advertiser data used in advertising PDUs + * @param[in] ble_ae_data - Extended Advertising data to be sent is filled in this + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the local device to set the AE advertiser data used in advertising PDUs + * @note Refer to Bluetooth spec 5.3 for possible combinations ae_adv/scanresp data can be set for . + */ +int32_t rsi_ble_set_ae_data(void *ble_ae_data) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_DATA; + memcpy(&ae_pdu.pdu_type.ae_adv_or_scn_rsp_data, (rsi_ble_ae_data_t *)ble_ae_data, sizeof(rsi_ble_ae_data_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_start_ae_advertising(void *adv_enable) + * @brief request the local device to enable or disable an advertising set using the advertising sets identified by the Advertising_Handle[i] parameter. + * @param[in] adv_enable - data to be sent is filled in this + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the local device to enable or disable an advertising set using the advertising sets identified by the Advertising_Handle[i] parameter. + */ +int32_t rsi_ble_start_ae_advertising(void *adv_enable) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_ENABLE; + memcpy(&ae_pdu.pdu_type.ae_adv_enable, (rsi_ble_ae_adv_enable_t *)adv_enable, sizeof(rsi_ble_ae_adv_enable_t)); + + //! Send start ae advertise command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_app_adv_set_clear_or_remove(uint8_t type, uint8_t handle) + * @brief request the local device to clear or remove the advertising sets based on the type specified + * @param[in] type - Specifies whether to remove or clear the advertising sets. + * {1} - clear + * {2} - remove + * @param[in] handle - Advertising_Handle - Used to identify an Advertising set. Possible Values : 0x00 to 0xEF + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the local device to clear or remove an advertising set from the controller based on the type specified + */ +int32_t rsi_ble_app_adv_set_clear_or_remove(uint8_t type, uint8_t handle) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_ADV_SET_CLEAR_OR_REMOVE; + ae_pdu.pdu_type.ae_adv_set_clear_or_remove.type = type; + ae_pdu.pdu_type.ae_adv_set_clear_or_remove.adv_handle = handle; + + //! Send adv set (clear/remove) command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_app_set_periodic_ae_params(void *periodic_adv_params) + * @brief request the local device to set periodic advertising params + * @param[in] periodic_adv_params - Parameters for Periodic Advertising to be filled here. + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function is used by the host to set the parameters for periodic advertising + */ +int32_t rsi_ble_app_set_periodic_ae_params(void *periodic_adv_params) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_PERIODIC_ADV_PARAMS; + memcpy(&ae_pdu.pdu_type.ae_periodic_adv_params, + (rsi_ble_ae_periodic_adv_params_t *)periodic_adv_params, + sizeof(rsi_ble_ae_periodic_adv_params_t)); + + //! Send ae periodic adv params set command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_app_set_periodic_ae_enable(uint8_t enable, uint8_t handle) + * @brief request the Controller to enable or disable the periodic advertising + * @param[in] enable - Enable, BIT map for Enable \n + * + * 0 - Enable Periodic Advertising \n + * 1 - Include the ADI field in AUX_SYNC_IND PDUs \n + * + * handle - Advertising_Handle - Used to Identify an Advertsing Set \n + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the Controller to enable or disable the periodic advertising for the advertising set specified by the Advertising_Handle parameter + */ +int32_t rsi_ble_app_set_periodic_ae_enable(uint8_t enable, uint8_t handle) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_PERIODIC_ADV_ENABLE; + ae_pdu.pdu_type.ae_periodic_adv_enable.enable = enable; + ae_pdu.pdu_type.ae_periodic_adv_enable.adv_handle = handle; + + //! Send ae periodic adv enable command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_ae_set_scan_params(void *ae_scan_params) + * @brief sets the extended scan parameters to be used on the advertising physical channels. + * @param[in] ae_scan_params - Extended scan Parameters data would be filled here + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function sets the extended scan parameters to be used on the advertising physical channels. + */ +int32_t rsi_ble_ae_set_scan_params(void *ae_scan_params) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_SCAN_PARAMS; + memcpy(&ae_pdu.pdu_type.ae_scan_params, + (rsi_ble_ae_set_scan_params_t *)ae_scan_params, + sizeof(rsi_ble_ae_set_scan_params_t)); + + //! Send ae set scan params command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_ae_set_scan_enable(void *ae_scan_enable) + * @brief request the local device to enable or disable scanning for both legacy and extended advertising PDUs + * @param[in] ae_scan_enable - Extended Scan Enable command Parameters would be filled here + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function requests the local device to enable or disable scanning for both legacy and extended advertising PDUs + */ +int32_t rsi_ble_ae_set_scan_enable(void *ae_scan_enable) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_SCAN_ENABLE; + memcpy(&ae_pdu.pdu_type.ae_scan_enable, + (rsi_ble_ae_set_scan_enable_t *)ae_scan_enable, + sizeof(rsi_ble_ae_set_scan_enable_t)); + + //! Send start ae scanning command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn rsi_ble_ae_set_periodic_sync + * @brief used to synchronize with a periodic advertising train from an advertiser and begin receiving periodic advertising packets. + * @param[in] type - Specifies whether to create/terminate/cancel the periodic advertising sync \n + * {1} - CREATE_SYNC \n + * {2} - CREATE_SYNC_CANCEL \n + * (3) - TERMINATE_SYNC \n + * @param[in] periodic_sync_data - Periodic Advertising Create Sync Command Parameters filled here \n + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to synchronize with a periodic advertising train from an advertiser and begin receiving periodic advertising packets. It performs action based on the type specified + */ +int32_t rsi_ble_ae_set_periodic_sync(uint8_t type, void *periodic_sync_data) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_SET_AE_PERIODIC_SYNC; + + ae_pdu.pdu_type.ae_periodic_sync.type = type; + + if (type == BLE_AE_PERIODIC_SYNC_CREATE) { + + memcpy(&ae_pdu.pdu_type.ae_periodic_sync.sync_type.create_sync, + (rsi_ble_ae_set_periodic_adv_create_sync_t *)periodic_sync_data, + sizeof(rsi_ble_ae_set_periodic_adv_create_sync_t)); + + LOG_PRINT("size of create struct is %d \n ", sizeof(rsi_ble_ae_set_periodic_adv_create_sync_t)); + } else if (type == BLE_AE_PERIODIC_SYNC_TERMINATE) { + + memcpy(&ae_pdu.pdu_type.ae_periodic_sync.sync_type.terminate_sync, + (rsi_ble_ae_set_periodic_adv_terminate_sync_t *)periodic_sync_data, + sizeof(rsi_ble_ae_set_periodic_adv_terminate_sync_t)); + LOG_PRINT("size of terminate struct is %d \n ", sizeof(rsi_ble_ae_set_periodic_adv_create_sync_t)); + } else if (type == BLE_AE_PERIODIC_SYNC_CREATE_CANCEL) { + //nothing to fo + } + + //! Send periodic sync command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_ae_dev_to_periodic_list(void *dev_to_list) + * @brief used to add,remove or clear the device to the periodic advertiser list + * @param[in] dev_to_list - holds the data of the Device to be added to periodic Advertising list + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to add,remove or clear the device to the periodic advertiser list + */ +int32_t rsi_ble_ae_dev_to_periodic_list(void *dev_to_list) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_AE_DEV_TO_PERIODIC_LIST; + memcpy(&ae_pdu.pdu_type.dev_to_periodic_list, + (rsi_ble_ae_dev_to_periodic_list_t *)dev_to_list, + sizeof(rsi_ble_ae_dev_to_periodic_list_t)); + + //! Send dev to periodic list cmd + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_ae_read_periodic_adv_list_size(uint8_t *resp) + * @brief used to read the periodic advertiser list size + * @param[in] none + * @param[out] resp - stores the value of total number of Periodic Advertiser list entries/ advertinsing list size filled by the controller + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to read the periodic advertiser list size + */ +int32_t rsi_ble_ae_read_periodic_adv_list_size(uint8_t *resp) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_AE_READ_PERIODIC_LIST_SIZE; + //! Send read periodic adv list size cmd + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_extended_connect_with_params(void *ble_extended_conn_params) + * @brief This command is used to create an ACL connection, with the local device in the Central role, to a connectable advertiser. + * @param[in] ble_extended_conn_params, It holds the data of the Parameters required to connect with the peer device. + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to used to create an ACL connection, with the local device in the Central role, to a connectable advertiser. + */ + +int32_t rsi_ble_extended_connect_with_params(void *ble_extended_conn_params) +{ + rsi_ble_ae_pdu_t ae_pdu = { 0 }; + + ae_pdu.cmd_sub_opcode = RSI_BLE_AE_EXTENDED_CREATE_CONNECT; + memcpy(&ae_pdu.pdu_type.extended_create_conn, + (rsi_ble_ae_extended_create_connect_t *)ble_extended_conn_params, + sizeof(rsi_ble_ae_extended_create_connect_t)); + + //! Send start ae scanning command + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_AE, &ae_pdu, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_read_transmit_power(rsi_ble_tx_pwr_t *resp) + * @brief used to read minimum and maximum transmit powers supported by the controller + * @param[in] none + * @param[out] resp - filled by the controller. Controller fills Minimum TX Power and Maximum TX power in this resp + * Min_TX_Power : Units in dBm Ranges from -127 to +20 \n + * Max_TX_Power : Units in dBm Ranges from -127 to +20 \n + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to read minimum and maximum transmit powers supported by the controller + */ + +int32_t rsi_ble_read_transmit_power(void *resp) +{ + //! Send read transmit power cmd + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_READ_TRANSMIT_POWER, NULL, (rsi_ble_tx_pwr_t *)resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_read_rf_path_compensation(rsi_ble_query_rf_path_comp_t *resp) + * @brief used to read rf path compensation value parameters used in the Tx power level and RSSI calculation + * @param[in] none + * @param[out] resp - filled by the controller. Controller fills RF_TX_Path_compensation_Value and RF_RX_Path_compensation_Value \n + * RF_TX_Path_compensation_Value - units in 0.1dB , Range : -128.0 dB (0xFB00) to 128.0 dB (0x0500) \n + * RF_RX_Path_compensation_Value - units in 0.1dB , Range : -128.0 dB (0xFB00) to 128.0 dB (0x0500) \n + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to read rf path compensation value parameters used in the Tx power level and RSSI calculation + * */ +int32_t rsi_ble_read_rf_path_compensation(void *resp) +{ + + //! Send read rf path compensation cmd + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_READ_RF_PATH_COMP, NULL, (rsi_ble_query_rf_path_comp_t *)resp); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_write_rf_path_compensation(uint16_t tx_path_value, uint16_t rx_path_value) + * @brief used to indicate the RF path gain or loss between the RF transceiver and the antenna contributed by intermediate components + * @param[in] tx_path_value - RF_TX_Path_Compensation_Value, rx_path_value - RF_RX_Path_Compensation_Value \n + * A positive value means a net RF path gain and a negative value means a net RF path loss \n + * RF_TX_Path_compensation_Value : units in 0.1dB , Range : -128.0 dB (0xFB00) to 128.0 dB (0x0500) \n + * RF_RX_Path_compensation_Value : units in 0.1dB , Range : -128.0 dB (0xFB00) to 128.0 dB (0x0500) \n + * @return 0 = success \n + * !0 = failure \n + * @section description + * This function used to indicate the RF path gain or loss between the RF transceiver and the antenna contributed by intermediate components. + * */ +int32_t rsi_ble_write_rf_path_compensation(uint16_t tx_path_value, uint16_t rx_path_value) +{ + rsi_ble_write_rf_path_comp_t rf_path_comp = { 0 }; + + rf_path_comp.tx_path_value = tx_path_value; + rf_path_comp.rx_path_value = rx_path_value; + //! Send write rf path compensation cmd + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_WRITE_RF_PATH_COMP, &rf_path_comp, NULL); +} +/** @} */ +#endif diff --git a/wiseconnect/sapi/bluetooth/rsi_ble_gatt_apis.c b/wiseconnect/sapi/bluetooth/rsi_ble_gatt_apis.c new file mode 100644 index 00000000..9fb25b9e --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_ble_gatt_apis.c @@ -0,0 +1,1751 @@ +/******************************************************************************* +* @file rsi_ble_gatt_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +#ifdef RSI_BLE_ENABLE + +#include "rsi_ble.h" +#include "rsi_ble_apis.h" +#include "rsi_ble_config.h" +#include "rsi_bt_common_apis.h" + +// GATT Client Functions +/********************************************************************** + * In all GAT client APIs, all actions (get/set/write) are referred to + * the GATT server running on the remote / connected device. + *********************************************************************/ + +/** @addtogroup BT-LOW-ENERGY4 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_profiles_async(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_profiles_list_t *p_prof_list) + * @brief Get the supported profiles / services of the connected + * remote device asynchronously. \ref rsi_ble_on_event_profiles_list_t callback function will be + * called after the profiles list event is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_profiles_list_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_profile_list - profiles/services information will be filled in this structure after retrieving from the remote device, + please refer rsi_ble_resp_profiles_list_s structure for more info.\n + * @note p_prof_list structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_profiles_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_profiles_list_t *p_prof_list) +{ + rsi_ble_req_profiles_list_t req_profiles; + memset(&req_profiles, 0, sizeof(req_profiles)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_profiles.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_profiles.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_profiles.start_handle = start_handle; + req_profiles.end_handle = end_handle; + + SL_PRINTF(SL_RSI_BLE_GET_PROFILES_HANDLE_ASYNC, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_PROFILES_ASYNC, &req_profiles, p_prof_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_profile_async(uint8_t *dev_addr, uuid_t profile_uuid, + * profile_descriptors_t *p_profile) + * @brief Get the specific profile / service of the connected remote device. + * \ref rsi_ble_one_event_profile_by_uuid_t callback function is called after + * the service characteristics response is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_one_event_profile_by_uuid_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] profile_uuid - services/profiles which are searched using profile_uuid \n + * @param[out] p_profile - profile / service information filled in this structure after retrieving from the remote device, + please refer profile_descriptor_s structure for more info. \n + * @note p_profile structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ +int32_t rsi_ble_get_profile_async(uint8_t *dev_addr, uuid_t profile_uuid, profile_descriptors_t *p_profile) +{ + + SL_PRINTF(SL_RSI_BLE_GET_PROFILES_UUID_ASYNC, BLE, LOG_INFO); + rsi_ble_req_profile_t req_profile; + memset(&req_profile, 0, sizeof(req_profile)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_profile.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_profile.dev_addr, (int8_t *)dev_addr, 6); +#endif + memcpy(&req_profile.profile_uuid, &profile_uuid, sizeof(uuid_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_PROFILE_ASYNC, &req_profile, p_profile); +} +/*==============================================*/ +/** + * @fn rint32_t rsi_ble_get_char_services_async(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_char_services_t *p_char_serv_list) + * @brief Get the service characteristics of the connected / remote device. + * \ref rsi_ble_on_event_read_by_char_services_t callback function is called after + * the included service characteristics response is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_read_by_char_services_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_char_services_list - service characteristics details are filled in this structure, please refer rsi_ble_resp_char_serv_s structure for more info. \n + * @note p_char_services_list structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_char_services_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_char_services_t *p_char_serv_list) +{ + + SL_PRINTF(SL_RSI_BLE_CHAR_SERVICES_ASYNC, BLE, LOG_INFO); + rsi_ble_req_char_services_t req_char_services; + memset(&req_char_services, 0, sizeof(req_char_services)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_char_services.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_char_services.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_char_services.start_handle, start_handle); + rsi_uint16_to_2bytes(req_char_services.end_handle, end_handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_CHARSERVICES_ASYNC, &req_char_services, p_char_serv_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_inc_services_async(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_inc_services_t *p_inc_serv_list) + * @brief Get the supported include services of the connected / remote device. + * \ref rsi_ble_on_event_read_by_inc_services_t callback function is called after + * the service characteristics response is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_read_by_inc_services_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_inc_serv_list - include service characteristics details are filled in this structure, please refer rsi_ble_resp_inc_serv structure for more info.\n + * @note p_inc_serv_list structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_inc_services_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_inc_services_t *p_inc_serv_list) +{ + + SL_PRINTF(SL_RSI_BLE_GET_INC_SERVICES_ASYNC, BLE, LOG_INFO); + rsi_ble_req_inc_services_t req_inc_services; + memset(&req_inc_services, 0, sizeof(req_inc_services)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_inc_services.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_inc_services.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_inc_services.start_handle, start_handle); + rsi_uint16_to_2bytes(req_inc_services.end_handle, end_handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_INCLUDESERVICES_ASYNC, &req_inc_services, p_inc_serv_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_char_value_by_uuid_async(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * uuid_t char_uuid, + * rsi_ble_resp_att_value_t *p_char_val) + * @brief Get the characteristic value by UUID (char_uuid). + * \ref rsi_ble_on_event_read_att_value_t callback function is called + * after the attribute value is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_read_att_value_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[in] char_uuid - UUID of the characteristic + * @param[out] p_char_value - characteristic value is filled in this structure, please refer rsi_ble_resp_att_value_s structure for more info.\n + * @note p_char_value structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_char_value_by_uuid_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + uuid_t char_uuid, + rsi_ble_resp_att_value_t *p_char_val) +{ + + SL_PRINTF(SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_ASYNC, BLE, LOG_INFO); + rsi_ble_req_char_val_by_uuid_t req_char_val; + memset(&req_char_val, 0, sizeof(req_char_val)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_char_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_char_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_char_val.start_handle, start_handle); + rsi_uint16_to_2bytes(req_char_val.end_handle, end_handle); + memcpy(&req_char_val.char_uuid, &char_uuid, sizeof(uuid_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_READCHARVALUEBYUUID_ASYNC, &req_char_val, p_char_val); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_att_descriptors_async(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_att_descs_t *p_att_desc) + * @brief Get the characteristic descriptors list from the remote device. \ref rsi_ble_on_gatt_desc_val_event_t + * callback function is called after the attribute descriptors response is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_gatt_desc_val_event_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_att_desc - pointer to characteristic descriptor structure, Please refer rsi_ble_resp_att_descs_s strcuture for more info.\n + * @note p_att_desc structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_att_descriptors_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_att_descs_t *p_att_desc) +{ + + SL_PRINTF(SL_RSI_BLE_GET_ATT_DESCRIPTORS_ASYNC, BLE, LOG_INFO); + rsi_ble_req_att_descs_t req_att_desc; + memset(&req_att_desc, 0, sizeof(req_att_desc)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_att_desc.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_att_desc.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_att_desc.start_handle, start_handle); + rsi_uint16_to_2bytes(req_att_desc.end_handle, end_handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_ATTRIBUTE_ASYNC, &req_att_desc, p_att_desc); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_att_value_async(uint8_t *dev_addr, uint16_t handle, + * rsi_ble_resp_att_value_t *p_att_val) + * @brief Get the attribute with a handle. + * \ref rsi_ble_on_event_read_resp_t callback function is called upon receiving the attribute value. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_read_resp_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - handle value of the attribute + * @param[out] p_att_val - attribute value is filled in this structure, Please refer rsi_ble_resp_att_value_s structure for more info.\n + * @note p_att_val structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_att_value_async(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_att_value_t *p_att_val) +{ + + SL_PRINTF(SL_RSI_BLE_GET_ATT_VALUE_ASYNC, BLE, LOG_INFO); + rsi_ble_req_att_value_t req_att_val; + memset(&req_att_val, 0, sizeof(req_att_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_att_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_att_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_att_val.handle, handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_DESCRIPTORVALUE_ASYNC, &req_att_val, p_att_val); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_multiple_att_values_async(uint8_t *dev_addr, + * uint8_t num_of_handlers, + * uint16_t *handles, + * rsi_ble_resp_att_value_t *p_att_vals) + * @brief Get the multiple attribute values by using multiple handles. + * \ref rsi_ble_on_event_read_resp_t callback function is called after the attribute value is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_read_resp_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] num_of_handlers - number of handles in the list + * @param[in] handles - list of attribute handles + * @param[out] p_att_vals - attribute values filled in this structure, please refer rsi_ble_resp_att_value_s structure for more info.\n + * @note p_att_vals structure should be passed as NULL because nothing will be filled in this structure \n + + * @return 0 - Success \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_multiple_att_values_async(uint8_t *dev_addr, + uint8_t num_of_handlers, + uint16_t *handles, + rsi_ble_resp_att_value_t *p_att_vals) +{ + + SL_PRINTF(SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC, BLE, LOG_INFO, "NUMBER_OF_HANDLERS: %1x", num_of_handlers); + rsi_ble_req_multi_att_values_t req_att_vals; + memset(&req_att_vals, 0, sizeof(req_att_vals)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_att_vals.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_att_vals.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_att_vals.num_of_handles = RSI_MIN(num_of_handlers, RSI_BLE_MAX_REQ_LIST); + for (ix = 0; ix < req_att_vals.num_of_handles; ix++) { + req_att_vals.handles[ix] = handles[ix]; + } + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_MULTIPLEVALUES_ASYNC, &req_att_vals, p_att_vals); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_long_att_value_async(uint8_t *dev_addr, + * uint16_t handle, + * uint16_t offset, + * rsi_ble_resp_att_value_t *p_att_vals) + * @brief Get the long attribute value by using handle and offset. + * \ref rsi_ble_on_event_read_resp_t callback function is called after the attribute value is received. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_read_resp_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute handle + * @param[in] offset - offset within the attribute value + * @param[out] p_att_vals - attribute value filled in this structure, please refer rsi_ble_resp_att_value_s structure for more info.\n + * @note p_att_vals structure should be passed as NULL because nothing will be filled in this structure \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_long_att_value_async(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + rsi_ble_resp_att_value_t *p_att_vals) +{ + + SL_PRINTF(SL_RSI_BLE_GET_LONG_ATT_VALUE_ASYNC, BLE, LOG_INFO, "HANDLE: %2x, OFFSET: %2x", handle, offset); + rsi_ble_req_long_att_value_t req_long_att_val; + memset(&req_long_att_val, 0, sizeof(req_long_att_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_long_att_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_long_att_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_long_att_val.handle = handle; + req_long_att_val.offset = offset; + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_LONGDESCVALUES_ASYNC, &req_long_att_val, p_att_vals); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, + * uint8_t data_len, uint8_t *p_data) + * @brief Set the attribute value of the remote device. \ref rsi_ble_on_event_write_resp_t + * callback function is called after the attribute set action is completed. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_write_resp_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute value handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_SET_ATT_VALUE_ASYNC, BLE, LOG_INFO, "HANDLE: %2x, DATA_LEN: %1x", handle, data_len); + rsi_ble_set_att_value_t set_att_val; + memset(&set_att_val, 0, sizeof(set_att_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_att_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)set_att_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(set_att_val.handle, handle); + set_att_val.length = RSI_MIN(sizeof(set_att_val.att_value), data_len); + memcpy(set_att_val.att_value, p_data, set_att_val.length); + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_DESCVALUE_ASYNC, &set_att_val, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_prepare_write_async(uint8_t *dev_addr, + * uint16_t handle, + * uint16_t offset, + * uint8_t data_len, + * uint8_t *p_data) + * @brief Prepare the attribute value. \ref rsi_ble_on_event_prepare_write_resp_t + * callback function is called after the prepare attribute write action is completed. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_prepare_write_resp_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute handle + * @param[in] offset - attribute value offset + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_prepare_write_async(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint8_t data_len, + uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_PREPARE_WRITE_ASYNC, + BLE, + LOG_INFO, + "HANDLE: %2x, OFFSET: %2x, DATA_LEN: %1x", + handle, + offset, + data_len); + rsi_ble_req_prepare_write_t req_prepare_write; + memset(&req_prepare_write, 0, sizeof(req_prepare_write)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_prepare_write.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_prepare_write.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_prepare_write.handle, handle); + rsi_uint16_to_2bytes(req_prepare_write.offset, offset); + req_prepare_write.length = RSI_MIN(sizeof(req_prepare_write.att_value), data_len); + memcpy(req_prepare_write.att_value, p_data, req_prepare_write.length); + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_PREPAREWRITE_ASYNC, &req_prepare_write, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_execute_write_async(uint8_t *dev_addr, uint8_t exe_flag) + * @brief Execute the prepared attribute values. \ref rsi_ble_on_event_write_resp_t + * callback function is called after the execute attribute write action is completed. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_write_resp_t or \ref rsi_ble_on_gatt_error_resp_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] exe_flag - execute flag to write, possible values mentioned below\n + 0 - BLE_ATT_EXECUTE_WRITE_CANCEL \n + 1 - BLE_ATT_EXECUTE_PENDING_WRITES_IMMEDIATELY \n + + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D05 - BLE Socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_execute_write_async(uint8_t *dev_addr, uint8_t exe_flag) +{ + SL_PRINTF(SL_RSI_BLE_EXECUTE_WRITE_ASYNC, BLE, LOG_INFO); + rsi_ble_req_execute_write_t req_exe_write; + memset(&req_exe_write, 0, sizeof(req_exe_write)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_exe_write.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_exe_write.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_exe_write.flag = exe_flag; + + return rsi_bt_driver_send_cmd(RSI_BLE_EXECUTE_LONGDESCWRITE_ASYNC, &req_exe_write, NULL); +} + +/** @} */ + +/** @addtogroup BT-LOW-ENERGY3 +* @{ +*/ +/*==============================================*/ +/** + * @fn nt32_t rsi_ble_get_profiles(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_profiles_list_t *p_prof_list) + * @brief Get the supported profiles / services of the connected + * remote device. \ref rsi_ble_on_profiles_list_resp_t callback + * function will be called after the profiles list response is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_profiles_list_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_profile_list - profiles/services information will be filled in this structure after retrieving from the remote device, + please refer rsi_ble_resp_profiles_list_s structure for more info.\n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_profiles(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_profiles_list_t *p_prof_list) +{ + + SL_PRINTF(SL_RSI_BLE_GET_PROFILES, BLE, LOG_INFO); + rsi_ble_req_profiles_list_t req_profiles; + memset(&req_profiles, 0, sizeof(req_profiles)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_profiles.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_profiles.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_profiles.start_handle = start_handle; + req_profiles.end_handle = end_handle; + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_PROFILES, &req_profiles, p_prof_list); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_profile(uint8_t *dev_addr, uuid_t profile_uuid, + * profile_descriptors_t *p_profile) + * @brief Get the specific profile / service of the connected remote device. + * \ref rsi_ble_on_profile_resp_t callback function is called after the service + * characteristics response is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_profile_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] profile_uuid - services/profiles which are searched using profile_uuid \n + * @param[out] p_profile - profile / service information filled in this structure after retrieving from the remote device, + please refer profile_descriptor_s structure for more info. \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_profile(uint8_t *dev_addr, uuid_t profile_uuid, profile_descriptors_t *p_profile) +{ + + SL_PRINTF(SL_RSI_BLE_GET_PROFILE, BLE, LOG_INFO); + rsi_ble_req_profile_t req_profile; + memset(&req_profile, 0, sizeof(req_profile)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_profile.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_profile.dev_addr, (int8_t *)dev_addr, 6); +#endif + memcpy(&req_profile.profile_uuid, &profile_uuid, sizeof(uuid_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_PROFILE, &req_profile, p_profile); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_char_services(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_char_services_t *p_char_serv_list) + * @brief Get the service characteristic services of the connected / remote device. + * \ref rsi_ble_on_char_services_resp_t callback function is called after the characteristic service + * response is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_char_services_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_char_services_list - service characteristics details are filled in this structure, please refer rsi_ble_resp_char_serv_s structure for more info. \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_char_services(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_char_services_t *p_char_serv_list) +{ + + SL_PRINTF(SL_RSI_BLE_GET_CHAR_SERVICES, BLE, LOG_INFO); + rsi_ble_req_char_services_t req_char_services; + memset(&req_char_services, 0, sizeof(req_char_services)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_char_services.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_char_services.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_char_services.start_handle, start_handle); + rsi_uint16_to_2bytes(req_char_services.end_handle, end_handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_CHAR_SERVICES, &req_char_services, p_char_serv_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_inc_services(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_inc_services_t *p_inc_serv_list) + * @brief Get the supported include services of the connected / remote device. + * \ref rsi_ble_on_inc_services_resp_t callback function is called after + * the include service response is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_inc_services_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_inc_serv_list - include service characteristics details are filled in this structure, please refer rsi_ble_resp_inc_serv structure for more info.\n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_inc_services(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_inc_services_t *p_inc_serv_list) +{ + + SL_PRINTF(SL_RSI_BLE_GET_INC_SERVICES, BLE, LOG_INFO); + rsi_ble_req_inc_services_t req_inc_services; + memset(&req_inc_services, 0, sizeof(req_inc_services)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_inc_services.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_inc_services.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_inc_services.start_handle, start_handle); + rsi_uint16_to_2bytes(req_inc_services.end_handle, end_handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_INC_SERVICES, &req_inc_services, p_inc_serv_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_char_value_by_uuid(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * uuid_t char_uuid, + * rsi_ble_resp_att_value_t *p_char_val) + * @brief Get the characteristic value by UUID (char_uuid). + * \ref rsi_ble_on_read_resp_t callback function is called after the attribute value is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_read_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[in] char_uuid - UUID of the characteristic + * @param[out] p_char_value - characteristic value is filled in this structure, please refer rsi_ble_resp_att_value_s structure for more info.\n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If the return value is less than 0 \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_char_value_by_uuid(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + uuid_t char_uuid, + rsi_ble_resp_att_value_t *p_char_val) +{ + + SL_PRINTF(SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID, BLE, LOG_INFO); + rsi_ble_req_char_val_by_uuid_t req_char_val; + memset(&req_char_val, 0, sizeof(req_char_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_char_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_char_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + + rsi_uint16_to_2bytes(req_char_val.start_handle, start_handle); + rsi_uint16_to_2bytes(req_char_val.end_handle, end_handle); + memcpy(&req_char_val.char_uuid, &char_uuid, sizeof(uuid_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_READ_BY_UUID, &req_char_val, p_char_val); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_att_descriptors(uint8_t *dev_addr, + * uint16_t start_handle, + * uint16_t end_handle, + * rsi_ble_resp_att_descs_t *p_att_desc) + * @brief Get the characteristic descriptors list from the remote device. + * \ref rsi_ble_on_att_desc_resp_t callback function is called after + * the attribute descriptors response is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_att_desc_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] start_handle - start handle (index) of the remote device's service records + * @param[in] end_handle - end handle (index) of the remote device's service records + * @param[out] p_att_desc - pointer to characteristic descriptor structure, Please refer rsi_ble_resp_att_descs_s strcuture for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_att_descriptors(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_att_descs_t *p_att_desc) +{ + + SL_PRINTF(SL_RSI_BLE_GET_ATT_DESCRIPTORS, BLE, LOG_INFO); + rsi_ble_req_att_descs_t req_att_desc; + memset(&req_att_desc, 0, sizeof(req_att_desc)); + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_att_desc.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_att_desc.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_att_desc.start_handle, start_handle); + rsi_uint16_to_2bytes(req_att_desc.end_handle, end_handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_DESC, &req_att_desc, p_att_desc); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_att_value(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_att_value_t *p_att_val) + * @brief Get the attribute by handle. + * \ref rsi_ble_on_read_resp_t callback function is called upon receiving the attribute value. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_read_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - handle value of the attribute + * @param[out] p_att_val - attribute value is filled in this structure, Please refer rsi_ble_resp_att_value_s structure for more info.\n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_att_value(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_att_value_t *p_att_val) +{ + + SL_PRINTF(SL_RSI_BLE_GET_ATT_VALUE, BLE, LOG_INFO); + rsi_ble_req_att_value_t req_att_val; + memset(&req_att_val, 0, sizeof(req_att_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_att_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_att_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_att_val.handle, handle); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_READ_VAL, &req_att_val, p_att_val); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_multiple_att_values(uint8_t *dev_addr, + * uint8_t num_of_handlers, + * uint16_t *handles, + * rsi_ble_resp_att_value_t *p_att_vals) + * @brief Get the multiple attribute values by using multiple handles. + * \ref rsi_ble_on_read_resp_t callback function is called after the attribute value is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_read_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] num_of_handlers - number of handles in the list + * @param[in] handles - list of attribute handles + * @param[out] p_att_vals - attribute values filled in this structure, please refer rsi_ble_resp_att_value_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_multiple_att_values(uint8_t *dev_addr, + uint8_t num_of_handlers, + uint16_t *handles, + rsi_ble_resp_att_value_t *p_att_vals) +{ + SL_PRINTF(SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES, BLE, LOG_INFO, "NUMBER_OF_HANDLERS: %1x", num_of_handlers); + rsi_ble_req_multi_att_values_t req_att_vals; + memset(&req_att_vals, 0, sizeof(req_att_vals)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_att_vals.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_att_vals.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_att_vals.num_of_handles = RSI_MIN(num_of_handlers, RSI_BLE_MAX_REQ_LIST); + for (ix = 0; ix < req_att_vals.num_of_handles; ix++) { + req_att_vals.handles[ix] = handles[ix]; + } + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_MULTIPLE_READ, &req_att_vals, p_att_vals); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_long_att_value(uint8_t *dev_addr, + * uint16_t handle, + * uint16_t offset, + * rsi_ble_resp_att_value_t *p_att_vals) + * @brief Get the long attribute value by using handle and offset. + * \ref rsi_ble_on_read_resp_t callback function is called after the attribute value is received. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_read_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute handle + * @param[in] offset - offset within the attribute value + * @param[out] p_att_vals - attribute value filled in this structure, please refer rsi_ble_resp_att_value_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_get_long_att_value(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + rsi_ble_resp_att_value_t *p_att_vals) +{ + + SL_PRINTF(SL_RSI_BLE_GET_LONG_ATT_VALUE, BLE, LOG_INFO, "HANDLES: %2x, OFFSET: %2x", handle, offset); + rsi_ble_req_long_att_value_t req_long_att_val; + memset(&req_long_att_val, 0, sizeof(req_long_att_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_long_att_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_long_att_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_long_att_val.handle = handle; + req_long_att_val.offset = offset; + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_LONG_READ, &req_long_att_val, p_att_vals); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, + * uint8_t data_len, uint8_t *p_data) + * @brief Set the attribute value of the remote device. + * \ref rsi_ble_on_write_resp_t callback function is called if the attribute set action is completed. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_write_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute value handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_SET_ATT_VALUE, BLE, LOG_INFO); + rsi_ble_set_att_value_t set_att_val; + memset(&set_att_val, 0, sizeof(set_att_val)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_att_val.dev_addr, dev_addr); +#else + memcpy((uint8_t *)set_att_val.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(set_att_val.handle, handle); + set_att_val.length = RSI_MIN(sizeof(set_att_val.att_value), data_len); + memcpy(set_att_val.att_value, p_data, set_att_val.length); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_WRITE, &set_att_val, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, + * uint8_t data_len, uint8_t *p_data) + * @brief Set the attribute value without waiting for an ACK from the remote device. This is a Blocking API. + * If the API returns RSI_ERROR_BLE_DEV_BUF_FULL (-31) error then wait untill the \ref rsi_ble_on_le_more_data_req_t event gets received from the module. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute value handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E60 - Invalid Handle range \n + * 0x4E62 - Invalid Parameters \n + * 0x4D04 - BLE not connected \n + * 0x4D05 - BLE Socket not available \n + * 0x4E65 - Invalid Attribute Length When Small Buffer Mode is Configured \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_SET_ATT_COMMAND, BLE, LOG_INFO, "HANDLE: %2x, DATA_LEN: %1x", handle, data_len); + rsi_ble_set_att_cmd_t set_att_cmd; + memset(&set_att_cmd, 0, sizeof(set_att_cmd)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_att_cmd.dev_addr, dev_addr); +#else + memcpy((uint8_t *)set_att_cmd.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(set_att_cmd.handle, handle); + set_att_cmd.length = RSI_MIN(sizeof(set_att_cmd.att_value), data_len); + memcpy(set_att_cmd.att_value, p_data, set_att_cmd.length); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_WRITE_NO_ACK, &set_att_cmd, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, + * uint16_t handle, + * uint16_t offset, + * uint8_t data_len, + * uint8_t *p_data) + * @brief Set the long attribute value of the remote device. \ref rsi_ble_on_write_resp_t + * callback function is called after the attribute set action is completed. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_write_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute handle + * @param[in] offset - attribute value offset + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint8_t data_len, + uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_SET_LONG_ATT_VALUE, + BLE, + LOG_INFO, + "HANDLE: %2x, DATA_LEN: %1x, OFFSET: %2x", + handle, + data_len, + offset); + rsi_ble_set_long_att_value_t set_long_att; + memset(&set_long_att, 0, sizeof(set_long_att)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_long_att.dev_addr, dev_addr); +#else + memcpy((uint8_t *)set_long_att.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(set_long_att.handle, handle); + rsi_uint16_to_2bytes(set_long_att.offset, offset); + set_long_att.length = RSI_MIN(sizeof(set_long_att.att_value), data_len); + memcpy(set_long_att.att_value, p_data, set_long_att.length); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_LONG_WRITE, &set_long_att, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_prepare_write(uint8_t *dev_addr, uint16_t handle, uint16_t offset, + * uint8_t data_len, uint8_t *p_data) + * @brief Prepare the attribute value. \ref rsi_ble_on_write_resp_t + * callback function is called after the prepare attribute write action is completed. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_write_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute handle + * @param[in] offset - attribute value offset + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_prepare_write(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, uint8_t *p_data) +{ + SL_PRINTF(SL_RSI_BLE_PREPARE_WRITE, + BLE, + LOG_INFO, + "HANDLE: %2x, DATA_LEN: %1x, OFFSET: %2x", + handle, + data_len, + offset); + rsi_ble_req_prepare_write_t req_prepare_write; + memset(&req_prepare_write, 0, sizeof(req_prepare_write)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_prepare_write.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_prepare_write.dev_addr, (int8_t *)dev_addr, 6); +#endif + rsi_uint16_to_2bytes(req_prepare_write.handle, handle); + rsi_uint16_to_2bytes(req_prepare_write.offset, offset); + req_prepare_write.length = RSI_MIN(sizeof(req_prepare_write.att_value), data_len); + memcpy(req_prepare_write.att_value, p_data, req_prepare_write.length); + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_PREPARE_WRITE, &req_prepare_write, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_execute_write(uint8_t *dev_addr, uint8_t exe_flag) + * @brief Execute the prepared attribute values. \ref rsi_ble_on_write_resp_t + * callback function is called after the execute attribute write action is completed. This is a non-blocking API, + * Still user need to wait untill the callback \ref rsi_ble_on_write_resp_t is received from the device, + * to initiate further attribute related transactions on this remote device address. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] exe_flag - execute flag to write, possible values mentioned below\n + 0 - BLE_ATT_EXECUTE_WRITE_CANCEL \n + 1 - BLE_ATT_EXECUTE_PENDING_WRITES_IMMEDIATELY \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_execute_write(uint8_t *dev_addr, uint8_t exe_flag) +{ + + SL_PRINTF(SL_RSI_BLE_EXECUTABLE_WRITE, BLE, LOG_INFO); + rsi_ble_req_execute_write_t req_exe_write; + memset(&req_exe_write, 0, sizeof(req_exe_write)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(req_exe_write.dev_addr, dev_addr); +#else + memcpy((uint8_t *)req_exe_write.dev_addr, (int8_t *)dev_addr, 6); +#endif + req_exe_write.flag = exe_flag; + + return rsi_bt_driver_send_cmd(RSI_BLE_REQ_EXECUTE_WRITE, &req_exe_write, NULL); +} + +/** @} */ + +/** @addtogroup BT-LOW-ENERGY5 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_add_service(uuid_t service_uuid, rsi_ble_resp_add_serv_t *p_resp_serv) + * @brief Add a new service to the local GATT Server. This is a Blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] service_uuid - new service UUID value, please refer uuid_s structure for more info. + * @param[out] p_resp_serv - new service handler filled in this structure, please refer rsi_ble_resp_add_serv_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - Invalid Arguments \n + * 0x4D08 - Profile record full \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_add_service(uuid_t service_uuid, rsi_ble_resp_add_serv_t *p_resp_serv) +{ + + SL_PRINTF(SL_RSI_BLE_ADD_SERVICE, BLE, LOG_INFO); + rsi_ble_req_add_serv_t new_service; + memset(&new_service, 0, sizeof(new_service)); + + memcpy(&new_service.service_uuid, &service_uuid, sizeof(uuid_t)); + + return rsi_bt_driver_send_cmd(RSI_BLE_ADD_SERVICE, &new_service, p_resp_serv); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_add_attribute(rsi_ble_req_add_att_t *p_attribute) + * @brief Add a new attribute to a specific service. This is a Blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] p_attribute - add a new attribute to the service, please refer rsi_ble_req_add_att_s structure for more info. \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - Invalid Arguments \n + * 0x4D09 - Attribute record full \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ + +int32_t rsi_ble_add_attribute(rsi_ble_req_add_att_t *p_attribute) +{ + + SL_PRINTF(SL_RSI_BLE_ADD_ATTRIBUTE, BLE, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BLE_ADD_ATTRIBUTE, p_attribute, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, + * uint8_t *p_data) + * @brief Change the local attribute value. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] handle - attribute value handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - Invalid Arguments \n + * 0x4D06 - Attribute record not found \n + * 0x4E60 - Invalid Handle Range \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + * @note This API can only be used if the service is maintained inside the firmware. \n + * The services which are maintained by firmware must follow the below rules. \n + * Rule 1: The attribute_data_size is less than 20 bytes during the service_creation \n + * Rule 2: while creating the service, don't use the RSI_BLE_ATT_MAINTAIN_IN_HOST bit \n + * in the RSI_BLE_ATT_CONFIG_BITMAP macro. \n + * Rule 3: The data_len must be less than or equal to the dat_length mentioned while \n + * creating the service/attribute \n + * Rule 4: If the services are maintained in the Application/Host,\n + * then need to use \ref rsi_ble_notify_value() API to send the notifications to the remote devices.\n + */ + +int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_SET_LOCAL_ATT_VALUE, BLE, LOG_INFO, "HANDLE: %2x", handle); + rsi_ble_set_local_att_value_t rec_data = { 0 }; + + rec_data.handle = handle; + rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + memcpy(rec_data.data, p_data, rec_data.data_len); + + return rsi_bt_driver_send_cmd(RSI_BLE_SET_LOCAL_ATT_VALUE, &rec_data, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, + * uint8_t buf_cnt) + * @brief Configure the buf mode for Notify and WO response commands for the remote device. This is a Blocking API. + * @param[in] dev_addr - remote device address + * @param[in] buf_mode - buffer mode configuration\n + 0 - BLE_SMALL_BUFF_MODE \n + 1 - BLE_BIG_BUFF_MODE \n + * @param[in] buf_count - no of buffers to be configured \n + only value 1 and 2 are supporetd in BLE_SMALL_BUFF_MODE \n + + in BLE_BIG_BUFF_MODE, buffers allocated based on the below notations. + intial available_buf_cnt = RSI_BLE_NUM_CONN_EVENTS, + a) When connection 1 is formed, the possible range of buffers is (available_buf_cnt - remaining possible no.connections) + b) After allocating X buffers using \ref rsi_ble_set_wo_resp_notify_buf_info to the 1st connection remaiining available_buf_cnt = (available_buf_cnt - X ) \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4046 - Invalid Arguments \n + * 0x4D05 - BLE socket not available \n + * 0x4D06 - Attribute record not found \n + * 0x4E60 - Invalid Handle Range \n + * 0x4E63 - BLE Buffer Count Exceeded \n + * 0x4E64 - BLE Buffer already in use \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ +int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, uint8_t buf_cnt) +{ + + SL_PRINTF(SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO, BLE, LOG_INFO, "BUF_MODE: %1x, BUF_COUNT: %1x", buf_mode, buf_cnt); + rsi_ble_set_wo_resp_notify_buf_info_t buf_info = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(buf_info.dev_addr, dev_addr); +#else + memcpy(buf_info.dev_addr, dev_addr, RSI_DEV_ADDR_LEN); +#endif + buf_info.buf_mode = buf_mode; + buf_info.buf_count = buf_cnt; + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_SET_WWO_RESP_NOTIFY_BUF_INFO, &buf_info, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, + * uint16_t data_len, uint8_t *p_data) + * @brief Notify the local value to the remote device. This is a Blocking API. + * If the API returns RSI_ERROR_BLE_DEV_BUF_FULL (-31) error then wait untill the \ref rsi_ble_on_le_more_data_req_t event gets received from the module. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - local attribute handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - Invalid Arguments \n + * 0x4A0D - Invalid attribute value length \n + * 0x4D05 - BLE socket not available \n + * 0x4D06 - Attribute record not found \n + * 0x4E60 - Invalid Handle Range \n + * 0x4E65 - Invalid Attribute Length When Small Buffer Mode is Configured \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + * + * @note If the services are maintained in the Application/Host,\n + * then need to use \ref rsi_ble_notify_value() API instead of using \ref rsi_ble_set_local_att_value() API\n + * to send the notifications to the remote devices. + */ +int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_NOTIFY_VALUE_TRIGGER, BLE, LOG_INFO, "HANDLE: %2x", handle); + rsi_ble_notify_att_value_t rec_data; + memset(&rec_data, 0, sizeof(rec_data)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(rec_data.dev_addr, dev_addr); +#else + memcpy(rec_data.dev_addr, dev_addr, 6); +#endif + + rec_data.handle = handle; + rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + memcpy(rec_data.data, p_data, rec_data.data_len); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_NOTIFY, &rec_data, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, + * uint16_t data_len, uint8_t *p_data) + * @brief Indicate the local value to the remote device. This is a blocking API and can unblock the application + * on the reception of the callback functions either \ref rsi_ble_on_event_indicate_confirmation_t. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - local attribute handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D05 - BLE socket not available \n + * 0x4E60 - Invalid Handle Range \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + * + */ + +int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_INDICATE_VOLUME_TRIGGER, BLE, LOG_INFO); + rsi_ble_notify_att_value_t rec_data; + memset(&rec_data, 0, sizeof(rec_data)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(rec_data.dev_addr, dev_addr); +#else + memcpy(rec_data.dev_addr, dev_addr, 6); +#endif + + rec_data.handle = handle; + rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + memcpy(rec_data.data, p_data, rec_data.data_len); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_INDICATE, &rec_data, NULL); +} +/** @} */ +/** @addtogroup BT-LOW-ENERGY4 + * * @{ */ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, + * uint16_t data_len, uint8_t *p_data) + * @brief Indicate the local value to the remote device. This is a blocking API. \n + * This will not send any confirmation event to the application instead \n + * send the status as success on receiving confirmation from remote side. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - local attribute handle + * @param[in] data_len - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D05 - BLE socket not available \n + * 0x4E60 - Invalid Handle Range \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + * + */ + +int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_INDICATE_VALUE_SYNC, BLE, LOG_INFO); + rsi_ble_notify_att_value_t rec_data; + memset(&rec_data, 0, sizeof(rec_data)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(rec_data.dev_addr, dev_addr); +#else + memcpy(rec_data.dev_addr, dev_addr, 6); +#endif + + rec_data.handle = handle; + rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + memcpy(rec_data.data, p_data, rec_data.data_len); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_INDICATE_SYNC, &rec_data, NULL); +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY4 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_ble_indicate_confirm(uint8_t *dev_addr) + * @brief Send indicate confirmation to the remote device. This is a blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4D05 - BLE socket not available \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + * + */ +int32_t rsi_ble_indicate_confirm(uint8_t *dev_addr) +{ + + SL_PRINTF(SL_RSI_BLE_INDICATE_CONFIRM, BLE, LOG_INFO); + rsi_ble_indicate_confirm_t rec_data = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(rec_data.dev_addr, dev_addr); +#else + memcpy(rec_data.dev_addr, dev_addr, 6); +#endif + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_INDICATE_CONFIRMATION, &rec_data, NULL); +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY5 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_get_local_att_value(uint16_t handle, + * rsi_ble_resp_local_att_value_t *p_resp_local_att_val) + * @brief Get the local attribute value. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] handle - local attribute handle + * @param[out] p_resp_local_att_val - local attribute value filled in this structure, plase refer rsi_ble_resp_local_att_value_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - Invalid Arguments \n + * 0x4D06 - Attribute record not found \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + * @note This API can only be used if the service is maintained inside the firmware. The services which are maintained by firmware must + * follow the below rules.\n + * Rule 1: The attribute_data_size is less than 20 bytes during the service_creation \n + * Rule 2: While creating the service, don't use the RSI_BLE_ATT_MAINTAIN_IN_HOST bit in the RSI_BLE_ATT_CONFIG_BITMAP macro. + * + */ +int32_t rsi_ble_get_local_att_value(uint16_t handle, rsi_ble_resp_local_att_value_t *p_resp_local_att_val) +{ + + SL_PRINTF(SL_RSI_BLE_GET_LOCAL_ATT_VALUE, BLE, LOG_INFO); + rsi_ble_get_local_att_value_t local_read_val = { 0 }; + + local_read_val.handle = handle; + + return rsi_bt_driver_send_cmd(RSI_BLE_GET_LOCAL_ATT_VALUE, &local_read_val, p_resp_local_att_val); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_gatt_read_response(uint8_t *dev_addr, + * uint8_t read_type, + * uint16_t handle, + * uint16_t offset, + * uint16_t length, + * uint8_t *p_data) + * @brief Send the response for the read request received from the remote device. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device Address + * @param[in] read_type - read value type \n + 0 - Read response \n + 1 - Read blob response + * @param[in] handle - attribute value handle + * @param[in] offset - attribute value offset + * @param[in] length - attribute value length + * @param[in] p_data - attribute value + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D04 - BLE not connected \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_gatt_read_response(uint8_t *dev_addr, + uint8_t read_type, + uint16_t handle, + uint16_t offset, + uint16_t length, + uint8_t *p_data) +{ + + SL_PRINTF(SL_RSI_BLE_GATT_READ_RESPONSE, BLE, LOG_INFO); + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(offset); + UNUSED_PARAMETER(handle); + rsi_ble_gatt_read_response_t local_read_blob_resp; + memset(&local_read_blob_resp, 0, sizeof(local_read_blob_resp)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(local_read_blob_resp.dev_addr, dev_addr); +#else + memcpy((uint8_t *)local_read_blob_resp.dev_addr, (int8_t *)dev_addr, 6); +#endif + local_read_blob_resp.type = read_type; + local_read_blob_resp.data_len = RSI_MIN(length, sizeof(local_read_blob_resp.data)); + memcpy(local_read_blob_resp.data, p_data, local_read_blob_resp.data_len); //local_read_blob_resp.data_len); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_READ_RESP, &local_read_blob_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_remove_gatt_service(uint32_t service_handler) + * @brief Remove the GATT service record. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] service_handle - GATT service record handle + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D0A - BLE profile not found (profile handler invalid) \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_remove_gatt_service(uint32_t service_handler) +{ + + SL_PRINTF(SL_RSI_BLE_REMOVE_GATT_SERVICE, BLE, LOG_INFO, "SERVICE_HANDLER: %4x", service_handler); + rsi_ble_gatt_remove_serv_t rem_serv; + + rem_serv.serv_hndler = service_handler; + + return rsi_bt_driver_send_cmd(RSI_BLE_RSP_REMOVE_SERVICE, &rem_serv, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_remove_gatt_attibute(uint32_t service_handler, uint16_t att_hndl) + * @brief Remove the GATT attribute record. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] service_handle - GATT service record handle + * @param[in] att_hndl - attribute handle + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4D06 - Attribute record not found \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_remove_gatt_attibute(uint32_t service_handler, uint16_t att_hndl) +{ + + SL_PRINTF(SL_RSI_BLE_REMOVE_GATT_ATTRIBUTE, + BLE, + LOG_INFO, + "SERVICE_HANDLER: %4x, ATT_HANDLE: %2x", + service_handler, + att_hndl); + rsi_ble_gatt_remove_att_t rem_att; + + rem_att.serv_hndler = service_handler; + rem_att.att_hndl = att_hndl; + + return rsi_bt_driver_send_cmd(RSI_BLE_RSP_REMOVE_ATTRIBUTE, &rem_att, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_att_error_response(uint8_t *dev_addr, uint16_t handle, + * uint8_t opcode, uint8_t err) + * @brief Send attribute error response for any of the att request. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute handle + * @param[in] opcode - error response opcode + * @param[in] error_code - specific error related Gatt + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4D04 - BLE not Connected \n + * 0x4E62 - Invalid Parameters \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_att_error_response(uint8_t *dev_addr, uint16_t handle, uint8_t opcode, uint8_t err) +{ + + SL_PRINTF(SL_RSI_BLE_ATT_ERROR_RESPONSE, BLE, LOG_INFO, "HANDLE: %2x", handle); + rsi_ble_att_error_response_t att_error = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_error.dev_addr, dev_addr); +#else + memcpy((uint8_t *)att_error.dev_addr, (int8_t *)dev_addr, 6); +#endif + + att_error.att_handle = handle; + att_error.req_opcode = opcode; + att_error.err_code = err; + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_ATT_ERROR, &att_error, NULL); +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY3 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_mtu_exchange_event(uint8_t *dev_addr, uint8_t mtu_size) + * @brief Initiates the MTU exchange request with the remote device. \n + * This is a Blocking API and will recive a callback event \ref rsi_ble_on_mtu_event_t as the response for this API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] mtu_size - requested MTU value + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4D04 - BLE not Connected \n + * 0x4E62 - Invalid Parameters \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_mtu_exchange_event(uint8_t *dev_addr, uint8_t mtu_size) +{ + + SL_PRINTF(SL_RSI_BLE_MTU_EXCHANGE_EVENT, BLE, LOG_INFO); + rsi_ble_mtu_exchange_t mtu_req; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(mtu_req.dev_addr, dev_addr); +#else + memcpy((uint8_t *)mtu_req.dev_addr, (int8_t *)dev_addr, 6); +#endif + mtu_req.req_mtu_size = mtu_size; + + return rsi_bt_driver_send_cmd(RSI_BLE_MTU_EXCHANGE_REQUEST, &mtu_req, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_ble_mtu_exchange_resp(uint8_t *dev_addr, uint8_t mtu_size) + * @brief This function (Exchange MTU Response) is sent in reply to a received Exchange MTU Request. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - Remote Device Address + * @param[in] mtu_size - requested MTU value + * @return 0 - Success \n + * 0x4D0C - When RSI_BLE_MTU_EXCHANGE_FROM_HOST BIT is not SET. + * 0x4D05 - BLE Socket Not Available. + * Non-Zero Value - Failure + * Refer Error Codes section for above error codes \ref error-codes + * + */ +int32_t rsi_ble_mtu_exchange_resp(uint8_t *dev_addr, uint8_t mtu_size) +{ + rsi_ble_mtu_exchange_resp_t mtu_resp; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(mtu_resp.dev_addr, dev_addr); +#else + memcpy((uint8_t *)mtu_resp.dev_addr, (int8_t *)dev_addr, 6); +#endif + mtu_resp.req_mtu_size = mtu_size; + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_MTU_EXCHANGE_RESP, &mtu_resp, NULL); +} + +/** @} */ + +/** @addtogroup BT-LOW-ENERGY5 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_gatt_write_response(uint8_t *dev_addr, uint8_t type) + * @brief Send the response to the write request received from the remote device. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] type - response type \n + 0 - write response, \n + 1 - execute write response. + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4046 - Invalid Arguments \n + * 0x4D04 - BLE not Connected \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_gatt_write_response(uint8_t *dev_addr, uint8_t type) +{ + + SL_PRINTF(SL_RSI_BLE_GATT_WRITE_RESPONSE, BLE, LOG_INFO); + rsi_ble_gatt_write_response_t local_write_resp; + memset(&local_write_resp, 0, sizeof(local_write_resp)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(local_write_resp.dev_addr, dev_addr); +#else + memcpy((uint8_t *)local_write_resp.dev_addr, (int8_t *)dev_addr, 6); +#endif + local_write_resp.type = type; + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_WRITE_RESP, &local_write_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_gatt_prepare_write_response(uint8_t *dev_addr, + * uint16_t handle, + * uint16_t offset, + * uint16_t length, + * uint8_t *data) + * @brief Send the response for the prepare write requests received from the remote device. This is a Blocking API. + * @pre \ref rsi_ble_connect() API needs to be called before this API. + * @param[in] dev_addr - remote device address + * @param[in] handle - attribute value handle + * @param[in] offset - attribute value offset + * @param[in] data_len - attribute value length + * @param[in] data - attribite value + * @return 0 - Success \n + * Non-Zero Value - Failure + * 0x4046 - Invalid Arguments \n + * 0x4D04 - BLE not Connected \n + * @note Refer Error Codes section for above error codes \ref error-codes \n + */ +int32_t rsi_ble_gatt_prepare_write_response(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint16_t length, + uint8_t *data) +{ + + SL_PRINTF(SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE, + BLE, + LOG_INFO, + "HANDLE: %2x, LENGTH: %2x, OFFSET: %2x", + handle, + length, + offset); + rsi_ble_gatt_prepare_write_response_t local_prepare_write_resp; + memset(&local_prepare_write_resp, 0, sizeof(local_prepare_write_resp)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(local_prepare_write_resp.dev_addr, dev_addr); +#else + memcpy((uint8_t *)local_prepare_write_resp.dev_addr, (int8_t *)dev_addr, 6); +#endif + local_prepare_write_resp.handle = handle; + local_prepare_write_resp.offset = offset; + local_prepare_write_resp.data_len = length; + + memcpy(local_prepare_write_resp.data, data, length); + + return rsi_bt_driver_send_cmd(RSI_BLE_CMD_PREPARE_WRITE_RESP, &local_prepare_write_resp, NULL); +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/bluetooth/rsi_bt_a2dp_apis.c b/wiseconnect/sapi/bluetooth/rsi_bt_a2dp_apis.c new file mode 100644 index 00000000..49a17d0f --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_bt_a2dp_apis.c @@ -0,0 +1,402 @@ +/******************************************************************************* +* @file rsi_bt_a2dp_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +#ifdef RSI_BT_ENABLE + +#include "rsi_bt.h" +#include "rsi_bt_apis.h" +#include "rsi_bt_config.h" +#include "rsi_bt_sbc_codec.h" + +/** @addtogroup BT-CLASSIC1 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_init(rsi_bt_a2dp_sbc_codec_cap_t *sbc_cap) + * @brief Initialize A2DP Profile with either user-defined audio codec params or default stack audio codec params. This is a blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] sbc_cap - audio codec params structure, please refer \ref rsi_bt_a2dp_sbc_codec_cap_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note if NULL is passed, A2DP profile initialize with default audio codec params. + */ +int32_t rsi_bt_a2dp_init(rsi_bt_a2dp_sbc_codec_cap_t *sbc_cap) +{ + rsi_bt_req_profile_mode_t bt_req_a2dp_init = { 0 }; + bt_req_a2dp_init.profile_mode = RSI_A2DP_PROFILE_BIT; + if (sbc_cap != NULL) { + bt_req_a2dp_init.data_len = sizeof(rsi_bt_a2dp_sbc_codec_cap_t); + memcpy(&bt_req_a2dp_init.data, sbc_cap, sizeof(rsi_bt_a2dp_sbc_codec_cap_t)); + } + SL_PRINTF(SL_RSI_BT_A2DP_INIT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_PROFILE_MODE, &bt_req_a2dp_init, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_connect(uint8_t *remote_dev_addr) + * @brief Initiate the A2DP connection. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_connect_t indicates that the a2dp connection response. + * @pre Call \ref rsi_bt_a2dp_init() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4511 RSI_APP_ERR_A2DP_CONN_ALRDY_EXISTS + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_connect(uint8_t *remote_dev_addr) +{ + rsi_bt_req_a2dp_connect_t bt_req_a2dp_connect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_connect.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_connect.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_A2DP_CONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_CONNECT, &bt_req_a2dp_connect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_disconnect(uint8_t *remote_dev_addr) + * @brief Use to disconnect A2DP. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_disconnect_t indicates that the a2dp disconnection response. + * @pre Call \ref rsi_bt_a2dp_init() and \ref rsi_bt_a2dp_connect() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_a2dp_disconnect(uint8_t *remote_dev_addr) +{ + rsi_bt_req_a2dp_disconnect_t bt_req_a2dp_disconnect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_disconnect.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_disconnect.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_A2DP_DISCONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_DISCONNECT, &bt_req_a2dp_disconnect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_send_pcm_mp3_data(uint8_t *remote_dev_addr, + * uint8_t *pcm_mp3_data, + * uint16_t pcm_mp3_data_len, + * uint8_t audio_type) + * @brief Send the PCM data to the BT stack. This is a blocking API. + * if returns RSI_APP_ERR_HW_BUFFER_OVERFLOW err means that the firmware buffers are full and + * eventually host will receive a event \ref rsi_bt_on_a2dp_data_req_t which requests more data from application. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP start is completed. + * @param[in] remote_dev_addr - remote device address + * @param[in] pcm_mp3_data - PCM data buffer. + * @param[in] pcm_mp3_data_len - PCM data length. + * @param[in] audio_type - audio type. \n + 0 - Reserved \n + 1 - PCM Audio \n + 2 - SBC Audio \n + 3 - MP3 Audio + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4512 RSI_APP_ERR_A2DP_NOT_STREAMING \n + * 0x4049 RSI_APP_ERR_A2DP_INVALID_SOCKET \n + * 0x4057 RSI_APP_ERR_HW_BUFFER_OVERFLOW + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ + +#if (!TA_BASED_ENCODER) +int32_t rsi_bt_a2dp_send_pcm_mp3_data(uint8_t *remote_dev_addr, + uint8_t *pcm_mp3_data, + uint16_t pcm_mp3_data_len, + uint8_t audio_type, + uint16_t *bytes_consumed) +#else +int32_t rsi_bt_a2dp_send_pcm_mp3_data(uint8_t *remote_dev_addr, + uint8_t *pcm_mp3_data, + uint16_t pcm_mp3_data_len, + uint8_t audio_type) +#endif +{ +#if (!TA_BASED_ENCODER) + /*These statement are added only to resolve compilation warning, value is unchanged*/ + UNUSED_PARAMETER(bytes_consumed); + UNUSED_PARAMETER(audio_type); + USED_PARAMETER(remote_dev_addr); + USED_PARAMETER(pcm_mp3_data); + USED_PARAMETER(pcm_mp3_data_len); +#endif + +#if (TA_BASED_ENCODER) + rsi_bt_req_a2dp_pcm_mp3_data_t bt_req_a2dp_pcm_mp3_pkt_part1 = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_pcm_mp3_pkt_part1.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_pcm_mp3_pkt_part1.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_req_a2dp_pcm_mp3_pkt_part1.pcm_mp3_data_len = + RSI_MIN(sizeof(bt_req_a2dp_pcm_mp3_pkt_part1.pcm_mp3_data), pcm_mp3_data_len); + bt_req_a2dp_pcm_mp3_pkt_part1.audio_type = audio_type; + memcpy(bt_req_a2dp_pcm_mp3_pkt_part1.pcm_mp3_data, pcm_mp3_data, bt_req_a2dp_pcm_mp3_pkt_part1.pcm_mp3_data_len); + + rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1, &bt_req_a2dp_pcm_mp3_pkt_part1, NULL); + + rsi_bt_req_a2dp_pcm_mp3_data_t bt_req_a2dp_pcm_mp3_pkt_part2 = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_pcm_mp3_pkt_part2.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_pcm_mp3_pkt_part2.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_req_a2dp_pcm_mp3_pkt_part2.pcm_mp3_data_len = + RSI_MIN(sizeof(bt_req_a2dp_pcm_mp3_pkt_part2.pcm_mp3_data), pcm_mp3_data_len); + bt_req_a2dp_pcm_mp3_pkt_part2.audio_type = audio_type; + memcpy(bt_req_a2dp_pcm_mp3_pkt_part2.pcm_mp3_data, + (pcm_mp3_data + sizeof(bt_req_a2dp_pcm_mp3_pkt_part1.pcm_mp3_data)), + bt_req_a2dp_pcm_mp3_pkt_part2.pcm_mp3_data_len); + + SL_PRINTF(SL_RSI_BT_A2DP_SEND_PCM_MP3_DATA_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_PCM_MP3_DATA, &bt_req_a2dp_pcm_mp3_pkt_part2, NULL); +#endif + return RSI_SUCCESS; // This is added to remove the compilation warning +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_send_sbc_aac_data(uint8_t *remote_dev_addr, + * uint8_t *sbc_aac_data, + * uint16_t sbc_aac_data_len, + * uint8_t audio_type) + * @brief Send the SBC/AAC data to the BT stack. This is a blocking API. + * if returns RSI_APP_ERR_HW_BUFFER_OVERFLOW err means that the firmware buffers are full and + * eventually host will receive a event \ref rsi_bt_on_a2dp_data_req_t which requests more data from application. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP start is completed. + * @param[in] remote_dev_addr - remote device address + * @param[in] sbc_aac_data - SBC/AAC data buffer. + * @param[in] sbc_aac_data_len - SBC/AAC data length. + * @param[in] audio_type - audio type. \n + 0 - Reserved \n + 1 - PCM Audio \n + 2 - SBC Audio \n + 3 - MP3 Audio + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4512 RSI_APP_ERR_A2DP_NOT_STREAMING \n + * 0x4049 RSI_APP_ERR_A2DP_INVALID_SOCKET \n + * 0x4057 RSI_APP_ERR_HW_BUFFER_OVERFLOW \n + * 0x405D RSI_APP_ERR_HW_BUFFER_OVERFLOW_TIMEOUT + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_send_sbc_aac_data(uint8_t *remote_dev_addr, + uint8_t *sbc_aac_data, + uint16_t sbc_aac_data_len, + uint8_t audio_type) +{ + rsi_bt_req_a2dp_sbc_aac_data_t bt_req_a2dp_sbc_aac_pkt; + memset(&bt_req_a2dp_sbc_aac_pkt, 0, sizeof(bt_req_a2dp_sbc_aac_pkt)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_sbc_aac_pkt.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_sbc_aac_pkt.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_req_a2dp_sbc_aac_pkt.sbc_aac_data_len = RSI_MIN(sizeof(bt_req_a2dp_sbc_aac_pkt.sbc_aac_data), sbc_aac_data_len); + bt_req_a2dp_sbc_aac_pkt.audio_type = audio_type; + memcpy(bt_req_a2dp_sbc_aac_pkt.sbc_aac_data, sbc_aac_data, bt_req_a2dp_sbc_aac_pkt.sbc_aac_data_len); + + SL_PRINTF(SL_RSI_BT_A2DP_SEND_SBC_AAC_DATA_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_SBC_AAC_DATA, &bt_req_a2dp_sbc_aac_pkt, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_start(uint8_t *remote_dev_addr) + * @brief Send the A2DP start to the BT stack to start the stream procedure. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_start_t indicates that the a2dp start response. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP Open is completed. + * @param[in] remote_dev_addr - remote device address. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_start(uint8_t *remote_dev_addr) +{ + rsi_bt_req_a2dp_start_t bt_req_a2dp_start = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_start.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_start.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + + SL_PRINTF(SL_RSI_BT_A2DP_START, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_START, &bt_req_a2dp_start, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_suspend(uint8_t *remote_dev_addr) + * @brief Send the A2DP suspend to the BT stack. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_suspend_t indicates that the a2dp suspend response. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP start is completed. + * @param[in] remote_dev_addr - remote device address. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_suspend(uint8_t *remote_dev_addr) +{ + rsi_bt_req_a2dp_suspend_t bt_req_a2dp_suspend = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_suspend.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_suspend.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_A2DP_SUSPEND, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_SUSPEND, &bt_req_a2dp_suspend, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_close(uint8_t *remote_dev_addr) + * @brief Send the A2DP close to the BT stack for removing the a2dp stream. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_close_t indicates that the a2dp close response. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP start is completed. + * @param[in] remote_dev_addr - remote device address. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_close(uint8_t *remote_dev_addr) +{ + rsi_bt_req_a2dp_close_t bt_req_a2dp_close = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_close.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_close.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_A2DP_CLOSE, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_CLOSE, &bt_req_a2dp_close, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_abort(uint8_t *remote_dev_addr) + * @brief Send the A2DP abort to the BT stack for aborting the exsting a2dp link. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_abort_t indicates that the a2dp abort response. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP start is completed. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_abort(uint8_t *remote_dev_addr) +{ + rsi_bt_req_a2dp_abort_t bt_req_a2dp_abort = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_abort.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_abort.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_A2DP_ABORT, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_ABORT, &bt_req_a2dp_abort, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_get_config(uint8_t *remote_dev_addr, + * rsi_bt_resp_a2dp_get_config_t *sbc_resp_cap) + * @brief To get remote device CODEC configuration. This is a blocking API.\n + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[out] sbc_resp_cap - get audio codec params response from stack, please refer \ref rsi_bt_resp_a2dp_get_config_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_get_config(uint8_t *remote_dev_addr, rsi_bt_resp_a2dp_get_config_t *sbc_resp_cap) +{ + rsi_bt_req_a2dp_get_config_t bt_req_a2dp_get_config = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_a2dp_get_config.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_a2dp_get_config.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_A2DP_GET_CONFIG, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_GET_CONFIG, &bt_req_a2dp_get_config, sbc_resp_cap); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_a2dp_set_config(uint8_t *remote_dev_addr, + * rsi_bt_a2dp_sbc_codec_cap_t *set_sbc_cap, + * int32_t *status) + * @brief Set A2DP CODEC configuration. Used for A2DP Reconfig purposes. This is a blocking API. + * A received event \ref rsi_bt_on_a2dp_reconfig_t indicates that the a2dp reconfig response. + * @pre Call \ref rsi_bt_a2dp_init() and rsi_bt_a2dp_connect() before calling this API. \n + * Call this API only after A2DP Open is completed. + * @param[in] remote_dev_addr - remote device address + * @param[in] set_sbc_cap - new SBC codec params used for reconfig, please refer \ref rsi_bt_a2dp_sbc_codec_cap_s structure for more info. + * @param[in] status - This is the response status. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4513 RSI_APP_ERR_A2DP_SBC_SAME_CODEC_PARAMS \n + * 0x4514 RSI_APP_ERR_A2DP_RECONFIG_CMD_TIMEOUT + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_a2dp_set_config(uint8_t *remote_dev_addr, rsi_bt_a2dp_sbc_codec_cap_t *set_sbc_cap, int32_t *status) +{ + rsi_bt_req_a2dp_set_config_t bt_a2dp_set_config; + memset(&bt_a2dp_set_config, 0, sizeof(bt_a2dp_set_config)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_a2dp_set_config.dev_addr, remote_dev_addr); +#else + memcpy(bt_a2dp_set_config.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + memcpy(&bt_a2dp_set_config.sbc_cap, set_sbc_cap, sizeof(rsi_bt_a2dp_sbc_codec_cap_t)); + SL_PRINTF(SL_RSI_BT_A2DP_SET_CONFIG, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_A2DP_SET_CONFIG, &bt_a2dp_set_config, status); +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/bluetooth/rsi_bt_avrcp_apis.c b/wiseconnect/sapi/bluetooth/rsi_bt_avrcp_apis.c new file mode 100644 index 00000000..3f8f89a6 --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_bt_avrcp_apis.c @@ -0,0 +1,1340 @@ +/******************************************************************************* +* @file rsi_bt_avrcp_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +#ifdef RSI_BT_ENABLE + +#include "rsi_bt.h" +#include "rsi_bt_apis.h" +#include "rsi_bt_config.h" +/** @addtogroup BT-CLASSIC2 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_init(uint8_t *avrcp_feature) + * @brief Set the AVRCP profile mode and also enables the Media Player Selection + * Feature, if required. This is a blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] avrcp_feature - used for enabling avrcp features \n + NULL - Default features used \n + 1 - MediaPlayerSelection Feature Enable + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note if NULL is passed, AVRCP profile initialize with default stack features. + **/ +int32_t rsi_bt_avrcp_init(uint8_t *avrcp_feature) +{ + rsi_bt_req_profile_mode_t bt_req_avrcp_init = { 0 }; + bt_req_avrcp_init.profile_mode = RSI_AVRCP_PROFILE_BIT; + if (avrcp_feature != NULL) { + bt_req_avrcp_init.data_len = 1; + bt_req_avrcp_init.data[0] = *avrcp_feature; + } + + SL_PRINTF(SL_RSI_BT_AVRCP_INIT, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_PROFILE_MODE, &bt_req_avrcp_init, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_conn(uint8_t *remote_dev_addr) + * @brief Initiate avrcp connection This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_connect_t indicates that the avrcp connection response. + * @pre Call \ref rsi_bt_avrcp_init() before calling this API. Call this API after BT PHY level conn is completed. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4540 ERR_BT_AVRCP_NOT_INITIALISED + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note If A2DP Profile is Initialized, then before calling this API the a2dp connection should be established using this \ref rsi_bt_a2dp_conn() API and once \n + * \ref rsi_bt_on_a2dp_open_t callback is received start the streaming using \ref rsi_bt_stream_start() API. \n + * This is applicable for all AVRCP related API's. + */ +int32_t rsi_bt_avrcp_conn(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_conn_t bt_req_avrcp_connect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_connect.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_connect.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + + SL_PRINTF(SL_RSI_BT_AVRCP_CONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_CONNECT, &bt_req_avrcp_connect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_disconn(uint8_t *remote_dev_addr) + * @brief Initiate avrcp disconnection. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_disconnect_t indicates that the avrcp disconnection response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_disconn(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_disconnect_t bt_req_avrcp_disconnect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_disconnect.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_disconnect.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_DISCONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_DISCONNECT, &bt_req_avrcp_disconnect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_play(uint8_t *remote_dev_addr) + * @brief To play a track, call this API. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_play_t indicates that the avrcp play(Button Pressed/Button Released) response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_play(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_play_t bt_req_avrcp_play = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_play.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_play.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_PLAY_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_PLAY, &bt_req_avrcp_play, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_pause(uint8_t *remote_dev_addr) + * @brief To Pause a track, call this API. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_pause_t indicates that the avrcp pause(Button Pressed/Button Released) response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_pause(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_pause_t bt_req_avrcp_pause = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_pause.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_pause.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_PAUSE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_PAUSE, &bt_req_avrcp_pause, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_stop(uint8_t *remote_dev_addr) + * @brief To Stop a track, call this API. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_stop(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_stop_t bt_req_avrcp_stop = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_stop.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_stop.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_STOP_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_STOP, &bt_req_avrcp_stop, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_next(uint8_t *remote_dev_addr) + * @brief To Play the next track, call this API. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_next_t indicates that the avrcp next(Button Pressed/Button Released) response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_next(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_next_t bt_req_avrcp_next = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_next.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_next.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_NEXT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_NEXT, &bt_req_avrcp_next, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_previous(uint8_t *remote_dev_addr) + * @brief To move to previous track, call this API. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_previous_t indicates that the avrcp previous(Button Pressed/Button Released) response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_previous(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_previous_t bt_req_avrcp_previous = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_previous.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_previous.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_PREV_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_PREVIOUS, &bt_req_avrcp_previous, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_vol_up(uint8_t *remote_dev_addr) + * @brief To Increase the volume of a track, call this API. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_vol_up_t indicates that the avrcp volume(Button Pressed/Button Released) response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_vol_up(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_vol_up_t bt_req_avrcp_vol_up = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_vol_up.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_vol_up.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_VOL_UP_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_VOL_UP, &bt_req_avrcp_vol_up, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_vol_down(uint8_t *remote_dev_addr) + * @brief To Decrease the volume a track, call this API. This is a blocking API. + * A received event \ref rsi_bt_on_avrcp_vol_down_t indicates that the avrcp volume(Button Pressed/Button Released) response. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_vol_down(uint8_t *remote_dev_addr) +{ + rsi_bt_req_avrcp_vol_down_t bt_req_avrcp_vol_down = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_vol_down.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_vol_down.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_AVRCP_VOL_DOWN_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_VOL_DOWN, &bt_req_avrcp_vol_down, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_capabilities(uint8_t *remote_dev_addr, + * uint8_t capability_type, + * rsi_bt_rsp_avrcp_get_capabilities_t *cap_list) + * @brief Gets the capabilities supported by remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] capability_type - capability type (either 2 or 3) \n + * 2 - Company ID \n + * 3 - Events Supported + * @param[out] cap_list - get remote capability list. Please refer \ref rsi_bt_rsp_avrcp_get_capabilities_s \n + * structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_get_capabilities(uint8_t *remote_dev_addr, + uint8_t capability_type, + rsi_bt_rsp_avrcp_get_capabilities_t *cap_list) +{ + rsi_bt_req_avrcp_get_capabilities_t bt_req_avrcp_cap; + memset(&bt_req_avrcp_cap, 0, sizeof(bt_req_avrcp_cap)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_cap.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_cap.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_req_avrcp_cap.type = capability_type; + + SL_PRINTF(SL_RSI_BT_AVRCP_GET_CAPABILITES_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_CAPABILITES, &bt_req_avrcp_cap, cap_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_att_list(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_get_atts_list_t *att_list) + * @brief Requests the TG to provide target supported player application setting attributes. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[out] att_list - attribute list, Please refer \ref rsi_bt_rsp_avrcp_get_atts_list_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_att_list(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_get_atts_list_t *att_list) +{ + rsi_bt_req_avrcp_get_att_list_t bt_req_avrcp_att = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_avrcp_att.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_avrcp_att.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_GET_ATT_LIST_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_ATTS_LIST, &bt_req_avrcp_att, att_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_att_vals_list(uint8_t *remote_dev_addr, + * uint8_t att_id, + * rsi_bt_rsp_avrcp_get_att_vals_list_t *att_vals_list) + * @brief Requests the TG to list the set of possible values for the requested player application setting attribute. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] att_id - attribute ID + * @param[out] att_vals_list - attribute value list, Please refer \ref rsi_bt_rsp_avrcp_get_att_vals_list_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_att_vals_list(uint8_t *remote_dev_addr, + uint8_t att_id, + rsi_bt_rsp_avrcp_get_att_vals_list_t *att_vals_list) +{ + rsi_bt_req_avrcp_get_att_vals_list_t avrcp_att_vals; + memset(&avrcp_att_vals, 0, sizeof(avrcp_att_vals)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(avrcp_att_vals.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(avrcp_att_vals.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + avrcp_att_vals.att_id = att_id; + + SL_PRINTF(SL_RSI_BT_GET_ATT_VALS_LIST_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_ATT_VALS_LIST, &avrcp_att_vals, att_vals_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_cur_att_val(uint8_t *remote_dev_addr, + uint8_t *att_list, + uint8_t nbr_atts, + rsi_bt_rsp_avrcp_get_cur_att_val_t *att_vals_list) + * @brief Requests the TG to provide the current set values on the target + * for the provided player application setting attributes list. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] att_list - attribute ID + * @param[in] nbr_atts - number of attributes + * @param[out] att_vals_list - attribute value list, Please refer \ref rsi_bt_rsp_avrcp_get_cur_att_val_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_cur_att_val(uint8_t *remote_dev_addr, + uint8_t *att_list, + uint8_t nbr_atts, + rsi_bt_rsp_avrcp_get_cur_att_val_t *att_vals_list) +{ + rsi_bt_req_avrcp_get_cur_att_val_t avrcp_atts; + memset(&avrcp_atts, 0, sizeof(avrcp_atts)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(avrcp_atts.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(avrcp_atts.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + avrcp_atts.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < RSI_MAX_ATT); ix++) { + avrcp_atts.att_list[ix] = att_list[ix]; + } + SL_PRINTF(SL_RSI_BT_GET_CURR_ATT_VAL_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_CUR_ATT_VAL, &avrcp_atts, att_vals_list); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_set_cur_att_val(uint8_t *remote_dev_addr, + * att_val_t *val_list, uint8_t nbr_atts) + * @brief requests to set the player application setting list of player + * application setting values on the TG for the corresponding defined + * list of PlayerApplicationSettingAttributes. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] val_list - value list + * @param[in] nbr_atts - number of attributes + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_set_cur_att_val(uint8_t *remote_dev_addr, att_val_t *val_list, uint8_t nbr_atts) +{ + rsi_bt_req_avrcp_set_cur_att_val_t att_val_list; + memset(&att_val_list, 0, sizeof(att_val_list)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_val_list.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_val_list.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_val_list.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < RSI_MAX_ATT); ix++) { + att_val_list.att_val_list[ix].att_id = val_list[ix].att_id; + att_val_list.att_val_list[ix].att_id = val_list[ix].att_val; + } + + SL_PRINTF(SL_RSI_BT_SET_CURR_ATT_VAL_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_SET_CUR_ATT_VAL, &att_val_list, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_element_att(uint8_t *remote_dev_addr, + * uint8_t *att_ids, + * uint8_t nbr_atts, + * rsi_bt_rsp_avrcp_elem_attr_t *att_vals) + * @brief Requests the TG to provide the attributes of the element specified in the parameter. + * This shall only be used to retrieve Metadata for the currently playing track from the + * Addressed Player on the Control channel when GetItemAttributes is not supported. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - Address of remote device + * @param[in] att_ids - attributes ids + * @param[in] nbr_atts - number of attributes + * @param[out] att_vals - attribute values in the list. Please refer \ref rsi_bt_rsp_avrcp_elem_attr_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_element_att(uint8_t *remote_dev_addr, + uint8_t *att_ids, + uint8_t nbr_atts, + rsi_bt_rsp_avrcp_elem_attr_t *att_vals) +{ + rsi_bt_req_avrcp_get_ele_att_t att_list; + memset(&att_list, 0, sizeof(att_list)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_list.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_list.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_list.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < RSI_MAX_ATT); ix++) { + att_list.att_list[ix] = att_ids[ix]; + } + + SL_PRINTF(SL_RSI_BT_GET_ELEM_ATT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_ELEMENT_ATT, &att_list, att_vals); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_play_status(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_get_player_status_t *play_status) + * @brief CT to get the status of the currently playing media at the TG. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[out] play_status - to capture the player status \n + * Please refer \ref rsi_bt_rsp_avrcp_get_player_status_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_play_status(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_get_player_status_t *play_status) +{ + rsi_bt_req_avrcp_get_player_status_t play_status_req = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(play_status_req.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(play_status_req.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_GET_PLAY_STATUS_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_PLAY_STATUS, &play_status_req, play_status); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_reg_notification(uint8_t *remote_dev_addr, uint8_t event_id, uint8_t *p_resp_val) + * @brief Registers with the TG to receive notifications asynchronously based on specific events occurring. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] event_id - event ID. + * @param[out] p_resp_val - used to capture response for the event which is registered. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_reg_notification(uint8_t *remote_dev_addr, uint8_t event_id, uint8_t *p_resp_val) +{ +#ifdef BD_ADDR_IN_ASCII + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(p_resp_val); +#endif + rsi_bt_req_avrcp_reg_notification_t reg_notify_req; + memset(®_notify_req, 0, sizeof(reg_notify_req)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(reg_notify_req.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(reg_notify_req.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + reg_notify_req.event_id = event_id; + SL_PRINTF(SL_RSI_BT_REG_NOTIFICATION_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_REG_NOTIFICATION, ®_notify_req, p_resp_val); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_remote_version(uint8_t *remote_dev_addr, + * rsi_bt_rsp_avrcp_remote_version_t *version) + * @brief Get the AVRCP profile version from remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[out] version - version info. Please refer \ref rsi_bt_rsp_avrcp_remote_version_s structure for more info + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_get_remote_version(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_remote_version_t *version) +{ + rsi_bt_req_avrcp_remote_version_t profile_version = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(profile_version.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(profile_version.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_GET_REMOTE_VERSION_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_REMOTE_VERSION, &profile_version, version); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_att_text(uint8_t *remote_dev_addr, + * uint8_t nbr_atts, + * uint8_t *p_atts, + * player_att_text_t *p_att_text_resp) + * @brief Requests the TG to provide supported player application + * setting attribute displayable text for the provided PlayerApplicationSettingAttributeID. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_atts - number of attributes. + * @param[in] p_atts - pointer to attributes. + * @param[out] p_att_text_resp - to capture response from this API. \n + * Please refer \ref player_att_text_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_att_text(uint8_t *remote_dev_addr, + uint8_t nbr_atts, + uint8_t *p_atts, + player_att_text_t *p_att_text_resp) +{ + rsi_bt_req_avrcp_get_cur_att_val_t att_text; + memset(&att_text, 0, sizeof(att_text)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_text.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_text.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_text.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < RSI_MAX_ATT); ix++) { + att_text.att_list[ix] = p_atts[ix]; + } + SL_PRINTF(SL_RSI_BT_GET_ATT_TEXT_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_ATT_TEXT, &att_text, p_att_text_resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_att_val_text(uint8_t *remote_dev_addr, + uint8_t att_id, + uint8_t nbr_vals, + uint8_t *p_vals, + player_att_text_t *p_att_text_resp) + * @brief Get the AVRCP profile player attribute values text from remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] att_id - attribute ID. + * @param[in] nbr_vals - number of attribute values. + * @param[in] p_vals - pointer to attribute values. + * @param[out] p_att_text_resp - to capture response from this API. \n + * Please refer \ref player_att_text_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_get_att_val_text(uint8_t *remote_dev_addr, + uint8_t att_id, + uint8_t nbr_vals, + uint8_t *p_vals, + player_att_text_t *p_att_text_resp) +{ + rsi_bt_req_avrcp_get_att_val_text_t att_val_text; + memset(&att_val_text, 0, sizeof(att_val_text)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_val_text.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_val_text.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_val_text.att_id = att_id; + att_val_text.nbr_vals = nbr_vals; + for (ix = 0; (ix < nbr_vals) && (ix < RSI_MAX_ATT); ix++) { + att_val_text.vals[ix] = p_vals[ix]; + } + SL_PRINTF(SL_RSI_BT_AVRCP_GET_ATT_VAL_TEXT_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_ATT_VALS_TEXT, &att_val_text, p_att_text_resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_batt_status(uint8_t *remote_dev_addr, uint8_t batt_level) + * @brief Send the device battery status to remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] batt_level - to update battery level. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_batt_status(uint8_t *remote_dev_addr, uint8_t batt_level) +{ + rsi_bt_req_avrcp_batt_status_t batt_status; + memset(&batt_status, 0, sizeof(batt_status)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(batt_status.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(batt_status.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + batt_status.batt_status = batt_level; + + SL_PRINTF(SL_RSI_BT_AVRCP_BATT_STATUS_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_BATTERY_STATUS, &batt_status, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_supp_char_sets(uint8_t *remote_dev_addr, uint8_t nbr_sets, uint16_t *p_sets) + * @brief Provides the list of character sets supported by CT to the TG. This shall allow the TG to + * send responses with strings in any of the character sets supported by CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_sets - Number of displayable character sets provided + * @param[in] p_sets - Supported Character Set + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_supp_char_sets(uint8_t *remote_dev_addr, uint8_t nbr_sets, uint16_t *p_sets) +{ + rsi_bt_req_avrcp_char_sets_t char_sets; + memset(&char_sets, 0, sizeof(char_sets)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(char_sets.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(char_sets.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + char_sets.char_sets.nbr_sets = nbr_sets; + for (ix = 0; (ix < nbr_sets) && (ix < MAX_SUPP_VALS); ix++) { + char_sets.char_sets.supp_vals[ix] = p_sets[ix]; + } + + SL_PRINTF(SL_RSI_BT_AVRCP_SUPP_CHAR_SETS_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_CHAR_SETS, &char_sets, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_set_abs_vol(uint8_t *remote_dev_addr, uint8_t abs_vol, uint8_t *p_resp_abs_vol) + * @brief Send absolute volume information to remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] abs_vol - absolute volume. + * @param[out] p_resp_abs_vol - to capture the response from this API. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_set_abs_vol(uint8_t *remote_dev_addr, uint8_t abs_vol, uint8_t *p_resp_abs_vol) +{ + rsi_bt_avrcp_set_abs_vol_t abs_vol_req; + memset(&abs_vol_req, 0, sizeof(abs_vol_req)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(abs_vol_req.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(abs_vol_req.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + abs_vol_req.abs_vol = abs_vol; + + SL_PRINTF(SL_RSI_BT_AVRCP_SEND_ABS_VOLUME_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_SET_ABS_VOL, &abs_vol_req, p_resp_abs_vol); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_cap_resp(uint8_t *remote_dev_addr, uint8_t cap_type, uint8_t nbr_caps, uint32_t *p_caps) + * @brief Sends the device capabilites Supported by TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] cap_type - capability type. + * @param[in] nbr_caps - number of capabilities + * @param[in] p_caps - capability ID's list. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_cap_resp(uint8_t *remote_dev_addr, uint8_t cap_type, uint8_t nbr_caps, uint32_t *p_caps) +{ + rsi_bt_avrcp_cap_resp_t cap_resp; + memset(&cap_resp, 0, sizeof(cap_resp)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(cap_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(cap_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + cap_resp.cap_type = cap_type; + cap_resp.nbr_caps = nbr_caps; + for (ix = 0; (ix < nbr_caps) && (ix < MAX_CAPS); ix++) { + cap_resp.caps[ix] = p_caps[ix]; + } + + SL_PRINTF(SL_RSI_BT_SEND_DEVICE_CAPABILITES_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_CAPABILITES_RESP, &cap_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_att_list_resp(uint8_t *remote_dev_addr, + * uint8_t nbr_atts, uint8_t *p_atts) + * @brief Sends the supported attribute lists from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_atts - number of attributes. + * @param[in] p_atts - pointer to attributes list. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_att_list_resp(uint8_t *remote_dev_addr, uint8_t nbr_atts, uint8_t *p_atts) +{ + rsi_bt_avrcp_att_list_resp_t att_resp; + memset(&att_resp, 0, sizeof(att_resp)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_resp.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < MAX_CAPS); ix++) { + att_resp.atts[ix] = p_atts[ix]; + } + + SL_PRINTF(SL_RSI_BT_AVRCP_ATT_LIST_RESP_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_ATTS_LIST_RESP, &att_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_att_val_list_resp(uint8_t *remote_dev_addr, + * uint8_t nbr_vals, uint8_t *p_vals) + * @brief Sends the attributes value list response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_vals - number of values. + * @param[in] p_vals - pointer to values list. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_att_val_list_resp(uint8_t *remote_dev_addr, uint8_t nbr_vals, uint8_t *p_vals) +{ + rsi_bt_avrcp_att_vals_list_resp_t att_vals_resp; + memset(&att_vals_resp, 0, sizeof(att_vals_resp)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_vals_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_vals_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_vals_resp.nbr_vals = nbr_vals; + for (ix = 0; (ix < nbr_vals) && (ix < MAX_CAPS); ix++) { + att_vals_resp.vals[ix] = p_vals[ix]; + } + + SL_PRINTF(SL_RSI_BT_AVRCP_ATT_VAL_LIST_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_ATT_VALS_LIST_RESP, &att_vals_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_cur_att_val_resp(uint8_t *remote_dev_addr, + * uint8_t nbr_atts, att_val_t *p_att_vals) + * @brief Sends the current attributes values from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_atts - number of attributes. + * @param[in] p_att_vals - pointer to attributes values list. + * Please refer \ref attr_list_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_cur_att_val_resp(uint8_t *remote_dev_addr, uint8_t nbr_atts, att_val_t *p_att_vals) +{ + rsi_bt_avrcp_cur_att_vals_resp_t att_vals_resp; + memset(&att_vals_resp, 0, sizeof(att_vals_resp)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_vals_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_vals_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_vals_resp.att_list.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < MAX_ATT_VALS); ix++) { + att_vals_resp.att_list.att_vals[ix].att_id = p_att_vals[ix].att_id; + att_vals_resp.att_list.att_vals[ix].att_val = p_att_vals[ix].att_val; + } + SL_PRINTF(SL_RSI_BT_AVRCP_CURR_ATT_VAL_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_CUR_ATT_VAL_RESP, &att_vals_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_set_cur_att_val_resp(uint8_t *remote_dev_addr, uint8_t status) + * @brief Sends the current attributes value status response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] status - status to be sent. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_set_cur_att_val_resp(uint8_t *remote_dev_addr, uint8_t status) +{ + rsi_bt_avrcp_set_att_vals_resp_t set_att_vals_resp; + memset(&set_att_vals_resp, 0, sizeof(set_att_vals_resp)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_att_vals_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(set_att_vals_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + set_att_vals_resp.status = status; + + SL_PRINTF(SL_RSI_BT_AVRCP_SET_CURR_ATT_VAL_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_SET_CUR_ATT_VAL_RESP, &set_att_vals_resp, NULL); +} + +#define BT_AVRCP_UTF_8_CHAR_SET 0x006A + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_ele_att_resp(uint8_t *remote_dev_addr, + * uint8_t num_attrs, attr_list_t *p_attr_list) + * @brief Sends the Current Playing Track attributes from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] num_attrs - number of attributes. + * @param[in] p_attr_list - pointer to attributes list. Please refer \ref attr_list_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_ele_att_resp(uint8_t *remote_dev_addr, uint8_t num_attrs, attr_list_t *p_attr_list) +{ + uint8_t ix; + rsi_bt_avrcp_elem_attr_resp_t elem_attr; + memset(&elem_attr, 0, sizeof(elem_attr)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(elem_attr.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(elem_attr.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + elem_attr.elem_attr_list.num_attrs = num_attrs; + for (ix = 0; (ix < num_attrs) && (ix < MAX_ATT_LIST); ix++) { + elem_attr.elem_attr_list.attr_list[ix].id = p_attr_list[ix].id; + elem_attr.elem_attr_list.attr_list[ix].char_set_id = BT_AVRCP_UTF_8_CHAR_SET; + elem_attr.elem_attr_list.attr_list[ix].attr_len = p_attr_list[ix].attr_len; + memcpy(elem_attr.elem_attr_list.attr_list[ix].attr_val, p_attr_list[ix].attr_val, p_attr_list[ix].attr_len); + } + + SL_PRINTF(SL_RSI_BT_AVRCP_ELE_ATT_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_ELEMENT_ATT_RESP, &elem_attr, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_play_status_resp(uint8_t *remote_dev_addr, + * uint8_t play_status, + * uint32_t song_len, + * uint32_t song_pos) + * @brief Sends the Current Playing Track status from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] play_status - player status. + * @param[in] song_len - song length. + * @param[in] song_pos - song position. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_play_status_resp(uint8_t *remote_dev_addr, + uint8_t play_status, + uint32_t song_len, + uint32_t song_pos) +{ + rsi_bt_avrcp_play_status_resp_t player_status; + memset(&player_status, 0, sizeof(player_status)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(player_status.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(player_status.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + player_status.play_status = play_status; + player_status.song_len = song_len; + player_status.song_pos = song_pos; + + SL_PRINTF(SL_RSI_BT_AVRCP_PLAY_STATUS_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_PLAY_STATUS_RESP, &player_status, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_reg_notify_resp(uint8_t *remote_dev_addr, + * uint8_t event_id, + * uint8_t event_data_len, + * uint8_t *event_data) + * @brief Register notify Interim response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] event_id - event ID. + * @param[in] event_data_len - length of event_data buffer. + * @param[in] event_data - event data. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_reg_notify_resp(uint8_t *remote_dev_addr, + uint8_t event_id, + uint8_t event_data_len, + uint8_t *event_data) +{ + rsi_bt_avrcp_reg_notify_interim_resp_t reg_event; + memset(®_event, 0, sizeof(reg_event)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(reg_event.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(reg_event.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + reg_event.event_id = event_id; + + if (event_id == 0x02 /* EVENT_TRACK_CHANGED */) + memcpy(reg_event.reg_notify_val.curr_track_idx, event_data, event_data_len); + else if (event_id == 0x0d /* EVENT_VOL_CHANGED */) + memcpy(®_event.reg_notify_val.abs_vol, event_data, event_data_len); + else if (event_id == 0x01 /* AVRCP_EVENT_PLAYBACK_STATUS_CHANGED */) + memcpy(®_event.reg_notify_val.play_status, event_data, event_data_len); + else if (event_id == 0x0b) { + reg_event.reg_notify_val.playerid = event_data[0] << 8; + reg_event.reg_notify_val.playerid += event_data[1]; + reg_event.reg_notify_val.uidcounter = event_data[2] << 8; + reg_event.reg_notify_val.uidcounter += event_data[3]; + } else { + } + + SL_PRINTF(SL_RSI_BT_AVRCP_REG_NOTIFY_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_REG_NOTIFICATION_RESP, ®_event, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_att_text_resp(uint8_t *remote_dev_addr, + * uint8_t nbr_atts, att_text_t *p_att_text) + * @brief Send supporting attribute text response to remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_atts - number of attributes. + * @param[in] p_att_text - pointer to attribute text. \n + * Please refer \ref att_text_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_att_text_resp(uint8_t *remote_dev_addr, uint8_t nbr_atts, att_text_t *p_att_text) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_ATT_TEXT_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + rsi_bt_avrcp_att_text_resp_t att_text; + memset(&att_text, 0, sizeof(att_text)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(att_text.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(att_text.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + att_text.atts_text.nbr_atts = nbr_atts; + for (ix = 0; (ix < nbr_atts) && (ix < MAX_TEXT_LIST); ix++) { + att_text.atts_text.list[ix].id = p_att_text[ix].id; + memcpy(att_text.atts_text.list[ix].att_text, p_att_text[ix].att_text, strlen((char *)p_att_text[ix].att_text)); + } + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_ATT_TEXT_RESP, &att_text, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_att_vals_text_resp(uint8_t *remote_dev_addr, + * uint8_t nbr_vals, att_text_t *p_vals_text) + * @brief Send supporting attribute values text response to remote device. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] nbr_vals - number of values. + * @param[in] p_vals_text - pointer to values list. \n + * Please refer \ref att_text_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_avrcp_att_vals_text_resp(uint8_t *remote_dev_addr, uint8_t nbr_vals, att_text_t *p_vals_text) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_ATT_VALS_TEXT_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO); + rsi_bt_avrcp_att_text_resp_t vals_text; + memset(&vals_text, 0, sizeof(vals_text)); + uint8_t ix; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(vals_text.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(vals_text.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + vals_text.atts_text.nbr_atts = nbr_vals; + for (ix = 0; (ix < nbr_vals) && (ix < MAX_TEXT_LIST); ix++) { + vals_text.atts_text.list[ix].id = p_vals_text[ix].id; + memcpy(vals_text.atts_text.list[ix].att_text, p_vals_text[ix].att_text, strlen((char *)p_vals_text[ix].att_text)); + } + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_ATT_VALS_TEXT_RESP, &vals_text, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_batt_status_resp(uint8_t *remote_dev_addr, uint8_t status) + * @brief Sends battery status response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] status - status to be sent. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_batt_status_resp(uint8_t *remote_dev_addr, uint8_t status) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_BATT_STATUS_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO, "STATUS: %1x", status); + rsi_bt_avrcp_reg_notify_resp_t batt_status; + memset(&batt_status, 0, sizeof(batt_status)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(batt_status.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(batt_status.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + batt_status.status = status; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_BATTERY_STATUS_RESP, &batt_status, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_char_set_status_resp(uint8_t *remote_dev_addr, uint8_t status) + * @brief Sends character set repsonse from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] status - status to be sent. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + * + */ +int32_t rsi_bt_avrcp_char_set_status_resp(uint8_t *remote_dev_addr, uint8_t status) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_CHAR_SET_STATUS_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO, "STATUS: %1x", status); + rsi_bt_avrcp_reg_notify_resp_t char_set; + memset(&char_set, 0, sizeof(char_set)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(char_set.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(char_set.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + char_set.status = status; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_CHAR_SETS_RESP, &char_set, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_notify(uint8_t *remote_dev_addr, + * uint8_t event_id, notify_val_t *p_notify_val) + * @brief Register notify CHANGED response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] event_id - event ID. + * @param[in] p_notify_val - pointer to notofication values. please refer \ref notify_val_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_notify(uint8_t *remote_dev_addr, uint8_t event_id, notify_val_t *p_notify_val) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_NOTIFY_TRIGGER, BLUETOOTH, LOG_INFO); + rsi_bt_avrcp_notify_t notify; + memset(¬ify, 0, sizeof(notify)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(notify.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(notify.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + notify.event_id = event_id; + memcpy(¬ify.notify_val, p_notify_val, sizeof(notify_val_t)); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_NOTIFICATION, ¬ify, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_cmd_reject(uint8_t *remote_dev_addr, uint8_t pdu_id, uint8_t status) + * @brief Rejects the received request from CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] pdu_id - PDU ID. + * @param[in] status - status to be sent. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_cmd_reject(uint8_t *remote_dev_addr, uint8_t pdu_id, uint8_t status) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_CMD_REJECT_TRIGGER, BLUETOOTH, LOG_INFO, "PDU_ID: %1x, STATUS: %1x", pdu_id, status); + rsi_bt_avrcp_cmd_reject_t cmd_reject; + memset(&cmd_reject, 0, sizeof(cmd_reject)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(cmd_reject.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(cmd_reject.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + cmd_reject.pdu_id = pdu_id; + cmd_reject.status = status; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_CMD_REJECT, &cmd_reject, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_set_abs_vol_resp(uint8_t *remote_dev_addr, uint8_t abs_vol) + * @brief Sends absolute volume response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - remote device address. + * @param[in] abs_vol - absolute volume. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_set_abs_vol_resp(uint8_t *remote_dev_addr, uint8_t abs_vol) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_SET_ABS_VOL_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO, "VOLUME: %1x", abs_vol); + rsi_bt_avrcp_set_abs_vol_resp_t abs_vol_resp; + memset(&abs_vol_resp, 0, sizeof(abs_vol_resp)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(abs_vol_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(abs_vol_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + abs_vol_resp.abs_vol = abs_vol; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_SET_ABS_VOL_RESP, &abs_vol_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_set_addr_player_resp(uint8_t *remote_dev_addr, uint8_t status) + * @brief Sends Addressed player response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - Remote device Address + * @param[in] status - Status + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note This funtion can be accessed only if Media Player Selection Feature is enabled via \ref bt_avrcp_init(). + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_set_addr_player_resp(uint8_t *remote_dev_addr, uint8_t status) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_SET_ADDR_PLAYER_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO, "STATUS: %1x", status); + rsi_bt_avrcp_set_addr_player_resp_t set_addr_player_resp = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(set_addr_player_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(set_addr_player_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + set_addr_player_resp.status = status; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_SET_ADDR_PLAYER_RESP, &set_addr_player_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_folder_items_resp(uint8_t *remote_dev_addr, + * uint8_t status, + * folder_items_resp_t folder_items_resp) + * @brief Sends folder items response from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - Remote device Address + * @param[in] status - Status + * @param[in] folder_items_resp - Folder items, Please refer \ref folder_items_resp_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note The folder_items_resp flag holds the details of Media Player Items. \n + * This funtion can be accessed only if Media Player Selection Feature is enabled via \ref bt_avrcp_init(). + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_folder_items_resp(uint8_t *remote_dev_addr, + uint8_t status, + folder_items_resp_t folder_items_resp) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_GET_FOLDER_ITEMS_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO, "STATUS: %1x", status); + rsi_bt_avrcp_get_folder_items_resp_t get_folder_items_resp = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(get_folder_items_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(get_folder_items_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + get_folder_items_resp.status = status; + memcpy(&get_folder_items_resp.fldr_items, &folder_items_resp, sizeof(folder_items_resp_t)); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_FOLDER_ITEMS_RESP, &get_folder_items_resp, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_avrcp_get_tot_num_items_resp(uint8_t *remote_dev_addr, + * uint8_t status, + * uint16_t uidcntr, + * uint32_t numofitems) + * @brief Sends the response for the total number of items from TG to CT. This is a blocking API. + * @pre Call \ref rsi_bt_avrcp_init() and \ref rsi_bt_avrcp_conn() before calling this API. + * @param[in] remote_dev_addr - Remote device Address + * @param[in] status - Status + * @param[in] uidcntr - uid counter + * @param[in] numofitems - Number of items + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note This funtion can be accessed only if Media Player Selection Feature is enabled via \ref bt_avrcp_init(). + * @note CT and TG specifies Controller and Target respectively as per BT AVRCP Specification. + */ +int32_t rsi_bt_avrcp_get_tot_num_items_resp(uint8_t *remote_dev_addr, + uint8_t status, + uint16_t uidcntr, + uint32_t numofitems) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_GET_TOTAL_NUM_ITEMS_RESPONSE_TRIGGER, + BLUETOOTH, + LOG_INFO, + "STATUS: %1x, UDICNTR: %2x, NUMBER_OF_ITEMS: %4x", + status, + uidcntr, + numofitems); + rsi_bt_avrcp_get_tot_num_items_resp_t get_tot_num_items_resp = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(get_tot_num_items_resp.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(get_tot_num_items_resp.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + get_tot_num_items_resp.status = status; + get_tot_num_items_resp.uidcntr = uidcntr; + get_tot_num_items_resp.numofitems = numofitems; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_AVRCP_GET_TOT_NUM_ITEMS_RESP, &get_tot_num_items_resp, NULL); +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/bluetooth/rsi_bt_common_apis.c b/wiseconnect/sapi/bluetooth/rsi_bt_common_apis.c new file mode 100644 index 00000000..caa55093 --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_bt_common_apis.c @@ -0,0 +1,673 @@ +/******************************************************************************* +* @file rsi_bt_common_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE)) +#include +#include +#include + +/** @addtogroup BT-BLE +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr) + * @brief Set the device BD address. This is blocking API. + * @pre needs to be called immediately after @ref rsi_wireless_init() OPERMODE command. + * @param[in] dev_addr - public address of the device to be set \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * -3 - Command is given in wrong state(i.e not immediate after opermode) + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr) +{ + rsi_bt_set_local_bd_addr_t bd_addr; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bd_addr.dev_addr, dev_addr); +#else + memcpy(bd_addr.dev_addr, dev_addr, RSI_DEV_ADDR_LEN); +#endif + SL_PRINTF(SL_RSI_BT_SET_BD_ADDRESS, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_SET_BD_ADDR_REQ, &bd_addr, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_ber_enable_or_disable(struct rsi_bt_ber_cmd_s *ber_cmd) + * @brief Enable and disable BER. This is blocking API. + * @param[in] ber_cmd - pointer address which contains the command structure. Please refer rsi_bt_ber_cmd_s structure for more info \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_ber_enable_or_disable(rsi_bt_ber_cmd_t *ber_cmd) +{ + if (ber_cmd == NULL) { + SL_PRINTF(SL_RSI_ERROR_INVALID_PARAMETER, BLUETOOTH, LOG_ERROR); + + return RSI_ERROR_INVALID_PARAM; + } + SL_PRINTF(SL_RSI_BT_BER_ENABLE_OR_DISABLE, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, (void *)ber_cmd, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_local_name(uint8_t *local_name) + * @brief Set the given name to local device. This is blocking API. + * @pre \ref rsi_wireless_init() API need to be called before this API. + * @param[in] local_name - Name to be set to the local device. + * @note For BLE alone Opermode : When the name of the local device is set to a value with length more than 16 bytes then error is returned with an error code 0x4E66. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ +int32_t rsi_bt_set_local_name(uint8_t *local_name) +{ + uint8_t name_len; + rsi_bt_req_set_local_name_t bt_req_set_local_name = { 0 }; + name_len = RSI_MIN(strlen((const char *)local_name), (RSI_DEV_NAME_LEN - 1)); + + memcpy(bt_req_set_local_name.name, local_name, name_len); + bt_req_set_local_name.name[name_len] = 0; + bt_req_set_local_name.name_len = name_len; + SL_PRINTF(SL_RSI_BT_SET_LOCAL_NAME, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_SET_LOCAL_NAME, &bt_req_set_local_name, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_cmd_update_gain_table_offset_or_max_pwr(uint8_t node_id, uint8_t payload_len, uint8_t *payload, uint8_t req_type) + * @brief Update gain table offset/max power. This is blocking API. + * @pre \ref rsi_wireless_init() API need to be called before this API. + * @param[in] node_id - Node ID (0 - BLE, 1 - BT). + * @param[in] payload_len - Length of the payload. + * @param[in] payload - Payload containing table data of gain table offset/max power + * @param[in] req_type - update gain table request type (0 - max power update, 1 - offset update) + * @note This API is applicable for High performance(HP) mode only. + * @return 0 - Success \n + * 0x4F01 - Invalid gain table payload length \n + * 0x4F02 - Invalid region. \n + * 0x4F03 - Invalid gain table offset request type \n + * 0x4F04 - Invalid node id. \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * + */ +int32_t rsi_bt_cmd_update_gain_table_offset_or_max_pwr(uint8_t node_id, + uint8_t payload_len, + uint8_t *payload, + uint8_t req_type) +{ + rsi_bt_cmd_update_gain_table_offset_or_maxpower_t bt_gain_table_offset = { 0 }; + bt_gain_table_offset.node_id = node_id; + bt_gain_table_offset.update_gain_table_type = req_type; + bt_gain_table_offset.payload_len = payload_len; + memcpy(bt_gain_table_offset.payload, payload, bt_gain_table_offset.payload_len); + SL_PRINTF(SL_RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE, &bt_gain_table_offset, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_local_name(rsi_bt_resp_get_local_name_t *bt_resp_get_local_name) + * @brief Get the local device name. This is blocking API. + * @pre \ref rsi_wireless_init() API need to be called before this API. + * @param[out] bt_resp_get_local_name - This parameter is the response buffer to hold the response of this API. Please refer rsi_bt_resp_get_local_name_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_get_local_name(rsi_bt_resp_get_local_name_t *bt_resp_get_local_name) +{ + SL_PRINTF(SL_RSI_BT_GET_LOCAL_NAME, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_GET_LOCAL_NAME, NULL, bt_resp_get_local_name); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_rssi(uint8_t *dev_addr, int8_t *resp) + * @brief Get the RSSI of the remote device. This is blocking API. + * @pre \ref rsi_bt_connect() API need to be called before this API. + * @param[in] dev_addr - Remote device address. + * @param[out] resp - Parameter to hold the response of this API, rssi is filled in this resp parameter. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_get_rssi(uint8_t *dev_addr, int8_t *resp) +{ + rsi_bt_get_rssi_t bt_rssi = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_rssi.dev_addr, dev_addr); +#else + memcpy(bt_rssi.dev_addr, dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_GET_RSSI, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_GET_RSSI, &bt_rssi, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_local_device_address(uint8_t *resp) + * @brief Get the local device address. This is blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[out] resp - Parameter to hold the response of this API, local bd_addr is filled in this resp parameter. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_get_local_device_address(uint8_t *resp) +{ + SL_PRINTF(SL_RSI_BT_GET_LOCAL_DEVICE_ADDRESS, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_GET_LOCAL_DEV_ADDR, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_bt_stack_version(rsi_bt_resp_get_bt_stack_version_t *bt_resp_get_bt_stack_version) + * @brief Get the BT stack version. This is blocking API. + * @param[out] bt_resp_get_bt_stack_version - Response buffer to hold the response of this API. Please refer rsi_bt_resp_get_bt_stack_version_s structure for more info + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_get_bt_stack_version(rsi_bt_resp_get_bt_stack_version_t *bt_resp_get_bt_stack_version) +{ + SL_PRINTF(SL_RSI_BT_STACK_VERSION, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_GET_BT_STACK_VERSION, NULL, bt_resp_get_bt_stack_version); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_init(void) + * @brief Initialize the BT device. This is blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. \n + * If the device is in powersave, get back the device to ACTIVE MODE by using \ref rsi_bt_power_save_profile() + * @param None + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_init(void) +{ + SL_PRINTF(SL_RSI_BT_INIT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_INIT, NULL, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_deinit(void) + * @brief Deinitialize the BT device. This is blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. \n + * If the device is in powersave, get back the device to ACTIVE MODE by using \ref rsi_bt_power_save_profile() + * @param None + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_deinit(void) +{ + SL_PRINTF(SL_RSI_BT_DEINIT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_DEINIT, NULL, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_antenna(uint8_t antenna_value) + * @brief Select either internal / external antenna on the chip. This is blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] antenna_value - Parameter is used to select either internal or external antenna. Possible values: \n + * 0x00 RSI_SEL_INTERNAL_ANTENNA \n + * 0x01 RSI_SEL_EXTERNAL_ANTENNA + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_set_antenna(uint8_t antenna_value) +{ + rsi_ble_set_antenna_t ble_set_antenna = { 0 }; + + ble_set_antenna.value = antenna_value; + SL_PRINTF(SL_RSI_BT_SET_ANTENNA, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_SET_ANTENNA_SELECT, &ble_set_antenna, NULL); +} +/** @} */ + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_feature_bitmap(uint32_t feature_bit_map) + * @brief Enable/Disable the mentioned features. This is blocking API. + * @note This API is not supported in the current release. + * @pre \ref rsi_sspmode_init() API needs to be called before this API. + * @param[in] feature_bit_map - features bit map list \n + * 0 This parameter is used for security purposes. \n + * If this bit is set pairing process occurs, else does not occur. \n + * 1 to 31 Reserved for future use. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_set_feature_bitmap(uint32_t feature_bit_map) +{ + rsi_bt_set_feature_bitmap_t bt_features = { 0 }; + + bt_features.bit_map = feature_bit_map; + SL_PRINTF(SL_RSI_SET_FEATURE_MAP, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_SET_FEATURES_BITMAP, &bt_features, NULL); +} + +/** @addtogroup BT-BLE +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_antenna_tx_power_level(uint8_t protocol_mode, int8_t tx_power) + * @brief Enable/Disable the mentioned features. This is blocking API. + * @pre \ref rsi_wireless_init() API need to be called before this API + * @param[in] protocol_mode - protocol mode \n + * 1 - BT classic \n + * 2 - BT Low Energy + * @param[in] tx-power - power value \n + * Antenna transmit power level \n + * Default Value for BLE Tx Power Index is 31, The range for the BLE Tx Power Index is 1 to 75 (0, 32 indexes are invalid) \n + * Default tx power index for BT classic is 14 \n + * 1 - 31 0DBM Mode. \n + * 33 - 63 10DBM Mode. \n + * 64 - 79 HP Mode. \n + * @note The default value will vary based on country region and board \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for above error codes \ref error-codes . + */ +int32_t rsi_bt_set_antenna_tx_power_level(uint8_t protocol_mode, int8_t tx_power) +{ + rsi_bt_set_antenna_tx_power_level_t bt_set_antenna_tx_power_level = { 0 }; + + bt_set_antenna_tx_power_level.protocol_mode = protocol_mode; +#if RSI_BLE_PWR_INX_DBM + if (protocol_mode == 2 /*BLE_MODE*/) { + bt_set_antenna_tx_power_level.tx_power = rsi_convert_db_to_powindex(tx_power); + if (bt_set_antenna_tx_power_level.tx_power == 0) { + return RSI_ERROR_INVALID_PARAM; + } + } else { + bt_set_antenna_tx_power_level.tx_power = tx_power; + } +#else + bt_set_antenna_tx_power_level.tx_power = tx_power; +#endif + SL_PRINTF(SL_RSI_BT_SET_ANTENNA_TX_POWER_LEVEL, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_SET_ANTENNA_TX_POWER_LEVEL, &bt_set_antenna_tx_power_level, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_power_save_profile(uint8_t psp_mode, uint8_t psp_type) + * @brief Select the power save profile mode for BT / BLE. This is blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API + * @param[in] psp_mode Following psp_mode is defined. \n + * 0 - RSI_ACTIVE. In this mode module is active and power save is disabled. \n + * 1 - RSI_SLEEP_MODE_1. On mode. In this sleep mode, SoC will never turn off, therefore no \n + * handshake is required before sending data to the module. BT/BLE does not support this mode. \n + * 2 - RSI_SLEEP_MODE_2. Connected sleep mode. In this sleep mode, SoC will go to sleep based \n + * on GPIO or Message, therefore handshake is required before sending data to the module. \n + * 8 - RSI_SLEEP_MODE_8 :Deep sleep mode with RAM RETENTION. \n + * 10- RSI_SLEEP_MODE_10 : Deep sleep mode without RAM RETENTION. \n + * In this sleep mode, module will turn off the \n + * SoC. Since SoC is turn off, therefore handshake is required before sending data to the module. \n + * @param[in] psp_type Following psp_type is defined. \n + * 0 - RSI_MAX_PSP. This psp_type will be used for max power saving \n + * 1 - Fast PSP \n + * 2 - UAPSD + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note If the user wants to enable power save in CoEx mode (WLAN + BT LE) mode - It is mandatory to enable WLAN power save along with BT LE power save. \n + * @note The device will enter into power save if and only if both protocol (WLAN, BLE) power save modes are enabled. \n + * @note Refer Error Codes section for above error codes \ref error-codes . + * @note psp_type is only valid in psp_mode 2. \n + * BT/BLE doesnot support in RSI_SLEEP_MODE_1. \n + * BT/BLE supports only RSI_MAX_PSP mode. Remaining modes are not supported. + * + */ +int32_t rsi_bt_power_save_profile(uint8_t psp_mode, uint8_t psp_type) +{ + int32_t status = RSI_SUCCESS; + + //Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + //Updating present bt power save type + rsi_common_cb->power_save.bt_psp_type = psp_type; + + //Updating present bt power save mode + rsi_common_cb->power_save.bt_psp_mode = psp_mode; + + status = rsi_sleep_mode_decision(rsi_common_cb); + + SL_PRINTF(SL_RSI_BT_POWER_SAVE_PROILE, BLUETOOTH, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ +/*! \cond RS9116 */ +/** @addtogroup BT-CLASSIC5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_per_stats(uint8_t cmd_type, struct rsi_bt_per_stats_s *rsi_bt_per_stats) + * @brief Request the local device for BT PER operation. + * @pre Call \ref rsi_bt_per_tx() or rsi_bt_per_rx() before calling this API. + * @param[in] cmd_type - Parameter to define the command id type for PER operation. \n + * BT_PER_STATS_CMD_ID (0x08) - Command id enables PER statistics \n + * BT_TRANSMIT_CMD_ID (0x15) - Command id enables PER transmit \n + * BT_RECEIVE_CMD_ID (0x16) - Command id enables PER receive + * @param[in] rsi_bt_per_stats - reference to the response structure. Please refer to rsi_bt_per_stats_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_per_stats(uint8_t cmd_type, struct rsi_bt_per_stats_s *per_stats) +{ + SL_PRINTF(SL_RSI_BT_REQUEST_LOCAL_DEVICE, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, &cmd_type, per_stats); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_per_cw_mode(struct rsi_bt_per_cw_mode_s *bt_cw_mode) + * @brief Keep the device in continuous wave mode. \n + * Not necessary to be called if transmit_mode is set to 2 - CONTINUOUS_WAVE_MODE in \ref rsi_bt_tx_per_params_s structure. + * @pre Call \ref rsi_bt_per_tx() before calling this API. + * @param[in] bt_cw_mode - continuous wave mode information needs to filled in this structure. Please refer \ref rsi_bt_per_cw_mode_s for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_per_cw_mode(struct rsi_bt_per_cw_mode_s *bt_cw_mode) +{ + if (bt_cw_mode == NULL) { + + SL_PRINTF(SL_RSI_ERROR_INVALID_PARAMETER, BLUETOOTH, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + SL_PRINTF(SL_RSI_PER_CW_MODE, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, bt_cw_mode, NULL); +} + +/** + * @fn int32_t rsi_bt_vendor_avdtp_stats_enable(uint16_t avdtp_stats_enable, + * uint32_t avdtp_stats_rate) + * @brief Issue vendor specific command for setting avdtp stats enable in controller, to receive the Stats. \n + * This is a blocking API. A received event \ref rsi_bt_on_avdtp_stats_t has AVDTP Stats. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] avdtp_stats_enable - stats enable, Enables the AVDTP stats in Controller + * @param[in] avdtp_stats_rate - stats rate, The rate for which the stats received to Host. \n + * @note Presently stats rate is defined with 30000 milisec. This is the minimum time will be fine tunes by running all the possible modes. + * @return 0 - Success \n + * Non-Zero Value - Failure + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_vendor_avdtp_stats_enable(uint16_t avdtp_stats_enable, uint32_t avdtp_stats_rate) +{ + rsi_bt_vendor_avdtp_stats_t rsi_bt_vendor_avdtp_stats; + + rsi_bt_vendor_avdtp_stats.opcode[0] = (BT_VENDOR_AVDTP_STATS_CMD_OPCODE & 0xFF); + rsi_bt_vendor_avdtp_stats.opcode[1] = ((BT_VENDOR_AVDTP_STATS_CMD_OPCODE >> 8) & 0xFF); + rsi_bt_vendor_avdtp_stats.avdtp_stats_enable = avdtp_stats_enable; + rsi_bt_vendor_avdtp_stats.avdtp_stats_rate = avdtp_stats_rate; + + SL_PRINTF(SL_RSI_BT_VENDOR_AVDTP_STATS_ENABLE, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &rsi_bt_vendor_avdtp_stats, NULL); +} + +/** + * @fn int32_t rsi_bt_vendor_ar_enable(uint16_t enable) + * @brief Issue vendor specific command for setting AutoRate in controller on given inputs. \n + * This is a blocking API. A received event \ref rsi_bt_on_ar_stats_t has AutoRate Stats. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] enable - enables the AutoRate. + * @return 0 - Success \n + * Non-Zero Value - Failure + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_vendor_ar_enable(uint16_t enable) +{ + rsi_bt_vendor_ar_cmd_t rsi_bt_vendor_ar_cmd; + rsi_bt_vendor_ar_cmd.opcode[0] = (BT_VENDOR_AR_CMD_OPCODE & 0xFF); + rsi_bt_vendor_ar_cmd.opcode[1] = ((BT_VENDOR_AR_CMD_OPCODE >> 8) & 0xFF); + + rsi_bt_vendor_ar_cmd.ar_enable = enable; + rsi_bt_vendor_ar_cmd._2m_state_continuous_pass_threshold = STATE_2M_CONTINUOUS_PASS_THRESHOLD; + rsi_bt_vendor_ar_cmd._2m_state_pass_threshold = STATE_2M_PASS_THRESHOLD; + rsi_bt_vendor_ar_cmd._3m_state_absolute_fail_threshold = STATE_3M_ABSOLUTE_FAIL_THRESHOLD; + rsi_bt_vendor_ar_cmd._3m_state_continuous_fail_threshold = STATE_3M_CONTINUOUS_FAIL_THRESHOLD; + rsi_bt_vendor_ar_cmd._3m_state_relative_fail_threshold = STATE_3M_RELATIVE_FAIL_THRESHOLD; + + SL_PRINTF(SL_RSI_BT_VENDOR_AR_ENABLE, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &rsi_bt_vendor_ar_cmd, NULL); +} +/** + * @fn int32_t rsi_bt_vendor_dynamic_pwr(uint16_t enable, + * uint8_t *remote_addr, + * uint8_t power_index_br, + * uint8_t power_index_2m, + * uint8_t power_index_3m) + * @brief Issue vendor specific command for setting dynamic_tx_power_index in controller on given inputs. \n + * This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_addr - Remote Device Address + * @param[in] power_index_br - Power value sets to BR Mode . + * @param[in] power_index_2m - Power value sets to 2m Mode data rate + * @param[in] power_index_3m - Power value sets to 3m Mode data rate + * @return 0 - Success \n + * Non-Zero Value - Failure + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * + * + */ +int32_t rsi_bt_vendor_dynamic_pwr(uint16_t enable, + uint8_t *remote_addr, + uint8_t power_index_br, + uint8_t power_index_2m, + uint8_t power_index_3m) +{ + rsi_bt_vendor_dynamic_pwr_cmd_t rsi_bt_vendor_dynamic_pwr_cmd = { 0 }; + rsi_bt_vendor_dynamic_pwr_cmd.opcode[0] = (BT_VENDOR_DYNAMIC_PWR_OPCODE & 0xFF); + rsi_bt_vendor_dynamic_pwr_cmd.opcode[1] = ((BT_VENDOR_DYNAMIC_PWR_OPCODE >> 8) & 0xFF); + + memcpy(rsi_bt_vendor_dynamic_pwr_cmd.set_dynamic_pwr_index.remote_dev, remote_addr, 6); + rsi_bt_vendor_dynamic_pwr_cmd.set_dynamic_pwr_index.dynamic_pwr_index.dynamic_power_enable = enable; + rsi_bt_vendor_dynamic_pwr_cmd.set_dynamic_pwr_index.dynamic_pwr_index.pwr_index_br = power_index_br; + rsi_bt_vendor_dynamic_pwr_cmd.set_dynamic_pwr_index.dynamic_pwr_index.pwr_index_2m = power_index_2m; + rsi_bt_vendor_dynamic_pwr_cmd.set_dynamic_pwr_index.dynamic_pwr_index.pwr_index_3m = power_index_3m; + + SL_PRINTF(SL_RSI_BT_VENDOR_DYNAMIC_POWER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &rsi_bt_vendor_dynamic_pwr_cmd, NULL); +} + +/** + * @fn int32_t rsi_bt_vendor_set_afh_classification_intervals(uint16_t afh_min, + * uint16_t afh_max) + * @brief Issue vendor specific command for setting afh min and max in controller on given inputs. + * @param[in] afh_min - afh minimum interval + * @param[in] afh_max - afh maximum interval + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ +int32_t rsi_bt_vendor_set_afh_classification_intervals(uint16_t afh_min, uint16_t afh_max) +{ + if ((afh_min > afh_max) || (afh_min < 0x640) || (afh_max > 0xBB80)) { + return RSI_ERROR_INVALID_PARAM; + } + rsi_bt_vendor_afh_classification_cmd_t rsi_bt_vendor_afh_classification_cmd = { 0 }; + rsi_bt_vendor_afh_classification_cmd.opcode[0] = (BT_VENDOR_AFH_CLASSIFICATION_CMD_OPCODE & 0xFF); + rsi_bt_vendor_afh_classification_cmd.opcode[1] = ((BT_VENDOR_AFH_CLASSIFICATION_CMD_OPCODE >> 8) & 0xFF); + rsi_bt_vendor_afh_classification_cmd.afh_min = afh_min; + rsi_bt_vendor_afh_classification_cmd.afh_max = afh_max; + + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &rsi_bt_vendor_afh_classification_cmd, NULL); +} + +/** @} */ +/*! \endcond */ + +/** + * @fn int32_t rsi_memory_stats_enable(uint8_t protocol, uint8_t memory_stats_enable, uint32_t memory_stats_interval_ms) + * @brief Gives vendor specific command to the controller to set memory utilization stats enable. + * @note This API is not supported in the current release. + * @param[in] protocol - Protocol + * @param[in] memory_stats_enable - Memory status enble + * @param[in] memory_stats_interval_ms - memory stats interval time + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ +int32_t rsi_memory_stats_enable(uint8_t protocol, uint8_t memory_stats_enable, uint32_t memory_stats_interval_ms) +{ + rsi_bt_vendor_memory_stats_t rsi_bt_vendor_memory_stats; + + rsi_bt_vendor_memory_stats.opcode[0] = (BT_VENDOR_MEMORY_STATS_CMD_OPCODE & 0xFF); + rsi_bt_vendor_memory_stats.opcode[1] = ((BT_VENDOR_MEMORY_STATS_CMD_OPCODE >> 8) & 0xFF); + rsi_bt_vendor_memory_stats.protocol = protocol; + rsi_bt_vendor_memory_stats.memory_stats_enable = memory_stats_enable; + rsi_bt_vendor_memory_stats.memory_stats_interval_ms = memory_stats_interval_ms; + + SL_PRINTF(SL_RSI_MEMORY_STATS_ENABLE, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_VENDOR_SPECIFIC, &rsi_bt_vendor_memory_stats, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_l2cap_connect(int8_t *remote_dev_addr, uint16_t psm, uint8_t preferred_mode) + * @brief Initiate the l2cap connection request + * @note This API is not supported in the current release. + * @param[in] remote_dev_addr - remote device address + * @param[in] psm - PSM + * @param[in] preferred_mode - preferred mode + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +int32_t rsi_bt_l2cap_connect(int8_t *remote_dev_addr, uint16_t psm, uint8_t preferred_mode) +{ + rsi_bt_req_l2cap_connect_t bt_req_l2cap_connect = { 0 }; + memcpy(bt_req_l2cap_connect.dev_addr, remote_dev_addr, 6); + bt_req_l2cap_connect.psm = psm; + bt_req_l2cap_connect.preferred_mode = preferred_mode; + + SL_PRINTF(SL_RSI_BT_L2CAP_CONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_L2CAP_CONNECT, &bt_req_l2cap_connect, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_l2cap_disconnect(int8_t *remote_dev_addr) + * @brief Initiate the l2cap disconnection request + * @note This API is not supported in the current release. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +int32_t rsi_bt_l2cap_disconnect(int8_t *remote_dev_addr) +{ + rsi_bt_req_l2cap_disconnect_t bt_req_l2cap_disconnect = { 0 }; + memcpy(bt_req_l2cap_disconnect.dev_addr, remote_dev_addr, 6); + SL_PRINTF(SL_RSI_BT_L2CAP_DISCONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_L2CAP_DISCONNECT, &bt_req_l2cap_disconnect, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_l2cap_init(void) + * @brief Initialize the l2cap profile for special data handling + * @note This API is not supported in the current release. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ +int32_t rsi_bt_l2cap_init(void) +{ + rsi_bt_req_profile_mode_t bt_req_l2cap_init = { 0 }; + bt_req_l2cap_init.profile_mode = 1 << 8; + SL_PRINTF(SL_RSI_BT_L2CAP_INIT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_PROFILE_MODE, &bt_req_l2cap_init, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_l2cap_data(int8_t *remote_dev_addr, uint8_t *data, uint16_t length, uint8_t frame_type) + * @brief Send the l2cap data to the remote device + * @note This API is not supported in the current release. + * @param[in] remote_dev_addr - remote device address + * @param[in] data - Data + * @param[in] length - Length + * @param[in] frame_type - Frame type + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_bt_l2cap_data(int8_t *remote_dev_addr, uint8_t *data, uint16_t length, uint8_t frame_type) +{ + uint16_t xfer_len = 0; + + rsi_bt_req_l2cap_data_t bt_req_l2cap_data = { 0 }; + xfer_len = RSI_MIN(length, RSI_BT_MAX_PAYLOAD_SIZE); + memcpy(bt_req_l2cap_data.dev_addr, remote_dev_addr, 6); + bt_req_l2cap_data.data_length[0] = (uint8_t)(xfer_len & 0x00FF); + bt_req_l2cap_data.data_length[1] = (xfer_len & 0xFF00) >> 8; + + memcpy(bt_req_l2cap_data.data, data, xfer_len); + bt_req_l2cap_data.frame_type = frame_type; + + // memset(bt_req_l2cap_data.data,0x0f,10); + + SL_PRINTF(SL_RSI_BT_L2CAP_SEND_DATA_REMOTE_DEVICE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_L2CAP_PROTOCOL_DATA, &bt_req_l2cap_data, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_l2cap_create_ertm_channel(rsi_bt_l2cap_ertm_channel_t l2cap_ertm) + * @brief Initiate the l2cap ertm channel connection. + * @note This API is not supported in the current release. + * @param[in] l2cap_ertm - Channel + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_bt_l2cap_create_ertm_channel(rsi_bt_l2cap_ertm_channel_t l2cap_ertm) +{ + + SL_PRINTF(SL_RSI_BT_L2CAP_CREATE_ERTM_CHANNEL_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_L2CAP_ERTM_CONFIGURE, &l2cap_ertm, NULL); +} + +#endif diff --git a/wiseconnect/sapi/bluetooth/rsi_bt_gap_apis.c b/wiseconnect/sapi/bluetooth/rsi_bt_gap_apis.c new file mode 100644 index 00000000..070a9dfe --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_bt_gap_apis.c @@ -0,0 +1,1372 @@ +/******************************************************************************* +* @file rsi_bt_gap_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +#ifdef RSI_BT_ENABLE + +#include "rsi_bt.h" +#include "rsi_bt_apis.h" +#include "rsi_bt_config.h" + +/** @addtogroup BT-CLASSIC3 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_local_class_of_device(uint32_t class_of_device) + * @brief Sets the local device COD (The Class_Of_Device parameter is used to \n + * indicate the capabilities of the local device to other device). This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] class_of_device - name to be set to the local device COD \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_set_local_class_of_device(uint32_t class_of_device) +{ + rsi_bt_req_set_local_cod_t bt_req_set_local_cod = { 0 }; + bt_req_set_local_cod.class_of_device = class_of_device; + SL_PRINTF(SL_RSI_BT_SET_LOCAL_CLASS_OF_DEVICE_TRIGGER, BLUETOOTH, LOG_INFO); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_LOCAL_COD, &bt_req_set_local_cod, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_local_class_of_device(uint8_t *resp) + * @brief Gets the local device COD (The Class_Of_Device parameter is used to \n + * indicate the capabilities of the local device to other device). This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[out] resp - response buffer to hold the response of this API \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_get_local_class_of_device(uint8_t *resp) +{ + SL_PRINTF(SL_RSI_BT_GET_LOCAL_CLASS_OF_DEVICE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_QUERY_LOCAL_COD, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_start_discoverable(void) + * @brief Sets the BT Module discovery mode status to INQUIRY_SCAN. This is a blocking API. + * @pre \ref rsi_wireless_init API needs to be called before this API + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_start_discoverable(void) +{ + rsi_bt_req_set_discv_mode_t bt_req_set_discv_mode = { 0 }; + bt_req_set_discv_mode.mode = START_DISCOVERY; + bt_req_set_discv_mode.time_out = 0; + SL_PRINTF(SL_RSI_BT_DISCOVERY_MODE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_DISCV_MODE, &bt_req_set_discv_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_start_limited_discoverable(int32_t time_out_ms) + * @brief Request the local device to enter limited discovery mode. \n + * The device comes out of discovery mode after the time out. \n + * If the 'time_out_ms' is set to '0', the device will be in continuous discoverable mode. \n + * This is a blocking API. + * @pre \ref rsi_wireless_init API needs to be called before this API. + * @param[in] time_out_ms - Limited discovery mode time_out in ms. \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_start_limited_discoverable(int32_t time_out_ms) +{ + rsi_bt_req_set_discv_mode_t bt_req_set_discv_mode = { 0 }; + bt_req_set_discv_mode.mode = START_LIMITED_DISCOVERY; + bt_req_set_discv_mode.time_out = time_out_ms; + SL_PRINTF(SL_RSI_BT_LIMITED_DISCOVERY_MODE_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_DISCV_MODE, &bt_req_set_discv_mode, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_write_current_iac_lap(uint8_t no_of_iaps, uint8_t *iap_lap_list) + * @brief Write the current iac lap to the controller. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] no_of_iaps - number of iap lap count \n + * @param[in] iap_lap_list - pointer to the iap laps list \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +#define IAP_LAP_SIZE 3 +int32_t rsi_bt_write_current_iac_lap(uint8_t no_of_iaps, uint8_t *iap_lap_list) +{ + rsi_bt_req_set_current_iap_lap_t bt_req_iap_lap = { 0 }; + uint8_t ix = 0; + uint8_t len = 0; + + bt_req_iap_lap.cnt = no_of_iaps; + + for (ix = 0; ix < no_of_iaps; ix++) { + len = ix * IAP_LAP_SIZE; + memcpy(&bt_req_iap_lap.list[len], (uint8_t *)&iap_lap_list[len], IAP_LAP_SIZE); + } + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_CURRENT_IAC_LAP, &bt_req_iap_lap, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_stop_discoverable(void) + * @brief Clears INQUIRY_SCAN BIT from BT Module discovery mode. This is a blocking API. + * @pre \ref rsi_wireless_init API needs to be called before this API. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_stop_discoverable(void) +{ + rsi_bt_req_set_discv_mode_t bt_req_set_discv_mode = { 0 }; + bt_req_set_discv_mode.mode = STOP_DISCOVERY; + bt_req_set_discv_mode.time_out = 0; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_DISCV_MODE, &bt_req_set_discv_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_discoverable_status(uint8_t *resp) + * @brief Gets the BT Module discovery mode status, \n + * whether INQUIRY_SCAN enabled/not. This is a blocking API. + * @pre \ref rsi_bt_start_discoverable() API need to be called before this API. + * @param[out] resp - response buffer to hold the response of this API \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ + +int32_t rsi_bt_get_discoverable_status(uint8_t *resp) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_QUERY_DISCV_MODE, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_connectable(void) + * @brief Sets the BT Module connectablity status to PAGE_SCAN. This is a blocking API. + * @pre \ref rsi_wireless_init API needs to be called before this API. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_set_connectable(void) +{ + rsi_bt_req_set_connectability_mode_t bt_req_set_connectability_mode = { 0 }; + bt_req_set_connectability_mode.connectability_mode = CONNECTABLE; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_CONNECTABILITY_MODE, &bt_req_set_connectability_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_afh_host_channel_classification(uint8_t enable, uint8_t *channel_map) + * @brief Sets the No.of channels to be used to Transmit or Receive the \n + * data/control packets between Local and Remote Devices. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] enable - This parameter is used to enable or disable afh host channel classification. \n + * This parameter supports the following values. \n + * 0 - Disable \n + * 1 - Enable \n + * @param[in] channel_map - Array of channel mapping values. \n + * Channel map range: This parameter contains 80 1-bit fields. \n + * The nth such field (in the range 0 to 78 bits) contains the value for channel n: \n + * 0: channel n is bad \n + * 1: channel n is unknown \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND \n + * 0x4E12 - INVALID_HCI_COMMAND_PARAMETERS + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_set_afh_host_channel_classification(uint8_t enable, uint8_t *channel_map) +{ + rsi_bt_req_set_afh_host_channel_classification_t afh_host_channel_classification = { 0 }; + + afh_host_channel_classification.channel_assessment_mode = RSI_WRITE_ASSESSMENT_MODE; + afh_host_channel_classification.enable = enable; + if (channel_map != NULL) { + memcpy(afh_host_channel_classification.channel_classification, channel_map, CHANNEL_MAP_LEN); + } + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_AFH_HOST_CHANNEL_CLASSIFICATION, &afh_host_channel_classification, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_afh_host_channel_classification(uint8_t *status) + * @brief Reads the afh mode, whether it is enable/disable. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[out] status - This parameter is to hold the response of this API. \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_get_afh_host_channel_classification(uint8_t *status) +{ + rsi_bt_req_set_afh_host_channel_classification_t afh_host_channel_classification = { 0 }; + + afh_host_channel_classification.channel_assessment_mode = RSI_READ_ASSESSMENT_MODE; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_AFH_HOST_CHANNEL_CLASSIFICATION, + &afh_host_channel_classification, + status); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_non_connectable(void) + * @brief Clears the PAGE_SCAN BIT in BT Module connectablity status. This is a blocking API. + * @pre \ref rsi_wireless_init API need to be called before this API. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_set_non_connectable(void) +{ + rsi_bt_req_set_connectability_mode_t bt_req_set_connectability_mode = { 0 }; + bt_req_set_connectability_mode.connectability_mode = NON_CONNECTABLE; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_CONNECTABILITY_MODE, &bt_req_set_connectability_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_connectable_status(uint8_t *resp) + * @brief Gets the BT Module connectablity status, \n + * whether PAGE_SCAN enabled/not. This is a blocking API. + * @pre \ref rsi_bt_set_connectable() API needs to be called before this API + * @param[out] resp - response buffer to hold the response of this API \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_get_connectable_status(uint8_t *resp) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_QUERY_CONNECTABILITY_MODE, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_enable_authentication(void) + * @brief If the local device requires to authenticate the remote device at \n + * connection setup (between the HCI_Create_Connection command or \n + * acceptance of an incoming ACL connection and the corresponding \n + * Connection Complete event).At connection setup, only the device(s) \n + * with the Authentication_Enable parameter enabled will try to authenticate \n + * the other device. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note Changing this parameter does not affect existing connection. + */ +int32_t rsi_bt_enable_authentication(void) +{ + rsi_bt_req_set_pair_mode_t bt_req_set_pair_mode = { 0 }; + bt_req_set_pair_mode.pair_mode = RSI_ENABLE; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_PAIR_MODE, &bt_req_set_pair_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_disable_authentication(void) + * @brief If the local device doesn't requires to authenticate the remote device at \n + * connection setup (between the HCI_Create_Connection command or acceptance \n + * of an incoming ACL connection and the corresponding Connection Complete event). \n + * This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note Changing this parameter does not affect existing connection. + */ +int32_t rsi_bt_disable_authentication(void) +{ + rsi_bt_req_set_pair_mode_t bt_req_set_pair_mode = { 0 }; + bt_req_set_pair_mode.pair_mode = RSI_DISABLE; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_PAIR_MODE, &bt_req_set_pair_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_authentication(uint8_t *resp) + * @brief Reads the value from the Authentication_Enable configuration parameter, \n + * whether Authentication is Enabled/Disabled. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[out] resp - response buffer to hold the response of this API + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_get_authentication(uint8_t *resp) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_QUERY_PAIR_MODE, NULL, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_remote_name_request_async(uint8_t *remote_dev_addr, + * rsi_bt_event_remote_device_name_t *bt_event_remote_device_name) + * @brief Know the remote device name, if empty name present in the Inquired list during Inquiry. And also can call this API after bt connection. \n + * This is a blocking API. A received event \ref rsi_bt_on_remote_name_resp_t has the name of the remote_dev_addr which is requested. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_inquiry() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[out] bt_event_remote_device_name - response buffer to hold the name of remote device \n + * Please refer \ref rsi_bt_event_remote_device_name_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_remote_name_request_async(uint8_t *remote_dev_addr, + rsi_bt_event_remote_device_name_t *bt_event_remote_device_name) +{ + rsi_bt_req_remote_name_t bt_req_remote_name = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_remote_name.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_remote_name.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_REMOTE_NAME_REQUEST, + &bt_req_remote_name, + (void *)bt_event_remote_device_name); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_remote_name_request_cancel(uint8_t *remote_dev_addr) + * @brief The Remote Device name request which is initiated by rsi_bt_remote_name_request_async() \n + * api will be cancelled by using this API. This is a blocking API. \n + * A received event \ref rsi_bt_on_remote_name_request_cancel_t indicates that remote name request has been cancelled. + * @pre \ref rsi_bt_remote_name_request_async() API needs to be called before this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E12 - INVALID_HCI_COMMAND_PARAMETERS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_remote_name_request_cancel(uint8_t *remote_dev_addr) +{ + rsi_bt_req_remote_name_cancel_t bt_req_remote_name_cancel = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_remote_name_cancel.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_remote_name_cancel.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_REMOTE_NAME_REQUEST_CANCEL, &bt_req_remote_name_cancel, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_inquiry(uint8_t inquiry_type, uint32_t inquiry_duration, uint8_t max_devices) + * @brief Starts the Inquiry procedure till duration specified in the \n + * inquiry_duration parameter and allowed maximum number of devices to \n + * be inquired is mentioned in max_devices parameter. This is a blocking API. \n + * A received event \ref rsi_bt_on_scan_resp_t provides the Inquired devices information. \n + * A received event \ref rsi_bt_on_inquiry_complete_t indicates that Inquiry has been completed \n + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] inquiry_type - This is the Inquiry type. \n + * 0 - Standard Inquiry \n + * 1 - Inquiry with RSSI \n + * 2 - Extended Inquiry \n + * @param[in] inquiry_duration - duration of inquiry. \n + * @param[in] max_devices - This is the maximum number of devices allowed to inquiry from 1 to 10 \n + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_inquiry(uint8_t inquiry_type, uint32_t inquiry_duration, uint8_t max_devices) +{ + rsi_bt_req_inquiry_t bt_req_inquiry = { 0 }; + if (inquiry_type & BIT(7)) { + bt_req_inquiry.lap[0] = 0x00; + bt_req_inquiry.lap[1] = 0x8B; + bt_req_inquiry.lap[2] = 0x9E; + } else { + bt_req_inquiry.lap[0] = 0x33; + bt_req_inquiry.lap[1] = 0x8B; + bt_req_inquiry.lap[2] = 0x9E; + } + + bt_req_inquiry.inquiry_type = (inquiry_type & ~(BIT(7))); + bt_req_inquiry.duration = inquiry_duration; + bt_req_inquiry.maximum_devices_to_find = max_devices; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_INQUIRY, &bt_req_inquiry, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_cancel_inquiry(void) + * @brief The Inquiry request which is initiated with rsi_bt_inquiry() api \n + * will be cancelled by using this API. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and then rsi_bt_inquiry() before calling this API. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4FF9 - ERROR_STATE_INVALID + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_cancel_inquiry(void) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_INQUIRY_CANCEL, NULL, NULL); +} + +/*! \cond RS9116 */ +/** @} */ +/** @addtogroup BT-CLASSIC5 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_enable_device_under_testmode(void) + * @brief LMP has PDUs to support different test modes used for certification and compliance testing \n + * of the Bluetooth radio and baseband. We can activate locally (via a HW or SW interface), \n + * or using the air interface. For activation over the air interface, entering the test mode shall be \n + * locally enabled for security and type approval reasons. So, to keep the device in test_mode locally, will call this API. \n + * This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_enable_device_under_testmode(void) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_ENABLE_DEVICE_UNDER_TESTMODE, NULL, NULL); +} +/** @} */ + +/** @addtogroup BT-CLASSIC3 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_connect(uint8_t *remote_dev_addr) + * @brief To Initiate Connection Request to the Remote Device, need to \n + * call this API. This is a blocking API. \n + * A received event \ref rsi_bt_on_connect_t indicates that the connection opened successfully. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4300 - ERR_BT_HCI_CONN_ALREADY_EXISTS \n + * 0x4059 - ERR_BT_HCI_CONNECTION_FAIL \n + * 0x4E0B - ERR_ACL_CONN_ALREADY_EXISTS \n + * 0x4E0D - ERR_LIMITED_RESOURCE \n + * 0x4E04 - ERR_PAGE_TIMEOUT + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_connect(uint8_t *remote_dev_addr) +{ + rsi_bt_req_connect_t bt_req_connect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_connect.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_connect.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_BOND, &bt_req_connect, NULL); +} + +/** @} */ +/** @addtogroup BT-CLASSIC3 +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_cancel_connect(uint8_t *remote_dev_address) + * @brief The Connection request which is initiated with rsi_bt_connect() api \n + * will be cancelled by using this API. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and then rsi_bt_connect() before calling this API. + * @param[in] remote_dev_address - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4E0B - ERR_ACL_CONN_ALREADY_EXISTS + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_cancel_connect(uint8_t *remote_dev_address) +{ + rsi_bt_req_connect_cancel_t bt_req_connect_cancel = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_connect_cancel.dev_addr, remote_dev_address); +#else + memcpy(bt_req_connect_cancel.dev_addr, remote_dev_address, 6); +#endif + // Send connect cancel command + return rsi_bt_driver_send_cmd(RSI_BT_REQ_BOND_CANCEL, &bt_req_connect_cancel, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_disconnect(uint8_t *remote_dev_address) + * @brief To disconnect the established PHY Level COnnection, need to \n + * call this API. This is a blocking API. \n + * A received event \ref rsi_bt_on_unbond_t/ \ref rsi_bt_on_disconnect_t indicates that the BT PHY Level connection is disconnected successfully. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_address - remote device address \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4061 - ERR_BT_NO_HCI_CONNECTION \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4E12 - INVALID_HCI_COMMAND_PARAMETERS + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_disconnect(uint8_t *remote_dev_address) +{ + rsi_bt_req_disconnect_t bt_req_disconnect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_disconnect.dev_addr, remote_dev_address); +#else + memcpy(bt_req_disconnect.dev_addr, remote_dev_address, 6); +#endif + // Send disconnect command + return rsi_bt_driver_send_cmd(RSI_BT_REQ_UNBOND, &bt_req_disconnect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_accept_ssp_confirm(uint8_t *remote_dev_address) + * @brief After LinkLevel Connection established between Local and Remote Device, \n + * the first level of authentication will occur by sharing the PASSKEY to the \n + * host to compare with the Remote Device. If the Local and Remote Devices has \n + * same PASSKEY, then need to call this API for confirmation. This is a blocking API. + * @pre \ref rsi_bt_set_ssp_mode() API need to be called before this API + * @param[in] remote_dev_address - remote device address \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E0C - COMMAND_DISALLOWED \n + * 0x4046 - ERR_BT_INVALID_ARGS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_accept_ssp_confirm(uint8_t *remote_dev_address) +{ + rsi_bt_req_user_confirmation_t bt_req_user_confirmation; + memset(&bt_req_user_confirmation, 0, sizeof(bt_req_user_confirmation)); + + bt_req_user_confirmation.confirmation = ACCEPT; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_user_confirmation.dev_addr, remote_dev_address); +#else + memcpy(bt_req_user_confirmation.dev_addr, remote_dev_address, 6); +#endif + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_USER_CONFIRMATION, &bt_req_user_confirmation, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_reject_ssp_confirm(uint8_t *remote_dev_address) + * @brief After LinkLevel Connection established between Local and Remote Device, \n + * the first level of authentication will occur by sharing the PASSKEY to the \n + * host to compare with the Remote Device. If the Local and Remote Devices has \n + * different PASSKEY, then need to call this API for Rejection. This is a blocking API. + * @pre \ref rsi_bt_set_ssp_mode() API need to be called before this API + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E06 - COMMAND_DISALLOWED \n + * 0x4046 - ERR_BT_INVALID_ARGS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_reject_ssp_confirm(uint8_t *remote_dev_address) +{ + rsi_bt_req_user_confirmation_t bt_req_user_confirmation; + memset(&bt_req_user_confirmation, 0, sizeof(bt_req_user_confirmation)); + + bt_req_user_confirmation.confirmation = REJECT; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_user_confirmation.dev_addr, remote_dev_address); +#else + memcpy(bt_req_user_confirmation.dev_addr, remote_dev_address, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_USER_CONFIRMATION, &bt_req_user_confirmation, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_passkey(uint8_t *remote_dev_addr, uint32_t passkey, uint8_t reply_type) + * @brief Send the passkey with Positive Reply or rejects the incoming pass key request with Negative Reply. \n + * This is a blocking API. + * @pre \ref rsi_wireless_init() and \ref rsi_bt_connect() APIs need to be called \n + * before this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] passkey - This is the passkey input + * @param[in] reply_type -This is the positive or negative reply \n + * 0 - negative reply \n + * 1 - positive reply + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E06 - COMMAND_DISALLOWED \n + * 0x4046 - ERR_BT_INVALID_ARGS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_passkey(uint8_t *remote_dev_addr, uint32_t passkey, uint8_t reply_type) +{ + rsi_bt_req_passkey_reply_t bt_req_passkey_reply; + memset(&bt_req_passkey_reply, 0, sizeof(bt_req_passkey_reply)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_passkey_reply.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_passkey_reply.dev_addr, remote_dev_addr, 6); +#endif + bt_req_passkey_reply.pass_key = passkey; + bt_req_passkey_reply.reply_type = reply_type; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PASSKEY_REPLY, &bt_req_passkey_reply, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_pincode_request_reply(uint8_t *remote_dev_addr, + * uint8_t *pin_code, uint8_t reply_type) + * @brief Sends the pincode with the positive reply or rejects with \n + * negative reply to the incoming pincode request. This is a blocking API. + * @pre \ref rsi_wireless_init() and \ref rsi_bt_connect() APIs need to be called \n + * before this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] pin_code - pin code input + * @param[in] reply_type - This is the positive or negative reply \n + * 0 - negative reply \n + * 1 - positive reply + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4039 - ERR_BT_PINCODE_REPLY_FOR_WRONG_BD_ADDRESS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note This API need to issue during the legacy connection process. + */ +int32_t rsi_bt_pincode_request_reply(uint8_t *remote_dev_addr, uint8_t *pin_code, uint8_t reply_type) +{ + rsi_bt_req_pincode_reply_t bt_req_pincode_reply; + memset(&bt_req_pincode_reply, 0, sizeof(bt_req_pincode_reply)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_pincode_reply.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_pincode_reply.dev_addr, remote_dev_addr, 6); +#endif + bt_req_pincode_reply.reply_type = reply_type; + memcpy(bt_req_pincode_reply.pincode, pin_code, RSI_MIN(strlen((const char *)pin_code), RSI_MAX_PINCODE_REPLY_SIZE)); + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PINCODE_REPLY, &bt_req_pincode_reply, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_linkkey_request_reply(uint8_t *remote_dev_addr, + * uint8_t *linkkey, + * uint8_t reply_type) + * @brief If linkkey exists, sends positive (along with the link key), else \n + * negative reply to the incoming link key request. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() api's before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] linkkey - Linkkey input + * @param[in] reply_type - Positive or negative reply \n + * 0 - negative reply \n + * 1 - positive reply + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4039 - ERR_BT_PINCODE_REPLY_FOR_WRONG_BD_ADDRESS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_linkkey_request_reply(uint8_t *remote_dev_addr, uint8_t *linkkey, uint8_t reply_type) +{ + rsi_bt_req_linkkey_reply_t bt_linkkey_req_reply; + memset(&bt_linkkey_req_reply, 0, sizeof(bt_linkkey_req_reply)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_linkkey_req_reply.dev_addr, remote_dev_addr); +#else + memcpy(bt_linkkey_req_reply.dev_addr, remote_dev_addr, 6); +#endif + bt_linkkey_req_reply.reply_type = reply_type; + if (linkkey != NULL) { + memcpy(bt_linkkey_req_reply.linkkey, linkkey, 16); + } + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_LINKKEY_REPLY, &bt_linkkey_req_reply, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_local_device_role(uint8_t *remote_dev_addr, uint8_t *resp) + * @brief Gets the role of local device, whether it is MASTER/SLAVE. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() api's before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[out] resp - response buffer to hold the response of this API + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_get_local_device_role(uint8_t *remote_dev_addr, uint8_t *resp) +{ + rsi_bt_req_query_role_t bt_req_query_role = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_query_role.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_query_role.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_QUERY_ROLE, &bt_req_query_role, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_local_device_role(uint8_t *remote_dev_addr, + * uint8_t set_role, uint8_t *resp) + * @brief Sets the role of local device, whether it is MASTER/SLAVE. This is a blocking API. \n + * A received event \ref rsi_bt_on_role_change_t indicates that the device role changed successfully. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() api's before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] set_role - This paramets sets either Master/Slave Role \n + 0 Master Role \n + 1 Slave Role + * @param[out] resp - response buffer to hold the response of this API + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E06 - COMMAND_DISALLOWED \n + * 0x4046 - ERR_BT_INVALID_ARGS + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_set_local_device_role(uint8_t *remote_dev_addr, uint8_t set_role, uint8_t *resp) +{ + rsi_bt_req_set_role_t bt_req_set_role; + memset(&bt_req_set_role, 0, sizeof(bt_req_set_role)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_set_role.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_set_role.dev_addr, remote_dev_addr, 6); +#endif + bt_req_set_role.role = set_role; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_ROLE, &bt_req_set_role, resp); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_get_services_async(uint8_t *remote_dev_addr, + * rsi_bt_resp_query_services_t *bt_resp_query_services) + * @brief Queries the services supported by remote device. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() before calling this API. + * @param[in] remote_dev_addr - Remote device address + * @param[out] bt_resp_query_services - Response struct to hold the response of this API, \n + * please refer \ref rsi_bt_resp_query_services_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4100 - ERR_BT_INVALID_PDU \n + * 0x4102 - ERR_BT_SDP_SERVICE_NOT_FOUND \n + * 0x4101 - ERR_BT_INVALID_PDU_DATA_ELEMENT \n + * 0x4049 - ERR_BT_SOCK_STATE_INVALID + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +//int32_t rsi_bt_get_services(uint8_t *remote_dev_addr, uint32_t *resp, uint16_t num_of_responses) +int32_t rsi_bt_get_services_async(uint8_t *remote_dev_addr, rsi_bt_resp_query_services_t *bt_resp_query_services) +{ + rsi_bt_req_query_services_t bt_req_query_services = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_query_services.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_query_services.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_QUERY_SERVICES, &bt_req_query_services, bt_resp_query_services); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_search_service_async(uint8_t *remote_dev_addr, uint32_t service_uuid) + * @brief Search service of the given uuid from remote device. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] service_uuid - uuid of the service for search + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4100 - ERR_BT_INVALID_PDU \n + * 0x4102 - ERR_BT_SDP_SERVICE_NOT_FOUND \n + * 0x4101 - ERR_BT_INVALID_PDU_DATA_ELEMENT \n + * 0x4049 - ERR_BT_SOCK_STATE_INVALID + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_search_service_async(uint8_t *remote_dev_addr, uint32_t service_uuid) +{ + rsi_bt_req_search_service_t bt_req_search_service; + memset(&bt_req_search_service, 0, sizeof(bt_req_search_service)); + bt_req_search_service.service_uuid = service_uuid; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_search_service.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_search_service.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SEARCH_SERVICE, &bt_req_search_service, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_sniff_mode(uint8_t *remote_dev_addr, + * uint16_t sniff_max_intv, + * uint16_t sniff_min_intv, + * uint16_t sniff_attempt, + * uint16_t sniff_tout) + * @brief Request the local device to enter into sniff mode. This is a blocking API. + * @pre \ref rsi_bt_spp_connect() API needs to be called before this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] sniff_max_intv - Sniff maximum Interval + * @param[in] sniff_min_intv - Sniff Minimum Interval + * @param[in] sniff_attempt - Sniff Attempt + * @param[in] sniff_tout - Sniff timeout + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4061 - ERR_BT_NO_HCI_CONNECTION \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4E06 - COMMAND_DISALLOWED + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_sniff_mode(uint8_t *remote_dev_addr, + uint16_t sniff_max_intv, + uint16_t sniff_min_intv, + uint16_t sniff_attempt, + uint16_t sniff_tout) +{ + rsi_bt_req_sniff_mode_t bt_req_sniff_mode; + memset(&bt_req_sniff_mode, 0, sizeof(bt_req_sniff_mode)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_sniff_mode.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_sniff_mode.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_req_sniff_mode.sniff_max_intv = sniff_max_intv; + bt_req_sniff_mode.sniff_min_intv = sniff_min_intv; + bt_req_sniff_mode.sniff_attempt = sniff_attempt; + bt_req_sniff_mode.sniff_tout = sniff_tout; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SNIFF_MODE, &bt_req_sniff_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_sniff_exit_mode(uint8_t *remote_dev_addr) + * @brief Request the local device to exit from sniff/sniff subrating mode. This is a blocking API. + * @pre \ref rsi_bt_sniff_mode() API needs to be called before this API. + * @param[in] remote_dev_addr - remote device address \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - ERR_BT_INVALID_ARGS \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4E06 - COMMAND_DISALLOWED + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_sniff_exit_mode(uint8_t *remote_dev_addr) +{ + rsi_bt_req_sniff_exit_mode_t bt_req_sniff_exit_mode = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_sniff_exit_mode.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_sniff_exit_mode.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SNIFF_EXIT_MODE, &bt_req_sniff_exit_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_sniff_subrating_mode(uint8_t *remote_dev_addr, + * uint16_t max_latency, + * uint16_t min_remote_tout, + * uint16_t min_local_tout) + * @brief Requests the device entered into the sniff subrating mode. This is a blocking API. + * @pre \ref rsi_bt_sniff_mode() API needs to be called before this API. + * @param[in] remote_dev_addr - remote device address + * @param[in] max_latency - Maximum Latency + * @param[in] min_remote_tout - Minimum remote timeout + * @param[in] min_local_tout - Minimum local timeout + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - ERR_BT_INVALID_ARGS \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_sniff_subrating_mode(uint8_t *remote_dev_addr, + uint16_t max_latency, + uint16_t min_remote_tout, + uint16_t min_local_tout) +{ + rsi_bt_req_sniff_subrating_mode_t bt_req_sniff_subrating_mode; + memset(&bt_req_sniff_subrating_mode, 0, sizeof(bt_req_sniff_subrating_mode)); +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_sniff_subrating_mode.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_sniff_subrating_mode.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_req_sniff_subrating_mode.max_latency = max_latency; + bt_req_sniff_subrating_mode.min_remote_tout = min_remote_tout; + bt_req_sniff_subrating_mode.min_local_tout = min_local_tout; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SNIFF_SUBRATING_MODE, &bt_req_sniff_subrating_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_ssp_mode(uint8_t pair_mode, uint8_t IOcapability) + * @brief Enables or disables Simple Secure Profile (SSP) mode and also \n + * updates the IOcapability, which is used for Authentication process. This is a blocking API. + * @pre \ref rsi_bt_set_connectable() API needs to be called before this API. + * @param[in] pair_mode - This parameter is used to enable or disable SSP mode. \n + * This parameters supports the following values. \n + * 0 - Disable \n + * 1 - Enable + * @param[in] IOcapability - This is the IO capability request for SSP mode. \n + * This parameter supports the following values. \n + * 0 - DisplayOnly \n + * 1 - DisplayYesNo \n + * 2 - KeyboardOnly \n + * 3 - NoInputNoOutput + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4046 - ERR_BT_INVALID_ARGS \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_set_ssp_mode(uint8_t pair_mode, uint8_t IOcapability) +{ + rsi_bt_req_set_ssp_mode_t bt_req_set_ssp_mode = { 0 }; + + bt_req_set_ssp_mode.pair_mode = pair_mode; + bt_req_set_ssp_mode.IO_capability = IOcapability; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_SSP_MODE, &bt_req_set_ssp_mode, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_eir_data(uint8_t *data, uint16_t data_len) + * @brief Sets the extended Inquiry Response data. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] data - Pointer to the EIR data buffer which is an array that can store data upto 200 Bytes + * @param[in] data_len - length of the eir data \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note Currently EIR data supports upto 200 bytes. \n + */ +int32_t rsi_bt_set_eir_data(uint8_t *data, uint16_t data_len) +{ + rsi_bt_set_eir_data_t eirdata = { 0 }; + + eirdata.fec_required = 0; + eirdata.data_len = RSI_MIN((data_len + 1), sizeof(eirdata.eir_data)); // adding 1byte(for fec_required variable) + + memcpy(eirdata.eir_data, data, eirdata.data_len); + + // Send stop advertise command + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_EIR, &eirdata, NULL); +} + +/** @} */ + +/** @addtogroup BT-CLASSIC5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_per_rx(uint32_t *bt_perrx) + * @brief Configure the per receive parameters in the controller and start/stop the PER. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] bt_rx_per - Buffer to hold the structure values. Please Refer to \ref rsi_bt_rx_per_params_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note Refer Error Codes section for common error codes \ref error-codes . + */ +int32_t rsi_bt_per_rx(uint32_t *bt_perrx) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, bt_perrx, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_per_tx(uint32_t *bt_pertx) + * @brief Configure the per transmit parameters in the controller and start/stop the PER. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] bt_tx_per - Buffer to hold the structure values. Please refer to \ref rsi_bt_tx_per_params_s structure for more info. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_per_tx(uint32_t *bt_pertx) +{ + return rsi_bt_driver_send_cmd(RSI_BT_REQ_PER_CMD, bt_pertx, NULL); +} +/** @} */ +/*! \endcond */ + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_gatt_connect(uint8_t *remote_dev_addr) + * @brief Initiate a connection request to the GATT Server on the Remote Device \n + * via BT Classic L2cap Channel instead BLE, which in terms called as ATT_OVER_CLASSIC. \n + * This is a blocking API. + * @note This API is not supported in the current release. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() before calling this API. + * @param[in] remote_dev_addr - remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4FF8 - ERROR_INVALID_COMMAND \n + * 0x4046 - ERR_BT_INVALID_ARGS \n + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * @note To enable att_over_classic feature, 29th bit to be set in bt_custom_feature_bit_map. + */ + +int32_t rsi_bt_gatt_connect(uint8_t *remote_dev_addr) +{ + rsi_bt_req_gatt_connect_t bt_req_gatt_connect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_gatt_connect.dev_addr, remote_dev_addr); +#else + memcpy(bt_req_gatt_connect.dev_addr, remote_dev_addr, 6); +#endif + return rsi_bt_driver_send_cmd(RSI_BT_REQ_GATT_CONNECT, &bt_req_gatt_connect, NULL); +} + +/** @addtogroup BT-CLASSIC3 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_add_device_id(uint16_t spec_id, + * uint16_t vendor_id, + * uint16_t product_id, + * uint16_t version, + * int primary_rec, + * uint16_t vendor_id_source) + * @brief Add device Identification in SDP protocol. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] spec_id - Version number of the Bluetooth Device ID Profile + * specification supported by the device. \n + * @param[in] vendor_id - Uniquely identify the vendor of the device. + * @param[in] product_id - To distinguish between different products made by the vendor + * @param[in] version - A numeric expression identifying the device release number in Binary-Coded Decimal + * @param[in] primary_rec - Set to TRUE in the case single Device ID Service \n + * Record exists in the device. If multiple Device ID Service Records exist, \n + * and no primary record has been defined, set to FALSE. + * @param[in] vendor_id_source - This attribute designates which organization assigned the \n + * VendorID attribute, 0x201. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4105 - ERR_BT_SDP_PNP_SERVICE_ALREADY_EXISTS \n + * 0x4046 - ERR_BT_INVALID_ARGS + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * + * + */ +int32_t rsi_bt_add_device_id(uint16_t spec_id, + uint16_t vendor_id, + uint16_t product_id, + uint16_t version, + int primary_rec, + uint16_t vendor_id_source) +{ + rsi_bt_req_add_device_id_t add_device_id = { 0 }; + + add_device_id.spec_id = spec_id; + add_device_id.vendor_id = vendor_id; + add_device_id.product_id = product_id; + add_device_id.version = version; + add_device_id.primary_rec = primary_rec; + add_device_id.vendor_id_source = vendor_id_source; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_ADD_DEVICE_ID, &add_device_id, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_change_pkt_type(uint8_t *remote_dev_addr, uint16_t pkt_type) + * @brief Change the packet types in the controller after connection only, can switch between \n + * 2DH3,2DH5,3DH3,3DH5. This is a blocking API. + * @pre Call \ref rsi_wireless_init() and \ref rsi_bt_connect() before calling this API. + * @param[in] remote_dev_addr - Remote device address + * @param[in] pkt_type - change the packet types in the controller + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4061 - ERR_BT_NO_HCI_CONNECTION \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_change_pkt_type(uint8_t *remote_dev_addr, uint16_t pkt_type) +{ + rsi_bt_ptt_pkt_type_t bt_pkttypechange = { 0 }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_pkttypechange.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_pkttypechange.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + bt_pkttypechange.pkt_type = pkt_type; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_CHANGE_CONNECTION_PKT_TYPE, &bt_pkttypechange, NULL); +} +/** @} */ + +/** @addtogroup BT-CLASSIC3 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_ptt_req(uint8_t mode) + * @brief Configure the LP HP transitions in the controller. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] mode - BR/EDR mode \n + * 0 - BR Mode \n + * 1 - EDR Mode + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E01 - UNKNOWN_HCI_COMMAND + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ +int32_t rsi_bt_ptt_req(uint8_t mode) +{ + rsi_bt_ptt_mode_t bt_lphpchange; + bt_lphpchange.mode = mode; + return rsi_bt_driver_send_cmd(RSI_BT_REQ_BR_EDR_LP_HP_TRANSISTION, &bt_lphpchange, NULL); +} + +/*=================================================*/ +/** + * @fn int32_t rsi_bt_request_authentication(int8_t *remote_dev_addr) + * @brief Usually Authentication procedure will starts from stack itself \n + * once PHY Level Connection completes, but if already authentication is in \n + * disable state and after PHY Level Connection if User needs Authetication, \n + * then firstly need to enable Authentication and secondly call this API. \n + * This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr - Remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4061 - ERR_BT_NO_HCI_CONNECTION \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ + +int32_t rsi_bt_request_authentication(int8_t *remote_dev_addr) +{ + + rsi_bt_cmd_conn_auth_t bt_conn_auth = { { 0 } }; + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_conn_auth.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_conn_auth.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_ENABLE_AUTH, &bt_conn_auth, NULL); +} + +/*=================================================*/ +/** + * @fn int32_t rsi_bt_encryption_enable_or_disable(int8_t *remote_dev_addr, uint8_t enable_or_disable) + * @brief Usually Encrytpion procedure will starts from stack itself once \n + * PHY Level Connection and authentication completed, but user can decide \n + * whether to enable/disable encryption from the host. This is a blocking API. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr - Remote device address + * @param[in] enable_or_disable - To enable/disable the encryption. \n + * 1 - Enable \n + * 0 - Disable \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4061 - ERR_BT_NO_HCI_CONNECTION \n + * 0x4E02 - UNKNOWN_CONNECTION_IDENTIFIER \n + * 0x4E11 - UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE + * + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * */ + +int32_t rsi_bt_encryption_enable_or_disable(int8_t *remote_dev_addr, uint8_t enable_or_disable) +{ + + rsi_bt_cmd_conn_enc_t bt_conn_enc = { 0 }; + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_conn_enc.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_conn_enc.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + + bt_conn_enc.enable_or_disable = enable_or_disable; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_ENABLE_ENC, &bt_conn_enc, NULL); +} +/** @} */ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_link_policy_settings_config(uint8_t *remote_dev_addr, uint8_t link_policy) + * @brief To set new link policy configuration. + * ENABLE_ROLE_SWITCH BIT(0) + * ENABLE_HOLD_MODE BIT(1) //Not actively being used + * ENABLE_SNIFF_MODE BIT(2) + * ENABLE_PARK_STATE BIT(3) //Not actively being used + * + * Note: Old link policy settings will be overwritten with the updated value of link_policy_settings + * Eg: 1. If you want to enable role_switch and sniff_mode you have to pass the link_policy_settings with value 5 (ENABLE_ROLE_SWITCH | ENABLE_SNIFF_MODE) + * 2. If you want to disable role_switch and keep the sniff_mode enabled you have to pass with value 4 (Only enable ENABLE_SNIFF_MODE) + * 3. If you want to enable role_switch and disable the sniff_mode you have to pass with value 1 (Only enable ENABLE_ROLE_SWITCH) + * @pre \ref rsi_wireless_init API needs to be called before this API + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +int32_t rsi_bt_link_policy_settings_config(uint8_t *remote_dev_addr, uint16_t link_policy_settings) +{ + + rsi_bt_cmd_link_policy_settings_t link_policy_sett; + + if (link_policy_settings > 7 || link_policy_settings < 0) { + return RSI_ERROR_INVALID_PARAM; + } + + memset(&link_policy_sett, 0, sizeof(rsi_bt_cmd_link_policy_settings_t)); + memcpy(link_policy_sett.dev_addr, (uint8_t *)remote_dev_addr, RSI_DEV_ADDR_LEN); + link_policy_sett.link_policy_settings = link_policy_settings; + return rsi_bt_driver_send_cmd(RSI_BT_LINK_POLICY_CONFIG, &link_policy_sett, NULL); +} + +/*=================================================*/ +/** + * @fn int32_t rsi_bt_delete_linkkeys(int8_t *remote_dev_addr, uint8_t delete_linkkeys) + * @brief Delete the existing linkkeys which are stored in Controller Memory. This is a blocking API. + * @note This API is not supported in the current release. + * @pre Call \ref rsi_wireless_init() before calling this API. + * @param[in] remote_dev_addr - Remote device address + * @param[in] delete_linkkeys - Based on this flag the Controller deletes all the stored linkkeys \n + * (or) deletes specific to the remote_dev_addr. \n + * 1 - Deletes all stored Linkkeys from Controller \n + * 0 - Deletes Specfic to the remote_dev_addr + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4E12 - ERR_BT_INVALID_HCI_COMMAND_PARAMETER \n + * 0x4E12 - UNKNOWN_HCI_COMMAND + * + * @note Refer Error Codes section for common error codes \ref error-codes . + */ + +int32_t rsi_bt_delete_linkkeys(int8_t *remote_dev_addr, uint8_t delete_linkkeys) +{ + + rsi_bt_cmd_delete_linkkeys_t bt_delete_linkkeys = { 0 }; + +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_delete_linkkeys.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_delete_linkkeys.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + + bt_delete_linkkeys.delete_linkkeys = delete_linkkeys; + + return rsi_bt_driver_send_cmd(RSI_BT_REQ_DEL_LINKKEYS, &bt_delete_linkkeys, NULL); +} + +#endif diff --git a/wiseconnect/sapi/bluetooth/rsi_bt_sbc_codec.c b/wiseconnect/sapi/bluetooth/rsi_bt_sbc_codec.c new file mode 100644 index 00000000..a7fdc16c --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_bt_sbc_codec.c @@ -0,0 +1,717 @@ +/******************************************************************************* +* @file rsi_bt_sbc_codec.c +* @brief +******************************************************************************* +* # License +* Copyright 2020-2021 Silicon Laboratories Inc. www.silabs.com +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_bt_sbc_codec.c + * @version 0.1 + * @date 28 Feb 2019 + * + * + * + * @brief : This file contains BT A2DP SBC encoding API's + * + * @section Description This file contains BT A2DP API's called from application + * + */ +#include "rsi_driver.h" +#if RSI_BT_ENABLE +#include +#include +#include "sbc_encoder.h" + +#include "rsi_bt_sbc_codec.h" +#include "rsi_bt_config.h" +#ifdef FRDM_K28F +#if ((BT_A2DP_SOURCE_SBC_CODEC || UNIFIED_PROTOCOL || COEX_MAX_APP || COEX_THROUGHPUT) || (defined LINUX_PLATFORM)) +#if (defined LINUX_PLATFORM) +#define LOG_PRINT +#endif +#endif +#endif +#define BT_EVT_A2DP_PCM_DATA 1 +#define BT_A2DP_MAX_DATA_PKT 32 +#define BT_A2DP_EX_DATA_PKT 18 //Need some space to store the extra packets temporarily due to reconstruction +#define BT_ADDR_ARRAY_LEN 18 +#define DEFAULT_MTU_SIZE 310 +#define PKT_HEADER_AND_CRC 11 // 11 --> l2cap+controller header + crc +#define RTP_HEADER 13 // 13 --> rtp_header +#define SBC_HEADER_SIZE 4 +#define SBC_SYNCWORD 0x9C + +#define MAX_SBC_PKT_SIZE 1048 + +#define SBC_FRAME_SIZE sbc_frame_size_t +#define SKIP_SIZE (SBC_FRAME_SIZE + RTP_HEADER + PKT_HEADER_AND_CRC) + +#define HW_BUFFER_OVERFLOW 0x4057 + +typedef struct a2dp_info_s { + uint16_t mtu; + uint16_t event_map; + SBC_ENC_PARAMS rsi_encoder; + uint8_t addr_s[BT_ADDR_ARRAY_LEN]; +} a2dp_info_t; + +uint16_t pcm_offset; +static a2dp_info_t a2dp_info; +uint8_t sbc_frame_size_t; + +#define PCM_AUDIO 1 +#define SBC_AUDIO 2 +#define MP3_AUDIO 3 +#define AAC_AUDIO 4 +uint32_t i_bytes_consumed; +uint32_t i_out_bytes; +#if (RSI_AUDIO_DATA_TYPE == MP3_AUDIO) +extern uint8_t mp3_data[MP3_INPUT_BUFFER_SIZE]; +uint16_t mp3_cur_buf_len = 0; +uint16_t mp3_offset = 0; +uint16_t mp3_bytes_consumed = 0; +uint16_t mp3_frame_len = 0; +int32_t mp3_err_code = 0; +uint8_t pcm_data1[4700] __attribute__((aligned(4))); +#endif + +#ifdef FRAME_WORK +uint8_t pcm_data_t[2560] __attribute__((aligned(4))); +uint8_t pcm_data_t[PCM_INPUT_BUFFER_SIZE] __attribute__((aligned(4))); +uint32_t pcm_cur_buf_len = 0; +uint8_t init_flag = 0; +uint8_t send_flag = 1; +rsi_sbc_queue_t rsi_sbc_queue; +uint16_t sbc_data_len_t[PRE_ENC_BUF_LEN] = { 0 }; +uint16_t sbc_offset = 0; +uint8_t idx = 0; +uint16_t sbc_len = 0; +uint8_t flag; +uint8_t sbc_data_t[1100 * PRE_ENC_BUF_LEN]; + +typedef struct data_pkt_s { + uint8_t used; + uint8_t reserved; + uint16_t data_len; +#if (RSI_AUDIO_DATA_TYPE == PCM_AUDIO) + uint8_t data[PCM_INPUT_BUFFER_SIZE]; +#else + uint8_t data[MP3_INPUT_BUFFER_SIZE]; +#endif + struct data_pkt_s *next; +} data_pkt_t; + +data_pkt_t *p_pkt; +data_pkt_t *pcm_q_head; +data_pkt_t pcm_data_pool[BT_A2DP_MAX_DATA_PKT]; +data_pkt_t *sbc_q_head; +data_pkt_t *sbc_pkt; +data_pkt_t *sbc_queue_head = NULL; +#endif + +typedef struct data_pkt_s { + uint8_t used; + uint8_t pkt_cnt; + uint16_t data_len; + uint8_t data[MAX_SBC_PKT_SIZE]; + struct data_pkt_s *next; +} data_pkt_t; + +typedef struct rsi_queue_s { + uint32_t pkt_cnt; + data_pkt_t *head; + data_pkt_t *tail; +} rsi_queue_t; + +rsi_queue_t rsi_sbc_queue; + +data_pkt_t sbc_data_pool[BT_A2DP_MAX_DATA_PKT + BT_A2DP_EX_DATA_PKT]; + +rsi_mutex_handle_t sbc_mutex; + +/**************************************************************************************/ +/*==============================================*/ +/** + * @fn void add_to_list(rsi_queue_t *rsi_queue, data_pkt_t *data_pkt) + * @brief Add the packet to the list + * @param[in] rsi_queue - pointer to q queue + * @param[in] data_pkt - poniter to a packet in queue + * @return void + */ +void add_to_list(rsi_queue_t *rsi_queue, data_pkt_t *data_pkt) +{ + rsi_queue->pkt_cnt++; + if (rsi_queue->tail == NULL) { + rsi_queue->head = data_pkt; + } else { + rsi_queue->tail->next = data_pkt; + } + rsi_queue->tail = data_pkt; + rsi_queue->tail->next = NULL; + SL_PRINTF(SL_RSI_BT_ADD_PAKCET_TO_LIST, BLUETOOTH, LOG_INFO); +} + +/**************************************************************************************/ +/*==============================================*/ +/** + * @fn void del_from_list(rsi_queue_t *rsi_queue) + * @brief Delete the packet from the list + * @param[in] rsi_queue - pointer to a queue + * @return void + * + */ +void del_from_list(rsi_queue_t *rsi_queue) +{ + rsi_queue->pkt_cnt--; + rsi_queue->head = rsi_queue->head->next; + if (rsi_queue->head == NULL) { + rsi_queue->tail = NULL; + } + SL_PRINTF(SL_RSI_BT_DELETE_PAKCET_FROM_LIST, BLUETOOTH, LOG_INFO); +} + +/**************************************************************************************/ +/*==============================================*/ +/** + * @fn static void free_data_pkt (data_pkt_t *p_data_pool, data_pkt_t *p_data_pkt) + * @brief Free "p_data_pkt" + * @param[in] p_data_pool - pointer to a data pool + * @param[in] p_data_pkt - pointer to a packet in queue + * @param[out] p_data_pool - pointer to a data pool + * @return void + */ +/***************************************************************************************/ +static void free_data_pkt(data_pkt_t *p_data_pool, data_pkt_t *p_data_pkt) +{ + uint8_t ix = 0; + if (p_data_pkt->used == 1) { + for (ix = 0; ix < (BT_A2DP_MAX_DATA_PKT + BT_A2DP_EX_DATA_PKT); ix++) { + if (&p_data_pool[ix] == p_data_pkt) { + p_data_pool[ix].used = 0; + return; + } + } + } + + if (ix >= (BT_A2DP_MAX_DATA_PKT + BT_A2DP_EX_DATA_PKT)) { + while (1) + ; + } + return; + SL_PRINTF(SL_RSI_BT_FREE_DATA_PACKET, BLUETOOTH, LOG_INFO); +} +/**************************************************************************************/ +/*==============================================*/ +/** + * @fn static data_pkt_t *alloc_data_pkt (data_pkt_t *p_data_pool) + * @brief Allocate data packet from pool + * @param[in] p_data_pool - pointer to a data pool + * @param[out] void + * @return data pool + * + */ +/***************************************************************************************/ +static data_pkt_t *alloc_data_pkt(data_pkt_t *p_data_pool) +{ + uint8_t ix = 0; + for (ix = 0; ix < (BT_A2DP_MAX_DATA_PKT + BT_A2DP_EX_DATA_PKT); ix++) { + if (p_data_pool[ix].used == 0) { + p_data_pool[ix].used = 1; + return (&p_data_pool[ix]); + } + } + return NULL; + SL_PRINTF(SL_RSI_BT_ALLOC_DATA_PACKET, BLUETOOTH, LOG_INFO); +} + +/**************************************************************************************/ +/*==============================================*/ +/** + * @fn void bt_evt_a2dp_disconn(void) + * @brief Clear PCM Data Event on A2DP Disconnection + * @return void + * + */ +/***************************************************************************************/ +void bt_evt_a2dp_disconn(void) +{ + a2dp_info.mtu = DEFAULT_MTU_SIZE; + SL_PRINTF(SL_RSI_BT_EVT_A2DP_DISCONNECT, BLUETOOTH, LOG_INFO); +} + +/**************************************************************************************/ +int16_t rsi_bt_app_send_sbc_data(void) +{ + data_pkt_t *sbc_head = NULL; + + int16_t send_sbc_cmd_status = RSI_SUCCESS; + + if (rsi_sbc_queue.pkt_cnt == 0) { + return RSI_APP_ERR_A2DP_SBC_BUFF_UNDERFLOW; + } + + rsi_mutex_lock(&sbc_mutex); + sbc_head = rsi_sbc_queue.head; + + send_sbc_cmd_status = rsi_bt_a2dp_send_sbc_aac_data(a2dp_info.addr_s, sbc_head->data, sbc_head->data_len, 0); + + free_data_pkt((data_pkt_t *)&sbc_data_pool, sbc_head); + del_from_list(&rsi_sbc_queue); + rsi_mutex_unlock(&sbc_mutex); + return send_sbc_cmd_status; +} +/*==============================================*/ +/** + * @fn int16_t rsi_bt_a2dp_sbc_encode_task (uint8_t *pcm_data, uint16_t pcm_data_len, + * uint16_t *bytes_consumed) + * @brief Encode Raw Data + * @param[in] pcm_data - Input raw audio data + * @param[in] pcm_data_len - Raw audio length in bytes + * @param[out] bytes_consumed - No of bytes consumed by encoder + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +/***************************************************************************************/ +int16_t rsi_bt_a2dp_sbc_encode_task(uint8_t *pcm_data, uint16_t pcm_data_len, uint16_t *bytes_consumed) +{ + int16_t status = 0; +#if !(RSI_AUDIO_DATA_TYPE == PCM_AUDIO || RSI_AUDIO_DATA_TYPE == MP3_AUDIO) + USED_PARAMETER(pcm_data_len); //This statement is added only to resolve compilation warning, value is unchanged +#endif +#if !(RSI_AUDIO_DATA_TYPE == MP3_AUDIO) + USED_PARAMETER(bytes_consumed); //This statement is added only to resolve compilation warning, value is unchanged +#endif + int16_t send_sbc_cmd_status = RSI_SUCCESS; + data_pkt_t *sbc_pkt = NULL; + + if (pcm_data == NULL) { + return RSI_APP_ERR_INVALID_INPUT; + SL_PRINTF(SL_RSI_APP_ERR_INVALID_INPUT, BLUETOOTH, LOG_ERROR); + } + + pcm_offset = 0; + + //The extra packets generated during reconstruction must be sent out first + while (rsi_sbc_queue.pkt_cnt >= BT_A2DP_MAX_DATA_PKT) { + status = rsi_bt_app_send_sbc_data(); + if (status == HW_BUFFER_OVERFLOW) { + break; + } + } + + sbc_pkt = (data_pkt_t *)alloc_data_pkt((data_pkt_t *)&sbc_data_pool); + + if (sbc_pkt == NULL) { + return RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW; + SL_PRINTF(SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW, BLUETOOTH, LOG_ERROR); + } + + sbc_pkt->data_len = 0; + +#if (RSI_AUDIO_DATA_TYPE == PCM_AUDIO) + while (pcm_offset < pcm_data_len) { + a2dp_info.rsi_encoder.ps16PcmBuffer = (SINT16 *)(pcm_data + pcm_offset); //PCM Data Pointer + a2dp_info.rsi_encoder.pu8Packet = sbc_pkt->data + sbc_pkt->data_len; //SBC Data Pointer + + /* SBC Encoding */ + pcm_offset += SBC_Encoder(&(a2dp_info.rsi_encoder)); + + sbc_pkt->data_len += a2dp_info.rsi_encoder.u16PacketLength; + sbc_frame_size_t = a2dp_info.rsi_encoder.u16PacketLength; + + if (sbc_pkt->data_len > (a2dp_info.mtu - SKIP_SIZE)) { + /* Reached MTU and add it to Queue */ + rsi_mutex_lock(&sbc_mutex); + add_to_list(&rsi_sbc_queue, sbc_pkt); + rsi_mutex_unlock(&sbc_mutex); + break; + } + } + + if (rsi_sbc_queue.pkt_cnt >= BT_A2DP_MAX_DATA_PKT) { + return RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW; + SL_PRINTF(SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW, BLUETOOTH, LOG_ERROR); + } + +#endif + +#if (RSI_AUDIO_DATA_TYPE == MP3_AUDIO) + memcpy(&mp3_data[mp3_cur_buf_len], pcm_data, pcm_data_len); + + mp3_cur_buf_len += pcm_data_len; + + /* Get MP3 Frame Length */ + mp3_frame_len = get_mp3_frame_len(mp3_data); + + while (mp3_frame_len < mp3_cur_buf_len) { + if (mp3_frame_len == 0) { + i_out_bytes = 0; + i_bytes_consumed = 0; + goto PROCESS_PCM_DATA; + } + mp3_err_code = ia_mp3_dec_main_process(mp3_data, pcm_data1, mp3_frame_len); + memcpy(&pcm_data_t[pcm_cur_buf_len], pcm_data1, i_out_bytes); + pcm_cur_buf_len += i_out_bytes; + mp3_offset += i_bytes_consumed; +PROCESS_PCM_DATA: + while (pcm_offset < pcm_cur_buf_len) { + init_flag = 0; + /* Buffer upto MTU size */ + if (sbc_data_len_t[idx] >= (a2dp_info.mtu - SKIP_SIZE)) { + if (idx < PRE_ENC_BUF_LEN - 1) { + idx++; + } else { + if (send_sbc_cmd_status == RSI_APP_ERR_HW_BUFFER_OVERFLOW) { + init_flag = 1; + break; + } + idx = 0; + sbc_offset = 0; + while ((idx < PRE_ENC_BUF_LEN) && (sbc_data_len_t[idx] >= (a2dp_info.mtu - SKIP_SIZE))) { + if (sbc_data_t[0] != SBC_SYNCWORD) { + LOG_PRINT("\n Invalid SBC Packet \n"); + SL_PRINTF(SL_RSI_INVALID_SBC_PACKET, BLUETOOTH, LOG_ERROR); + } + send_sbc_cmd_status = + rsi_bt_a2dp_send_sbc_aac_data(a2dp_info.addr_s, sbc_data_t + sbc_offset, sbc_data_len_t[idx], 0); + if (send_sbc_cmd_status == RSI_APP_ERR_A2DP_NOT_STREAMING) { + continue; + } + sbc_offset += sbc_data_len_t[idx]; + sbc_data_len_t[idx] = 0; + idx++; + if (send_sbc_cmd_status == RSI_APP_ERR_HW_BUFFER_OVERFLOW) { + /* Clear More Data Request */ + //rsi_app_async_event_map &= ~BIT(RSI_APP_EVENT_A2DP_MORE_DATA_REQ); + + memcpy(sbc_data_t, sbc_data_t + sbc_offset, sbc_len - sbc_offset); + for (int i = 0, j = idx; (i < PRE_ENC_BUF_LEN) && (j < PRE_ENC_BUF_LEN); i++, j++) { + sbc_data_len_t[i] = sbc_data_len_t[j]; + sbc_data_len_t[j] = 0; + } + idx = PRE_ENC_BUF_LEN - idx; + sbc_len -= sbc_offset; + goto ENCODE; + } + } + idx = 0; + sbc_len -= sbc_offset; + } + } +ENCODE: + a2dp_info.rsi_encoder.ps16PcmBuffer = pcm_data_t + pcm_offset; //PCM Data Pointer + a2dp_info.rsi_encoder.pu8Packet = sbc_data_t + sbc_len; //SBC Data Pointer + + /* SBC Encoding */ + pcm_offset += SBC_Encoder(&(a2dp_info.rsi_encoder)); + + sbc_data_len_t[idx] += a2dp_info.rsi_encoder.u16PacketLength; + sbc_frame_size_t = a2dp_info.rsi_encoder.u16PacketLength; + sbc_len += sbc_frame_size_t; + } + + /* Copy the remaining PCM Data input Buffer to Zero'th location of the same */ + if (pcm_offset != 0) { + memmove(pcm_data_t, &pcm_data_t[pcm_offset], (pcm_cur_buf_len - pcm_offset)); + } + pcm_cur_buf_len -= pcm_offset; + pcm_offset = 0; + + if (mp3_offset != 0) { + memmove(mp3_data, &mp3_data[mp3_offset], (mp3_cur_buf_len - mp3_offset)); + } + mp3_cur_buf_len -= mp3_offset; + mp3_bytes_consumed += i_bytes_consumed; + mp3_frame_len = get_mp3_frame_len(mp3_data); + mp3_offset = 0; + + if (init_flag) { + break; + } + + if (mp3_frame_len == 0) { + mp3_bytes_consumed = 0; + break; + } + } + + *bytes_consumed = mp3_bytes_consumed; + mp3_offset = 0; + mp3_bytes_consumed = 0; +#endif + return send_sbc_cmd_status; +} + +/**************************************************************************************/ +/*==============================================*/ +/** + * @fn int16_t rsi_bt_cmd_a2dp_pcm_mp3_data (uint8_t *addr, uint8_t *pcm_data, + * uint16_t pcm_data_len, uint16_t *bytes_consumed) + * @brief Set PCM Data event + * @param[in] addr - Remote BD Address + * @param[in] pcm_data - PCM Data + * @param[in] pcm_data_len - PCM Data Length + * @param[in] bytes_consumed - Bytes consumed + * @return 0 - Success \n + * Non-Zero Value - Failure +***************************************************************************************/ +int16_t rsi_bt_cmd_a2dp_pcm_mp3_data(uint8_t *addr, uint8_t *pcm_data, uint16_t pcm_data_len, uint16_t *bytes_consumed) +{ + int16_t err = 0; + + memcpy(a2dp_info.addr_s, addr, BT_ADDR_ARRAY_LEN); + + err = rsi_bt_a2dp_sbc_encode_task(pcm_data, pcm_data_len, bytes_consumed); + + SL_PRINTF(SL_RSI_BT_CMD_A2DP_PCM_MP3_DATA, BLUETOOTH, LOG_INFO); + + return err; +} +/************************************************************************************** + * @fn int16_t rsi_bt_cmd_sbc_init (void) + * @brief Initialize SBC with default configuration + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + * +***************************************************************************************/ +int16_t rsi_bt_cmd_sbc_init(void) +{ + int8_t status = RSI_SUCCESS; + + a2dp_info.rsi_encoder.s16SamplingFreq = SBC_sf44100; + a2dp_info.rsi_encoder.s16ChannelMode = SBC_JOINT_STEREO; + a2dp_info.rsi_encoder.s16NumOfSubBands = SUB_BANDS_8; + a2dp_info.rsi_encoder.s16NumOfBlocks = SBC_BLOCK_3; + a2dp_info.rsi_encoder.s16AllocationMethod = SBC_LOUDNESS; + a2dp_info.rsi_encoder.s16BitPool = 53; + + SBC_Encoder_Init(&(a2dp_info.rsi_encoder)); + SL_PRINTF(SL_RSI_BT_CMD_SBC_INIT_SUCCESS, BLUETOOTH, LOG_INFO); + + status = rsi_mutex_create(&sbc_mutex); + if (status != RSI_ERROR_NONE) { + LOG_PRINT("failed to create mutex object, error = %d \r\n", status); + } + return 0; +} +/************************************************************************************** + * @fn int16_t rsi_bt_cmd_sbc_reinit (rsi_bt_a2dp_sbc_codec_cap_t *sbc_cap) + * @brief Reinit SBC with user configuration + * @param[in] sbc_cap, a pointer to a sbc capability structure + * @param[out] None + * @return +*************************************************************************************/ +typedef struct rsi_bt_a2dp_sbc_codec_cap_ss { + uint8_t ChannelMode : 4; + uint8_t Freq : 4; + uint8_t AllocMethod : 2; + uint8_t SubBands : 2; + uint8_t BlockLength : 4; + uint8_t MinBitPool; + uint8_t MaxBitPool; +} rsi_bt_a2dp_sbc_codec_cap_tt; + +int16_t rsi_bt_cmd_sbc_reinit(void *p_sbc_cap) +{ + rsi_bt_a2dp_sbc_codec_cap_tt *sbc_cap = (rsi_bt_a2dp_sbc_codec_cap_tt *)p_sbc_cap; + + /* Sampling Frequency */ + if (((uint32_t)sbc_cap->Freq) & SBC_SAMPLING_FREQ_48000) + a2dp_info.rsi_encoder.s16SamplingFreq = SBC_sf48000; + else if (((uint32_t)sbc_cap->Freq) & SBC_SAMPLING_FREQ_44100) + a2dp_info.rsi_encoder.s16SamplingFreq = SBC_sf44100; + else if (((uint32_t)sbc_cap->Freq) & SBC_SAMPLING_FREQ_32000) + a2dp_info.rsi_encoder.s16SamplingFreq = SBC_sf32000; + else if (((uint32_t)sbc_cap->Freq) & SBC_SAMPLING_FREQ_16000) + a2dp_info.rsi_encoder.s16SamplingFreq = SBC_sf16000; + else + LOG_PRINT("\n Frequency Mismatch \n"); + SL_PRINTF(SL_RSI_BT_FREQUENCY_MISMATCH, BLUETOOTH, LOG_ERROR); + + /* Block Length */ + if (((uint32_t)sbc_cap->BlockLength) & SBC_BLOCK_LENGTH_16) + a2dp_info.rsi_encoder.s16NumOfBlocks = SBC_BLOCK_3; + else if (((uint32_t)sbc_cap->BlockLength) & SBC_BLOCK_LENGTH_12) + a2dp_info.rsi_encoder.s16NumOfBlocks = SBC_BLOCK_2; + else if (((uint32_t)sbc_cap->BlockLength) & SBC_BLOCK_LENGTH_8) + a2dp_info.rsi_encoder.s16NumOfBlocks = SBC_BLOCK_1; + else if (((uint32_t)sbc_cap->BlockLength) & SBC_BLOCK_LENGTH_4) + a2dp_info.rsi_encoder.s16NumOfBlocks = SBC_BLOCK_0; + else + LOG_PRINT("\n Block Length Mismatch \n"); + SL_PRINTF(SL_RSI_BT_BLOCK_LENGTH_MISMATCH, BLUETOOTH, LOG_ERROR); + + /* SubBands */ + if (((uint32_t)sbc_cap->SubBands) & SBC_SUBBANDS_8) + a2dp_info.rsi_encoder.s16NumOfSubBands = SUB_BANDS_8; + else if (((uint32_t)sbc_cap->SubBands) & SBC_SUBBANDS_4) + a2dp_info.rsi_encoder.s16NumOfSubBands = SUB_BANDS_4; + else + LOG_PRINT("\n Subbands Mismatch \n"); + SL_PRINTF(SL_RSI_BT_SUBBANDS_MISMATCH, BLUETOOTH, LOG_ERROR); + + /* Channel Mode */ + if (((uint32_t)sbc_cap->ChannelMode) & SBC_CHANNEL_MODE_JOINT_STEREO) + a2dp_info.rsi_encoder.s16ChannelMode = SBC_JOINT_STEREO; + else if (((uint32_t)sbc_cap->ChannelMode) & SBC_CHANNEL_MODE_STEREO) + a2dp_info.rsi_encoder.s16ChannelMode = SBC_STEREO; + else if (((uint32_t)sbc_cap->ChannelMode) & SBC_CHANNEL_MODE_DUAL_CHANNEL) + a2dp_info.rsi_encoder.s16ChannelMode = SBC_DUAL; + else if (((uint32_t)sbc_cap->ChannelMode) & SBC_CHANNEL_MODE_MONO) + a2dp_info.rsi_encoder.s16ChannelMode = SBC_MONO; + else + LOG_PRINT("\n Channel Mode Mismatch \n"); + SL_PRINTF(SL_RSI_BT_CHANNEL_MODE_MISMATCH, BLUETOOTH, LOG_ERROR); + + /* Allocation Method */ + if (((uint32_t)sbc_cap->AllocMethod) & SBC_ALLOCATION_LOUDNESS) + a2dp_info.rsi_encoder.s16AllocationMethod = SBC_LOUDNESS; + else if (((uint32_t)sbc_cap->AllocMethod) & SBC_ALLOCATION_SNR) + a2dp_info.rsi_encoder.s16AllocationMethod = SBC_SNR; + else + LOG_PRINT("\n Allocation Method Mismatch \n"); + SL_PRINTF(SL_RSI_BT_ALLOCATION_METHOD_MISMATCH, BLUETOOTH, LOG_ERROR); + + /* BitPool */ + a2dp_info.rsi_encoder.s16BitPool = (uint8_t)sbc_cap->MaxBitPool; + + /* Reinitialize SBC Encoder with new parameters */ + SBC_Encoder_Init(&(a2dp_info.rsi_encoder)); + + return 0; +} +/*==============================================*/ +int16_t rsi_bt_sbc_encode(uint8_t *remote_dev_addr, + uint8_t *pcm_mp3_data, + uint16_t pcm_mp3_data_len, + uint16_t *bytes_consumed) +{ + int16_t err = 0; + + memcpy(a2dp_info.addr_s, remote_dev_addr, BT_ADDR_ARRAY_LEN); + + err = rsi_bt_a2dp_sbc_encode_task(pcm_mp3_data, pcm_mp3_data_len, bytes_consumed); + SL_PRINTF(SL_RSI_SBC_ENCODE, BLUETOOTH, LOG_INFO); + + return err; +} + +/*==============================================*/ +void reset_audio_params(void) +{ + while (rsi_sbc_queue.head != NULL) { + free_data_pkt((data_pkt_t *)&sbc_data_pool, rsi_sbc_queue.head); + del_from_list(&rsi_sbc_queue); + } + return; +} + +/*==============================================*/ +void rebuild_sbc_buffer(uint16_t prev_mtu, uint16_t curr_mtu) +{ + data_pkt_t *head = rsi_sbc_queue.head; + data_pkt_t *new_sbc_pkt = NULL; + uint8_t nmbr_of_queue_nodes = rsi_sbc_queue.pkt_cnt; + uint8_t old_node_head_idx = 0; + uint8_t new_node_head_idx = 0; + uint8_t sbc_frame_size = a2dp_info.rsi_encoder.u16PacketLength; + uint8_t prev_sbc_frames_cnt = 0; + uint8_t curr_sbc_frames_cnt = 0; + + /* Calculate the maximum number of SBC frames in each packet */ + if (sbc_frame_size != 0) { + prev_sbc_frames_cnt = (uint8_t)((prev_mtu - PKT_HEADER_AND_CRC - RTP_HEADER) / sbc_frame_size); + curr_sbc_frames_cnt = (uint8_t)((curr_mtu - PKT_HEADER_AND_CRC - RTP_HEADER) / sbc_frame_size); + } + + if ((prev_sbc_frames_cnt != curr_sbc_frames_cnt) && (sbc_frame_size != 0)) { + /* Allocate a data pkt to put the first packet rebuilt */ + new_sbc_pkt = (data_pkt_t *)alloc_data_pkt((data_pkt_t *)&sbc_data_pool); + if (new_sbc_pkt == NULL) { + return; + } + new_node_head_idx = 0; + + /* Loop for all Packets in Queue */ + while (nmbr_of_queue_nodes != 0) { + if (new_node_head_idx < curr_sbc_frames_cnt) { + /* Copy sbc frames over */ + memcpy((new_sbc_pkt->data + (new_node_head_idx * sbc_frame_size)), + (head->data + (old_node_head_idx * sbc_frame_size)), + sbc_frame_size * sizeof(uint8_t)); + new_node_head_idx++; + old_node_head_idx++; + } + + if (new_node_head_idx == curr_sbc_frames_cnt) { + /* Reached New MTU, add to the list */ + new_node_head_idx = 0; + new_sbc_pkt->data_len = curr_sbc_frames_cnt * sbc_frame_size; + add_to_list(&rsi_sbc_queue, new_sbc_pkt); + + /* Allocate another data pkt to store the next packet rebuilt */ + new_sbc_pkt = (data_pkt_t *)alloc_data_pkt((data_pkt_t *)&sbc_data_pool); + if (new_sbc_pkt == NULL) { + return; + } + new_node_head_idx = 0; + } + + if (old_node_head_idx == prev_sbc_frames_cnt) { + /* The data of this packet has been copied and can be released */ + nmbr_of_queue_nodes--; + old_node_head_idx = 0; + free_data_pkt((data_pkt_t *)&sbc_data_pool, rsi_sbc_queue.head); + del_from_list(&rsi_sbc_queue); + head = head->next; + } + } /* end of while */ + + if (new_node_head_idx != 0) { + /* The remaining sbc frames becomes the last packet */ + new_sbc_pkt->data_len = new_node_head_idx * sbc_frame_size; + new_node_head_idx = 0; + add_to_list(&rsi_sbc_queue, new_sbc_pkt); + } else { + /* Free unused packet */ + free_data_pkt((data_pkt_t *)&sbc_data_pool, new_sbc_pkt); + } + } + return; +} + +/*==============================================*/ +void update_modified_mtu_size(uint16_t rem_mtu_size) +{ + if (a2dp_info.mtu != rem_mtu_size) { + rsi_mutex_lock(&sbc_mutex); + /* Re-Build SBC Buffer */ + rebuild_sbc_buffer(a2dp_info.mtu, rem_mtu_size); + rsi_mutex_unlock(&sbc_mutex); + } + +#ifdef USE_REM_MTU_SIZE_ONLY + a2dp_info.mtu = rem_mtu_size; +#else + a2dp_info.mtu = (rem_mtu_size > DEFAULT_MTU_SIZE) ? rem_mtu_size : DEFAULT_MTU_SIZE; +#endif + return; +} + +#endif diff --git a/wiseconnect/sapi/bluetooth/rsi_bt_spp_apis.c b/wiseconnect/sapi/bluetooth/rsi_bt_spp_apis.c new file mode 100644 index 00000000..6a8b0980 --- /dev/null +++ b/wiseconnect/sapi/bluetooth/rsi_bt_spp_apis.c @@ -0,0 +1,147 @@ +/******************************************************************************* +* @file rsi_bt_spp_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +#ifdef RSI_BT_ENABLE + +#include "rsi_bt.h" +#include "rsi_bt_apis.h" +#include "rsi_bt_config.h" + +/** @addtogroup BT-CLASSIC4 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_spp_init(void) + * @brief Set the SPP profile mode. This is a blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + * + * @note Refer Error Codes section for common error codes \ref error-codes . + * + */ + +int32_t rsi_bt_spp_init(void) +{ + rsi_bt_req_profile_mode_t bt_req_spp_init = { 0 }; + bt_req_spp_init.profile_mode = RSI_SPP_PROFILE_BIT; + SL_PRINTF(SL_RSI_BT_SPP_INIT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SET_PROFILE_MODE, &bt_req_spp_init, NULL); +} +/*==============================================*/ +/** + * @fn int32_t rsi_bt_spp_connect(uint8_t *remote_dev_addr) + * @brief Initiate the SPP profile level connection. This is a blocking API. + * A received event \ref rsi_bt_on_spp_connect_t indicates that the connection opened successfully. + * @pre \ref rsi_bt_spp_init() API and \ref rsi_bt_connect() API needs to be called before this API + * @param[in] remote_dev_addr - Remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4501 - ERR_BT_SPP_NOT_INITIALISED \n + * 0x4046 - ERR_BT_INVALID_ARGS \n + * 0x4102 - ERR_SDP_SRV_NOT_FOUND + * + *@note Refer Error Codes section for common error codes \ref error-codes . + * + */ + +int32_t rsi_bt_spp_connect(uint8_t *remote_dev_addr) +{ + rsi_bt_req_connect_t bt_req_spp_connect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_spp_connect.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_spp_connect.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_SPP_CONN_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SPP_CONNECT, &bt_req_spp_connect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_spp_disconnect(uint8_t *remote_dev_addr) + * @brief Initiate the SPP Profile level disconnection. This is a blocking API. + * A received event \ref rsi_bt_on_spp_disconnect_t indicates that the spp connection is disconnected successfully. + * @pre \ref rsi_bt_spp_connect() API need to be called before this API + * @param[in] remote_dev_addr - This is the remote device address + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * 0x4501 - ERR_BT_SPP_NOT_INITIALISED \n + * 0x4500 - ERR_BT_SPP_NOT_CONNECTED + * + *@note Refer Error Codes section for common error codes \ref error-codes . + */ + +int32_t rsi_bt_spp_disconnect(uint8_t *remote_dev_addr) +{ + //This statement is added only to resolve compilation warning, value is unchanged + USED_PARAMETER(remote_dev_addr); + rsi_bt_req_disconnect_t bt_req_spp_disconnect = { { 0 } }; +#ifdef BD_ADDR_IN_ASCII + rsi_ascii_dev_address_to_6bytes_rev(bt_req_spp_disconnect.dev_addr, (int8_t *)remote_dev_addr); +#else + memcpy(bt_req_spp_disconnect.dev_addr, (int8_t *)remote_dev_addr, 6); +#endif + SL_PRINTF(SL_RSI_BT_SPP_DISCONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SPP_DISCONNECT, &bt_req_spp_disconnect, NULL); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_spp_transfer(uint8_t *remote_dev_addr, uint8_t *data, uint16_t length) + * @brief Transfers the data through SPP profile. This is a blocking API. + * @pre \ref rsi_bt_spp_connect() API needs to be called before this API. + * @param[in] remote_dev_addr - This is the remote device address + * @param[in] data - This is the data for transmission + * @param[in] length - This is the data length for transfer, Max length supported upto 1000 bytes + * @return 0 - Success \n + * Non Zero Value - Failure \n + * 0x4501 - ERR_BT_SPP_NOT_INITIALISED \n + * 0x4500 - ERR_BT_SPP_NOT_CONNECTED \n + * 0x4201 - ERR_BT_RFCOMM_DISCONNECTED \n + * 0x4049 - ERR_BT_SOCK_STATE_INVALID + * + *@note Refer Error Codes section for common error codes \ref error-codes . + * + */ + +int32_t rsi_bt_spp_transfer(uint8_t *remote_dev_addr, uint8_t *data, uint16_t length) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(remote_dev_addr); + uint16_t xfer_len = 0; + + rsi_bt_req_spp_transfer_t bt_req_spp_transfer = { 0 }; + xfer_len = RSI_MIN(length, RSI_BT_MAX_PAYLOAD_SIZE); + bt_req_spp_transfer.data_length = xfer_len; + + memcpy(bt_req_spp_transfer.data, data, xfer_len); + + SL_PRINTF(SL_RSI_BT_SPP_DISCONNECT_TRIGGER, BLUETOOTH, LOG_INFO); + return rsi_bt_driver_send_cmd(RSI_BT_REQ_SPP_TRANSFER, &bt_req_spp_transfer, NULL); +} + +#endif + +/** @} */ diff --git a/wiseconnect/sapi/common/rsi_apis_non_rom.c b/wiseconnect/sapi/common/rsi_apis_non_rom.c new file mode 100644 index 00000000..7763cd19 --- /dev/null +++ b/wiseconnect/sapi/common/rsi_apis_non_rom.c @@ -0,0 +1,166 @@ +/******************************************************************************* +* @file rsi_apis_non_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_apis_rom.h" +#include "rsi_driver.h" +#include "rsi_socket.h" +#include "rsi_wlan_non_rom.h" +#include "rsi_apis_rom.h" + +global_cb_t *global_cb; +global_cb_t *global_cb_p; +rsi_wlan_cb_non_rom_t *rsi_wlan_cb_non_rom; +rsi_socket_select_info_t *rsi_socket_select_info; +struct rom_apis_s *rom_apis; +#ifndef ROM_WIRELESS +const struct ROM_WL_API_S api_wl_s = { + +#ifdef RSI_WLAN_ENABLE + // Socket APIs + .rsi_get_application_socket_descriptor = &ROM_WL_rsi_get_application_socket_descriptor, + .calculate_buffers_required = &ROM_WL_calculate_buffers_required, + .calculate_length_to_send = &ROM_WL_calculate_length_to_send, +#endif + + // Scheduler + .rsi_scheduler_init = &ROM_WL_rsi_scheduler_init, + .rsi_get_event = &ROM_WL_rsi_get_event, + .rsi_scheduler = &ROM_WL_rsi_scheduler, + + // Packet Allocation Management + .rsi_pkt_pool_init = &ROM_WL_rsi_pkt_pool_init, + .rsi_pkt_alloc = &ROM_WL_rsi_pkt_alloc, + .rsi_pkt_free = &ROM_WL_rsi_pkt_free, + .rsi_is_pkt_available = &ROM_WL_rsi_is_pkt_available, + + // Queue Management + .rsi_queues_init = &ROM_WL_rsi_queues_init, + .rsi_enqueue_pkt = &ROM_WL_rsi_enqueue_pkt, + .rsi_dequeue_pkt = &ROM_WL_rsi_dequeue_pkt, + .rsi_check_queue_status = &ROM_WL_rsi_check_queue_status, + .rsi_block_queue = &ROM_WL_rsi_block_queue, + .rsi_unblock_queue = &ROM_WL_rsi_unblock_queue, + .rsi_enqueue_pkt_from_isr = &ROM_WL_rsi_enqueue_pkt_from_isr, + + // Events + .rsi_set_event = &ROM_WL_rsi_set_event, + .rsi_clear_event = &ROM_WL_rsi_clear_event, + .rsi_mask_event = &ROM_WL_rsi_mask_event, + .rsi_unmask_event = &ROM_WL_rsi_unmask_event, + .rsi_find_event = &ROM_WL_rsi_find_event, + .rsi_register_event = &ROM_WL_rsi_register_event, + .rsi_set_event_from_isr = &ROM_WL_rsi_set_event_from_isr, + .rsi_unmask_event_from_isr = &ROM_WL_rsi_unmask_event_from_isr, + + // Utils + .rsi_uint16_to_2bytes = &ROM_WL_rsi_uint16_to_2bytes, + .rsi_uint32_to_4bytes = &ROM_WL_rsi_uint32_to_4bytes, + .rsi_bytes2R_to_uint16 = &ROM_WL_rsi_bytes2R_to_uint16, + .rsi_bytes4R_to_uint32 = &ROM_WL_rsi_bytes4R_to_uint32, + +#ifdef RSI_M4_INTERFACE + // M4 HAL + .rsi_m4_interrupt_isr = &ROM_WL_rsi_m4_interrupt_isr, + .mask_ta_interrupt = &ROM_WL_mask_ta_interrupt, + .unmask_ta_interrupt = &ROM_WL_unmask_ta_interrupt, + .rsi_frame_read = &ROM_WL_rsi_frame_read, + .rsi_frame_write = &ROM_WL_rsi_frame_write, + .rsi_submit_rx_pkt = &ROM_WL_rsi_submit_rx_pkt +#endif +}; + +ROM_WL_API_T *api_wl = NULL; +#endif + +extern rsi_socket_info_t *rsi_socket_pool; + +void rom_init(void) +{ +#ifndef ROM_WIRELESS + api_wl = &api_wl_s; +#endif + + global_cb_p = global_cb; + + global_cb_p->rsi_driver_cb = rsi_driver_cb; +#ifdef RSI_WLAN_ENABLE + global_cb_p->rsi_socket_pool = rsi_socket_pool; +#endif + global_cb_p->rom_apis_p = rom_apis; + global_cb_p->no_of_sockets = RSI_NUMBER_OF_SOCKETS; +#ifdef RSI_LITTLE_ENDIAN + global_cb_p->endian = IS_LITTLE_ENDIAN; +#else + global_cb_p->endian = IS_BIG_ENDIAN; +#endif + +#ifdef RX_BUFFER_MEM_COPY + global_cb_p->rx_buffer_mem_copy = 1; +#else + global_cb_p->rx_buffer_mem_copy = 0; +#endif + + global_cb_p->rsi_tcp_listen_min_backlog = RSI_TCP_LISTEN_MIN_BACKLOG; + +#ifdef RSI_WITH_OS + global_cb_p->os_enabled = 1; +#else + global_cb_p->os_enabled = 0; +#endif + + global_cb_p->rsi_max_num_events = RSI_MAX_NUM_EVENTS; + +#ifdef RSI_M4_INTERFACE + global_cb_p->tx_desc = &tx_desc[0]; + global_cb_p->rx_desc = &rx_desc[0]; +#endif + + global_cb_p->rom_apis_p->rsi_mutex_create = rsi_mutex_create; + global_cb_p->rom_apis_p->rsi_mutex_lock = rsi_mutex_lock; + global_cb_p->rom_apis_p->rsi_mutex_unlock = rsi_mutex_unlock; + global_cb_p->rom_apis_p->rsi_semaphore_create = rsi_semaphore_create; + global_cb_p->rom_apis_p->rsi_critical_section_entry = rsi_critical_section_entry; + global_cb_p->rom_apis_p->rsi_critical_section_exit = rsi_critical_section_exit; + global_cb_p->rom_apis_p->rsi_semaphore_wait = rsi_semaphore_wait; + global_cb_p->rom_apis_p->rsi_semaphore_post = rsi_semaphore_post; +#ifdef RSI_M4_INTERFACE + global_cb_p->rom_apis_p->rsi_semaphore_post_from_isr = rsi_semaphore_post_from_isr; + global_cb_p->rom_apis_p->rsi_mask_ta_interrupt = rsi_mask_ta_interrupt; + global_cb_p->rom_apis_p->rsi_unmask_ta_interrupt = rsi_unmask_ta_interrupt; +#endif +#ifdef RSI_WLAN_ENABLE + global_cb_p->rom_apis_p->rsi_driver_wlan_send_cmd = rsi_driver_wlan_send_cmd; + global_cb_p->rom_apis_p->rsi_driver_send_data = rsi_driver_send_data; +#endif + global_cb_p->rom_apis_p->rsi_delay_ms = rsi_delay_ms; +#ifdef RSI_M4_INTERFACE + global_cb_p->rom_apis_p->rsi_assertion = rsi_assertion; +#endif + +#ifdef RSI_WLAN_ENABLE +#ifdef ROM_WIRELESS + global_cb_p->rom_apis_p->ROM_WL_calculate_length_to_send = ROMAPI_WL->calculate_length_to_send; +#else + global_cb_p->rom_apis_p->ROM_WL_calculate_length_to_send = api_wl->calculate_length_to_send; +#endif +#endif +} diff --git a/wiseconnect/sapi/common/rsi_apis_rom.c b/wiseconnect/sapi/common/rsi_apis_rom.c new file mode 100644 index 00000000..17298c6d --- /dev/null +++ b/wiseconnect/sapi/common/rsi_apis_rom.c @@ -0,0 +1,83 @@ +/******************************************************************************* +* @file rsi_apis_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_apis_rom.h" +#include "rsi_driver.h" +#include "rsi_socket.h" + +#ifndef ROM_WIRELESS + +const struct ROM_WL_API_S wl_api = { +#ifdef RSI_WLAN_ENABLE + // Socket APIs + .rsi_get_application_socket_descriptor = &ROM_WL_rsi_get_application_socket_descriptor, + .calculate_buffers_required = &ROM_WL_calculate_buffers_required, + .calculate_length_to_send = &ROM_WL_calculate_length_to_send, +#endif + + // Scheduler + .rsi_scheduler_init = &ROM_WL_rsi_scheduler_init, + .rsi_get_event = &ROM_WL_rsi_get_event, + .rsi_scheduler = &ROM_WL_rsi_scheduler, + + // Packet Allocation Management + .rsi_pkt_pool_init = &ROM_WL_rsi_pkt_pool_init, + .rsi_pkt_alloc = &ROM_WL_rsi_pkt_alloc, + .rsi_pkt_free = &ROM_WL_rsi_pkt_free, + .rsi_is_pkt_available = &ROM_WL_rsi_is_pkt_available, + + // Queue Management + .rsi_queues_init = &ROM_WL_rsi_queues_init, + .rsi_enqueue_pkt = &ROM_WL_rsi_enqueue_pkt, + .rsi_dequeue_pkt = &ROM_WL_rsi_dequeue_pkt, + .rsi_check_queue_status = &ROM_WL_rsi_check_queue_status, + .rsi_block_queue = &ROM_WL_rsi_block_queue, + .rsi_unblock_queue = &ROM_WL_rsi_unblock_queue, + .rsi_enqueue_pkt_from_isr = &ROM_WL_rsi_enqueue_pkt_from_isr, + + // Events + .rsi_set_event = &ROM_WL_rsi_set_event, + .rsi_clear_event = &ROM_WL_rsi_clear_event, + .rsi_mask_event = &ROM_WL_rsi_mask_event, + .rsi_unmask_event = &ROM_WL_rsi_unmask_event, + .rsi_find_event = &ROM_WL_rsi_find_event, + .rsi_register_event = &ROM_WL_rsi_register_event, + .rsi_set_event_from_isr = &ROM_WL_rsi_set_event_from_isr, + .rsi_unmask_event_from_isr = &ROM_WL_rsi_unmask_event_from_isr, + + // Utils + .rsi_uint16_to_2bytes = &ROM_WL_rsi_uint16_to_2bytes, + .rsi_uint32_to_4bytes = &ROM_WL_rsi_uint32_to_4bytes, + .rsi_bytes2R_to_uint16 = &ROM_WL_rsi_bytes2R_to_uint16, + .rsi_bytes4R_to_uint32 = &ROM_WL_rsi_bytes4R_to_uint32, + +#ifdef RSI_M4_INTERFACE + // M4 HAL + .rsi_m4_interrupt_isr = &ROM_WL_rsi_m4_interrupt_isr, + .mask_ta_interrupt = &ROM_WL_mask_ta_interrupt, + .unmask_ta_interrupt = &ROM_WL_unmask_ta_interrupt, + .rsi_frame_read = &ROM_WL_rsi_frame_read, + .rsi_frame_write = &ROM_WL_rsi_frame_write, + .rsi_submit_rx_pkt = &ROM_WL_rsi_submit_rx_pkt +#endif +}; +#endif diff --git a/wiseconnect/sapi/common/rsi_common_apis.c b/wiseconnect/sapi/common/rsi_common_apis.c new file mode 100644 index 00000000..acdbac34 --- /dev/null +++ b/wiseconnect/sapi/common/rsi_common_apis.c @@ -0,0 +1,2791 @@ +/******************************************************************************* +* @file rsi_common_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#ifdef RSI_M4_INTERFACE +#include "rsi_ipmu.h" +#endif +#include "rsi_timer.h" +#ifdef RSI_BT_ENABLE +#include "rsi_bt.h" +#include "rsi_bt_config.h" +#endif +#ifdef RSI_BLE_ENABLE +#include "rsi_ble.h" +#endif + +#include "rsi_wlan_non_rom.h" +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; +extern rsi_socket_select_info_t *rsi_socket_select_info; +#ifdef PROCESS_SCAN_RESULTS_AT_HOST +extern struct wpa_scan_results_arr *scan_results_array; +#endif +/* + Global Variables + * */ +rsi_driver_cb_t *rsi_driver_cb = NULL; +#ifdef RSI_M4_INTERFACE +extern efuse_ipmu_t global_ipmu_calib_data; +#endif +extern global_cb_t *global_cb; +extern rom_apis_t *rom_apis; +extern void rom_init(void); +int32_t rsi_driver_memory_estimate(void); + +/* For Remove sapi Wranings*/ +#if defined(RSI_SDIO_INTERFACE) +void rsi_sdio_deinit(void); +#endif + +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * @brief Return the common control block status. This is a non-blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_device_init() API should be called before this API + */ + +int32_t rsi_common_get_status(void) +{ + return rsi_driver_cb->common_cb->status; +} + +/*==============================================*/ +/** + * @brief Set the common control block status. This is a non-blocking API. + * @param[in] status - Status of common control block + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private + +void rsi_common_set_status(int32_t status) +{ + rsi_driver_cb->common_cb->status = status; +} + +/*==============================================*/ +/** + * + * @brief Initialize WiSeConnect driver. This is a non-blocking API. + * Designate memory to all driver components from the buffer provided by the application. + * ...........Initilize Scheduler, Events, and Queues needed. + * @param[in] buffer - Pointer to buffer from application. \n Driver uses this buffer to hold driver control for its operation. + * @param[in] length - Length of the buffer. + * @return **Success** - Returns the memory used, which is less than or equal to buffer length provided. \n + * **Failure** - Non-Zero values\n + * + * **RSI_ERROR_TIMEOUT** - If UART initialization fails in SPI / UART mode \n + * + * **RSI_ERROR_INVALID_PARAM** - If maximum sockets is greater than 10 + */ + +uint8_t *buffer_addr = NULL; +int32_t rsi_driver_init(uint8_t *buffer, uint32_t length) +{ +#if (defined RSI_WLAN_ENABLE) || (defined RSI_UART_INTERFACE) || (defined LINUX_PLATFORM) + int32_t status = RSI_SUCCESS; +#endif + + uint32_t actual_length = 0; + + // If (((uint32_t)buffer & 3) != 0) + if (((uintptr_t)buffer & 3) != 0) // To avoid compiler warning, replace uint32_t with uintptr_t + { + // Making buffer 4 byte aligned + // Length -= (4 - ((uint32_t)buffer & 3)); + // To avoid compiler warning, replace uint32_t with uintptr_t + length -= (4 - ((uintptr_t)buffer & 3)); + // Buffer = (uint8_t *)(((uint32_t)buffer + 3) & ~3);// To avoid compiler warning, replace uint32_t with uintptr_t + buffer = (uint8_t *)(((uintptr_t)buffer + 3) & ~3); + } + + // Memset user buffer + memset(buffer, 0, length); + + actual_length += rsi_driver_memory_estimate(); + + // If length is not sufficient + if (length < actual_length) { + return actual_length; + } + buffer_addr = buffer; + + // Store length minus any alignment bytes to first 32-bit address in buffer. + *(uint32_t *)buffer = length; + buffer += sizeof(uint32_t); + + // Designate memory for driver cb + rsi_driver_cb = (rsi_driver_cb_t *)buffer; + buffer += sizeof(rsi_driver_cb_t); + global_cb = (global_cb_t *)buffer; + buffer += sizeof(global_cb_t); + rom_apis = (rom_apis_t *)buffer; + buffer += sizeof(rom_apis_t); +#ifdef RSI_WLAN_ENABLE + // Memory for sockets + rsi_socket_pool = (rsi_socket_info_t *)buffer; + buffer += RSI_SOCKET_INFO_POOL_SIZE; + rsi_socket_pool_non_rom = (rsi_socket_info_non_rom_t *)buffer; + buffer += RSI_SOCKET_INFO_POOL_ROM_SIZE; + rsi_socket_select_info = (rsi_socket_select_info_t *)buffer; + buffer += RSI_SOCKET_SELECT_INFO_POOL_SIZE; + rsi_wlan_cb_non_rom = (rsi_wlan_cb_non_rom_t *)buffer; + buffer += RSI_WLAN_CB_NON_ROM_POOL_SIZE; +#ifdef PROCESS_SCAN_RESULTS_AT_HOST + scan_results_array = (struct wpa_scan_results_arr *)buffer; + buffer += sizeof(struct wpa_scan_results_arr); +#endif + + // Check for max no of sockets + if (RSI_NUMBER_OF_SOCKETS > (10 + RSI_NUMBER_OF_LTCP_SOCKETS)) { + status = RSI_ERROR_INVALID_PARAM; + SL_PRINTF(SL_DRIVER_INIT_MAX_SOCKETS_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + +// Disabled in M4 A11 condition; Enabled in rest all condition. +#if !(defined(RSI_M4_INTERFACE) && !defined(A11_ROM)) + rsi_driver_cb->event_list = (rsi_event_cb_t *)buffer; + buffer += RSI_EVENT_INFO_POOL_SIZE; +#endif + + rom_init(); + + // Designate memory for rx_pool +#if !((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) + rsi_pkt_pool_init(&rsi_driver_cb->rx_pool, buffer, RSI_DRIVER_RX_POOL_SIZE, RSI_DRIVER_RX_PKT_LEN); + buffer += RSI_DRIVER_RX_POOL_SIZE; +#endif + // Designate memory for common_cb + rsi_driver_cb_non_rom = (rsi_driver_cb_non_rom_t *)buffer; + buffer += sizeof(rsi_driver_cb_non_rom_t); + +#ifdef SAPI_LOGGING_ENABLE + buffer += sl_log_init(buffer); +#endif +#ifdef FW_LOGGING_ENABLE + buffer += sl_fw_log_init(buffer); +#endif + + // Designate memory for common_cb + rsi_driver_cb->common_cb = (rsi_common_cb_t *)buffer; + buffer += sizeof(rsi_common_cb_t); + + // Initialize common cb + rsi_common_cb_init(rsi_driver_cb->common_cb); + + // Designate pool for common block + rsi_pkt_pool_init(&rsi_driver_cb->common_cb->common_tx_pool, buffer, RSI_COMMON_POOL_SIZE, RSI_COMMON_CMD_LEN); + buffer += RSI_COMMON_POOL_SIZE; + + // Designate memory for wlan block + rsi_driver_cb->wlan_cb = (rsi_wlan_cb_t *)buffer; + buffer += sizeof(rsi_wlan_cb_t); + +#ifdef RSI_M4_INTERFACE + // Designate memory for efuse ipmu block + rsi_driver_cb->common_cb->ipmu_calib_data_cb = (efuse_ipmu_t *)buffer; + // ipmu_calib_data_cb = (efuse_ipmu_t *)buffer; + // efuse_size = sizeof(efuse_ipmu_t); + buffer += RSI_M4_MEMORY_POOL_SIZE; +#endif +#ifdef RSI_WLAN_ENABLE + // Initialize wlan cb + rsi_wlan_cb_init(rsi_driver_cb->wlan_cb); +#endif + + // Designate memory for wlan_cb pool + rsi_pkt_pool_init(&rsi_driver_cb->wlan_cb->wlan_tx_pool, buffer, RSI_WLAN_POOL_SIZE, RSI_WLAN_CMD_LEN); + buffer += RSI_WLAN_POOL_SIZE; + + // Initialize scheduler + rsi_scheduler_init(&rsi_driver_cb->scheduler_cb); + + // Initialize events + rsi_events_init(); + + rsi_queues_init(&rsi_driver_cb->wlan_tx_q); + + rsi_queues_init(&rsi_driver_cb->common_tx_q); +#ifdef RSI_M4_INTERFACE + rsi_queues_init(&rsi_driver_cb->m4_tx_q); + + rsi_queues_init(&rsi_driver_cb->m4_rx_q); + +#endif +#ifdef RSI_ZB_ENABLE + rsi_driver_cb->zigb_cb = (rsi_zigb_cb_t *)buffer; + buffer += sizeof(rsi_zigb_cb_t); + + // Initialize zigb cb + rsi_zigb_cb_init(rsi_driver_cb->zigb_cb); + + // Designate memory for zigb_cb buffer pool + rsi_pkt_pool_init(&rsi_driver_cb->zigb_cb->zigb_tx_pool, buffer, RSI_ZIGB_POOL_SIZE, RSI_ZIGB_CMD_LEN); + buffer += RSI_ZIGB_POOL_SIZE; + +#ifdef ZB_MAC_API + rsi_driver_cb->zigb_cb->zigb_global_mac_cb = (rsi_zigb_global_mac_cb_t *)buffer; + buffer += sizeof(rsi_zigb_global_mac_cb_t); + // Fill in zigb_global_cb + buffer += rsi_zigb_global_mac_cb_init(buffer); +#else + rsi_driver_cb->zigb_cb->zigb_global_cb = (rsi_zigb_global_cb_t *)buffer; + buffer += sizeof(rsi_zigb_global_cb_t); + + // Fill in zigb_global_cb + buffer += rsi_zigb_global_cb_init(buffer); +#endif + rsi_queues_init(&rsi_driver_cb->zigb_tx_q); +#ifdef ZB_DEBUG + printf("\n ZIGB POOL INIT \n"); +#endif +#endif + +#if defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE) + // Designate memory for bt_common_cb + rsi_driver_cb->bt_common_cb = (rsi_bt_cb_t *)buffer; + buffer += ((sizeof(rsi_bt_cb_t) + 3) & ~3); + + // Initialize bt_common_cb + rsi_bt_cb_init(rsi_driver_cb->bt_common_cb, RSI_PROTO_BT_COMMON); + + // Designate memory for bt_common_cb pool + rsi_pkt_pool_init(&rsi_driver_cb->bt_common_cb->bt_tx_pool, buffer, RSI_BT_COMMON_POOL_SIZE, RSI_BT_COMMON_CMD_LEN); + buffer += ((RSI_BT_COMMON_POOL_SIZE + 3) & ~3); + + rsi_queues_init(&rsi_driver_cb->bt_single_tx_q); +#endif + +#ifdef RSI_BT_ENABLE + // Designate memory for bt_classic_cb + rsi_driver_cb->bt_classic_cb = (rsi_bt_cb_t *)buffer; + buffer += ((sizeof(rsi_bt_cb_t) + 3) & ~3); + + // Initialize bt_classic_cb + rsi_bt_cb_init(rsi_driver_cb->bt_classic_cb, RSI_PROTO_BT_CLASSIC); + + // Designate memory for bt_classic_cb pool + rsi_pkt_pool_init(&rsi_driver_cb->bt_classic_cb->bt_tx_pool, + buffer, + RSI_BT_CLASSIC_POOL_SIZE, + RSI_BT_CLASSIC_CMD_LEN); + buffer += ((RSI_BT_CLASSIC_POOL_SIZE + 3) & ~3); +#endif + +#ifdef RSI_BLE_ENABLE + // Designate memory for ble_cb + rsi_driver_cb->ble_cb = (rsi_bt_cb_t *)buffer; + buffer += ((sizeof(rsi_bt_cb_t) + 3) & ~3); + + // Initialize ble_cb + rsi_bt_cb_init(rsi_driver_cb->ble_cb, RSI_PROTO_BLE); + + // Designate memory for ble_cb pool + rsi_pkt_pool_init(&rsi_driver_cb->ble_cb->bt_tx_pool, buffer, RSI_BLE_POOL_SIZE, RSI_BLE_CMD_LEN); + buffer += ((RSI_BLE_POOL_SIZE + 3) & ~3); +#endif + +#ifdef RSI_PROP_PROTOCOL_ENABLE + // Designate memory for prop_protocol_cb + rsi_driver_cb->prop_protocol_cb = (rsi_bt_cb_t *)buffer; + buffer += ((sizeof(rsi_bt_cb_t) + 3) & ~3); + + // Initialize prop_protocol_cb + rsi_bt_cb_init(rsi_driver_cb->prop_protocol_cb, RSI_PROTO_PROP_PROTOCOL); + + // Designate memory for prop_protocol_cb pool + rsi_pkt_pool_init(&rsi_driver_cb->prop_protocol_cb->bt_tx_pool, + buffer, + RSI_PROP_PROTOCOL_POOL_SIZE, + RSI_PROP_PROTOCOL_CMD_LEN); + buffer += ((RSI_PROP_PROTOCOL_POOL_SIZE + 3) & ~3); + + rsi_queues_init(&rsi_driver_cb->prop_protocol_tx_q); +#endif + +#ifdef SAPIS_BT_STACK_ON_HOST + // Designate memory for bt_classic_cb + rsi_driver_cb->bt_ble_stack_cb = (rsi_bt_cb_t *)buffer; + buffer += sizeof(rsi_bt_cb_t); + + // Initialize bt_classic_cb + rsi_bt_cb_init(rsi_driver_cb->bt_ble_stack_cb, RSI_PROTO_BT_BLE_STACK); + + // Designate memory for bt_classic_cb pool + rsi_pkt_pool_init(&rsi_driver_cb->bt_ble_stack_cb->bt_tx_pool, + buffer, + RSI_BT_CLASSIC_POOL_SIZE, + RSI_BT_CLASSIC_CMD_LEN); + buffer += RSI_BT_CLASSIC_POOL_SIZE; + + rsi_queues_init(&rsi_driver_cb->bt_ble_stack_tx_q); + +#endif +#if defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE) + // Designate memory for bt_common_cb + rsi_driver_cb->bt_global_cb = (rsi_bt_global_cb_t *)buffer; + buffer += sizeof(rsi_bt_global_cb_t); + + // Fill in bt_global_cb + buffer += rsi_bt_global_cb_init(rsi_driver_cb, buffer); +#endif + + if (length < (uint32_t)(buffer - buffer_addr)) { + SL_PRINTF(SL_DRIVER_INIT_INSUFFICIENT_BUFFER_2, COMMON, LOG_ERROR, "length: %4x", (uint32_t)(buffer - buffer_addr)); + return buffer - buffer_addr; + } + +#ifndef LINUX_PLATFORM +#ifdef RSI_SPI_INTERFACE + rsi_timer_start(RSI_TIMER_NODE_0, + RSI_HAL_TIMER_TYPE_PERIODIC, + RSI_HAL_TIMER_MODE_MILLI, + 1, + rsi_timer_expiry_interrupt_handler); +#endif + +#if (defined(RSI_SPI_INTERFACE) || defined(RSI_SDIO_INTERFACE) || defined(RSI_UART_INTERFACE)) + // Configure power save GPIOs + rsi_powersave_gpio_init(); +#endif +#endif + +#ifdef LINUX_PLATFORM +#if (defined(RSI_USB_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + status = rsi_linux_app_init(); + if (status != RSI_SUCCESS) { + return status; + } + +#endif +#endif + +#ifdef RSI_UART_INTERFACE + // UART initialization + status = rsi_uart_init(); + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_DRIVER_INIT_UART_INIT_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + + // Update state + rsi_driver_cb_non_rom->device_state = RSI_DRIVER_INIT_DONE; + + SL_PRINTF(SL_DRIVER_INIT_EXIT, COMMON, LOG_INFO, "actual_length=%4x", actual_length); + return actual_length; +} +/** @} */ + +/** @addtogroup COMMON +* @{ +*/ + +/*==============================================*/ + +/** + * @brief Configure the WLAN/Coex operating mode and also configures features based on bitmaps available in rsi_wlan_config.h. + * In case of failure, appropriate error code is returned to the application. Default configurations (for reference) are available in rsi_wlan_common_config.h. + * Based on the features required for a specific example, modify the rsi_wlan_config.h provided in the respective example folder. + * For more information about the bitmaps, refer \ref Opermode-Parameters + * This is a blocking API. + * @pre \ref rsi_device_init() API needs to be called before this API. + * @param[in] opermode - WLAN Operating mode \n + * 0 - Client mode \n + * 2 - Enterprise security client mode \n + * 6 - Access point mode \n + * 8 - Transmit test mode \n + * 9 - Concurrent mode + * @param[in] coex_mode - Coexistence mode + * 0 - WLAN only mode \n + * 1 - WLAN \n + * 5 - WLAN + Bluetooth \n + * 9 - WLAN + Dual Mode (Bluetooth and BLE) \n + * 13- WLAN + BLE \n + * + * @note **Precondition** - \ref rsi_device_init() API needs to be called before this API + * @note WLAN operating mode 1 - WiFi-Direct mode is not supported. + * @note Coex modes are supported only in 384K memory configuration. + * @note Coex mode 4(Bluetooth classic), 8 (Dual mode), and 12(BLE mode) are not supported. + * @note To achieve the same functionality, use coex mode 5, 9, and 13 respectively instead of coex mode 4, 8, and 12. + * + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0x0021,0x0025,0xFF73,0x002C,0xFF6E,0xFF6F, 0xFF70,0xFFC5) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_wireless_init(uint16_t opermode, uint16_t coex_mode) +{ + rsi_pkt_t *pkt; + rsi_opermode_t *rsi_opermode; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WIRELESS_INIT_ENTRY, COMMON, LOG_INFO); +#if !((defined(RSI_UART_INTERFACE) && defined(RSI_STM32))) + rsi_timer_instance_t timer_instance; +#endif +#ifdef RSI_M4_INTERFACE + // int32_t ipmu_status = RSI_SUCCESS; + +#endif + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((rsi_driver_cb_non_rom->device_state < RSI_DEVICE_INIT_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + common_cb->ps_coex_mode = coex_mode; + common_cb->ps_coex_mode &= ~BIT(0); + +#if (defined(RSI_UART_INTERFACE) && defined(RSI_STM32)) + common_cb->state = RSI_COMMON_CARDREADY; +#else + rsi_init_timer(&timer_instance, RSI_CARD_READY_WAIT_TIME); + // If state is not in card ready received state + while (common_cb->state == RSI_COMMON_STATE_NONE) { +#ifndef RSI_WITH_OS + // Wait until receive card ready + rsi_scheduler(&rsi_driver_cb->scheduler_cb); + + if (rsi_timer_expired(&timer_instance)) { + SL_PRINTF(SL_WIRELESS_INIT_CARD_READY_TIMEOUT, COMMON, LOG_ERROR); + return RSI_ERROR_CARD_READY_TIMEOUT; + } +#else +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(3); +#endif +#ifdef RSI_WITH_OS + if (rsi_wait_on_common_semaphore(&common_cb->common_card_ready_sem, RSI_CARD_READY_WAIT_TIME) != RSI_ERROR_NONE) { + SL_PRINTF(SL_WIRELESS_INIT_RESPONSE_TIMEOUT, COMMON, LOG_ERROR); + return RSI_ERROR_RESPONSE_TIMEOUT; + } +#endif +#endif + } +#endif + if (wlan_cb->auto_config_state != RSI_WLAN_STATE_NONE) { + while (1) { + // Check auto config state + + if ((wlan_cb->auto_config_state == RSI_WLAN_STATE_AUTO_CONFIG_DONE) + || (wlan_cb->auto_config_state == RSI_WLAN_STATE_AUTO_CONFIG_FAILED)) { + if (wlan_cb->state >= RSI_WLAN_STATE_INIT_DONE) { + common_cb->ps_coex_mode |= BIT(0); + } + wlan_cb->auto_config_state = 0; + break; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + +#ifdef RSI_WLAN_ENABLE + // Signal the WLAN semaphore + if (rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_AUTO_JOIN_RESPONSE_WAIT_TIME) + != RSI_ERROR_NONE) { + SL_PRINTF(SL_WIRELESS_INIT_RESPONSE_TIMEOUT, COMMON, LOG_ERROR); + return RSI_ERROR_RESPONSE_TIMEOUT; + } +#endif + } +#ifdef RSI_WLAN_ENABLE + status = rsi_common_get_status(); + if (status) { + // Return error + SL_PRINTF(SL_WIRELESS_INIT_EXIT1, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + status = rsi_wlan_get_status(); + if (status) { + // Return error + SL_PRINTF(SL_WIRELESS_INIT_EXIT2, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + // Auto configuration status + return RSI_USER_STORE_CFG_STATUS; + } else if (common_cb->state != RSI_COMMON_CARDREADY) { + // Command given in wrong state + SL_PRINTF(SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure + SL_PRINTF(SL_WIRELESS_INIT_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // memset the packet data + memset(&pkt->data, 0, sizeof(rsi_opermode_t)); + + // Take the user provided data and fill it in opermode mode structure + rsi_opermode = (rsi_opermode_t *)pkt->data; + + // Save opermode command + wlan_cb->opermode = opermode; + + // Fill coex and opermode parameters + rsi_uint32_to_4bytes(rsi_opermode->opermode, (coex_mode << 16 | opermode)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif +#if defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE) + // Save expected response type + rsi_driver_cb->bt_common_cb->expected_response_type = RSI_BT_EVENT_CARD_READY; + rsi_driver_cb->bt_common_cb->sync_rsp = 1; +#endif + // Send opermode command to driver + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_OPERMODE, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_OPERMODE_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_WIRELESS_INIT_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + +#if defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE) + if (!status) { + if ((coex_mode == RSI_OPERMODE_WLAN_BLE) || (coex_mode == RSI_OPERMODE_WLAN_BT_CLASSIC) + || (coex_mode == RSI_OPERMODE_WLAN_BT_DUAL_MODE) +#if defined(RSI_PROP_PROTOCOL_ENABLE) + || (coex_mode == RSI_OPERMODE_PROP_PROTOCOL) +#endif + ) { + // WC waiting for BT Classic/ZB/BLE card ready + rsi_bt_common_init(); + } + } +#endif + +#ifdef RSI_M4_INTERFACE + // ipmu_status = rsi_cmd_m4_ta_secure_handshake(2,0,NULL,sizeof(efuse_ipmu_t),(uint8_t *)&global_ipmu_calib_data); + // RSI_IPMU_UpdateIpmuCalibData(&global_ipmu_calib_data); +#endif + + // Return status + SL_PRINTF(SL_WIRELESS_INIT_EXIT3, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ +/*==============================================*/ + +/** @addtogroup COMMON +* @{ +*/ +/** + * @brief Enable or disable UART flow control. This is a blocking API. + * @param[in] uartflow_en - Enable or Disable UART hardware flow control \n + * 1/2 - Enable and Pin set to be used to for RTS/CTS purpose. \n + * 0 - Disable \n + * If the parameter is given as 1 or 2, then UART hardware flow control is enabled and Pin set to be used \n + * If parameter is given as 1: Pin set used for RTS/CTS functionality is: \n + * UART_CTS: GPIO - 11 \n + * UART_RTS: GPIO - 7 \n + * If parameter is given as 2: Pin set used for RTS/CTS functionality is: \n + * UART_CTS: GPIO - 15 \n + * UART_RTS: GPIO - 12 + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note Hardware flow control feature is not supported in Auto-Join/Auto-Create mode. \n + * In such a case, the feature has to be enabled separately. + * + */ +int32_t rsi_cmd_uart_flow_ctrl(uint8_t uartflow_en) +{ + rsi_pkt_t *pkt; + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_CMD_UART_FLOW_CTRL_ENTRY, COMMON, LOG_INFO); + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_CMD_UART_FLOW_CTRL_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pkt->data[0] = uartflow_en; +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send antenna select command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_UART_FLOW_CTRL_ENABLE, pkt); + + //Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_UART_FLOW_CTRL_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_CMD_UART_FLOW_CTRL_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_CMD_UART_FLOW_CTRL_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +#ifdef RSI_M4_INTERFACE +#ifdef CHIP_9117 +/*==============================================*/ +/** + * @brief To write content on TA flash from M4. This is a blocking API. + * @param[in] wr_addr - address at which data will be written on TA flash memory + * @param[in] write_data - Input data + * @param[in] wr_data_len - total length + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * + */ +int32_t rsi_cmd_to_wr_comm_flash(uint32_t wr_addr, uint8_t *write_data, uint16_t wr_data_len) +{ + static uint32_t rem_len; + uint16_t chunk_size = 0; + static uint32_t offset; + rsi_pkt_t *pkt; + rsi_req_ta2m4_t *rsi_chunk_ptr; + int32_t status = RSI_SUCCESS; + + SL_PRINTF(SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY, COMMON, LOG_INFO); + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + + if (status == RSI_SUCCESS) { + + // Get the chunk size + chunk_size = RSI_MAX_CHUNK_SIZE - (sizeof(rsi_req_ta2m4_t) - RSI_MAX_CHUNK_SIZE); + + // Get input length + rem_len = wr_data_len; + + while (rem_len) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + // Return packet allocation failure error + SL_PRINTF(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + rsi_chunk_ptr = (rsi_req_ta2m4_t *)pkt->data; + + memset(&pkt->data, 0, RSI_MAX_CHUNK_SIZE); + + // Take the sub_cmd_type for TA and M4 commands + rsi_chunk_ptr->sub_cmd = RSI_WRITE_TO_COMMON_FLASH; + + // Writes on which TA Flash location + rsi_chunk_ptr->addr = wr_addr; + + // Total remaining length + rsi_chunk_ptr->in_buf_len = rem_len; + + if (rem_len >= chunk_size) { + + //Total chunck length + rsi_chunk_ptr->chunk_len = chunk_size; + + // More chunks to send + rsi_chunk_ptr->more_chunks = 1; + + // Copy the chunk + memcpy(rsi_chunk_ptr->input_data, write_data + offset, chunk_size); + + // Move the offset by chunk size + offset += chunk_size; + + // Subtract the rem_len by the chunk size + rem_len -= chunk_size; + } else { + + rsi_chunk_ptr->chunk_len = rem_len; + + // last chunk to send + rsi_chunk_ptr->more_chunks = 0; + + // Copy the chunk + memcpy(rsi_chunk_ptr->input_data, write_data + offset, rem_len); + + // Reset rem_len and offset + rem_len = 0; + offset = 0; + } +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send antenna select command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_TA_M4_COMMANDS, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_TA_M4_COMMAND_RESPONSE_WAIT_TIME); + + // Get common command response status + status = rsi_common_get_status(); + } + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + } else { + // Return common command error + SL_PRINTF(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +#endif +/*==============================================*/ +/** + * @brief Secure handshake. This is a blocking API. + * @param[in] sub_cmd_type - Sub command + * @param[in] input_data - Input data + * @param[in] input_len - Length length + * @param[in] output_len - Output length + * @param[in] output_data - Output data + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * + */ + +int32_t rsi_cmd_m4_ta_secure_handshake(uint8_t sub_cmd_type, + uint8_t input_len, + uint8_t *input_data, + uint8_t output_len, + uint8_t *output_data) +{ + rsi_pkt_t *pkt; + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY, COMMON, LOG_INFO); + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the sub_cmd_type for TA and M4 commands + pkt->data[0] = sub_cmd_type; + + pkt->data[1] = input_len; + + memcpy(&pkt->data[2], input_data, input_len); + + // Attach the buffer given by user + common_cb->app_buffer = output_data; + + // Length of buffer provided by user + common_cb->app_buffer_length = output_len; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send antenna select command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_TA_M4_COMMANDS, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_TA_M4_COMMAND_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +#endif +/** @} */ + +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * @brief Resets the module to a state that was before execution of \ref rsi_wireless_init + * To choose the new configuration(operating mode) rsi_wireless_init() API needs to be called after this API. + * This is a blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * + * @note To restart the RS9116W module from the host, the application needs to call rsi_driver_deinit() + * followed by rsi_driver_init() and rsi_device_init(). + * For OS cases, additionally needs to call rsi_task_destroy(driver_task_handle) to delete the driver task before calling + * rsi_driver_deinit() and should create again, after rsi_device_init() using rsi_task_create() + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_wireless_deinit(void) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WIRELESS_DEINIT_ENTRY, COMMON, LOG_INFO); +#ifndef RSI_M4_INTERFACE + int32_t length = 0; +#endif +#ifdef RSI_M4_INTERFACE + rsi_pkt_t *pkt; + // Get common cb structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WIRELESS_DEINIT_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Send softreset command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_SOFT_RESET, pkt); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_WIRELESS_DEINIT_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#ifdef SOFT_RESET_ENABLE + // Mask interrupts + rsi_hal_intr_mask(); +#endif +#ifdef SOFT_RESET_ENABLE + // Unmask interrupts + rsi_hal_intr_unmask(); +#endif + +#ifdef RSI_UART_INTERFACE + rsi_uart_deinit(); + +#endif +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(2); +#endif + + // Wait on common semaphore + if (rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_DEINIT_RESPONSE_WAIT_TIME) + != RSI_ERROR_NONE) { + return RSI_ERROR_RESPONSE_TIMEOUT; + } + + // Get common status + status = rsi_common_get_status(); +#else + + if (buffer_addr != NULL) { + length = *(uint32_t *)buffer_addr; + // Driver initialization + status = rsi_driver_init(buffer_addr, length); + if ((status < 0) || (status > length)) { + SL_PRINTF(SL_WIRELESS_DEINIT_DRIVER_INIT_ERROR_1, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + } else { + return -1; + } + + // State update + rsi_driver_cb->common_cb->state = RSI_COMMON_STATE_NONE; +#ifdef RSI_WLAN_ENABLE + rsi_driver_cb->wlan_cb->state = RSI_WLAN_STATE_NONE; +#endif + + // Deinitializing SDIO Interface +#if defined(RSI_SDIO_INTERFACE) + rsi_sdio_deinit(); +#endif + // Initialize Device + status = rsi_device_init(LOAD_NWP_FW); + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_WIRELESS_DEINIT_DEVICE_INIT_ERROR_2, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + +#endif + SL_PRINTF(SL_WIRELESS_DEINIT_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Select antenna type on the device. This is a blocking API. + * @param[in] type - 0 : RF_OUT_2/Internal Antenna is selected \n + * 1 : RF_OUT_1/uFL connector is selected. + * @param[in] gain_2g - Currently not supported + * @param[in] gain_5g - Currently not supported + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffc, 0x0025, 0x002C) \n + * + * @note **Precondition** - \ref rsi_wlan_radio_init API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_wireless_antenna(uint8_t type, uint8_t gain_2g, uint8_t gain_5g) +{ + + rsi_pkt_t *pkt; + rsi_antenna_select_t *rsi_antenna; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WIRELESS_ANTENNA_ENTRY, COMMON, LOG_INFO); + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + // Pre-condition for antenna selection + if ((wlan_cb->state < RSI_WLAN_STATE_INIT_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_WIRELESS_ANTENNA_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WIRELESS_ANTENNA_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in antenna select structure + rsi_antenna = (rsi_antenna_select_t *)pkt->data; + + // Antenna type + rsi_antenna->antenna_value = type; + + // Antenna gain in 2.4GHz + rsi_antenna->gain_2g = gain_2g; + + // Antenna gain in 5GHz + rsi_antenna->gain_5g = gain_5g; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send antenna select command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ANTENNA_SELECT, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_ANTENNA_SEL_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_WIRELESS_ANTENNA_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_WIRELESS_ANTENNA_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Select internal or external RF type, clock frequency and to pass Feature enables dynamically. + * This is a blocking API. + * @param[in] feature_enables - Feature enables \n + * BIT[0] - Enable Preamble duty cycling. \n + * BIT[4] - Enable LP chain for stand-by associate mode. \n + * BIT[5] - Enable hardware beacon drop during power save. \n + * Remaining bits are reserved. + * + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** -0xfffffffe, 0xfffffffd, 0xfffffffc, 0x0021, 0xFF74) \n + * + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_send_feature_frame_dyn(uint32_t feature_enables) +{ + + rsi_pkt_t *pkt; + rsi_feature_frame_t *rsi_feature_frame; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SEND_FEATURE_FRAME_ENTRY, COMMON, LOG_INFO); + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in antenna select structure + rsi_feature_frame = (rsi_feature_frame_t *)pkt->data; + + // PLL mode value + rsi_feature_frame->pll_mode = PLL_MODE; + + // RF type + rsi_feature_frame->rf_type = RF_TYPE; + + // Wireless mode + rsi_feature_frame->wireless_mode = WIRELESS_MODE; + + // Enable PPP + rsi_feature_frame->enable_ppp = ENABLE_PPP; + + // AFE type + rsi_feature_frame->afe_type = AFE_TYPE; + + // Feature enables + rsi_feature_frame->feature_enables = feature_enables; + + // Send antenna select command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_FEATURE_FRAME, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_FEATURE_FRAME_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_SEND_FEATURE_FRAME_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_SEND_FEATURE_FRAME_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Select internal or external RF type and clock frequency. + * This is a blocking API. + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0x0021, 0xFF74) \n + * If return value is less than 0 \n + * + * @note **Precondition** - \ref rsi_wireless_init API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_send_feature_frame(void) +{ + + rsi_pkt_t *pkt; + rsi_feature_frame_t *rsi_feature_frame; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SEND_FEATURE_FRAME_ENTRY, COMMON, LOG_INFO); + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in antenna select structure + rsi_feature_frame = (rsi_feature_frame_t *)pkt->data; + + // PLL mode value + rsi_feature_frame->pll_mode = PLL_MODE; + + // RF type + rsi_feature_frame->rf_type = RF_TYPE; + + // Wireless mode + rsi_feature_frame->wireless_mode = WIRELESS_MODE; + + // Enable PPP + rsi_feature_frame->enable_ppp = ENABLE_PPP; + + // AFE type + rsi_feature_frame->afe_type = AFE_TYPE; + + // Feature enables + rsi_feature_frame->feature_enables = + (RSI_WLAN_TRANSMIT_TEST_MODE == rsi_driver_cb->wlan_cb->opermode) + ? (FEATURE_ENABLES + & ~(RSI_FEAT_FRAME_PREAMBLE_DUTY_CYCLE | RSI_FEAT_FRAME_LP_CHAIN | RSI_FEAT_FRAME_IN_PACKET_DUTY_CYCLE)) + : FEATURE_ENABLES; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send antenna select command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_FEATURE_FRAME, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_FEATURE_FRAME_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_SEND_FEATURE_FRAME_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_SEND_FEATURE_FRAME_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Get firmware version present in the device. This is a blocking API. + * @param[in] length - Length of the response buffer in bytes to hold result. + * @param[out] response - Response of the requested command. + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0xfffffffa, 0x0021, 0x0025, 0x002c) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_get_fw_version(uint8_t *response, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_GET_FW_VERSION_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + + // Get common cb structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + // If state is not in card ready received state + if (common_cb->state == RSI_COMMON_STATE_NONE) { + while (common_cb->state != RSI_COMMON_CARDREADY) { +#ifndef RSI_WITH_OS + rsi_scheduler(&rsi_driver_cb->scheduler_cb); +#endif + } + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + // Return packet allocation failure error + SL_PRINTF(SL_GET_FW_VERSION_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (response != NULL) { + // Attach the buffer given by user + common_cb->app_buffer = response; + + // Length of the buffer provided by user + common_cb->app_buffer_length = length; + } else { + // Assign NULL to the app_buffer to avoid junk + common_cb->app_buffer = NULL; + + // Length of the buffer to 0 + common_cb->app_buffer_length = 0; + } + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send firmware version query request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_FW_VERSION, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_FWUP_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_GET_FW_VERSION_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_GET_FW_VERSION_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Get module type. This is a blocking API. + * @pre Need to call after the device initialization, \ref rsi_device_init API + * @param[out] response - Response of the requested command. \n + * 0 - B8 \n + * 1 - Q7 (QMS) \n + * 2 - Q7 + EXT FLASH \n + * 3 - DB_T \n + * 4 - SB \n + * 5 - M7DB (CC0) \n + * 6 - M4SB (B00) \n + * 7 - B6F \n + * 8 - B8SDB \n + * 9 - W2 \n + * 10 - WMS \n + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If return value is less than 0 \n + * -3: Command given in wrong state \n + * -4: Buffer not available to serve the command \n + * -6: Insufficient input buffer given \n + * If return value is greater than 0 \n + * 0x0021, 0x0025, 0x002c + * @note Refer to Error Codes section for above error codes \ref error-codes . + */ + +int32_t rsi_get_module_type(uint8_t *response) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt; + + if (rsi_driver_cb_non_rom->module_type_valid) { + *response = rsi_driver_cb_non_rom->module_type_id; + return RSI_SUCCESS; + } + // Get common cb structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + // if state is not in card ready received state + if (common_cb->state == RSI_COMMON_STATE_NONE) { + while (common_cb->state != RSI_COMMON_CARDREADY) { +#ifndef RSI_WITH_OS + rsi_scheduler(&rsi_driver_cb->scheduler_cb); +#endif + } + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (response != NULL) { + // attach the buffer given by user + common_cb->app_buffer = response; + + // length of the buffer provided by user + common_cb->app_buffer_length = 1; + } else { + // Assign NULL to the app_buffer to avoid junk + common_cb->app_buffer = NULL; + + // length of the buffer to 0 + common_cb->app_buffer_length = 0; + } + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send module type query request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_MODULE_TYPE, pkt); + + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_MTYPE_RESPONSE_WAIT_TIME); + + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //return common command error + return status; + } + + // get common command response status + status = rsi_common_get_status(); + + if (status == RSI_SUCCESS) { + rsi_driver_cb_non_rom->module_type_id = *response; + rsi_driver_cb_non_rom->module_type_valid = 1; + } + + // Return the status + return status; +} + +/*==============================================*/ +/** + * @brief Debug prints on UART interfaces 1 and 2. Host can get 5 types of debug prints based on + * the assertion level and assertion type. This is a blocking API. + * @param[in] assertion_type - Assertion_type (Possible values 0 - 15) \n + * 0000 - LMAC core \n + * 0001 - SME \n + * 0010 - UMAC \n + * 0100 - NETX \n + * 1000 - Enables assertion indication and provides ram dump in critical assertion. \n + * @param[in] assertion_level - Assertion_level (Possible values 0 - 15) \n + * 1 is least value/only specific prints \n + * 15 is the highest level/Enable all prints. \n + * 0000 - Assertion required \n + * 0010 - Recoverable \n + * 0100 - Information \n + * @return 0 - Success \n + * @return Non-Zero value - Failure (**Possible Error Codes** - 0xfffffffe)\n + * + * @note Refer to \ref error-codes for the description of above error codes. + * @note To minimize the debug prints host is supposed to give the same API with assertion type and assertion level as 0. + * @note Baud rate for UART 2 on host application side should be 460800. + * @note Enable few feature bit maps for getting debug logs on UART: \n + * (#define RSI_CUSTOM_FEATURE_BIT_MAP FEAT_CUSTOM_FEAT_EXTENTION_VALID) and \n + * (#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP EXT_FEAT_UART_SEL_FOR_DEBUG_PRINTS) + */ + +int32_t rsi_common_debug_log(int32_t assertion_type, int32_t assertion_level) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_COMMON_DEBUG_LOG_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_debug_uart_print_t *debug_uart_print; + // Get common cb structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_COMMON_DEBUG_LOG_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + if (((assertion_type > 15) || (assertion_type < 0)) || ((assertion_level < 0) || (assertion_level > 15))) { + SL_PRINTF(SL_COMMON_DEBUG_LOG_INVALID_PARAM, COMMON, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_COMMON_DEBUG_LOG_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in debug uart print select structure + debug_uart_print = (rsi_debug_uart_print_t *)pkt->data; + + // Assertion_type + debug_uart_print->assertion_type = assertion_type; + + // RF type + debug_uart_print->assertion_level = assertion_level; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send firmware version query request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_DEBUG_LOG, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_DEBUG_LOG_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_COMMON_DEBUG_LOG_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_COMMON_DEBUG_LOG_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief To enable or disable BT. This is a blocking API. + * @param[in] type - Type + * @param[in] callback - Indicate BT enable or disable based on mode value + * @param[out] mode - Indicate BT enable or disable + * @param[out] bt_disabled_status - BT disabled status either success or failure to host + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xFF) + * + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_switch_proto(uint8_t type, void (*callback)(uint16_t mode, uint8_t *bt_disabled_status)) +{ + rsi_pkt_t *pkt; + rsi_switch_proto_t *ptr; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SWITCH_PROTO_ENTRY, COMMON, LOG_INFO); + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if ((type == 1) && (callback != NULL)) { + /* In ENABLE case, callback must be NULL */ + SL_PRINTF(SL_SWITCH_PROTO_INVALID_PARAM, COMMON, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SWITCH_PROTO_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SWITCH_PROTO_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Take the user provided data and fill it in switch proto structure + ptr = (rsi_switch_proto_t *)pkt->data; + + // Type + ptr->mode_value = type; + + common_cb->sync_mode = type; +#ifdef RSI_WLAN_ENABLE + if (callback != NULL) { + // Set socket asynchronous receive callback + rsi_wlan_cb_non_rom->switch_proto_callback = callback; + + } else { + // Set socket asynchronous receive callback + rsi_wlan_cb_non_rom->switch_proto_callback = NULL; + } +#endif +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + + // Send switch proto command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_SWITCH_PROTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_SWITCH_PROTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_SWITCH_PROTO_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_SWITCH_PROTO_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * + * @brief Handles driver events. Called in application main loop for non-OS platforms. \n + * With OS, this is a blocking API and without OS this API is a non-blocking API. + * @param[in] Void + * @return None + */ + +void rsi_wireless_driver_task(void) +{ + SL_PRINTF(SL_WIRELESS_DRIVER_TASK_ENTRY, COMMON, LOG_INFO); +#ifdef RSI_WITH_OS + while (1) +#endif + { + rsi_scheduler(&rsi_driver_cb->scheduler_cb); + } + SL_PRINTF(SL_WIRELESS_DRIVER_TASK_EXIT, COMMON, LOG_INFO); +} +//====================================================== +/** + * + * @brief De-Initialize driver components by clearing all the memory given for driver operations through rsi_driver_init() API. + * With OS case, you need to take care of OS variables initialized in rsi_driver_init(). + * This API must be called by the thread/task/master thread that it is not dependent on the OS variables allocated/initialized in rsi_driver_init() API. \n + * This is a non-blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * @note **Precondition** - \ref rsi_driver_init API needs to be called before this API. + */ + +int32_t rsi_driver_deinit(void) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_DRIVER_DEINIT_ENTRY, COMMON, LOG_INFO); + uint32_t actual_length = 0; + + if ((rsi_driver_cb_non_rom->device_state < RSI_DRIVER_INIT_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // Check if buffer is enough for driver components + actual_length += rsi_driver_memory_estimate(); + if (buffer_addr == NULL) { + return RSI_FAILURE; + } +#ifndef RSI_M4_INTERFACE + rsi_hal_intr_mask(); +#else + mask_ta_interrupt(RX_PKT_TRANSFER_DONE_INTERRUPT | TX_PKT_TRANSFER_DONE_INTERRUPT); +#endif +#ifndef RSI_CHECK_PKT_QUEUE + rsi_check_pkt_queue_and_dequeue(); +#endif +#ifdef RSI_WITH_OS + rsi_vport_enter_critical(); +#endif +#ifndef RSI_RELEASE_SEMAPHORE + rsi_release_waiting_semaphore(); +#endif + rsi_semaphore_destroy(&rsi_driver_cb->scheduler_cb.scheduler_sem); +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD + rsi_semaphore_destroy(&rsi_driver_cb->common_cb->wakeup_gpio_sem); +#endif +#ifdef RSI_WITH_OS + rsi_semaphore_destroy(&rsi_driver_cb->common_cb->common_card_ready_sem); +#endif + status = rsi_semaphore_destroy(&rsi_driver_cb->common_cb->common_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_1, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + rsi_mutex_destroy(&rsi_driver_cb->common_cb->common_mutex); + rsi_mutex_destroy(&rsi_driver_cb_non_rom->tx_mutex); +#ifdef SAPI_LOGGING_ENABLE + sl_log_deinit(); +#endif +#ifdef FW_LOGGING_ENABLE + sl_fw_log_deinit(); +#endif +#if defined(RSI_DEBUG_PRINTS) || defined(FW_LOGGING_ENABLE) + rsi_mutex_destroy(&rsi_driver_cb_non_rom->debug_prints_mutex); +#endif +#ifdef RSI_ZB_ENABLE + rsi_mutex_destroy(&rsi_driver_cb->zigb_tx_q.queue_mutex); +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + rsi_mutex_destroy(&rsi_driver_cb->prop_protocol_tx_q.queue_mutex); +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + rsi_mutex_destroy(&rsi_driver_cb->bt_single_tx_q.queue_mutex); +#endif +#if (defined RSI_BLE_ENABLE || defined RSI_BT_ENABLE) + rsi_mutex_destroy(&rsi_driver_cb->bt_common_tx_q.queue_mutex); +#endif +// Added WLAN define +#ifdef RSI_WLAN_ENABLE + rsi_mutex_destroy(&rsi_driver_cb->wlan_tx_q.queue_mutex); +#endif + rsi_mutex_destroy(&rsi_driver_cb->common_tx_q.queue_mutex); +// Added WLAN define +#ifdef RSI_WLAN_ENABLE + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->send_data_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_2, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#endif + if (rsi_driver_cb->rx_pool.pkt_sem != (uint32_t)NULL) { + status = rsi_semaphore_destroy(&rsi_driver_cb->rx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_3, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + } + status = rsi_semaphore_destroy(&rsi_driver_cb->common_cb->common_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_4, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->common_cmd_send_sem); + if (status != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->common_cmd_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_5, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#ifdef RSI_WLAN_ENABLE + // Create WLAN semaphore + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->nwk_cmd_send_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_6, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->nwk_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_7, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_8, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb_non_rom->wlan_cmd_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_9, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->wlan_cb->wlan_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_10, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->wlan_cb->wlan_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_11, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + rsi_mutex_destroy(&rsi_driver_cb->wlan_cb->wlan_mutex); + rsi_socket_pool = NULL; + rsi_socket_pool_non_rom = NULL; +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + // Create BT semaphore + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_common_cb->bt_cmd_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_12, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_common_cb->bt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_13, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_common_cb->bt_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_14, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#ifdef SAPIS_BT_STACK_ON_HOST + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_ble_stack_cb->bt_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_15, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#endif +#ifdef RSI_BT_ENABLE + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_classic_cb->bt_cmd_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_16, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_classic_cb->bt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_17, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->bt_classic_cb->bt_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_18, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#endif +#ifdef RSI_BLE_ENABLE + status = rsi_semaphore_destroy(&rsi_driver_cb->ble_cb->bt_cmd_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_19, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->ble_cb->bt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_20, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->ble_cb->bt_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_21, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + status = rsi_semaphore_destroy(&rsi_driver_cb->prop_protocol_cb->bt_cmd_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_22, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->prop_protocol_cb->bt_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_23, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } +#endif +#endif +#ifdef RSI_ZB_ENABLE + status = rsi_semaphore_destroy(&rsi_driver_cb->zigb_cb->zigb_tx_pool.pkt_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_24, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + status = rsi_semaphore_destroy(&rsi_driver_cb->zigb_cb->zigb_sem); + if (status != RSI_ERROR_NONE) { + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_25, COMMON, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + rsi_mutex_destroy(&rsi_driver_cb->zigb_cb->zigb_mutex); +#endif +#ifdef RSI_WITH_OS + rsi_vport_exit_critical(); +#endif + // state update + rsi_driver_cb->common_cb->state = RSI_COMMON_STATE_NONE; +#ifdef RSI_WLAN_ENABLE + rsi_driver_cb->wlan_cb->state = RSI_WLAN_STATE_NONE; +#endif +#ifndef LINUX_PLATFORM +#ifdef RSI_SPI_INTERFACE + rsi_timer_stop(RSI_TIMER_NODE_0); +#endif +#endif + rsi_driver_cb_non_rom->device_state = RSI_DEVICE_STATE_NONE; + SL_PRINTF(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_26, COMMON, LOG_INFO); + return RSI_SUCCESS; +} + +/*======================================================*/ +/** + * + * @brief In OS case, delete driver task before calling rsi_driver_deinit() API. + * @param[in] task_handle - Task handle/instance to be deleted + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_driver_init API needs to be called before this API. + */ + +int32_t rsi_destroy_driver_task_and_driver_deinit(rsi_task_handle_t *task_handle) +{ +#ifndef RSI_WITH_OS + UNUSED_PARAMETER(task_handle); //This statement is added only to resolve compilation warning, value is unchanged +#endif + SL_PRINTF(SL_DRIVER_DEINIT_TASK_DESTROY_ENTRY, COMMON, LOG_INFO); + int32_t status = RSI_SUCCESS; + +#ifdef RSI_WITH_OS + rsi_task_destroy(task_handle); +#endif + + status = rsi_driver_deinit(); + SL_PRINTF(SL_DRIVER_DEINIT_TASK_DESTROY_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +/*=============================================================================*/ +/** + * @brief Get current driver version. This is a non-blocking API. + * @param[in] Request - Pointer to fill driver version + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +int32_t rsi_driver_version(uint8_t *request) +{ + SL_PRINTF(SL_DRIVER_VERSION_ENTRY, COMMON, LOG_INFO); + memcpy(request, (uint8_t *)RSI_DRIVER_VERSION, sizeof(RSI_DRIVER_VERSION)); + SL_PRINTF(SL_DRIVER_VERSION_EXIT, COMMON, LOG_INFO); + return RSI_SUCCESS; +} +/** @} */ +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the host rtc timer. This is a blocking API. + * @param[in] timer - Pointer to fill RTC time. + * second --> seconds [0-59] \n + * minute --> minutes [0-59] \n + * hour --> hours since midnight [0-23] \n + * day --> day of the month [1-31] \n + * month --> months since January [0-11] \n + * year --> year since 1990. \n + * Weekday--> Weekday from Sunday to Saturday [1-7] \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API + * @note Hour is 24-hour format only (valid values are 0 to 23). Valid values for Month are 0 to 11 (January to December). + */ + +int32_t rsi_set_rtc_timer(module_rtc_time_t *timer) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SET_RTC_TIMER_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + module_rtc_time_t *rtc; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + if ((timer->tm_sec[0] > 59) || (timer->tm_min[0] > 59) || (timer->tm_hour[0] > 23) + || ((timer->tm_mday[0] < 1) || (timer->tm_mday[0] > 31)) || (timer->tm_mon[0] > 11) + || ((timer->tm_wday[0] < 1) || (timer->tm_wday[0] > 7))) { + + // Checking Invalid Parameters + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SET_RTC_TIMER_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in module RTC time structure + rtc = (module_rtc_time_t *)pkt->data; + + memcpy(&rtc->tm_sec, &timer->tm_sec, 4); + memcpy(&rtc->tm_min, &timer->tm_min, 4); + memcpy(&rtc->tm_hour, &timer->tm_hour, 4); + memcpy(&rtc->tm_mday, &timer->tm_mday, 4); + memcpy(&rtc->tm_mon, &timer->tm_mon, 4); + memcpy(&rtc->tm_year, &timer->tm_year, 4); + memcpy(&rtc->tm_wday, &timer->tm_wday, 4); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send set RTC timer request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_SET_RTC_TIMER, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_SET_RTC_TIMER_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_SET_RTC_TIMER_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_SET_RTC_TIMER_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +//*==============================================*/ +/** + * @brief Get ram log on UART/UART2. This is a blocking API. + * @param[in] addr - Address in RS9116 module + * @param[in] length - Chunk length to read from RS9116 module + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0x0021, 0x003E) \n + * + * @note \ref rsi_wireless_init() needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_get_ram_log(uint32_t addr, uint32_t length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_GET_RAM_LOG_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_ram_dump_t *ram; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_GET_RAM_LOG_EXIT1, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_GET_RAM_LOG_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in ram_dump structure + ram = (rsi_ram_dump_t *)pkt->data; + // Address + ram->addr = addr; + // Length + ram->length = length; +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send RAM dump request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_GET_RAM_DUMP, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_GET_RAM_DUMP_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_GET_RAM_LOG_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_GET_RAM_LOG_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * + * @brief Provide the memory required by the application. This is a non-blocking API. + * @param[in] Void + * @return Driver pool size + * + */ + +int32_t rsi_driver_memory_estimate(void) +{ + uint32_t actual_length = 0; + + // Calculate the Memory length of the application + actual_length += RSI_DRIVER_POOL_SIZE; + return actual_length; +} + +/*==============================================*/ +/** + * + * @brief De-register event handler for the given event. This is a non-blocking API. + * @param[out] event_num - Event number + * @return 0 - Success \n + * @return Non-Zero Value- Failure \n + */ +void rsi_uregister_events_callbacks(void (*callback_handler_ptr)(uint32_t event_num)) +{ + SL_PRINTF(SL_UNREGISTER_EVENTS_CALLBACK_ENTRY, COMMON, LOG_INFO); + global_cb_p->rsi_driver_cb->unregistered_event_callback = callback_handler_ptr; + SL_PRINTF(SL_UNREGISTER_EVENTS_CALLBACK_EXIT, COMMON, LOG_INFO); +} +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE +/*==============================================*/ +/** + * + * @brief Register SAPI wait timeout handler. This is a non-blocking API. + * @param[out] status - Status + * @param[out] cmd_type - Command + * @return 0 - Success \n + * @return Non-Zero - Failure \n + */ +void rsi_register_wait_timeout_error_callbacks(void (*callback_handler_ptr)(int32_t status, uint32_t cmd_type)) +{ + SL_PRINTF(SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_ENTRY, COMMON, LOG_INFO); + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb = callback_handler_ptr; + SL_PRINTF(SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_EXIT, COMMON, LOG_INFO); +} +#endif +/** @} */ +/** @addtogroup COMMON +* @{ +*/ +//*==============================================*/ +/** + * @brief Fetch current time from hardware Real Time Clock. This is a blocking API. + * @pre \ref rsi_set_rtc_timer() API needs to be called before this API. + * Also this API needs to be called only after \ref rsi_wlan_scan() API or \ref rsi_wlan_radio_init() API. + * @param[out] response - Response of the requested command. \n + * Response parameters: \n + * second --> Current real time clock seconds. \n + * minute --> Current real time clock minute. \n + * hour --> Current real time clock hour. \n + * day --> Current real time clock day. \n + * month --> Current real time clock month. \n + * year --> Current real time clock year. \n + * weekday--> Current real time clock Weekday. \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0x0021, 0x0025) \n + * @note **Precondition** - \ref rsi_set_rtc_timer() API needs to be called before this API. \n + * rsi_wlan_scan() API or rsi_wlan_radio_init() API needs to be called before this API. + * @note Hour is 24-hour format only (valid values are 0 to 23). Valid values for Month are 0 to 11 (January to December). + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_get_rtc_timer(module_rtc_time_t *response) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_GET_RTC_TIMER_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_GET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Unlock mutex + rsi_mutex_unlock(&common_cb->common_mutex); + // Return packet allocation failure error + SL_PRINTF(SL_GET_RTC_TIMER_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (response != NULL) { + // Attach the buffer given by user + common_cb->app_buffer = (uint8_t *)response; + + // Length of the buffer provided by user + common_cb->app_buffer_length = sizeof(module_rtc_time_t); + } else { + // Assign NULL to the app_buffer to avoid junk + common_cb->app_buffer = NULL; + + // Length of the buffer to 0 + common_cb->app_buffer_length = 0; + } +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + + // Send get RTC timer request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_GET_RTC_TIMER, pkt); + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_GET_RTC_TIMER_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_GET_RTC_TIMER_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_GET_RTC_TIMER_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_set_config( uint32_t code, uint8_t value) + * @brief Configure XO Ctune value from host + * @param[in] Code - XO_CTUNE_FROM_HOST + * @param[in] value - Value to be configured + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int32_t rsi_set_config(uint32_t code, uint8_t value) +{ + rsi_pkt_t *pkt; + rsi_set_config_t *set_config = NULL; + int32_t status = RSI_SUCCESS; + + // Get common cb structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if (common_cb->state < RSI_COMMON_OPERMODE_DONE) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + if (code != XO_CTUNE_FROM_HOST) { + // if flag set is other than xo_ctune from host + return RSI_ERROR_INVALID_SET_CONFIG_FLAG; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Changing the common cmd state to allow + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + set_config = (rsi_set_config_t *)pkt->data; + + //code + set_config->code = code; + + //xo ctune value from host + set_config->values.xo_ctune = value; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // send set config request command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_SET_CONFIG, pkt); + + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_SET_CONFIG_RESPONSE_WAIT_TIME); + + // Changing the common cmd state to allow + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } else { + // return common command error + return status; + } + // get common command response status + status = rsi_common_get_status(); + + // Return the status + return status; +} +#ifdef RSI_ASSERT_API +/*==============================================*/ +/** + * @brief Trigger an assert. This is a blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int32_t rsi_assert(void) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ASSERT_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_ASSERT_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Command given in wrong state + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_ASSERT_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + + // Send assert request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ASSERT, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_ASSERT_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_ASSERT_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + SL_PRINTF(SL_ASSERT_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} +#endif +#ifdef CONFIGURE_GPIO_FROM_HOST + +//*==============================================*/ +/** + * @brief Configure TA GPIOs from host. This is a non-blocking API. + * @param[in] gpio_type - GPIO types : \n + * 0 - TA_GPIO \n + * 1 - ULP_GPIO \n + * 2 - UULP_GPIO \n + * @param[in] pin_num - GPIO Number : \n + * Valid values 0 - 63, if gpio_type is TA_GPIO. \n + * Valid values 0 - 15, if gpio_type is ULP_GPIO. \n + * Valid values 0 and 2, if gpio_type is UULP_GPIO. \n + * @param[in] configuration - BIT[0 - 1] : Drive strength \n + * 0 - 2mA \n + * 1 - 4mA \n + * 2 - 8mA \n + * 3 - 12mA \n + * BIT[2] : Reserved \n + * BIT[3] : Reserved \n + * BIT[4] : I/O mode \n + * 1 - Input mode \n + * 0 - Output mode \n + * BIT[5] : Reserved \n + * BIT[6 - 7] : Type \n + * 0 - Hi-Z \n + * 1 - Pull-up \n + * 2 - Pull-down \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note It is not recommended to configure ULP_GPIO_6 as it is used for WoW feature + * @note You need to define the CONFIGURE_GPIO_FROM_HOST to enable this API + */ + +int32_t rsi_gpio_pininit(uint8_t gpio_type, uint8_t pin_num, uint8_t configuration) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_GPIO_PININIT_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + rsi_gpio_pin_config_t *config_gpio; + // Take lock on common control block + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_GPIO_PININIT_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_GPIO_PININIT_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + config_gpio = (rsi_gpio_pin_config_t *)pkt->data; + config_gpio->gpio_type = gpio_type; + config_gpio->config_mode = RSI_CONFIG_GPIO; + config_gpio->pin_num = pin_num; + config_gpio->output_value = 0; + config_gpio->config_values = configuration; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send GPIO configuration request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_GPIO_CONFIG, pkt); + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_GPIO_CONFIG_RESP_WAIT_TIME); + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + } else { + // Return common command error + SL_PRINTF(SL_GPIO_PININIT_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + // Get common command response status + status = rsi_common_get_status(); + // Return status + SL_PRINTF(SL_GPIO_PININIT_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +//*==============================================*/ +/** + * @brief Drive the module GPIOs high or low from host. This is a non-blocking API. + * @param[in] gpio_type - GPIO types : \n + * 0 - TA_GPIO \n + * 1 - ULP_GPIO \n + * 2 - UULP_GPIO \n + * @param[in] pin_num - GPIO Number : \n + * Valid values 0 - 63, if gpio_type is TA_GPIO. \n + * Valid values 0 - 15, if gpio_type is ULP_GPIO. \n + * Valid values 0 and 2, if gpio_type is UULP_GPIO. \n + * @param[in] value - Value to be driven on GPIO \n + * 1 - High \n + * 0 - Low \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note It is not recommended to configure ULP_GPIO_6 as it is used for WoW feature + * @note You need to define the CONFIGURE_GPIO_FROM_HOST to enable this API + */ + +int32_t rsi_gpio_writepin(uint8_t gpio_type, uint8_t pin_num, uint8_t value) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_GPIO_WRITEPIN_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + rsi_gpio_pin_config_t *config_gpio; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_GPIO_WRITEPIN_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_GPIO_WRITEPIN_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + config_gpio = (rsi_gpio_pin_config_t *)pkt->data; + config_gpio->gpio_type = gpio_type; + config_gpio->config_mode = RSI_SET_GPIO; + config_gpio->pin_num = pin_num; + config_gpio->output_value = value; + config_gpio->config_values = 0; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send GPIO configuration request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_GPIO_CONFIG, pkt); + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_GPIO_CONFIG_RESP_WAIT_TIME); + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + } else { + // Return common command error + SL_PRINTF(SL_GPIO_WRITEPIN_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + // Get common command response status + status = rsi_common_get_status(); + // Return status + SL_PRINTF(SL_GPIO_WRITEPIN_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +//*==============================================*/ +/** + * @brief Read status of TA GPIOs from host. This is a non-blocking API. + * @param[in] gpio_type - GPIO types : \n + * 0 - TA_GPIO \n + * 1 - ULP_GPIO \n + * 2 - UULP_GPIO \n + * @param[in] pin_num - GPIO Number : \n + * Valid values 0 - 63, if gpio_type is TA_GPIO. \n + * Valid values 0 - 15, if gpio_type is ULP_GPIO. \n + * Valid values 0 and 2, if gpio_type is UULP_GPIO. \n + * @param[in] gpio_value - Address of variable to store the value + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note It is not recommended to configure ULP_GPIO_6 as it is used for WoW feature. + * @note You need to define the CONFIGURE_GPIO_FROM_HOST to enable this API. + */ + +int32_t rsi_gpio_readpin(uint8_t gpio_type, uint8_t pin_num, uint8_t *gpio_value) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_GPIO_READPIN_ENTRY, COMMON, LOG_INFO); + rsi_pkt_t *pkt; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + rsi_gpio_pin_config_t *config_gpio; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_GPIO_READPIN_COMMAND_GIVEN_IN_WRONG_STATE, COMMON, LOG_ERROR, "status: %4x", common_cb->state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_GPIO_READPIN_PKT_ALLOCATION_FAILURE, COMMON, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + config_gpio = (rsi_gpio_pin_config_t *)pkt->data; + config_gpio->gpio_type = gpio_type; + config_gpio->config_mode = RSI_GET_GPIO; + config_gpio->pin_num = pin_num; + config_gpio->output_value = 0; + config_gpio->config_values = 0; + + // Attach the buffer given by user + common_cb->app_buffer = (uint8_t *)gpio_value; + // Length of the buffer provided by user + common_cb->app_buffer_length = 1; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send GPIO configuration request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_GPIO_CONFIG, pkt); + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_GPIO_CONFIG_RESP_WAIT_TIME); + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + } else { + // Return common command error + SL_PRINTF(SL_GPIO_READPIN_COMMAND_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + // Get common command response status + status = rsi_common_get_status(); + // Return status + SL_PRINTF(SL_GPIO_READPIN_EXIT, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +//*==============================================*/ +/** + * @brief Read status of NWP GPIOs from host. This is a non-blocking API. + * @param[in] gpio_num - GPIO Number : \n + * Valid values 0 - 15 for ULP \n + * Valid values 0 - 63 for SOC \n + * Valid values 0 - 3 for UULP \n + * @return 0 - Status of NWP GPIO is LOW \n + * @return 1 - status of NWP GPIO is HIGH \n + * @return Non-Zero Value (< 0) - Failure + */ + +int32_t rsi_gpio_read(uint8_t gpio_num) +{ + int32_t status = 0; + int32_t buf = 0; + status = rsi_mem_rd((PAD_REN + (4 * gpio_num)), 4, (uint8_t *)&buf); + if (status < 0) { + return status; + } + buf |= 0x10; + status = rsi_mem_wr((PAD_REN + (4 * gpio_num)), 4, (uint8_t *)&buf); + if (status < 0) { + return status; + } + buf = 0x20; + status = rsi_mem_wr((RSI_GPIO_ADDR + (gpio_num * 2)), 2, (uint8_t *)&buf); + if (status < 0) { + return status; + } + status = rsi_mem_rd((RSI_GPIO_ADDR + (gpio_num * 2)), 2, (uint8_t *)&buf); + if (status < 0) { + return status; + } + return (buf >> 13); +} + +//*==============================================*/ +/** + *@brief Drive the NWP GPIOs from host. This is a non-blocking API. + *@param[in] gpio_num - GPIO Number : \n + * Valid values 0 - 15 for ULP \n + * Valid values 0 - 63 for SOC \n + * Valid values 0 - 3 for UULP \n + *@param[in] write - Value to be driven on GPIO \n + * 1 - High \n + * 0 - Low \n + *@return 0 - Success \n + *@return Non-Zero Value - Failure + *@note You need to define the CONFIGURE_GPIO_FROM_HOST to enable this API + */ +int32_t rsi_gpio_write(uint8_t gpio_num, uint8_t write) +{ + int32_t status = 0; + + status = rsi_mem_wr((RSI_GPIO_ADDR + (gpio_num * 2)), 2, (uint8_t *)&write); + if (status < 0) { + return status; + } + return status; +} + +#endif +/*==============================================*/ +/** + * @fn int32_t rsi_set_region(void) + * @brief set/change the region on user based configuration + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +int32_t rsi_set_region(void) +{ + rsi_pkt_t *pkt __attribute__((unused)); + int32_t status = RSI_SUCCESS; + rsi_wlan_cb_t *wlan_cb __attribute__((unused)) = rsi_driver_cb->wlan_cb; +#if RSI_SET_REGION_SUPPORT + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&rsi_driver_cb->common_cb->common_tx_pool); + if (pkt == NULL) { + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + memset(&pkt->data, 0, sizeof(rsi_req_set_region_t)); +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION, pkt); + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_RESPONSE_WAIT_TIME); + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + return status; + } +#else + return RSI_ERROR_SET_REGION_NOT_ENABLED; +#endif + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/common/rsi_device_init_apis.c b/wiseconnect/sapi/common/rsi_device_init_apis.c new file mode 100644 index 00000000..59c34f8f --- /dev/null +++ b/wiseconnect/sapi/common/rsi_device_init_apis.c @@ -0,0 +1,367 @@ +/******************************************************************************* +* @file rsi_device_init_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ +#include "rsi_driver.h" +#ifdef SIM_9118 +#include "rsi_board.h" +#endif +#ifdef RSI_M4_INTERFACE +#ifdef ROM_WIRELESS +#include "rsi_chip.h" +#endif +#include "core_cm4.h" +#include "rsi_board.h" +#endif +#ifdef LINUX_PLATFORM +#include +#include +#endif +#include "rsi_hal.h" +#include "rsi_wlan_non_rom.h" + +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * @brief Power cycle the module and set the firmware image type to be loaded. This is a blocking API. + * @param[in] select_option - \ref LOAD_NWP_FW : To load Firmware image \n + * \ref LOAD_DEFAULT_NWP_FW_ACTIVE_LOW : To load active low Firmware image. \n + * Active low firmware will generate active low interrupts to indicate that packets are pending on the \n + * module, instead of the default active high. \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_driver_init() must be called before this API. + * @note Add the ENABLE_POC_IN_TOGGLE macro in the preprocessor to enable toggling of the POC_IN pin if it is controlled by the host to power cycle the module. For STM32 and EFM32 hosts, pins have been configured to drive the POC_IN pin. For EFR32, a pin has to be configured by the user to drive the POC_IN pin. + * @return **Success** - RSI_SUCCESS \n + * @return **Failure** - Non-Zero Value + * + */ + +int32_t rsi_device_init(uint8_t select_option) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_DEVICE_INIT_ENTRY, COMMON, LOG_INFO); +#if (defined(RSI_SPI_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + rsi_timer_instance_t timer_instance; +#endif +#if defined(RSI_M4_INTERFACE) || defined(LINUX_PLATFORM) + uint8_t skip_bootload_sequence = 0; + int32_t retval = 0; +#endif + if ((rsi_driver_cb_non_rom->device_state != RSI_DRIVER_INIT_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + +#if defined(RSI_SPI_INTERFACE) || defined(RSI_M4_INTERFACE) || defined(RSI_UART_INTERFACE) \ + || defined(RSI_SDIO_INTERFACE) + // Board Initialization + rsi_hal_board_init(); +#endif + +#ifdef RSI_M4_INTERFACE + + SysTick_Config(SystemCoreClock / 1000); +#ifdef RSI_WITH_OS + // Set P2P Intr priority + NVIC_SetPriority(SysTick_IRQn, SYSTICK_INTR_PRI); +#endif + if (!(P2P_STATUS_REG & TA_is_active)) { +#ifdef DEBUG_UART + DEBUGOUT("\r\nM4 Indicate TA To Wakeup From Sleep\r\n"); +#endif + P2P_STATUS_REG |= M4_wakeup_TA; + skip_bootload_sequence = 1; + } +#ifdef DEBUG_UART + DEBUGOUT("\r\n Wait Until TA is Active \r\n"); +#endif + while (!(P2P_STATUS_REG & TA_is_active)) + ; +#ifdef DEBUG_UART + DEBUGOUT("\r\n TA is in Active Mode Now \r\n"); +#endif + + if (!skip_bootload_sequence) { + do { + retval = rsi_waitfor_boardready(); + if (retval == RSI_ERROR_IN_OS_OPERATION) { +#ifdef DEBUG_UART + DEBUGOUT("\r\n Wait Until TA is Active \r\n"); +#endif + } + if ((retval < 0) && (retval != RSI_ERROR_WAITING_FOR_BOARD_READY) && (retval != RSI_ERROR_IN_OS_OPERATION)) { + SL_PRINTF(SL_DEVICE_INIT_EXIT_1, COMMON, LOG_ERROR, "retval:%d", retval); + return retval; + } + } while ((retval == RSI_ERROR_WAITING_FOR_BOARD_READY) && (retval == RSI_ERROR_IN_OS_OPERATION)); + retval = rsi_select_option(select_option); + if (retval < 0) { + SL_PRINTF(SL_DEVICE_INIT_EXIT_2, COMMON, LOG_ERROR, "retval:%d", retval); + return retval; + } + } + // Update TX & RX DMA descriptor address + rsi_update_tx_dma_desc(skip_bootload_sequence); + rsi_update_rx_dma_desc(); +#endif + +#ifdef LINUX_PLATFORM +#if (defined(RSI_USB_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + if (!skip_bootload_sequence) { + do { + retval = rsi_waitfor_boardready(); + if ((retval < 0) && (retval != RSI_ERROR_WAITING_FOR_BOARD_READY) && (retval != RSI_ERROR_IN_OS_OPERATION)) { + SL_PRINTF(SL_DEVICE_INIT_EXIT_3, COMMON, LOG_ERROR, "retval:%d", retval); + return retval; + } + } while (retval == RSI_ERROR_WAITING_FOR_BOARD_READY); + retval = rsi_select_option(select_option); + if (retval < 0) { + SL_PRINTF(SL_DEVICE_INIT_EXIT_4, COMMON, LOG_ERROR, "retval:%d", retval); + return retval; + } + } +#endif +#else +#ifndef RSI_M4_INTERFACE + // power cycle the module + status = rsi_bl_module_power_cycle(); + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_DEVICE_INIT_MODULE_POWER_CYCLE_FAILURE, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#endif +#if defined(RSI_SDIO_INTERFACE) + // SDIO interface initialization + status = rsi_sdio_iface_init(); +#elif defined(RSI_SPI_INTERFACE) + // SPI interface initialization + status = rsi_spi_iface_init(); +#endif + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_DEVICE_INIT_SPI_INIT_FAILURE, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + +#if (defined(RSI_SPI_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + rsi_init_timer(&timer_instance, RSI_BOARD_READY_WAIT_TIME); //40000 + do { + status = rsi_bl_waitfor_boardready(); + + if ((status < 0) && (status != RSI_ERROR_WAITING_FOR_BOARD_READY)) { + SL_PRINTF(SL_DEVICE_INIT_BL_WAIT_FOR_BOARD_READY_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + + if (rsi_timer_expired(&timer_instance)) { + SL_PRINTF(SL_DEVICE_INIT_BOARD_READY_TIMEOUT, COMMON, LOG_ERROR); + return RSI_ERROR_BOARD_READY_TIMEOUT; + } + + } while (status == RSI_ERROR_WAITING_FOR_BOARD_READY); +#ifdef RSI_SPI_INTERFACE + if (select_option == LOAD_NWP_FW) { + rsi_set_intr_type(RSI_ACTIVE_HIGH_INTR); + } else if (select_option == LOAD_DEFAULT_NWP_FW_ACTIVE_LOW) { + + status = rsi_set_intr_type(RSI_ACTIVE_LOW_INTR); + if (status < 0) { + SL_PRINTF(SL_DEVICE_INIT_SET_INTR_TYPE_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + } +#endif +#if (defined(RSI_SPI_INTERFACE) || defined(RSI_SDIO_INTERFACE)) +#if RSI_FAST_FW_UP + status = rsi_set_fast_fw_up(); + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#endif +#ifdef RSI_INTEGRITY_CHECK_BYPASS_ENABLE + status = rsi_integrity_check_bypass(); + if (status != RSI_SUCCESS) { + return status; + } +#endif + + status = rsi_bl_select_option(select_option); + if (status < 0) { + SL_PRINTF(SL_DEVICE_INIT_BL_SELECT_OPTION_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } +#endif +#endif +#endif +#ifdef RSI_M4_INTERFACE + rsi_m4_ta_interrupt_init(); + if (!(M4SS_P2P_INTR_SET_REG & RX_BUFFER_VALID)) { + rsi_submit_rx_pkt(); + } +#else +#if ((defined RSI_SPI_INTERFACE) && defined(RSI_SPI_HIGH_SPEED_ENABLE)) + // Enable high speed SPI + status = rsi_spi_high_speed_enable(); + if (status < 0) { + SL_PRINTF(SL_DEVICE_INIT_HIGH_SPEED_ENABLE_ERROR, COMMON, LOG_ERROR, "status: %4x", status); + return status; + } + // Switch host clock to high frequency + rsi_switch_to_high_clk_freq(); +#endif +#ifdef RSI_SDIO_INTERFACE + // Switch host clock to high frequency + rsi_switch_to_high_clk_freq(); +#endif +#if (defined(RSI_SPI_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + // Configure interrupt + rsi_hal_intr_config(rsi_interrupt_handler); + + // Unmask interrupts + rsi_hal_intr_unmask(); +#endif +#endif + // Updating state + rsi_driver_cb_non_rom->device_state = RSI_DEVICE_INIT_DONE; + SL_PRINTF(SL_DEVICE_INIT_EXIT_5, COMMON, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief De-Initialize the module and reset the module. \n + * Reset is driven to the module by asserting the reset pin for some duration and releasing it. \n + * This is a non-blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int32_t rsi_device_deinit(void) +{ +#if defined (RSI_WITH_OS) && defined (RSI_WLAN_ENABLE) + int32_t status = RSI_SUCCESS; +#endif + SL_PRINTF(SL_DEVICE_DEINIT_ENTRY, COMMON, LOG_INFO); +#ifdef RSI_WLAN_ENABLE + uint8_t i; +#endif + if ((rsi_driver_cb_non_rom->device_state < RSI_DEVICE_INIT_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_DEVICE_DEINIT_COMMAND_GIVEN_IN_WRONG_STATE, + COMMON, + LOG_ERROR, + "state: %4x", + rsi_driver_cb_non_rom->device_state); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + if (rsi_driver_cb != NULL) { +#ifndef RSI_M4_INTERFACE + // Mask the interrupt + rsi_hal_intr_mask(); +#else + mask_ta_interrupt(RX_PKT_TRANSFER_DONE_INTERRUPT | TX_PKT_TRANSFER_DONE_INTERRUPT); +#endif + } +#ifdef RSI_SPI_INTERFACE + // Power cycle the module + rsi_bl_module_power_cycle(); +#endif + if (rsi_driver_cb != NULL) { + rsi_driver_cb->common_cb->state = RSI_COMMON_STATE_NONE; +#ifdef RSI_WLAN_ENABLE + rsi_driver_cb->wlan_cb->state = RSI_WLAN_STATE_NONE; +#endif + } +#ifdef RSI_WLAN_ENABLE + + if (rsi_socket_pool != NULL) { + // Added this loop for socket pool not memset/clear while deinit/reset + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + // Memset socket info + memset(&rsi_socket_pool[i], 0, sizeof(rsi_socket_info_t)); + } + } + if (rsi_socket_pool_non_rom != NULL) { + // Added this loop for socket pool not memset/clear while deinit/reset + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { +#ifdef RSI_WITH_OS + status = rsi_semaphore_check_and_destroy(&(rsi_socket_pool_non_rom[i].socket_sem)); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + status = rsi_semaphore_check_and_destroy(&(rsi_socket_pool_non_rom[i].sock_recv_sem)); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_EXIT4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + status = rsi_semaphore_check_and_destroy(&(rsi_socket_pool_non_rom[i].sock_send_sem)); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + // Memset socket info + memset(&rsi_socket_pool_non_rom[i], 0, sizeof(rsi_socket_info_non_rom_t)); + } + } + +#endif + rsi_driver_cb_non_rom->device_state = RSI_DRIVER_INIT_DONE; + SL_PRINTF(SL_DEVICE_INIT_EXIT, COMMON, LOG_INFO); + return RSI_SUCCESS; +} +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) +/*==================================================*/ +/** + * @brief Get the interrupt status. + * @param[in] NA + * @return 1 - when there is an interrupt \n + * @return 0 - when there is no interrupt +*/ + +uint8_t rsi_get_intr_status() +{ +#if ((defined RSI_SPI_INTERFACE) && (!(defined RSI_ACTIVE_LOW))) + return rsi_hal_intr_pin_status(); +#else + return !rsi_hal_intr_pin_status(); +#endif +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/crypto/rsi_crypto.c b/wiseconnect/sapi/crypto/rsi_crypto.c new file mode 100644 index 00000000..3877a620 --- /dev/null +++ b/wiseconnect/sapi/crypto/rsi_crypto.c @@ -0,0 +1,3135 @@ +/******************************************************************************* +* @file rsi_crypto.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_crypto.h" + +#ifdef RSI_CRYPTO_ENABLE + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Compute the SHA digest. This is a blocking API. + * @param[in] sha_mode 1 – For SHA1 \n 2 – For SHA256 \n 3 – For SHA384 \n 4 – For SHA512 \n 5 – For SHA224 \n + * @param[in] msg - Pointer to message + * @param[in] msg_length - Total message length + * @param[in] chunk_length - Current chunk length + * @param[in] pending_flag - BIT(0) - 1st chunk \n BIT(1) - Middle chunk \n BIT(2) - Last chunk \n + * @param[out] digest - Output parameter to hold computed digest from SHA + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_sha_pen(uint8_t sha_mode, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_len, + uint8_t pending_flag, + uint8_t *digest) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SHA_PEN_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t digest_len = 0; + rsi_pkt_t *pkt; + rsi_sha_req_t *sha; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE, CRYPTO, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + // Input pointer check + if (msg == NULL) { + SL_PRINTF(SL_SHA_PEN_INVALID_PARAM_1, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Fill digest length based on sha mode + if (sha_mode == SHA_1) { + digest_len = SHA_1_DIGEST_LEN; + } else if (sha_mode == SHA_224) { + digest_len = SHA_224_DIGEST_LEN; + } else if (sha_mode == SHA_256) { + digest_len = SHA_256_DIGEST_LEN; + } else if (sha_mode == SHA_384) { + digest_len = SHA_384_DIGEST_LEN; + } else if (sha_mode == SHA_512) { + digest_len = SHA_512_DIGEST_LEN; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_SHA_PEN_INVALID_PARAM_2, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SHA_PEN_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (digest != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = digest; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = digest_len; + } + + // Get Data Pointer + sha = (rsi_sha_req_t *)pkt->data; + + // Memset before filling + memset(sha, 0, sizeof(rsi_sha_req_t)); + + // Fill Algorithm type SHA - 4 + sha->algorithm_type = SHA; + + sha->algorithm_sub_type = sha_mode; + + // Fill sha_flags BIT(0) - 1st chunk BIT(2) - Last chunk + sha->sha_flags = pending_flag; + + // Fill total msg length + sha->total_msg_length = msg_length; + + // Fill current chunk length + sha->current_chunk_length = chunk_len; + + // Data + // Memset before filling + memset(&sha->msg[0], 0, MAX_DATA_SIZE_BYTES); + + // Copy Data + memcpy(&sha->msg[0], msg, chunk_len); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_sha_req_t) - MAX_DATA_SIZE_BYTES + chunk_len; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send sha digest computation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_SHA_PEN_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_SHA_PEN_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Decide whether the SHA message can be sent once or requires multiple calls to send. This is a blocking API. + * @param[in] sha_mode 1 – For SHA1 \n 2 – For SHA256 \n 3 – For SHA384 \n 4 – For SHA512 \n 5– For SHA224 \n + * @param[in] msg - Pointer to message + * @param[in] msg_length - Total message length + * @param[out] digest - Output parameter to hold computed digest from SHA + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_sha(uint8_t sha_mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SHA_ENTRY, CRYPTO, LOG_INFO); + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t sha_flags = 0; + + total_len = msg_length; + + while (total_len) { + // Check total length + if (total_len > MAX_DATA_SIZE_BYTES) { + chunk_len = MAX_DATA_SIZE_BYTES; + if (offset == 0) { + // Make sha_flag as first chunk + sha_flags |= FIRST_CHUNK; + } else { + // Make sha_flag as Middle chunk + sha_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + + // Make sha_flag as Last chunk + sha_flags = LAST_CHUNK; + if (offset == 0) { + /* If the total length is less than 1400 and offset is zero, + make sha_flag as both first chunk as well as last chunk*/ + sha_flags |= FIRST_CHUNK; + } + } + + // Send the current chunk length message + status = rsi_sha_pen(sha_mode, msg, msg_length, chunk_len, sha_flags, digest); + + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_SHA_CHUNK_LENGTH_MSG_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Increment the offset value + offset += chunk_len; + msg += chunk_len; + + // Decrement the total message lenth + total_len -= chunk_len; + } + SL_PRINTF(SL_SHA_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Hold computed digest from HMAC-SHA. This is a blocking API. + * @param[in] hmac_sha_mode - 1 – For HMAC-SHA1 \n 2 – For HMAC-SHA256 \n 3 – For HMAC-SHA384 \n 4 – For HMAC-SHA512 \n + * @param[in] data - Pointer to key along with message + * @param[in] total_length - Total message length + * @param[in] chunk_length - Current chunk length + * @param[in] pending_flag - BIT(0) - 1st chunk \n BIT(1) - Middle chunk \n BIT(2) - Last chunk \n + * @param[out] digest - Output parameter to hold computed digest from HMAC-SHA + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_hmac_sha_pen(uint8_t hmac_sha_mode, + uint8_t *data, + uint16_t total_length, + uint16_t chunk_length, + uint32_t key_length, + uint8_t pending_flag, + uint8_t *digest) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_HMAC_SHA_PEN_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t digest_len = 0; + rsi_pkt_t *pkt; + rsi_hmac_sha_req_t *hmac_sha; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_HMAC_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE, CRYPTO, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + // Input pointer check + if (data == NULL) { + SL_PRINTF(SL_HMAC_SHA_PEN_INVALID_PARAM_1, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Fill digest length based on sha mode + if (hmac_sha_mode == SHA_1) { + digest_len = SHA_1_DIGEST_LEN; + } else if (hmac_sha_mode == SHA_256) { + digest_len = SHA_256_DIGEST_LEN; + } else if (hmac_sha_mode == SHA_384) { + digest_len = SHA_384_DIGEST_LEN; + } else if (hmac_sha_mode == SHA_512) { + digest_len = SHA_512_DIGEST_LEN; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_HMAC_SHA_PEN_INVALID_PARAM_2, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HMAC_SHA_PEN_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (digest != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = digest; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = digest_len; + } + + // Get Data Pointer + hmac_sha = (rsi_hmac_sha_req_t *)pkt->data; + + // Memset before filling + memset(hmac_sha, 0, sizeof(rsi_hmac_sha_req_t)); + + // Fill Algorithm type HMAC_SHA - 5 + hmac_sha->algorithm_type = HMAC_SHA; + + // Fill Algorithm sub type + hmac_sha->algorithm_sub_type = hmac_sha_mode; + + // Fill sha_flags BIT(0) - 1st chunk BIT(2) - Last chunk + hmac_sha->hmac_sha_flags = pending_flag; + + // Fill total msg length + hmac_sha->total_msg_length = total_length; + + // Fill current chunk length + hmac_sha->current_chunk_length = chunk_length; + + // Fill key length + hmac_sha->key_length = key_length; + + // Data + // Memset before filling + memset(&hmac_sha->hmac_data[0], 0, MAX_DATA_SIZE_BYTES); + + // Copy Data + memcpy(&hmac_sha->hmac_data[0], data, chunk_length); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_hmac_sha_req_t) - MAX_DATA_SIZE_BYTES + chunk_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send hmac sha digest computation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_HMAC_SHA_PEN_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_HMAC_SHA_PEN_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Decide whether the HMAC-SHA message can be sent once or requires multiple calls to send the message. This is a blocking API. + * @param[in] hmac_sha_mode - 1 – For HMAC-SHA1 \n 2 – For HMAC-SHA256 \n 3 – For HMAC-SHA384 \n 4 – For HMAC-SHA512 \n + * @param[in] msg - Pointer to message + * @param[in] msg_length - Total message length + * @param[in] key - Pointer to HMAC key + * @param[in] key_length - HMAC key length in bytes + * @param[out] digest - Output parameter to hold computed digest from HMAC-SHA + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ + +int32_t rsi_hmac_sha(uint8_t hmac_sha_mode, + uint8_t *msg, + uint32_t msg_length, + uint8_t *key, + uint32_t key_length, + uint8_t *digest, + uint8_t *hmac_buffer) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_HMAC_SHA_ENTRY, CRYPTO, LOG_INFO); + uint32_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t hmac_sha_flags = 0; + uint8_t *data = NULL; + data = hmac_buffer; + total_len = msg_length + key_length; + + // Copy key in to data + memcpy(data, key, key_length); + + // Copy message in to data + memcpy((data + key_length), msg, msg_length); + + while (total_len) { + + // Check total length + if (total_len > MAX_DATA_SIZE_BYTES) { + chunk_len = MAX_DATA_SIZE_BYTES; + if (offset == 0) { + // Make hmac_sha_flag as first chunk + hmac_sha_flags |= FIRST_CHUNK; + } else { + // Make hmac_sha_flag as Middle chunk + hmac_sha_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + + // Make hmac_sha_flag as Last chunk + hmac_sha_flags = LAST_CHUNK; + if (offset == 0) { + /* If the total length is less than 1400 and offset is zero, + make hmac_sha_flag as both first chunk as well as last chunk*/ + hmac_sha_flags |= FIRST_CHUNK; + } + } + + // Send the current chunk length message + status = + rsi_hmac_sha_pen(hmac_sha_mode, data, (msg_length + key_length), chunk_len, key_length, hmac_sha_flags, digest); + + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_HMAC_SHA_CHUNK_LENGTH_MSG_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Increment the offset value + offset += chunk_len; + data += chunk_len; + + // Decrement the total message lenth + total_len -= chunk_len; + } + SL_PRINTF(SL_HMAC_SHA_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Decide whether the AES message can be sent once or requires multiple calls to send the message. This is a blocking API. + * @param[in] aes_mode - 1 – For AES CBC mode \n 2 – For AES ECB mode \n 3 – For AES CTR mode \n + * @param[in] enc_dec - 1 – For AES Encryption \n 2 – For AES Decryption \n + * @param[in] msg - Pointer to message + * @param[in] msg_length - Total message length + * @param[in] key - Pointer to AES key + * @param[in] key_length - AES key length in bytes + * @param[in] iv - Pointer to AES iv + * @param[out] output - Output parameter to hold encrypted/decrypted from AES + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_aes(uint16_t aes_mode, + uint16_t enc_dec, + uint8_t *msg, + uint16_t msg_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint8_t *output) +{ + SL_PRINTF(SL_AES_ENTRY, CRYPTO, LOG_INFO); + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t aes_flags = 0; + int32_t status = RSI_SUCCESS; + + total_len = msg_length; + + while (total_len) { + // Check total length + if (total_len > MAX_DATA_SIZE_BYTES) { + chunk_len = MAX_DATA_SIZE_BYTES; + if (offset == 0) { + // Make aes_flags as first chunk + aes_flags |= FIRST_CHUNK; + } else { + // Make aes_flags as Last chunk + aes_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + aes_flags = LAST_CHUNK; + if (offset == 0) { + /* If the total length is less than 1400 and offset is zero, + make aes_flags as both first chunk as well as last chunk*/ + aes_flags |= FIRST_CHUNK; + } + } + + // Send the current chunk length message + status = rsi_aes_pen(aes_mode, enc_dec, msg, msg_length, chunk_len, key, key_length, iv, aes_flags, output); + + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_AES_CHUNK_LENGTH_MSG_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Increment the offset value + offset += chunk_len; + msg += chunk_len; + + // Decrement the total message lenth + total_len -= chunk_len; + } + SL_PRINTF(SL_AES_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ + +/*==============================================*/ +/** + * @brief Encrypt/decrypt the data using AES + * @param[in] aes_mode - 1 – For AES CBC mode \n 2 – For AES ECB mode \n 3 – For AES CTR mode \n + * @param[in] enc_dec - 1 – For AES Encryption \n 2 – For AES Decryption \n + * @param[in] msg - Pointer to message + * @param[in] msg_lengthm - Total message length + * @param[in] chunk_length - Current chunk length + * @param[in] key - Pointer to AES key + * @param[in] key_length - AES key length in bytes + * @param[in] iv - Pointer to AES iv + * @param[in] aes_flags - BIT(0) - 1st chunk \n BIT(1) - Middle chunk \n BIT(2) - Last chunk \n + * @param[out] output - Output parameter to hold encrypted/decrypted from AES + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_aes_pen(uint16_t aes_mode, + uint16_t enc_dec, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint8_t aes_flags, + uint8_t *output) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_AES_PEN_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_aes_req_t *aes; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + // Input pointer check + if (msg == NULL) { + SL_PRINTF(SL_AES_PEN_INVALID_PARAM_1, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + if (((aes_mode == CBC_MODE) || (aes_mode == CTR_MODE)) && (iv == NULL)) { + SL_PRINTF(SL_AES_PEN_INVALID_PARAM_2, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_AES_PEN_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (output != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = output; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = msg_length; + } + + // Get Data Pointer + aes = (rsi_aes_req_t *)pkt->data; + + // Memset before filling + memset(aes, 0, sizeof(rsi_aes_req_t)); + + // Fill Algorithm type AES - 2 + aes->algorithm_type = AES; + + // Fill Algorithm subtype + aes->algorithm_sub_type = aes_mode; + + // Fill enc_dec: 1 – For AES Encryption 2 – For AES Decryption + aes->encrypt_decryption = enc_dec; + + // Fill aes_flags BIT(0) - 1st chunk BIT(2) - Last chunk + aes->aes_flags = aes_flags; + + // Fill msg length + aes->total_msg_length = msg_length; + + // Fill chunk length + aes->current_chunk_length = chunk_length; + + // Fill key length + aes->key_length = key_length; + + //KEY + // Memset before filling + memset(&aes->key[0], 0, key_length); + + // Copy KEY + memcpy(&aes->key[0], key, key_length); + + if ((aes_mode == CBC_MODE) || (aes_mode == CTR_MODE)) { + // IV + // Memset before filling + memset(&aes->IV[0], 0, IV_SIZE); + + // Copy IV + memcpy(&aes->IV[0], iv, IV_SIZE); + } + + // Data + // Memset before filling + memset(&aes->msg[0], 0, MAX_DATA_SIZE_BYTES); + + // Copy Data + memcpy(&aes->msg[0], msg, chunk_length); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_aes_req_t) - MAX_DATA_SIZE_BYTES + chunk_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send aes encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_AES_PEN_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_AES_PEN_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Calculate the DH key. This is a blocking API. + * @param[in] prime - Pointer to the prime + * @param[in] prime_length - Length of the prime + * @param[in] base - Pointer to base + * @param[in] base_length - Length of the base + * @param[in] exponent - Pointer to exponent + * @param[in] exponent_length - Length of the exponent + * @param[out] exp_result - Output exponentiation result + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_exponentiation(uint8_t *prime, + uint32_t prime_length, + uint8_t *base, + uint32_t base_length, + uint8_t *exponent, + uint32_t exponent_length, + uint8_t *exp_result) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EXPONENTIATION_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_exp_req_t *exp; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_EXPONENTIATION_COMMAND_GIVEN_IN_WRONG_STATE, CRYPTO, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + // Input pointer check + if ((base == NULL) || (prime == NULL) || (exponent == NULL)) { + SL_PRINTF(SL_EXPONENTIATION_INVALID_PARAM, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EXPONENTIATION_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (exp_result != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = exp_result; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = DH_MAX_OUTPUT_SIZE; + } + + // Get Data Pointer + exp = (rsi_exp_req_t *)pkt->data; + + // Memset before filling + memset(exp, 0, sizeof(rsi_exp_req_t)); + + // Fill Algorithm type Exponentiation - 14 + exp->algorithm_type = DH; + + // Fill prime length + exp->prime_length = prime_length; + + // Fill base length + exp->base_length = base_length; + + // Fill exponent length + exp->exponent_length = exponent_length; + + //PRIME + // Memset before filling + memset(&exp->prime[0], 0, prime_length); + + // Copy Prime + memcpy(&exp->prime[0], prime, prime_length); + + //BASE + // Memset before filling + memset(&exp->base[0], 0, base_length); + + // Copy Base + memcpy(&exp->base[0], base, base_length); + + // EXPONENT + // Memset before filling + memset(&exp->exponent[0], 0, exponent_length); + + // Copy Exponent + memcpy(&exp->exponent[0], exponent, exponent_length); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_exp_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send DH key calculation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_EXPONENTIATION_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_EXPONENTIATION_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Compute the ECDH point multiplication vector. This is a blocking API. + * @param[in] ecdh_mode - 1 – For ECDH 192 \n 2 – For ECDH 224 \n 3 – For ECDH 256 \n + * @param[in] d - Pointer to scalar value that needs to be multiplied + * @param[in] sx, sy, sz - Pointers to x, y, z coordinates of the point to be multiplied with scalar ‘d’ + * @param[out] rx, ry, rz - Pointers to x, y, z coordinates of the result point + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_ecdh_point_multiplication(uint8_t ecdh_mode, + uint8_t *d, + uint8_t *sx, + uint8_t *sy, + uint8_t *sz, + uint8_t *rx, + uint8_t *ry, + uint8_t *rz) +{ + SL_PRINTF(SL_ECDH_POINT_MULTIPLICATION_ENTRY, CRYPTO, LOG_INFO); + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t result[96] = { 0 }; + uint8_t size = 0; + uint8_t offset = 0; + rsi_pkt_t *pkt; + rsi_ecdh_pm_req_t *ecdh; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + if (ecdh_mode == ECDH_192) { + size = ECDH_VECTOR_192_SIZE; + } else if (ecdh_mode == ECDH_224) { + size = ECDH_VECTOR_224_SIZE; + } else if (ecdh_mode == ECDH_256) { + size = ECDH_VECTOR_256_SIZE; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_ECDH_POINT_MULTIPLICATION_INVALID_PARAM, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_ECDH_POINT_MULTIPLICATION_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (result != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = result; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = ECDH_MAX_OUTPUT_SIZE; + } + + // Get Data Pointer + ecdh = (rsi_ecdh_pm_req_t *)pkt->data; + + // Memset before filling + memset(ecdh, 0, sizeof(rsi_ecdh_pa_ps_req_t)); + + // Fill Algorithm type ECDH - 15 + ecdh->algorithm_type = ECDH; + + // Fill ecdh mode + ecdh->ecdh_mode = ecdh_mode; + + // Fill ecdh sub mode 1 - point Multiplication + ecdh->ecdh_sub_mode = ECDH_PM; + // Fill Curve type + ecdh->ecdh_curve_type = ECDH_CURVE_P; + + // Memset before filling + memset(&ecdh->sx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sx[0], sx, size); + + // Memset before filling + memset(&ecdh->sy[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sy[0], sy, size); + + // Memset before filling + memset(&ecdh->sz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sz[0], sz, size); + + // Memset before filling + memset(&ecdh->d[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->d[0], d, size); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_ecdh_pm_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send ecdh point multiplication request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Copy Data + memcpy(rx, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(ry, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(rz, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_ECDH_POINT_MULTIPLICATION_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_ECDH_POINT_MULTIPLICATION_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Compute the ECDH point addition vector. This is a blocking API. + * @param[in] ecdh_mode - 1 – For ECDH 192 \n 2 – For ECDH 224 \n 3 – For ECDH 256 \n + * @param[in] sx, sy, sz - Pointers to x, y, z coordinates of the point1 that needs to be added + * @param[in] tx, ty, tz - Pointers to x, y, z coordinates of the point2 that needs to be added + * @param[out] rx, ry, rz - Pointers to x, y, z coordinates of the result point + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_ecdh_point_addition(uint8_t ecdh_mode, + uint8_t *sx, + uint8_t *sy, + uint8_t *sz, + uint8_t *tx, + uint8_t *ty, + uint8_t *tz, + uint8_t *rx, + uint8_t *ry, + uint8_t *rz) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ECDH_POINT_ADDITION_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t result[96] = { 0 }; + uint8_t size = 0; + uint8_t offset = 0; + rsi_pkt_t *pkt; + rsi_ecdh_pa_ps_req_t *ecdh; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE) == RSI_SUCCESS) { + // Fill vector size based on ecdh mode + if (ecdh_mode == ECDH_192) { + size = ECDH_VECTOR_192_SIZE; + } else if (ecdh_mode == ECDH_224) { + size = ECDH_VECTOR_224_SIZE; + } else if (ecdh_mode == ECDH_256) { + size = ECDH_VECTOR_256_SIZE; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_ECDH_POINT_ADDITION_INVALID_PARAM, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_ECDH_POINT_ADDITION_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (result != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = result; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = ECDH_MAX_OUTPUT_SIZE; + } + + // Get Data Pointer + ecdh = (rsi_ecdh_pa_ps_req_t *)pkt->data; + + // Memset before filling + memset(ecdh, 0, sizeof(rsi_ecdh_pa_ps_req_t)); + + // Fill Algorithm type ECDH - 15 + ecdh->algorithm_type = ECDH; + + // Fill ecdh mode + ecdh->ecdh_mode = ecdh_mode; + + // Fill ecdh sub mode 2 - point Addition + ecdh->ecdh_sub_mode = ECDH_PA; + + // Memset before filling + memset(&ecdh->sx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sx[0], sx, size); + + // Memset before filling + memset(&ecdh->sy[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sy[0], sy, size); + + // Memset before filling + memset(&ecdh->sz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sz[0], sz, size); + + // Memset before filling + memset(&ecdh->tx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->tx[0], tx, size); + + // Memset before filling + memset(&ecdh->ty[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->ty[0], ty, size); + + // Memset before filling + memset(&ecdh->tz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->tz[0], tz, size); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_ecdh_pa_ps_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send point addition calculation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Copy Data + memcpy(rx, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(ry, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(rz, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_ECDH_POINT_ADDITION_COMMON_CMD_IN_PROGRESS, CRYPTO, LOG_ERROR); + return RSI_ERROR_COMMON_CMD_IN_PROGRESS; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_ECDH_POINT_ADDITION_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Compute the ECDH point subtraction vector. This is a blocking API. + * @param[in] ecdh_mode - 1 – For ECDH 192 \n 2 – For ECDH 224 \n 3 – For ECDH 256 \n + * @param[in] sx, sy, sz - Pointers to x, y, z coordinates of the point1 that needs to be subtracted + * @param[in] tx, ty, tz - Pointers to x, y, z coordinates of the point2 that needs to be subtracted + * @param[out] rx, ry, rz - Pointers to x, y, z coordinates of the result point + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_ecdh_point_subtraction(uint8_t ecdh_mode, + uint8_t *sx, + uint8_t *sy, + uint8_t *sz, + uint8_t *tx, + uint8_t *ty, + uint8_t *tz, + uint8_t *rx, + uint8_t *ry, + uint8_t *rz) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ECDH_POINT_SUBTRACTION_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t result[96] = { 0 }; + uint8_t size = 0; + uint8_t offset = 0; + rsi_pkt_t *pkt; + rsi_ecdh_pa_ps_req_t *ecdh; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Fill vector size based on ecdh mode + if (ecdh_mode == ECDH_192) { + size = ECDH_VECTOR_192_SIZE; + } else if (ecdh_mode == ECDH_224) { + size = ECDH_VECTOR_224_SIZE; + } else if (ecdh_mode == ECDH_256) { + size = ECDH_VECTOR_256_SIZE; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_ECDH_POINT_SUBTRACTION_INVALID_PARAM, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_ECDH_POINT_SUBTRACTION_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (result != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = result; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = ECDH_MAX_OUTPUT_SIZE; + } + + // Get Data Pointer + ecdh = (rsi_ecdh_pa_ps_req_t *)pkt->data; + + // Memset before filling + memset(ecdh, 0, sizeof(rsi_ecdh_pa_ps_req_t)); + + // Fill Algorithm type ECDH - 15 + ecdh->algorithm_type = ECDH; + + // Fill ecdh mode + ecdh->ecdh_mode = ecdh_mode; + + // Fill ecdh sub mode 3 - point subtraction + ecdh->ecdh_sub_mode = ECDH_PS; + + // Memset before filling + memset(&ecdh->sx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sx[0], sx, size); + + // Memset before filling + memset(&ecdh->sy[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sy[0], sy, size); + + // Memset before filling + memset(&ecdh->sz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sz[0], sz, size); + + // Memset before filling + memset(&ecdh->tx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->tx[0], tx, size); + + // Memset before filling + memset(&ecdh->ty[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->ty[0], ty, size); + + // Memset before filling + memset(&ecdh->tz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->tz[0], tz, size); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_ecdh_pa_ps_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send point subtraction calculation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Copy Data + memcpy(rx, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(ry, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(rz, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_ECDH_POINT_SUBTRACTION_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_ECDH_POINT_SUBTRACTION_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Compute the ECDH point double vector. This is a blocking API. + * @param[in] ecdh_mode - 1 – For ECDH 192 \n 2 – For ECDH 224 \n 3 – For ECDH 256 \n + * @param[in] sx, sy, sz - Pointers to x, y, z coordinates of the point1 that needs to be doubled + * @param[out] rx, ry, rz - Pointers to x, y, z coordinates of the result point + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ + +int32_t rsi_ecdh_point_double(uint8_t ecdh_mode, + uint8_t *sx, + uint8_t *sy, + uint8_t *sz, + uint8_t *rx, + uint8_t *ry, + uint8_t *rz) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ECDH_POINT_DOUBLE_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t result[96] = { 0 }; + uint8_t size = 0; + uint8_t offset = 0; + rsi_pkt_t *pkt; + rsi_ecdh_pd_req_t *ecdh; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Fill vector size based on ecdh mode + if (ecdh_mode == ECDH_192) { + size = ECDH_VECTOR_192_SIZE; + } else if (ecdh_mode == ECDH_224) { + size = ECDH_VECTOR_224_SIZE; + } else if (ecdh_mode == ECDH_256) { + size = ECDH_VECTOR_256_SIZE; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_ECDH_POINT_DOUBLE_INVALID_PARAM, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_ECDH_POINT_DOUBLE_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (result != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = result; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = ECDH_MAX_OUTPUT_SIZE; + } + + // Get Data Pointer + ecdh = (rsi_ecdh_pd_req_t *)pkt->data; + + // Memset before filling + memset(ecdh, 0, sizeof(rsi_ecdh_pa_ps_req_t)); + + // Fill Algorithm type ECDH - 15 + ecdh->algorithm_type = ECDH; + + // Fill ecdh mode + ecdh->ecdh_mode = ecdh_mode; + + // Fill ecdh sub mode 4 - point double + ecdh->ecdh_sub_mode = ECDH_PD; + + // Memset before filling + memset(&ecdh->sx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sx[0], sx, size); + + // Memset before filling + memset(&ecdh->sy[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sy[0], sy, size); + + // Memset before filling + memset(&ecdh->sz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sz[0], sz, size); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_ecdh_pd_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send point double calculation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Copy Data + memcpy(rx, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(ry, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(rz, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_ECDH_POINT_DOUBLE_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_ECDH_POINT_DOUBLE_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup CRYPTO +* @{ +*/ +/*==============================================*/ +/** + * @brief Compute the ECDH point affinity vector. This is a blocking API. + * @param[in] ecdh_mode - 1 – For ECDH 192 \n 2 – For ECDH 224 \n 3 – For ECDH 256 \n + * @param[in] sx, sy, sz - Pointers to x, y, z coordinates of the point1 that needs to be affinified + * @param[out] rx, ry, rz - Pointers to x, y, z coordinates of the result point + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xFF15, 0xCC9C, 0xCC9B) \n + * + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_ecdh_point_affine(uint8_t ecdh_mode, + uint8_t *sx, + uint8_t *sy, + uint8_t *sz, + uint8_t *rx, + uint8_t *ry, + uint8_t *rz) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ECDH_POINT_AFFINE_ENTRY, CRYPTO, LOG_INFO); + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t result[96] = { 0 }; + uint8_t size = 0; + uint8_t offset = 0; + rsi_pkt_t *pkt; + rsi_ecdh_affine_req_t *ecdh; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Fill vector size based on ecdh mode + if (ecdh_mode == ECDH_192) { + size = ECDH_VECTOR_192_SIZE; + } else if (ecdh_mode == ECDH_224) { + size = ECDH_VECTOR_224_SIZE; + } else if (ecdh_mode == ECDH_256) { + size = ECDH_VECTOR_256_SIZE; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + SL_PRINTF(SL_ECDH_POINT_AFFINE_INVALID_PARAM, CRYPTO, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_ECDH_POINT_AFFINE_PKT_ALLOCATION_FAILURE, CRYPTO, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (result != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = result; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = ECDH_MAX_OUTPUT_SIZE; + } + + // Get Data Pointer + ecdh = (rsi_ecdh_affine_req_t *)pkt->data; + + // Memset before filling + memset(ecdh, 0, sizeof(rsi_ecdh_affine_req_t)); + + // Fill Algorithm type ECDH - 15 + ecdh->algorithm_type = ECDH; + + // Fill ecdh mode + ecdh->ecdh_mode = ecdh_mode; + + // Fill Curve type + ecdh->ecdh_curve_type = ECDH_CURVE_P; + + // Fill ecdh sub mode 5 - point affine + ecdh->ecdh_sub_mode = ECDH_PAF; + + // Memset before filling + memset(&ecdh->sx[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sx[0], sx, size); + + // Memset before filling + memset(&ecdh->sy[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sy[0], sy, size); + + // Memset before filling + memset(&ecdh->sz[0], 0, ECDH_MAX_VECTOR_SIZE); + + // Copy Data + memcpy(&ecdh->sz[0], sz, size); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_ecdh_affine_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send point affine calculation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + // Copy Data + memcpy(rx, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(ry, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + offset += ECDH_MAX_VECTOR_SIZE; + + // Copy Data + memcpy(rz, (rsi_common_cb->app_buffer) + offset, ECDH_MAX_VECTOR_SIZE); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + SL_PRINTF(SL_ECDH_POINT_AFFINE_COMMAND_ERROR, CRYPTO, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + SL_PRINTF(SL_SET_RTC_TIMER_EXIT, CRYPTO, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ +void reverse_8(unsigned char *xx, int no_digits) +{ + int count; + uint8_t temp; + for (count = 0; count < (no_digits / 2); count++) { + temp = xx[count]; + xx[count] = xx[no_digits - count - 1]; + xx[no_digits - count - 1] = temp; + } +} + +#ifdef CHIP_9117 +/*==============================================*/ +/** + * @fn int32 trng_init + * @brief This API Initializes the TRNG hardware engine and Evaluate AES-CBC + * @param[in] trng_key - Pointer to trng_key + * @param[in] trng_test_data - Pointer to test data for trng + * @param[in] input_length - Length of test data in dwords + * @param[out] output - Pointer to output + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This API Initializes the TRNG hardware engine + */ +int32_t trng_init(uint32_t *trng_key, uint32_t *trng_test_data, uint16_t input_length, uint32_t *output) +{ + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_trng_req_t *trng; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (rsi_common_cb == NULL) { + + return RSI_ERROR_INVALID_MEMORY; + } + + // Input pointer check + if ((trng_key == NULL) && (trng_test_data == NULL) && (output == NULL) && (input_length == 0)) { + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (output != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = output; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = input_length; + } + + // Get Data Pointer + trng = (rsi_trng_req_t *)pkt->data; + + // Memset before filling + memset(trng, 0, sizeof(rsi_trng_req_t)); + + // Fill Algorithm type TRNG - 21 + trng->algorithm_type = TRNG; + + // Fill Algorithm subtype - 1 + trng->algorithm_sub_type = TRNG_INIT; + + // Fill msg length + trng->total_msg_length = input_length; + + // Copy KEY + memcpy(&trng->trng_key[0], trng_key, (TRNG_KEY_SIZE * 4)); + + // Copy Data + memcpy(&trng->msg[0], trng_test_data, input_length * 4); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_trng_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send aes encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + return status; +} + +/*==============================================*/ +/** + * @fn int32 check_trng_entropy() + * @brief This API check the health of Trng + * @param[in] None + * @param[out] None + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This API checks the Entropy of TRNG + */ + +int32_t trng_entropy(void) +{ + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_trng_req_t *trng; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (rsi_common_cb == NULL) { + return RSI_ERROR_INVALID_MEMORY; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Get Data Pointer + trng = (rsi_trng_req_t *)pkt->data; + + // Memset before filling + memset(trng, 0, sizeof(rsi_trng_req_t)); + + // Fill Algorithm type TRNG - 21 + trng->algorithm_type = TRNG; + + // Fill Algorithm subtype - 2 + trng->algorithm_sub_type = TRNG_ENTROPY; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_trng_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send aes encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + return status; +} + +/*==============================================*/ +/** + * @fn int32 trng_program_key(uint32 *key,uint16 key_length) + * @brief This API Initializes key which needs to be programmed to TRNG hardware engine + * @param[in] key, Key for TRNG + * @param[in] key_length, key length in Dwords + * @param[out] None + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This API Initializes key which needs to be programmed to TRNG hardware engine + */ +int32_t trng_program_key(uint32_t *trng_key, uint16_t key_length) +{ + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_trng_req_t *trng; + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (rsi_common_cb == NULL) { + return RSI_ERROR_INVALID_MEMORY; + } + + // Input pointer check and key length check + if ((trng_key == NULL) && (key_length != TRNG_KEY_SIZE)) { + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Get Data Pointer + trng = (rsi_trng_req_t *)pkt->data; + + // Memset before filling + memset(trng, 0, sizeof(rsi_trng_req_t)); + + // Fill Algorithm type TRNG - 21 + trng->algorithm_type = TRNG; + + // Fill Algorithm subtype - 3 + trng->algorithm_sub_type = TRNG_KEY; + + // Copy KEY + memcpy(&trng->trng_key[0], trng_key, (TRNG_KEY_SIZE * 4)); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_trng_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send aes encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + return status; +} + +/*==============================================*/ +/** + * @fn int32 trng_get_random_num(uint32 *random_number,uint16 length) + * @brief This API generated random number of desired length + * @param[in] random_number, Address for Random number + * @param[in] length,Random number which needs to be generated in Dwords + * @param[out] None + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This API generates random number of desired length + */ + +int32_t trng_get_random_num(uint32_t *random_number, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_trng_req_t *trng; + + if ((random_number == NULL) && (length == 0)) { + return RSI_ERROR_INVALID_PARAM; + } + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (rsi_common_cb == NULL) { + return RSI_ERROR_INVALID_MEMORY; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (random_number != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = random_number; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = (length * 4); + } + + // Get Data Pointer + trng = (rsi_trng_req_t *)pkt->data; + + // Memset before filling + memset(trng, 0, sizeof(rsi_trng_req_t)); + + // Fill Algorithm type TRNG - 21 + trng->algorithm_type = TRNG; + + // Fill Algorithm subtype - 4 + trng->algorithm_sub_type = TRNG_GENERATION; + + // Update the length + trng->total_msg_length = length; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_trng_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send aes encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + return status; +} +/*==============================================*/ +/** + * @fn int32 sl_attestation_get_token(uint8_t *token,uint16 length,uint32_t *nonce) + * @brief This API gets token + * @param[in] token, Address for token + * @param[in] length,Length of token request + * @param[in] nonce, 32 byte nonce + * @param[out] none + * return 0 - success + * !0 - Failure + * + * @section description + * This API gets token + */ + +int32_t sl_attestation_get_token(uint8_t *token, uint16_t length, uint32_t *nonce) +{ + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_token_req_t *attest; + + if ((token == NULL) && (length == 0)) { + return RSI_ERROR_INVALID_PARAM; + } + + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (rsi_common_cb == NULL) { + return RSI_ERROR_INVALID_MEMORY; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (token != NULL) { + // Attach the buffer given by user + rsi_common_cb->app_buffer = token; + + // Length of the buffer provided by user + rsi_common_cb->app_buffer_length = (length * 4); + } + + // Get Data Pointer + attest = (rsi_token_req_t *)pkt->data; + + // Memset before filling + memset(attest, 0, sizeof(rsi_token_req_t)); + + // Fill Algorithm type ATTESTATION - 30 + attest->algorithm_type = ATTESTATION; + + // Update the length + attest->total_msg_length = length; + + // Send 32 byte nonce + //! Memset before filling + memset(&attest->msg[0], 0, NONCE_DATA_SIZE); + + //! Copy Data + memcpy(&attest->msg[0], nonce, NONCE_DATA_SIZE); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_token_req_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send Attestation request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + return status; + } + + // Get common command response stattus + status = rsi_common_get_status(); + + // Return the status + return status; +} +/*==============================================*/ +/** + * @fn rsi_sha3_shake_pen(uint8_t pad_char,uint8_t mode, uint8_t *msg, uint16_t msg_length, + * uint16_t chunk_len, uint8_t pending_flag, uint8_t *digest) + * @brief Computes the sha3/shake digest + * @param[in] pad_char: 0x1F SHAKE, 0x06 SHA3 + * @param[in] mode: 21 - SHAKE_128 \n + * 17 - SHAKE_256, SHA3_256 \n + * 18 - SHA3_224 \n + * 13 - SHA3_384 \n + * 9 - SHA3_512 + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[in] chunk_length: current chunk length + * @param[in] pending_flag: BIT(0) - 1st chunk BIT(1) - Middle chunk BIT(2) - Last chunk + * @param[out] digest: Output parameter to hold computed digest from SHA3/SHAKE + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function computes the sha3/shake digest for the given input message + * + */ +int32_t rsi_sha3_shake_pen(uint8_t pad_char, + uint8_t mode, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_len, + uint8_t pending_flag, + uint8_t *digest) +{ + + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t digest_len = 0; + rsi_pkt_t *pkt; + + //!using same structure for sha3 and shake + rsi_sha_req_t *sha3; + + //! Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + //! Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + //! Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + //! Input pointer check + if (msg == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + if (rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE) == RSI_SUCCESS) { + + //! Fill digest length based on sha mode + if (mode == SHA3_224) { + digest_len = SHA_224_DIGEST_LEN; + } else if (mode == SHA3_256 || mode == SHAKE_256) { + digest_len = SHA_256_DIGEST_LEN; + } else if (mode == SHA3_384) { + digest_len = SHA_384_DIGEST_LEN; + } else if (mode == SHA3_512) { + digest_len = SHA_512_DIGEST_LEN; + } else if (mode == SHAKE_128) { + digest_len = SHAKE_128_DIGEST_LEN; + } + + else { + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + return RSI_ERROR_INVALID_PARAM; + } + + //! allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + //! If allocation of packet fails + if (pkt == NULL) { + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + //! return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (digest != NULL) { + //! attach the buffer given by user + rsi_common_cb->app_buffer = digest; + + //! length of the buffer provided by user + rsi_common_cb->app_buffer_length = digest_len; + } + + //! Get Data Pointer + sha3 = (rsi_sha_req_t *)pkt->data; + + //! Memset before filling + memset(sha3, 0, sizeof(rsi_sha_req_t)); + + //! Fill Algorithm type SHA3 or SHAKE + if (pad_char == PAD_CHAR_SHA3) { + sha3->algorithm_type = SHA3; + } else { + sha3->algorithm_type = SHAKE; + } + + sha3->algorithm_sub_type = mode; + + //! Fill sha_flags BIT(0) - 1st chunk BIT(2) - Last chunk + sha3->sha_flags = pending_flag; + + //! Fill total msg length + sha3->total_msg_length = msg_length; + + //! Fill current chunk length + sha3->current_chunk_length = chunk_len; + + //!Data + //! Memset before filling + memset(&sha3->msg[0], 0, MAX_DATA_SIZE_BYTES); + + //! Copy Data + memcpy(&sha3->msg[0], msg, chunk_len); + + //! Using host descriptor to set payload length + send_size = sizeof(rsi_sha_req_t) - MAX_DATA_SIZE_BYTES + chunk_len; + + //! get the host descriptor + host_desc = (pkt->desc); + + //! Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + //! send sha digest computation request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + //! wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //!return common command error + return RSI_ERROR_COMMON_CMD_IN_PROGRESS; + } + + //! get common command response stattus + status = rsi_common_get_status(); + + //! Return the status + return status; +} + +/*==============================================*/ +/** + * @fn rsi_shake(uint8_t mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest) + * @brief Decides whether the sha message can be sent once or requires multiple calls to send + * @param[in] mode: 21 - SHAKE_128 \n + * 17 - SHAKE_256 \n + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[out] digest: Output parameter to hold computed digest from SHAKE + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function decides whether the shakeamessage can be sent once or requires multiple calls to send the message + * + */ +int32_t rsi_shake(uint8_t mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest) +{ + int32_t status = RSI_SUCCESS; + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t sha_flags = 0; + uint8_t pad_char = PAD_CHAR_SHAKE; + + total_len = msg_length; + + while (total_len) { + //! check total length + if (total_len > MAX_DATA_SIZE_BYTES) { + chunk_len = MAX_DATA_SIZE_BYTES; + if (offset == 0) { + //! Make sha_flag as first chunk + sha_flags |= FIRST_CHUNK; + } else { + //! Make sha_flag as Middle chunk + sha_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + + //! Make sha_flag as Last chunk + sha_flags = LAST_CHUNK; + if (offset == 0) { + /* if the total length is less than 1400 and offset is zero + then make sha_flag as both first chunk as well as last chunk*/ + sha_flags |= FIRST_CHUNK; + } + } + + //! send the current chunk length message + status = rsi_sha3_shake_pen(pad_char, mode, msg, msg_length, chunk_len, sha_flags, digest); + + if (status != RSI_SUCCESS) { + return status; + } + + //! Increment the offset value + offset += chunk_len; + msg += chunk_len; + + //! Decrement the total message lenth + total_len -= chunk_len; + } + + return status; +} + +/*==============================================*/ +/** + * @fn rsi_sha3(uint8_t mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest) + * @brief Decides whether the sha message can be sent once or requires multiple calls to send + * @param[in] mode: 17 - SHA3_256 \n + * 18 - SHA3_224 \n + * 13 - SHA3_384 \n + * 9 - SHA3_512 \n + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[out] digest: Output parameter to hold computed digest from SHA3 + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function decides whether the sha message can be sent once or requires multiple calls to send the message + * + */ + +int32_t rsi_sha3(uint8_t mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest) +{ + int32_t status = RSI_SUCCESS; + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t sha_flags = 0; + uint8_t pad_char = PAD_CHAR_SHA3; + + total_len = msg_length; + + while (total_len) { + //! check total length + if (total_len > MAX_DATA_SIZE_BYTES) { + chunk_len = MAX_DATA_SIZE_BYTES; + if (offset == 0) { + //! Make sha_flag as first chunk + sha_flags |= FIRST_CHUNK; + } else { + //! Make sha_flag as Middle chunk + sha_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + + //! Make sha_flag as Last chunk + sha_flags = LAST_CHUNK; + if (offset == 0) { + /* if the total length is less than 1400 and offset is zero + then make sha_flag as both first chunk as well as last chunk*/ + sha_flags |= FIRST_CHUNK; + } + } + + //! send the current chunk length message + status = rsi_sha3_shake_pen(pad_char, mode, msg, msg_length, chunk_len, sha_flags, digest); + + if (status != RSI_SUCCESS) { + return status; + } + + //! Increment the offset value + offset += chunk_len; + msg += chunk_len; + + //! Decrement the total message lenth + total_len -= chunk_len; + } + + return status; +} + +/*==============================================*/ +/** + * @fn rsi_chachapoly(uint16_t chachapoly_mode, uint16_t enc_dec,uint16_t dma_use, uint8_t *msg, uint16_t msg_length, uint8_t *key_chacha, uint8_t *keyr_in,uint8_t *keys_in, + uint8_t *nonce, uint8_t *header_input, uint16_t header_length, uint8_t *output) + * @brief Decides whether the CHACHAPOLY message can be sent once or requires multiple calls to send + * @param[in] chacha_mode : 0 – For CHACHA20POLY1305 mode \n 1 – For CHACHA20 mode \n 3 – For POLY1305 mode \n + * @param[in] enc_dec: 0 – For CHACHAPOLY Encryption \n 1 – For CHACHAPOLY Decryption \n + * @param[in] dma_use: 1 - DMA enable \n 0- disable DMA \n + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[in] key_chacha: Pointer to chacha key + * @param[in] keyr_in: pointer to keyr_in + * @param[in] keys_in: pointer to keys_in + * @param[in] nonce: pointer to nonce (1st index is IV) + * @param[in] header_input: Pointer to header + * @param[in] header_length: header length in bytes + * @param[out] output: Output parameter to hold encrypted/decrypted from chachapoly + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function decides whether the chachapoly message can be sent once or requires multiple calls to send the message + * + */ +int32_t rsi_chachapoly(uint16_t chachapoly_mode, + uint16_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint8_t *key_chacha, + uint8_t *keyr_in, + uint8_t *keys_in, + uint8_t *nonce, + uint8_t *header_input, + uint16_t header_length, + uint8_t *output) +{ + + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t chachapoly_flags = 0; + int32_t status = RSI_SUCCESS; + + total_len = msg_length; + + //! Input pointer check + if (msg == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + + while (total_len) { + //! check total length + if (total_len > MAX_DATA_SIZE_BYTES_FOR_CHACHAPOLY) { + chunk_len = MAX_DATA_SIZE_BYTES_FOR_CHACHAPOLY; + if (offset == 0) { + //! Make chachapoly_flags as first chunk + chachapoly_flags |= FIRST_CHUNK; + } else { + //! Make chachapoly_flags as Last chunk + chachapoly_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + chachapoly_flags = LAST_CHUNK; + if (offset == 0) { + /* if the total length is less than 1400 and offset is zero + then make chachapoly_flags as both first chunk as well as last chunk*/ + chachapoly_flags |= FIRST_CHUNK; + } + } + + //! send the current chunk length message + status = rsi_chachapoly_pen(chachapoly_mode, + enc_dec, + dma_use, + msg, + msg_length, + chunk_len, + key_chacha, + keyr_in, + keys_in, + nonce, + header_input, + header_length, + chachapoly_flags, + output); + + if (status != RSI_SUCCESS) { + return status; + } + + //! Increment the offset value + offset += chunk_len; + msg += chunk_len; + + //! Decrement the total message lenth + total_len -= chunk_len; + } + + return status; +} + +/*==============================================*/ +/** + * @fn rsi_chachapoly_pen(uint16_t chachapoly_mode, uint16_t enc_dec,uint16_t dma_use, uint8_t *msg, uint16_t msg_length,uint16_t chunk_len, uint8_t *key_chacha, uint8_t *keyr_in,uint8_t *keys_in, + uint8_t *nonce, uint8_t *header_input, uint16_t header_length,uint8_t chachapoly_flags,uint8_t *output) + * @brief Encrypt/Decrypt the data using CHACHA_POLY + * @param[in] chacha_mode : 0 – For CHACHA20POLY1305 mode \n 1 – For CHACHA20 mode \n 3 – For POLY1305 mode \n + * @param[in] enc_dec: 0 – For CHACHAPOLY Encryption \n 1 – For CHACHAPOLY Decryption \n + * @param[in] dma_use: 0 - DMA disable \n 1- DMA enable \n + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[in] chunk_len: current chunk length + * @param[in] key_chacha: Pointer to chacha key + * @param[in] keyr_in: pointer to keyr_in + * @param[in] keys_in: pointer to keys_in + * @param[in] nonce: pointer to nonce (1st index is IV) + * @param[in] header_input: Pointer to header + * @param[in] header_length: header length in bytes + * @param[in] chachapoly_flags: BIT(0) - 1st chunk \n BIT(1) - Middle chunk \n BIT(2) - Last chunk \n + * @param[out] output: Output parameter to hold encrypted/decrypted from chachapoly + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function encrypt/decrypt the data using CHACHAPOLY + * + */ +int32_t rsi_chachapoly_pen(uint16_t chachapoly_mode, + uint16_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_len, + uint8_t *key_chacha, + uint8_t *keyr_in, + uint8_t *keys_in, + uint8_t *nonce, + uint8_t *header_input, + uint16_t header_length, + uint8_t chachapoly_flags, + uint8_t *output) +{ + + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_chachapoly_req_t *chachapoly; + + //! Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + //! Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + //!check for valid mode + if (chachapoly_mode > 3) { + return RSI_ERROR_INVALID_PARAM; + } + + //! check for proper key + if (chachapoly_mode == CHACHAPOLY_MODE_POLY1305_KEYR_KEYS) { + if ((keyr_in == NULL) || (keys_in == NULL)) + return RSI_ERROR_INVALID_PARAM; + } else if (chachapoly_mode == CHACHA20POLY1305 || chachapoly_mode == CHACHA20) { + if (key_chacha == NULL || nonce == NULL) + return RSI_ERROR_INVALID_PARAM; + } else { + if ((keyr_in == NULL) || (keys_in == NULL)) + return RSI_ERROR_INVALID_PARAM; + } + + if (rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE) == RSI_SUCCESS) { + + //! allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + //! If allocation of packet fails + if (pkt == NULL) { + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + //! return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (output != NULL) { + //! attach the buffer given by user + rsi_common_cb->app_buffer = output; + + //! length of the buffer provided by user + rsi_common_cb->app_buffer_length = msg_length + TAG_SIZE; + } + + //! Get Data Pointer + chachapoly = (rsi_chachapoly_req_t *)pkt->data; + + //! Memset before filling + memset(chachapoly, 0, sizeof(rsi_chachapoly_req_t)); + + //! Fill Algorithm type CHACHAPOLY - 17 + chachapoly->algorithm_type = CHACHAPOLY; + + //! Fill Algorithm subtype + chachapoly->algorithm_sub_type = chachapoly_mode; + + //! Fill enc_dec: 0 – For chachapoly Encryption 1 – For chachapoly Decryption + chachapoly->encrypt_decryption = enc_dec; + + //! Fill the DMA + chachapoly->dma_use = dma_use; + + //! Fill chachapoly_flags BIT(0) - 1st chunk BIT(1)-Middle chunk BIT(2) - Last chunk + chachapoly->chachapoly_flags = chachapoly_flags; + + //! Fill msg length + chachapoly->total_msg_length = msg_length; + + //! Fill chunk length + chachapoly->current_chunk_length = chunk_len; + + //!Fill header length + chachapoly->header_length = header_length; + + //!memset header before filling + memset(&chachapoly->header_input[0], 0, header_length); + + //!copy the header input + memcpy(&chachapoly->header_input[0], header_input, header_length); + + if (chachapoly_mode == CHACHA20POLY1305 || chachapoly_mode == CHACHA20 + || chachapoly_mode == CHACHAPOLY_MODE_POLY1305_KEYR_KEYS) { + //!Keychacha + //! Memset before filling + memset(&chachapoly->key_chacha[0], 0, KEY_CHACHA_SIZE); + + //! Copy KEY chacha + memcpy(&chachapoly->key_chacha[0], key_chacha, KEY_CHACHA_SIZE); + + //!Nonce + //!Memset before filling + memset(&chachapoly->nonce[0], 0, NONCE_SIZE); + + //! Copy the Nonce + memcpy(&chachapoly->nonce[0], nonce, NONCE_SIZE); + } + + if (chachapoly_mode == CHACHAPOLY_MODE_POLY1305_KEYR_KEYS || chachapoly_mode == POLY1305_MODE) { + //!KEYR and KEYS + //! Memset before filling + memset(&chachapoly->keyr_in[0], 0, KEYR_SIZE); + memset(&chachapoly->keys_in[0], 0, KEYS_SIZE); + + //! Copy keyr and keys + memcpy(&chachapoly->keyr_in[0], keyr_in, KEYR_SIZE); + memcpy(&chachapoly->keys_in[0], keys_in, KEYS_SIZE); + } + + //!Data + //! Memset before filling + memset(&chachapoly->msg[0], 0, MAX_DATA_SIZE_BYTES_FOR_CHACHAPOLY); + + //! Copy Data + memcpy(&chachapoly->msg[0], msg, chunk_len); + + //! Using host descriptor to set payload length + send_size = sizeof(rsi_chachapoly_req_t) - MAX_DATA_SIZE_BYTES_FOR_CHACHAPOLY + chunk_len; + + //! get the host descriptor + host_desc = (pkt->desc); + + //! Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + //! send chachapoly encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + //! wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + } + + else { + //!return common command error + return RSI_ERROR_COMMON_CMD_IN_PROGRESS; + } + + //! get common command response stattus + status = rsi_common_get_status(); + + //! Return the status + return status; +} +/*==============================================*/ +/** + * @fn rsi_gcm(uint8_t enc_dec,uint16_t dma_use, uint8_t *msg, uint16_t msg_length, uint8_t *key, + * uint16_t key_length, uint8_t *iv,uint8_t iv_sz,uint8_t *header,uint16_t header_length, uint8_t *output,uint8_t tag_out) + * @brief Decides whether the GCM message can be sent once or requires multiple calls to send + * @param[in] enc_dec: 0 – For GCM Encryption \n 1 – For GCM Decryption \n + * @param[in] dma_use: 0 - DMA disable \n 1: DMA Enable \n + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[in] key: Pointer to GCM key + * @param[in] key_length: GCM key length in bits + * @param[in] iv: Pointer to GCM iv + * @param[in] iv_sz:size of IV + * @param[in] header:pointer to header + * @param[in] header_length: Total length of header + * @param[out] output: Output parameter to hold encrypted/decrypted from GCM + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function decides whether the GCM message can be sent once or requires multiple calls to send the message + * + */ +int32_t rsi_gcm(uint8_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint16_t iv_sz, + uint8_t *header, + uint16_t header_length, + uint8_t *output) +{ + + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t gcm_flags = 0; + int32_t status = RSI_SUCCESS; + + total_len = msg_length; + + //! Input pointer check + if (msg == NULL || header == NULL || iv == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + + while (total_len) { + //! check total length + if (total_len > MAX_DATA_SIZE_BYTES) { + chunk_len = MAX_DATA_SIZE_BYTES; + if (offset == 0) { + //! Make gcm_flags as first chunk + gcm_flags |= FIRST_CHUNK; + } else { + //! Make gcm_flags as Last chunk + gcm_flags = MIDDLE_CHUNK; + } + } else { + chunk_len = total_len; + gcm_flags = LAST_CHUNK; + if (offset == 0) { + /* if the total length is less than 1400 and offset is zero + then make gcm_flags as both first chunk as well as last chunk*/ + gcm_flags |= FIRST_CHUNK; + } + } + + //! send the current chunk length message + status = rsi_gcm_pen(enc_dec, + dma_use, + msg, + msg_length, + chunk_len, + key, + key_length, + iv, + iv_sz, + header, + header_length, + gcm_flags, + output); + + if (status != RSI_SUCCESS) { + return status; + } + + //! Increment the offset value + offset += chunk_len; + msg += chunk_len; + + //! Decrement the total message lenth + total_len -= chunk_len; + } + + return status; +} +/*==============================================*/ +/** + * @fn rsi_gcm_pen(uint8_t enc_dec,uint16_t dma_use, uint8_t *msg, uint16_t msg_length, uint16_t chunk_length, uint8_t *key, uint16_t key_length, + * uint8_t *iv,uint16_t iv_sz, uint8_t *header,uint16_t header_length, uint8_t gcm_flags, uint8_t *output, uint8_t *tag_out) + * @brief Encrypt/Decrypt the data using GCM + * @param[in] enc_dec: 0 – For GCM Encryption \n 1 – For GCM Decryption \n + * @param[in] dma_use: 0 - DMA disable \n 1 - DMA Enable \n + * @param[in] msg: Pointer to message + * @param[in] msg_length: Total message length + * @param[in] chunk_length: current chunk length + * @param[in] key: Pointer to GCM key + * @param[in] key_length: GCM key length in bits + * @param[in] iv: Pointer to GCM iv + * @param[in] iv_sz: size of IV + * @param[in] header:pointer to header + * @param[in] header_length: Total length of header + * @param[in] gcm_flags: BIT(0) - 1st chunk \n BIT(1) - Middle chunk \n BIT(2) - Last chunk \n + * @param[out] output: Output parameter to hold encrypted/decrypted from GCM + * @return 0 - Success + * @return Non-Zero Value - Failure + * + * @section description + * This function encrypt/decrypt the data using GCM + * + */ +int32_t rsi_gcm_pen(uint8_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint16_t iv_sz, + uint8_t *header, + uint16_t header_length, + uint8_t gcm_flags, + uint8_t *output) +{ + + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_pkt_t *pkt; + rsi_gcm_req_t *gcm; + + //! Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + //! Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + //! Check IV size for gcm + //!Return error if IV size if not 12 bytes/96 bits + + if (iv_sz != GCM_IV_SIZE_IN_BYTES) { + return RSI_ERROR_INVALID_PARAM; + } + + if (rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE) == RSI_SUCCESS) { + + //! allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + //! If allocation of packet fails + if (pkt == NULL) { + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + //! return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (output != NULL) { + //! attach the buffer given by user + rsi_common_cb->app_buffer = output; + + //! length of the buffer provided by user + rsi_common_cb->app_buffer_length = msg_length + TAG_SIZE; + } + + //! Get Data Pointer + gcm = (rsi_gcm_req_t *)pkt->data; + + //! Memset before filling + memset(gcm, 0, sizeof(rsi_gcm_req_t)); + + //! Fill Algorithm type GCM - 18 + gcm->algorithm_type = GCM; + + //! Fill enc_dec: 0 – For GCM Encryption 1 – For GCM Decryption + gcm->encrypt_decryption = enc_dec; + + //! Fill the DMA + gcm->dma_use = dma_use; + + //! Fill aes_flags BIT(0) - 1st chunk BIT(1)- Middle chunk BIT(2) - Last chunk + gcm->gcm_flags = gcm_flags; + + //! Fill msg length + gcm->total_msg_length = msg_length; + + //! Fill chunk length + gcm->current_chunk_length = chunk_length; + + //! Fill key length + gcm->key_length = key_length; + + //!KEY + //! Memset before filling + memset(&gcm->key[0], 0, key_length); + + //! Copy KEY + memcpy(&gcm->key[0], key, key_length); + + //!IV + //! Memset before filling + memset(&gcm->IV[0], 0, GCM_IV_SIZE_IN_BYTES); + + //! Copy IV + memcpy(&gcm->IV[0], iv, GCM_IV_SIZE_IN_BYTES); + + //!Fill the header length + gcm->header_length = header_length; + + //!Header + //!Memset before filling + memset(&gcm->header[0], 0, header_length); + + //!Copy header + memcpy(&gcm->header[0], header, header_length); + + //!Data + //! Memset before filling + memset(&gcm->msg[0], 0, MAX_DATA_SIZE_BYTES); + + //! Copy Data + memcpy(&gcm->msg[0], msg, chunk_length); + + //! Using host descriptor to set payload length + send_size = sizeof(rsi_gcm_req_t) - MAX_DATA_SIZE_BYTES + chunk_length; + + //! get the host descriptor + host_desc = (pkt->desc); + + //! Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + //! send aes encrypt/decrypt request to module + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_ENCRYPT_CRYPTO, pkt); + + //! wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_CRYPTO_RESPONSE_WAIT_TIME); + + //!Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //!return common command error + return RSI_ERROR_COMMON_CMD_IN_PROGRESS; + } + + //! get common command response stattus + status = rsi_common_get_status(); + + //! Return the status + return status; +} + +#endif + +#endif \ No newline at end of file diff --git a/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_frame_rd_wr.c b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_frame_rd_wr.c new file mode 100644 index 00000000..5f9bf324 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_frame_rd_wr.c @@ -0,0 +1,126 @@ +/******************************************************************************* +* @file rsi_sdio_frame_rd_wr.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_sdio_frame_rd_wr.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SDIO Control: Functions to control SDIO frame read/write functions + * + * Description + * SDIO function to read/write management descriptors frames to/from the wlan module + * + * Improvements + * Function header is modified for frameDscRd() function + */ + +/* + Includes + */ +#include "rsi_driver.h" +#include "rsi_pkt_mgmt.h" +#ifdef RSI_SDIO_INTERFACE +/* + Global Variables + */ +/** @addtogroup DRIVER1 +* @{ +*/ +/*====================================================*/ +/** + * @brief This API reads the frame from the host interface. + * @param[in] read_buff - The frame contents read from the host interface are populated to this buffer. + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ +int16_t rsi_frame_read(uint8_t *read_buff) +{ + int16_t retval = RSI_SUCCESS; + uint8_t response = 0; + uint16_t no_of_blocks; + + // Read number of blocks + retval = rsi_reg_rd(0xf1, &response); + if (retval != RSI_SUCCESS) { + return retval; + } +#ifdef CHIP_9117B0 + no_of_blocks = (response & 0xFF); +#else + no_of_blocks = (response & 0x1F); +#endif + + // Frame read + retval = rsi_sdio_read_multiple(read_buff, no_of_blocks); + return retval; +} + +/*====================================================*/ +/** + * @brief This API writes the frame to the host interface. + * @param[in] uFrameDscFrame - 16 bytes host descriptor. + * @param[in] payloadparam - buffer to the frame payload. + * @param[in] size_param - size of the payload. + * @return 0 - Success \n + * @return Negative value - Failure \n + * + */ +int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param) +{ + UNUSED_PARAMETER(payloadparam); //This statement is added only to resolve compilation warning, value is unchanged + int16_t retval = RSI_SUCCESS; + uint16_t Addr = 0x0000; + uint16_t no_of_blocks = 0; + uint16_t queue_type = 0; + + uint16_t size_of_headroom = 0; + + queue_type = (uFrameDscFrame->frame_len_queue_no[1] >> 4); +#ifdef CHIP_9117 + if ((queue_type == RSI_WLAN_DATA_Q) || (queue_type == RSI_WLAN_MGMT_Q)) { + size_of_headroom = SIZE_OF_HEADROOM; + } +#endif + + // Calculate number of blocks + no_of_blocks = ((size_param + 16 + size_of_headroom) / 256); + if ((size_param + 16 + size_of_headroom) % 256) { + no_of_blocks = no_of_blocks + 1; + } + + Addr = (no_of_blocks * 256); + + Addr = (Addr | (queue_type << 12)); + + // Transfer packet + retval = rsi_sdio_write_multiple(((uint8_t *)uFrameDscFrame - size_of_headroom), Addr, no_of_blocks); + if (retval == 0) { + return retval; + } else { + return RSI_ERROR_SDIO_WRITE_FAIL; + } +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_iface_init.c b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_iface_init.c new file mode 100644 index 00000000..358aeae3 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_iface_init.c @@ -0,0 +1,121 @@ +/******************************************************************************* +* @file rsi_sdio_iface_init.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_sdio_iface_init.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SPI INIT: Functions that initialize the SPI hardware interface in the module + * This file contains the SPI Initialization function. + * This function enables the SPI interface on the chip. + * This function is only ran once during startup, after power-on, or reset + * + * + */ + +/* + Includes + */ +#include "rsi_driver.h" +#ifdef RSI_SDIO_INTERFACE +/* + Global Variables + */ +void rsi_sdio_hal_efm_deinit(void); + +/** @addtogroup DRIVER1 +* @{ +*/ +/*=============================================*/ +/** + * @brief Initialize the RS9116 SDIO secondary device interface. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int16_t rsi_sdio_iface_init(void) +{ + int16_t retval = RSI_SUCCESS; + SL_PRINTF(SL_SDIO_IFACE_INIT_ENTRY, DRIVER, LOG_INFO); + uint8_t data; + +#ifdef MXRT_595s + // Do enumeration + retval = rsi_mcu_sdcard_init(); + + if (retval != RSI_SUCCESS) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_1, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } +#endif + // Do enumeration + retval = rsi_mcu_sdio_init(); + + if (retval != RSI_SUCCESS) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_2, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + + // SDIO_READ_START_LVL + data = 0x24; + retval = rsi_reg_wr(0xfc, &data); + if (retval != RSI_SUCCESS) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_3, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + + // SDIO_READ_FIFO_CTL + data = 0x60; + retval = rsi_reg_wr(0xfd, &data); + if (retval != RSI_SUCCESS) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_4, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + + // SDIO_WRITE_FIFO_CTL + data = 0x20; + retval = rsi_reg_wr(0xfe, &data); + if (retval != RSI_SUCCESS) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_5, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_6, DRIVER, LOG_INFO, "retval: %d", retval); + return retval; +} + +/** + * @brief This API deinitializes SDIO host interface. + * + */ + +void rsi_sdio_deinit(void) +{ +#ifdef EFM32GG11B820F2048GL192 + rsi_sdio_hal_efm_deinit(); +#endif + return; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_mem_rd_wr.c b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_mem_rd_wr.c new file mode 100644 index 00000000..43a90a4d --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_mem_rd_wr.c @@ -0,0 +1,146 @@ +/******************************************************************************* +* @file rsi_sdio_mem_rd_wr.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_sdio_mem_rd_wr.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SDIO MEMRDWR: SPI Memory Read/Write functions, r/w memory on the module via the SPI interface + * + * + */ + +/* + Includes + */ +#include "rsi_driver.h" +#ifdef RSI_SDIO_INTERFACE +/* + Global Variables + */ +/** @addtogroup DRIVER1 +* @{ +*/ +/*===========================================================================*/ +/** + * @brief This API writes contents of dBuf buffer to the device memory address addr for the length len + * @param[in] addr - Device memory address. + * @param[in] len - Length of the buffer. + * @param[in] dBuf - Data present in this buffer + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ + +int16_t rsi_mem_wr(uint32_t addr, uint16_t len, uint8_t *dBuf) +{ + uint8_t data; + int16_t retval = RSI_SUCCESS; + uint16_t no_of_blocks = 0; + data = ((addr & 0xff000000) >> 24); + // write MSB to 0xFB + retval = rsi_reg_wr(0xfb, &data); + if (retval != RSI_SUCCESS) + return retval; + + data = ((addr & 0x00ff0000) >> 16); + // write MSB to 0xFA + retval = rsi_reg_wr(0xfa, &data); + if (retval != RSI_SUCCESS) + return retval; + + if (len > 256) { + // Calculate number of blocks + no_of_blocks = (len / 256); + if (len % 256) { + no_of_blocks = no_of_blocks + 1; + } + // Transfer packet + return rsi_sdio_write_multiple(dBuf, (addr & 0xffff) | SD_MASTER_ACCESS, no_of_blocks); + } else { + return rsi_sdio_writeb((addr & 0xffff) | SD_MASTER_ACCESS, len, dBuf); + } +} + +/*===========================================================================*/ +/** + * @brief This API reads the device memory contents present at the address addr into the dBuf buffer for the length len + * @param[in] addr - Device memory address. + * @param[in] len - Length of the buffer. + * @param[in] dBuf - Destination buffer. + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ +int16_t rsi_mem_rd(uint32_t addr, uint16_t len, uint8_t *dBuf) +{ + int16_t retval = RSI_SUCCESS; + uint8_t data; + + data = ((addr & 0xff000000) >> 24); + // write MSB to 0xFB + retval = rsi_reg_wr(0xfb, &data); + if (retval != RSI_SUCCESS) + return retval; + + data = ((addr & 0x00ff0000) >> 16); + // write MSB to 0xFA + retval = rsi_reg_wr(0xfa, &data); + if (retval != RSI_SUCCESS) + return retval; + + return rsi_sdio_readb((addr & 0xffff) | SD_MASTER_ACCESS, len, dBuf); +} + +/*==================================================*/ +/** + * @brief This API reads the status register of the host interface layer to validate the interrupt received. + * @param[in] int_status - Interrupt status. + * @return 0 - Success \n + * @return Non-zero value - Failure (**Possible Error Codes** - 0xffffffd0, ) \n + * + */ +int16_t rsi_device_interrupt_status(uint8_t *int_status) +{ + int16_t retval; + uint32_t timeout; + timeout = RSI_SDIO_TIMEOUT; + RSI_RESET_SDIO_TIMER; + while (1) { + if (RSI_INC_SDIO_TIMER > timeout) { + retval = RSI_ERROR_SDIO_TIMEOUT; + break; + } + // Read the interrupt register + retval = rsi_reg_rd(RSI_SDIO_INTF_STATUS_REG, int_status); + + if (retval == 0) { + break; + } + } + + return retval; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_reg_rd_wr.c b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_reg_rd_wr.c new file mode 100644 index 00000000..49c7d83a --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/sdio/rsi_sdio_reg_rd_wr.c @@ -0,0 +1,72 @@ +/******************************************************************************* +* @file rsi_sdio_reg_rd_wr.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_spi_reg_rd_wr.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SDIO REGRDWR: SDIO Register Read/Write functions + * + * + * + */ + +/* + Includes + */ +#include "rsi_driver.h" +#ifdef RSI_SDIO_INTERFACE +/* + Global Variables + */ +/** @addtogroup DRIVER1 +* @{ +*/ +/** + * @brief This API reads the content of the host interface register regAddr to the buffer dBuf + * @param[in] regAddr - Host interface. + * @param[in] dBuf - Buffer. + * @return 0 - Success \n + * + */ +int16_t rsi_reg_rd(uint8_t regAddr, uint8_t *dBuf) +{ + return sdio_reg_readb(regAddr, dBuf); +} + +/** + * @brief This API writes the content provided by dBuf to the host interface register regAddr + * @param[in] regAddr - Destination address. + * @param[in] dBuf - Buffer with the content to be written to the register. + * @return 0 - Success \n + * + */ + +int16_t rsi_reg_wr(uint8_t regAddr, uint8_t *dBuf) +{ + return sdio_reg_writeb(regAddr, dBuf); +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_frame_rd_wr.c b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_frame_rd_wr.c new file mode 100644 index 00000000..6c8fb2a7 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_frame_rd_wr.c @@ -0,0 +1,405 @@ +/******************************************************************************* +* @file rsi_spi_frame_rd_wr.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_spi_frame_rd_wr.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SPI Control: Control SPI frame read/write functions + * + * Description + * SPI function to read/write management descriptors frames to/from the Wi-Fi module + * + * Improvements + * Function header is modified for frameDscRd() function + */ + +/* + * Includes + */ +#include "rsi_driver.h" + +#if ((defined DEBUG_PACKET_EXCHANGE) && (defined RSI_DEBUG_PRINTS)) +#include +#define MAX_PRINT_PAYLOAD_LEN 8 +#define DEBUG_OUTPUT_SZ (80 + MAX_PRINT_PAYLOAD_LEN * 2) +char debug_output[DEBUG_OUTPUT_SZ]; +#endif + +#ifdef RSI_SPI_INTERFACE +/* + Global Variables + */ + +/** @} */ +/** @addtogroup DRIVER2 +* @{ +*/ + +/*====================================================*/ +/** + * @brief Read response for every command and data sent from the module + * @param[in] pkt_buffer - pointer to buffer to which packet has to be read + * @return 0 - Success \n + * @return Non-Zero Failure - Failure \n + * @note Enable DEBUG_PACKET_EXCHANGE macro for SPI level packet exchange debug prints and + * MAX_PRINT_PAYLOAD_LEN for configuring number of bytes of payload to print, + * by default it will print 8 bytes of payload. + * + */ +int16_t rsi_frame_read(uint8_t *pkt_buffer) +{ + + int16_t retval; + uint8_t local_buffer[8]; + // Read first 4 bytes + retval = rsi_pre_dsc_rd(&local_buffer[0]); + if (retval != RSI_SUCCESS) { + return retval; + } + // Read complete RX packet + retval = rsi_pkt_rd(pkt_buffer, + ((rsi_bytes2R_to_uint16(&local_buffer[2])) - 4), + ((rsi_bytes2R_to_uint16(&local_buffer[0])) - 4)); + if (retval != RSI_SUCCESS) { + return retval; + } + +#ifdef DEBUG_PACKET_EXCHANGE + uint16_t size = rsi_bytes2R_to_uint16(pkt_buffer) & 0x0FFF; + memset(debug_output, '\0', sizeof(debug_output)); + sprintf(debug_output, "[RD(%d)]", rsi_hal_gettickcount()); + for (uint32_t i = 0; i < 16; i++) { + sprintf(debug_output, "%s%.2x", debug_output, pkt_buffer[i]); + } + if (size) { + sprintf(debug_output, "%s | ", debug_output); + // Print max of 8 bytes of payload + for (uint32_t i = 0; i < size && i < MAX_PRINT_PAYLOAD_LEN; i++) { + sprintf(debug_output, "%s%.2x", debug_output, pkt_buffer[16 + i]); + } + } + LOG_PRINT("%s\r\n", debug_output); +#endif + return retval; +} + +/*====================================================*/ +/** + * @brief Process a command to the module. + * @param[in] uFrameDscFrame - Frame descriptor + * @param[in] payloadparam - Pointer to the command payload parameter structure + * @param[in] size_param - Size of the payload for the command + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * @note Enable DEBUG_PACKET_EXCHANGE macro for SPI level packet exchange debug prints and + * MAX_PRINT_PAYLOAD_LEN for configuring number of bytes of payload to print, + * by default it will print 8 bytes of payload. + * + */ +int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param) +{ + int16_t retval; + +#ifdef DEBUG_PACKET_EXCHANGE + memset(debug_output, '\0', sizeof(debug_output)); + sprintf(debug_output, "[WR(%d)]", rsi_hal_gettickcount()); + for (uint32_t i = 0; i < 16; i++) { + sprintf(debug_output, "%s%.2x", debug_output, ((char *)(uFrameDscFrame))[i]); + } + if (size_param) { + sprintf(debug_output, "%s | ", debug_output); + // Print max of 8 bytes of payload + for (uint32_t i = 0; i < size_param && i < MAX_PRINT_PAYLOAD_LEN; i++) { + sprintf(debug_output, "%s%.2x", debug_output, payloadparam[i]); + } + } + LOG_PRINT("%s\r\n", debug_output); +#endif + // Write host descriptor + retval = rsi_spi_frame_dsc_wr(uFrameDscFrame); + if (retval != RSI_SUCCESS) { + return retval; + } + + // Write payload if present + if (size_param) { + // 4 byte align for payload size + size_param = (size_param + 3) & ~3; + retval = rsi_spi_frame_data_wr(size_param, payloadparam, 0, NULL); + if (retval != RSI_SUCCESS) { + return retval; + } + } + return retval; +} + +/*===========================================================================*/ +/** + * @brief Read a pre-frame descriptor + * @param[in] dbuf - Pointer to the buffer into which pre-decriptor has to be read + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ +int16_t rsi_pre_dsc_rd(uint8_t *dbuf) +{ + int16_t retval; + uint8_t c1; + uint8_t c2; + uint8_t c3; + uint8_t c4; + + c1 = RSI_C1FRMRD16BIT4BYTE; +#ifdef RSI_BIT_32_SUPPORT + c2 = RSI_C2SPIADDR4BYTE; +#else + c2 = RSI_C2MEMRDWRNOCARE; +#endif + // Command frame response descriptor + c3 = 0x04; + + // Upper byte of transfer length + c4 = 0x00; + + // Send C1/C2 + retval = rsi_send_c1c2(c1, c2); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // Send C3/C4 + retval = rsi_send_c3c4(c3, c4); + if (retval != RSI_SUCCESS) { + return retval; + } + + // Wait for start token + retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // SPI read after start token + retval = rsi_spi_transfer(NULL, (uint8_t *)dbuf, 0x4, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + + return retval; +} + +/*===========================================================================*/ +/** + * @brief Read frame descriptor and payload + * @param[in] buf - Pointer to the buffer into which decriptor and payload has to be read + * @param[in] dummy_len - Number of dummy bytes which can be discarded + * @param[in] total_len - Number of bytes to be read + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ + +int16_t rsi_pkt_rd(uint8_t *buf, uint16_t dummy_len, uint16_t total_len) +{ + int16_t retval; + uint8_t c1; + uint8_t c2; + uint8_t c3; + uint8_t c4; +#ifdef SAPIS_BT_STACK_ON_HOST + uint8_t dummy_buf[150]; +#else + uint8_t dummy_buf[8]; +#endif + uint32_t aligned_len = 0; + + aligned_len = ((total_len) + 3) & ~3; + + c1 = RSI_C1FRMRD16BIT1BYTE; +#ifdef RSI_BIT_32_SUPPORT + c2 = RSI_C2SPIADDR1BYTE; +#else + c2 = RSI_C2MEMRDWRNOCARE; +#endif + // Command frame response descriptor + c3 = aligned_len & 0xff; + + // Upper byte of transfer length + c4 = (aligned_len & 0xff00) >> 8; + + // Send C1/C2 + retval = rsi_send_c1c2(c1, c2); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // Send C3/C4 + retval = rsi_send_c3c4(c3, c4); + if (retval != RSI_SUCCESS) { + return retval; + } + + // Wait for start token + retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + if (dummy_len) { + retval = rsi_spi_transfer(NULL, (uint8_t *)&dummy_buf[0], dummy_len, RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + } + + // Actual spi read for descriptor and payload + if (buf) { + retval = rsi_spi_transfer(NULL, buf, (aligned_len - dummy_len), RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + } + + return retval; +} + +/*===========================================================================*/ +/** + * @brief Write the frame descriptor + * @param[in] uFrameDscFrame - Frame descriptor + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ +int16_t rsi_spi_frame_dsc_wr(rsi_frame_desc_t *uFrameDscFrame) +{ + int16_t retval; + uint8_t localBuf[16]; + uint8_t c1; + uint8_t c2; + uint8_t c3; + uint8_t c4; + + c1 = RSI_C1FRMWR16BIT4BYTE; +#ifdef RSI_BIT_32_SUPPORT + c2 = RSI_C2RDWR4BYTE; +#else + c2 = RSI_C2RDWR1BYTE; +#endif + // Frame descriptor is 16 bytes long + c3 = RSI_FRAME_DESC_LEN; + + // Upper byte of transfer length + c4 = 0x00; + + // Send C1/C2 + retval = rsi_send_c1c2(c1, c2); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // Send C3/C4 + retval = rsi_send_c3c4(c3, c4); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + // SPI send + retval = rsi_spi_transfer(uFrameDscFrame->frame_len_queue_no, localBuf, RSI_FRAME_DESC_LEN, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + return retval; +} + +/*===========================================================================*/ +/** + * @brief Write frame data + * @param[in] buflen - Length of the data buffer to write + * @param[in] dBuf - Pointer to the buffer of data to write + * @param[in] tbuflen - Length of the data fragment to write + * @param[in] tBuf - Pointer to the buffer of data fragment to write + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ +int16_t rsi_spi_frame_data_wr(uint16_t bufLen, uint8_t *dBuf, uint16_t tbufLen, uint8_t *tBuf) +{ + int16_t retval; + uint8_t c1; + uint8_t c2; + uint8_t c3; + uint8_t c4; + uint16_t tempbufLen; + tempbufLen = bufLen + tbufLen; + + c1 = RSI_C1FRMWR16BIT4BYTE; +#ifdef RSI_BIT_32_SUPPORT + c2 = RSI_C2RDWR4BYTE; +#else + c2 = RSI_C2RDWR1BYTE; +#endif + // Lower byte of transfer length + c3 = (uint8_t)(tempbufLen & 0x00ff); + + // Upper byte of transfer length + c4 = (uint8_t)((tempbufLen >> 8) & 0x00FF); + + // Send C1/C2 + retval = rsi_send_c1c2(c1, c2); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // Send C3/C4 + retval = rsi_send_c3c4(c3, c4); + if (retval != RSI_SUCCESS) { + return retval; + } + + // SPI send + retval = rsi_spi_transfer(dBuf, NULL, bufLen, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + if (tbufLen) { + retval = rsi_spi_transfer(tBuf, NULL, tbufLen, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + } + + return retval; +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_functs.c b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_functs.c new file mode 100644 index 00000000..5f925687 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_functs.c @@ -0,0 +1,357 @@ +/******************************************************************************* +* @file rsi_spi_functs.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_spi_functs.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief Common SPI Functions + * + * Description + * SPI bus Layer function used to transfer spi protocol level commands to module. + * For more details and for spi commands, refer to the Programming Reference Manual. + * + */ + +/* + * Includes + */ +#include "rsi_driver.h" + +#ifdef RSI_SPI_INTERFACE + +/* + Global Variables + */ +/** @addtogroup DRIVER2 +* @{ +*/ +/*==================================================*/ +/** + * @brief Send the C1 and C2 commands. Check response for C1 command, if busy, should retry. + * @param[in] c1 - SPI c1 command + * @param[in] c2 - SPI c2 command + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ +int16_t rsi_send_c1c2(uint8_t c1, uint8_t c2) +{ + int16_t retval; + uint32_t timeout; + uint8_t txCmd[2]; + uint8_t localBuf[8]; + + timeout = 1 * RSI_TICKS_PER_SECOND; + + // Reset the timeout timer to 0 + RSI_RESET_TIMER1; + + while (1) { + txCmd[0] = c1; + txCmd[1] = c2; + if (RSI_INC_TIMER_1 > timeout) { + retval = RSI_ERROR_SPI_TIMEOUT; + break; + } + + // Send C1 & C2 + retval = rsi_spi_transfer(&txCmd[0], localBuf, 2, RSI_MODE_8BIT); + if ((localBuf[1] == RSI_SPI_SUCCESS) || (localBuf[1] == 0x00)) { + // Success, return now + retval = RSI_SUCCESS; + break; + } else if (localBuf[1] == RSI_SPI_FAIL) { + retval = RSI_ERROR_SPI_FAIL; + break; + } else if (localBuf[1] == RSI_SPI_BUSY) { + // Busy, retry once again + retval = RSI_ERROR_SPI_BUSY; + } + } + + return retval; +} + +/*==================================================*/ +/** + * @brief Send the C3 and C4 commands. + * @param[in] c3 - SPI c3 command bytes to be sent + * @param[in] c4 - SPI c4 command bytes to be sent + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * @note A succesful rsi_send_c1c2() is required before this function. + */ +int16_t rsi_send_c3c4(uint8_t c3, uint8_t c4) +{ + int16_t retval; + // Command buffer + uint8_t txCmd[2]; + + txCmd[0] = c3; + txCmd[1] = c4; + + // Command should only send 8-bit mode + retval = rsi_spi_transfer(txCmd, NULL, 2, RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + + return retval; +} + +/*==================================================*/ +/** + * @brief Loop read the SPI until a start token (i.e., 0x55) is received. + * @param[in] timeout - Timeout for start token. + * @param[in] mode - To indicate 8-bit/32-bit mode. + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * @note Should issue read commands before using this function + */ +int16_t rsi_spi_wait_start_token(uint32_t timeout, uint8_t mode) +{ + int16_t retval; +#ifdef RSI_BIT_32_SUPPORT + // Char to send/receive data in + uint32_t txChar; +#else + uint8_t txChar; +#endif + // Look for start token + // Send a character, could be any character, and check the response for a start token + // If not found within the timeout time, error out + // Timeout value needs to be passed since context is important + // Reset the timeout timer to 0; + RSI_RESET_TIMER1; + + while (1) { + if (RSI_INC_TIMER_1 > timeout) { + retval = RSI_ERROR_SPI_BUSY; + // Timeout + break; + } + + txChar = 0x00; +#ifdef RSI_BIT_32_SUPPORT + if (mode == RSI_MODE_8BIT) +#endif + retval = rsi_spi_transfer(NULL, &txChar, 1, mode); +#ifdef RSI_BIT_32_SUPPORT + else + retval = rsi_spi_transfer(NULL, (uint8_t *)&txChar, 4, mode); +#endif + if (txChar == RSI_SPI_START_TOKEN) { + // Found the start token + retval = RSI_SUCCESS; + break; + } + } + return retval; +} + +/*==================================================*/ +/** + * @brief Set the interrupt mask register of the module + * @param[in] interruptMask - The value to set the mask register to + * @return 0 - Success \n + * @return Non-Zero value - Failure \n +*/ +int16_t rsi_set_intr_mask(uint8_t interruptMask) +{ + int16_t retval; + int16_t i; +#ifdef RSI_BIT_32_SUPPORT + uint8_t dBuf[4] = { 0, 0, 0, 0 }; +#else + uint8_t dBuf[2] = { 0, 0 }; +#endif + + // Create the data to write to the interrupt mask register + for (i = 0; (uint16_t)i < sizeof(dBuf); i++) { + dBuf[i] = 0; + } + + dBuf[0] = interruptMask; + + // Memory write the mask value + retval = rsi_mem_wr(RSI_INT_MASK_REG_ADDR, sizeof(dBuf), dBuf); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + return retval; +} + +/*==================================================*/ +/** + * @brief Set the interrupt type of the module + * @param[in] interruptMaskVal - The value to set the mask register + * @return 0 - Success \n + * @return Non-Zero value - Failure \n +*/ + +int16_t rsi_set_intr_type(uint32_t interruptMaskVal) +{ + int16_t retval; +#ifdef RSI_BIT_32_SUPPORT + uint8_t dBuf[4] = { 0, 0, 0, 0 }; +#else + uint8_t dBuf[2] = { 0, 0 }; +#endif + + retval = rsi_mem_rd(RSI_INT_MASK_REG_ADDR, sizeof(dBuf), dBuf); + + if (!retval) { + dBuf[1] = dBuf[1] & 0xFC; + dBuf[1] = dBuf[1] | interruptMaskVal; + // Memory write the mask value + retval = rsi_mem_wr(RSI_INT_MASK_REG_ADDR, sizeof(dBuf), dBuf); + if (retval != RSI_SUCCESS) { + // exit with error if we timed out waiting for the SPI to get ready + return retval; + } + } + + return retval; +} + +/*==================================================*/ +/** + * @brief Clear the interrupt register. + * @param[in] interrutClear - The value to set the interrupt clear register to + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ +int16_t rsi_clear_interrupt(uint8_t interruptClear) +{ + int16_t retval; +#ifdef RSI_BIT_32_SUPPORT + uint8_t dBuf[4] = { 0, 0, 0, 0 }; +#else + uint8_t dBuf[2] = { 0, 0 }; +#endif + // Read in the register to set bit 5 and write back out + // Retval = rsi_memRd(RSI_INT_CLR_REG_ADDR, sizeof(dBuf), dBuf); + // 0x74, 0x00, 0x22000010 + // Set bit 5, interrupt clear + dBuf[0] |= interruptClear; + + // Memory write the mask value + retval = rsi_mem_wr(RSI_INT_CLR_REG_ADDR, sizeof(dBuf), dBuf); + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + return retval; +} + +/*==================================================*/ +/** + * @brief Read the SPI interrupt register status + * @param[in] int_status - Pointer to the buffer of data to be read, assumed to be at least a byte + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ +int16_t rsi_device_interrupt_status(uint8_t *int_status) +{ + int16_t retval; + uint32_t timeout; + + timeout = 1 * RSI_TICKS_PER_SECOND; + + RSI_RESET_TIMER2; + while (1) { + if (RSI_INC_TIMER_2 > timeout) { + // Timeout + retval = RSI_ERROR_SPI_TIMEOUT; + break; + } + + // Read the interrupt register + retval = rsi_reg_rd(RSI_SPI_INT_REG_ADDR, int_status); + + if (retval != RSI_ERROR_SPI_BUSY) { + break; + } + } + + return retval; +} + +/*==================================================*/ +/** + * @brief Read the length of the incoming packet to the module + * @param[in] length - Pointer to the buffer of data to write, assumed to be at least 2 bytes long + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ +int16_t rsi_spi_pkt_len(uint16_t *length) +{ + int16_t retval; + uint32_t timeout; + + timeout = 1 * RSI_TICKS_PER_SECOND; + + RSI_RESET_TIMER2; + while (1) { + if (RSI_INC_TIMER_2 > timeout) { + // Timeout + retval = RSI_ERROR_SPI_BUSY; + break; + } + + // Read the interrupt register + retval = rsi_reg_rd2(RSI_SPI_LENGTH_REG_ADDR, length); + + if (retval != RSI_ERROR_SPI_BUSY) { + break; + } + } + + return retval; +} + +/*==================================================================*/ +/** + * @brief Configure the module SPI interface to high speed mode + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * @note This API should be called only if the SPI clock frequency is more than 25 MHz and shouldn't be called otherwise. + * @note SPI initialization has to be done in low-speed mode. After device SPI is configured to high-speed mode using this API, \n + * rsi_switch_to_high_clk_freq() will be executed to configure the host SPI to a frequency that is more than 25 MHz. \n + * The latter API has to be ported by the user to implement the host clock switch. + */ + +int16_t rsi_spi_high_speed_enable(void) +{ + uint8_t data = 0x3; + uint8_t return_val; + return_val = rsi_reg_wr(0x08, &data); + return return_val; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_iface_init.c b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_iface_init.c new file mode 100644 index 00000000..012a7d49 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_iface_init.c @@ -0,0 +1,125 @@ +/******************************************************************************* +* @file rsi_spi_iface_init.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_spi_iface_init.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SPI INIT: Functions to initiaize the SPI hardware interface in the module + * Description + * Contains the SPI Initialization function. + * Enable the SPI interface on the Wi-Fi chip. + * Only run once - during startup, after power-on, or reset + * + * + */ + +/* + Includes + */ +#include "rsi_driver.h" +#ifdef RSI_SPI_INTERFACE + +/* + Global Variables + */ +/** @addtogroup DRIVER2 +* @{ +*/ +/*=============================================*/ +/** + * @brief Initialize the SPI secondary device interface of the module + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ + +int16_t rsi_spi_iface_init(void) +{ + SL_PRINTF(SL_SPI_IFACE_INIT_ENTRY, DRIVER, LOG_INFO); + + uint8_t txCmd[4]; + uint8_t localBuf[4] = { 0 }; + int16_t retval = 0; + uint16_t timeout; + + // 10ms timeout on command, nothing magic, just a reasonable number + timeout = 10; + + // Init the timer counter + RSI_RESET_TIMER1; + while (1) { + if (RSI_INC_TIMER_1 > timeout) { + retval = RSI_ERROR_SPI_TIMEOUT; + break; + } + + txCmd[0] = (RSI_RS9116_INIT_CMD & 0xFF); + txCmd[1] = ((RSI_RS9116_INIT_CMD >> 8) & 0xFF); + txCmd[2] = ((RSI_RS9116_INIT_CMD >> 16) & 0xFF); + txCmd[3] = ((RSI_RS9116_INIT_CMD >> 24) & 0xFF); + + retval = rsi_spi_transfer(txCmd, localBuf, sizeof(localBuf), RSI_MODE_8BIT); + // Retval = rsi_spi_send(txCmd, 2, localBuf, RSI_MODE_8BIT); + if (localBuf[3] == RSI_SPI_SUCCESS) { + retval = RSI_SUCCESS; + break; + } else { + retval = RSI_ERROR_SPI_BUSY; + } + } + SL_PRINTF(SL_SPI_IFACE_INIT_EXIT, DRIVER, LOG_INFO, "retval: %d", retval); + return retval; +} + +/*=============================================*/ +/** + * @brief Initialize the SPI secondary device interface of the module on ULP wakeup + * @param[in] void + * @return Void + */ +void rsi_ulp_wakeup_init(void) +{ + uint8_t txCmd[4]; + uint8_t rxbuff[2]; + + txCmd[0] = (RSI_RS9116_INIT_CMD & 0xFF); + txCmd[1] = ((RSI_RS9116_INIT_CMD >> 8) & 0xFF); + txCmd[2] = ((RSI_RS9116_INIT_CMD >> 16) & 0xFF); + txCmd[3] = ((RSI_RS9116_INIT_CMD >> 24) & 0xFF); + + while (1) { + rsi_spi_transfer(txCmd, rxbuff, 2, RSI_MODE_8BIT); + if (rxbuff[1] == RSI_SPI_FAIL) { + return; + } else if (rxbuff[1] == 0x00) { + rsi_spi_transfer(&txCmd[2], rxbuff, 2, RSI_MODE_8BIT); + if (rxbuff[1] == RSI_SPI_SUCCESS) { + break; + } + } + } +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_mem_rd_wr.c b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_mem_rd_wr.c new file mode 100644 index 00000000..4b530f18 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_mem_rd_wr.c @@ -0,0 +1,186 @@ +/******************************************************************************* +* @file rsi_spi_mem_rd_wr.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_spi_mem_rd_wr.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SPI MEMRDWR: SPI Memory Read/Write functions, r/w memory on the module via the SPI interface + * Description + * Contains the SPI Memory Read/Write functions to the module + * + * + */ + +/* + Includes + */ +#include "rsi_driver.h" + +#ifdef RSI_SPI_INTERFACE + +/* + Global Variables + */ +/** @addtogroup DRIVER2 +* @{ +*/ +/*===========================================================================*/ +/** + * @brief Memory write to the module + * @param[in] addr - Address to write to + * @param[in] len - Number of bytes to write + * @param[in] dBuf - Pointer to the buffer of data to write + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + * + */ +int16_t rsi_mem_wr(uint32_t addr, uint16_t len, uint8_t *dBuf) +{ + uint8_t txCmd[4]; + int16_t retval; + uint8_t c1; + uint8_t c2; + uint8_t c3; + uint8_t c4; + + c1 = RSI_C1MEMWR16BIT4BYTE; +#ifdef RSI_BIT_32_SUPPORT + c2 = RSI_C2SPIADDR4BYTE; +#else + c2 = RSI_C2SPIADDR1BYTE; +#endif + // C3, LSB of length + c3 = (int8_t)(len & 0x00ff); + + // C4, MSB of length + c4 = (int8_t)((len >> 8) & 0x00ff); + + rsi_uint32_to_4bytes(txCmd, addr); + + // Send C1/C2 + retval = rsi_send_c1c2(c1, c2); + + // Check for SPI Busy/Error + if (retval != RSI_SUCCESS) { + return retval; + } + + // Send C3/C4 + retval = rsi_send_c3c4(c3, c4); + if (retval != RSI_SUCCESS) { + return retval; + } + + // Send the 4 address bytes + retval = rsi_spi_transfer(txCmd, NULL, sizeof(txCmd), RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + + // Send the Data +#ifdef RSI_BIT_32_SUPPORT + retval = rsi_spi_transfer(dBuf, NULL, len, RSI_MODE_32BIT); + if (retval != RSI_SUCCESS) { + return retval; + } +#else + retval = rsi_spi_transfer(dBuf, NULL, len, RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } +#endif + return retval; +} + +/*===========================================================================*/ +/** + * @brief Memory read from the module + * @param[in] addr - Address to read from + * @param[in] len - Number of bytes to read + * @param[in] dBuf - Pointer to the buffer to receive the data into + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + * + */ +int16_t rsi_mem_rd(uint32_t addr, uint16_t len, uint8_t *dBuf) +{ + uint8_t txCmd[4]; + int16_t retval; + uint8_t c1; + uint8_t c2; + uint8_t c3; + uint8_t c4; + uint8_t localBuf[8]; + + c1 = RSI_C1MEMRD16BIT4BYTE; +#ifdef RSI_BIT_32_SUPPORT + c2 = RSI_C2SPIADDR4BYTE; +#else + c2 = RSI_C2MEMRDWRNOCARE; +#endif + c3 = len & 0x00ff; // C3, LSB of length + c4 = (len >> 8) & 0x00ff; // C4, MSB of length + // Put the address bytes into the buffer to send + txCmd[0] = addr & 0x000000ff; // A0, Byte 0 of address (LSB) + txCmd[1] = (addr >> 8) & 0x000000ff; // A1, Byte 1 of address + txCmd[2] = (addr >> 16) & 0x000000ff; // A2, Byte 2 of address + txCmd[3] = (addr >> 24) & 0x000000ff; // A3, Byte 3 of address (MSB) + // Send C1/C2 + retval = rsi_send_c1c2(c1, c2); + + // Check for SPI busy + if (retval != RSI_SUCCESS) { + return retval; + } + + // Send C3/C4 + retval = rsi_send_c3c4(c3, c4); + if (retval != RSI_SUCCESS) { + return retval; + } + // Send the 4 address bytes + retval = rsi_spi_transfer(txCmd, localBuf, sizeof(txCmd), RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + // Wait for the start token + retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT, RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + // Read in the memory data + retval = rsi_spi_transfer(NULL, dBuf, len, RSI_MODE_8BIT); + if (retval != RSI_SUCCESS) { + return retval; + } + + return retval; +} + +#endif + +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_reg_rd_wr.c b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_reg_rd_wr.c new file mode 100644 index 00000000..6f18ac64 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/spi/rsi_spi_reg_rd_wr.c @@ -0,0 +1,178 @@ +/******************************************************************************* +* @file rsi_spi_reg_rd_wr.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_spi_reg_rd_wr.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief SPI REGRDWR: SPI Register Read/Write functions + * Description + * Contains the SPI based Register R/W functions + * + * + */ + +/* + Includes + */ +#include "rsi_driver.h" + +#ifdef RSI_SPI_INTERFACE + +/* + Global Variables + */ +/** @addtogroup DRIVER2 +* @{ +*/ +/** + * @brief Read from a register in the module from the address specified. + * @param[in] regAddr - Address of SPI register to read, address is 6-bits, upper 2 bits must be cleared + * @param[in] dBuf - Pointer to the buffer of data to write, assumed to be at least 2 bytes long + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + * + */ +int16_t rsi_reg_rd(uint8_t regAddr, uint8_t *dBuf) +{ + int16_t retval; + uint8_t c1; + uint8_t c2; + + // Set the C1/C2 values + c1 = RSI_C1INTREAD1BYTES; + c2 = 0x00; + // And/or the address into C2, addr is 6-bits long, upper two bits must be cleared for byte mode + c2 |= regAddr; + + // Send C1C2 + retval = rsi_send_c1c2(c1, c2); + + // Check for SPI Busy/Error + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // Wait for start token + retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT, RSI_MODE_8BIT); + + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for start token + return retval; + } + + // Start token found now read the two bytes of data + retval = rsi_spi_transfer(NULL, dBuf, 1, RSI_MODE_8BIT); + + return retval; +} + +/** + * @brief Read from a register in the wlan module from the address specified. + * @param[in] regAddr - Address of SPI register to read, address is 6-bits, upper 2 bits must be cleared + * @param[in] dBuf - Pointer to the buffer of data to write, assumed to be at least 2 bytes long + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + */ +int16_t rsi_reg_rd2(uint8_t regAddr, uint16_t *dBuf) +{ + int16_t retval; + uint8_t c1; + uint8_t c2; + + // Set the C1/C2 values + c1 = RSI_C1INTREAD2BYTES; + c2 = 0x00; + + // And/or the address into C2, addr is 6-bits long, upper two bits must be cleared for byte mode + c2 |= regAddr; + + // Send C1C2 + retval = rsi_send_c1c2(c1, c2); + + // Check for SPI Busy/Error + if (retval != 0) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // Wait for start token + retval = rsi_spi_wait_start_token(RSI_START_TOKEN_TIMEOUT, RSI_MODE_8BIT); + + if (retval != 0) { + // Exit with error if timed out waiting for start token + return retval; + } + + // Start token found now read the two bytes of data + retval = rsi_spi_transfer(NULL, (uint8_t *)dBuf, 2, RSI_MODE_8BIT); + + return retval; +} + +/** + * @brief Write to a register in the module with an address specified. + * @param[in] regAddr - Address of SPI register to be written + * @param[in] dBuf - Pointer to the buffer of data to write, assumed to be at least 2 bytes long + * @return 0 - Success \n + * @return Non-Zero value - Failure \n + + */ + +int16_t rsi_reg_wr(uint8_t regAddr, uint8_t *dBuf) +{ + int16_t retval; + uint8_t c1; + uint8_t c2; + uint8_t localBuf[8]; + + // Set the C1/C2 values + c1 = RSI_C1INTWRITE2BYTES; + c2 = 0x00; + + // And/or the address into C2, addr is 6-bits long, upper two bits must be cleared for byte mode + c2 |= regAddr; + + // Send C1C2 + retval = rsi_send_c1c2(c1, c2); + + // Check for SPI Busy/Error + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for the SPI to get ready + return retval; + } + + // SPI send + retval = rsi_spi_transfer(dBuf, localBuf, 2, RSI_MODE_8BIT); + + if (retval != RSI_SUCCESS) { + // Exit with error if timed out waiting for start token + return retval; + } + return retval; +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/device_interface/uart/rsi_uart.c b/wiseconnect/sapi/driver/device_interface/uart/rsi_uart.c new file mode 100644 index 00000000..165a4693 --- /dev/null +++ b/wiseconnect/sapi/driver/device_interface/uart/rsi_uart.c @@ -0,0 +1,134 @@ +/******************************************************************************* +* @file rsi_uart.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_uart.c + * @version 0.1 + * @date 15 Aug 2015 + * + * + * + * @brief : Contains UART HAL porting functionality + * + * Description Contains UART HAL porting functionality + * + * + */ +#include "rsi_driver.h" +#ifndef EFM32_SDIO // This file is not needed for EFM32 board. In order to avoid compilation warnings, we excluded the below code for EFM32 +#include "rsi_board_configuration.h" +#endif +#ifdef RSI_UART_INTERFACE +#include "stm32f4xx_hal.h" +#include "stm32f4xx_hal_uart.h" +extern UART_HandleTypeDef huart1; + +#include +#include +#include "rsi_data_types.h" +#include "rsi_error.h" +#include "rsi_utils.h" +#include "rsi_pkt_mgmt.h" +#include "rsi_os.h" +#include "rsi_queue.h" +#include "rsi_uart.h" +#include "rsi_events.h" + +rsi_linux_app_cb_t rsi_linux_app_cb; +/** @addtogroup DRIVER3 +* @{ +*/ +/*==============================================*/ +/** + * @brief Reads response for every command and data from the module. + * @param[in] pkt_buffer - pointer to buffer to which packet has to read + * @return 0 - Success \n + + */ + +int16_t rsi_frame_read(uint8_t *pkt_buffer) +{ + // API to read packet via UART interface + memcpy(pkt_buffer, uart_rev_buf + 4, desired_len); + + return 0; +} + +/*==============================================*/ +/** + * @brief Process a command to the wlan module. + * @param[in] uFrameDscFrame - Frame descriptor + * @param[in] payloadparam - Pointer to the command payload parameter structure + * @param[in] size_param - Size of the payload for the command + * @return 0 - SUCCESS \n + * < 0 - FAILURE \n + */ +int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param) +{ + int16_t retval = 0; + + // API to send packet via UART interface + retval = rsi_uart_send((uint8_t *)uFrameDscFrame, (size_param + RSI_FRAME_DESC_LEN)); + UNUSED_PARAMETER(payloadparam); //This statement is added only to resolve compilation warnings, value is unchanged + while (huart1.gState != HAL_UART_STATE_READY) + ; + while (huart1.TxXferCount != 0) + ; + return retval; +} + +/*==============================================*/ +/** + * @brief Initialize the UART interface of the module + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +int32_t rsi_uart_init(void) +{ + SL_PRINTF(SL_UART_INIT_ENTRY, DRIVER, LOG_INFO); + huart1.Instance = USART1; + huart1.Init.BaudRate = 921600; + huart1.Init.WordLength = UART_WORDLENGTH_8B; + huart1.Init.StopBits = UART_STOPBITS_1; + huart1.Init.Parity = UART_PARITY_NONE; + huart1.Init.Mode = UART_MODE_TX_RX; + huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart1.Init.OverSampling = UART_OVERSAMPLING_16; + SL_PRINTF(SL_UART_INIT_EXIT, DRIVER, LOG_INFO); + return 0; +} + +/*==============================================*/ +/** + * @brief De-initialize the UART interface of the module + * @param[in] void + * @return 0 - Success \n + */ + +int32_t rsi_uart_deinit(void) +{ + return 0; +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_bt_ble.c b/wiseconnect/sapi/driver/rsi_bt_ble.c new file mode 100644 index 00000000..109555aa --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_bt_ble.c @@ -0,0 +1,4570 @@ +/******************************************************************************* +* @file rsi_bt_ble.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include "rsi_driver.h" +/* + Include files + */ +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + +#include "rsi_bt.h" +#include "rsi_hid.h" +#include "rsi_bt_common.h" +#include "rsi_ble.h" +#ifdef RSI_BT_ENABLE +#include "rsi_bt_config.h" +#endif +#ifdef RSI_BLE_ENABLE +#include "rsi_ble_config.h" +#endif +#include "stdio.h" + +#ifdef SAPIS_BT_STACK_ON_HOST +#include "bt_stack_interface.h" +#endif + +#include "rsi_bt_sbc_codec.h" + +#define BT_SEM 0x1 +#define BT_CMD_SEM 0x2 +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Clear the Bluetooth wait bitmap + * @param[in] protocol_type - Protocol type + * @param[in] sem_type - Type + * @return void + * + */ + +void rsi_bt_clear_wait_bitmap(uint16_t protocol_type, uint8_t sem_type) +{ + + SL_PRINTF(SL_RSI_BT_CLEAR_WAIT_BITMAP_TRIGGER, + BLUETOOTH, + LOG_INFO, + "PROTOCOL_TYPE: %2x, SEM_TYPE: %1x", + protocol_type, + sem_type); +#ifndef RSI_BT_SEM_BITMAP + if (sem_type == BT_SEM) { + if (protocol_type == RSI_PROTO_BT_COMMON) { + rsi_driver_cb_non_rom->bt_wait_bitmap &= ~BIT(1); + } else if (protocol_type == RSI_PROTO_BT_CLASSIC) { + rsi_driver_cb_non_rom->bt_wait_bitmap &= ~BIT(2); + } else if (protocol_type == RSI_PROTO_BLE) { + rsi_driver_cb_non_rom->bt_wait_bitmap &= ~BIT(3); + } +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (protocol_type == RSI_PROTO_PROP_PROTOCOL) { + rsi_driver_cb_non_rom->bt_wait_bitmap &= ~BIT(4); + } +#endif + } else if (sem_type == BT_CMD_SEM) { + if (protocol_type == RSI_PROTO_BT_COMMON) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap &= ~BIT(1); + } else if (protocol_type == RSI_PROTO_BT_CLASSIC) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap &= ~BIT(2); + } else if (protocol_type == RSI_PROTO_BLE) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap &= ~BIT(3); + } +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (protocol_type == RSI_PROTO_PROP_PROTOCOL) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap &= ~BIT(4); + } +#endif + } +#endif +} +/** + * @brief Set the bt wait bitmap + * @param[in] protocol_type - Protocol + * @param[in] sem_type - Type + * @return void + * + */ +void rsi_bt_set_wait_bitmap(uint16_t protocol_type, uint8_t sem_type) +{ + + SL_PRINTF(SL_RSI_BT_SET_WAIT_BITMAP_TRIGGER, + BLUETOOTH, + LOG_INFO, + "PROTOCOL_TYPE: %2x, SEM_TYPE: %1x", + protocol_type, + sem_type); +#ifndef RSI_BT_SEM_BITMAP + if (sem_type == BT_SEM) { + if (protocol_type == RSI_PROTO_BT_COMMON) { + rsi_driver_cb_non_rom->bt_wait_bitmap |= BIT(1); + } else if (protocol_type == RSI_PROTO_BT_CLASSIC) { + rsi_driver_cb_non_rom->bt_wait_bitmap |= BIT(2); + } else if (protocol_type == RSI_PROTO_BLE) { + rsi_driver_cb_non_rom->bt_wait_bitmap |= BIT(3); + } +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (protocol_type == RSI_PROTO_PROP_PROTOCOL) { + rsi_driver_cb_non_rom->bt_wait_bitmap |= BIT(4); + } +#endif + } else if (sem_type == BT_CMD_SEM) { + if (protocol_type == RSI_PROTO_BT_COMMON) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap |= BIT(1); + } else if (protocol_type == RSI_PROTO_BT_CLASSIC) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap |= BIT(2); + } else if (protocol_type == RSI_PROTO_BLE) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap |= BIT(3); + } +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (protocol_type == RSI_PROTO_PROP_PROTOCOL) { + rsi_driver_cb_non_rom->bt_cmd_wait_bitmap |= BIT(4); + } +#endif + } +#endif +} +/** @} */ +/* + * Global Variables + * */ + +// rsi_bt_ble.c function declarations +void rsi_bt_common_register_callbacks(rsi_bt_get_ber_pkt_t rsi_bt_get_ber_pkt_from_app); +uint32_t rsi_bt_get_timeout(uint16_t cmd_type, uint16_t protocol_type); +uint32_t rsi_bt_get_status(rsi_bt_cb_t *bt_cb); +void rsi_ble_update_le_dev_buf(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_dev_buf_ind); +void rsi_add_remote_ble_dev_info(rsi_ble_event_enhance_conn_status_t *remote_dev_info); +void rsi_remove_remote_ble_dev_info(rsi_ble_event_disconnect_t *remote_dev_info); +int32_t rsi_driver_process_bt_resp( + rsi_bt_cb_t *bt_cb, + rsi_pkt_t *pkt, + void (*rsi_bt_async_callback_handler)(rsi_bt_cb_t *cb, uint16_t type, uint8_t *data, uint16_t length), + uint16_t protocol_type); +void rsi_bt_hid_register_callbacks(rsi_bt_on_hid_connect_t bt_on_hid_connect_event, + rsi_bt_on_hid_rx_data_t bt_on_hid_rx_data_event, + rsi_bt_on_hid_handshake_t bt_on_hid_handshake_event, + rsi_bt_on_hid_control_t bt_on_hid_control_event, + rsi_bt_on_hid_get_report_t bt_on_hid_get_report, + rsi_bt_on_hid_set_report_t bt_on_hid_set_report, + rsi_bt_on_hid_get_protocol_t bt_on_hid_get_proto, + rsi_bt_on_hid_set_protocol_t bt_on_hid_set_proto); +void rsi_ble_on_chip_memory_status_callbacks_register(chip_ble_buffers_stats_handler_t ble_on_chip_memory_status_event); +uint16_t rsi_bt_prepare_common_pkt(uint16_t cmd_type, void *cmd_struct, rsi_pkt_t *pkt); +uint16_t rsi_bt_prepare_classic_pkt(uint16_t cmd_type, void *cmd_struct, rsi_pkt_t *pkt); +uint16_t rsi_bt_prepare_le_pkt(uint16_t cmd_type, void *cmd_struct, rsi_pkt_t *pkt); + +/* + Global Variables + */ +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Register the bt-common callbacks + * @param[in] rsi_bt_get_ber_pkt_from_app - BER Call back + * @return void + * + * + */ + +void rsi_bt_common_register_callbacks(rsi_bt_get_ber_pkt_t rsi_bt_get_ber_pkt_from_app) +{ + // Get bt cb struct pointer + rsi_bt_common_specific_cb_t *bt_common_specific_cb = rsi_driver_cb->bt_global_cb->bt_common_specific_cb; + + // Assign the call backs to the respective call back + bt_common_specific_cb->rsi_bt_get_ber_pkt = rsi_bt_get_ber_pkt_from_app; +} + +/** + * @fn uint8_t rsi_bt_get_ACL_type(uint16_t rsp_type) + * @brief Determine the ACL packet type (BT classic) using the frame type + * @param[in] rsp_type - packet type + * @return 1 - HCI Command Packet, 2 - HCI ACL packet ,3 - HCI PER Packet\n + * Non-Zero Value - Failure (Not a BT Classic Packet) + * + * + */ + +uint8_t rsi_bt_get_ACL_type(uint16_t rsp_type) +{ + + SL_PRINTF(SL_RSI_BT_GET_ACL_TYPE_TRIGGER, BLUETOOTH, LOG_INFO, "RESPONSE_TYPE: %2x", rsp_type); + uint16_t proto_type = 0xFF; + uint8_t return_type = 0; + + if (((rsp_type >= RSI_BT_REQ_SET_LOCAL_COD) && (rsp_type <= RSI_BT_REQ_QUERY_LOCAL_COD)) + || ((rsp_type >= RSI_BT_REQ_SET_PROFILE_MODE) && (rsp_type <= RSI_BT_REQ_UNBOND)) + || ((rsp_type >= RSI_BT_REQ_USER_CONFIRMATION) && (rsp_type <= RSI_BT_REQ_DEL_LINKKEYS)) + || (rsp_type == RSI_BT_REQ_LINKKEY_REPLY) || ((rsp_type >= RSI_BT_REQ_PER_TX) && (rsp_type <= RSI_BT_REQ_PER_RX)) + || (rsp_type == RSI_BT_REQ_CW_MODE) + || ((rsp_type >= RSI_BT_REQ_SNIFF_MODE) && (rsp_type <= RSI_BT_REQ_SET_SSP_MODE)) + || (rsp_type == RSI_BT_REQ_SET_EIR) + || ((rsp_type >= RSI_BT_REQ_A2DP_CLOSE) && (rsp_type <= RSI_BT_REQ_BR_EDR_LP_HP_TRANSISTION)) + || ((rsp_type >= RSI_BT_REQ_A2DP_GET_CONFIG) && (rsp_type <= RSI_BT_REQ_A2DP_SET_CONFIG)) + || ((rsp_type >= RSI_BT_REQ_AVRCP_SET_ABS_VOL) && (rsp_type <= RSI_BT_REQ_GATT_CONNECT)) + || (rsp_type == RSI_BT_REQ_CHANGE_CONNECTION_PKT_TYPE) + || ((rsp_type >= RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1) && (rsp_type <= RSI_BT_REQ_AVRCP_GET_TOT_NUM_ITEMS_RESP)) + || ((rsp_type >= RSI_BT_REQ_IAP_CONN) && (rsp_type <= RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_DATA))) { + proto_type = RSI_PROTO_BT_CLASSIC; + } + + if (proto_type == RSI_PROTO_BT_CLASSIC) { + if ((((rsp_type >= RSI_BT_REQ_SET_LOCAL_COD) && (rsp_type <= RSI_BT_REQ_QUERY_LOCAL_COD)) + || ((rsp_type >= RSI_BT_REQ_SET_DISCV_MODE) && (rsp_type <= RSI_BT_REQ_UNBOND)) + || ((rsp_type >= RSI_BT_REQ_USER_CONFIRMATION) && (rsp_type <= RSI_BT_REQ_SET_ROLE)) + || ((rsp_type >= RSI_BT_REQ_ENABLE_AUTH) && (rsp_type <= RSI_BT_REQ_DEL_LINKKEYS)) + || (rsp_type == RSI_BT_REQ_LINKKEY_REPLY) + || ((rsp_type >= RSI_BT_REQ_SNIFF_MODE) && (rsp_type <= RSI_BT_REQ_SET_SSP_MODE)) + || (rsp_type == RSI_BT_REQ_SET_EIR) || (rsp_type == RSI_BT_REQ_SET_AFH_HOST_CHANNEL_CLASSIFICATION) + || ((rsp_type >= RSI_BT_REQ_SET_CURRENT_IAC_LAP) && (rsp_type <= RSI_BT_REQ_BR_EDR_LP_HP_TRANSISTION)) + || (rsp_type == RSI_BT_REQ_CHANGE_CONNECTION_PKT_TYPE))) { + return_type = RSI_BT_HCI_CMD_PKT; + } else if ((rsp_type >= RSI_BT_REQ_PER_TX) && (rsp_type <= RSI_BT_REQ_CW_MODE)) { + return_type = RSI_BT_HCI_PER_CMD_PKT; + } else { + return_type = RSI_BT_HCI_ACL_PKT; + } + } + return return_type; +} +/** + * @brief Determine the BT protocol (BT COMMON / BT classic / BLE ) using the packet type + * @param[in] rsp_type - Packet type + * @param[in] bt_cb - BT control back + * @return 0 - Success \n + * Non-Zero Value - Failure + * + * + */ + +uint16_t rsi_bt_get_proto_type(uint16_t rsp_type, rsi_bt_cb_t **bt_cb) +{ + SL_PRINTF(SL_RSI_BT_GET_PROTO_TYPE_TRIGGER, BLUETOOTH, LOG_INFO, "RESPONSE_TYPE: %2x", rsp_type); + uint16_t return_value = 0xFF; + //static uint16_t local_prototype; + //static rsi_bt_cb_t *local_cb; + + if (rsp_type == RSI_BT_EVT_DISCONNECTED) { + /* if (!((rsi_driver_cb->common_cb->ps_coex_mode & RSI_BT_BLE_MODE_BITS) == RSI_BT_DUAL_MODE)) { + *bt_cb = local_cb; + return local_prototype; + } else { */ +#ifdef RSI_BT_ENABLE + if (rsi_driver_cb->bt_common_cb->dev_type == RSI_BT_CLASSIC_DEVICE) { + return_value = RSI_PROTO_BT_CLASSIC; + *bt_cb = rsi_driver_cb->bt_classic_cb; + } +#endif +#ifdef RSI_BLE_ENABLE + if (rsi_driver_cb->bt_common_cb->dev_type == RSI_BT_LE_DEVICE) { + return_value = RSI_PROTO_BLE; + *bt_cb = rsi_driver_cb->ble_cb; + } +#endif + + return return_value; + //} + } + /** @} */ + // Determine the protocol type by looking at the packet type + if ((rsp_type == RSI_BT_EVENT_CARD_READY) + || ((rsp_type >= RSI_BT_SET_LOCAL_NAME) && (rsp_type <= RSI_BT_GET_LOCAL_DEV_ADDR)) + || ((rsp_type >= RSI_BT_REQ_INIT) && (rsp_type <= RSI_BT_SET_ANTENNA_SELECT)) + || (rsp_type == RSI_BT_SET_FEATURES_BITMAP) || (rsp_type == RSI_BT_SET_ANTENNA_TX_POWER_LEVEL) + || (rsp_type == RSI_BT_SET_BD_ADDR_REQ) || (rsp_type == RSI_BLE_ONLY_OPER_MODE) + || (rsp_type == RSI_BLE_REQ_PWRMODE) || (rsp_type == RSI_BLE_REQ_SOFTRESET) || (rsp_type == RSI_BT_REQ_PER_CMD) + || (rsp_type == RSI_BT_VENDOR_SPECIFIC) || (rsp_type == RSI_BT_GET_BT_STACK_VERSION) + || (rsp_type == RSI_BT_REQ_L2CAP_CONNECT) || (rsp_type == RSI_BT_REQ_L2CAP_DISCONNECT) + || (rsp_type == RSI_BT_REQ_L2CAP_PROTOCOL_DATA) || (rsp_type == RSI_BT_REQ_L2CAP_ERTM_CONFIGURE) + || (rsp_type == RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE)) { + return_value = RSI_PROTO_BT_COMMON; + *bt_cb = rsi_driver_cb->bt_common_cb; + } +#ifdef RSI_BT_ENABLE + else if (((rsp_type >= RSI_BT_REQ_SET_LOCAL_COD) && (rsp_type <= RSI_BT_REQ_QUERY_LOCAL_COD)) + || ((rsp_type >= RSI_BT_REQ_SET_PROFILE_MODE) && (rsp_type <= RSI_BT_REQ_PBAP_CONTACTS)) + || ((rsp_type >= RSI_BT_REQ_HID_CONNECT) && (rsp_type <= RSI_BT_REQ_HID_SDP_ATT_INIT)) + || (rsp_type == RSI_BT_REQ_LINKKEY_REPLY) + || ((rsp_type >= RSI_BT_REQ_PER_TX) && (rsp_type <= RSI_BT_REQ_CW_MODE)) + || ((rsp_type >= RSI_BT_REQ_SNIFF_MODE) && (rsp_type <= RSI_BT_REQ_SET_SSP_MODE)) + || (rsp_type == RSI_BT_REQ_SET_EIR) + || ((rsp_type >= RSI_BT_REQ_A2DP_CLOSE) && (rsp_type <= RSI_BT_REQ_BR_EDR_LP_HP_TRANSISTION)) + || (rsp_type == RSI_BT_REQ_CHANGE_CONNECTION_PKT_TYPE) || (rsp_type == RSI_BT_REQ_A2DP_GET_CONFIG) + || (rsp_type == RSI_BT_REQ_A2DP_SET_CONFIG) + || ((rsp_type >= RSI_BT_REQ_AVRCP_SET_ABS_VOL) && (rsp_type <= RSI_BT_REQ_GATT_CONNECT)) + || ((rsp_type >= RSI_BT_EVT_ROLE_CHANGE_STATUS) && (rsp_type <= RSI_BT_EVENT_CONNECTION_INITIATED)) + || ((rsp_type >= RSI_BT_EVT_SPP_RECEIVE) && (rsp_type <= RSI_BT_EVT_SPP_DISCONNECTED)) + || ((rsp_type >= RSI_BT_EVT_A2DP_CONNECTED) && (rsp_type <= RSI_BT_EVT_A2DP_RECONFIG)) + || ((rsp_type >= RSI_BT_EVT_AVRCP_CONNECTED) && (rsp_type <= RSI_BT_EVT_AVRCP_GET_TOT_NUM_ITEMS)) + || ((rsp_type >= RSI_BT_EVT_HFP_CONN) && (rsp_type <= RSI_BT_EVT_HFP_AUDIO_CODECSELECT)) + || ((rsp_type >= RSI_BT_EVT_PBAP_CONN) && (rsp_type <= RSI_BT_EVT_PBAP_DATA)) + || (rsp_type == RSI_BT_EVENT_HID_CONN) || (rsp_type == RSI_BT_EVENT_HID_RXDATA) + || (rsp_type == RSI_BT_EVENT_PKT_CHANGE) || (rsp_type == RSI_BT_DISABLED_EVENT) + || (rsp_type == BT_VENDOR_DYNAMIC_PWR_OPCODE) || (rsp_type == RSI_BT_EVT_AR_STATS) + || (rsp_type == BT_VENDOR_AFH_CLASSIFICATION_CMD_OPCODE) + || ((rsp_type >= RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1) + && (rsp_type <= RSI_BT_REQ_AVRCP_GET_TOT_NUM_ITEMS_RESP)) + || (rsp_type == RSI_BT_EVENT_L2CAP_CONN) || (rsp_type == RSI_BT_EVENT_L2CAP_RXDATA) + || ((rsp_type >= RSI_BT_REQ_ENABLE_AUTH) && (rsp_type <= RSI_BT_REQ_DEL_LINKKEYS)) + || (rsp_type == RSI_BT_LINK_POLICY_CONFIG)) + + { + return_value = RSI_PROTO_BT_CLASSIC; + *bt_cb = rsi_driver_cb->bt_classic_cb; + } else if ((rsp_type == RSI_BT_REQ_IAP_SET_ACCESSORY_INFO) || (rsp_type == RSI_BT_REQ_IAP_SET_PROTOCOL_TYPE) + || (rsp_type == RSI_BT_REQ_IAP1_IDENTIFICATION) || (rsp_type == RSI_BT_REQ_IAP2_IDENTIFICATION) + || (rsp_type == RSI_BT_REQ_IAP_FIND_PROTOCOL_TYPE) || (rsp_type == RSI_BT_EVENT_IAP_DISCONN) + || (rsp_type == RSI_BT_EVENT_IAP_ACC_AUTH_STARTED) || (rsp_type == RSI_BT_EVENT_IAP_ACC_AUTH_FAILED) + || (rsp_type == RSI_BT_EVENT_IAP2_AUTH_START) || (rsp_type == RSI_BT_EVENT_IAP2_AUTH_COMPLETE) + || (rsp_type == RSI_BT_EVENT_IAP2_AUTH_FAILED) || (rsp_type == RSI_BT_EVENT_IAP2_IDENTIFICATION_START) + || (rsp_type == RSI_BT_EVENT_IAP2_IDENTIFICATION_COMPLETE) + || (rsp_type == RSI_BT_EVENT_IAP2_IDENTIFICATION_REJECT) + || (rsp_type == RSI_BT_EVENT_IAP_ACC_AUTH_COMPLETE) + || (rsp_type == RSI_BT_REQ_IAP2_CONTROL_SESSION_DATA_TX) || (rsp_type == RSI_BT_EVENT_IAP2_RX_DATA) + || (rsp_type == RSI_BT_REQ_IAP2_RECV_CMD_LIST) || (rsp_type == RSI_BT_REQ_IAP2_SEND_CMD_LIST) + || (rsp_type == RSI_BT_REQ_IAP2_INIT_FILE_TRANSFER) || (rsp_type == RSI_BT_REQ_IAP2_DE_INIT_FILE_TRANSFER) + || (rsp_type == RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_STATE) + || (rsp_type == RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_DATA) + || (rsp_type == RSI_BT_EVENT_IAP2_RX_FILE_TRANSFER_STATE) + || (rsp_type == RSI_BT_EVENT_IAP2_RX_FILE_TRANSFER_DATA) || (rsp_type == RSI_BT_EVENT_IAP_CONN) + || (rsp_type == RSI_BT_EVENT_PKT_CHANGE) || (rsp_type == RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1) + || (rsp_type == RSI_BT_LINK_POLICY_CONFIG)) { + return_value = RSI_PROTO_BT_CLASSIC; + *bt_cb = rsi_driver_cb->bt_classic_cb; + } +#endif +#ifdef RSI_BLE_ENABLE + else if (((rsp_type >= RSI_BLE_REQ_ADV) && (rsp_type <= RSI_BLE_REQ_EXECUTE_WRITE)) + || ((rsp_type >= RSI_BLE_ADD_SERVICE) && (rsp_type <= RSI_BLE_CMD_INDICATE)) + || (rsp_type == RSI_BLE_SET_ADVERTISE_DATA) + || ((rsp_type >= RSI_BLE_GET_LE_PING) && (rsp_type <= RSI_BLE_CMD_READ_RESP)) + || (rsp_type == RSI_BLE_SET_SCAN_RESPONSE_DATA) + || ((rsp_type >= RSI_BLE_LE_WHITE_LIST) && (rsp_type <= RSI_BLE_CBFC_DISCONN)) + || ((rsp_type >= RSI_BLE_LE_LTK_REQ_REPLY) && (rsp_type <= RSI_BLE_PER_RX_MODE)) + || (rsp_type == RSI_BLE_CMD_ATT_ERROR) || (rsp_type == RSI_BLE_CMD_SET_BLE_TX_POWER) + || (rsp_type == RSI_BLE_CMD_INDICATE_SYNC) || (rsp_type == RSI_BLE_CMD_AE) + || ((rsp_type >= RSI_BLE_REQ_PROFILES_ASYNC) && (rsp_type <= RSI_BLE_EXECUTE_LONGDESCWRITE_ASYNC)) + || (rsp_type == RSI_BLE_SET_SMP_PAIRING_CAPABILITY_DATA) || (rsp_type == RSI_BLE_REQ_SMP_PAIRING_FAILED) + || ((rsp_type >= RSI_BLE_CONN_PARAM_RESP_CMD) && (rsp_type <= RSI_BLE_CMD_MTU_EXCHANGE_RESP)) + || ((rsp_type >= RSI_BLE_EVENT_GATT_ERROR_RESPONSE) && (rsp_type <= RSI_BLE_EVENT_SCAN_REQ_RECVD)) + || (rsp_type == RSI_BLE_REQ_CONN_ENHANCE) || (rsp_type == RSI_BLE_EVENT_REMOTE_DEVICE_INFORMATION) + || ((rsp_type >= RSI_BLE_CMD_READ_TRANSMIT_POWER) && (rsp_type <= RSI_BLE_CMD_WRITE_RF_PATH_COMP))) { + + return_value = RSI_PROTO_BLE; + *bt_cb = rsi_driver_cb->ble_cb; + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + if ((rsp_type == RSI_PROP_PROTOCOL_CMD) || (rsp_type == RSI_PROP_PROTOCOL_CMD_PER)) { + return_value = RSI_PROTO_PROP_PROTOCOL; + *bt_cb = rsi_driver_cb->prop_protocol_cb; + } +#endif + /*if (return_value != RSI_PROTO_BT_COMMON) + { + local_prototype = return_value; + local_cb = *bt_cb; + }*/ + + return return_value; +} +/** @addtogroup DRIVER14 +* @{ +*/ + +/** + * @brief Calculate semaphore wait time for a protocol (BT COMMON / BT classic / BLE ) + * using the packet type + * @param[in] cmd_type - Command Type + * @param[in] protocol_type - Protocol type , whether it is BT Common/BT Classic/BLE + * @return 0 - Success \n + * Non-Zero Value - Failure + * + * + */ + +uint32_t rsi_bt_get_timeout(uint16_t cmd_type, uint16_t protocol_type) +{ + + SL_PRINTF(SL_RSI_BT_GET_TIMEOUT_TRIGGER, + BLUETOOTH, + LOG_INFO, + "COMMAND_TYPE: %2x, PROTOCOL_TYPE: %2x", + cmd_type, + protocol_type); + uint32_t return_value = 0; // 0 means RSI_WAIT_FOREVER + + switch (protocol_type) { + case RSI_PROTO_BT_COMMON: { + return_value = RSI_BT_COMMON_CMD_RESP_WAIT_TIME; + } break; + + case RSI_PROTO_BT_CLASSIC: { + if (((cmd_type >= RSI_BT_REQ_A2DP_CONNECT) && (cmd_type <= RSI_BT_REQ_A2DP_DISCONNECT)) + || ((cmd_type >= RSI_BT_REQ_A2DP_CLOSE) && (cmd_type <= RSI_BT_REQ_A2DP_SUSPEND)) + || ((cmd_type >= RSI_BT_REQ_A2DP_GET_CONFIG) && (cmd_type <= RSI_BT_REQ_A2DP_SET_CONFIG))) { + return_value = RSI_BT_A2DP_CMD_RESP_WAIT_TIME; + } else if (((cmd_type >= RSI_BT_REQ_A2DP_PCM_MP3_DATA) && (cmd_type <= RSI_BT_REQ_A2DP_SBC_AAC_DATA)) + || ((cmd_type == RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1))) { + return_value = RSI_BT_A2DP_DATA_CMD_RESP_WAIT_TIME; + } else if (((cmd_type >= RSI_BT_REQ_AVRCP_CONNECT) && (cmd_type <= RSI_BT_REQ_AVRCP_VOL_DOWN)) + || ((cmd_type >= RSI_BT_REQ_AVRCP_GET_CAPABILITES) && (cmd_type <= RSI_BT_REQ_AVRCP_CMD_REJECT)) + || ((cmd_type >= RSI_BT_REQ_AVRCP_SET_ABS_VOL) && (cmd_type <= RSI_BT_REQ_AVRCP_SET_ABS_VOL_RESP))) { + return_value = RSI_BT_AVRCP_CMD_RESP_WAIT_TIME; + } else if (((cmd_type >= RSI_BT_REQ_HFP_CONNECT) && (cmd_type <= RSI_BT_REQ_HFP_AUDIOTRANSFER)) + || ((cmd_type == RSI_BT_REQ_HFP_AUDIODATA))) { + return_value = RSI_BT_HFP_CMD_RESP_WAIT_TIME; + } else if ((cmd_type >= RSI_BT_REQ_PBAP_CONNECT) && (cmd_type <= RSI_BT_REQ_PBAP_CONTACTS)) { + return_value = RSI_BT_PBAP_CMD_RESP_WAIT_TIME; + } else if ((cmd_type >= RSI_BT_REQ_HID_CONNECT) && (cmd_type <= RSI_BT_REQ_HID_SDP_ATT_INIT)) { + return_value = RSI_BT_HID_CMD_RESP_WAIT_TIME; + } else if ((cmd_type >= RSI_BT_REQ_SPP_CONNECT) && (cmd_type <= RSI_BT_REQ_SPP_TRANSFER)) { + return_value = RSI_BT_SPP_CMD_RESP_WAIT_TIME; + } else { + return_value = RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME; //RSI_WAIT_FOREVER; + } + } break; + + case RSI_PROTO_BLE: { + if (((cmd_type >= RSI_BLE_REQ_ADV) && (cmd_type <= RSI_BLE_SMP_PASSKEY)) + || ((cmd_type >= RSI_BLE_SET_ADVERTISE_DATA) && (cmd_type <= RSI_BLE_PER_RX_MODE)) + || ((cmd_type == RSI_BLE_CONN_PARAM_RESP_CMD)) + || ((cmd_type == RSI_BLE_MTU_EXCHANGE_REQUEST) || ((cmd_type == RSI_BLE_CMD_MTU_EXCHANGE_RESP))) +#ifdef RSI_PROP_PROTOCOL_ENABLE + || ((cmd_type == RSI_PROP_PROTOCOL_CMD)) +#endif + ) { + return_value = RSI_BLE_GAP_CMD_RESP_WAIT_TIME; + } else if (((cmd_type >= RSI_BLE_REQ_PROFILES) && (cmd_type <= RSI_BLE_CMD_INDICATE)) + || ((cmd_type >= RSI_BLE_CMD_ATT_ERROR) && (cmd_type <= RSI_BLE_SET_SMP_PAIRING_CAPABILITY_DATA)) + || ((cmd_type == RSI_BLE_CMD_INDICATE_CONFIRMATION)) || (cmd_type == RSI_BLE_CMD_INDICATE_SYNC)) { + return_value = RSI_BLE_GATT_CMD_RESP_WAIT_TIME; + } else { + return_value = RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME; //RSI_WAIT_FOREVER; + } + } break; + + default: { + return_value = RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME; + } break; + } + return return_value; +} + +/** + * @brief Handle BT data transfer completion. + * @param[in] pkt - Pointer to packet + * @return void + */ + +void rsi_bt_common_tx_done(rsi_pkt_t *pkt) +{ + + SL_PRINTF(SL_RSI_BT_COMMON_TX_DONE, BLUETOOTH, LOG_INFO); + uint8_t *host_desc = NULL; + uint8_t protocol_type = 0; + uint16_t rsp_type = 0; + rsi_bt_cb_t *bt_cb = NULL; + + // Get Host Descriptor + host_desc = pkt->desc; + + // Get Command response Type + rsp_type = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_TYPE_OFFSET); + + // Get the protocol Type + protocol_type = rsi_bt_get_proto_type(rsp_type, &bt_cb); + + if (protocol_type == 0xFF) { + return; + } + + rsi_pkt_free(&bt_cb->bt_tx_pool, pkt); + + // If the command is not a synchronous/blocking one + if (!bt_cb->sync_rsp) { + // Set bt_common status as success + rsi_bt_set_status(bt_cb, RSI_SUCCESS); + + rsi_bt_clear_wait_bitmap(protocol_type, BT_SEM); + // Post the semaphore which is waiting on driver_send API + rsi_semaphore_post(&bt_cb->bt_sem); + } +} +/** @} */ +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * + * @brief Return BT status + * @param[in] bt_cb - BT control block + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +uint32_t rsi_get_bt_state(rsi_bt_cb_t *bt_cb) +{ + SL_PRINTF(SL_RSI_BT_STATE_TRIGGER, BLUETOOTH, LOG_INFO); + return bt_cb->state; +} + +/*==============================================*/ +/** + * @brief Set BT status + * @param[in] bt_cb - BT control block + * @param[in] status - Status value to be set + * @param[out] None + * @return void + */ + +void rsi_bt_set_status(rsi_bt_cb_t *bt_cb, int32_t status) +{ + + SL_PRINTF(SL_RSI_BT_SET_STATUS_TRIGGER, BLUETOOTH, LOG_INFO, "STATUS: %4x", status); + bt_cb->status = status; +} + +/*==============================================*/ +/** + * @brief Get bt status + * @param[in] bt_cb - BT control block + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +uint32_t rsi_bt_get_status(rsi_bt_cb_t *bt_cb) +{ + return bt_cb->status; +} + +#ifdef RSI_BLE_ENABLE +/** + * @brief Update local Device buffer availability per slave in global ble cb structure + * @param[in] void + * @return void + * + */ + +void rsi_ble_update_le_dev_buf(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_dev_buf_ind) +{ + + SL_PRINTF(SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER, BLUETOOTH, LOG_INFO); + uint8_t inx = 0; + rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; + + for (inx = 0; inx < (RSI_BLE_MAX_NBR_SLAVES + RSI_BLE_MAX_NBR_MASTERS); inx++) { + if (!memcmp(rsi_ble_event_le_dev_buf_ind->remote_dev_bd_addr, + le_cb->remote_ble_info[inx].remote_dev_bd_addr, + RSI_DEV_ADDR_LEN)) { + rsi_mutex_lock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + le_cb->remote_ble_info[inx].avail_buf_cnt += rsi_ble_event_le_dev_buf_ind->avail_buf_cnt; + rsi_mutex_unlock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + break; + } + } +} + +/** + * @brief Update Remote BLE Device info in global ble cb structure + * @param[in] void + * @return void + * + * + */ + +void rsi_add_remote_ble_dev_info(rsi_ble_event_enhance_conn_status_t *remote_dev_info) +{ + + SL_PRINTF(SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER, BLUETOOTH, LOG_INFO); + uint8_t inx = 0; + rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; + + for (inx = 0; inx < (RSI_BLE_MAX_NBR_SLAVES + RSI_BLE_MAX_NBR_MASTERS); inx++) { + if (!le_cb->remote_ble_info[inx].used) { + memcpy(le_cb->remote_ble_info[inx].remote_dev_bd_addr, remote_dev_info->dev_addr, RSI_DEV_ADDR_LEN); + le_cb->remote_ble_info[inx].used = 1; + /* On connection default values are set as follows*/ + le_cb->remote_ble_info[inx].max_buf_cnt = 1; + le_cb->remote_ble_info[inx].avail_buf_cnt = 1; + le_cb->remote_ble_info[inx].mode = 1; + rsi_mutex_create(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + break; + } + } +} + +/** + * @brief Remove Remote BLE Device info in global ble cb structure + * @param[in] remote_dev_info - Remote device information + * @return void + * + * + */ + +void rsi_remove_remote_ble_dev_info(rsi_ble_event_disconnect_t *remote_dev_info) +{ + + SL_PRINTF(SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER, BLUETOOTH, LOG_INFO); + uint8_t inx = 0; + rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; + + for (inx = 0; inx < (RSI_BLE_MAX_NBR_SLAVES + RSI_BLE_MAX_NBR_MASTERS); inx++) { + if (!memcmp(remote_dev_info->dev_addr, le_cb->remote_ble_info[inx].remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { + memset(le_cb->remote_ble_info[inx].remote_dev_bd_addr, 0, RSI_DEV_ADDR_LEN); + le_cb->remote_ble_info[inx].used = 0; + le_cb->remote_ble_info[inx].avail_buf_cnt = 0; + le_cb->remote_ble_info[inx].cmd_in_use = 0; + le_cb->remote_ble_info[inx].max_buf_cnt = 0; + le_cb->remote_ble_info[inx].expected_resp = 0; + le_cb->remote_ble_info[inx].mode = 0; + le_cb->remote_ble_info[inx].remote_dev_addr_type = 0; + le_cb->remote_ble_info[inx].max_buf_len = 0; + rsi_mutex_destroy(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + break; + } + } +} +#endif + +/** + * @brief Process BT RX packets + * @param[in ] bt_cb - BT control block + * @param[in] pkt - Pointer to received RX packet + * @param[in] bt_aync_callback_handler + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_driver_process_bt_resp( + rsi_bt_cb_t *bt_cb, + rsi_pkt_t *pkt, + void (*rsi_bt_async_callback_handler)(rsi_bt_cb_t *cb, uint16_t type, uint8_t *data, uint16_t length), + uint16_t protocol_type) +{ + + SL_PRINTF(SL_RSI_DRIVER_PROCESS_BT_RESPONSE_TRIGGER, BLUETOOTH, LOG_INFO, "PROTOCOL_TYPE: %2x", protocol_type); + uint16_t rsp_type = 0; + int16_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + uint8_t *payload; + uint16_t payload_length; + uint16_t expected_resp = 0; + + // Get Host Descriptor + host_desc = pkt->desc; + + // Get Command response Type + rsp_type = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_TYPE_OFFSET); + + // Get Payload start pointer + payload = pkt->data; + + // Get Payload length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // Get Status + status = rsi_bytes2R_to_uint16(host_desc + RSI_BT_STATUS_OFFSET); + + // Check bt_cb for any task is waiting for response + if (bt_cb->expected_response_type == rsp_type) { + // Update the status in bt_cb + rsi_bt_set_status(bt_cb, status); + if (bt_cb->expected_response_type == RSI_BT_EVENT_CARD_READY) { + bt_cb->state = RSI_BT_STATE_OPERMODE_DONE; + } + if (status == RSI_SUCCESS) { //To not allow BT SetAddress after these states are triggered + if (bt_cb->expected_response_type == RSI_BLE_REQ_ADV || bt_cb->expected_response_type == RSI_BLE_REQ_SCAN + || bt_cb->expected_response_type == RSI_BLE_REQ_CONN) { + //bt_cb->state = RSI_BT_STATE_NONE; + rsi_driver_cb->bt_common_cb->state = RSI_BT_STATE_NONE; + } + } + expected_resp = bt_cb->expected_response_type; + // Clear expected response type + bt_cb->expected_response_type = 0; + + // Copy the expected response to response structure/buffer, if any, passed in API + if (bt_cb->expected_response_buffer != NULL) { + // If (payload_length <= RSI_BLE_GET_MAX_PAYLOAD_LENGTH(expected_response_type)) + memcpy(bt_cb->expected_response_buffer, payload, payload_length); + + // Save expected_response pointer to a local variable, since it is being cleared below + payload = bt_cb->expected_response_buffer; + + // Clear the expected response pointer + bt_cb->expected_response_buffer = NULL; + } + + // Check if it is sync response + if (bt_cb->sync_rsp) { + + /* handling this for the new buf configuration */ + if (expected_resp == RSI_BLE_RSP_SET_WWO_RESP_NOTIFY_BUF_INFO) { + if (status == RSI_SUCCESS) { + rsi_ble_set_wo_resp_notify_buf_info_t *buf_info = (rsi_ble_set_wo_resp_notify_buf_info_t *)payload; + + bt_cb->remote_ble_info[bt_cb->remote_ble_index].mode = buf_info->buf_mode; + + if (buf_info->buf_mode == 0) /* small buf cnt */ + { + bt_cb->remote_ble_info[bt_cb->remote_ble_index].max_buf_cnt = (buf_info->buf_count * 10); + bt_cb->remote_ble_info[bt_cb->remote_ble_index].avail_buf_cnt = (buf_info->buf_count * 10); + } else /* big buf cnt */ + { + bt_cb->remote_ble_info[bt_cb->remote_ble_index].max_buf_cnt = buf_info->buf_count; + bt_cb->remote_ble_info[bt_cb->remote_ble_index].avail_buf_cnt = buf_info->buf_count; + } + bt_cb->remote_ble_index = 0; /* assigning value to 0 after successful response */ + } + } + rsi_bt_clear_wait_bitmap(protocol_type, BT_SEM); + // Signal the bt semaphore + rsi_semaphore_post(&bt_cb->bt_sem); + } else { + if (rsi_bt_async_callback_handler != NULL) { + + bt_cb->async_status = status; + // Call callbacks handler + rsi_bt_async_callback_handler(bt_cb, rsp_type, payload, payload_length); + } + } + } else { + if (rsi_bt_async_callback_handler != NULL) { + bt_cb->async_status = status; + // Call callbacks handler + rsi_bt_async_callback_handler(bt_cb, rsp_type, payload, payload_length); + } + } + + return status; +} + +/** + * @brief Process BT RX packets + * @param[in] pkt - Pointer to received RX packet + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +uint16_t rsi_driver_process_bt_resp_handler(rsi_pkt_t *pkt) +{ + + SL_PRINTF(SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER, BLUETOOTH, LOG_INFO); + uint8_t *host_desc = NULL; + uint8_t protocol_type = 0; + uint16_t rsp_type = 0; + // uint16_t rsp_len = 0; + int16_t status = RSI_SUCCESS; + rsi_bt_cb_t *bt_cb = NULL; + rsi_ble_event_disconnect_t *temp_data = NULL; + + // Get Host Descriptor + host_desc = pkt->desc; + + // Get Command response Type + rsp_type = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_TYPE_OFFSET); + //rsp_len = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_LEN_OFFSET) & RSI_BT_RSP_LEN_MASK; + + if (/*((rsi_driver_cb->common_cb->ps_coex_mode & RSI_BT_BLE_MODE_BITS) == RSI_BT_DUAL_MODE) && */ + (rsp_type == RSI_BLE_EVENT_DISCONNECT)) { + + // rsi_driver_cb->bt_common_cb->dev_type = ((rsi_ble_event_disconnect_t *)pkt->data)->dev_type; + temp_data = (rsi_ble_event_disconnect_t *)pkt->data; + rsi_driver_cb->bt_common_cb->dev_type = + ((temp_data->dev_type) & LOWERNIBBLE); //Getting the dev_type from lower nibble + } + + // Get the protocol Type + protocol_type = rsi_bt_get_proto_type(rsp_type, &bt_cb); + + SL_PRINTF(SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER, BLUETOOTH, LOG_INFO, "PROTOCOL_TYPE: %1x", protocol_type); + if (protocol_type == 0xFF) { + return 0; + } + // Call the corresponding protocol process rsp handler + if (protocol_type == RSI_PROTO_BT_COMMON) { + // Call BT common process rsp handler + status = rsi_driver_process_bt_resp(bt_cb, pkt, NULL, protocol_type); + } +#ifdef RSI_BT_ENABLE + else if (protocol_type == RSI_PROTO_BT_CLASSIC) { + // Call BT classic process response handler + status = rsi_driver_process_bt_resp(bt_cb, pkt, rsi_bt_callbacks_handler, protocol_type); + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (protocol_type == RSI_PROTO_PROP_PROTOCOL) { + // Call PROP_PROTOCOL process response handler + status = rsi_driver_process_prop_protocol_resp(bt_cb, pkt, rsi_prop_protocol_callbacks_handler); + } +#endif +#ifdef RSI_BLE_ENABLE + else { + // Call BLE process response handler + status = rsi_driver_process_bt_resp(bt_cb, pkt, rsi_ble_callbacks_handler, protocol_type); + } +#endif + return status; +} + +/** + * @brief Initialize bt control block structure + * @param[in] bt_cb - Pointer to bt_cb structure + * @param[in] protocol_type - Protocol type + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int8_t rsi_bt_cb_init(rsi_bt_cb_t *bt_cb, uint16_t protocol_type) +{ + + SL_PRINTF(SL_RSI_BT_CB_INIT_TRIGGER, BLUETOOTH, LOG_INFO, "PROTOCOL_TYPE: %2x", protocol_type); + + int8_t retval = RSI_ERR_NONE; + + // validate input parameter + if (bt_cb == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + + // Initialize bt control block with default values + bt_cb->state = 0; + bt_cb->status = 0; + + // Create bt mutex + bt_cb->expected_response_type = 0; + bt_cb->expected_response_buffer = NULL; + + // Create common/bt/ble sync semaphore + retval = rsi_semaphore_create(&bt_cb->bt_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + + // Create common/bt/ble command semaphore + retval = rsi_semaphore_create(&bt_cb->bt_cmd_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + rsi_bt_clear_wait_bitmap(protocol_type, BT_CMD_SEM); + rsi_semaphore_post(&bt_cb->bt_cmd_sem); + bt_cb->app_buffer = 0; + + return retval; +} + +/** + * @brief Initialize bt global control block + * @param[in] driver_cb - Pointer to bt_cb structure + * @param[in] buffer - Buffer + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ +uint16_t rsi_bt_global_cb_init(rsi_driver_cb_t *driver_cb, uint8_t *buffer) +{ + + SL_PRINTF(SL_RSI_BT_GLOBAL_CB_INIT_TRIGGER, BLUETOOTH, LOG_INFO); + rsi_bt_global_cb_t *bt_global_cb = driver_cb->bt_global_cb; + uint16_t total_size = 0; + +#ifdef RSI_BLE_ENABLE + bt_global_cb->ble_specific_cb = (rsi_ble_cb_t *)buffer; + + driver_cb->ble_cb->bt_global_cb = bt_global_cb; + total_size += sizeof(rsi_ble_cb_t); +#endif + +#ifdef RSI_BT_ENABLE + bt_global_cb->bt_specific_cb = (rsi_bt_classic_cb_t *)(buffer + total_size); + + driver_cb->bt_classic_cb->bt_global_cb = bt_global_cb; + total_size += sizeof(rsi_bt_classic_cb_t); +#endif + +#ifdef RSI_PROP_PROTOCOL_ENABLE + bt_global_cb->prop_protocol_specific_cb = (rsi_prop_protocol_cb_t *)(buffer + total_size); + + driver_cb->prop_protocol_cb->bt_global_cb = bt_global_cb; + total_size += sizeof(rsi_prop_protocol_cb_t); +#endif + + return total_size; +} +/** @} */ +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Wait for BT card ready + * @param[in] void + * @return void + * */ + +void rsi_bt_common_init(void) +{ + SL_PRINTF(SL_RSI_BT_COMMON_INIT_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt_common_cb structure pointer + rsi_bt_cb_t *bt_common_cb = rsi_driver_cb->bt_common_cb; + + rsi_bt_set_wait_bitmap(RSI_PROTO_BT_COMMON, BT_SEM); + // Wait on BLE semaphore + rsi_semaphore_wait(&bt_common_cb->bt_sem, RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME); +} + +/*! \cond RS9116 */ +/** @} */ +/** @addtogroup BT-CLASSIC6 +* @{ +*/ +#ifdef RSI_BT_ENABLE +/** + * @brief Register the GAP callbacks. + * @param[in] bt_on_role_change_status_event - Connection status callback + * @param[in] bt_on_conn_status_event - Connection status callback + * @param[in] bt_on_unbond_status - Connection status callback + * @param[in] bt_on_disconnect_event - Disconnection status callback + * @param[in] bt_on_scan_resp_event - Scan report callback + * @param[in] bt_on_remote_name_resp_event - Remote name report callback + * @param[in] bt_on_passkey_display_event - Passkey display report callback + * @param[in] bt_on_remote_name_request_cancel_event - Remote name request cancel status callback + * @param[in] bt_on_confirm_request_event - Authentication status callback + * @param[in] bt_on_pincode_request_event - Pincode request status callback + * @param[in] bt_on_passkey_request_event - Passkey request status callback + * @param[in] bt_on_inquiry_complete_event - Inquiry report callback + * @param[in] bt_on_auth_complete_event - Authentication status callback + * @param[in] bt_on_linkkey_request_event - Linkkey request report callback + * @param[in] bt_on_ssp_complete_event - SSP status callback + * @param[in] bt_on_linkkey_save_event - Linkkey save status callback + * @param[in] bt_on_get_services_event - Get services report callback + * @param[in] bt_on_search_service_event - Search service status callback + * @return void + * + */ +void rsi_bt_gap_register_callbacks(rsi_bt_on_role_change_t bt_on_role_change_status_event, + rsi_bt_on_connect_t bt_on_conn_status_event, + rsi_bt_on_unbond_t bt_on_unbond_status, + rsi_bt_on_disconnect_t bt_on_disconnect_event, + rsi_bt_on_scan_resp_t bt_on_scan_resp_event, + rsi_bt_on_remote_name_resp_t bt_on_remote_name_resp_event, + rsi_bt_on_passkey_display_t bt_on_passkey_display_event, + rsi_bt_on_remote_name_request_cancel_t bt_on_remote_name_request_cancel_event, + rsi_bt_on_confirm_request_t bt_on_confirm_request_event, + rsi_bt_on_pincode_request_t bt_on_pincode_request_event, + rsi_bt_on_passkey_request_t bt_on_passkey_request_event, + rsi_bt_on_inquiry_complete_t bt_on_inquiry_complete_event, + rsi_bt_on_auth_complete_t bt_on_auth_complete_event, + rsi_bt_on_linkkey_request_t bt_on_linkkey_request_event, + rsi_bt_on_ssp_complete_t bt_on_ssp_complete_event, + rsi_bt_on_linkkey_save_t bt_on_linkkey_save_event, + rsi_bt_on_get_services_t bt_on_get_services_event, + rsi_bt_on_search_service_t bt_on_search_service_event, + rsi_bt_on_mode_chnage_t bt_on_mode_change_event, + rsi_bt_on_sniff_subrating_t bt_on_sniff_subrating_event, + rsi_bt_on_connection_initiated_t bt_on_connection_initiated) +{ + + SL_PRINTF(SL_RSI_BT_GAP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_role_change_status_event = bt_on_role_change_status_event; + bt_specific_cb->bt_on_conn_status_event = bt_on_conn_status_event; + bt_specific_cb->bt_on_unbond_status = bt_on_unbond_status; + bt_specific_cb->bt_on_disconnect_event = bt_on_disconnect_event; + bt_specific_cb->bt_on_scan_resp_event = bt_on_scan_resp_event; // inq resp + bt_specific_cb->bt_on_remote_name_resp_event = bt_on_remote_name_resp_event; + bt_specific_cb->bt_on_passkey_display_event = bt_on_passkey_display_event; + bt_specific_cb->bt_on_remote_name_request_cancel_event = bt_on_remote_name_request_cancel_event; + bt_specific_cb->bt_on_confirm_request_event = bt_on_confirm_request_event; + bt_specific_cb->bt_on_pincode_request_event = bt_on_pincode_request_event; + bt_specific_cb->bt_on_passkey_request_event = bt_on_passkey_request_event; + bt_specific_cb->bt_on_inquiry_complete_event = bt_on_inquiry_complete_event; + bt_specific_cb->bt_on_auth_complete_event = bt_on_auth_complete_event; + bt_specific_cb->bt_on_linkkey_request_event = bt_on_linkkey_request_event; + bt_specific_cb->bt_on_ssp_complete_event = bt_on_ssp_complete_event; + bt_specific_cb->bt_on_linkkey_save_event = bt_on_linkkey_save_event; + bt_specific_cb->bt_on_get_services_event = bt_on_get_services_event; + bt_specific_cb->bt_on_search_service_event = bt_on_search_service_event; + bt_specific_cb->bt_on_mode_change_event = bt_on_mode_change_event; + bt_specific_cb->bt_on_sniff_subrating_event = bt_on_sniff_subrating_event; + bt_specific_cb->bt_on_connection_initiated = bt_on_connection_initiated; +} +/** @} */ +/*! \endcond */ +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Register the GAP extended callbacks + * @param[in] bt_on_gatt_connection_event - GATT Connection status callback + * @param[in] bt_on_gatt_disconnection_event - GATT Disconnection status callback + * @return void + * + */ + +void rsi_bt_gatt_extended_register_callbacks(rsi_bt_on_gatt_connection_t bt_on_gatt_connection_event, + rsi_bt_on_gatt_disconnection_t bt_on_gatt_disconnection_event) +{ + + SL_PRINTF(SL_RSI_BT_GATT_EXTENDED_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_gatt_connection_event = bt_on_gatt_connection_event; + bt_specific_cb->bt_on_gatt_disconnection_event = bt_on_gatt_disconnection_event; +} +/** @} */ +/*! \cond RS9116 */ +/** @addtogroup BT-CLASSIC6 +* @{ +*/ +/** + * @brief Register the AVDTP Event callbacks + * @param[in] bt_on_avdtp_stats_event - AVDP stats callback + * @return void + * + * + */ + +void rsi_bt_avdtp_events_register_callbacks(rsi_bt_on_avdtp_stats_t bt_on_avdtp_stats_event) +{ + + SL_PRINTF(SL_RSI_BT_AVDTP_EVENTS_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + bt_specific_cb->bt_on_avdtp_stats_event = bt_on_avdtp_stats_event; +} + +/** + * @brief Register the HCI callbacks. + * @param[in] bt_pkt_change_stats_event - This a callback function and will be called when ever packet change event received from the module. + * @return void + * + */ + +void rsi_bt_pkt_change_events_register_callbacks(rsi_bt_pkt_change_stats_t bt_pkt_change_stats_event) +{ + + SL_PRINTF(SL_RSI_BT_PKT_CHANGE_EVENTS_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + bt_specific_cb->bt_pkt_change_stats_event = bt_pkt_change_stats_event; +} +/** @} */ +/*! \endcond */ +/** + * @brief Register the chip memory stats callbacks. + * @note This API is not supported in the current release. + * @param[in] bt_on_chip_memory_stats_event - Memory utilization Event callback + * @return void + * + * + */ + +void rsi_bt_on_chip_memory_status_callbacks_register( + rsi_bt_on_chip_memory_stats_handler_t bt_on_chip_memory_stats_event) +{ + + SL_PRINTF(SL_RSI_BT_CHIP_MEMORY_STATUS_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + bt_specific_cb->bt_on_chip_memory_stats_event = bt_on_chip_memory_stats_event; +} +/*! \cond RS9116 */ +/** @addtogroup BT-CLASSIC6 +* @{ +*/ + +/** + * @brief Register events stats callbacks. + * @param[in] bt_on_ar_stats_event - Status Event callback + * @return void + * + * + */ +void rsi_bt_ar_events_register_callbacks(rsi_bt_on_ar_stats_t bt_on_ar_stats_event) +{ + SL_PRINTF(SL_RSI_BT_AR_EVENTS_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + bt_specific_cb->bt_on_ar_stats_event = bt_on_ar_stats_event; +} + +/** @} */ +/*! \endcond */ +/** + * @brief Register the l2cap callbacks + * @param[in] bt_on_l2cap_connect_event - HID connection status callback + * @param[in] bt_on_l2cap_rx_data_event - HID data transfer status callback + * @return void + * + * + */ +void rsi_bt_l2cap_register_callbacks(rsi_bt_on_l2cap_connect_t bt_on_l2cap_connect_event, + rsi_bt_on_l2cap_rx_data_t bt_on_l2cap_rx_data_event) +{ + SL_PRINTF(SL_RSI_BT_L2CAP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_l2cap_connect_event = bt_on_l2cap_connect_event; + bt_specific_cb->bt_on_l2cap_rx_data_event = bt_on_l2cap_rx_data_event; +} +/** + * @brief Register the hid event callbacks for received HID messages. + * @param[in] bt_on_hid_connect_event - HID connection status callback + * @param[in] bt_on_hid_rx_data_event - HID data transfer status callback + * @param[in] bt_on_hid_handshake_event - Callback on HID profile handshake msg is received. + * @param[in] bt_on_hid_control_event - Callback on HID profile control msg is received + * @param[in] bt_on_hid_get_report - Callback on HID profile get report msg is received + * @param[in] bt_on_hid_set_report - Callback on HID profile set report msg is received + * @param[in] bt_on_hid_get_proto - Callback on HID profile get protocol msg is received + * @param[in] bt_on_hid_set_proto - Callback on HID profile set protocol msg is received + * @return void + * + * + */ + +void rsi_bt_hid_register_callbacks(rsi_bt_on_hid_connect_t bt_on_hid_connect_event, + rsi_bt_on_hid_rx_data_t bt_on_hid_rx_data_event, + rsi_bt_on_hid_handshake_t bt_on_hid_handshake_event, + rsi_bt_on_hid_control_t bt_on_hid_control_event, + rsi_bt_on_hid_get_report_t bt_on_hid_get_report, + rsi_bt_on_hid_set_report_t bt_on_hid_set_report, + rsi_bt_on_hid_get_protocol_t bt_on_hid_get_proto, + rsi_bt_on_hid_set_protocol_t bt_on_hid_set_proto) +{ + + SL_PRINTF(SL_RSI_BT_HID_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_hid_connect_event = bt_on_hid_connect_event; + bt_specific_cb->bt_on_hid_rx_data_event = bt_on_hid_rx_data_event; + bt_specific_cb->bt_on_hid_handshake_event = bt_on_hid_handshake_event; + bt_specific_cb->bt_on_hid_control_event = bt_on_hid_control_event; + bt_specific_cb->bt_on_hid_get_report = bt_on_hid_get_report; + bt_specific_cb->bt_on_hid_set_report = bt_on_hid_set_report; + bt_specific_cb->bt_on_hid_get_proto = bt_on_hid_get_proto; + bt_specific_cb->bt_on_hid_set_proto = bt_on_hid_set_proto; +} +/*! \cond RS9116 */ +/** @addtogroup BT-CLASSIC6 +* @{ +*/ + +/** + * @brief Register the SPP callbacks + * @param[in] bt_on_spp_connect_event - spp connection status callback + * @param[in] bt_on_spp_disconnect_event - spp disconnection status callback + * @param[in] bt_on_spp_rx_data_event - spp data transfer status callback + * @return void + */ + +void rsi_bt_spp_register_callbacks(rsi_bt_on_spp_connect_t bt_on_spp_connect_event, + rsi_bt_on_spp_disconnect_t bt_on_spp_disconnect_event, + rsi_bt_on_spp_rx_data_t bt_on_spp_rx_data_event) +{ + + SL_PRINTF(SL_RSI_BT_SPP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_spp_connect_event = bt_on_spp_connect_event; + bt_specific_cb->bt_on_spp_disconnect_event = bt_on_spp_disconnect_event; + bt_specific_cb->bt_on_spp_rx_data_event = bt_on_spp_rx_data_event; +} + +/** + * @brief Register the A2DP callbacks + * @param[in] bt_on_a2dp_connect_event - A2DP connection status callback + * @param[in] bt_on_a2dp_disconnect_event - A2DP disconnection status callback + * @param[in] bt_on_a2dp_configure_event - A2DP configure status callback + * @param[in] bt_on_a2dp_open_event - A2DP open callback + * @param[in] bt_on_a2dp_start_event - A2DP start status callback + * @param[in] bt_on_a2dp_suspend_event - A2DP suspend status callback + * @param[in] bt_on_a2dp_abort_event - A2DP abort status callback + * @param[in] bt_on_a2dp_close_event - A2DP close status callback + * @param[in] bt_on_a2dp_encode_data_event - A2DP encode data stauts callback + * @param[in] bt_on_a2dp_pcm_data_event - A2DP pcm data status callback + * @param[in] bt_on_a2dp_data_req_event - A2DP data request status callback + * @param[in] bt_on_a2dp_reconfig_event - A2DP reconfig status callback + * @return void + * + * + */ + +void rsi_bt_a2dp_register_callbacks(rsi_bt_on_a2dp_connect_t bt_on_a2dp_connect_event, + rsi_bt_on_a2dp_disconnect_t bt_on_a2dp_disconnect_event, + rsi_bt_on_a2dp_configure_t bt_on_a2dp_configure_event, + rsi_bt_on_a2dp_open_t bt_on_a2dp_open_event, + rsi_bt_on_a2dp_start_t bt_on_a2dp_start_event, + rsi_bt_on_a2dp_suspend_t bt_on_a2dp_suspend_event, + rsi_bt_on_a2dp_abort_t bt_on_a2dp_abort_event, + rsi_bt_on_a2dp_close_t bt_on_a2dp_close_event, + rsi_bt_on_a2dp_encode_data_t bt_on_a2dp_encode_data_event, + rsi_bt_on_a2dp_pcm_data_t bt_on_a2dp_pcm_data_event, + rsi_bt_on_a2dp_data_req_t bt_on_a2dp_data_req_event, + rsi_bt_on_a2dp_reconfig_t bt_on_a2dp_reconfig_event) +{ + + SL_PRINTF(SL_RSI_BT_A2DP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_a2dp_connect_event = bt_on_a2dp_connect_event; + bt_specific_cb->bt_on_a2dp_disconnect_event = bt_on_a2dp_disconnect_event; + bt_specific_cb->bt_on_a2dp_configure_event = bt_on_a2dp_configure_event; + bt_specific_cb->bt_on_a2dp_open_event = bt_on_a2dp_open_event; + bt_specific_cb->bt_on_a2dp_start_event = bt_on_a2dp_start_event; + bt_specific_cb->bt_on_a2dp_suspend_event = bt_on_a2dp_suspend_event; + bt_specific_cb->bt_on_a2dp_abort_event = bt_on_a2dp_abort_event; + bt_specific_cb->bt_on_a2dp_close_event = bt_on_a2dp_close_event; + bt_specific_cb->bt_on_a2dp_encode_data_event = bt_on_a2dp_encode_data_event; + bt_specific_cb->bt_on_a2dp_pcm_data_event = bt_on_a2dp_pcm_data_event; + bt_specific_cb->bt_on_a2dp_data_req_event = bt_on_a2dp_data_req_event; + bt_specific_cb->bt_on_a2dp_reconfig_event = bt_on_a2dp_reconfig_event; +} + +/** + * @brief Register the AVRCP callbacks + * @param[in] bt_on_avrcp_connect_event - AVRCP connection status callback + * @param[in] bt_on_avrcp_disconnect_event - AVRCP disconnection status callback + * @param[in] bt_on_avrcp_play_event - AVRCP play status callback + * @param[in] bt_on_avrcp_pause_event - AVRCP pause status callback + * @param[in] bt_on_avrcp_stop_event - AVRCP stop status callback + * @param[in] bt_on_avrcp_next_event - AVRCP next status callback + * @param[in] bt_on_avrcp_previous_event - AVRCP previous status callback + * @param[in] bt_on_avrcp_vol_up_event - AVRCP vol up status callback + * @param[in] bt_on_avrcp_vol_down_event - AVRCP vol down status callback + * @param[in] bt_on_avrcp_get_elem_attr_resp_event - AVRCP elem attr resp status callback + * @return void + * + * + */ + +void rsi_bt_avrcp_register_callbacks(rsi_bt_on_avrcp_connect_t bt_on_avrcp_connect_event, + rsi_bt_on_avrcp_disconnect_t bt_on_avrcp_disconnect_event, + rsi_bt_on_avrcp_play_t bt_on_avrcp_play_event, + rsi_bt_on_avrcp_pause_t bt_on_avrcp_pause_event, + rsi_bt_on_avrcp_stop_t bt_on_avrcp_stop_event, + rsi_bt_on_avrcp_next_t bt_on_avrcp_next_event, + rsi_bt_on_avrcp_previous_t bt_on_avrcp_previous_event, + rsi_bt_on_avrcp_vol_up_t bt_on_avrcp_vol_up_event, + rsi_bt_on_avrcp_vol_down_t bt_on_avrcp_vol_down_event, + rsi_bt_on_avrcp_get_elem_attr_resp_t bt_on_avrcp_get_elem_attr_resp_event, + rsi_bt_on_avrcp_notify_event_t bt_on_avrcp_notify_event) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_avrcp_connect_event = bt_on_avrcp_connect_event; + bt_specific_cb->bt_on_avrcp_disconnect_event = bt_on_avrcp_disconnect_event; + bt_specific_cb->bt_on_avrcp_play_event = bt_on_avrcp_play_event; + bt_specific_cb->bt_on_avrcp_pause_event = bt_on_avrcp_pause_event; + bt_specific_cb->bt_on_avrcp_stop_event = bt_on_avrcp_stop_event; + bt_specific_cb->bt_on_avrcp_next_event = bt_on_avrcp_next_event; + bt_specific_cb->bt_on_avrcp_previous_event = bt_on_avrcp_previous_event; + bt_specific_cb->bt_on_avrcp_vol_up_event = bt_on_avrcp_vol_up_event; + bt_specific_cb->bt_on_avrcp_vol_down_event = bt_on_avrcp_vol_down_event; + bt_specific_cb->bt_on_avrcp_get_elem_attr_resp_event = bt_on_avrcp_get_elem_attr_resp_event; + bt_specific_cb->bt_on_avrcp_notify_event = bt_on_avrcp_notify_event; +} + +/** + * @brief Register the AVRCP target callbacks + * @param[in] bt_on_avrcp_gat_cap - AVRCP gat callback + * @param[in] bt_on_avrcp_get_app_att_list - AVRCP get application callbacks + * @param[in] bt_on_avrcp_get_app_att_vals_list - AVRCP get application list callback + * @param[in] bt_on_avrcp_get_app_cur_att_val - AVRCP get current value callback + * @param[in] bt_on_avrcp_set_app_cur_att_val -AVRCP set current value callback + * @param[in] bt_on_avrcp_get_app_att_text - AVRCP get text callback + * @param[in] bt_on_avrcp_get_app_att_vals_text - AVRCP get vals text callback + * @param[in] bt_on_avrcp_supp_char_sets - AVRCP support character set callback + * @param[in] bt_on_avrcp_batt_status - AVRCP status callback + * @param[in] bt_on_avrcp_get_song_atts - AVRCP get song + * @param[in] bt_on_avrcp_get_player_status - AVRCP get player status callback + * @param[in] bt_on_avrcp_reg_notifivation - AVRCP notification callback + * @param[in] bt_on_avrcp_set_abs_vol - AVRCP set abs volume callback + * @return void + * + * + */ +void rsi_bt_avrcp_target_register_callbacks( + rsi_bt_on_avrcp_get_cap_event_t bt_on_avrcp_gat_cap, + rsi_bt_on_avrcp_get_app_supp_atts_event_t bt_on_avrcp_get_app_att_list, + rsi_bt_on_avrcp_get_app_suup_att_vals_event_t bt_on_avrcp_get_app_att_vals_list, + rsi_bt_on_avrcp_get_app_cur_att_val_event_t bt_on_avrcp_get_app_cur_att_val, + rsi_bt_on_avrcp_set_app_cur_att_val_event_t bt_on_avrcp_set_app_cur_att_val, + rsi_bt_on_avrcp_get_app_att_text_event_t bt_on_avrcp_get_app_att_text, + rsi_bt_on_avrcp_get_app_att_vals_text_event_t bt_on_avrcp_get_app_att_vals_text, + rsi_bt_on_avrcp_supp_char_sets_event_t bt_on_avrcp_supp_char_sets, + rsi_bt_on_avrcp_batt_status_event_t bt_on_avrcp_batt_status, + rsi_bt_on_avrcp_get_song_atts_event_t bt_on_avrcp_get_song_atts, + rsi_bt_on_avrcp_get_play_status_event_t bt_on_avrcp_get_player_status, + rsi_bt_on_avrcp_reg_notify_event_t bt_on_avrcp_reg_notifivation, + rsi_bt_on_avrcp_set_abs_vol_event_t bt_on_avrcp_set_abs_vol, + rsi_bt_on_avrcp_set_addr_player_event_t bt_on_avrcp_set_addr_player, + rsi_bt_on_avrcp_get_folder_items_event_t bt_on_avrcp_get_folder_items, + rsi_bt_on_avrcp_get_tot_num_items_event_t bt_on_avrcp_get_tot_num_items) +{ + + SL_PRINTF(SL_RSI_BT_AVRCP_TARGET_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_avrcp_gat_cap = bt_on_avrcp_gat_cap; + bt_specific_cb->bt_on_avrcp_get_app_att_list = bt_on_avrcp_get_app_att_list; + bt_specific_cb->bt_on_avrcp_get_app_att_vals_list = bt_on_avrcp_get_app_att_vals_list; + bt_specific_cb->bt_on_avrcp_get_app_cur_att_val = bt_on_avrcp_get_app_cur_att_val; + bt_specific_cb->bt_on_avrcp_set_app_cur_att_val = bt_on_avrcp_set_app_cur_att_val; + bt_specific_cb->bt_on_avrcp_get_app_att_text = bt_on_avrcp_get_app_att_text; + bt_specific_cb->bt_on_avrcp_get_app_att_vals_text = bt_on_avrcp_get_app_att_vals_text; + bt_specific_cb->bt_on_avrcp_supp_char_sets = bt_on_avrcp_supp_char_sets; + bt_specific_cb->bt_on_avrcp_batt_status = bt_on_avrcp_batt_status; + bt_specific_cb->bt_on_avrcp_get_song_atts = bt_on_avrcp_get_song_atts; + bt_specific_cb->bt_on_avrcp_get_player_status = bt_on_avrcp_get_player_status; + bt_specific_cb->bt_on_avrcp_reg_notifivation = bt_on_avrcp_reg_notifivation; + bt_specific_cb->bt_on_avrcp_set_abs_vol = bt_on_avrcp_set_abs_vol; + bt_specific_cb->bt_on_avrcp_set_addr_player = bt_on_avrcp_set_addr_player; + bt_specific_cb->bt_on_avrcp_get_folder_items = bt_on_avrcp_get_folder_items; + bt_specific_cb->bt_on_avrcp_get_tot_num_items = bt_on_avrcp_get_tot_num_items; + + return; +} +/** @} */ +/*! \endcond */ +/** + * @brief Register the bt_hfp callbacks + * @param[in] bt_on_hfp_connect_event - HFP connect event +* @param[in] bt_on_hfp_disconnect_event - HFP disconnect event +* @param[in] bt_on_hfp_ring_event - HFP ring event +* @param[in] bt_on_hfp_callcallerid_event - HFP call callerid event +* @param[in] bt_on_hfp_audioconnected_event - HFP audio connected event +* @param[in] bt_on_hfp_audiodisconnected_event - HFP audio disconnected event +* @param[in] bt_on_hfp_dialcomplete_event - HFP dail complete event +* @param[in] bt_on_hfp_answercomplete_event - HFP answer complete event +* @param[in] bt_on_hfp_hangupcomplete_event - HFP hangup complete event +* @param[in] bt_on_hfp_senddtmfcomplete_event - HFP send dtmf complete event +* @param[in] bt_on_hfp_callwait_event - HFP call wait event +* @param[in] bt_on_hfp_callvoicerecogdeactivated_event - HFP call voice record deactivated event +* @param[in] bt_on_hfp_callvoicerecogactivated_event - HFP call voice record activated +* @param[in] bt_on_hfp_servicenotfound_event - HFP service not found +* @param[in] bt_on_hfp_callstatus_event - HFP call status event +* @param[in] bt_on_hfp_signalstrength_event - HFP signal strength event +* @param[in] bt_on_hfp_batterylevel_event - HFP battery level event +* @param[in] bt_on_hfp_phoneservice_event - HFP phone service event +* @param[in] bt_on_hfp_roamingstatus_event - HFP roaming status event +* @param[in] bt_on_hfp_callsetup_event - HFP call setup event +* @param[in] bt_on_hfp_callheld_event - HFP call held event + + * @return void + */ + +void rsi_bt_hfp_register_callbacks(rsi_bt_on_hfp_connect_t bt_on_hfp_connect_event, + rsi_bt_on_hfp_disconnect_t bt_on_hfp_disconnect_event, + rsi_bt_on_hfp_ring_t bt_on_hfp_ring_event, + rsi_bt_on_hfp_callcallerid_t bt_on_hfp_callcallerid_event, + rsi_bt_on_hfp_audioconnected_t bt_on_hfp_audioconnected_event, + rsi_bt_on_hfp_audiodisconnected_t bt_on_hfp_audiodisconnected_event, + rsi_bt_on_hfp_dialcomplete_t bt_on_hfp_dialcomplete_event, + rsi_bt_on_hfp_answercomplete_t bt_on_hfp_answercomplete_event, + rsi_bt_on_hfp_hangupcomplete_t bt_on_hfp_hangupcomplete_event, + rsi_bt_on_hfp_senddtmfcomplete_t bt_on_hfp_senddtmfcomplete_event, + rsi_bt_on_hfp_callwait_t bt_on_hfp_callwait_event, + rsi_bt_on_hfp_callvoicerecogdeactivated_t bt_on_hfp_callvoicerecogdeactivated_event, + rsi_bt_on_hfp_callvoicerecogactivated_t bt_on_hfp_callvoicerecogactivated_event, + rsi_bt_on_hfp_servicenotfound_t bt_on_hfp_servicenotfound_event, + rsi_bt_app_on_hfp_callstatus_t bt_on_hfp_callstatus_event, + rsi_bt_app_on_hfp_signalstrength_t bt_on_hfp_signalstrength_event, + rsi_bt_app_on_hfp_batterylevel_t bt_on_hfp_batterylevel_event, + rsi_bt_app_on_hfp_phoneservice_t bt_on_hfp_phoneservice_event, + rsi_bt_app_on_hfp_roamingstatus_t bt_on_hfp_roamingstatus_event, + rsi_bt_app_on_hfp_callsetup_t bt_on_hfp_callsetup_event, + rsi_bt_app_on_hfp_callheld_t bt_on_hfp_callheld_event, + rsi_bt_app_on_hfp_voice_data_t bt_on_hfp_voice_data_event, + rsi_bt_app_on_hfp_audio_codecselect_t bt_on_hfp_audio_codecselect_event) + +{ + + SL_PRINTF(SL_RSI_BT_HFP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_hfp_connect_event = bt_on_hfp_connect_event; + bt_specific_cb->bt_on_hfp_disconnect_event = bt_on_hfp_disconnect_event; + bt_specific_cb->bt_on_hfp_ring_event = bt_on_hfp_ring_event; + bt_specific_cb->bt_on_hfp_callcallerid_event = bt_on_hfp_callcallerid_event; + bt_specific_cb->bt_on_hfp_audioconnected_event = bt_on_hfp_audioconnected_event; + bt_specific_cb->bt_on_hfp_audiodisconnected_event = bt_on_hfp_audiodisconnected_event; + bt_specific_cb->bt_on_hfp_dialcomplete_event = bt_on_hfp_dialcomplete_event; + bt_specific_cb->bt_on_hfp_answercomplete_event = bt_on_hfp_answercomplete_event; + bt_specific_cb->bt_on_hfp_hangupcomplete_event = bt_on_hfp_hangupcomplete_event; + bt_specific_cb->bt_on_hfp_senddtmfcomplete_event = bt_on_hfp_senddtmfcomplete_event; + bt_specific_cb->bt_on_hfp_callwait_event = bt_on_hfp_callwait_event; + bt_specific_cb->bt_on_hfp_callvoicerecogdeactivated_event = bt_on_hfp_callvoicerecogdeactivated_event; + bt_specific_cb->bt_on_hfp_callvoicerecogactivated_event = bt_on_hfp_callvoicerecogactivated_event; + bt_specific_cb->bt_on_hfp_servicenotfound_event = bt_on_hfp_servicenotfound_event; + bt_specific_cb->bt_on_hfp_callstatus_event = bt_on_hfp_callstatus_event; + bt_specific_cb->bt_on_hfp_signalstrength_event = bt_on_hfp_signalstrength_event; + bt_specific_cb->bt_on_hfp_batterylevel_event = bt_on_hfp_batterylevel_event; + bt_specific_cb->bt_on_hfp_phoneservice_event = bt_on_hfp_phoneservice_event; + bt_specific_cb->bt_on_hfp_roamingstatus_event = bt_on_hfp_roamingstatus_event; + bt_specific_cb->bt_on_hfp_callsetup_event = bt_on_hfp_callsetup_event; + bt_specific_cb->bt_on_hfp_callheld_event = bt_on_hfp_callheld_event; + bt_specific_cb->bt_on_hfp_voice_data_event = bt_on_hfp_voice_data_event; + bt_specific_cb->bt_on_hfp_audio_codecselect_event = bt_on_hfp_audio_codecselect_event; +} + +/** + * @brief Register the PBAP callbacks + * @param[in] bt_on_pbap_connect_event - PBAP connection status callback + * @param[in] bt_on_pbap_disconnect_event - PBAP disconnection status callback + * @param[in] bt_on_pbap_data_event - PBAP data status callback + * @return void + * + */ +void rsi_bt_pbap_register_callbacks(rsi_bt_on_pbap_connect_t bt_on_pbap_connect_event, + rsi_bt_on_pbap_disconnect_t bt_on_pbap_disconnect_event, + rsi_bt_on_pbap_data_t bt_on_pbap_data_event) +{ + + SL_PRINTF(SL_RSI_BT_PBAP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_on_pbap_connect_event = bt_on_pbap_connect_event; + bt_specific_cb->bt_on_pbap_disconnect_event = bt_on_pbap_disconnect_event; + bt_specific_cb->bt_on_pbap_data_event = bt_on_pbap_data_event; +} + +/** + * @brief Register the IAP callbacks + * @param[in] bt_app_iap_conn - IAP connection status + * @param[in] bt_app_iap_disconn - IAP disconnection status + * @param[in] bt_app_iap_acc_auth_strt - IAP access authentication start status + * @param[in] bt_app_iap_acc_auth_fail - IAP access authentication failed status + * @param[in] bt_app_iap_acc_auth_complete - IAP access authentication complete status + * @param[in] bt_app_iap2_auth_start - IAP2 authentication start status + * @param[in] bt_app_iap2_auth_complete - IAP2 authentication complete status + * @param[in] bt_app_iap2_auth_fail - IAP2 authentication fail status + * @param[in] bt_app_iap2_identification_start - IAP2 identification start status + * @param[in] bt_app_iap2_identification_complete - IAP2 identification complete status + * @param[in] bt_app_iap2_identification_reject - IAP2 identification reject status + * @param[in] bt_app_on_iap2_data_rx - IAP2 data receive + * @param[in] bt_app_iap2_File_Transfer_state - IAP2 file transfer state + * @param[in] bt_app_iap2_File_Transfer_data - IAP2 file transfer data + * @return void + */ +void rsi_bt_iap_register_callbacks(rsi_bt_app_iap_conn_t bt_app_iap_conn, + rsi_bt_app_iap_disconn_t bt_app_iap_disconn, + rsi_bt_app_iap_acc_auth_strt_t bt_app_iap_acc_auth_strt, + rsi_bt_app_iap_acc_auth_fail_t bt_app_iap_acc_auth_fail, + rsi_bt_app_iap_acc_auth_complete_t bt_app_iap_acc_auth_complete, + rsi_bt_app_iap2_auth_start_t bt_app_iap2_auth_start, + rsi_bt_app_iap2_auth_complete_t bt_app_iap2_auth_complete, + rsi_bt_app_iap2_auth_fail_t bt_app_iap2_auth_fail, + rsi_bt_app_iap2_identification_start_t bt_app_iap2_identification_start, + rsi_bt_app_iap2_identification_complete_t bt_app_iap2_identification_complete, + rsi_bt_app_iap2_identification_reject_t bt_app_iap2_identification_reject, + rsi_bt_app_on_iap2_data_rx_t bt_app_on_iap2_data_rx, + rsi_bt_app_iap2_File_Tx_state_t bt_app_iap2_File_Transfer_state, + rsi_bt_app_iap2_File_Transfer_rx_data_t bt_app_iap2_File_Transfer_data) +{ + + SL_PRINTF(SL_RSI_BT_IAP_REGISTER_CALLBACKS_TRIGGER, BLUETOOTH, LOG_INFO); + // Get bt cb struct pointer + rsi_bt_classic_cb_t *bt_specific_cb = rsi_driver_cb->bt_classic_cb->bt_global_cb->bt_specific_cb; + + // Assign the call backs to the respective call back + bt_specific_cb->bt_app_iap_conn = bt_app_iap_conn; + bt_specific_cb->bt_app_iap_disconn = bt_app_iap_disconn; + bt_specific_cb->bt_app_iap_acc_auth_strt = bt_app_iap_acc_auth_strt; + bt_specific_cb->bt_app_iap_acc_auth_fail = bt_app_iap_acc_auth_fail; + bt_specific_cb->bt_app_iap_acc_auth_complete = bt_app_iap_acc_auth_complete; + bt_specific_cb->bt_app_iap2_auth_start = bt_app_iap2_auth_start; + bt_specific_cb->bt_app_iap2_auth_complete = bt_app_iap2_auth_complete; + bt_specific_cb->bt_app_iap2_auth_fail = bt_app_iap2_auth_fail; + bt_specific_cb->bt_app_iap2_identification_start = bt_app_iap2_identification_start; + bt_specific_cb->bt_app_iap2_identification_complete = bt_app_iap2_identification_complete; + bt_specific_cb->bt_app_iap2_identification_reject = bt_app_iap2_identification_reject; + bt_specific_cb->bt_app_on_iap2_data_rx = bt_app_on_iap2_data_rx; + bt_specific_cb->bt_app_iap2_File_Tx_state = bt_app_iap2_File_Transfer_state; + bt_specific_cb->bt_app_iap2_File_Transfer_rx_data = bt_app_iap2_File_Transfer_data; +} + +#endif +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Initailize the BT callbacks register + * @param[in] bt_classic_cb - BT BLE struct pointer + * @param[in] rsp_type - BT Packet type + * @param[in] payload - Payload + * @param[in] payload_length - payload length + * @return void + * + */ + +void rsi_bt_callbacks_handler(rsi_bt_cb_t *bt_classic_cb, uint16_t rsp_type, uint8_t *payload, uint16_t payload_length) +{ + + SL_PRINTF(SL_RSI_BT_CALLBACKS_HANDLER_TRIGGER, BLUETOOTH, LOG_INFO, "RESPONSE_TYPE: %2x", rsp_type); + // Get ble cb struct pointer + UNUSED_PARAMETER(payload_length); + rsi_bt_classic_cb_t *bt_specific_cb = bt_classic_cb->bt_global_cb->bt_specific_cb; + + uint16_t status = 0; + uint16_t sync_status = 0; + + // updating the response status; + status = bt_classic_cb->async_status; + + sync_status = rsi_bt_get_status(bt_classic_cb); + + SL_PRINTF(SL_RSI_BT_CALLBACKS_HANDLER_STATUS, BLUETOOTH, LOG_INFO, "STATUS: %2x", status); + + // Check each cmd_type like decode_resp_handler and call the respective callback + switch (rsp_type) { + case RSI_BT_RSP_QUERY_SERVICES: { + if (bt_specific_cb->bt_on_get_services_event != NULL) { + bt_specific_cb->bt_on_get_services_event(sync_status, (void *)payload); + } + } break; + case RSI_BT_RSP_SEARCH_SERVICE: { + if (bt_specific_cb->bt_on_search_service_event != NULL) { + bt_specific_cb->bt_on_search_service_event(sync_status, (uint8_t *)payload); + } + } break; + + case RSI_BT_EVT_ROLE_CHANGE_STATUS: { + if (bt_specific_cb->bt_on_role_change_status_event != NULL) { + bt_specific_cb->bt_on_role_change_status_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_UNBOND_STATUS: { + if (bt_specific_cb->bt_on_unbond_status != NULL) { + bt_specific_cb->bt_on_unbond_status(status, (void *)payload); + } + } break; + case RSI_BT_EVT_BOND_RESPONSE: { + if (bt_specific_cb->bt_on_conn_status_event != NULL) { + bt_specific_cb->bt_on_conn_status_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_INQUIRY_RESPONSE: { + if (bt_specific_cb->bt_on_scan_resp_event != NULL) { + bt_specific_cb->bt_on_scan_resp_event(status, (void *)payload); + } + } break; + case RSI_BT_EVENT_CONNECTION_INITIATED: { + if (bt_specific_cb->bt_on_connection_initiated != NULL) { + bt_specific_cb->bt_on_connection_initiated(status, (void *)payload); + } + } break; + case RSI_BT_EVT_REMOTE_DEVICE_NAME: { + if (bt_specific_cb->bt_on_remote_name_resp_event != NULL) { + bt_specific_cb->bt_on_remote_name_resp_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_REMOTE_NAME_REQUEST_CANCEL: { + if (bt_specific_cb->bt_on_remote_name_request_cancel_event != NULL) { + bt_specific_cb->bt_on_remote_name_request_cancel_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_DISCONNECTED: //Physical Level Disconnection (GAP Disconnected) + { + if (bt_specific_cb->bt_on_disconnect_event != NULL) { + /* GAR-7701: Removing reset of powersave state, as + * after BT disconnection, Module can't be in + * Active state */ + bt_specific_cb->bt_on_disconnect_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_USER_CONFIRMATION_REQUEST: { + if (bt_specific_cb->bt_on_confirm_request_event != NULL) { + bt_specific_cb->bt_on_confirm_request_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_USER_PASSKEY_NOTIFY: + case RSI_BT_EVT_USER_PASKEY_DISPLAY: { + if (bt_specific_cb->bt_on_passkey_display_event != NULL) { + bt_specific_cb->bt_on_passkey_display_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVDTP_STATS: { + if (bt_specific_cb->bt_on_avdtp_stats_event != NULL) { + bt_specific_cb->bt_on_avdtp_stats_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AR_STATS: { + if (bt_specific_cb->bt_on_ar_stats_event != NULL) { + bt_specific_cb->bt_on_ar_stats_event(status, (void *)payload); + } + } break; + case RSI_BT_EVENT_PKT_CHANGE: { + if (bt_specific_cb->bt_pkt_change_stats_event != NULL) { + bt_specific_cb->bt_pkt_change_stats_event(status, (void *)payload); + } + } break; + case RSI_BT_DISABLED_EVENT: { +#ifdef RSI_WLAN_ENABLE + if (rsi_wlan_cb_non_rom->switch_proto_callback == NULL) { + rsi_common_set_status((uint8_t)*payload); +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_sem); + } else { + rsi_wlan_cb_non_rom->switch_proto_callback(status, (void *)payload); + } + +#endif + } break; + case RSI_BT_EVT_CHIP_MEMORY_STATS: { + if (bt_specific_cb->bt_on_chip_memory_stats_event != NULL) { + bt_specific_cb->bt_on_chip_memory_stats_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_USER_PINCODE_REQUEST: { + if (bt_specific_cb->bt_on_pincode_request_event != NULL) { + bt_specific_cb->bt_on_pincode_request_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_USER_PASSKEY_REQUEST: { + if (bt_specific_cb->bt_on_passkey_request_event != NULL) { + bt_specific_cb->bt_on_passkey_request_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_INQ_COMPLETE: { + if (bt_specific_cb->bt_on_inquiry_complete_event != NULL) { + bt_specific_cb->bt_on_inquiry_complete_event(status); + } + } break; + case RSI_BT_EVT_AUTH_COMPLETE: { + if (bt_specific_cb->bt_on_auth_complete_event != NULL) { + bt_specific_cb->bt_on_auth_complete_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_USER_LINKKEY_REQUEST: { + if (bt_specific_cb->bt_on_linkkey_request_event != NULL) { + bt_specific_cb->bt_on_linkkey_request_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_USER_LINKKEY_SAVE: { + if (bt_specific_cb->bt_on_linkkey_save_event != NULL) { + bt_specific_cb->bt_on_linkkey_save_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_SPP_RECEIVE: { + if (bt_specific_cb->bt_on_spp_rx_data_event != NULL) { + bt_specific_cb->bt_on_spp_rx_data_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_SPP_CONNECTED: { + if (bt_specific_cb->bt_on_spp_connect_event != NULL) { + bt_specific_cb->bt_on_spp_connect_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_SPP_DISCONNECTED: { + if (bt_specific_cb->bt_on_spp_disconnect_event != NULL) { + bt_specific_cb->bt_on_spp_disconnect_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_MODE_CHANGED: { + if (bt_specific_cb->bt_on_mode_change_event != NULL) { + bt_specific_cb->bt_on_mode_change_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_SNIFF_SUBRATING_CHANGED: { + if (bt_specific_cb->bt_on_sniff_subrating_event != NULL) { + bt_specific_cb->bt_on_sniff_subrating_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_GATT_CONNECTED: { + if (bt_specific_cb->bt_on_gatt_connection_event != NULL) { + bt_specific_cb->bt_on_gatt_connection_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_GATT_DISCONNECTED: { + if (bt_specific_cb->bt_on_gatt_disconnection_event != NULL) { + bt_specific_cb->bt_on_gatt_disconnection_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_SSP_COMPLETE: { + if (bt_specific_cb->bt_on_ssp_complete_event != NULL) { + bt_specific_cb->bt_on_ssp_complete_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_A2DP_CONNECTED: { + if (bt_specific_cb->bt_on_a2dp_connect_event != NULL) { + bt_specific_cb->bt_on_a2dp_connect_event(status, (rsi_bt_event_a2dp_connect_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_DISCONNECTED: { + if (bt_specific_cb->bt_on_a2dp_disconnect_event != NULL) { + bt_specific_cb->bt_on_a2dp_disconnect_event(status, (rsi_bt_event_a2dp_disconnect_t *)payload); + } + } break; + + case RSI_BT_REQ_A2DP_PCM_MP3_DATA: { + if (bt_specific_cb->bt_on_a2dp_pcm_data_event != NULL) { + bt_specific_cb->bt_on_a2dp_pcm_data_event(status, (rsi_bt_event_a2dp_pcm_data_t *)payload); + } + } break; + + case RSI_BT_EVT_A2DP_CONFIGURED: { + if (bt_specific_cb->bt_on_a2dp_configure_event != NULL) { + bt_specific_cb->bt_on_a2dp_configure_event(status, (rsi_bt_event_a2dp_configure_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_OPEN: { + if (bt_specific_cb->bt_on_a2dp_open_event != NULL) { + bt_specific_cb->bt_on_a2dp_open_event(status, (rsi_bt_event_a2dp_open_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_START: { + if (bt_specific_cb->bt_on_a2dp_start_event != NULL) { + bt_specific_cb->bt_on_a2dp_start_event(status, (rsi_bt_event_a2dp_start_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_SUSPEND: { + if (bt_specific_cb->bt_on_a2dp_suspend_event != NULL) { + bt_specific_cb->bt_on_a2dp_suspend_event(status, (rsi_bt_event_a2dp_suspend_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_ABORT: { + if (bt_specific_cb->bt_on_a2dp_abort_event != NULL) { + bt_specific_cb->bt_on_a2dp_abort_event(status, (rsi_bt_event_a2dp_abort_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_CLOSE: { + if (bt_specific_cb->bt_on_a2dp_close_event != NULL) { + bt_specific_cb->bt_on_a2dp_close_event(status, (rsi_bt_event_a2dp_close_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_ENCODE_DATA: { + if (bt_specific_cb->bt_on_a2dp_encode_data_event != NULL) { + bt_specific_cb->bt_on_a2dp_encode_data_event(status, (rsi_bt_event_a2dp_encode_data_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_MORE_DATA_REQ: { + if (bt_specific_cb->bt_on_a2dp_data_req_event != NULL) { + bt_specific_cb->bt_on_a2dp_data_req_event(status, (rsi_bt_event_a2dp_more_data_req_t *)payload); + } + } break; + case RSI_BT_EVT_A2DP_RECONFIG: { + if (bt_specific_cb->bt_on_a2dp_reconfig_event != NULL) { + bt_specific_cb->bt_on_a2dp_reconfig_event(status, (rsi_bt_event_a2dp_reconfig_t *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_CONNECTED: { + if (bt_specific_cb->bt_on_avrcp_connect_event != NULL) { + bt_specific_cb->bt_on_avrcp_connect_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_DISCONNECTED: { + if (bt_specific_cb->bt_on_avrcp_disconnect_event != NULL) { + bt_specific_cb->bt_on_avrcp_disconnect_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_PLAY: { + if (bt_specific_cb->bt_on_avrcp_play_event != NULL) { + bt_specific_cb->bt_on_avrcp_play_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_PAUSE: { + if (bt_specific_cb->bt_on_avrcp_pause_event != NULL) { + bt_specific_cb->bt_on_avrcp_pause_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_STOP: { + if (bt_specific_cb->bt_on_avrcp_stop_event != NULL) { + bt_specific_cb->bt_on_avrcp_stop_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_NEXT: { + if (bt_specific_cb->bt_on_avrcp_next_event != NULL) { + bt_specific_cb->bt_on_avrcp_next_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_PREVIOUS: { + if (bt_specific_cb->bt_on_avrcp_previous_event != NULL) { + bt_specific_cb->bt_on_avrcp_previous_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_VOL_UP: { + if (bt_specific_cb->bt_on_avrcp_vol_up_event != NULL) { + bt_specific_cb->bt_on_avrcp_vol_up_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_AVRCP_VOL_DOWN: { + if (bt_specific_cb->bt_on_avrcp_vol_down_event != NULL) { + bt_specific_cb->bt_on_avrcp_vol_down_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_ELEM_RESP: { + if (bt_specific_cb->bt_on_avrcp_get_elem_attr_resp_event != NULL) { + bt_specific_cb->bt_on_avrcp_get_elem_attr_resp_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_NOTIFY: { + if (bt_specific_cb->bt_on_avrcp_notify_event != NULL) { + bt_specific_cb->bt_on_avrcp_notify_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GAT_CAPS: { + if (bt_specific_cb->bt_on_avrcp_gat_cap != NULL) { + bt_specific_cb->bt_on_avrcp_gat_cap(payload, payload[6]); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_APP_SUPP_ATTS: { + if (bt_specific_cb->bt_on_avrcp_get_app_att_list != NULL) { + bt_specific_cb->bt_on_avrcp_get_app_att_list(payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_APP_SUUP_ATT_VALS: { + if (bt_specific_cb->bt_on_avrcp_get_app_att_vals_list != NULL) { + bt_specific_cb->bt_on_avrcp_get_app_att_vals_list(payload, payload[6]); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_APP_CUR_ATT_VAL: { + if (bt_specific_cb->bt_on_avrcp_get_app_cur_att_val != NULL) { + bt_specific_cb->bt_on_avrcp_get_app_cur_att_val((rsi_bt_event_avrcp_get_cur_att_val_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_SET_APP_CUR_ATT_VAL: { + if (bt_specific_cb->bt_on_avrcp_set_app_cur_att_val != NULL) { + bt_specific_cb->bt_on_avrcp_set_app_cur_att_val((rsi_bt_event_avrcp_set_att_val_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_APP_ATT_TEXT: { + if (bt_specific_cb->bt_on_avrcp_get_app_att_text != NULL) { + bt_specific_cb->bt_on_avrcp_get_app_att_text((rsi_bt_event_avrcp_get_cur_att_val_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_APP_ATT_VAL_TEXT: { + if (bt_specific_cb->bt_on_avrcp_get_app_att_vals_text != NULL) { + bt_specific_cb->bt_on_avrcp_get_app_att_vals_text((rsi_bt_event_avrcp_vals_text_req_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_INFORM_CHAR_SETS: { + if (bt_specific_cb->bt_on_avrcp_supp_char_sets != NULL) { + bt_specific_cb->bt_on_avrcp_supp_char_sets((rsi_bt_event_avrcp_char_sets_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_INFORM_BATT_STATUS: { + if (bt_specific_cb->bt_on_avrcp_batt_status != NULL) { + bt_specific_cb->bt_on_avrcp_batt_status(payload, payload[6]); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_SONG_ATTS: { + if (bt_specific_cb->bt_on_avrcp_get_song_atts != NULL) { + bt_specific_cb->bt_on_avrcp_get_song_atts((rsi_bt_event_avrcp_ele_att_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_PLAY_STATUS: { + if (bt_specific_cb->bt_on_avrcp_get_player_status != NULL) { + bt_specific_cb->bt_on_avrcp_get_player_status(payload); + } + } break; + + case RSI_BT_EVT_AVRCP_REG_NOTIFICATION: { + if (bt_specific_cb->bt_on_avrcp_reg_notifivation != NULL) { + bt_specific_cb->bt_on_avrcp_reg_notifivation(payload, payload[6]); + } + } break; + + case RSI_BT_EVT_AVRCP_SET_ABS_VOL: { + if (bt_specific_cb->bt_on_avrcp_set_abs_vol != NULL) { + bt_specific_cb->bt_on_avrcp_set_abs_vol(status, (rsi_bt_event_avrcp_set_abs_vol_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_SET_ADDR_PLAYER: { + if (bt_specific_cb->bt_on_avrcp_set_addr_player != NULL) { + bt_specific_cb->bt_on_avrcp_set_addr_player((rsi_bt_event_avrcp_set_addr_player_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_FOLDER_ITEMS: { + printf("\nBT_EVT_GET_FOLDER_ITEMS\n"); + if (bt_specific_cb->bt_on_avrcp_get_folder_items != NULL) { + bt_specific_cb->bt_on_avrcp_get_folder_items((rsi_bt_event_avrcp_get_folder_items_t *)payload); + } + } break; + + case RSI_BT_EVT_AVRCP_GET_TOT_NUM_ITEMS: { + if (bt_specific_cb->bt_on_avrcp_get_tot_num_items != NULL) { + bt_specific_cb->bt_on_avrcp_get_tot_num_items((rsi_bt_event_avrcp_get_tot_num_items_t *)payload); + } + } break; + + case RSI_BT_EVENT_L2CAP_CONN: { + if (bt_specific_cb->bt_on_l2cap_connect_event != NULL) { + bt_specific_cb->bt_on_l2cap_connect_event(status, (rsi_bt_event_l2cap_connect_t *)payload); + } + } break; + + case RSI_BT_EVENT_L2CAP_RXDATA: { + if (bt_specific_cb->bt_on_l2cap_rx_data_event != NULL) { + bt_specific_cb->bt_on_l2cap_rx_data_event(status, (rsi_bt_event_l2cap_data_t *)payload); + } + } break; + case RSI_BT_EVT_HFP_CONN: { + if (bt_specific_cb->bt_on_hfp_connect_event != NULL) { + bt_specific_cb->bt_on_hfp_connect_event(status, (void *)payload); + } + } break; + case RSI_BT_EVT_HFP_DISCONN: { + if (bt_specific_cb->bt_on_hfp_disconnect_event != NULL) { + bt_specific_cb->bt_on_hfp_disconnect_event(status, (void *)payload); + } + } break; + + case RSI_BT_EVT_HFP_RING: { + if (bt_specific_cb->bt_on_hfp_ring_event != NULL) { + bt_specific_cb->bt_on_hfp_ring_event(status, (void *)payload); //, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_CALLCALLERID: { + if (bt_specific_cb->bt_on_hfp_callcallerid_event != NULL) { + bt_specific_cb->bt_on_hfp_callcallerid_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_AUDIOCONNECTED: { + if (bt_specific_cb->bt_on_hfp_audioconnected_event != NULL) { + bt_specific_cb->bt_on_hfp_audioconnected_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_AUDIODISCONNECTED: { + if (bt_specific_cb->bt_on_hfp_audiodisconnected_event != NULL) { + bt_specific_cb->bt_on_hfp_audiodisconnected_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_DIALCOMPLETE: { + if (bt_specific_cb->bt_on_hfp_dialcomplete_event != NULL) { + bt_specific_cb->bt_on_hfp_dialcomplete_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_ANSWERCOMPLETE: { + if (bt_specific_cb->bt_on_hfp_answercomplete_event != NULL) { + bt_specific_cb->bt_on_hfp_answercomplete_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_HANGUPCOMPLETE: { + if (bt_specific_cb->bt_on_hfp_hangupcomplete_event != NULL) { + bt_specific_cb->bt_on_hfp_hangupcomplete_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_SENDDTMFCOMPLETE: { + if (bt_specific_cb->bt_on_hfp_senddtmfcomplete_event != NULL) { + bt_specific_cb->bt_on_hfp_senddtmfcomplete_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_CALLWAIT: { + if (bt_specific_cb->bt_on_hfp_callwait_event != NULL) { + bt_specific_cb->bt_on_hfp_callwait_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_VOICERECOGDEACTIVATED: { + if (bt_specific_cb->bt_on_hfp_callvoicerecogdeactivated_event != NULL) { + bt_specific_cb->bt_on_hfp_callvoicerecogdeactivated_event(status, + (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_VOICERECOGACTIVATED: { + if (bt_specific_cb->bt_on_hfp_callvoicerecogactivated_event != NULL) { + bt_specific_cb->bt_on_hfp_callvoicerecogactivated_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_SERVICENOTFOUND: { + if (bt_specific_cb->bt_on_hfp_servicenotfound_event != NULL) { + bt_specific_cb->bt_on_hfp_servicenotfound_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_CALL_STATUS: { + if (bt_specific_cb->bt_on_hfp_callstatus_event != NULL) { + bt_specific_cb->bt_on_hfp_callstatus_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_SIGNALSTRENGTH: { + if (bt_specific_cb->bt_on_hfp_signalstrength_event != NULL) { + bt_specific_cb->bt_on_hfp_signalstrength_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_BATTERYLEVEL: { + if (bt_specific_cb->bt_on_hfp_batterylevel_event != NULL) { + bt_specific_cb->bt_on_hfp_batterylevel_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + + case RSI_BT_EVT_HFP_PHONESERVICE: { + if (bt_specific_cb->bt_on_hfp_phoneservice_event != NULL) { + bt_specific_cb->bt_on_hfp_phoneservice_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_ROAMINGSTATUS: { + if (bt_specific_cb->bt_on_hfp_roamingstatus_event != NULL) { + bt_specific_cb->bt_on_hfp_roamingstatus_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_CALLSETUP: { + if (bt_specific_cb->bt_on_hfp_callsetup_event != NULL) { + bt_specific_cb->bt_on_hfp_callsetup_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_CALLHELDSTATUS: { + if (bt_specific_cb->bt_on_hfp_callheld_event != NULL) { + bt_specific_cb->bt_on_hfp_callheld_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_VOICE_DATA: { + if (bt_specific_cb->bt_on_hfp_voice_data_event != NULL) { + bt_specific_cb->bt_on_hfp_voice_data_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVT_HFP_AUDIO_CODECSELECT: { + if (bt_specific_cb->bt_on_hfp_audio_codecselect_event != NULL) { + bt_specific_cb->bt_on_hfp_audio_codecselect_event(status, (void *)payload); //(status, (void *)payload ); + } + } break; + case RSI_BT_EVENT_IAP_CONN: { + if (bt_specific_cb->bt_app_iap_conn != NULL) { + bt_specific_cb->bt_app_iap_conn(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP_DISCONN: { + if (bt_specific_cb->bt_app_iap_disconn != NULL) { + bt_specific_cb->bt_app_iap_disconn(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP_ACC_AUTH_STARTED: { + if (bt_specific_cb->bt_app_iap_acc_auth_strt != NULL) { + bt_specific_cb->bt_app_iap_acc_auth_strt(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP_ACC_AUTH_FAILED: { + if (bt_specific_cb->bt_app_iap_acc_auth_fail != NULL) { + bt_specific_cb->bt_app_iap_acc_auth_fail(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP2_AUTH_START: { + if (bt_specific_cb->bt_app_iap2_auth_start != NULL) { + bt_specific_cb->bt_app_iap2_auth_start(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP2_AUTH_COMPLETE: { + if (bt_specific_cb->bt_app_iap2_auth_complete != NULL) { + bt_specific_cb->bt_app_iap2_auth_complete(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP2_AUTH_FAILED: { + if (bt_specific_cb->bt_app_iap2_auth_fail != NULL) { + bt_specific_cb->bt_app_iap2_auth_fail(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP2_IDENTIFICATION_START: { + if (bt_specific_cb->bt_app_iap2_identification_start != NULL) { + bt_specific_cb->bt_app_iap2_identification_start(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP2_IDENTIFICATION_COMPLETE: { + if (bt_specific_cb->bt_app_iap2_identification_complete != NULL) { + bt_specific_cb->bt_app_iap2_identification_complete(status, (rsi_bt_event_iap2_receive_t *)payload); + } + } break; + case RSI_BT_EVENT_IAP2_IDENTIFICATION_REJECT: { + if (bt_specific_cb->bt_app_iap2_identification_reject != NULL) { + bt_specific_cb->bt_app_iap2_identification_reject(status, (rsi_bt_event_iap2_receive_t *)payload); + } + } break; + + case RSI_BT_EVENT_IAP2_RX_DATA: { + if (bt_specific_cb->bt_app_on_iap2_data_rx != NULL) { + bt_specific_cb->bt_app_on_iap2_data_rx(status, (rsi_bt_event_iap2_receive_t *)payload); + } + } break; + + case RSI_BT_EVENT_IAP2_RX_FILE_TRANSFER_STATE: { + if (bt_specific_cb->bt_app_iap2_File_Tx_state != NULL) { + bt_specific_cb->bt_app_iap2_File_Tx_state(status, (rsi_bt_event_iap2_receive_t *)payload); + } + } break; + + case RSI_BT_EVENT_IAP2_RX_FILE_TRANSFER_DATA: { + if (bt_specific_cb->bt_app_iap2_File_Transfer_rx_data != NULL) { + + bt_specific_cb->bt_app_iap2_File_Transfer_rx_data(status, (rsi_bt_event_iap2_receive_t *)payload); + } + } break; + + case RSI_BT_EVENT_IAP_ACC_AUTH_COMPLETE: { + if (bt_specific_cb->bt_app_iap_acc_auth_complete != NULL) { + bt_specific_cb->bt_app_iap_acc_auth_complete(status, (rsi_bt_event_iap_t *)payload); + } + } break; + case RSI_BT_EVT_PBAP_CONN: { + if (bt_specific_cb->bt_on_pbap_connect_event != NULL) { + bt_specific_cb->bt_on_pbap_connect_event(status, (rsi_bt_event_pbap_connect_t *)payload); + } + } break; + case RSI_BT_EVT_PBAP_DISCONN: { + if (bt_specific_cb->bt_on_pbap_disconnect_event != NULL) { + bt_specific_cb->bt_on_pbap_disconnect_event(status, (rsi_bt_event_pbap_disconnect_t *)payload); + } + } break; + case RSI_BT_EVT_PBAP_DATA: { + + if (bt_specific_cb->bt_on_pbap_data_event != NULL) { + bt_specific_cb->bt_on_pbap_data_event(status, (rsi_bt_event_pbap_data_t *)payload); + } + } break; + case RSI_BT_EVENT_HID_CONN: { + if (bt_specific_cb->bt_on_hid_connect_event != NULL) { + bt_specific_cb->bt_on_hid_connect_event(status, (rsi_bt_event_hid_connect_t *)payload); + } + } break; + case RSI_BT_EVENT_HID_RXDATA: { + rsi_bt_event_hid_receive_t *hid_rx_event = (rsi_bt_event_hid_receive_t *)payload; + +#if 1 + switch ((hid_rx_event->data[0]) >> 4) { + case HID_MSG_HANDSHAKE: { + if (bt_specific_cb->bt_on_hid_handshake_event != NULL) { + bt_specific_cb->bt_on_hid_handshake_event(status, (rsi_bt_event_hid_receive_t *)payload); + } + } break; + case HID_MSG_CONTROL: { + if (bt_specific_cb->bt_on_hid_control_event != NULL) { + bt_specific_cb->bt_on_hid_control_event(status, (rsi_bt_event_hid_receive_t *)payload); + } + } break; + case HID_MSG_GET_REPORT: { + if (bt_specific_cb->bt_on_hid_get_report != NULL) { + bt_specific_cb->bt_on_hid_get_report(status, (rsi_bt_event_hid_receive_t *)payload); + } + } break; + case HID_MSG_SET_REPORT: { + if (bt_specific_cb->bt_on_hid_set_report != NULL) { + bt_specific_cb->bt_on_hid_set_report(status, (rsi_bt_event_hid_receive_t *)payload); + } + } break; + case HID_MSG_GET_PROTO: { + if (bt_specific_cb->bt_on_hid_get_proto != NULL) { + bt_specific_cb->bt_on_hid_get_proto(status, (rsi_bt_event_hid_receive_t *)payload); + } + } break; + case HID_MSG_SET_PROTO: { + if (bt_specific_cb->bt_on_hid_set_proto != NULL) { + bt_specific_cb->bt_on_hid_set_proto(status, (rsi_bt_event_hid_receive_t *)payload); + } + } + // Fall through + case HID_MSG_DATA: { + if (bt_specific_cb->bt_on_hid_rx_data_event != NULL) { + bt_specific_cb->bt_on_hid_rx_data_event(status, (rsi_bt_event_hid_receive_t *)payload); + } + } break; + default: + + break; + } + +#endif + } break; + default: { + } + } +} +/** @} */ +/** @addtogroup BT-LOW-ENERGY7 +* @{ +*/ +/*==============================================*/ +/** + * @brief Register GAP callbacks. + * @param[in] ble_on_adv_report_event - Callback function for Advertise events + * @param[in] ble_on_connect - Callback function for Connect events + * @param[in] ble_on_disconnect - Callback function for Disconnect events + * @param[in] timeout_expired_event - Callback function for le ping timeout events + * @param[in] ble_on_phy_update_complete_event - Callback function for phy update complete events + * @param[in] ble_on_data_length_update_complete_event - Callback function for data length update events + * @param[in] ble_on_enhance_conn_status_event - Callback function for enhanced connection status events + * @param[in] ble_on_directed_adv_report_event - Callback function for directed advertiseing report events + * @param[in] ble_on_conn_update_complete_event - Callback function for conn update complete events + * @param[in] ble_on_remote_conn_params_request_event - Callback function to remote conn params request events + * @return void + */ + +#ifdef RSI_BLE_ENABLE +void rsi_ble_gap_register_callbacks(rsi_ble_on_adv_report_event_t ble_on_adv_report_event, + rsi_ble_on_connect_t ble_on_conn_status_event, + rsi_ble_on_disconnect_t ble_on_disconnect_event, + rsi_ble_on_le_ping_payload_timeout_t ble_on_le_ping_time_expired_event, + rsi_ble_on_phy_update_complete_t ble_on_phy_update_complete_event, + rsi_ble_on_data_length_update_t rsi_ble_on_data_length_update_event, + rsi_ble_on_enhance_connect_t ble_on_enhance_conn_status_event, + rsi_ble_on_directed_adv_report_event_t ble_on_directed_adv_report_event, + rsi_ble_on_conn_update_complete_t ble_on_conn_update_complete_event, + rsi_ble_on_remote_conn_params_request_t ble_on_remote_conn_params_request_event) +{ + + SL_PRINTF(SL_RSI_BLE_GAP_REGISTER_CALLBACKS_TRIGGER, BLE, LOG_INFO); + // Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_adv_report_event = ble_on_adv_report_event; + ble_specific_cb->ble_on_conn_status_event = ble_on_conn_status_event; + ble_specific_cb->ble_on_disconnect_event = ble_on_disconnect_event; + ble_specific_cb->ble_on_le_ping_time_expired_event = ble_on_le_ping_time_expired_event; + ble_specific_cb->ble_on_phy_update_complete_event = ble_on_phy_update_complete_event; + ble_specific_cb->rsi_ble_on_data_length_update_event = rsi_ble_on_data_length_update_event; + ble_specific_cb->ble_on_enhance_conn_status_event = ble_on_enhance_conn_status_event; + ble_specific_cb->ble_on_directed_adv_report_event = ble_on_directed_adv_report_event; + ble_specific_cb->ble_on_conn_update_complete_event = ble_on_conn_update_complete_event; + ble_specific_cb->ble_on_remote_conn_params_request_event = ble_on_remote_conn_params_request_event; +} +/*==============================================*/ +/** + * @brief Register GAP Extended responses/events callbacks. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] ble_on_remote_features_event - Call back function for Remote feature request + * @param[in] ble_on_le_more_data_req_event - Call back function for LE More data request + * @note For more information about each callback, please refer to GAP Extended callbacks description section. + * @return void + */ + +void rsi_ble_gap_extended_register_callbacks(rsi_ble_on_remote_features_t ble_on_remote_features_event, + rsi_ble_on_le_more_data_req_t ble_on_le_more_data_req_event) +{ + + SL_PRINTF(SL_RSI_BLE_GAP_EXTENDED_REGISTER_CALLBACKS_TRIGGER, BLE, LOG_INFO); + // Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_remote_features_event = ble_on_remote_features_event; + ble_specific_cb->ble_on_le_more_data_req_event = ble_on_le_more_data_req_event; +} +/** @} */ + +/** @addtogroup BT-LOW-ENERGY7 +* @{ +*/ +/** + * @brief Register the SMP callbacks + * @param[in] ble_on_smp_request_event - smp request callback + * @param[in] ble_on_smp_response_event - smp response callback + * @param[in] ble_on_smp_passkey_event - smp passkey callback + * @param[in] ble_on_smp_failed_event - smp failed callback + * @param[in] ble_on_smp_encryptrd - encription enabled callback + * @param[in] ble_on_smp_passkey_display_event - smp passkey display callback + * @param[in] ble_sc_passkey_event - sc passkey display callback + * @param[in] ble_on_le_ltk_req_event - This is the SMP ltk request callback + * @param[in] ble_on_le_security_keys_event - This is the SMP security keys callback + * @param[in] ble_on_sc_method_event - sc method display callback + * @return void + * + */ + +void rsi_ble_smp_register_callbacks(rsi_ble_on_smp_request_t ble_on_smp_request_event, + rsi_ble_on_smp_response_t ble_on_smp_response_event, + rsi_ble_on_smp_passkey_t ble_on_smp_passkey_event, + rsi_ble_on_smp_failed_t ble_on_smp_failed_event, + rsi_ble_on_encrypt_started_t ble_on_smp_encryptrd, + rsi_ble_on_smp_passkey_display_t ble_on_smp_passkey_display_event, + rsi_ble_on_sc_passkey_t ble_sc_passkey_event, + rsi_ble_on_le_ltk_req_event_t ble_on_le_ltk_req_event, + rsi_ble_on_le_security_keys_t ble_on_le_security_keys_event, + rsi_ble_on_smp_response_t ble_on_cli_smp_response_event, + rsi_ble_on_sc_method_t ble_on_sc_method_event) +{ + + SL_PRINTF(SL_RSI_BLE_SMP_REGISTER_CALLBACKS_TRIGGER, BLE, LOG_INFO); + // Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_smp_request_event = ble_on_smp_request_event; + ble_specific_cb->ble_on_smp_response_event = ble_on_smp_response_event; + ble_specific_cb->ble_on_smp_passkey_event = ble_on_smp_passkey_event; + ble_specific_cb->ble_on_smp_fail_event = ble_on_smp_failed_event; + ble_specific_cb->ble_on_smp_encrypt_started = ble_on_smp_encryptrd; + ble_specific_cb->ble_on_smp_passkey_display = ble_on_smp_passkey_display_event; + ble_specific_cb->ble_on_sc_passkey = ble_sc_passkey_event; + ble_specific_cb->ble_on_le_ltk_req_event = ble_on_le_ltk_req_event; + ble_specific_cb->ble_on_le_security_keys_event = ble_on_le_security_keys_event; + ble_specific_cb->ble_on_cli_smp_response_event = ble_on_cli_smp_response_event; + ble_specific_cb->ble_on_sc_method_event = ble_on_sc_method_event; +} + +/** + * @brief Register the GATT callbacks. + * @param[in] rsi_ble_on_profiles_list_resp_t ble_on_profiles_list_resp - Callback for rsi_ble_get_profiles command + * @param[in] rsi_ble_on_profile_resp_t ble_on_profile_resp - Callback for rsi_ble_get_profile command + * @param[in] rsi_ble_on_char_services_resp_t ble_on_char_services_resp - Callback for rsi_ble_get_char_services command + * @param[in] rsi_ble_on_inc_services_resp_t ble_on_inc_services_resp - Callback for rsi_ble_get_inc_services command + * @param[in] rsi_ble_on_att_desc_resp_t ble_on_att_desc_resp - Callback for rsi_ble_get_att_descriptors command + * @param[in] rsi_ble_on_read_resp_t ble_on_read_resp - Callback for all read requests command + * @param[in] rsi_ble_on_write_resp_t ble_on_write_resp - Callback for all write commands + * @param[in] rsi_ble_on_gatt_write_event_t blw_on_gatt_event - Callback for all GATT events + * @param[in] rsi_ble_on_gatt_error_resp_t ble_on_gatt_error_resp_event - Callback for GATT error events + * @param[in] rsi_ble_on_gatt_desc_val_event_t ble_on_gatt_desc_val_resp_event - Callback for GATT descriptor value event + * @param[in] rsi_ble_on_event_profiles_list_t ble_on_profiles_list_event - Callback function for profiles list event + * @param[in] rsi_ble_on_event_profile_by_uuid_t ble_on_profile_by_uuid_event - Callback function for profile event + * @param[in] rsi_ble_on_event_read_by_char_services_t ble_on_read_by_char_services_event- Callback function for char services event + * @param[in] rsi_ble_on_event_read_by_inc_services_t ble_on_read_by_inc_services_event - Callback function for inc services event + * @param[in] rsi_ble_on_event_read_att_value_t ble_on_read_att_value_event - Callback function for read att value event + * @param[in] rsi_ble_on_event_read_resp_t ble_on_read_resp_event - Callback function for read att event + * @param[in] rsi_ble_on_event_write_resp_t ble_on_write_resp_event - Callback function for write event + * @param[in] rsi_ble_on_event_indicate_confirmation_t ble_on_indicate_confirmation_event- Callback function for indicate confirmation event + * @param[in] rsi_ble_on_event_prepare_write_resp_t ble_on_prepare_write_resp_event - Callback function for prepare write event + * @return void + * + */ + +void rsi_ble_gatt_register_callbacks(rsi_ble_on_profiles_list_resp_t ble_on_profiles_list_resp, + rsi_ble_on_profile_resp_t ble_on_profile_resp, + rsi_ble_on_char_services_resp_t ble_on_char_services_resp, + rsi_ble_on_inc_services_resp_t ble_on_inc_services_resp, + rsi_ble_on_att_desc_resp_t ble_on_att_desc_resp, + rsi_ble_on_read_resp_t ble_on_read_resp, + rsi_ble_on_write_resp_t ble_on_write_resp, + rsi_ble_on_gatt_write_event_t ble_on_gatt_event, + rsi_ble_on_gatt_prepare_write_event_t ble_on_gatt_prepare_write_event, + rsi_ble_on_execute_write_event_t ble_on_execute_write_event, + rsi_ble_on_read_req_event_t ble_on_read_req_event, + rsi_ble_on_mtu_event_t ble_on_mtu_event, + rsi_ble_on_gatt_error_resp_t ble_on_gatt_error_resp_event, + rsi_ble_on_gatt_desc_val_event_t ble_on_gatt_desc_val_resp_event, + rsi_ble_on_event_profiles_list_t ble_on_profiles_list_event, + rsi_ble_on_event_profile_by_uuid_t ble_on_profile_by_uuid_event, + rsi_ble_on_event_read_by_char_services_t ble_on_read_by_char_services_event, + rsi_ble_on_event_read_by_inc_services_t ble_on_read_by_inc_services_event, + rsi_ble_on_event_read_att_value_t ble_on_read_att_value_event, + rsi_ble_on_event_read_resp_t ble_on_read_resp_event, + rsi_ble_on_event_write_resp_t ble_on_write_resp_event, + rsi_ble_on_event_indicate_confirmation_t ble_on_indicate_confirmation_event, + rsi_ble_on_event_prepare_write_resp_t ble_on_prepare_write_resp_event) +{ + + SL_PRINTF(SL_RSI_BLE_GATT_REGISTER_CALLBACKS_TRIGGER, BLE, LOG_INFO); + // Get ble specific cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_profiles_list_resp = ble_on_profiles_list_resp; + ble_specific_cb->ble_on_profile_resp = ble_on_profile_resp; + ble_specific_cb->ble_on_char_services_resp = ble_on_char_services_resp; + ble_specific_cb->ble_on_inc_services_resp = ble_on_inc_services_resp; + ble_specific_cb->ble_on_att_desc_resp = ble_on_att_desc_resp; + ble_specific_cb->ble_on_read_resp = ble_on_read_resp; + ble_specific_cb->ble_on_write_resp = ble_on_write_resp; + ble_specific_cb->ble_on_gatt_events = ble_on_gatt_event; + ble_specific_cb->ble_on_prepare_write_event = ble_on_gatt_prepare_write_event; + ble_specific_cb->ble_on_execute_write_event = ble_on_execute_write_event; + ble_specific_cb->ble_on_read_req_event = ble_on_read_req_event; + ble_specific_cb->ble_on_mtu_event = ble_on_mtu_event; + ble_specific_cb->ble_on_gatt_error_resp_event = ble_on_gatt_error_resp_event; + ble_specific_cb->ble_on_profiles_list_event = ble_on_profiles_list_event; + ble_specific_cb->ble_on_gatt_desc_val_resp_event = ble_on_gatt_desc_val_resp_event; + ble_specific_cb->ble_on_profile_by_uuid_event = ble_on_profile_by_uuid_event; + ble_specific_cb->ble_on_read_by_char_services_event = ble_on_read_by_char_services_event; + ble_specific_cb->ble_on_read_by_inc_services_event = ble_on_read_by_inc_services_event; + ble_specific_cb->ble_on_read_att_value_event = ble_on_read_att_value_event; + ble_specific_cb->ble_on_read_resp_event = ble_on_read_resp_event; + ble_specific_cb->ble_on_write_resp_event = ble_on_write_resp_event; + ble_specific_cb->ble_on_indicate_confirmation_event = ble_on_indicate_confirmation_event; + ble_specific_cb->ble_on_prepare_write_resp_event = ble_on_prepare_write_resp_event; + + return; +} +/** + * @brief Register the GATT Extended responses/events callbacks. + * @param[in] rsi_ble_on_mtu_exchange_info_t ble_on_mtu_exchange_info_event - Call back function for MTU Exchange information Event + * @return void + * + */ + +void rsi_ble_gatt_extended_register_callbacks(rsi_ble_on_mtu_exchange_info_t ble_on_mtu_exchange_info_event) +{ + // Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_mtu_exchange_info_event = ble_on_mtu_exchange_info_event; +} + +/** + * @fn uint16_t rsi_ble_enhanced_gap_extended_register_callbacks(uint16_t callback_id, void (*callback_handler_ptr)(uint16_t status, + * uint8_t *buffer)) + * @brief Register the BLE GAP extended callback functions. + * @param[in] callback_id - This is the Id of the call back function, following ids are supported: \n + * RSI_BLE_ON_REMOTE_DEVICE_INFORMATION \n + * RSI_BLE_ON_RCP_EVENT \n + * @param[in] void(*callback_handler_ptr) - This is the Callback handler \n + * @param[out] status - status of the asynchronous response \n + * @param[out] buffer - payload of the asynchronous response \n \n + * @return 0 - Success \n + * -53 - Failure \n + * If call_back_id is greater than the maximum callbacks to register, returns \ref RSI_ERROR_BLE_INVALID_CALLBACK_CNT. + * @note In callbacks, application should not initiate any TX operation to the module. + */ +uint32_t rsi_ble_enhanced_gap_extended_register_callbacks(uint16_t callback_id, + void (*callback_handler_ptr)(uint16_t status, + uint8_t *buffer)) +{ + // Get BLE cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + if (callback_id > RSI_BLE_MAX_NUM_GAP_EXT_CALLBACKS) { + + /*Return , if the callback number exceeds the RSI_BT_COMMON_MAX_NUM_EXT_CALLBACKS */ + + return RSI_ERROR_BLE_INVALID_CALLBACK_CNT; + } + switch (callback_id) { + case RSI_BLE_ON_REMOTE_DEVICE_INFORMATION: { + ble_specific_cb->ble_on_remote_device_info_event = (rsi_ble_on_remote_device_info_t)callback_handler_ptr; + } break; + default: + LOG_PRINT("\nInvalid Callback ID\n"); + return RSI_ERROR_BLE_INVALID_CALLBACK_CNT; + } + return RSI_SUCCESS; +} + +/** + * @fn uint16_t rsi_ble_adv_ext_events_register_callbacks (uint16_t callback_id, void (*callback_handler_ptr)(uint16_t status, + * uint8_t *buffer)) + * @brief Register the BLE call back functions. + * @param[in] callback_id - This is the Id of the call back function following ids are supported: + * @param[in] void (*callback_handler_ptr)(void - This is the Call back handler + * @param[in] status - status of the asynchronous response + * @param[in] buffer - payload of the asynchronous response + * @return 0 - Success \n + * -53 - Failure \n + * If call_back_id is greater than the maximum callbacks to register, returns ref/ RSI_ERROR_BLE_INVALID_CALLBACK_CNT. + * @note In callbacks, application should not initiate any TX operation to the module. + */ + +int32_t rsi_ble_adv_ext_events_register_callbacks(uint16_t callback_id, + void (*callback_handler_ptr)(uint16_t status, uint8_t *buffer)) +{ + //Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + if (callback_id > RSI_BLE_MAX_NUM_ADV_EXT_EVENT_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_BLE_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + return RSI_ERROR_BLE_INVALID_CALLBACK_CNT; + } + + switch (callback_id) { + case RSI_BLE_ON_ADV_EXT_ADVERTISE_REPORT_EVENT: { + ble_specific_cb->ble_ae_report_complete_event = (rsi_ble_ae_report_complete_t)callback_handler_ptr; + } break; + case RSI_BLE_ON_ADV_EXT_PERIODIC_ADV_SYNC_ESTBL_EVENT: { + ble_specific_cb->ble_ae_per_adv_sync_estbl_event = (rsi_ble_ae_per_adv_sync_estbl_t)callback_handler_ptr; + } break; + case RSI_BLE_ON_ADV_EXT_PERIODIC_ADVERTISE_REPORT_EVENT: { + ble_specific_cb->ble_ae_per_adv_report_event = (rsi_ble_ae_per_adv_report_t)callback_handler_ptr; + } break; + case RSI_BLE_ON_ADV_EXT_PERIODIC_ADV_SYNC_LOST_EVENT: { + ble_specific_cb->ble_ae_per_adv_sync_lost_event = (rsi_ble_ae_per_adv_sync_lost_t)callback_handler_ptr; + } break; + case RSI_BLE_ON_ADV_EXT_SCAN_TIMEOUT_EVENT: { + ble_specific_cb->ble_ae_scan_timeout_event = (rsi_ble_ae_scan_timeout_t)callback_handler_ptr; + } break; + case RSI_BLE_ON_ADV_EXT_ADVERTISE_SET_TERMINATED_EVENT: { + ble_specific_cb->ble_ae_adv_set_terminated_event = (rsi_ble_ae_adv_set_terminated_t)callback_handler_ptr; + } break; + case RSI_BLE_ON_ADV_EXT_SCAN_REQUEST_RECEIVED_EVENT: { + ble_specific_cb->ble_ae_scan_req_recvd_event = (rsi_ble_ae_scan_req_recvd_t)callback_handler_ptr; + } break; + default: + return RSI_ERROR_BLE_INVALID_CALLBACK_CNT; + } + + return RSI_SUCCESS; +} + +/** @} */ + +/*==============================================*/ +/** + * @brief Register the function pointers for GATT responses + * @param[in] ble_on_cbsc_conn_req - Callback function for CBFC connection request event + * @param[in] ble_on_cbsc_conn_complete - Callback function for CBFC connection complete status event + * @param[in] ble_on_cbsc_rx_data - Callback function for CBFC data receive event + * @param[in] ble_on_cbsc_disconn - Callback function for CBFC disconnect event + * @return void + */ + +void rsi_ble_l2cap_cbsc_register_callbacks(rsi_ble_on_cbfc_conn_req_event_t ble_on_cbsc_conn_req, + rsi_ble_on_cbfc_conn_complete_event_t ble_on_cbsc_conn_complete, + rsi_ble_on_cbfc_rx_data_event_t ble_on_cbsc_rx_data, + rsi_ble_on_cbfc_disconn_event_t ble_on_cbsc_disconn) +{ + + SL_PRINTF(SL_RSI_BLE_L2CAP_CBSC_REGISTER_CALLBACKS_TRIGGER, BLE, LOG_INFO); + // Get ble specific cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_cbfc_conn_req_event = ble_on_cbsc_conn_req; + ble_specific_cb->ble_on_cbfc_conn_complete_event = ble_on_cbsc_conn_complete; + ble_specific_cb->ble_on_cbfc_rx_data_event = ble_on_cbsc_rx_data; + ble_specific_cb->ble_on_cbfc_disconn_event = ble_on_cbsc_disconn; + + return; +} + +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Initailize the BT callbacks register. + * @param[in] ble_cb - BLE control back + * @param[in] rsp_type - BLE Packet type + * @param[in] payload - Payload + * @param[in] payload_length - Payload length + * @return void + * + */ +void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t *payload, uint16_t payload_length) +{ + SL_PRINTF(SL_RSI_BLE_CALLBACKS_HANDLER_TRIGGER, BLE, LOG_INFO, "RESPONSE_TYPE: %2x", rsp_type); + // This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(payload_length); + // Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = ble_cb->bt_global_cb->ble_specific_cb; + uint16_t status = 0; + uint16_t sync_status = 0; + uint8_t le_cmd_inuse_check = 0; + + // updating the response status; + status = ble_cb->async_status; + + sync_status = rsi_bt_get_status(ble_cb); + + SL_PRINTF(SL_RSI_BLE_CALLBACKS_HANDLER_STATUS, BLE, LOG_INFO, "STATUS: %2x", status); + + // Check each cmd_type like decode_resp_handler and call the respective callback + switch (rsp_type) { + case RSI_BLE_EVENT_ADV_REPORT: { + if (ble_specific_cb->ble_on_adv_report_event != NULL) { + ble_specific_cb->ble_on_adv_report_event((rsi_ble_event_adv_report_t *)payload); + } + } break; + case RSI_BLE_EVENT_CONN_STATUS: { + if (ble_specific_cb->ble_on_conn_status_event != NULL) { + ble_specific_cb->ble_on_conn_status_event((rsi_ble_event_conn_status_t *)payload); + } + // rsi_bt_set_status(ble_cb, RSI_BLE_STATE_CONNECTION); + rsi_add_remote_ble_dev_info((rsi_ble_event_enhance_conn_status_t *)payload); + } break; + + case RSI_BLE_EVENT_ENHANCE_CONN_STATUS: { + if (ble_specific_cb->ble_on_enhance_conn_status_event != NULL) { + ble_specific_cb->ble_on_enhance_conn_status_event((rsi_ble_event_enhance_conn_status_t *)payload); + } + // rsi_bt_set_status(ble_cb, RSI_BLE_STATE_CONNECTION); + rsi_add_remote_ble_dev_info((rsi_ble_event_enhance_conn_status_t *)payload); + } break; + + case RSI_BLE_EVENT_DISCONNECT: { + if (ble_specific_cb->ble_on_disconnect_event != NULL) { + ble_specific_cb->ble_on_disconnect_event((rsi_ble_event_disconnect_t *)payload, status); + } + // rsi_bt_set_status(ble_cb, RSI_BLE_STATE_DSICONNECT); + rsi_remove_remote_ble_dev_info((rsi_ble_event_disconnect_t *)payload); + } break; + case RSI_BLE_EVENT_GATT_ERROR_RESPONSE: { + if (ble_specific_cb->ble_on_gatt_error_resp_event != NULL) { + ble_specific_cb->ble_on_gatt_error_resp_event(status, (rsi_ble_event_error_resp_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_DESC_VAL_RESPONSE: { + if (ble_specific_cb->ble_on_gatt_desc_val_resp_event != NULL) { + ble_specific_cb->ble_on_gatt_desc_val_resp_event(status, (rsi_ble_event_gatt_desc_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + + case RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_LIST: { + if (ble_specific_cb->ble_on_profiles_list_event != NULL) { + ble_specific_cb->ble_on_profiles_list_event(status, (rsi_ble_event_profiles_list_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_BY_UUID: { + if (ble_specific_cb->ble_on_profile_by_uuid_event != NULL) { + ble_specific_cb->ble_on_profile_by_uuid_event(status, (rsi_ble_event_profile_by_uuid_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_READ_CHAR_SERVS: { + if (ble_specific_cb->ble_on_read_by_char_services_event != NULL) { + ble_specific_cb->ble_on_read_by_char_services_event(status, (rsi_ble_event_read_by_type1_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_READ_INC_SERVS: { + if (ble_specific_cb->ble_on_read_by_inc_services_event != NULL) { + ble_specific_cb->ble_on_read_by_inc_services_event(status, (rsi_ble_event_read_by_type2_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_READ_VAL_BY_UUID: { + if (ble_specific_cb->ble_on_read_att_value_event != NULL) { + ble_specific_cb->ble_on_read_att_value_event(status, (rsi_ble_event_read_by_type3_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_READ_RESP: + case RSI_BLE_EVENT_GATT_READ_BLOB_RESP: + case RSI_BLE_EVENT_GATT_READ_MULTIPLE_RESP: { + if (ble_specific_cb->ble_on_read_resp_event != NULL) { + ble_specific_cb->ble_on_read_resp_event(status, (rsi_ble_event_att_value_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_WRITE_RESP: + case RSI_BLE_EVENT_GATT_EXECUTE_WRITE_RESP: { + if (ble_specific_cb->ble_on_write_resp_event != NULL) { + ble_specific_cb->ble_on_write_resp_event(status, (rsi_ble_set_att_resp_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_INDICATE_CONFIRMATION: { + if (ble_specific_cb->ble_on_indicate_confirmation_event != NULL) { + ble_specific_cb->ble_on_indicate_confirmation_event(status, (rsi_ble_set_att_resp_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_GATT_PREPARE_WRITE_RESP: { + if (ble_specific_cb->ble_on_prepare_write_resp_event != NULL) { + ble_specific_cb->ble_on_prepare_write_resp_event(status, (rsi_ble_prepare_write_resp_t *)payload); + } + le_cmd_inuse_check = 1; + } break; + case RSI_BLE_EVENT_SMP_REQUEST: { + if (ble_specific_cb->ble_on_smp_request_event != NULL) { + ble_specific_cb->ble_on_smp_request_event((rsi_bt_event_smp_req_t *)payload); + } + } break; + + case RSI_BLE_EVENT_SMP_RESPONSE: { + if (ble_specific_cb->ble_on_smp_response_event != NULL) { + ble_specific_cb->ble_on_smp_response_event((rsi_bt_event_smp_resp_t *)payload); + } + } break; + + case RSI_BLE_EVENT_CLI_SMP_RESPONSE: { + if (ble_specific_cb->ble_on_cli_smp_response_event != NULL) { + ble_specific_cb->ble_on_cli_smp_response_event((rsi_bt_event_smp_resp_t *)payload); + } + } break; + case RSI_BLE_EVENT_CHIP_MEMORY_STATS: { + if (ble_specific_cb->ble_on_chip_memory_status_event != NULL) { + ble_specific_cb->ble_on_chip_memory_status_event((chip_ble_buffers_stats_t *)payload); + } + } break; + + case RSI_BLE_EVENT_SMP_PASSKEY: { + if (ble_specific_cb->ble_on_smp_passkey_event != NULL) { + ble_specific_cb->ble_on_smp_passkey_event((rsi_bt_event_smp_passkey_t *)payload); + } + } break; + + case RSI_BLE_EVENT_SMP_FAILED: { + if (ble_specific_cb->ble_on_smp_fail_event != NULL) { + ble_specific_cb->ble_on_smp_fail_event(status, (rsi_bt_event_smp_failed_t *)payload); + } + } break; + + case RSI_BLE_EVENT_SC_METHOD: { + if (ble_specific_cb->ble_on_sc_method_event != NULL) { + ble_specific_cb->ble_on_sc_method_event((rsi_bt_event_sc_method_t *)payload); + } + } break; + + case RSI_BLE_EVENT_ENCRYPT_STARTED: { + if (ble_specific_cb->ble_on_smp_encrypt_started != NULL) { + ble_specific_cb->ble_on_smp_encrypt_started(status, (rsi_bt_event_encryption_enabled_t *)payload); + } + } break; + case RSI_BLE_EVENT_SMP_PASSKEY_DISPLAY_EVENT: { + if (ble_specific_cb->ble_on_smp_passkey_display != NULL) { + ble_specific_cb->ble_on_smp_passkey_display((rsi_bt_event_smp_passkey_display_t *)payload); + } + } break; + case RSI_BLE_RSP_PROFILES: { + if (ble_specific_cb->ble_on_profiles_list_resp != NULL) { + ble_specific_cb->ble_on_profiles_list_resp(sync_status, (rsi_ble_resp_profiles_list_t *)payload); + } + } break; + case RSI_BLE_RSP_PROFILE: { + if (ble_specific_cb->ble_on_profile_resp != NULL) { + ble_specific_cb->ble_on_profile_resp(sync_status, (profile_descriptors_t *)payload); + } + } break; + case RSI_BLE_RSP_CHAR_SERVICES: { + if (ble_specific_cb->ble_on_char_services_resp != NULL) { + ble_specific_cb->ble_on_char_services_resp(sync_status, (rsi_ble_resp_char_services_t *)payload); + } + } break; + case RSI_BLE_RSP_INC_SERVICES: { + if (ble_specific_cb->ble_on_inc_services_resp != NULL) { + ble_specific_cb->ble_on_inc_services_resp(sync_status, (rsi_ble_resp_inc_services_t *)payload); + } + } break; + case RSI_BLE_RSP_DESC: { + if (ble_specific_cb->ble_on_att_desc_resp != NULL) { + ble_specific_cb->ble_on_att_desc_resp(sync_status, (rsi_ble_resp_att_descs_t *)payload); + } + } break; + case RSI_BLE_RSP_READ_BY_UUID: + case RSI_BLE_RSP_READ_VAL: + case RSI_BLE_RSP_MULTIPLE_READ: + case RSI_BLE_RSP_LONG_READ: { + if (ble_specific_cb->ble_on_read_resp != NULL) { + ble_specific_cb->ble_on_read_resp(sync_status, rsp_type, (rsi_ble_resp_att_value_t *)payload); + } + } break; + case RSI_BLE_RSP_WRITE: + case RSI_BLE_RSP_WRITE_NO_ACK: + case RSI_BLE_RSP_LONG_WRITE: + case RSI_BLE_RSP_PREPARE_WRITE: + case RSI_BLE_RSP_EXECUTE_WRITE: { + if (ble_specific_cb->ble_on_write_resp != NULL) { + ble_specific_cb->ble_on_write_resp(sync_status, rsp_type); + } + } break; + case RSI_BLE_EVENT_GATT_NOTIFICATION: + case RSI_BLE_EVENT_GATT_INDICATION: + case RSI_BLE_EVENT_GATT_WRITE: + if (ble_specific_cb->ble_on_gatt_events != NULL) { + ble_specific_cb->ble_on_gatt_events(rsp_type, (rsi_ble_event_write_t *)payload); + } + break; + case RSI_BLE_EVENT_MTU: + if (ble_specific_cb->ble_on_mtu_event != NULL) { + ble_specific_cb->ble_on_mtu_event((rsi_ble_event_mtu_t *)payload); + } + le_cmd_inuse_check = 1; + break; + case RSI_BLE_EVENT_MTU_EXCHANGE_INFORMATION: + if (ble_specific_cb->ble_on_mtu_exchange_info_event != NULL) { + ble_specific_cb->ble_on_mtu_exchange_info_event((rsi_ble_event_mtu_exchange_information_t *)payload); + } + le_cmd_inuse_check = 1; + break; + case RSI_BLE_EVENT_LE_PING_TIME_EXPIRED: + if (ble_specific_cb->ble_on_le_ping_time_expired_event != NULL) { + ble_specific_cb->ble_on_le_ping_time_expired_event((rsi_ble_event_le_ping_time_expired_t *)payload); + } + break; + + case RSI_BLE_EVENT_PREPARE_WRITE: + if (ble_specific_cb->ble_on_prepare_write_event != NULL) { + ble_specific_cb->ble_on_prepare_write_event(rsp_type, (rsi_ble_event_prepare_write_t *)payload); + } + break; + + case RSI_BLE_EVENT_EXECUTE_WRITE: + if (ble_specific_cb->ble_on_execute_write_event != NULL) { + ble_specific_cb->ble_on_execute_write_event(rsp_type, (rsi_ble_execute_write_t *)payload); + } + break; + + case RSI_BLE_EVENT_READ_REQ: + if (ble_specific_cb->ble_on_read_req_event != NULL) { + ble_specific_cb->ble_on_read_req_event(rsp_type, (rsi_ble_read_req_t *)payload); + } + break; + + case RSI_BLE_EVENT_PHY_UPDATE_COMPLETE: { + if (ble_specific_cb->ble_on_phy_update_complete_event != NULL) { + ble_specific_cb->ble_on_phy_update_complete_event((rsi_ble_event_phy_update_t *)payload); + } + } break; + + case RSI_BLE_EVENT_DATA_LENGTH_UPDATE_COMPLETE: + if (ble_specific_cb->rsi_ble_on_data_length_update_event != NULL) { + ble_specific_cb->rsi_ble_on_data_length_update_event((rsi_ble_event_data_length_update_t *)payload); + } + break; + + case RSI_BLE_EVENT_SC_PASSKEY: { + if (ble_specific_cb->ble_on_sc_passkey != NULL) { + ble_specific_cb->ble_on_sc_passkey((rsi_bt_event_sc_passkey_t *)payload); + } + } break; + + case RSI_BLE_EVENT_DIRECTED_ADV_REPORT: { + if (ble_specific_cb->ble_on_directed_adv_report_event != NULL) { + ble_specific_cb->ble_on_directed_adv_report_event((rsi_ble_event_directedadv_report_t *)payload); + } + } break; + + case RSI_BLE_EVENT_LE_LTK_REQUEST: + if (ble_specific_cb->ble_on_le_ltk_req_event != NULL) { + ble_specific_cb->ble_on_le_ltk_req_event((rsi_bt_event_le_ltk_request_t *)payload); + } + break; + + case RSI_BLE_EVENT_SECURITY_KEYS: { + if (ble_specific_cb->ble_on_le_security_keys_event != NULL) { + ble_specific_cb->ble_on_le_security_keys_event((rsi_bt_event_le_security_keys_t *)payload); + } + } break; + + case RSI_BLE_EVENT_PSM_CONN_REQ: { + if (ble_specific_cb->ble_on_cbfc_conn_req_event != NULL) { + ble_specific_cb->ble_on_cbfc_conn_req_event((rsi_ble_event_cbfc_conn_req_t *)payload); + } + } break; + + case RSI_BLE_EVENT_PSM_CONN_COMPLETE: { + if (ble_specific_cb->ble_on_cbfc_conn_complete_event != NULL) { + ble_specific_cb->ble_on_cbfc_conn_complete_event((rsi_ble_event_cbfc_conn_complete_t *)payload, status); + } + } break; + + case RSI_BLE_EVENT_PSM_RX_DATA: { + if (ble_specific_cb->ble_on_cbfc_rx_data_event != NULL) { + ble_specific_cb->ble_on_cbfc_rx_data_event((rsi_ble_event_cbfc_rx_data_t *)payload); + } + } break; + + case RSI_BLE_EVENT_PSM_DISCONNECT: { + if (ble_specific_cb->ble_on_cbfc_disconn_event != NULL) { + ble_specific_cb->ble_on_cbfc_disconn_event((rsi_ble_event_cbfc_disconn_t *)payload); + } + } break; + + case RSI_BLE_EVENT_CONN_UPDATE_COMPLETE: { + if (ble_specific_cb->ble_on_conn_update_complete_event != NULL) { + ble_specific_cb->ble_on_conn_update_complete_event((rsi_ble_event_conn_update_t *)payload, status); + } + } break; + case RSI_BLE_EVENT_REMOTE_FEATURES: { + if (ble_specific_cb->ble_on_remote_features_event != NULL) { + ble_specific_cb->ble_on_remote_features_event((rsi_ble_event_remote_features_t *)payload); + } + } break; + case RSI_BLE_EVENT_LE_MORE_DATA_REQ: { + rsi_ble_update_le_dev_buf((rsi_ble_event_le_dev_buf_ind_t *)payload); + if (ble_specific_cb->ble_on_le_more_data_req_event != NULL) { + ble_specific_cb->ble_on_le_more_data_req_event((rsi_ble_event_le_dev_buf_ind_t *)payload); + } + } break; + case RSI_BLE_EVENT_REMOTE_CONN_PARAMS_REQUEST: { + if (ble_specific_cb->ble_on_remote_conn_params_request_event != NULL) { + ble_specific_cb->ble_on_remote_conn_params_request_event((rsi_ble_event_remote_conn_param_req_t *)payload, + status); + } + } break; + case RSI_BLE_EVENT_REMOTE_DEVICE_INFORMATION: { + if (ble_specific_cb->ble_on_remote_device_info_event != NULL) { + ble_specific_cb->ble_on_remote_device_info_event(status, (rsi_ble_event_remote_device_info_t *)payload); + } + } break; + + case RSI_BLE_EVENT_AE_ADVERTISING_REPORT: { + if (ble_specific_cb->ble_ae_report_complete_event != NULL) { + ble_specific_cb->ble_ae_report_complete_event(status, (rsi_ble_ae_adv_report_t *)payload); + } + } break; + case RSI_BLE_EVENT_PER_ADV_SYNC_ESTBL: { + if (ble_specific_cb->ble_ae_per_adv_sync_estbl_event != NULL) { + ble_specific_cb->ble_ae_per_adv_sync_estbl_event(status, (rsi_ble_per_adv_sync_estbl_t *)payload); + } + } break; + case RSI_BLE_EVENT_PER_ADV_REPORT: { + if (ble_specific_cb->ble_ae_per_adv_report_event != NULL) { + ble_specific_cb->ble_ae_per_adv_report_event(status, (rsi_ble_per_adv_report_t *)payload); + } + } break; + case RSI_BLE_EVENT_PER_ADV_SYNC_LOST: { + if (ble_specific_cb->ble_ae_per_adv_sync_lost_event != NULL) { + ble_specific_cb->ble_ae_per_adv_sync_lost_event(status, (rsi_ble_per_adv_sync_lost_t *)payload); + } + } break; + case RSI_BLE_EVENT_SCAN_TIMEOUT: { + if (ble_specific_cb->ble_ae_scan_timeout_event != NULL) { + ble_specific_cb->ble_ae_scan_timeout_event(status, (rsi_ble_scan_timeout_t *)payload); + } + } break; + case RSI_BLE_EVENT_ADV_SET_TERMINATED: { + if (ble_specific_cb->ble_ae_adv_set_terminated_event != NULL) { + ble_specific_cb->ble_ae_adv_set_terminated_event(status, (rsi_ble_adv_set_terminated_t *)payload); + } + } break; + case RSI_BLE_EVENT_SCAN_REQ_RECVD: { + if (ble_specific_cb->ble_ae_scan_req_recvd_event != NULL) { + ble_specific_cb->ble_ae_scan_req_recvd_event(status, (rsi_ble_scan_req_recvd_t *)payload); + } + } break; + default: { + } + } + + if (le_cmd_inuse_check) { + uint8_t inx = 0; + uint8_t *remote_dev_bd_addr = (uint8_t *)payload; + for (inx = 0; inx < (RSI_BLE_MAX_NBR_SLAVES + RSI_BLE_MAX_NBR_MASTERS); inx++) { + if (!memcmp(ble_cb->remote_ble_info[inx].remote_dev_bd_addr, remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { + if (ble_cb->remote_ble_info[inx].cmd_in_use) { + if ((rsp_type == RSI_BLE_EVENT_GATT_ERROR_RESPONSE) + || (rsp_type == ble_cb->remote_ble_info[inx].expected_resp)) { + ble_cb->remote_ble_info[inx].cmd_in_use = 0; + ble_cb->remote_ble_info[inx].expected_resp = 0; + } + } + break; + } + } + } +} +/** + * @brief Chip memory status + * @param[in] ble_on_chip_memory_status_event - Memory status + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ +void rsi_ble_on_chip_memory_status_callbacks_register(chip_ble_buffers_stats_handler_t ble_on_chip_memory_status_event) +{ + + SL_PRINTF(SL_RSI_BLE_CHIP_MEMORY_STATUS_CALLBACKS_REGISTER, BLE, LOG_INFO); + // Get ble cb struct pointer + rsi_ble_cb_t *ble_specific_cb = rsi_driver_cb->ble_cb->bt_global_cb->ble_specific_cb; + + // Assign the call backs to the respective call back + ble_specific_cb->ble_on_chip_memory_status_event = ble_on_chip_memory_status_event; +} +#endif +/** + * @brief Form the payload of the BT command packet + * @param[in] cmd_type - Type of the command + * @param[in] cmd_stuct - Pointer of the command structure + * @param[out] pkt - Pointer of the packet to fill the contents of the payload + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +uint16_t rsi_bt_prepare_common_pkt(uint16_t cmd_type, void *cmd_struct, rsi_pkt_t *pkt) +{ + + SL_PRINTF(SL_RSI_BT_PREPARE_COMMON_PACKET_TRIGGER, BLUETOOTH, LOG_INFO, "COMMAND_TYPE: %2x", cmd_type); + uint16_t payload_size = 0; + + switch (cmd_type) { + case RSI_BT_SET_LOCAL_NAME: { + payload_size = sizeof(rsi_bt_req_set_local_name_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_SET_LOCAL_COD: { + payload_size = sizeof(rsi_bt_req_set_local_cod_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_SET_BD_ADDR_REQ: { + rsi_bt_cb_t *bt_cb = rsi_driver_cb->bt_common_cb; + if (bt_cb->state == RSI_BT_STATE_OPERMODE_DONE) { + bt_cb->state = RSI_BT_STATE_NONE; + payload_size = sizeof(rsi_bt_set_local_bd_addr_t); + memcpy(pkt->data, cmd_struct, payload_size); + } + } break; + + case RSI_BT_GET_RSSI: { + payload_size = sizeof(rsi_bt_get_rssi_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_GET_LOCAL_DEV_ADDR: + case RSI_BT_GET_LOCAL_NAME: + case RSI_BT_REQ_QUERY_LOCAL_COD: + case RSI_BT_REQ_INIT: + case RSI_BT_REQ_DEINIT: + case RSI_BT_GET_BT_STACK_VERSION: + break; + case RSI_BT_SET_ANTENNA_SELECT: { + payload_size = sizeof(rsi_ble_set_antenna_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_SET_FEATURES_BITMAP: { + payload_size = sizeof(rsi_bt_set_feature_bitmap_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_SET_ANTENNA_TX_POWER_LEVEL: { + payload_size = sizeof(rsi_bt_set_antenna_tx_power_level_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_ONLY_OPER_MODE: { + payload_size = sizeof(rsi_ble_oper_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_REQ_PWRMODE: { + payload_size = sizeof(rsi_ble_power_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_REQ_SOFTRESET: + break; + case RSI_BT_REQ_PER_CMD: { + pkt->data[0] = *(uint8_t *)cmd_struct; + switch (pkt->data[0]) { + case HCI_BT_PER_STATS_CMD_ID: + payload_size = 1; + pkt->data[0] = *(uint8_t *)cmd_struct; + break; +#ifdef RSI_BLE_ENABLE + case HCI_BLE_TRANSMIT_CMD_ID: + payload_size = sizeof(rsi_ble_per_transmit_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + case HCI_BLE_RECEIVE_CMD_ID: + payload_size = sizeof(rsi_ble_per_receive_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; +#endif +#ifdef RSI_BT_ENABLE + case HCI_BT_TRANSMIT_CMD_ID: + payload_size = sizeof(rsi_bt_tx_per_params_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + case HCI_BT_RECEIVE_CMD_ID: + payload_size = sizeof(rsi_bt_rx_per_params_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; +#endif + case HCI_BT_CW_MODE_CMD_ID: + payload_size = sizeof(rsi_bt_per_cw_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + default: { + } + } + } break; + case RSI_BT_VENDOR_SPECIFIC: { + pkt->data[0] = ((uint8_t *)cmd_struct)[0]; + pkt->data[1] = ((uint8_t *)cmd_struct)[1]; + switch ((pkt->data[0] | (pkt->data[1] << 8))) { + case BLE_VENDOR_RF_TYPE_CMD_OPCODE: + payload_size = sizeof(rsi_ble_vendor_rf_type_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + + case BT_VENDOR_AVDTP_STATS_CMD_OPCODE: + payload_size = sizeof(rsi_bt_vendor_avdtp_stats_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + + case BT_VENDOR_MEMORY_STATS_CMD_OPCODE: + payload_size = sizeof(rsi_bt_vendor_memory_stats_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + + case BLE_VENDOR_WHITELIST_USING_ADV_DATA_PAYLOAD: + payload_size = sizeof(rsi_ble_req_whitelist_using_payload_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + case BT_VENDOR_AR_CMD_OPCODE: + payload_size = sizeof(rsi_bt_vendor_ar_cmd_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + case BT_VENDOR_DYNAMIC_PWR_OPCODE: + payload_size = sizeof(rsi_bt_vendor_dynamic_pwr_cmd_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + case BT_VENDOR_AFH_CLASSIFICATION_CMD_OPCODE: + payload_size = sizeof(rsi_bt_vendor_afh_classification_cmd_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + default: + break; + } + } break; + case RSI_BT_REQ_L2CAP_CONNECT: { + payload_size = sizeof(rsi_bt_req_l2cap_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_L2CAP_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_l2cap_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_L2CAP_PROTOCOL_DATA: { + payload_size = sizeof(rsi_bt_req_l2cap_data_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_L2CAP_ERTM_CONFIGURE: { + payload_size = sizeof(rsi_bt_l2cap_ertm_channel_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE: { + payload_size = sizeof(rsi_bt_cmd_update_gain_table_offset_or_maxpower_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + default: + break; + } + + // Return payload_size + return payload_size; +} + +/** @} */ +#ifdef RSI_BT_ENABLE +typedef uint8_t UINT08; +typedef uint16_t UINT16; +//typedef uint32_t UINT32; + +/** @addtogroup DRIVER14 +* @{ +*/ +/** + * @brief Fill the BT Classic command packet payload + * @param[in] cmd_type - Type of the command + * @param[in] cmd_stuct - Pointer of the command structure + * @param[out] pkt - Pointer of the packet to fill the contents of the payload + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +uint16_t rsi_bt_prepare_classic_pkt(uint16_t cmd_type, void *cmd_struct, rsi_pkt_t *pkt) +{ + + SL_PRINTF(SL_RSI_BT_PREPARE_CLASSIC_PKT_TRIGGER, BLUETOOTH, LOG_INFO, "COMMAND_TYPE: %2x", cmd_type); + uint16_t payload_size = 0; + rsi_bt_cb_t *bt_cb = rsi_driver_cb->bt_classic_cb; + rsi_bt_iap_payload_t *iap_data; + switch (cmd_type) { + case RSI_BT_REQ_LINKKEY_REPLY: { + payload_size = sizeof(rsi_bt_req_linkkey_reply_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + } + case RSI_BT_REQ_SET_PROFILE_MODE: { + payload_size = sizeof(rsi_bt_req_profile_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + break; + } + case RSI_BT_REQ_SET_DISCV_MODE: { + payload_size = sizeof(rsi_bt_req_set_discv_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_QUERY_DISCV_MODE: { + break; + } + case RSI_BT_REQ_SET_CONNECTABILITY_MODE: { + payload_size = sizeof(rsi_bt_req_set_connectability_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_QUERY_CONNECTABILITY_MODE: { + break; + } + case RSI_BT_REQ_SET_PAIR_MODE: { + payload_size = sizeof(rsi_bt_req_set_pair_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_QUERY_PAIR_MODE: { + break; + } + case RSI_BT_REQ_REMOTE_NAME_REQUEST: { + payload_size = sizeof(rsi_bt_req_remote_name_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_REMOTE_NAME_REQUEST_CANCEL: { + payload_size = sizeof(rsi_bt_req_remote_name_cancel_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_INQUIRY: { + payload_size = sizeof(rsi_bt_req_inquiry_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_INQUIRY_CANCEL: + break; + case RSI_BT_REQ_BOND: { + payload_size = sizeof(rsi_bt_req_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_BOND_CANCEL: { + payload_size = sizeof(rsi_bt_req_connect_cancel_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_UNBOND: { + payload_size = sizeof(rsi_bt_req_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_USER_CONFIRMATION: { + payload_size = sizeof(rsi_bt_req_user_confirmation_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_PASSKEY_REPLY: { + payload_size = sizeof(rsi_bt_req_passkey_reply_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_PINCODE_REPLY: { + payload_size = sizeof(rsi_bt_req_pincode_reply_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_QUERY_ROLE: { + payload_size = sizeof(rsi_bt_req_query_role_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_SET_ROLE: { + payload_size = sizeof(rsi_bt_req_set_role_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_QUERY_SERVICES: { + payload_size = sizeof(rsi_bt_req_query_services_t); + memcpy(pkt->data, cmd_struct, payload_size); + bt_cb->sync_rsp = 0; + } break; + case RSI_BT_REQ_SEARCH_SERVICE: { + payload_size = sizeof(rsi_bt_req_search_service_t); + memcpy(pkt->data, cmd_struct, payload_size); + bt_cb->sync_rsp = 0; + } break; + case RSI_BT_REQ_SPP_CONNECT: { + payload_size = sizeof(rsi_bt_req_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_SPP_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_IAP_SET_ACCESSORY_INFO: { + payload_size = sizeof(rsi_bt_req_iap_accessory_info_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_IAP_SET_PROTOCOL_TYPE: { + payload_size = sizeof(rsi_bt_req_iap_set_proto_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_IAP_CONN: { + payload_size = sizeof(rsi_bt_req_iap_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_IAP_DISCONN: { + payload_size = sizeof(rsi_bt_req_iap_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_IAP2_CONTROL_SESSION_DATA_TX: { + + iap_data = (rsi_bt_iap_payload_t *)cmd_struct; + payload_size = iap_data->len; + memcpy(pkt->data, iap_data->data, payload_size); + + } break; + + case RSI_BT_REQ_IAP2_RECV_CMD_LIST: + case RSI_BT_REQ_IAP2_SEND_CMD_LIST: { + payload_size = ((rsi_bt_iap_cmds_info_t *)cmd_struct)->len; + + memcpy(pkt->data, ((rsi_bt_iap_cmds_info_t *)cmd_struct)->cmd, payload_size); + + } break; + + case RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_STATE: + case RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_DATA: { + payload_size = ((rsi_bt_iap_File_transfer_info_t *)cmd_struct)->len; + + memcpy(pkt->data, (uint8_t *)cmd_struct + 2, payload_size); + + } break; + + case RSI_BT_REQ_IAP1_IDENTIFICATION: + case RSI_BT_REQ_IAP2_IDENTIFICATION: + case RSI_BT_REQ_IAP1_DEVICE_AUTHENTICATION: + case RSI_BT_REQ_IAP2_INIT_FILE_TRANSFER: + case RSI_BT_REQ_IAP2_DE_INIT_FILE_TRANSFER: + + break; + + case RSI_BT_REQ_SPP_TRANSFER: { + payload_size = sizeof(rsi_bt_req_spp_transfer_t); + payload_size -= (sizeof(((rsi_bt_req_spp_transfer_t *)cmd_struct)->data) + - ((rsi_bt_req_spp_transfer_t *)cmd_struct)->data_length); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_SNIFF_MODE: { + payload_size = sizeof(rsi_bt_req_sniff_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_SNIFF_EXIT_MODE: { + payload_size = sizeof(rsi_bt_req_sniff_exit_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_SNIFF_SUBRATING_MODE: { + payload_size = sizeof(rsi_bt_req_sniff_subrating_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_SET_SSP_MODE: { + payload_size = sizeof(rsi_bt_req_set_ssp_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } + + break; + + case RSI_BT_REQ_ENABLE_AUTH: { + payload_size = sizeof(rsi_bt_cmd_conn_auth_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_ENABLE_ENC: { + payload_size = sizeof(rsi_bt_cmd_conn_enc_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_DEL_LINKKEYS: { + payload_size = sizeof(rsi_bt_cmd_delete_linkkeys_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_LINK_POLICY_CONFIG: { + payload_size = sizeof(rsi_bt_cmd_link_policy_settings_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_SET_EIR: { + payload_size = sizeof(rsi_bt_set_eir_data_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_CW_MODE: { + } break; + case RSI_BT_REQ_A2DP_CONNECT: { + payload_size = sizeof(rsi_bt_req_a2dp_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_A2DP_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_a2dp_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_PCM_MP3_DATA: { + payload_size = sizeof(rsi_bt_req_a2dp_pcm_mp3_data_t); + payload_size -= (sizeof(((rsi_bt_req_a2dp_pcm_mp3_data_t *)cmd_struct)->pcm_mp3_data) + - ((rsi_bt_req_a2dp_pcm_mp3_data_t *)cmd_struct)->pcm_mp3_data_len); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_SBC_AAC_DATA: { + payload_size = sizeof(rsi_bt_req_a2dp_sbc_aac_data_t); + payload_size -= (sizeof(((rsi_bt_req_a2dp_sbc_aac_data_t *)cmd_struct)->sbc_aac_data) + - ((rsi_bt_req_a2dp_sbc_aac_data_t *)cmd_struct)->sbc_aac_data_len); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_CLOSE: { + payload_size = sizeof(rsi_bt_req_a2dp_close_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_ABORT: { + payload_size = sizeof(rsi_bt_req_a2dp_abort_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_START: { + payload_size = sizeof(rsi_bt_req_a2dp_start_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_SUSPEND: { + payload_size = sizeof(rsi_bt_req_a2dp_suspend_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_CONNECT: { + payload_size = sizeof(rsi_bt_req_avrcp_conn_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_avrcp_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_PLAY: { + payload_size = sizeof(rsi_bt_req_avrcp_play_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_PAUSE: { + payload_size = sizeof(rsi_bt_req_avrcp_pause_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_STOP: { + payload_size = sizeof(rsi_bt_req_avrcp_stop_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_NEXT: { + payload_size = sizeof(rsi_bt_req_avrcp_next_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_PREVIOUS: { + payload_size = sizeof(rsi_bt_req_avrcp_previous_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_VOL_UP: { + payload_size = sizeof(rsi_bt_req_avrcp_vol_up_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_VOL_DOWN: { + payload_size = sizeof(rsi_bt_req_avrcp_vol_down_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_HFP_CONNECT: { + payload_size = sizeof(rsi_bt_req_hfp_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_hfp_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_PHONEOPERATOR: { + payload_size = sizeof(rsi_bt_req_hfp_phoneoperator_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_DIALNUM: { + payload_size = sizeof(rsi_bt_req_hfp_dialnum_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_DIALMEM: { + payload_size = sizeof(rsi_bt_req_hfp_dialmem_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_SPKGAIN: { + payload_size = sizeof(rsi_bt_req_hfp_spkgain_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_MICGAIN: { + payload_size = sizeof(rsi_bt_req_hfp_micgain_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_AUDIOTRANSFER: { + payload_size = sizeof(rsi_bt_req_hfp_audiotransfer_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HFP_AUDIODATA: { + bt_cb->sync_rsp = 0; + payload_size = sizeof(rsi_bt_req_hfp_audio_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_PBAP_CONNECT: { + payload_size = sizeof(rsi_bt_req_pbap_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_PBAP_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_pbap_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_PBAP_CONTACTS: { + payload_size = sizeof(rsi_bt_req_pbap_contacts_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_SET_AFH_HOST_CHANNEL_CLASSIFICATION: { + payload_size = sizeof(rsi_bt_req_set_afh_host_channel_classification_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_CAPABILITES: { + payload_size = sizeof(rsi_bt_req_avrcp_get_capabilities_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_GET_ATTS_LIST: { + payload_size = sizeof(rsi_bt_req_avrcp_get_att_list_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_GET_ATT_VALS_LIST: { + payload_size = sizeof(rsi_bt_req_avrcp_get_att_vals_list_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_GET_CUR_ATT_VAL: { + payload_size = sizeof(rsi_bt_req_avrcp_get_cur_att_val_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_SET_CUR_ATT_VAL: { + payload_size = sizeof(rsi_bt_req_avrcp_set_cur_att_val_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_GET_ELEMENT_ATT: { + payload_size = sizeof(rsi_bt_req_avrcp_get_ele_att_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_GET_PLAY_STATUS: { + payload_size = sizeof(rsi_bt_req_avrcp_get_player_status_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_REG_NOTIFICATION: { + payload_size = sizeof(rsi_bt_req_avrcp_reg_notification_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_REMOTE_VERSION: { + payload_size = sizeof(rsi_bt_req_avrcp_remote_version_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_ATT_TEXT: { + payload_size = sizeof(rsi_bt_req_avrcp_get_cur_att_val_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_ATT_VALS_TEXT: { + payload_size = sizeof(rsi_bt_req_avrcp_get_att_val_text_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_BATTERY_STATUS: { + payload_size = sizeof(rsi_bt_req_avrcp_batt_status_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_CHAR_SETS: { + payload_size = sizeof(rsi_bt_avrcp_cap_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_SET_ABS_VOL: { + payload_size = sizeof(rsi_bt_avrcp_set_abs_vol_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_SET_ADDR_PLAYER_RESP: { + payload_size = sizeof(rsi_bt_avrcp_set_addr_player_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_FOLDER_ITEMS_RESP: { + payload_size = sizeof(rsi_bt_avrcp_get_folder_items_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_TOT_NUM_ITEMS_RESP: { + payload_size = sizeof(rsi_bt_avrcp_get_tot_num_items_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_AVRCP_GET_CAPABILITES_RESP: { + payload_size = sizeof(rsi_bt_req_avrcp_char_sets_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_ATTS_LIST_RESP: { + payload_size = sizeof(rsi_bt_avrcp_att_list_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_ATT_VALS_LIST_RESP: { + payload_size = sizeof(rsi_bt_avrcp_att_vals_list_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_CUR_ATT_VAL_RESP: { + payload_size = sizeof(rsi_bt_avrcp_cur_att_vals_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_SET_CUR_ATT_VAL_RESP: { + payload_size = sizeof(rsi_bt_avrcp_set_att_vals_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_GET_ELEMENT_ATT_RESP: { + // payload_size = sizeof(rsi_bt_avrcp_elem_attr_resp_t); + // memcpy(pkt->data, cmd_struct, payload_size); + uint16_t data_idx = 0; + uint8_t ix = 0; + rsi_bt_avrcp_elem_attr_resp_t *elem_attr = cmd_struct; + + memcpy(pkt->data, elem_attr, 9); + data_idx += 9; + for (ix = 0; ix < elem_attr->elem_attr_list.num_attrs; ix++) { + uint16_t tmp_len = 0; + tmp_len = elem_attr->elem_attr_list.attr_list[ix].attr_len; + BT_MEM_WR_BE_32U(pkt->data + data_idx, elem_attr->elem_attr_list.attr_list[ix].id); + data_idx += 4; + BT_MEM_WR_BE_16U(pkt->data + data_idx, elem_attr->elem_attr_list.attr_list[ix].char_set_id); + data_idx += 2; + BT_MEM_WR_BE_16U(pkt->data + data_idx, tmp_len); + data_idx += 2; + memcpy(pkt->data + data_idx, elem_attr->elem_attr_list.attr_list[ix].attr_val, tmp_len); + data_idx += tmp_len; + } + payload_size = data_idx; + } break; + + case RSI_BT_REQ_AVRCP_GET_PLAY_STATUS_RESP: { + payload_size = sizeof(rsi_bt_avrcp_play_status_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_REG_NOTIFICATION_RESP: { + payload_size = sizeof(rsi_bt_avrcp_reg_notify_interim_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_ATT_TEXT_RESP: { + payload_size = sizeof(rsi_bt_avrcp_att_text_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_ATT_VALS_TEXT_RESP: { + payload_size = sizeof(rsi_bt_avrcp_att_text_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_BATTERY_STATUS_RESP: { + payload_size = sizeof(rsi_bt_avrcp_reg_notify_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_CHAR_SETS_RESP: { + payload_size = sizeof(rsi_bt_avrcp_reg_notify_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_NOTIFICATION: { + payload_size = sizeof(rsi_bt_avrcp_notify_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_CMD_REJECT: { + payload_size = sizeof(rsi_bt_avrcp_cmd_reject_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_AVRCP_SET_ABS_VOL_RESP: { + payload_size = sizeof(rsi_bt_avrcp_set_abs_vol_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_ENABLE_DEVICE_UNDER_TESTMODE: + break; + + case RSI_BT_REQ_CHANGE_CONNECTION_PKT_TYPE: { + payload_size = sizeof(rsi_bt_ptt_pkt_type_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_BR_EDR_LP_HP_TRANSISTION: { + payload_size = sizeof(rsi_bt_ptt_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_GET_CONFIG: { + payload_size = sizeof(rsi_bt_req_a2dp_get_config_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_A2DP_SET_CONFIG: { + payload_size = sizeof(rsi_bt_req_a2dp_set_config_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_ADD_DEVICE_ID: { + payload_size = sizeof(rsi_bt_req_add_device_id_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_SET_CURRENT_IAC_LAP: { + payload_size = sizeof(rsi_bt_req_set_current_iap_lap_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HID_CONNECT: + case RSI_BT_REQ_HID_DISCONNECT: { + payload_size = sizeof(rsi_bt_req_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HID_PROFILE_DATA: { + rsi_bt_hid_profile_data_t *hid_profile_data = (rsi_bt_hid_profile_data_t *)cmd_struct; + payload_size = + (sizeof(rsi_bt_hid_profile_data_t) - (MAX_PROFILE_DATA_BUFFER_LEN) + (*(uint16_t *)&hid_profile_data->len[0])); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_HID_SDP_ATT_INIT: { + payload_size = sizeof(rsi_sdp_att_record_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BT_REQ_GATT_CONNECT: { + payload_size = sizeof(rsi_bt_req_gatt_connect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1: { + payload_size = sizeof(rsi_bt_req_a2dp_pcm_mp3_data_t); + payload_size -= (sizeof(((rsi_bt_req_a2dp_pcm_mp3_data_t *)cmd_struct)->pcm_mp3_data) + - ((rsi_bt_req_a2dp_pcm_mp3_data_t *)cmd_struct)->pcm_mp3_data_len); + memcpy(pkt->data, cmd_struct, payload_size); + bt_cb->sync_rsp = 0; + } break; + + default: + break; + } + + // return payload_size + return payload_size; +} +#endif + +#ifdef RSI_BLE_ENABLE +/** + * @brief Form the payload of the BT Classic command packet. + * @param[in] cmd_type - Type of the command + * @param[in] cmd_stuct - Pointer of the command structure + * @param[out] pkt - Pointer of the packet to fill the contents of the payload + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +uint16_t rsi_bt_prepare_le_pkt(uint16_t cmd_type, void *cmd_struct, rsi_pkt_t *pkt) +{ + + SL_PRINTF(SL_RSI_BT_PREPARE_LE_PKT_TRIGGER, BLUETOOTH, LOG_INFO, "COMMAND_TYPE: %2x", cmd_type); + uint16_t payload_size = 0; + uint8_t le_buf_check = 0; + uint8_t le_cmd_inuse_check = 0; + uint8_t le_buf_in_use_check = 0; + uint8_t le_buf_config_check = 0; + uint16_t expected_resp = 0; + uint8_t is_it_legacy_cmd = 0; + rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; + + switch (cmd_type) { + case RSI_BLE_REQ_ADV: { + payload_size = sizeof(rsi_ble_req_adv_t); + memcpy(pkt->data, cmd_struct, payload_size); + is_it_legacy_cmd = 1; + } break; + case RSI_BLE_SET_ADVERTISE_DATA: { + payload_size = sizeof(rsi_ble_req_adv_data_t); + memcpy(pkt->data, cmd_struct, payload_size); + is_it_legacy_cmd = 1; + } break; + case RSI_BLE_SET_SCAN_RESPONSE_DATA: { + payload_size = sizeof(rsi_ble_req_scanrsp_data_t); + memcpy(pkt->data, cmd_struct, payload_size); + is_it_legacy_cmd = 1; + } break; + case RSI_BLE_REQ_SCAN: { + payload_size = sizeof(rsi_ble_req_scan_t); + memcpy(pkt->data, cmd_struct, payload_size); + is_it_legacy_cmd = 1; + } break; + case RSI_BLE_REQ_CONN: { + payload_size = sizeof(rsi_ble_req_conn_t); + memcpy(pkt->data, cmd_struct, payload_size); + is_it_legacy_cmd = 1; + } break; + + case RSI_BLE_REQ_CONN_ENHANCE: { + payload_size = sizeof(rsi_ble_req_enhance_conn_t); + memcpy(pkt->data, cmd_struct, payload_size); + is_it_legacy_cmd = 1; + } break; + + case RSI_BLE_CMD_CONN_PARAMS_UPDATE: { + payload_size = sizeof(rsi_ble_cmd_conn_params_update_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_REQ_DISCONNECT: { + payload_size = sizeof(rsi_ble_req_disconnect_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_REQ_START_ENCRYPTION: { + payload_size = sizeof(rsi_ble_strat_encryption_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_REQ_SMP_PAIR: { + payload_size = sizeof(rsi_ble_req_smp_pair_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_SMP_PAIR_RESPONSE: { + payload_size = sizeof(rsi_ble_smp_response_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_SMP_PASSKEY: { + payload_size = sizeof(rsi_ble_smp_passkey_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_REQ_SMP_PAIRING_FAILED: { + payload_size = sizeof(rsi_ble_req_smp_pair_failed_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + //GATT cases + case RSI_BLE_REQ_PROFILES: { + payload_size = sizeof(rsi_ble_req_profiles_list_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_PROFILE: { + payload_size = sizeof(rsi_ble_req_profile_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_CHAR_SERVICES: { + payload_size = sizeof(rsi_ble_req_char_services_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_INC_SERVICES: { + payload_size = sizeof(rsi_ble_req_inc_services_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_READ_BY_UUID: { + payload_size = sizeof(rsi_ble_req_char_val_by_uuid_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_DESC: { + payload_size = sizeof(rsi_ble_req_att_descs_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_READ_VAL: { + payload_size = sizeof(rsi_ble_req_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_MULTIPLE_READ: { + payload_size = sizeof(rsi_ble_req_multi_att_values_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_LONG_READ: { + payload_size = sizeof(rsi_ble_req_long_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_WRITE: { + payload_size = sizeof(rsi_ble_set_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_WRITE_NO_ACK: { + payload_size = sizeof(rsi_ble_set_att_cmd_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_buf_check = 1; + } break; + + case RSI_BLE_REQ_LONG_WRITE: { + payload_size = sizeof(rsi_ble_set_long_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_PREPARE_WRITE: { + payload_size = sizeof(rsi_ble_req_prepare_write_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + + case RSI_BLE_REQ_EXECUTE_WRITE: { + payload_size = sizeof(rsi_ble_req_execute_write_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + case RSI_BLE_ADD_SERVICE: { + payload_size = sizeof(rsi_ble_req_add_serv_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_ADD_ATTRIBUTE: { + payload_size = sizeof(rsi_ble_req_add_att_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_SET_LOCAL_ATT_VALUE: { + payload_size = sizeof(rsi_ble_set_local_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_CMD_SET_WWO_RESP_NOTIFY_BUF_INFO: { + payload_size = sizeof(rsi_ble_set_wo_resp_notify_buf_info_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_buf_in_use_check = 1; + le_buf_config_check = 1; + } break; + case RSI_BLE_CMD_NOTIFY: { + payload_size = sizeof(rsi_ble_notify_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_buf_check = 1; + } break; + case RSI_BLE_CMD_INDICATE: { + payload_size = sizeof(rsi_ble_notify_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_INDICATE_CONFIRMATION; + } break; + case RSI_BLE_CMD_INDICATE_CONFIRMATION: { + payload_size = sizeof(rsi_ble_indicate_confirm_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_GET_LOCAL_ATT_VALUE: { + payload_size = sizeof(rsi_ble_get_local_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_GET_LE_PING: { + payload_size = sizeof(rsi_ble_get_le_ping_timeout_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_SET_LE_PING: { + payload_size = sizeof(rsi_ble_set_le_ping_timeout_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_ENCRYPT: { + payload_size = sizeof(rsi_ble_encrypt_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_SET_RANDOM_ADDRESS: { + uint8_t dummy_rand_addr[6] = { 0 }; + rsi_ble_req_rand_t *rsi_ble_rand = (rsi_ble_req_rand_t *)pkt->data; + memcpy(rsi_ble_rand, cmd_struct, sizeof(rsi_ble_req_rand_t)); + if (memcmp(rsi_ble_rand->rand_addr, dummy_rand_addr, 6) == 0) { + rsi_ascii_dev_address_to_6bytes_rev(rsi_ble_rand->rand_addr, (int8_t *)RSI_BLE_SET_RAND_ADDR); + } + // fill payload size + payload_size = sizeof(rsi_ble_req_rand_t); + } break; + + case RSI_BLE_CMD_READ_RESP: { + payload_size = sizeof(rsi_ble_gatt_read_response_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_LE_WHITE_LIST: { + payload_size = sizeof(rsi_ble_white_list_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_RSP_REMOVE_SERVICE: { + payload_size = sizeof(rsi_ble_gatt_remove_serv_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_RSP_REMOVE_ATTRIBUTE: { + payload_size = sizeof(rsi_ble_gatt_remove_att_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_PROCESS_RESOLV_LIST: { + payload_size = sizeof(rsi_ble_resolvlist_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_GET_RESOLVING_LIST_SIZE: + break; + + case RSI_BLE_SET_ADDRESS_RESOLUTION_ENABLE: { + payload_size = sizeof(rsi_ble_set_addr_resolution_enable_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_SET_PRIVACY_MODE: { + payload_size = sizeof(rsi_ble_set_privacy_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_REQ_READ_PHY: { + payload_size = sizeof(rsi_ble_req_read_phy_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_REQ_SET_PHY: { + payload_size = sizeof(rsi_ble_set_phy_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_SET_DATA_LEN: { + payload_size = sizeof(rsi_ble_setdatalength_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CBFC_CONN_REQ: { + payload_size = sizeof(rsi_ble_cbfc_conn_req_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CBFC_CONN_RESP: { + payload_size = sizeof(rsi_ble_cbfc_conn_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CBFC_TX_DATA: { + payload_size = sizeof(rsi_ble_cbfc_data_tx_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CBFC_DISCONN: { + payload_size = sizeof(rsi_ble_cbfc_disconn_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CMD_ATT_ERROR: { + payload_size = sizeof(rsi_ble_att_error_response_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_LE_LTK_REQ_REPLY: { + payload_size = sizeof(rsi_ble_set_le_ltkreqreply_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_RX_TEST_MODE: { + payload_size = sizeof(rsi_ble_rx_test_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_TX_TEST_MODE: { + payload_size = sizeof(rsi_ble_tx_test_mode_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_REQ_PROFILES_ASYNC: { + payload_size = sizeof(rsi_ble_req_profiles_list_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_LIST; + } break; + + case RSI_BLE_REQ_PROFILE_ASYNC: { + payload_size = sizeof(rsi_ble_req_profile_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_BY_UUID; + } break; + case RSI_BLE_GET_CHARSERVICES_ASYNC: { + payload_size = sizeof(rsi_ble_req_char_services_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_READ_CHAR_SERVS; + } break; + + case RSI_BLE_GET_INCLUDESERVICES_ASYNC: { + payload_size = sizeof(rsi_ble_req_inc_services_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_READ_INC_SERVS; + } break; + + case RSI_BLE_READCHARVALUEBYUUID_ASYNC: { + payload_size = sizeof(rsi_ble_req_char_val_by_uuid_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_READ_VAL_BY_UUID; + } break; + + case RSI_BLE_GET_ATTRIBUTE_ASYNC: { + payload_size = sizeof(rsi_ble_req_att_descs_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_DESC_VAL_RESPONSE; + } break; + + case RSI_BLE_GET_DESCRIPTORVALUE_ASYNC: { + payload_size = sizeof(rsi_ble_req_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_READ_RESP; + } break; + + case RSI_BLE_GET_MULTIPLEVALUES_ASYNC: { + payload_size = sizeof(rsi_ble_req_multi_att_values_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_READ_MULTIPLE_RESP; + } break; + + case RSI_BLE_GET_LONGDESCVALUES_ASYNC: { + payload_size = sizeof(rsi_ble_req_long_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_READ_BLOB_RESP; + } break; + case RSI_BLE_SET_DESCVALUE_ASYNC: { + payload_size = sizeof(rsi_ble_set_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_WRITE_RESP; + } break; + case RSI_BLE_SET_PREPAREWRITE_ASYNC: { + payload_size = sizeof(rsi_ble_req_prepare_write_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_PREPARE_WRITE_RESP; + } break; + case RSI_BLE_EXECUTE_LONGDESCWRITE_ASYNC: { + payload_size = sizeof(rsi_ble_req_execute_write_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_GATT_EXECUTE_WRITE_RESP; + } break; + case RSI_BLE_SET_SMP_PAIRING_CAPABILITY_DATA: { + payload_size = sizeof(rsi_ble_set_smp_pairing_capabilty_data_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_CONN_PARAM_RESP_CMD: { + payload_size = sizeof(rsi_ble_cmd_conn_param_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_END_TEST_MODE: + break; + case RSI_BLE_MTU_EXCHANGE_REQUEST: { + payload_size = sizeof(rsi_ble_mtu_exchange_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cmd_inuse_check = 1; + expected_resp = RSI_BLE_EVENT_MTU; + } break; + case RSI_BLE_CMD_MTU_EXCHANGE_RESP: { + payload_size = sizeof(rsi_ble_mtu_exchange_resp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_CMD_WRITE_RESP: { + payload_size = sizeof(rsi_ble_gatt_write_response_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CMD_PREPARE_WRITE_RESP: { + payload_size = sizeof(rsi_ble_gatt_prepare_write_response_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + case RSI_BLE_CMD_SET_LOCAL_IRK: { + payload_size = sizeof(rsi_ble_set_local_irk_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_CMD_SET_BLE_TX_POWER: { + payload_size = sizeof(rsi_ble_set_ble_tx_power_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + case RSI_BLE_CMD_INDICATE_SYNC: { + payload_size = sizeof(rsi_ble_notify_att_value_t); + memcpy(pkt->data, cmd_struct, payload_size); + le_cb->sync_rsp = 0; + } break; + case RSI_BLE_CMD_SET_PROP_PROTOCOL_BLE_BANDEDGE_TXPOWER: { + payload_size = sizeof(rsi_ble_set_prop_protocol_ble_bandedge_tx_power_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + //AE ENABLE + case RSI_BLE_CMD_AE: { + payload_size = sizeof(rsi_ble_ae_pdu_t); + memcpy(pkt->data, cmd_struct, payload_size); + + if (le_cb->state & RSI_BLE_LEGACY_CMD_USED) { + le_cb->state |= RSI_BLE_CHECK_CMD; + } else { + le_cb->state |= RSI_BLE_ADV_EXT_CMD_USED; + } + } break; + + case RSI_BLE_CMD_READ_TRANSMIT_POWER: { + // No TX payload + } break; + + case RSI_BLE_CMD_READ_RF_PATH_COMP: { + // No Tx Payload + } break; + + case RSI_BLE_CMD_WRITE_RF_PATH_COMP: { + payload_size = sizeof(rsi_ble_write_rf_path_comp_t); + memcpy(pkt->data, cmd_struct, payload_size); + } break; + + default: + break; + } + + if (le_buf_check || le_cmd_inuse_check || le_buf_in_use_check) { + uint8_t inx = 0; + uint8_t *remote_dev_bd_addr = (uint8_t *)cmd_struct; + for (inx = 0; inx < (RSI_BLE_MAX_NBR_SLAVES + RSI_BLE_MAX_NBR_MASTERS); inx++) { + if (!memcmp(le_cb->remote_ble_info[inx].remote_dev_bd_addr, remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { + + /* ERROR PRONE : Do not changes if else checks order */ + if (le_buf_config_check) { + rsi_mutex_lock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + if ((le_cb->remote_ble_info[inx].avail_buf_cnt) != (le_cb->remote_ble_info[inx].max_buf_cnt)) { + le_cb->buf_status = 2; //return error based on the status + rsi_mutex_unlock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + break; + } + rsi_mutex_unlock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + } + + if (le_buf_in_use_check) { + le_cb->remote_ble_index = inx; + le_buf_in_use_check = RSI_FALSE; + break; + } else if (le_buf_check) { + rsi_mutex_lock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + if (le_cb->remote_ble_info[inx].avail_buf_cnt == 0) { + le_cb->buf_status = SI_LE_BUFFER_FULL; + rsi_mutex_unlock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + break; + } else { + le_cb->buf_status = SI_LE_BUFFER_AVL; + le_cb->remote_ble_info[inx].avail_buf_cnt -= 1; + rsi_mutex_unlock(&(le_cb->remote_ble_info[inx].ble_buff_mutex)); + break; + } + } else if (le_cmd_inuse_check) { + if (le_cb->remote_ble_info[inx].cmd_in_use) { + le_cb->cmd_status = RSI_TRUE; + } else { + le_cb->cmd_status = RSI_FALSE; + le_cb->remote_ble_info[inx].cmd_in_use = RSI_TRUE; + le_cb->remote_ble_info[inx].expected_resp = expected_resp; + } + } + break; + } + } + } + + if (is_it_legacy_cmd) { + if (le_cb->state & RSI_BLE_ADV_EXT_CMD_USED) { + le_cb->state |= RSI_BLE_CHECK_CMD; //bt_cb->state + } else { + le_cb->state |= RSI_BLE_LEGACY_CMD_USED; //bt_cb->state + } + } + // Return payload_size + return payload_size; +} +#endif +/** + * @brief Fill commands and places into Bt TX queue + * @param[in] cmd - Type of the command to send + * @param[in] cmd_stuct - Pointer of the packet structure to send + * @param[in] resp - Pointer of the packet to fill the contents of the payload + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +int32_t rsi_bt_driver_send_cmd(uint16_t cmd, void *cmd_struct, void *resp) +{ + + SL_PRINTF(SL_RSI_BT_SEND_CMD_TRIGGER, BLUETOOTH, LOG_INFO, "COMMAND: %2x", cmd); + uint16_t payload_size = 0; + uint16_t protocol_type = 0; + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + uint8_t *host_desc = NULL; + rsi_bt_cb_t *bt_cb = NULL; + uint32_t calculate_timeout_ms = 0; + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + + SL_PRINTF(SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE, BLUETOOTH, LOG_ERROR, "COMMAND: %2x", cmd); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + protocol_type = rsi_bt_get_proto_type(cmd, &bt_cb); + + SL_PRINTF(SL_RSI_BT_SEND_CMD_PROTOCOL_TYPE, BLUETOOTH, LOG_INFO, "PROTOCOL_TYPE: %2x", protocol_type); + if (protocol_type == 0xFF) { + // Return packet allocation failure error + SL_PRINTF(SL_RSI_ERROR_PACKET_ALLOCATION_FAILURE, + BLUETOOTH, + LOG_ERROR, + "COMMAND: %2x , PROTOCOL_TYPE: %2x", + protocol_type, + cmd); + + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if ((cmd == RSI_BT_SET_BD_ADDR_REQ) && (rsi_driver_cb->bt_common_cb->state != RSI_BT_STATE_OPERMODE_DONE)) { + SL_PRINTF(SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE, BLUETOOTH, LOG_ERROR, "COMMAND: %2x", cmd); + + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // Get timeout based on cmd + calculate_timeout_ms = rsi_bt_get_timeout(cmd, protocol_type); + rsi_bt_set_wait_bitmap(protocol_type, BT_CMD_SEM); + if (rsi_semaphore_wait(&bt_cb->bt_cmd_sem, calculate_timeout_ms) != RSI_ERROR_NONE) { + // LOG_PRINT("%s: Command ID:0x%x Command timed-out with:%d\n",__func__, cmd, calculate_timeout_ms); + SL_PRINTF(SL_RSI_ERROR_BT_BLE_CMD_IN_PROGRESS, + BLUETOOTH, + LOG_ERROR, + "COMMAND: %2x, Calculate_timeout_ms: %4x", + cmd, + calculate_timeout_ms); + + return RSI_ERROR_BT_BLE_CMD_IN_PROGRESS; + } + +#ifdef BT_STACK_IN_HOST + // If allocation of packet fails + if (!bt_stack_buf_avail) { + rsi_bt_clear_wait_bitmap(protocol_type, BT_CMD_SEM); + rsi_semaphore_post(&bt_cb->bt_cmd_sem); + + // Return packet allocation failure error + + SL_PRINTF(SL_RSI_ERROR_PKT_ALLOCATION_FAILURE, BLUETOOTH, LOG_ERROR, "COMMAND: %2x", cmd); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#endif + + // Allocate command buffer from ble pool + pkt = rsi_pkt_alloc(&bt_cb->bt_tx_pool); + + // Get host descriptor pointer + host_desc = (pkt->desc); + + // If allocation of packet fails + if (pkt == NULL) { + rsi_bt_clear_wait_bitmap(protocol_type, BT_CMD_SEM); + rsi_semaphore_post(&bt_cb->bt_cmd_sem); + + // Return packet allocation failure error + SL_PRINTF(SL_RSI_ERROR_PKT_ALLOCATION_FAILURE, BLUETOOTH, LOG_ERROR, "COMMAND: %2x", cmd); + + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset host descriptor + memset(host_desc, 0, RSI_HOST_DESC_LENGTH); + + bt_cb->sync_rsp = 1; + + payload_size = 0; + + if (protocol_type == RSI_PROTO_BT_COMMON) { + // Memset data + memset(pkt->data, 0, (RSI_BT_COMMON_CMD_LEN - sizeof(rsi_pkt_t))); + payload_size = rsi_bt_prepare_common_pkt(cmd, cmd_struct, pkt); + } +#ifdef RSI_BT_ENABLE + else if (protocol_type == RSI_PROTO_BT_CLASSIC) { + // Memset data + memset(pkt->data, 0, (RSI_BT_CLASSIC_CMD_LEN - sizeof(rsi_pkt_t))); + payload_size = rsi_bt_prepare_classic_pkt(cmd, cmd_struct, pkt); + } +#endif +#ifdef RSI_BLE_ENABLE + else if (protocol_type == RSI_PROTO_BLE) { + // Memset data + memset(pkt->data, 0, (RSI_BLE_CMD_LEN - sizeof(rsi_pkt_t))); + payload_size = rsi_bt_prepare_le_pkt(cmd, cmd_struct, pkt); + if (cmd == RSI_BLE_REQ_CONN_ENHANCE) { + cmd = RSI_BLE_REQ_CONN; + } + } +#endif + + if (bt_cb->buf_status || bt_cb->cmd_status || (bt_cb->state & RSI_BLE_CHECK_CMD)) { + rsi_pkt_free(&bt_cb->bt_tx_pool, pkt); + + if (bt_cb->buf_status == SI_LE_BUFFER_IN_PROGRESS) { + status = RSI_ERROR_BLE_DEV_BUF_IS_IN_PROGRESS; + } else if (bt_cb->buf_status == SI_LE_BUFFER_FULL) { + status = RSI_ERROR_BLE_DEV_BUF_FULL; + } else if (bt_cb->cmd_status) { + status = RSI_ERROR_BLE_ATT_CMD_IN_PROGRESS; + } + + if (bt_cb->state & RSI_BLE_CHECK_CMD) { + if (bt_cb->state & RSI_BLE_LEGACY_CMD_USED) { + status = RSI_ERROR_BLE_ADV_EXT_COMMAND_NOT_ALLOWED; + } else if (bt_cb->state & RSI_BLE_ADV_EXT_CMD_USED) { + status = RSI_ERROR_BLE_LEGACY_COMMAND_NOT_ALLOWED; + } + } + + bt_cb->buf_status = SI_LE_BUFFER_AVL; + bt_cb->cmd_status = 0; + rsi_bt_clear_wait_bitmap(protocol_type, BT_CMD_SEM); + rsi_semaphore_post(&bt_cb->bt_cmd_sem); + SL_PRINTF(SL_RSI_BLE_ERROR, BLUETOOTH, LOG_ERROR, "Status: %4x", status); + + return status; + } + // Fill payload length + rsi_uint16_to_2bytes(host_desc, (payload_size & 0xFFF)); + + // Fill frame type + host_desc[1] |= (RSI_BT_Q << 4); + + // Fill frame type + rsi_uint16_to_2bytes(&host_desc[2], cmd); + + // Save expected response type + bt_cb->expected_response_type = cmd; + + // Save expected response type + bt_cb->expected_response_buffer = resp; + +#ifdef SAPIS_BT_STACK_ON_HOST + send_cmd_from_app_to_bt_stack(host_desc, pkt->data, payload_size); +#else + // Enqueue packet to BT TX queue + rsi_enqueue_pkt(&rsi_driver_cb->bt_single_tx_q, pkt); + + // Set TX packet pending event + rsi_set_event(RSI_TX_EVENT); +#endif + + if (cmd == RSI_BLE_ONLY_OPER_MODE) { + // Save expected response type + bt_cb->expected_response_type = RSI_BT_EVENT_CARD_READY; + bt_cb->sync_rsp = 1; + } + + rsi_bt_set_wait_bitmap(protocol_type, BT_SEM); + if (rsi_semaphore_wait(&bt_cb->bt_sem, calculate_timeout_ms) != RSI_ERROR_NONE) { + rsi_bt_set_status(bt_cb, RSI_ERROR_RESPONSE_TIMEOUT); + SL_PRINTF(SL_RSI_SEMAPHORE_TIMEOUT, + BLUETOOTH, + LOG_ERROR, + " Command: %2x , Calculate_timeout_ms: %4x", + cmd, + calculate_timeout_ms); + +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + if (rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb != NULL) { + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb(RSI_ERROR_RESPONSE_TIMEOUT, BT_CMD); + } +#endif + //LOG_PRINT("%s: Command ID:0x%x response timed-out with:%d\n",__func__, cmd, calculate_timeout_ms); + } + // Get command response status + status = rsi_bt_get_status(bt_cb); + + SL_PRINTF(SL_RSI_BT_COMMAND_RESPONSE_STATUS, BLUETOOTH, LOG_INFO, "STATUS: %4x", status); + // Clear sync rsp variable + bt_cb->sync_rsp = 0; + + rsi_bt_clear_wait_bitmap(protocol_type, BT_CMD_SEM); + // Post the semaphore which is waiting on driver_send API + rsi_semaphore_post(&bt_cb->bt_cmd_sem); + + // Return status + return status; +} + +#ifndef SAPIS_BT_STACK_ON_HOST +//Start BT-BLE Stack +/** + * @brief Initialize bt stack + * @param[in] mode - Mode + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +int32_t intialize_bt_stack(uint8_t mode) +{ + SL_PRINTF(SL_RSI_INIT_BT_STACK, BLUETOOTH, LOG_INFO, "MODE: %1x", mode); + // This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(mode); + // Dummy Function + return 0; +} +/** @} */ +#endif + +#endif + +/*==============================================*/ diff --git a/wiseconnect/sapi/driver/rsi_common.c b/wiseconnect/sapi/driver/rsi_common.c new file mode 100644 index 00000000..fcb9fab5 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_common.c @@ -0,0 +1,1827 @@ +/******************************************************************************* +* @file rsi_common.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_hal.h" +#ifdef RSI_M4_INTERFACE +#include "rsi_m4.h" +#endif +#include "rsi_wlan_non_rom.h" +#ifdef RSI_BLE_ENABLE +#include "rsi_ble_common_config.h" +#endif +#ifdef RSI_BT_ENABLE +#include "rsi_bt_common_config.h" +#endif + +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; +extern rsi_socket_select_info_t *rsi_socket_select_info; +/** @addtogroup DRIVER5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int8_t rsi_common_cb_init(rsi_common_cb_t *common_cb) + * @brief Initialize common control block structure + * @param[in] common_cb - pointer to common cb structure + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int8_t rsi_common_cb_init(rsi_common_cb_t *common_cb) +{ + int8_t retval = RSI_ERR_NONE; + + // validate input parameter + if (common_cb == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + + // Initialize common state + common_cb->state = RSI_COMMON_STATE_NONE; + + // Initializes common status + common_cb->status = RSI_SUCCESS; + + // Creates common mutex + rsi_mutex_create(&common_cb->common_mutex); + + // Creates tx mutex + rsi_mutex_create(&rsi_driver_cb_non_rom->tx_mutex); + +#if defined(RSI_DEBUG_PRINTS) || defined(FW_LOGGING_ENABLE) + // Creates debug prints mutex + rsi_mutex_create(&rsi_driver_cb_non_rom->debug_prints_mutex); +#endif + // Creates common cmd mutex + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->common_cmd_send_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_send_sem); + + // Set expected_response to zero + common_cb->expected_response = RSI_COMMON_RSP_CLEAR; + + retval = rsi_semaphore_create(&common_cb->common_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->common_cmd_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } +#ifdef RSI_WITH_OS + retval = rsi_semaphore_create(&common_cb->common_card_ready_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } +#endif +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD + retval = rsi_semaphore_create(&common_cb->wakeup_gpio_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } +#endif + return retval; +} +/*==============================================*/ +/** + * @fn int32_t rsi_driver_common_send_cmd(rsi_common_cmd_request_t cmd, rsi_pkt_t *pkt) + * @brief Fill commands and packets into WLAN TX queue. + * @param[in] cmd - type of the command to send + * @param[in] pkt - pointer of packet to send + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +/// @private +int32_t rsi_driver_common_send_cmd(rsi_common_cmd_request_t cmd, rsi_pkt_t *pkt) +{ + uint16_t payload_size = 0; + int32_t status = RSI_SUCCESS; + // Get common control block structure pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + // Get host descriptor pointer + uint8_t *host_desc = (pkt->desc); +#ifdef RSI_PUF_ENABLE + if (!(((cmd >= RSI_COMMON_REQ_PUF_ENROLL) && (cmd <= RSI_COMMON_REQ_AES_MAC)) + || (cmd == RSI_COMMON_REQ_PUF_INTR_KEY))) +#endif +#ifdef RSI_CRYPTO_ENABLE + if (!(cmd == RSI_COMMON_REQ_ENCRYPT_CRYPTO)) +#endif + + { + // Memset host descriptor + memset(host_desc, 0, RSI_HOST_DESC_LENGTH); + } + + switch (cmd) { + case RSI_COMMON_REQ_FW_VERSION: { + + } break; + case RSI_COMMON_REQ_MODULE_TYPE: { + + } break; + case RSI_COMMON_REQ_OPERMODE: { + // opermode Parameters + rsi_opermode_t *rsi_opermode = (rsi_opermode_t *)pkt->data; + + // fill other parameters from configuration file +#ifdef RSI_M4_INTERFACE + rsi_uint32_to_4bytes(rsi_opermode->feature_bit_map, (FEAT_WPS_DISABLE | RSI_FEATURE_BIT_MAP)); +#else + rsi_uint32_to_4bytes(rsi_opermode->feature_bit_map, RSI_FEATURE_BIT_MAP); +#endif +#if RSI_TCP_IP_BYPASS + rsi_uint32_to_4bytes(rsi_opermode->tcp_ip_feature_bit_map, RSI_TCP_IP_FEATURE_BIT_MAP); +#else + rsi_uint32_to_4bytes(rsi_opermode->tcp_ip_feature_bit_map, + (RSI_TCP_IP_FEATURE_BIT_MAP | RSI_APP_TCP_IP_FEATURE_BITMAP)); +#endif + rsi_uint32_to_4bytes(rsi_opermode->custom_feature_bit_map, + (FEAT_CUSTOM_FEAT_EXTENTION_VALID | RSI_CUSTOM_FEATURE_BIT_MAP)); + +#ifdef CHIP_9117 + rsi_uint32_to_4bytes(rsi_opermode->ext_custom_feature_bit_map, (RSI_EXT_CUSTOM_FEATURE_BIT_MAP)); +#else //defaults +#ifdef RSI_M4_INTERFACE + rsi_uint32_to_4bytes(rsi_opermode->ext_custom_feature_bit_map, + (EXT_FEAT_256K_MODE | RSI_EXT_CUSTOM_FEATURE_BIT_MAP)); +#else + rsi_uint32_to_4bytes(rsi_opermode->ext_custom_feature_bit_map, + (EXT_FEAT_384K_MODE | RSI_EXT_CUSTOM_FEATURE_BIT_MAP)); +#endif +#endif + +#ifdef RSI_PROCESS_MAX_RX_DATA + rsi_uint32_to_4bytes( + rsi_opermode->ext_tcp_ip_feature_bit_map, + (RSI_EXT_TCPIP_FEATURE_BITMAP | RSI_APP_EXT_TCP_IP_FEATURE_BITMAP | EXT_TCP_MAX_RECV_LENGTH)); +#else + rsi_uint32_to_4bytes(rsi_opermode->ext_tcp_ip_feature_bit_map, + (RSI_EXT_TCPIP_FEATURE_BITMAP | RSI_APP_EXT_TCP_IP_FEATURE_BITMAP)); +#endif + rsi_uint32_to_4bytes(rsi_opermode->config_feature_bit_map, + (RSI_APP_CONFIG_FEATURE_BITMAP | RSI_CONFIG_FEATURE_BITMAP)); + + rsi_uint32_to_4bytes(rsi_opermode->bt_feature_bit_map, RSI_BT_FEATURE_BITMAP); + +#if (defined RSI_BLE_ENABLE || defined RSI_BT_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + if ((((rsi_bytes4R_to_uint32(rsi_opermode->opermode) >> 16) & 0xFFFF) == RSI_OPERMODE_WLAN_BLE) + || (((rsi_bytes4R_to_uint32(rsi_opermode->opermode) >> 16) & 0xFFFF) == RSI_OPERMODE_WLAN_BT_CLASSIC) + || (((rsi_bytes4R_to_uint32(rsi_opermode->opermode) >> 16) & 0xFFFF) == RSI_OPERMODE_WLAN_BT_DUAL_MODE)) { + rsi_opermode->custom_feature_bit_map[3] |= 0x80; + rsi_opermode->ext_custom_feature_bit_map[3] |= 0x80; +#if (defined A2DP_POWER_SAVE_ENABLE) + rsi_opermode->ext_custom_feature_bit_map[2] |= 0x40; +#endif +#ifdef RSI_BLE_ENABLE + //!ENABLE_BLE_PROTOCOL in bt_feature_bit_map + rsi_opermode->bt_feature_bit_map[3] |= 0x80; + rsi_uint32_to_4bytes(rsi_opermode->ble_feature_bit_map, + ((RSI_BLE_MAX_NBR_SLAVES << 12) | (RSI_BLE_MAX_NBR_MASTERS << 27) + | (RSI_BLE_MAX_NBR_ATT_SERV << 8) | RSI_BLE_MAX_NBR_ATT_REC)); + + /*Enable BLE custom feature bitmap*/ + rsi_opermode->ble_feature_bit_map[3] |= 0x80; + rsi_uint32_to_4bytes(rsi_opermode->ble_ext_feature_bit_map, + (RSI_BLE_NUM_CONN_EVENTS) | (RSI_BLE_NUM_REC_BYTES << 5)); + rsi_opermode->ble_ext_feature_bit_map[1] |= + (RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST << 6); //indication response from app + rsi_opermode->ble_ext_feature_bit_map[1] |= + (RSI_BLE_MTU_EXCHANGE_FROM_HOST << 7); //MTU Exchange request initiation from app + rsi_opermode->ble_ext_feature_bit_map[2] |= + (RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST); //Set SCAN Resp Data from app + rsi_opermode->ble_ext_feature_bit_map[2] |= + (RSI_BLE_DISABLE_CODED_PHY_FROM_HOST << 1); //Disable Coded PHY from app + rsi_opermode->ble_ext_feature_bit_map[2] |= (BLE_CP_BUFF_SIZE_512 << 2); // BIT 18 for BLE 512 Buff + rsi_opermode->ble_ext_feature_bit_map[2] |= + (RSI_BLE_ENABLE_ADV_EXTN << 3); // BIT 19 for enabling advertising extensions + rsi_opermode->ble_ext_feature_bit_map[2] |= + (RSI_BLE_AE_MAX_ADV_SETS << 4); // ble_custom_ext_feature_bit_map[20:23] for max AE adv sets +#if BLE_SIMPLE_GATT + rsi_opermode->ble_ext_feature_bit_map[1] |= (1 << 5); +#endif + rsi_opermode->ble_feature_bit_map[2] |= RSI_BLE_PWR_INX; + rsi_opermode->ble_feature_bit_map[3] |= RSI_BLE_PWR_SAVE_OPTIONS; + rsi_opermode->ble_feature_bit_map[3] |= (1 << 6); + rsi_opermode->ble_feature_bit_map[3] |= (RSI_BLE_GATT_ASYNC_ENABLE << 5); +#endif +#if (RSI_BT_ENABLE && RSI_BLE_ENABLE && RSI_BT_GATT_ON_CLASSIC) + rsi_opermode->bt_feature_bit_map[3] |= (1 << 5); /* to support att over classic acl link */ +#endif + } +#endif + + // fill payload size + payload_size = sizeof(rsi_opermode_t); + } break; + case RSI_COMMON_REQ_ANTENNA_SELECT: { + // fill payload size + payload_size = sizeof(rsi_antenna_select_t); + } break; + case RSI_COMMON_REQ_DEBUG_LOG: { + // fill payload size + payload_size = sizeof(rsi_debug_uart_print_t); + } break; + case RSI_COMMON_REQ_SWITCH_PROTO: { + payload_size = sizeof(rsi_switch_proto_t); + + } break; + case RSI_COMMON_REQ_GET_RAM_DUMP: { + payload_size = sizeof(rsi_ram_dump_t); + + } break; + + case RSI_COMMON_REQ_SET_RTC_TIMER: { + payload_size = sizeof(module_rtc_time_t); + } break; + case RSI_COMMON_REQ_GET_RTC_TIMER: { + payload_size = sizeof(module_rtc_time_t); + } break; + case RSI_COMMON_REQ_FEATURE_FRAME: { + // fill payload size + payload_size = sizeof(rsi_feature_frame_t); + } break; + case RSI_COMMON_REQ_SOFT_RESET: { + rsi_driver_cb->common_cb->state = RSI_COMMON_STATE_NONE; + + } break; + + case RSI_COMMON_REQ_UART_FLOW_CTRL_ENABLE: { + payload_size = 1; + } break; + case RSI_COMMON_REQ_PWRMODE: { + // Power mode setting + rsi_power_save_req_t *power_mode = (rsi_power_save_req_t *)pkt->data; + if (power_mode->power_mode != RSI_POWER_MODE_DISABLE) { + if (rsi_common_cb->power_save.wlan_psp_mode == 0xA) { + power_mode->ulp_mode_enable = RSI_ULP_WITHOUT_RAM_RET; + } else if (rsi_common_cb->power_save.wlan_psp_mode == 0x8) { + power_mode->ulp_mode_enable = RSI_ULP_WITH_RAM_RET; + } else { + // set LP/ULP/ULP-without RAM retention + power_mode->ulp_mode_enable = RSI_SELECT_LP_OR_ULP_MODE; + } + + // set DTIM aligment required + // 0 - module wakes up at beacon which is just before or equal to listen_interval + // 1 - module wakes up at DTIM beacon which is just after or equal to listen_interval + power_mode->dtim_aligned_type = RSI_DTIM_ALIGNED_TYPE; + + // Monitor interval for the FAST PSP mode + // default is 50 ms, and this parameter is valid for FAST PSP only + power_mode->monitor_interval = RSI_MONITOR_INTERVAL; + power_mode->num_of_dtim_skip = RSI_NUM_OF_DTIM_SKIP; +#ifdef RSI_WLAN_ENABLE + power_mode->listen_interval = rsi_wlan_cb_non_rom->ps_listen_interval; +#endif + } + + if (power_mode->ulp_mode_enable == RSI_ULP_WITHOUT_RAM_RET) { + rsi_driver_cb->common_cb->state = RSI_COMMON_STATE_NONE; + } + + // fill payload size + payload_size = sizeof(rsi_power_save_req_t); + } break; + +#ifdef RSI_WAC_MFI_ENABLE + case RSI_COMMON_REQ_IAP_INIT: + break; + case RSI_COMMON_REQ_IAP_GENERATE_SIGATURE: { + payload_size = sizeof(rsi_mfi_auth_create_request_t); + } break; + case RSI_COMMON_REQ_IAP_GET_CERTIFICATE: + break; +#endif + +#ifdef RSI_PUF_ENABLE + case RSI_COMMON_REQ_PUF_ENROLL: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_DIS_ENROLL: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_START: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_SET_KEY: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_DIS_SET_KEY: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_GET_KEY: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_DIS_GET_KEY: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_LOAD_KEY: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_AES_ENCRYPT: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_AES_DECRYPT: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_AES_MAC: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_COMMON_REQ_PUF_INTR_KEY: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; +#endif +#ifdef RSI_CRYPTO_ENABLE + case RSI_COMMON_REQ_ENCRYPT_CRYPTO: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; +#endif + case RSI_COMMON_REQ_TA_M4_COMMANDS: { +#ifdef RSI_M4_INTERFACE +#ifdef CHIP_9117 + rsi_req_ta2m4_t *ta2m4 = (rsi_req_ta2m4_t *)pkt->data; + if (ta2m4->sub_cmd == RSI_WRITE_TO_COMMON_FLASH) { + payload_size = ta2m4->chunk_len + (sizeof(rsi_req_ta2m4_t) - RSI_MAX_CHUNK_SIZE); + } else +#endif + { + payload_size = sizeof(ta_m4_handshake_param_t); + } +#endif + + } break; +#ifdef CONFIGURE_GPIO_FROM_HOST + case RSI_COMMON_REQ_GPIO_CONFIG: { + payload_size = sizeof(rsi_gpio_pin_config_t); + } break; +#endif + case RSI_COMMON_REQ_SET_CONFIG: { + payload_size = sizeof(rsi_set_config_t); + } break; +#ifdef FW_LOGGING_ENABLE + case RSI_COMMON_REQ_DEVICE_LOGGING_INIT: { + payload_size = sizeof(sl_fw_logging_t); + } break; +#endif + default: { + } + } + // Fill payload length + rsi_uint16_to_2bytes(host_desc, (payload_size & 0xFFF)); + + // Fill frame type + host_desc[1] |= (RSI_WLAN_MGMT_Q << 4); + + // Fill frame type + host_desc[2] = cmd; + + if ((cmd == RSI_COMMON_REQ_PWRMODE) || (cmd == RSI_COMMON_REQ_OPERMODE) || (cmd == RSI_COMMON_REQ_SOFT_RESET)) { + // Block WLAN TX queue + rsi_block_queue(&rsi_driver_cb->wlan_tx_q); +#ifdef RSI_ZB_ENABLE + // Block ZB TX queue + rsi_block_queue(&rsi_driver_cb->zigb_tx_q); +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + rsi_block_queue(&rsi_driver_cb->bt_single_tx_q); +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + rsi_block_queue(&rsi_driver_cb->prop_protocol_tx_q); +#endif + } + + // Enqueue packet to common TX queue + rsi_enqueue_pkt(&rsi_driver_cb->common_tx_q, pkt); + + // Set TX packet pending event + rsi_set_event(RSI_TX_EVENT); + + // Return status + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_driver_process_common_recv_cmd(rsi_pkt_t *pkt) + * @brief Process commands received to common block + * @param[in] pkt - pointer to common block packet + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t rsi_driver_process_common_recv_cmd(rsi_pkt_t *pkt) +{ + uint8_t cmd_type; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = pkt->desc; + uint16_t copy_length; + uint8_t *payload; + uint16_t payload_length; +#ifdef RSI_WLAN_ENABLE + uint8_t i = 0; +#endif + // Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + // Get wlan cb pointer + rsi_wlan_cb_t *rsi_wlan_cb = rsi_driver_cb->wlan_cb; + + // Get command type + cmd_type = pkt->desc[2]; + + // Get status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // Get payload pointer + payload = pkt->data; + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + rsi_common_set_status(status); + + switch (cmd_type) { + case RSI_COMMON_RSP_CARDREADY: { + // if success, update state common_cb state + if (status == RSI_SUCCESS) { + rsi_common_cb->state = RSI_COMMON_CARDREADY; + // Check for auto config status + if (host_desc[15] & RSI_AUTO_CONFIG_GOING_ON) { + // Set auto config failed status + rsi_wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON; + + // Check for auto config handler + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_GOING_ON); + } + } + // Check for auto config status + else if (host_desc[15] & RSI_AUTO_CONFIG_FAILED) { + // Set auto config failed status + rsi_wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_FAILED; + + // Check for auto config handler + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_FAILED); + } + } + } + } break; + + case RSI_COMMON_RSP_OPERMODE: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // if success update state common_cb state and wlan_cb state to OPERMODE done + if (status == RSI_SUCCESS) { + // Update wlan state to OPERMODE done + rsi_wlan_cb->state = RSI_WLAN_STATE_OPERMODE_DONE; + + rsi_common_cb->state = RSI_COMMON_OPERMODE_DONE; + + // unblock protocol queues + rsi_unblock_queue(&rsi_driver_cb->wlan_tx_q); + +#ifdef RSI_ZB_ENABLE + // unblock ZB TX queue + rsi_unblock_queue(&rsi_driver_cb->zigb_tx_q); +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + // unblock BT common TX queue + rsi_unblock_queue(&rsi_driver_cb->bt_single_tx_q); +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + // unblock PROP_PROTOCOL TX queue + rsi_unblock_queue(&rsi_driver_cb->prop_protocol_tx_q); +#endif + } + } break; + case RSI_COMMON_RSP_PWRMODE: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // if success update state common_cb state and wlan_cb state to OPERMODE done + if (status == RSI_SUCCESS) { + if (rsi_common_cb->power_save.current_ps_mode != 0) { + // set power_save_enable + rsi_common_cb->power_save.power_save_enable = 1; + } + } + // unblock protocol queues + rsi_unblock_queue(&rsi_driver_cb->wlan_tx_q); + +#ifdef RSI_ZB_ENABLE + // unblock ZB TX queue + rsi_unblock_queue(&rsi_driver_cb->zigb_tx_q); +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + // unblock BT TX queue + rsi_unblock_queue(&rsi_driver_cb->bt_single_tx_q); +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + // unblock PROP_PROTOCOL TX queue + rsi_unblock_queue(&rsi_driver_cb->prop_protocol_tx_q); +#endif + // Flush module state + rsi_common_cb->power_save.module_state = RSI_IDLE; + } break; + case RSI_COMMON_RSP_ANTENNA_SELECT: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + } break; + case RSI_COMMON_RSP_DEBUG_LOG: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + } break; + case RSI_COMMON_RSP_FEATURE_FRAME: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + } break; + + case RSI_COMMON_RSP_SOFT_RESET: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // check common_cb for any task is waiting for response + // No need to check for expected response as all variables will be reseted after reset command + //if(rsi_common_cb->expected_response == cmd_type ) + { + // state update + rsi_common_cb->state = RSI_COMMON_CARDREADY; + rsi_wlan_cb->state = RSI_WLAN_STATE_NONE; +#ifdef RSI_WLAN_ENABLE + // added this loop for socket pool not memset/clear sometime while deinit/reset. For more info. + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + // Memset socket info + memset(&rsi_socket_pool[i], 0, sizeof(rsi_socket_info_t)); + } +#endif + // Check for auto config status + if (host_desc[15] & RSI_AUTO_CONFIG_GOING_ON) { + // Set auto config failed status + rsi_wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON; + + // Check for auto config handler + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_GOING_ON); + } + } + // Check for auto config status + else if (host_desc[15] & RSI_AUTO_CONFIG_FAILED) { + // Set auto config failed status + rsi_wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_FAILED; + + // Check for auto config handler + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_FAILED); + } + } + } + } break; +#ifdef RSI_CRYPTO_ENABLE + case RSI_RSP_ENCRYPT_CRYPTO: { + if (status == RSI_SUCCESS) { + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + } + } + + } break; +#endif +#ifdef RSI_WAC_MFI_ENABLE + case RSI_COMMON_RSP_IAP_INIT: + break; + case RSI_COMMON_RSP_IAP_GET_CERTIFICATE: + case RSI_COMMON_RSP_IAP_GENERATE_SIGATURE: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // Get payload pointer + payload = pkt->data; + + // if success update state common_cb state and wlan_cb state to OPERMODE done + if (status == RSI_SUCCESS) { + + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + + } break; +#endif + +#ifdef RSI_PUF_ENABLE + case RSI_COMMON_RSP_PUF_ENROLL: { + if (status == RSI_SUCCESS) { + rsi_common_cb->puf_state = RSI_PUF_STATE_STARTED; + } + } break; + case RSI_COMMON_RSP_PUF_DIS_ENROLL: { + if (status == RSI_SUCCESS) { + } + } break; + case RSI_COMMON_RSP_PUF_START: { + if (status == RSI_SUCCESS) { + rsi_common_cb->puf_state = RSI_PUF_STATE_STARTED; + // check common_cb for any task is waiting for response + } + } break; + case RSI_COMMON_RSP_PUF_SET_KEY: { + if (status == RSI_SUCCESS) { + rsi_common_cb->puf_state = RSI_PUF_STATE_SET_KEY; + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + + } break; + case RSI_COMMON_RSP_PUF_DIS_SET_KEY: { + if (status == RSI_SUCCESS) { + } + } break; + + case RSI_COMMON_RSP_PUF_GET_KEY: { + if (status == RSI_SUCCESS) { + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + } break; + case RSI_COMMON_RSP_PUF_DIS_GET_KEY: { + if (status == RSI_SUCCESS) { + } + } break; + case RSI_COMMON_RSP_PUF_LOAD_KEY: { + if (status == RSI_SUCCESS) { + rsi_common_cb->puf_state = RSI_PUF_STATE_KEY_LOADED; + } + } break; + case RSI_COMMON_RSP_AES_ENCRYPT: { + if (status == RSI_SUCCESS) { + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + } break; + case RSI_COMMON_RSP_AES_DECRYPT: { + if (status == RSI_SUCCESS) { + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + } break; + case RSI_COMMON_RSP_AES_MAC: { + if (status == RSI_SUCCESS) { + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + } break; + case RSI_COMMON_RSP_PUF_INTR_KEY: { + if (status == RSI_SUCCESS) { + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + + } break; + +#endif + + case RSI_COMMON_RSP_FW_VERSION: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy firmware version + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + + } break; + + case RSI_COMMON_RSP_MODULE_TYPE: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy the module type + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + + } break; + + case RSI_COMMON_RSP_GET_RTC_TIMER: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + + } break; + + case RSI_COMMON_RSP_TA_M4_COMMANDS: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // Get payload pointer + payload = pkt->data; + + // if success update state common_cb state and wlan_cb state to OPERMODE done + if (status == RSI_SUCCESS) { + + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + } break; + case RSI_COMMON_RSP_SWITCH_PROTO: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // Get payload pointer + payload = pkt->data; + +#ifdef RSI_WLAN_ENABLE + if (rsi_wlan_cb_non_rom->callback_list.rsi_max_available_rx_window) { + rsi_wlan_cb_non_rom->callback_list.rsi_max_available_rx_window(status, payload, payload_length); + } +#endif + } break; +#ifdef CONFIGURE_GPIO_FROM_HOST + case RSI_COMMON_RSP_GPIO_CONFIG: { + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // Get payload pointer + payload = pkt->data; + + // if success update state common_cb state to OPERMODE done + if (status == RSI_SUCCESS) { + + if ((rsi_common_cb->app_buffer != NULL) && (rsi_common_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_common_cb->app_buffer_length) ? (payload_length) + : (rsi_common_cb->app_buffer_length); + memcpy(rsi_common_cb->app_buffer, payload, copy_length); + rsi_common_cb->app_buffer = NULL; + } + } + } break; +#endif +#ifdef FW_LOGGING_ENABLE + case RSI_COMMON_RSP_DEVICE_LOGGING_INIT: { + // Check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // Get payload pointer + payload = pkt->data; + + // if SUCCESS, notify application using callback + if (pkt->desc[15] == SL_LOG_DATA) { + if (status == RSI_SUCCESS) { + if (rsi_common_cb->sl_fw_log_callback != NULL) { + rsi_common_cb->sl_fw_log_callback(&payload[0], payload_length); + return RSI_SUCCESS; + } else { + return RSI_FAILURE; + } + } else { + return RSI_FAILURE; + } + } + } break; +#endif + default: { + } + } +#ifdef RSI_WITH_OS + if (cmd_type == RSI_COMMON_RSP_CARDREADY) { +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(3); +#endif + rsi_semaphore_post(&rsi_common_cb->common_card_ready_sem); + } +#endif + if ((cmd_type != RSI_COMMON_RSP_CARDREADY)) { + // signal the common_cb semaphore + if (cmd_type == RSI_COMMON_RSP_SWITCH_PROTO) { + if (rsi_common_cb->sync_mode) { +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_sem); + } else if ((rsi_wlan_cb_non_rom->switch_proto_callback != NULL) || (status != RSI_SUCCESS)) { +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_sem); + } + } else { +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_sem); + } + } + + return RSI_SUCCESS; +} + +/*=================================================*/ +/** + * @fn void rsi_handle_slp_wkp(uint8_t frame_type) + * @brief Handle sleep and wakeup frames. + * @param[in] frame_type - Frame type + * @return Void + */ +/// @private +void rsi_handle_slp_wkp(uint8_t frame_type) +{ +#ifdef RSI_WLAN_ENABLE + uint8_t i = 0; +#endif + //Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + // Get wlan cb pointer + rsi_wlan_cb_t *rsi_wlan_cb = rsi_driver_cb->wlan_cb; + + // Handle them here based on power save state machine + switch (frame_type) { + case RSI_RSP_SLP: { + rsi_common_cb->power_save.module_state = RSI_SLP_RECEIVED; + rsi_set_event(RSI_TX_EVENT); + } break; + case RSI_RSP_WKP: { + rsi_common_cb->power_save.module_state = RSI_WKUP_RECEIVED; + rsi_unmask_event(RSI_TX_EVENT); + } break; + case RSI_COMMON_RSP_ULP_NO_RAM_RETENTION: { + // state update + rsi_common_cb->state = RSI_COMMON_CARDREADY; + rsi_wlan_cb->state = RSI_WLAN_STATE_NONE; +#ifdef RSI_WLAN_ENABLE + // added this loop for socket pool not memset/clear sometime while deinit/reset. For more info (RSC-4333) . + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + // Memset socket info + memset(&rsi_socket_pool[i], 0, sizeof(rsi_socket_info_t)); + memset(&rsi_socket_pool_non_rom[i], 0, sizeof(rsi_socket_info_non_rom_t)); + } + rsi_wlan_cb_non_rom->wlan_radio = 0; + rsi_wlan_cb_non_rom->socket_bitmap = 0; + // Set expected_response to zero + rsi_wlan_cb->expected_response = RSI_WLAN_RSP_CLEAR; +#endif + // Set expected_response to zero + rsi_common_cb->expected_response = RSI_COMMON_RSP_CLEAR; + rsi_allow_sleep(); + memset(&(rsi_common_cb->power_save), 0, sizeof(rsi_common_cb->power_save)); + rsi_unmask_event(RSI_TX_EVENT); +#ifdef RSI_WITH_OS +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(3); +#endif + rsi_semaphore_post(&rsi_common_cb->common_card_ready_sem); +#endif + } break; + default: { + } + } +} + +/*====================================================*/ +/** + * @fn int8_t rsi_req_wakeup(void) + * @brief Set wakeup GPIO high + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int8_t rsi_req_wakeup(void) +{ + +#ifndef RSI_M4_INTERFACE + rsi_timer_instance_t timer_instance; +#if (RSI_SELECT_LP_OR_ULP_MODE != RSI_LP_MODE) + rsi_hal_set_gpio(RSI_HAL_SLEEP_CONFIRM_PIN); +#else + rsi_hal_set_gpio(RSI_HAL_LP_SLEEP_CONFIRM_PIN); +#endif +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD + if (rsi_hal_get_gpio(RSI_HAL_WAKEUP_INDICATION_PIN)) { +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif + } else { + rsi_hal_gpio_unmask(); +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(4); +#endif + if (rsi_semaphore_wait(&rsi_driver_cb->common_cb->wakeup_gpio_sem, RSI_GPIO_WAIT_TIME) != RSI_ERROR_NONE) { + return RSI_ERROR_GPIO_WAKEUP_TIMEOUT; + } +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif + } +#else + rsi_init_timer(&timer_instance, RSI_GPIO_WAIT_TIME); + do { + if (rsi_hal_get_gpio(RSI_HAL_WAKEUP_INDICATION_PIN)) { +#if (RSI_SELECT_LP_OR_ULP_MODE != RSI_LP_MODE) +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif +#endif + break; + } + if (rsi_timer_expired(&timer_instance)) { + return RSI_ERROR_GPIO_WAKEUP_TIMEOUT; + } + } while (1); +#endif +#endif + return RSI_SUCCESS; +} + +/*====================================================*/ +/** + * @fn int8_t rsi_wait4wakeup(void) + * @brief Waits for wakeup confirmation pin to be set + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int8_t rsi_wait4wakeup(void) +{ +#ifndef RSI_M4_INTERFACE + rsi_timer_instance_t timer_instance; +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD + if (rsi_hal_get_gpio(RSI_HAL_WAKEUP_INDICATION_PIN)) { +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif + } else { + rsi_hal_gpio_unmask(); +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(4); +#endif + if (rsi_semaphore_wait(&rsi_driver_cb->common_cb->wakeup_gpio_sem, RSI_GPIO_WAIT_TIME) != RSI_ERROR_NONE) { + return RSI_ERROR_GPIO_WAKEUP_TIMEOUT; + } +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif + } +#else + rsi_init_timer(&timer_instance, RSI_GPIO_WAIT_TIME); + if (rsi_driver_cb->wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + rsi_hal_set_gpio(RSI_HAL_SLEEP_CONFIRM_PIN); + } + do { + if (rsi_hal_get_gpio(RSI_HAL_WAKEUP_INDICATION_PIN)) { +#if (RSI_SELECT_LP_OR_ULP_MODE != RSI_LP_MODE) + if (rsi_driver_cb->wlan_cb->state >= RSI_WLAN_STATE_CONNECTED) { + rsi_hal_set_gpio(RSI_HAL_SLEEP_CONFIRM_PIN); + } +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif +#else + rsi_hal_set_gpio(RSI_HAL_LP_SLEEP_CONFIRM_PIN); +#endif + break; + } + if (rsi_timer_expired(&timer_instance)) { + return RSI_ERROR_GPIO_WAKEUP_TIMEOUT; + } + } while (1); +#endif +#endif + return RSI_SUCCESS; +} + +/*====================================================*/ +/** + * @fn void rsi_allow_sleep(void) + * @brief Set wakeup GPIO low. + * @param[in] void + * @return Void + */ +/// @private +void rsi_allow_sleep(void) +{ + +#ifdef RSI_M4_INTERFACE + P2P_STATUS_REG &= ~M4_wakeup_TA; +#else +#if (RSI_SELECT_LP_OR_ULP_MODE != RSI_LP_MODE) + rsi_hal_clear_gpio(RSI_HAL_SLEEP_CONFIRM_PIN); +#else + rsi_hal_clear_gpio(RSI_HAL_LP_SLEEP_CONFIRM_PIN); +#endif +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_powersave_gpio_init(void) + * @brief Initialize GPIOs used in power save . + * @param[in] void + * @return Void + */ +/// @private +void rsi_powersave_gpio_init(void) +{ + SL_PRINTF(SL_POWERSAVE_GPIO_INIT_ENTRY, DRIVER, LOG_INFO); +#ifndef RSI_M4_INTERFACE + rsi_hal_config_gpio(RSI_HAL_WAKEUP_INDICATION_PIN, 0, 0); +#if (RSI_SELECT_LP_OR_ULP_MODE != RSI_LP_MODE) + rsi_hal_config_gpio(RSI_HAL_SLEEP_CONFIRM_PIN, 1, 0); + rsi_hal_clear_gpio(RSI_HAL_SLEEP_CONFIRM_PIN); +#else + rsi_hal_config_gpio(RSI_HAL_LP_SLEEP_CONFIRM_PIN, 1, 0); + rsi_hal_clear_gpio(RSI_HAL_LP_SLEEP_CONFIRM_PIN); +#endif +#endif + SL_PRINTF(SL_POWERSAVE_GPIO_INIT_EXIT, DRIVER, LOG_INFO); +} +/*==============================================*/ +/** + * @fn void rsi_common_packet_transfer_done(rsi_pkt_t *pkt) + * @brief Handle packet transfer completion which has an asyncronous response. + * @param[in] pkt - pointer to packet + * @return Void + */ +/// @private +void rsi_common_packet_transfer_done(rsi_pkt_t *pkt) +{ + UNUSED_PARAMETER(pkt); //This statement is added only to resolve compilation warning, value is unchanged + // Set wlan status as success + rsi_common_set_status(RSI_SUCCESS); +} + +/*====================================================*/ +/** + * @fn int32_t rsi_sleep_mode_decision(rsi_common_cb_t *rsi_common_cb) + * @brief Decides the power mode to program + * @param[in] rsi_common_cb - pointer to the common control block + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t rsi_sleep_mode_decision(rsi_common_cb_t *rsi_common_cb) +{ + int32_t status = RSI_SUCCESS; + uint8_t selected_ps_mode = 0; + uint8_t selected_ps_type = 0; + uint8_t mode_decision = 0; + + switch ((rsi_common_cb->ps_coex_mode & 0xF)) { + case 1: { + mode_decision = ((rsi_common_cb->power_save.wlan_psp_mode << 4) | (rsi_common_cb->power_save.wlan_psp_mode)); + } break; + case 4: + case 12: + case 8: { + mode_decision = ((rsi_common_cb->power_save.bt_psp_mode << 4) | (rsi_common_cb->power_save.bt_psp_mode)); + } break; + case 5: + case 9: + case 13: { + mode_decision = ((rsi_common_cb->power_save.wlan_psp_mode << 4) | (rsi_common_cb->power_save.bt_psp_mode)); + } break; + case 3: { + mode_decision = ((rsi_common_cb->power_save.wlan_psp_mode << 4) | (rsi_common_cb->power_save.zb_psp_mode)); + } break; + default: + break; + } + + switch (mode_decision) { + case 0x00: + case 0x10: + case 0x01: + case 0x20: + case 0x02: + case 0x80: + case 0x08: { + selected_ps_mode = RSI_ACTIVE; + } break; + case 0x88: + case 0xAA: { + // Update power save profile mode +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + + selected_ps_mode = RSI_GPIO_BASED_DEEP_SLEEP; + +#elif defined(RSI_M4_INTERFACE) && (RSI_HAND_SHAKE_TYPE == M4_BASED) + + selected_ps_mode = RSI_M4_BASED_DEEP_SLEEP; +#else + selected_ps_mode = RSI_MSG_BASED_DEEP_SLEEP; +#endif + } break; + case 0x11: + case 0x81: + case 0x18: + case 0x12: + case 0x21: { + // Update power save profile mode + selected_ps_mode = RSI_CONNECTED_SLEEP_PS; + + // Update power save profile type + selected_ps_type = rsi_common_cb->power_save.wlan_psp_type; + } break; + case 0x22: + case 0x82: + case 0x28: { + // Update power save profile mode +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + selected_ps_mode = RSI_CONNECTED_GPIO_BASED_PS; + +#elif defined(RSI_M4_INTERFACE) && (RSI_HAND_SHAKE_TYPE == M4_BASED) + selected_ps_mode = RSI_CONNECTED_M4_BASED_PS; +#else + selected_ps_mode = RSI_CONNECTED_MSG_BASED_PS; +#endif + // Update power save profile type + selected_ps_type = rsi_common_cb->power_save.wlan_psp_type; + } break; + default: { + // Do nothing + } break; + } + + if (rsi_common_cb->power_save.current_ps_mode != selected_ps_mode) { + status = rsi_send_ps_mode_to_module(selected_ps_mode, selected_ps_type); + } + + return status; +} +/*====================================================*/ +/** + * @fn int32_t rsi_send_ps_mode_to_module(uint8_t selected_ps_mode, uint8_t selected_ps_type) + * @brief Send the power save mode and type to module + * @param[in] selected_ps_mode - Select power save mode + * @param[in] selected_ps_type - Select power save type + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t rsi_send_ps_mode_to_module(uint8_t selected_ps_mode, uint8_t selected_ps_type) +{ + rsi_pkt_t *pkt; + rsi_power_save_req_t *ps_req; + int32_t status = 0; + + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the common cmd state to progress + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Power mode setting + ps_req = (rsi_power_save_req_t *)pkt->data; + + // reset to 0 + memset(&pkt->data, 0, sizeof(rsi_power_save_req_t)); + + //take backup of powe save mode + rsi_common_cb->power_save.current_ps_mode = 0; + + // send power save command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_PWRMODE, pkt); + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_PWRMODE_RESPONSE_WAIT_TIME); + + // unmask Tx event + rsi_unmask_event(RSI_TX_EVENT); + + // get common command response stattus + status = rsi_common_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return status + return status; + } + + rsi_common_cb->power_save.power_save_enable = 0; + + if (selected_ps_mode == 0) { + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return status + return RSI_SUCCESS; + } + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the common cmd state to progress + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + memset(&pkt->data, 0, sizeof(rsi_power_save_req_t)); + + //take backup of powe save mode + rsi_common_cb->power_save.current_ps_mode = selected_ps_mode; + + // Update power save profile mode + ps_req->power_mode = selected_ps_mode; + + // Update power save profile type + ps_req->psp_type = selected_ps_type; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // send power save command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_PWRMODE, pkt); + + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_PWRMODE_RESPONSE_WAIT_TIME); + + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //return common command error + return status; + } + + // get common command response stattus + status = rsi_common_get_status(); + + if (status == RSI_SUCCESS) { + // Enable power save + rsi_common_cb->power_save.power_save_enable = 1; + } + + // unmask Tx event + rsi_unmask_event(RSI_TX_EVENT); + return status; +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_wait_on_common_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms ) + * @brief Wait for common semaphore + * @param[in] semaphore - Semaphore handle pointer + * @param[in] timeout_ms - Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait + till acquire semaphore. + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +rsi_error_t rsi_wait_on_common_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) +{ + // Wait on wlan semaphore + if (rsi_semaphore_wait(semaphore, timeout_ms) != RSI_ERROR_NONE) { + rsi_common_set_status(RSI_ERROR_RESPONSE_TIMEOUT); +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + if (rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb != NULL) { + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb(RSI_ERROR_RESPONSE_TIMEOUT, COMMON_CMD); + } +#endif + return RSI_ERROR_RESPONSE_TIMEOUT; + } + return RSI_ERROR_NONE; +} +/*==============================================*/ +/** + * @fn int32_t rsi_check_and_update_cmd_state(uint8_t cmd_type,uint8_t cmd_state) + * @brief Check and update the command state + * @param[in] cmd_type - Command type \n + * 1 - COMMON_CMD \n + * 2 - WLAN_CMD \n + * 3 - NWK_CMD + * @param[in] cmd_state - command state \n + * 1 - IN_USE \n + * 2 - ALLOW + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t rsi_check_and_update_cmd_state(uint8_t cmd_type, uint8_t cmd_state) +{ + int32_t status = RSI_SUCCESS; + if (rsi_driver_cb_non_rom->device_state < RSI_DEVICE_INIT_DONE) { + //command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + switch (cmd_type) { + case COMMON_CMD: { + if (cmd_state == IN_USE) { +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(1); +#endif + // common semaphore + status = rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_send_sem, + RSI_COMMON_SEND_CMD_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + return RSI_ERROR_COMMON_CMD_IN_PROGRESS; + } + } else if (cmd_state == ALLOW) { +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap &= ~BIT(1); +#endif + // common semaphore post + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_send_sem); + } + } break; +#ifdef RSI_WLAN_ENABLE + case WLAN_CMD: { + if (cmd_state == IN_USE) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(1); +#endif + // wlan semaphore + status = + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_send_sem, RSI_WLAN_SEND_CMD_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + return RSI_ERROR_WLAN_CMD_IN_PROGRESS; + } + } else if (cmd_state == ALLOW) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(1); +#endif + // wlan semaphore post + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + } + } break; + case NWK_CMD: { + if (cmd_state == IN_USE) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(1); +#endif + // nwk semaphore + status = + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_cmd_send_sem, RSI_NWK_SEND_CMD_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + return RSI_ERROR_NWK_CMD_IN_PROGRESS; + } + } else if (cmd_state == ALLOW) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap &= ~BIT(1); +#endif + // nwk semaphore post + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_cmd_send_sem); + } + } break; +#endif + default: + status = RSI_ERROR_INVALID_PARAM; + break; + } + return status; +} +/*==============================================*/ +/** + * @fn void rsi_post_waiting_common_semaphore(void) + * @brief Release all the common semaphores which are on semaphore wait + * @param[in] void + * @return Void + * + * + */ +#ifndef RSI_COMMON_SEM_BITMAP +/// @private +void rsi_post_waiting_common_semaphore(void) +{ + if (rsi_driver_cb_non_rom->common_wait_bitmap & BIT(0)) { + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_sem); + } + if (rsi_driver_cb_non_rom->common_wait_bitmap & BIT(1)) { + rsi_semaphore_post(&rsi_driver_cb_non_rom->common_cmd_send_sem); + } + if (rsi_driver_cb_non_rom->common_wait_bitmap & BIT(2)) { + rsi_semaphore_post(&rsi_driver_cb->common_cb->common_sem); + } + + if (rsi_driver_cb_non_rom->common_wait_bitmap & BIT(3)) { +#ifdef RSI_WITH_OS + rsi_semaphore_post(&rsi_driver_cb->common_cb->common_card_ready_sem); +#endif + } + if (rsi_driver_cb_non_rom->common_wait_bitmap & BIT(4)) { +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD + rsi_semaphore_post(&rsi_driver_cb->common_cb->wakeup_gpio_sem); +#endif + } + rsi_driver_cb_non_rom->common_wait_bitmap = 0; +} +#endif +/*==============================================*/ +/** + * @fn void rsi_post_waiting_bt_semaphore(void) + * @brief Release all the BT, BLE protocol semaphores + * @param[in] void + * @return Void + * + * + */ +/// @private +void rsi_post_waiting_bt_semaphore(void) +{ +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(1)) { + rsi_semaphore_post(&rsi_driver_cb->bt_common_cb->bt_sem); + } +#endif +#ifdef RSI_BT_ENABLE + + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(2)) { + rsi_semaphore_post(&rsi_driver_cb->bt_classic_cb->bt_sem); + } +#endif +#ifdef RSI_BLE_ENABLE + + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(3)) { + rsi_semaphore_post(&rsi_driver_cb->ble_cb->bt_sem); + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(4)) { + rsi_semaphore_post(&rsi_driver_cb->prop_protocol_cb->bt_sem); + } +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + + if (rsi_driver_cb_non_rom->bt_cmd_wait_bitmap & BIT(1)) { + rsi_semaphore_post(&rsi_driver_cb->bt_common_cb->bt_cmd_sem); + } +#endif +#ifdef RSI_BT_ENABLE + + if (rsi_driver_cb_non_rom->bt_cmd_wait_bitmap & BIT(2)) { + rsi_semaphore_post(&rsi_driver_cb->bt_classic_cb->bt_cmd_sem); + } +#endif +#ifdef RSI_BLE_ENABLE + + if (rsi_driver_cb_non_rom->bt_cmd_wait_bitmap & BIT(3)) { + rsi_semaphore_post(&rsi_driver_cb->ble_cb->bt_cmd_sem); + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + + if (rsi_driver_cb_non_rom->bt_cmd_wait_bitmap & BIT(4)) { + rsi_semaphore_post(&rsi_driver_cb->prop_protocol_cb->bt_cmd_sem); + } +#endif +} +/*=============================================================================*/ +/** + * @fn int32_t rsi_release_waiting_semaphore(void) + * @brief Releases all common ,WLAN and network semaphores which are semaphore wait + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t rsi_release_waiting_semaphore(void) +{ + +#ifdef RSI_WLAN_ENABLE + rsi_wlan_set_status(RSI_ERROR_IN_WLAN_CMD); + rsi_post_waiting_wlan_semaphore(); + rsi_post_waiting_semaphore(); + +#endif + rsi_common_set_status(RSI_ERROR_IN_COMMON_CMD); + rsi_post_waiting_common_semaphore(); + + rsi_post_waiting_bt_semaphore(); + if (rsi_driver_cb_non_rom->send_wait_bitmap & BIT(0)) { +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->send_data_sem); + } +#ifdef RSI_ZB_ENABLE + if (rsi_driver_cb_non_rom->zigb_wait_bitmap & BIT(0)) { +#ifndef RSI_ZIGB_SEM_BITMAP + rsi_driver_cb_non_rom->zigb_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb->zigb_cb->zigb_sem); + } +#endif + return RSI_SUCCESS; +} + +/*==============================================*/ +/** + * @fn void rsi_check_pkt_queue_and_dequeue(void) + * @brief Check the packet in queue and dequeue the packet + * @param[in] void + * @return Void + * + */ +/// @private +void rsi_check_pkt_queue_and_dequeue(void) +{ + uint8_t common_pkt_pending = 0; + uint8_t wlan_pkt_pending = 0; +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + uint8_t bt_pkt_pending = 0; +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + uint8_t prop_protocol_pkt_pending = 0; +#endif + rsi_pkt_t *pkt = NULL; + + /*First Check for Common Queue */ + common_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->common_tx_q); + + // check for packet pending in wlan queue + + if (common_pkt_pending) { + // if packet pending dequeue the packet from common queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->common_tx_q); + + // free the packet + rsi_pkt_free(&rsi_driver_cb->common_cb->common_tx_pool, pkt); + } + + // check for packet pending in wlan queue + wlan_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->wlan_tx_q); + + if (wlan_pkt_pending) { + // dequeue the packet from wlan queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->wlan_tx_q); + // free the packet + rsi_pkt_free(&rsi_driver_cb->wlan_cb->wlan_tx_pool, pkt); + } +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + // check for packet pending in bt/ble queue + bt_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->bt_single_tx_q); + + if (bt_pkt_pending) { + // dequeue the packet from bt/ble queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->bt_single_tx_q); + // free the packet +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + rsi_pkt_free(&rsi_driver_cb->bt_common_cb->bt_tx_pool, pkt); +#endif +#ifdef RSI_BT_ENABLE + rsi_pkt_free(&rsi_driver_cb->bt_classic_cb->bt_tx_pool, pkt); +#endif +#ifdef RSI_BLE_ENABLE + rsi_pkt_free(&rsi_driver_cb->ble_cb->bt_tx_pool, pkt); +#endif + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + // check for packet pending in prop_protocol queue + prop_protocol_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->prop_protocol_tx_q); + + if (prop_protocol_pkt_pending) { + // dequeue the packet from prop_protocol queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->prop_protocol_tx_q); + // free the packet + rsi_pkt_free(&rsi_driver_cb->prop_protocol_cb->bt_tx_pool, pkt); + } +#endif +} +/*==============================================*/ +/** + * @fn void rsi_free_queue_pkt(uint8_t pkt_dequeued,rsi_pkt_t *pkt) + * @brief Free the queued packet + * @param[in] pkt_dequeued - pkt to be free + * @param[in] pkt - pointer of the packet to be free + * @return Void + * + */ +void rsi_free_queue_pkt(uint8_t pkt_dequeued, rsi_pkt_t *pkt) +{ + if (pkt_dequeued == COMMON_PKT) { + rsi_pkt_free(&rsi_driver_cb->common_cb->common_tx_pool, pkt); + } +#ifdef RSI_WLAN_ENABLE + if (pkt_dequeued == WLAN_PKT) { + rsi_pkt_free(&rsi_driver_cb->wlan_cb->wlan_tx_pool, pkt); + } +#endif +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + if (pkt_dequeued == BT_PKT) { +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + rsi_pkt_free(&rsi_driver_cb->bt_common_cb->bt_tx_pool, pkt); +#endif +#ifdef RSI_BT_ENABLE + rsi_pkt_free(&rsi_driver_cb->bt_classic_cb->bt_tx_pool, pkt); +#endif +#ifdef RSI_BLE_ENABLE + rsi_pkt_free(&rsi_driver_cb->ble_cb->bt_tx_pool, pkt); +#endif + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + if (pkt_dequeued == PROP_PROTOCOL_PKT) { + rsi_pkt_free(&rsi_driver_cb->prop_protocol_cb->bt_tx_pool, pkt); + } +#endif +} +/*==============================================*/ +/** + * @fn void rsi_error_timeout_and_clear_events(int32_t error, uint32_t cmd_type) + * @brief Clears the event and gives timeout error + * @param[in] error - Error + * @param[in] cmd_type - command type + * @return Void + */ +/// @private +void rsi_error_timeout_and_clear_events(int32_t error, uint32_t cmd_type) +{ + rsi_clear_event(RSI_TX_EVENT); + rsi_clear_event(RSI_RX_EVENT); + if (cmd_type == TX_EVENT_CMD) { +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_timer_start = 0; +#endif +#ifndef RSI_CHECK_PKT_QUEUE + rsi_check_pkt_queue_and_dequeue(); +#endif + } else if (cmd_type == RX_EVENT_CMD) { +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_rx_timer_start = 0; +#endif + } +#ifndef RSI_RELEASE_SEMAPHORE + rsi_release_waiting_semaphore(); +#endif +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + if (rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb != NULL) { + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb(error, cmd_type); + } +#endif + return; +} + +/*==============================================*/ +/** + * @fn void rsi_check_waiting_cmds(rsi_rsp_waiting_cmds_t *reponse) + * @brief Check the commands which are waiting for the response + * @param[in] response - pointer to the command waiting for response + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +int32_t rsi_check_waiting_cmds(rsi_rsp_waiting_cmds_t *response) +{ +#ifdef RSI_WLAN_ENABLE + int32_t i = 0; +#endif + if (response == NULL) { + return RSI_FAILURE; + } else { + memset(response, 0, sizeof(rsi_rsp_waiting_cmds_t)); + if (rsi_driver_cb_non_rom->common_wait_bitmap & BIT(0)) { + response->waiting_cmds |= BIT(0); + } +#ifdef RSI_WLAN_ENABLE + if (rsi_driver_cb_non_rom->wlan_wait_bitmap & BIT(1)) { + response->waiting_cmds |= BIT(1); + } + if (rsi_driver_cb_non_rom->nwk_wait_bitmap & BIT(0)) { + response->waiting_cmds |= BIT(2); + } + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool[i].sock_state > RSI_SOCKET_STATE_INIT) { + if (rsi_socket_pool_non_rom[i].socket_wait_bitmap) { + response->waiting_cmds |= BIT(3); + break; + } + } + } + for (i = 0; i < RSI_NUMBER_OF_SELECTS; i++) { + if (rsi_socket_select_info[i].select_state == RSI_SOCKET_SELECT_STATE_CREATE) { + response->waiting_cmds |= BIT(4); + break; + } + } + if (rsi_driver_cb_non_rom->send_wait_bitmap & BIT(0)) { + response->waiting_cmds |= BIT(5); + } +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(1)) { + response->waiting_cmds |= BIT(6); + } +#endif +#ifdef RSI_BT_ENABLE + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(2)) { + response->waiting_cmds |= BIT(7); + } +#endif +#ifdef RSI_BLE_ENABLE + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(3)) { + response->waiting_cmds |= BIT(8); + } +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + if (rsi_driver_cb_non_rom->bt_wait_bitmap & BIT(4)) { + response->waiting_cmds |= BIT(9); + } +#endif + response->rx_driver_flag = rsi_driver_cb_non_rom->rx_driver_flag; + rsi_driver_cb_non_rom->rx_driver_flag = 1; + } + return RSI_SUCCESS; +} diff --git a/wiseconnect/sapi/driver/rsi_device_init.c b/wiseconnect/sapi/driver/rsi_device_init.c new file mode 100644 index 00000000..23e61fee --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_device_init.c @@ -0,0 +1,670 @@ +/******************************************************************************* +* @file rsi_device_init.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +#include "rsi_spi_cmd.h" +#define RSI_SAFE_UPGRADE_ADDR 0x1d408 +#define RSI_SECURE_ZONE_ADDR 0x1d418 +#define RSI_SAFE_UPGRADE BIT(12) +#define RSI_INTEGRITY_CHECK_BYPASS BIT(13) +#define RSI_SECURE_ZONE BIT(20) +#define PING_BUFF 0 +#define PONG_BUFF 1 +#ifndef RSI_M4_INTERFACE +#ifndef RSI_UART_INTERFACE +#ifndef RSI_USB_INTERFACE + +#if RSI_FAST_FW_UP +int16_t rsi_secure_ping_pong_wr(uint32_t ping_pong, uint8_t *src_addr, uint16_t size_param); +#endif + +/** @addtogroup DRIVER5 +* @{ +*/ +/** @fn int16_t rsi_secure_ping_pong_wr(uint32_t ping_pong, uint8_t *src_addr, uint16_t size_param) + * @brief Write the given data in the ping or pong buffer to the specified register address in the module. + * @param[in] ping_pong - ping or pong buffer write + * @param[in] size_param - Number of bytes to read. (def: 2 since we have 16 bit regs) + * @param[in ] src_addr - pointer contain the buffer of content to be written + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ + +#if RSI_FAST_FW_UP +/// @private +int16_t rsi_secure_ping_pong_wr(uint32_t ping_pong, uint8_t *src_addr, uint16_t size_param) +{ + + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(ping_pong); + + int16_t retval; + rsi_frame_desc_t frame_desc; + + *(uint16_t *)frame_desc.frame_len_queue_no = size_param; + + // Write out the Command Frame Descriptor + retval = rsi_spi_frame_dsc_wr(&frame_desc); + + if (retval != 0x00) { +#ifdef RSI_DEBUG_PRINT + RSI_DPRINT(RSI_PL4, "Descriptor write failErr=%02x", retval); +#endif + return retval; + } + + // Write the Command Frame Data + if (size_param) { + size_param = (size_param + 3) & ~3; + retval = rsi_spi_frame_data_wr(size_param, src_addr, 0, NULL); + if (retval != 0x00) { +#ifdef RSI_DEBUG_PRINT + RSI_DPRINT(RSI_PL4, "FramePayload writeErr=%02x", retval); +#endif + return retval; + } + } + return retval; +} +#endif +/** @} */ +/** @addtogroup DRIVER6 +* @{ +*/ +/*===========================================================*/ +/** + * @fn int16_t rsi_bl_module_power_cycle(void) + * @brief Power cycles the module. This API is valid only if there is a power gate, external to the module, + * which is controlling the power to the module using a GPIO signal of the MCU. + * @pre \ref rsi_driver_init() must be called before this API. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_driver_init() must be called before this API. + */ +/** @} */ +/** @addtogroup DRIVER5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int16_t rsi_bl_waitfor_boardready(void) + * @brief This API checks for the readiness of the bootloader to receive the commands from the host. + * @param[in] void + * @return 0 - Success \n + * @return Negative Value - Failure \n + */ +/// @private +int16_t rsi_bl_waitfor_boardready(void) +{ + SL_PRINTF(SL_BL_WAITFOR_BOARDREADY_ENTRY, DRIVER, LOG_INFO); + int16_t retval = 0; + uint16_t read_value = 0; + + retval = rsi_bootloader_instructions(RSI_REG_READ, &read_value); + + if (retval < 0) { + SL_PRINTF(SL_BL_WAITFOR_BOARDREADY_EXIT, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + if ((read_value & 0xFF00) == (RSI_HOST_INTERACT_REG_VALID & 0xFF00)) { + if ((read_value & 0xFF) == RSI_BOOTUP_OPTIONS_LAST_CONFIG_NOT_SAVED) { + return RSI_ERROR_BOOTUP_OPTIONS_NOT_SAVED; + } else if ((read_value & 0xFF) == RSI_BOOTUP_OPTIONS_CHECKSUM_FAIL) { + return RSI_ERROR_BOOTUP_OPTIONS_CHECKSUM_FAIL; + } else if ((read_value & 0xFF) == RSI_BOOTLOADER_VERSION_1P0) { + rsi_driver_cb_non_rom->rom_version_info = RSI_ROM_VERSION_1P0; + } else if ((read_value & 0xFF) == RSI_BOOTLOADER_VERSION_1P1) { + rsi_driver_cb_non_rom->rom_version_info = RSI_ROM_VERSION_1P1; + } +#if RSI_BOOTLOADER_VERSION_CHECK + else if ((read_value & 0xFF) == RSI_BOOTLOADER_VERSION) { + } else { + SL_PRINTF(SL_BL_WAITFOR_BOARDREADY_BOOTLOADER_VERSION_NOT_MATCHING, DRIVER, LOG_ERROR); + return RSI_ERROR_BOOTLOADER_VERSION_NOT_MATCHING; + } +#endif + SL_PRINTF(SL_BL_WAITFOR_BOARDREADY_SUCCESS, DRIVER, LOG_ERROR); + return RSI_SUCCESS; + } + SL_PRINTF(SL_BL_WAITFOR_BOARDREADY_WAITING_FOR_BOARD_READY, DRIVER, LOG_ERROR); + return RSI_ERROR_WAITING_FOR_BOARD_READY; +} +/*==============================================*/ +/** + * @fn int16_t rsi_bl_select_option(uint8_t cmd) + * @brief Send firmware load request or update default configurations to the module. + * @param[in] cmd - type of configuration to be saved \n + * BURN_NWP_FW - 0x42 \n + * LOAD_NWP_FW - 0x31 \n + * LOAD_DEFAULT_NWP_FW_ACTIVE_LOW - 0x71 \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffff2, 0xfffffff1, 0xffffffe4) \n + * @note Refer to \ref error-codes for the description of above error codes. + */ +/// @private +int16_t rsi_bl_select_option(uint8_t cmd) +{ + uint16_t boot_cmd = 0; + int16_t retval = 0; + uint16_t read_value = 0; + rsi_timer_instance_t timer_instance; + + retval = rsi_mem_wr(RSI_HOST_INTF_REG_OUT, 2, (uint8_t *)&boot_cmd); + if (retval < 0) { + return retval; + } + + if (cmd == BURN_NWP_FW) { + boot_cmd = RSI_HOST_INTERACT_REG_VALID_FW | cmd; + } else { + boot_cmd = RSI_HOST_INTERACT_REG_VALID | cmd; + } + retval = rsi_bootloader_instructions(RSI_REG_WRITE, &boot_cmd); + if (retval < 0) { + return retval; + } + + rsi_init_timer(&timer_instance, 300); + + while ((cmd != LOAD_NWP_FW) && (cmd != LOAD_DEFAULT_NWP_FW_ACTIVE_LOW)) { + retval = rsi_bootloader_instructions(RSI_REG_READ, &read_value); + if (retval < 0) { + return retval; + } + if (cmd == BURN_NWP_FW) { + if (read_value == (RSI_HOST_INTERACT_REG_VALID | RSI_SEND_RPS_FILE)) { + break; + } + } + + else if (read_value == (RSI_HOST_INTERACT_REG_VALID | cmd)) { + break; + } + if (rsi_timer_expired(&timer_instance)) { + return RSI_ERROR_FW_LOAD_OR_UPGRADE_TIMEOUT; + } + } + if ((cmd == LOAD_NWP_FW) || (cmd == LOAD_DEFAULT_NWP_FW_ACTIVE_LOW)) { + rsi_init_timer(&timer_instance, 3000); + do { + retval = rsi_bootloader_instructions(RSI_REG_READ, &read_value); + if (retval < 0) { + return retval; + } + if ((read_value & 0xF000) == (RSI_HOST_INTERACT_REG_VALID_FW & 0xF000)) { + if ((read_value & 0xFF) == VALID_FIRMWARE_NOT_PRESENT) { +#ifdef RSI_DEBUG_PRINT + RSI_DPRINT(RSI_PL4, "VALID_FIRMWARE_NOT_PRESENT\n"); +#endif + return RSI_ERROR_VALID_FIRMWARE_NOT_PRESENT; + } + if ((read_value & 0xFF) == RSI_INVALID_OPTION) { +#ifdef RSI_DEBUG_PRINT + RSI_DPRINT(RSI_PL4, "INVALID CMD\n"); +#endif + + return RSI_ERROR_INVALID_OPTION; + } + if ((read_value & 0xFF) == RSI_CHECKSUM_SUCCESS) { +#ifdef RSI_DEBUG_PRINT + RSI_DPRINT(RSI_PL4, "LOAD SUCCESS\n"); +#endif + break; + } + } + if (rsi_timer_expired(&timer_instance)) { + return RSI_ERROR_FW_LOAD_OR_UPGRADE_TIMEOUT; + } + + } while (1); + } + return retval; +} +/** @} */ +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * @fn int16_t rsi_bl_upgrade_firmware(uint8_t *firmware_image , uint32_t fw_image_size, uint8_t flags) + * @brief Upgrade the firmware in the module from the host. The firmware file is given in chunks to this API. \n + * Each chunk must be a multiple of 4096 bytes unless it is the last chunk. \n + * This is blocking API. + * @param[in] firmware_image - This is a pointer to firmware image buffer + * @param[in] fw_image_size - This is the size of firmware image + * @param[in] flags - 1 - RSI_FW_START_OF_FILE, set for the first chunk \n + * 2 - RSI_FW_END_OF_FILE, set for the last chunk \n + * 0 - for all other chunks + * @note In rsi_bootloader_instructions() API, by default the RSI_HAL_MAX_WR_BUFF_LEN macro (Max supported write buffer size) is 4096 bytes. + * You can reduce this buffer size (minimum value of 1600 bytes is expected) as per HAL memory availability at the cost of the increase in execution time of this API. \n + * This macro can be configured in rsi_user.h file. \n + * Example: uint8_t dummy[RSI_HAL_MAX_WR_BUFF_LEN]; + * @note For safe firmware upgrade via the bootloader, \n + * it will take approx. 65 sec duration for upgrading the firmware of 1.5 MB file. + * @note For fast firmware upgrade via the bootloader, \n + * it will take approx. 35 sec duration for upgrading the firmware of 1.5 MB file. + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ + +int16_t rsi_bl_upgrade_firmware(uint8_t *firmware_image, uint32_t fw_image_size, uint8_t flags) +{ + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_ENTRY, COMMON, LOG_INFO); + static uint16_t boot_cmd; + uint16_t read_value = 0; + uint32_t offset = 0; + int16_t retval = 0; + uint32_t boot_insn = 0, poll_resp = 0; + rsi_timer_instance_t timer_instance; + + // If it is a start of file set the boot cmd to pong valid + if (flags & RSI_FW_START_OF_FILE) { + boot_cmd = RSI_HOST_INTERACT_REG_VALID | RSI_PONG_VALID; + } + + // check for invalid packet + if ((fw_image_size % (RSI_MIN_CHUNK_SIZE) != 0) && (!(flags & RSI_FW_END_OF_FILE))) { + return RSI_ERROR_INVALID_PACKET; + } + + // loop to execute multiple of 4K chunks + while (offset < fw_image_size) { + switch (boot_cmd) { + case (RSI_HOST_INTERACT_REG_VALID | RSI_PING_VALID): + boot_insn = RSI_PONG_WRITE; + poll_resp = RSI_PING_AVAIL; + boot_cmd = RSI_HOST_INTERACT_REG_VALID | RSI_PONG_VALID; + break; + + case (RSI_HOST_INTERACT_REG_VALID | RSI_PONG_VALID): + boot_insn = RSI_PING_WRITE; + poll_resp = RSI_PONG_AVAIL; + boot_cmd = RSI_HOST_INTERACT_REG_VALID | RSI_PING_VALID; + break; + default: { + } + } + + retval = rsi_bootloader_instructions(boot_insn, (uint16_t *)((uint8_t *)firmware_image + offset)); + if (retval < 0) { + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT1, COMMON, LOG_ERROR, "retval: %d", retval); + return retval; + } + + rsi_init_timer(&timer_instance, 1000); + + while (1) { + retval = rsi_bootloader_instructions(RSI_REG_READ, &read_value); + if (retval < 0) { + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT2, COMMON, LOG_ERROR, "retval: %d", retval); + return retval; + } + if (read_value == (RSI_HOST_INTERACT_REG_VALID | poll_resp)) { + break; + } + if (rsi_timer_expired(&timer_instance)) { + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT3, COMMON, LOG_ERROR); + return RSI_ERROR_FW_UPGRADE_TIMEOUT; + } + } + offset += RSI_MIN_CHUNK_SIZE; + } + + // For last chunk set boot cmd as End of file reached + if (flags & RSI_FW_END_OF_FILE) { + boot_cmd = RSI_HOST_INTERACT_REG_VALID | RSI_EOF_REACHED; + + retval = rsi_bootloader_instructions(RSI_REG_WRITE, &boot_cmd); + if (retval < 0) { + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT4, COMMON, LOG_ERROR, "retval: %d", retval); + return retval; + } + rsi_init_timer(&timer_instance, 40000); + // check for successful firmware upgrade + do { + retval = rsi_bootloader_instructions(RSI_REG_READ, &read_value); + if (retval < 0) { + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT5, COMMON, LOG_ERROR, "retval: %d", retval); + return retval; + } + if (rsi_timer_expired(&timer_instance)) { + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT6, COMMON, LOG_ERROR); + return RSI_ERROR_FW_UPGRADE_TIMEOUT; + } + + } while (read_value != (RSI_HOST_INTERACT_REG_VALID | RSI_FWUP_SUCCESSFUL)); + } + SL_PRINTF(SL_BL_UPGRADE_FIRMWARE_EXIT5, COMMON, LOG_INFO, "retval: %d", retval); + return retval; +} +/** @} */ +/** @addtogroup DRIVER5 +* @{ +*/ +/** + * @fn int32_t rsi_set_fast_fw_up(void) + * @brief Set fast firmware upgrade. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +///@private +int32_t rsi_set_fast_fw_up(void) +{ + SL_PRINTF(SL_SET_FAST_FW_UP_ENTRY, DRIVER, LOG_INFO); + uint32_t read_data = 0; + int32_t retval = 0; + retval = rsi_mem_rd(RSI_SAFE_UPGRADE_ADDR, 4, (uint8_t *)&read_data); + if (retval < 0) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_1, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + //disabling safe upgradation bit + if ((read_data & RSI_SAFE_UPGRADE)) { + read_data &= ~(RSI_SAFE_UPGRADE); + retval = rsi_mem_wr(RSI_SAFE_UPGRADE_ADDR, 4, (uint8_t *)&read_data); + if (retval < 0) { + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_2, DRIVER, LOG_ERROR, "retval: %d", retval); + return retval; + } + } + SL_PRINTF(SL_SDIO_IFACE_INIT_EXIT_3, DRIVER, LOG_INFO, "retval: %d", retval); + return retval; +} +/** @} */ +/*! \cond PRIVATE */ +/** + * @fn int32_t rsi_integrity_check_bypass(void) + * @brief This API bypasses the fw image integrity check during initialization sequence. It will be called after board + * ready. This is meant to be used only during error recovery cases that require a reset to restore the firmware health. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + */ +int32_t rsi_integrity_check_bypass(void) +{ + uint32_t read_data = 0; + int32_t retval = 0; + retval = rsi_mem_rd(RSI_SAFE_UPGRADE_ADDR, 4, (uint8_t *)&read_data); + if (retval < 0) { + return retval; + } + //enabling integrity check bypass + if (!(read_data & (RSI_INTEGRITY_CHECK_BYPASS))) { + read_data |= RSI_INTEGRITY_CHECK_BYPASS; + retval = rsi_mem_wr(RSI_SAFE_UPGRADE_ADDR, 4, (uint8_t *)&read_data); + if (retval < 0) { + return retval; + } + } + return retval; +} +/*! \endcond */ + +/** @} */ +/** @addtogroup DRIVER6 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_get_rom_version(void) + * @brief Get the ROM version of the module. + * @param[in] void + * @return 1 - RSI_ROM_VERSION_1P0 \n + * @return 2 - RSI_ROM_VERSION_1P1 + * + * @note The return value of this API can be used to infer chip version of the module. \n + * 1 - 1.4EVK \n + * 2 - 1.5EVK + */ + +int32_t rsi_get_rom_version(void) +{ + SL_PRINTF(SL_GET_ROM_VERSION_ENTRY, DRIVER, LOG_INFO); + return rsi_driver_cb_non_rom->rom_version_info; +} +/** @} */ +/** @addtogroup DRIVER5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int16_t rsi_bootloader_instructions(uint8_t type, uint16_t *data) + * @brief Send boot instructions to the module + * @param[in] type - type of the insruction to perform \n + * 0xD1 - RSI_REG_READ \n + * 0xD2 - RSI_REG_WRITE \n + * 0xD5 - RSI_PING_WRITE \n + * 0xD4 - RSI_PONG_WRITE \n + * 0x42 - BURN_NWP_FW \n + * 0x31 - LOAD_NWP_FW \n + * 0x71 - LOAD_DEFAULT_NWP_FW_ACTIVE_LOW + * @param[in] data - pointer to data which is to be read/write \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xffffffff, 0xfffffffe, 0xffffffe4) \n + * @note Refer to \ref error-codes for the description of above error codes. + * @note This is a proprietry API and is not recommended to be used + */ +/// @private +int16_t rsi_bootloader_instructions(uint8_t type, uint16_t *data) +{ + int16_t retval = 0; + uint32_t cmd = 0; + uint32_t j = 0; + uint16_t len = 0; + uint16_t offset = 0; + uint16_t local = 0; + uint16_t read_data = 0; + rsi_timer_instance_t timer_instance; + + switch (type) { + case RSI_REG_READ: + retval = rsi_mem_rd(RSI_HOST_INTF_REG_OUT, 2, (uint8_t *)&read_data); + *data = read_data; + break; + + case RSI_REG_WRITE: + retval = rsi_mem_wr(RSI_HOST_INTF_REG_IN, 2, (uint8_t *)data); + break; + case RSI_PING_WRITE: + + for (j = 0; j <= RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN; j++) { + if (j == RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN) { + len = (RSI_PING_PONG_CHUNK_SIZE % RSI_HAL_MAX_WR_BUFF_LEN); + if (len == 0) { + break; + } + } else { + len = RSI_HAL_MAX_WR_BUFF_LEN; + } + retval = rsi_mem_wr(RSI_PING_BUFFER_ADDR + offset, len, (uint8_t *)((uint32_t)data + offset)); + if (retval < 0) { + return retval; + } + offset += len; + } + local = (RSI_PING_AVAIL | RSI_HOST_INTERACT_REG_VALID); + retval = rsi_mem_wr(RSI_HOST_INTF_REG_IN, 2, (uint8_t *)&local); + break; + case RSI_PONG_WRITE: + + for (j = 0; j <= RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN; j++) { + if (j == RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN) { + len = (RSI_PING_PONG_CHUNK_SIZE % RSI_HAL_MAX_WR_BUFF_LEN); + if (len == 0) { + break; + } + } else { + len = RSI_HAL_MAX_WR_BUFF_LEN; + } + retval = rsi_mem_wr(RSI_PONG_BUFFER_ADDR + offset, len, (uint8_t *)((uint32_t)data + offset)); + if (retval < 0) { + return retval; + } + offset += len; + } + // Perform the write operation + local = (RSI_PONG_AVAIL | RSI_HOST_INTERACT_REG_VALID); + + retval = rsi_mem_wr(RSI_HOST_INTF_REG_IN, 2, (uint8_t *)&local); + break; + case BURN_NWP_FW: + + cmd = BURN_NWP_FW | RSI_HOST_INTERACT_REG_VALID; + + retval = rsi_mem_wr(RSI_HOST_INTF_REG_IN, 2, (uint8_t *)&cmd); + if (retval < 0) { + return retval; + } + + rsi_init_timer(&timer_instance, 300); + + do { + retval = rsi_mem_rd(RSI_HOST_INTF_REG_OUT, 2, (uint8_t *)&read_data); + if (retval < 0) { + return retval; + } + if (rsi_timer_expired(&timer_instance)) { + return RSI_ERROR_FW_LOAD_OR_UPGRADE_TIMEOUT; + } + } while (read_data != (RSI_SEND_RPS_FILE | RSI_HOST_INTERACT_REG_VALID)); + break; + case LOAD_NWP_FW: + cmd = LOAD_NWP_FW | RSI_HOST_INTERACT_REG_VALID; + retval = rsi_mem_wr(RSI_HOST_INTF_REG_IN, 2, (uint8_t *)&cmd); + break; + case LOAD_DEFAULT_NWP_FW_ACTIVE_LOW: + cmd = LOAD_DEFAULT_NWP_FW_ACTIVE_LOW | RSI_HOST_INTERACT_REG_VALID; + retval = rsi_mem_wr(RSI_HOST_INTF_REG_IN, 2, (uint8_t *)&cmd); + break; + default: + retval = RSI_ERROR_INVALID_PARAM; + break; + } + return retval; +} +/** @} */ + +#ifndef LINUX_PLATFORM +#if ((defined RSI_SPI_INTERFACE || defined RSI_SDIO_INTERFACE)) +/** @addtogroup COMMON +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_get_ram_dump(uint32_t addr, uint16_t length, uint8_t *buf) + * @brief Get RAM dump. This is blocking API. + * @param[in] addr - Address of memory location in RS9116 + * @param[in] length - Length of the content to read + * @param[out] buf - Buffer to keep the read content + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * + */ + +int32_t rsi_get_ram_dump(uint32_t addr, uint16_t length, uint8_t *buf) +{ + SL_PRINTF(SL_GET_RAM_DUMP_ENTRY, COMMON, LOG_INFO); + uint32_t retval = 0; + if (buf == NULL) { + SL_PRINTF(SL_SET_RTC_TIMER_NULL_BUFFER, COMMON, LOG_ERROR); + return -1; + } + if (!length || length > 4096) { + SL_PRINTF(SL_SET_RTC_TIMER_BUFFER_LENGTH_ERROR, COMMON, LOG_ERROR); + return -2; + } + retval = rsi_mem_rd(addr, length, buf); + SL_PRINTF(SL_SET_RTC_TIMER_EXIT, COMMON, LOG_INFO, "retval: %d", retval); + return retval; +} +/** @} */ +#endif +#endif +#endif +#endif + +/** @} */ +/** @addtogroup DRIVER6 +* @{ +*/ +/*===========================================================*/ +/** + * @fn int16_t rsi_bl_module_power_cycle(void) + * @brief Power cycle the module.This API is valid only if there is a power gate, external to the module,which is controlling the power + * to the module using a GPIO signal of the MCU. + * @pre \ref rsi_driver_init() must be called before this API. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +int16_t rsi_bl_module_power_cycle(void) +{ + SL_PRINTF(SL_BL_MODULE_POWER_CYCLE_ENTRY, DRIVER, LOG_INFO); + +#ifdef ENABLE_POC_IN_TOGGLE + // configure POC_IN pin in GPIO mode + rsi_hal_config_gpio(RSI_HAL_POC_IN_PIN, RSI_HAL_GPIO_OUTPUT_MODE, RSI_HAL_GPIO_LOW); +#endif + + // configure Reset pin in GPIO mode + rsi_hal_config_gpio(RSI_HAL_RESET_PIN, RSI_HAL_GPIO_OUTPUT_MODE, RSI_HAL_GPIO_LOW); + +#ifdef ENABLE_POC_IN_TOGGLE + // reset/drive low value on the GPIO + rsi_hal_clear_gpio(RSI_HAL_POC_IN_PIN); + + rsi_delay_ms(CONFIG_DELAY_POCIN_RESET_PIN_CLEAR); +#endif + + // reset/drive low value on the GPIO + rsi_hal_clear_gpio(RSI_HAL_RESET_PIN); + + // delay for 100 milli seconds + rsi_delay_ms(100); + +#ifdef ENABLE_POC_IN_TOGGLE + // set/drive high value on the GPIO + rsi_hal_set_gpio(RSI_HAL_POC_IN_PIN); + + rsi_delay_ms(CONFIG_DELAY_POCIN_RESET_PIN_SET); +#endif + + // set/drive high value on the GPIO + rsi_hal_set_gpio(RSI_HAL_RESET_PIN); + + // delay for 100 milli seconds + rsi_delay_ms(100); + + SL_PRINTF(SL_BL_MODULE_POWER_CYCLE_EXIT, DRIVER, LOG_INFO); + + return RSI_SUCCESS; +} +#endif \ No newline at end of file diff --git a/wiseconnect/sapi/driver/rsi_driver.c b/wiseconnect/sapi/driver/rsi_driver.c new file mode 100644 index 00000000..6af5898d --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_driver.c @@ -0,0 +1,88 @@ +/******************************************************************************* +* @file rsi_driver.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ + +#include "rsi_driver.h" +/** @addtogroup DRIVER5 +* @{ +*/ +/*===================================================*/ +/** + * @fn void rsi_interrupt_handler(void) + * @brief Handle the interrupt coming from the module. + * @param[in] void + * @return Void + */ +/// @private +void rsi_interrupt_handler(void) +{ +#ifndef RSI_M4_INTERFACE + // Disable the interrupt + rsi_hal_intr_mask(); +#ifdef RSI_WITH_OS + // Set event RX pending from device + rsi_set_event_from_isr(RSI_RX_EVENT); +#else + // Set event RX pending from device + rsi_set_event(RSI_RX_EVENT); +#endif +#endif + return; +} +/*===================================================*/ +/** + * @fn void rsi_mask_ta_interrupt(void) + * @brief Mask the TA interrupt. + * @param[in] void + * @return Void + */ +/// @private +void rsi_mask_ta_interrupt(void) +{ +#ifdef RSI_M4_INTERFACE + // mask P2P interrupt + mask_ta_interrupt(TX_PKT_TRANSFER_DONE_INTERRUPT | RX_PKT_TRANSFER_DONE_INTERRUPT); +#else + rsi_hal_intr_mask(); +#endif +} +/*===================================================*/ +/** + * @fn void rsi_unmask_ta_interrupt(void) + * @brief Unmask the TA interrupt. + * @param[in] void + * @return Void + */ +/// @private +void rsi_unmask_ta_interrupt(void) +{ +#ifdef RSI_M4_INTERFACE + // unmask P2P interrupt + unmask_ta_interrupt(TX_PKT_TRANSFER_DONE_INTERRUPT | RX_PKT_TRANSFER_DONE_INTERRUPT); +#else + rsi_hal_intr_unmask(); +#endif +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_driver_event_handlers.c b/wiseconnect/sapi/driver/rsi_driver_event_handlers.c new file mode 100644 index 00000000..a74c0daf --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_driver_event_handlers.c @@ -0,0 +1,1080 @@ +/******************************************************************************* +* @file rsi_driver_event_handlers.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/** + * Includes + * */ + +#include "rsi_driver.h" +#ifdef RSI_UART_INTERFACE +#include "rsi_uart.h" +#endif +#ifdef RSI_M4_INTERFACE +#include "rsi_m4.h" +#endif +#ifdef LINUX_PLATFORM +#if (defined(RSI_USB_INTERFACE) || defined(RSI_SDIO_INTERFACE)) +#include "rsi_linux_app_init.h" +#endif +#endif +#include "rsi_wlan_non_rom.h" +#include "rsi_sdio.h" +#include "rsi_pkt_mgmt.h" + +// Sleep Ack frame +const uint8_t rsi_sleep_ack[RSI_FRAME_DESC_LEN] = { 0x00, 0x40, 0xDE, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +#if (((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) && (RSI_ASSERT_ENABLE)) +#endif +rsi_driver_cb_non_rom_t *rsi_driver_cb_non_rom = NULL; + +#define COMMON_PKT 1 +#define BT_BLE_STACK_PACKET 2 +#define BT_PKT 3 +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define PROP_PROTOCOL_PKT 4 +#endif +#define ZB_PKT 5 +#define WLAN_PKT 6 +uint8_t rsi_get_intr_status(void); +/** @addtogroup DRIVER8 +* @{ +*/ +/*==============================================*/ +/** + * @fn void rsi_tx_event_handler(void) + * @brief Retrieve the packet from the TX pending queue and forward to the module. + * and forwards to the module. + * @param[in] void + * @return Void + * + */ + +void rsi_tx_event_handler(void) +{ + rsi_pkt_t *pkt = NULL; + uint8_t *buf_ptr; + uint16_t length = 0; + + //To remove the warning type condition always true, the status variable declared to int16_t. + int16_t status = 0; +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + int16_t ret_status = 0; + uint8_t int_status = 0; +#endif + + //Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + uint8_t common_pkt_pending = 0; + uint8_t bt_pkt_pending = 0; +#ifdef SAPIS_BT_STACK_ON_HOST + uint8_t bt_ble_stack_pkt_pending = 0; +#endif + uint8_t wlan_pkt_pending = 0; + uint8_t zb_pkt_pending = 0; +#ifdef RSI_PROP_PROTOCOL_ENABLE + uint8_t prop_protocol_pkt_pending = 0; +#endif + uint8_t queueno = 0xff; + uint8_t frame_type = 0x00; + uint8_t pkt_dequeued = 0xff; + +#if ((defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) \ + && (defined RSI_M4_INTERFACE)) + rsi_bt_cb_t *bt_cb; +#endif + +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + if (!rsi_driver_cb_non_rom->driver_timer_start) { + rsi_init_timer(&rsi_driver_cb_non_rom->timer_start, RSI_TX_EVENT_WAIT_TIME); + rsi_driver_cb_non_rom->driver_timer_start = 1; + } + if ((rsi_timer_expired(&rsi_driver_cb_non_rom->timer_start)) && (rsi_driver_cb_non_rom->driver_timer_start == 1)) { + rsi_error_timeout_and_clear_events(RSI_ERROR_TX_BUFFER_FULL, TX_EVENT_CMD); + return; + } +#endif + +#ifdef RSI_M4_INTERFACE + + if (rsi_driver_cb->rsi_tx_done_handler != NULL) { + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->m4_tx_q); + rsi_driver_cb->rsi_tx_done_handler(pkt); + rsi_driver_cb->rsi_tx_done_handler = NULL; + pkt = NULL; + } +#endif + /* First Check for Common Queue */ + common_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->common_tx_q); +#ifdef SAPIS_BT_STACK_ON_HOST + // check for packet pending in bt/ble stack common queue + if ((&rsi_driver_cb->bt_single_tx_q)->head != NULL) { + bt_ble_stack_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->bt_single_tx_q); + } + +#else +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + // check for packet pending in bt/ble common queue + if ((&rsi_driver_cb->bt_single_tx_q)->head != NULL) { + bt_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->bt_single_tx_q); + } +#endif +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + // check for packet pending in prop_protocol queue + if ((&rsi_driver_cb->prop_protocol_tx_q)->head != NULL) { + prop_protocol_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->prop_protocol_tx_q); + } +#endif + +#ifdef RSI_ZB_ENABLE + // check for packet pending in zb queue + zb_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->zigb_tx_q); +#endif + + // check for packet pending in wlan queue + wlan_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->wlan_tx_q); + + if (rsi_common_cb->power_save.power_save_enable + && (common_pkt_pending || wlan_pkt_pending || bt_pkt_pending +#ifdef RSI_PROP_PROTOCOL_ENABLE + || prop_protocol_pkt_pending +#endif + || zb_pkt_pending)) { +#ifdef RSI_M4_INTERFACE + P2P_STATUS_REG |= M4_wakeup_TA; + P2P_STATUS_REG; + P2P_STATUS_REG; + P2P_STATUS_REG; + if (!(P2P_STATUS_REG & TA_is_active)) { + while (!(P2P_STATUS_REG & TA_is_active)) + ; + } +#endif +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + // request wakeup if module is in GPIO_BASED handshake power save +#if (RSI_WMM_PS_ENABLE && RSI_WMM_PS_TYPE) + status = rsi_wait4wakeup(); + if (status != 0) { +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(status, TX_EVENT_CMD); +#endif + return; + } +#else + status = rsi_req_wakeup(); + if (status != 0) { +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(status, TX_EVENT_CMD); +#endif + return; + } +#endif +#else +#if (RSI_ULP_MODE == 1) + rsi_ulp_wakeup_init(); +#endif +#endif + } + +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) \ + || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + if (bt_pkt_pending +#ifdef RSI_PROP_PROTOCOL_ENABLE + || prop_protocol_pkt_pending +#endif + ) { +#ifdef RSI_BT_ENABLE + // Read packet from BT/BLE Common Queue + pkt = (rsi_pkt_t *)(rsi_driver_cb->bt_single_tx_q.head); + + /* GAR-8247: Check for the Null Pointer and proceed with Buffer full checks */ + if (pkt != NULL) { + buf_ptr = (uint8_t *)pkt->desc; + + // Get Frame type + frame_type = buf_ptr[2]; + } +#endif + // Read interrupt status register to check buffer full condition + ret_status = rsi_device_interrupt_status(&int_status); + + // if buffer full then return without clearing Tx event + if ((ret_status != 0x0) +#ifdef RSI_BT_ENABLE + || ((int_status & (BIT(1))) + && (rsi_bt_get_ACL_type(frame_type) == RSI_BT_HCI_ACL_PKT)) /* Check for ACL Packet Buffer full Condition */ +#endif +#if ((defined RSI_BT_ENABLE) || (defined RSI_BLE_ENABLE)) + || ((int_status & (BIT(4))) /* Check for Command Pool Buffer full Condition */ +#ifdef RSI_BT_ENABLE + // ACL Packets should not blocked by Command Buffer Full Condition + && (!(frame_type == RSI_BT_REQ_A2DP_SBC_AAC_DATA) || (frame_type == RSI_BT_REQ_SPP_TRANSFER)) +#endif + ) +#endif +#ifdef RSI_BLE_ENABLE + || (int_status & (BIT(2))) +#endif + ) { + if (ret_status != 0x0) { +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(ret_status, TX_EVENT_CMD); +#endif + return; + } + bt_pkt_pending = 0; +#ifdef RSI_PROP_PROTOCOL_ENABLE + if (int_status & BIT(4)) { + prop_protocol_pkt_pending = 0; + } +#endif + // Mask the TX event until RX event is served + if (rsi_driver_cb->scheduler_cb.event_map & ~(BIT(RSI_TX_EVENT))) { + // masking the tx event + rsi_mask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 1; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } + } + } +#endif +#endif + + if (common_pkt_pending) { +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) \ + || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + rsi_driver_cb->rsi_tx_done_handler = &rsi_common_packet_transfer_done; + // Read interrupt status register to check buffer full condition + ret_status = rsi_device_interrupt_status(&int_status); + + // if buffer full then return without clearing Tx event + if ((ret_status != 0x0) || (int_status & RSI_BUFFER_FULL)) { + if (ret_status != 0x0) { +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(ret_status, TX_EVENT_CMD); +#endif + return; + } + // Mask the TX event until RX event is served + if (rsi_driver_cb->scheduler_cb.event_map & ~(BIT(RSI_TX_EVENT))) { + // masking the tx event + rsi_mask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 1; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } +#if BUFFER_FULL_HANDLING + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->common_tx_q); + + rsi_check_common_buffer_full(pkt); +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_timer_start = 0; +#endif + // if fail , return or + // if buffer full then return without clearing Tx event + return; +#else + // if buffer full then return without clearing Tx event + return; +#endif + } +#endif + + // if packet pending dequeue the packet from common queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->common_tx_q); + + pkt_dequeued = COMMON_PKT; + } +#ifdef BT_STACK_ON_FREERTOS + else if (bt_ble_stack_pkt_pending) { +#ifdef RSI_M4_INTERFACE + rsi_driver_cb->rsi_tx_done_handler = &bt_tx_pkt_free; +#endif + // if packet pending dequeue the packet from bt/ble common queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->bt_single_tx_q); + pkt_dequeued = BT_BLE_STACK_PACKET; + } +#else +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + else if (bt_pkt_pending) { + // if packet pending dequeue the packet from bt/ble common queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->bt_single_tx_q); + pkt_dequeued = BT_PKT; + +#ifdef RSI_M4_INTERFACE + rsi_bt_get_proto_type(rsi_bytes2R_to_uint16(((uint8_t *)(pkt->desc)) + RSI_BT_RSP_TYPE_OFFSET), &bt_cb); + rsi_driver_cb->rsi_tx_done_handler = &rsi_bt_common_tx_done; +#endif + } +#endif +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (prop_protocol_pkt_pending) { + // if packet pending dequeue the packet from prop_protocol queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->prop_protocol_tx_q); + pkt_dequeued = PROP_PROTOCOL_PKT; +#ifdef RSI_M4_INTERFACE + rsi_bt_get_proto_type(rsi_bytes2R_to_uint16(((uint8_t *)(pkt->desc)) + RSI_BT_RSP_TYPE_OFFSET), &bt_cb); + rsi_driver_cb->rsi_tx_done_handler = &rsi_prop_protocol_common_tx_done; +#endif + } +#endif +#ifdef RSI_ZB_ENABLE + else if (zb_pkt_pending) { +#ifdef RSI_M4_INTERFACE + rsi_driver_cb->rsi_tx_done_handler = &rsi_zb_tx_done; +#endif + // if packet pending dequeue the packet from zb queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->zigb_tx_q); + pkt_dequeued = ZB_PKT; + } +#endif + else if (wlan_pkt_pending) { +#ifdef RSI_WLAN_ENABLE +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) \ + || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + // Read interrupt status register to check buffer full condition + ret_status = rsi_device_interrupt_status(&int_status); + + // if buffer full then return without clearing Tx event + if ((ret_status != 0x0) || (int_status & RSI_BUFFER_FULL)) { + if (ret_status != 0x0) { +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(ret_status, TX_EVENT_CMD); +#endif + return; + } + // Mask the TX event until RX event is served + if (rsi_driver_cb->scheduler_cb.event_map & ~(BIT(RSI_TX_EVENT))) { + // masking the tx event + rsi_mask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 1; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } + +#if BUFFER_FULL_HANDLING + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->wlan_tx_q); +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_timer_start = 0; +#endif + rsi_check_wlan_buffer_full(pkt); + // if fail , return or + // if buffer full then return without clearing Tx event + return; +#else + // if buffer full then return without clearing Tx event + return; +#endif + } + +#endif + // dequeue the packet from wlan queue + pkt = (rsi_pkt_t *)rsi_dequeue_pkt(&rsi_driver_cb->wlan_tx_q); + pkt_dequeued = WLAN_PKT; +#ifdef RSI_M4_INTERFACE + rsi_driver_cb->rsi_tx_done_handler = &rsi_wlan_packet_transfer_done; +#endif +#endif + } + + // Check any packet pending in protocol queue +#ifdef BT_STACK_ON_FREERTOS + if (common_pkt_pending || wlan_pkt_pending || zb_pkt_pending || bt_ble_stack_pkt_pending) +#else + if (common_pkt_pending || wlan_pkt_pending || bt_pkt_pending +#ifdef RSI_PROP_PROTOCOL_ENABLE + || prop_protocol_pkt_pending +#endif + || zb_pkt_pending) +#endif + { +#ifdef RSI_M4_INTERFACE + if (rsi_driver_cb->rsi_tx_done_handler) { + rsi_enqueue_pkt(&rsi_driver_cb->m4_tx_q, pkt); + } +#endif + buf_ptr = (uint8_t *)pkt->desc; + + // Get Frame type + frame_type = buf_ptr[2]; + + // Get protocol type + queueno = (buf_ptr[1] & 0xf0) >> 4; + + // Get packet length + length = (*(uint16_t *)buf_ptr & 0x0FFF); + if ((frame_type == RSI_COMMON_REQ_PWRMODE) && (queueno == RSI_WLAN_MGMT_Q)) { + // Mask Tx events while sending pwr mode req + rsi_mask_event(RSI_TX_EVENT); + + // Adding small delay + rsi_delay_ms(3); + } +#ifdef RSI_M4_INTERFACE + rsi_mask_event(RSI_TX_EVENT); +#endif + // Writing to Module + status = rsi_frame_write((rsi_frame_desc_t *)buf_ptr, &buf_ptr[RSI_HOST_DESC_LENGTH], length); + if (status < 0x0) { +#ifndef RSI_FREE_QUEUE_PKT + rsi_free_queue_pkt(pkt_dequeued, pkt); +#endif +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(status, TX_EVENT_CMD); + +#endif + SL_PRINTF(SL_RSI_ERROR_TIMEOUT, + BLUETOOTH, + LOG_ERROR, + "STATUS: %4x, length: %2x, queue_number: %1x", + status, + length, + queueno); + SL_PRINTF(SL_RSI_ERROR_TIMEOUT_FRAME_TYPE, BLUETOOTH, LOG_ERROR, "Frame_type: %1x", frame_type); + + return; + } +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_timer_start = 0; +#endif +#ifdef RSI_M4_INTERFACE + if ((queueno == RSI_WLAN_MGMT_Q) && (frame_type == RSI_COMMON_REQ_SOFT_RESET)) { + rsi_config_m4_dma_desc_on_reset(); + } + if (pkt_dequeued == COMMON_PKT) { + // free the packet + rsi_pkt_free(&rsi_driver_cb->common_cb->common_tx_pool, pkt); + // signal semaphore incase of packet having async response + rsi_common_packet_transfer_done(pkt); + } + return; +#endif +#ifndef RSI_M4_INTERFACE + if (pkt_dequeued == COMMON_PKT) { + // free the packet + rsi_pkt_free(&rsi_driver_cb->common_cb->common_tx_pool, pkt); + // signal semaphore incase of packet having async response + rsi_common_packet_transfer_done(pkt); + } else +#endif + if (pkt_dequeued == WLAN_PKT) { +#ifdef RSI_WLAN_ENABLE + if ((queueno == RSI_WLAN_MGMT_Q) || (queueno == RSI_WLAN_DATA_Q)) { + // signal semaphore incase of packet having async response + rsi_wlan_packet_transfer_done(pkt); + } +#endif + } else if (pkt_dequeued == BT_PKT) { +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + if (queueno == RSI_BT_Q) { + rsi_bt_common_tx_done(pkt); + } +#endif + } +#ifdef RSI_PROP_PROTOCOL_ENABLE + else if (pkt_dequeued == PROP_PROTOCOL_PKT) { + if (queueno == RSI_BT_Q) { + rsi_prop_protocol_common_tx_done(pkt); + } + } +#endif +#ifdef BT_STACK_ON_FREERTOS + else if (pkt_dequeued == BT_BLE_STACK_PACKET) { + if ((queueno == RSI_BT_INT_MGMT_Q) || (queueno == RSI_BT_HCI_Q)) { + int_status = bt_tx_pkt_free(pkt); + + if (int_status != 0) + breakpt(); + } + } +#endif + else if (pkt_dequeued == ZB_PKT) { +#ifdef RSI_ZB_ENABLE + if (queueno == RSI_ZB_Q) { + rsi_zb_tx_done(pkt); + } +#endif + } + } else { + +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) + /* REVIEW : reviewed by siva. */ + if ((&rsi_driver_cb->bt_single_tx_q)->head != NULL) { + bt_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->bt_single_tx_q); + + if (bt_pkt_pending) { +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) \ + || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + // Read interrupt status register to check buffer full condition + ret_status = rsi_device_interrupt_status(&int_status); + + // if buffer full then return without clearing Tx event + if ((ret_status != 0x0) +#ifdef RSI_BT_ENABLE + || ((int_status & (BIT(1))) + && (rsi_bt_get_ACL_type(frame_type) + == RSI_BT_HCI_ACL_PKT)) /* Check for ACL Packet Buffer full Condition */ +#endif +#if ((defined RSI_BT_ENABLE) || (defined RSI_BLE_ENABLE)) + || ((int_status & (BIT(4))) /* Check for Command Pool Buffer full Condition */ +#ifdef RSI_BT_ENABLE + // ACL Packets should not blocked by Command Buffer Full Condition + && (!(frame_type == RSI_BT_REQ_A2DP_SBC_AAC_DATA) || (frame_type == RSI_BT_REQ_SPP_TRANSFER)) +#endif + ) +#endif +#ifdef RSI_BLE_ENABLE + || (int_status & (BIT(2))) +#endif + ) { + //do nothing + } else +#endif + { + return; + } + } + } +#ifdef RSI_PROP_PROTOCOL_ENABLE + if ((&rsi_driver_cb->prop_protocol_tx_q)->head != NULL) { + prop_protocol_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->prop_protocol_tx_q); + + if (prop_protocol_pkt_pending) { + return; + } + } +#endif +#endif +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_timer_start = 0; +#endif + + if (rsi_common_cb->power_save.power_save_enable) { +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + + // Keep Sleep confirm GPIO low + rsi_allow_sleep(); + +#elif defined(RSI_M4_INTERFACE) && (RSI_HAND_SHAKE_TYPE == M4_BASED) + rsi_allow_sleep(); +#elif (RSI_HAND_SHAKE_TYPE == MSG_BASED) + + if (rsi_common_cb->power_save.module_state == RSI_SLP_RECEIVED) { + // Send ACK if POWERMODE 3 and 9,incase of powermode 2 and 8 make GPIO low + if (rsi_frame_write((rsi_frame_desc_t *)rsi_sleep_ack, NULL, 0)) { + // Handle failure + } + rsi_mask_event(RSI_TX_EVENT); + rsi_common_cb->power_save.module_state = RSI_SLP_ACK_SENT; + } +#endif + } + +#ifndef RSI_M4_INTERFACE + // signal semaphore incase of packet having async response + rsi_common_packet_transfer_done(pkt); +#endif + rsi_clear_event(RSI_TX_EVENT); + } +} +/** @} */ + +/** @addtogroup DRIVER5 +* @{ +*/ + +/*==============================================*/ +/** + * @fn void rsi_rx_event_handler(void) + * @brief Read and process the RX packet from the module + * @param[in] void + * @return Void + * + */ + +void rsi_rx_event_handler(void) +{ + uint8_t queue_no; + uint8_t frame_type; + uint16_t status = 0; + uint8_t *buf_ptr = NULL; + rsi_pkt_t *rx_pkt = NULL; + uint8_t int_status = 0; + +#if RSI_ASSERT_ENABLE +#if ((defined RSI_SPI_INTERFACE) || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + uint32_t assert_val = 0; + uint32_t assert_intr_clear = 0; +#endif +#endif +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) + uint32_t actual_offset = 0; +#endif +#ifndef RSI_M4_INTERFACE + uint16_t ret_status = 0; +#endif + + //Get commmon cb pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + //rsi_wlan_cb variable is not so to avoid unused variable warning the below code is commented + + //#if (((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE))) + // Get wlan cb structure pointer + // rsi_wlan_cb_t *rsi_wlan_cb = rsi_driver_cb->wlan_cb; + //#endif + +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + if (!rsi_driver_cb_non_rom->driver_rx_timer_start) { + rsi_init_timer(&rsi_driver_cb_non_rom->rx_timer_start, RSI_RX_EVENT_WAIT_TIME); + rsi_driver_cb_non_rom->driver_rx_timer_start = 1; + } + if ((rsi_timer_expired(&rsi_driver_cb_non_rom->rx_timer_start)) + && (rsi_driver_cb_non_rom->driver_rx_timer_start == 1)) { + rsi_error_timeout_and_clear_events(RSI_ERROR_RESPONSE_TIMEOUT, RX_EVENT_CMD); + return; + } +#endif +#if ((defined RSI_SPI_INTERFACE) || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (!rsi_get_intr_status()) { + + rsi_clear_event(RSI_RX_EVENT); + rsi_hal_intr_unmask(); + if (rsi_get_intr_status()) { + // Set RX event + rsi_set_event(RSI_RX_EVENT); + } + if (rsi_driver_cb_non_rom->tx_mask_event == 1) { + rsi_unmask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 0; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_rx_timer_start = 0; +#endif + return; + } +#endif + if (rsi_common_cb->power_save.power_save_enable) { +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + // request wakeup if module is in GPIO_BASED handshake power save +#if (RSI_WMM_PS_ENABLE && RSI_WMM_PS_TYPE) + status = rsi_wait4wakeup(); + if (status != 0) { +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(status, RX_EVENT_CMD); +#endif + return; + } +#else + status = rsi_req_wakeup(); + if (status != 0) { +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(status, RX_EVENT_CMD); +#endif + return; + } + //rsi_delay_ms(5); +#endif +#elif (RSI_HAND_SHAKE_TYPE == MSG_BASED) +#if (RSI_SELECT_LP_OR_ULP_MODE != RSI_LP_MODE) +#ifdef RSI_SPI_INTERFACE + rsi_ulp_wakeup_init(); +#endif +#endif +#endif +#endif + } +#if (RSI_SPI_DUP_INTR_HANDLE || RSI_ASSERT_ENABLE) + ret_status = rsi_device_interrupt_status(&int_status); + if (ret_status != 0x0) { + // if SPI fail then return +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(ret_status, RX_EVENT_CMD); +#endif + return; + } +#endif //! (RSI_SPI_DUP_INTR_HANDLE || RSI_ASSERT_ENABLE) +#if RSI_ASSERT_ENABLE + // Check for assertion interrupt + if (int_status & RSI_ASSERT_INTR) { + int_status &= (~RSI_ASSERT_INTR); + ret_status = rsi_mem_rd(RSI_ASSERT_VAL_RD_REG, 4, (uint8_t *)&assert_val); + if (ret_status == RSI_SUCCESS) { + if (rsi_wlan_cb_non_rom->callback_list.rsi_assertion_cb != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.rsi_assertion_cb(assert_val, NULL, 0); + } + assert_intr_clear = RSI_ASSERT_INTR; + ret_status = rsi_mem_wr(RSI_ASSERT_INTR_CLR_REG, 4, (uint8_t *)&assert_intr_clear); + } + if (ret_status != 0x0) { + // if SPI fail then return +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_error_timeout_and_clear_events(ret_status, RX_EVENT_CMD); +#endif + return; + } + } +#endif //! (RSI_ASSERT_ENABLE) + if (!(int_status & RSI_RX_PKT_PENDING)) { + rsi_clear_event(RSI_RX_EVENT); + rsi_hal_intr_unmask(); +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_get_intr_status()) { + // Set RX event + rsi_set_event(RSI_RX_EVENT); + } +#endif + +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_driver_cb_non_rom->tx_mask_event == 1) { + rsi_unmask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 0; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } +#endif + if (rsi_common_cb->power_save.power_save_enable) { +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + rsi_allow_sleep(); +#endif + } +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_rx_timer_start = 0; +#endif + return; + } +#endif +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) +#else +#ifndef RSI_M4_INTERFACE + // Allocate packet to receive packet from module + rx_pkt = rsi_pkt_alloc(&rsi_driver_cb->rx_pool); + if (rx_pkt == NULL) { + // rx_pkt not available mask rx event +#ifndef RSI_ENABLE_DEMOS + rsi_mask_event(RSI_RX_EVENT); +#endif + return; + } + + buf_ptr = (uint8_t *)rx_pkt->desc; + +#endif +#endif + +#ifdef RSI_M4_INTERFACE + rx_pkt = (rsi_pkt_t *)rsi_frame_read(); + buf_ptr = (uint8_t *)&rx_pkt->desc[0]; +#elif ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) + status = (uint16_t)rsi_frame_read(&rsi_driver_cb_non_rom->sdio_read_buff[SIZE_OF_HEADROOM]); +#else + // Read packet from module + status = rsi_frame_read(buf_ptr); +#endif + // Allow Power save again + if (rsi_common_cb->power_save.power_save_enable) { +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + rsi_allow_sleep(); +#endif + } + if (status) { +#ifdef LINUX_PLATFORM +#ifdef RSI_UART_INTERFACE + if (!rsi_check_queue_status(&rsi_linux_app_cb.rcv_queue)) +#endif +#if (defined(RSI_USB_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + if (rsi_linux_driver_app_cb.rcv_queue.pending_pkt_count == 0) +#endif +#endif + rsi_clear_event(RSI_RX_EVENT); +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) +// rx_pkt is not from pool, so not freeing +#else + rsi_pkt_free(&rsi_driver_cb->rx_pool, rx_pkt); +#endif +#ifndef RSI_M4_INTERFACE + rsi_hal_intr_unmask(); +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_get_intr_status()) { + // Set RX event + rsi_set_event(RSI_RX_EVENT); + } +#endif +#endif +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_driver_cb_non_rom->tx_mask_event == 1) { + rsi_unmask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 0; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } +#endif +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_rx_timer_start = 0; +#endif + SL_PRINTF(SL_RSI_ERROR_TIMEOUT_READ, BLUETOOTH, LOG_ERROR, "STATUS: %4x", status); + + return; + } + +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) + actual_offset = rsi_driver_cb_non_rom->sdio_read_buff[2 + SIZE_OF_HEADROOM]; + actual_offset |= (rsi_driver_cb_non_rom->sdio_read_buff[3 + SIZE_OF_HEADROOM] << 8); + buf_ptr = (uint8_t *)&rsi_driver_cb_non_rom->sdio_read_buff[actual_offset + SIZE_OF_HEADROOM]; + rx_pkt = (rsi_pkt_t *)(buf_ptr - 4 - SIZE_OF_HEADROOM); +#endif +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + rsi_driver_cb_non_rom->driver_rx_timer_start = 0; +#endif + if (rsi_driver_cb_non_rom->rx_driver_flag) { + rsi_driver_cb_non_rom->rx_driver_flag = 0; + } + // Extract the queue number from the receivec frame + queue_no = ((buf_ptr[1] & 0xF0) >> 4); + + // Extract the frame type from the received frame + frame_type = *(uint8_t *)(buf_ptr + RSI_RESP_OFFSET); +#if (RSI_HAND_SHAKE_TYPE == GPIO_BASED) + rsi_handle_slp_wkp(frame_type); +#endif +#if (RSI_HAND_SHAKE_TYPE != GPIO_BASED) + if ((queue_no == RSI_WLAN_MGMT_Q) + && ((frame_type == RSI_COMMON_RSP_ULP_NO_RAM_RETENTION) || (frame_type == RSI_RSP_SLP) + || (frame_type == RSI_RSP_WKP))) { + rsi_handle_slp_wkp(frame_type); +#ifndef RSI_M4_INTERFACE +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) +#else + rsi_pkt_free(&rsi_driver_cb->rx_pool, rx_pkt); +#endif +#ifdef LINUX_PLATFORM +#if RSI_UART_INTERFACE + if (!rsi_check_queue_status(&rsi_linux_app_cb.rcv_queue)) +#endif +#if (defined(RSI_USB_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + if (rsi_linux_driver_app_cb.rcv_queue.pending_pkt_count == 0) +#endif +#endif + rsi_clear_event(RSI_RX_EVENT); + // Unmask RX event + rsi_unmask_event(RSI_RX_EVENT); + + rsi_hal_intr_unmask(); +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_driver_cb_non_rom->tx_mask_event == 1) { + rsi_unmask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 0; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } +#endif + return; +#endif + } +#endif + if (((queue_no == RSI_WLAN_MGMT_Q) + && ((frame_type == RSI_COMMON_RSP_CARDREADY) || (frame_type == RSI_COMMON_RSP_OPERMODE) + || (frame_type == RSI_COMMON_RSP_PWRMODE) || (frame_type == RSI_COMMON_RSP_ANTENNA_SELECT) + || (frame_type == RSI_COMMON_RSP_FEATURE_FRAME) || (frame_type == RSI_COMMON_RSP_SOFT_RESET) + || (frame_type == RSI_COMMON_REQ_UART_FLOW_CTRL_ENABLE) || (frame_type == RSI_COMMON_RSP_FW_VERSION) + || (frame_type == RSI_COMMON_RSP_DEBUG_LOG) || (frame_type == RSI_COMMON_RSP_SWITCH_PROTO) + || (frame_type == RSI_COMMON_RSP_GET_RAM_DUMP) || (frame_type == RSI_COMMON_RSP_SET_RTC_TIMER) + || (frame_type == RSI_COMMON_RSP_GET_RTC_TIMER) || (frame_type == RSI_COMMON_REQ_SET_CONFIG) + || (frame_type == RSI_COMMON_RSP_MODULE_TYPE) +#ifdef FW_LOGGING_ENABLE + || (frame_type == RSI_COMMON_RSP_DEVICE_LOGGING_INIT) +#endif +#ifdef RSI_ASSERT_API + || (frame_type == RSI_COMMON_RSP_ASSERT) +#endif +#ifdef RSI_M4_INTERFACE + || (frame_type == RSI_COMMON_RSP_TA_M4_COMMANDS) +#endif +#ifdef RSI_WAC_MFI_ENABLE + || (frame_type == RSI_COMMON_RSP_IAP_INIT) || (frame_type == RSI_COMMON_RSP_IAP_GET_CERTIFICATE) + || (frame_type == RSI_COMMON_RSP_IAP_GENERATE_SIGATURE) +#endif +#ifdef RSI_PUF_ENABLE + || (frame_type == RSI_COMMON_RSP_PUF_DIS_ENROLL) || (frame_type == RSI_COMMON_RSP_PUF_DIS_GET_KEY) + || (frame_type == RSI_COMMON_RSP_PUF_DIS_SET_KEY) || (frame_type == RSI_COMMON_RSP_PUF_ENROLL) + || (frame_type == RSI_COMMON_RSP_PUF_GET_KEY) || (frame_type == RSI_COMMON_RSP_PUF_LOAD_KEY) + || (frame_type == RSI_COMMON_RSP_PUF_SET_KEY) || (frame_type == RSI_COMMON_RSP_PUF_START) + || (frame_type == RSI_COMMON_RSP_AES_DECRYPT) || (frame_type == RSI_COMMON_RSP_AES_ENCRYPT) + || (frame_type == RSI_COMMON_RSP_AES_MAC) || (frame_type == RSI_COMMON_RSP_PUF_INTR_KEY) +#endif +#ifdef RSI_CRYPTO_ENABLE + || (frame_type == RSI_RSP_ENCRYPT_CRYPTO) +#endif + ) +#ifdef CONFIGURE_GPIO_FROM_HOST + || (frame_type == RSI_COMMON_RSP_GPIO_CONFIG) +#endif + ) +#ifdef FW_LOGGING_ENABLE + || ((queue_no == RSI_SL_LOG_DATA_Q) && (frame_type == RSI_COMMON_RSP_DEVICE_LOGGING_INIT)) +#endif + ) { + // Process common packet + rsi_driver_process_common_recv_cmd(rx_pkt); + } +#ifdef SAPIS_BT_STACK_ON_HOST + else if ((queue_no == RSI_BT_INT_MGMT_Q) || (queue_no == RSI_BT_HCI_Q) || (queue_no == RSI_ZB_Q)) +#else + else if ((queue_no == RSI_BT_Q) || (queue_no == RSI_ZB_Q)) +#endif + { + // Process BT/ZB packet +#ifdef RSI_ZB_ENABLE + rsi_driver_process_zigb_recv_cmd(rx_pkt); +#endif +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) +#ifdef SAPIS_BT_STACK_ON_HOST + if ((queue_no == RSI_BT_INT_MGMT_Q) || (queue_no == RSI_BT_HCI_Q)) { + + //Post Packet to BT Stack + frame_from_module_to_bt_stack(rx_pkt); + } else +#endif + { + rsi_driver_process_bt_resp_handler(rx_pkt); + } +#endif + } +#ifdef RSI_WLAN_ENABLE + else if (queue_no == RSI_WLAN_MGMT_Q) { + // Process WLAN packet + rsi_driver_process_wlan_recv_cmd(rx_pkt); + } else if (queue_no == RSI_WLAN_DATA_Q) { +#if (RSI_TCP_IP_BYPASS || TCP_IP_ETHERNET_BRIDGE) + // Process Raw DATA packet + rsi_wlan_process_raw_data(rx_pkt); +#elif RSI_ENABLE_DUAL_HOST + if (frame_type == DUAL_HOST_RAW_DATA_PACKET) { + // Process Raw DATA packet - dual host enabled + rsi_wlan_process_raw_data(rx_pkt); + } else { + // Process DATA packet + rsi_driver_process_recv_data(rx_pkt); + } +#else + // Process DATA packet + rsi_driver_process_recv_data(rx_pkt); +#endif + } +#endif + +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) +#else + // Free the packet after processing + rsi_pkt_free(&rsi_driver_cb->rx_pool, rx_pkt); +#endif +#ifdef LINUX_PLATFORM +#ifdef RSI_UART_INTERFACE + if (!rsi_check_queue_status(&rsi_linux_app_cb.rcv_queue)) +#endif +#if (defined(RSI_USB_INTERFACE) || defined(RSI_SDIO_INTERFACE)) + if (rsi_linux_driver_app_cb.rcv_queue.pending_pkt_count == 0) +#endif +#endif +#ifdef RSI_M4_INTERFACE + + mask_ta_interrupt(RX_PKT_TRANSFER_DONE_INTERRUPT); + + if (!rsi_check_queue_status(&global_cb_p->rsi_driver_cb->m4_rx_q)) +#endif +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (!rsi_get_intr_status()) +#endif + { + // Clear RX event + rsi_clear_event(RSI_RX_EVENT); + } +#if !THROUGHPUT_EN +#if RSI_SPI_DUP_INTR_HANDLE + if (!rsi_common_cb->power_save.power_save_enable) { + // Read interrupt status register + ret_status = rsi_device_interrupt_status(&int_status); + // Check packet pending in interrupt status register + if (int_status & RSI_RX_PKT_PENDING) { + rsi_set_event(RSI_RX_EVENT); + return; + } + } +#endif +#endif + // Unmask RX event + rsi_unmask_event(RSI_RX_EVENT); +#ifdef RSI_M4_INTERFACE + // submit to TA submit packet + rsi_submit_rx_pkt(); + + unmask_ta_interrupt(RX_PKT_TRANSFER_DONE_INTERRUPT); +#endif +#ifndef RSI_M4_INTERFACE + rsi_hal_intr_unmask(); +#endif + +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_get_intr_status()) { + // Set RX event + rsi_set_event(RSI_RX_EVENT); + } +#endif +#if ((defined RSI_SPI_INTERFACE) || (defined RSI_M4_INTERFACE) || (defined RSI_SDIO_INTERFACE)) + if (rsi_driver_cb_non_rom->tx_mask_event == 1) { + rsi_unmask_event(RSI_TX_EVENT); + // lock the mutex + rsi_mutex_lock(&rsi_driver_cb_non_rom->tx_mutex); + rsi_driver_cb_non_rom->tx_mask_event = 0; + // unlock mutex + rsi_mutex_unlock(&rsi_driver_cb_non_rom->tx_mutex); + } +#endif + + return; +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_events.c b/wiseconnect/sapi/driver/rsi_events.c new file mode 100644 index 00000000..12d1f276 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_events.c @@ -0,0 +1,324 @@ +/******************************************************************************* +* @file rsi_events.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ +#include "rsi_driver.h" + +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) +extern rsi_task_handle_t driver_task_handle; +/* + Global Variables + */ +/** @addtogroup DRIVER8 +* @{ +*/ +/*====================================================*/ +/** + * @fn void rsi_set_event_non_rom( uint32_t event_num) + * @brief Set an event + * @param[in] event_num - event number to be set + * @return void + */ +///@private +void rsi_set_event_non_rom(uint32_t event_num) +{ + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + +#ifdef RSI_M4_INTERFACE + // mask P2P interrupt + RSI_MASK_TA_INTERRUPT(); +#endif + + // Set the event bit in bitmap + rsi_driver_cb->scheduler_cb.event_map |= BIT(event_num); + +#ifdef RSI_M4_INTERFACE + // unmask P2P interrupt + RSI_UNMASK_TA_INTERRUPT(); +#endif + + if (global_cb_p->os_enabled == 1) { + // notify to driver task + rsi_task_notify(driver_task_handle, BIT(event_num)); + } +} + +/*====================================================*/ +/** + * @fn void rsi_set_event_from_isr_non_rom(uint32_t event_num) + * @brief Set an event from ISR + * @param[in] uint32_t event_num - event number to be set + * @return void + */ +///@private +void rsi_set_event_from_isr_non_rom(uint32_t event_num) +{ + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + + // Set the event bit in scheduler bitmap + rsi_driver_cb->scheduler_cb.event_map |= BIT(event_num); + + rsi_task_notify_from_isr(driver_task_handle, BIT(event_num), NULL); +} + +/*====================================================*/ +/** + * @fn void rsi_unmask_event_from_isr_non_rom(uint32_t event_num) + * @brief Unmask an event from ISR + * @param[in] uint32_t event_num - event number to unmask + * @return void + */ +///@private +void rsi_unmask_event_from_isr_non_rom(uint32_t event_num) +{ + // set event bit in mask bitmap + global_cb_p->rsi_driver_cb->scheduler_cb.mask_map |= BIT(event_num); + + // notify to driver task + rsi_task_notify_from_isr(driver_task_handle, BIT(event_num), NULL); +} + +/*====================================================*/ +/** + * @fn void rsi_unmask_event_non_rom(uint32_t event_num) + * @brief Unmask an event + * @param[in] event_num - event number to unmask + * @return void + */ +///@private +void rsi_unmask_event_non_rom(uint32_t event_num) +{ +#ifdef RSI_M4_INTERFACE + // mask P2P interrupt + RSI_MASK_TA_INTERRUPT(); +#endif + + // set event bit in mask bitmap + global_cb_p->rsi_driver_cb->scheduler_cb.mask_map |= BIT(event_num); + +#ifdef RSI_M4_INTERFACE + // unmask P2P interrupt + RSI_UNMASK_TA_INTERRUPT(); +#endif + + // notify to driver task + rsi_task_notify(driver_task_handle, BIT(event_num)); +} +#endif +/** @} */ + +/** @addtogroup DRIVER5 +* @{ +*/ +/*====================================================*/ +/** + * @fn void rsi_set_event(uint32_t event_num) + * @brief Set an event. + * @param[in] event_num - Event number to be set + * @return void + */ +///@private +void rsi_set_event(uint32_t event_num) +{ +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) + rsi_set_event_non_rom(event_num); +#elif (defined(ROM_WIRELESS)) + ROMAPI_WL->rsi_set_event(global_cb_p, event_num); +#else + api_wl->rsi_set_event(global_cb_p, event_num); +#endif +} +/*====================================================*/ +/** + * @fn void rsi_clear_event(uint32_t event_num) + * @brief Clear an event. + * @param[in] event_num - Event number to clear + * @return void + */ +///@private +void rsi_clear_event(uint32_t event_num) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_clear_event(global_cb_p, event_num); +#else + api_wl->rsi_clear_event(global_cb_p, event_num); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_mask_event(uint32_t event_num) + * @brief Mask the specified event + * @param[in] event_num - Event number to mask + * @return Void + */ +///@private +void rsi_mask_event(uint32_t event_num) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_mask_event(global_cb_p, event_num); +#else + api_wl->rsi_mask_event(global_cb_p, event_num); +#endif +} +/** @} */ + +/** @addtogroup DRIVER8 +* @{ +*/ +/*====================================================*/ +/** + * @fn void rsi_unmask_event(uint32_t event_num) + * @brief Unmask an event. + * @param[in] event_num - Event number to unmask + * @return void + */ +///@private +void rsi_unmask_event(uint32_t event_num) +{ +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) + rsi_unmask_event_non_rom(event_num); +#elif (defined(ROM_WIRELESS)) + ROMAPI_WL->rsi_unmask_event(global_cb_p, event_num); +#else + api_wl->rsi_unmask_event(global_cb_p, event_num); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_unmask_event_from_isr(uint32_t event_num) + * @brief Unmask an event from ISR context. + * @param[in] event_num - event number to unmask + * @return void + */ +///@private +void rsi_unmask_event_from_isr(uint32_t event_num) +{ +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) + rsi_unmask_event_from_isr_non_rom(event_num); +#elif (defined(ROM_WIRELESS)) + ROMAPI_WL->rsi_unmask_event_from_isr(global_cb_p, event_num); +#else + api_wl->rsi_unmask_event_from_isr(global_cb_p, event_num); +#endif +} +/** @} */ + +/** @addtogroup DRIVER5 +* @{ +*/ +/*====================================================*/ +/** + * @fn uint32_t rsi_find_event(uint32_t event_map) + * @brief Find the event which is set + * @param[in] event_map - Event map + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +///@private +uint32_t rsi_find_event(uint32_t event_map) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_find_event(global_cb_p, event_map); +#else + return api_wl->rsi_find_event(global_cb_p, event_map); +#endif +} + +/*====================================================*/ +/** + * @fn uint16_t rsi_register_event(uint32_t event_id, void (*event_handler_ptr)(void)) + * @brief Register the given event + * @param[in] event_id - event number which needs to be registered + * @param[in] event_handler_ptr - event handler which needs to be registered for a given event + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +///@private +uint16_t rsi_register_event(uint32_t event_id, void (*event_handler_ptr)(void)) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_register_event(global_cb_p, event_id, event_handler_ptr); +#else + return api_wl->rsi_register_event(global_cb_p, event_id, event_handler_ptr); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_set_event_from_isr(uint32_t event_num) + * @brief Set the event from isr context. + * @param[in] event_num - Event number to mask + * @return Void + * + */ +///@private +void rsi_set_event_from_isr(uint32_t event_num) +{ +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) + rsi_set_event_from_isr_non_rom(event_num); +#elif (defined(ROM_WIRELESS)) + ROMAPI_WL->rsi_set_event_from_isr(global_cb_p, event_num); +#else + api_wl->rsi_set_event_from_isr(global_cb_p, event_num); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_events_init(void) + * @brief Initialize the events. + * @param[in] void + * @return Void + */ +///@private +void rsi_events_init(void) +{ + // Initialze RX event + rsi_register_event(RSI_RX_EVENT, rsi_rx_event_handler); + + // Initialze TX event + rsi_register_event(RSI_TX_EVENT, rsi_tx_event_handler); + +#ifndef RSI_M4_INTERFACE +#ifdef RSI_WLAN_ENABLE + // Initialze Socket event + rsi_register_event(RSI_SOCKET_EVENT, rsi_socket_event_handler); +#endif +#endif + +#ifdef RSI_ENABLE_DEMOS +#if (BT_A2DP_SOURCE_WIFI_HTTP_S_RX || BLE_DUAL_MODE_BT_A2DP_SOURCE_WIFI_HTTP_S_RX \ + || BT_A2DP_SOURCE_WIFI_HTTP_S_RX_DYN_COEX) + // Initialize application event1 + rsi_register_event(RSI_APP_EVENT1, rsi_app_event1_handler); + + // Initialize application event2 + rsi_register_event(RSI_APP_EVENT2, rsi_app_event2_handler); +#endif +#endif +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_events_rom.c b/wiseconnect/sapi/driver/rsi_events_rom.c new file mode 100644 index 00000000..df99fde1 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_events_rom.c @@ -0,0 +1,256 @@ +/******************************************************************************* +* @file rsi_events_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ + +#include "rsi_driver.h" +#ifndef ROM_WIRELESS + +/* + Global Variables + */ + +/** @addtogroup DRIVER5 +* @{ +*/ +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_set_event(global_cb_t *global_cb_p, uint32_t event_num) + * @brief Set an event + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_num - event number to be set + * @return Void + */ +///@private +void ROM_WL_rsi_set_event(global_cb_t *global_cb_p, uint32_t event_num) +{ + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + + rsi_reg_flags_t flags; + +#ifdef RSI_M4_INTERFACE + // mask P2P interrupt + RSI_MASK_TA_INTERRUPT(); +#endif + + // Disable all the interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + // Set the event bit in bitmap + rsi_driver_cb->scheduler_cb.event_map |= BIT(event_num); + + // Enable all the interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + +#ifdef RSI_M4_INTERFACE + // unmask P2P interrupt + RSI_UNMASK_TA_INTERRUPT(); +#endif + + if (global_cb_p->os_enabled == 1) { + // Post the semaphore + RSI_SEMAPHORE_POST(&rsi_driver_cb->scheduler_cb.scheduler_sem); + } +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_clear_event(global_cb_t *global_cb_p,uint32_t event_num) + * @brief Clear an event + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_num - event number to clear + * @return Void + */ +///@private +void ROM_WL_rsi_clear_event(global_cb_t *global_cb_p, uint32_t event_num) +{ + + rsi_reg_flags_t flags; + + // Disable all the interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + // Reset the event bit in bitmap + global_cb_p->rsi_driver_cb->scheduler_cb.event_map &= ~BIT(event_num); + + // Enable all the interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + return; +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_mask_event(global_cb_t *global_cb_p,uint32_t event_num) + * @brief Mask an event + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_num - event number to mask + * @return Void + */ +///@private +void ROM_WL_rsi_mask_event(global_cb_t *global_cb_p, uint32_t event_num) +{ + rsi_reg_flags_t flags; + + // Disable all the interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + // Reset event bit in mask bitmap + global_cb_p->rsi_driver_cb->scheduler_cb.mask_map &= ~BIT(event_num); + + // Enable all the interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + return; +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_unmask_event(global_cb_t *global_cb_p, uint32_t event_num) + * @brief Unmask an event + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_num - event number to unmask + * @return Void + */ +///@private +void ROM_WL_rsi_unmask_event(global_cb_t *global_cb_p, uint32_t event_num) +{ +#ifdef RSI_M4_INTERFACE + // mask P2P interrupt + RSI_MASK_TA_INTERRUPT(); +#endif + + // set event bit in mask bitmap + global_cb_p->rsi_driver_cb->scheduler_cb.mask_map |= BIT(event_num); + +#ifdef RSI_M4_INTERFACE + // unmask P2P interrupt + RSI_UNMASK_TA_INTERRUPT(); +#endif + + if (global_cb_p->os_enabled == 1) { + // Post the semaphore + RSI_SEMAPHORE_POST(&global_cb_p->rsi_driver_cb->scheduler_cb.scheduler_sem); + } +} + +/*====================================================*/ +/** + * @fn uint32_t ROM_WL_rsi_find_event(global_cb_t *global_cb_p, uint32_t event_map) + * @brief Find the event which is set + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_map - event map + * @return Event number + */ +///@private +uint32_t ROM_WL_rsi_find_event(global_cb_t *global_cb_p, uint32_t event_map) +{ + uint8_t i; + + for (i = 0; i < global_cb_p->rsi_max_num_events; i++) { + if (event_map & BIT(i)) { + break; + } + } + return i; +} + +/*====================================================*/ +/** + * @fn uint16_t ROM_WL_rsi_register_event(global_cb_t *global_cb_p, uint32_t event_id, void (*event_handler_ptr)(void)) + * @brief Register the event + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_id - event number which needs to be registered + * @param[in] event_handler_ptr - event handler which needs to be registered for a given event + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +///@private +uint16_t ROM_WL_rsi_register_event(global_cb_t *global_cb_p, uint32_t event_id, void (*event_handler_ptr)(void)) +{ + if ((event_id > global_cb_p->rsi_max_num_events) + || (global_cb_p->rsi_driver_cb->event_list[event_id].event_handler != NULL)) { + /* + *Return , if the event number exceeds the RSI_MAX_NUM_EVENTS ,or + * the event is already registered + */ + return 1; + } + + // Register event handler + global_cb_p->rsi_driver_cb->event_list[event_id].event_handler = event_handler_ptr; + + return 0; +} + +#endif +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_set_event_from_isr(global_cb_t *global_cb_p, uint32_t event_num) + * @brief Set an event from ISR + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_num - event number to be set + * @return Void + */ +///@private +void ROM_WL_rsi_set_event_from_isr(global_cb_t *global_cb_p, uint32_t event_num) +{ + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + + // Set the event bit in scheduler bitmap + rsi_driver_cb->scheduler_cb.event_map |= BIT(event_num); + + if (global_cb_p->os_enabled == 1) { + // Post the semaphore + RSI_SEMAPHORE_POST_FROM_ISR(&rsi_driver_cb->scheduler_cb.scheduler_sem); + } else { + // Post the semaphore + RSI_SEMAPHORE_POST(&rsi_driver_cb->scheduler_cb.scheduler_sem); + } +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_unmask_event_from_isr(global_cb_t *global_cb_p, uint32_t event_num) + * @brief Unmask an event from ISR + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] event_num - event number to unmask + * @return Void + */ +///@private +void ROM_WL_rsi_unmask_event_from_isr(global_cb_t *global_cb_p, uint32_t event_num) +{ + + // set event bit in mask bitmap + global_cb_p->rsi_driver_cb->scheduler_cb.mask_map |= BIT(event_num); + + if (global_cb_p->os_enabled == 1) { + // Post the semaphore + RSI_SEMAPHORE_POST_FROM_ISR(&global_cb_p->rsi_driver_cb->scheduler_cb.scheduler_sem); + } else { + // Post the semaphore + RSI_SEMAPHORE_POST(&global_cb_p->rsi_driver_cb->scheduler_cb.scheduler_sem); + } +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_iap.c b/wiseconnect/sapi/driver/rsi_iap.c new file mode 100644 index 00000000..daae3d76 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_iap.c @@ -0,0 +1,221 @@ +/******************************************************************************* +* @file rsi_iap.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#ifdef RSI_WAC_MFI_ENABLE + +/*==============================================*/ +/** + * @fn int32_t rsi_iap_init() + * @brief Initialize the IAP + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_iap_init() +{ + + rsi_pkt_t *pkt; + + int32_t status = 0; + + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + + // send power save command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_IAP_INIT, pkt); + + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_IAP_RESPONSE_WAIT_TIME); + + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //return common command error + return status; + } + // get common command response stattus + status = rsi_common_get_status(); + + // return status + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_iap_generate_signature(uint16_t digest_length, int8_t *digest, uint16_t buffer_len, uint8_t *buffer) + * @brief Generate signature for the digest given by feeding it to the IAP chip and this signature is used in apple authentication process + * @param[in] digest_length - length of the digest + * @param[in] digest - pointer to the digest buffer + * @param[in] buffer_len - length of the buffer which is given to copy signature data + * @param[in] buffer - pointer to the buffer + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_iap_generate_signature(uint16_t digest_length, int8_t *digest, uint16_t buffer_len, uint8_t *buffer) +{ + + rsi_pkt_t *pkt; + int32_t status = 0; + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + rsi_mfi_auth_create_request_t *auth_req = NULL; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset the packet + memset(pkt, 0, (digest_length + 4)); + + auth_req = (rsi_mfi_auth_create_request_t *)pkt->data; + + // copy Digest data length + rsi_uint32_to_4bytes(auth_req->digest_length, digest_length); + + // Copy Digest + memcpy(auth_req->digest, digest, digest_length); + + // point the buffer to the app buffer + rsi_common_cb->app_buffer = buffer; + + rsi_common_cb->app_buffer_length = buffer_len; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // send IAP generate signature command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_IAP_GENERATE_SIGATURE, pkt); + + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_IAP_GEN_SIG_RESPONSE_WAIT_TIME); + + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //return common command error + return status; + } + // get common command response stattus + status = rsi_common_get_status(); + + // return status + return status; +} + +/*==============================================*/ +/** + * @fn int8_t rsi_iap_get_certificate(uint16_t buffer_len, uint8_t *buffer) + * @brief Get the certificate of the IAP chip + * @param[in] buffer_len - length of the buffer + * @param[out] buffer - pointer to the buffer in which certificate is to be copied + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_iap_get_certificate(uint16_t buffer_len, uint8_t *buffer) +{ + + rsi_pkt_t *pkt; + + int32_t status = 0; + + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // allocate command buffer from common pool + pkt = rsi_pkt_alloc(&rsi_common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // point the buffer to the app buffer + rsi_common_cb->app_buffer = buffer; + + rsi_common_cb->app_buffer_length = buffer_len; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // send IAP generate signature command + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_IAP_GET_CERTIFICATE, pkt); + + // wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_IAP_GET_CERT_RESPONSE_WAIT_TIME); + + //Changing the common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + //return common command error + return status; + } + // get common command response stattus + status = rsi_common_get_status(); + + // return status + return status; +} +#endif diff --git a/wiseconnect/sapi/driver/rsi_nwk.c b/wiseconnect/sapi/driver/rsi_nwk.c new file mode 100644 index 00000000..43b0c5f1 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_nwk.c @@ -0,0 +1,649 @@ +/******************************************************************************* +* @file rsi_nwk.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +#include "rsi_wlan_non_rom.h" +#ifdef RSI_WLAN_ENABLE + +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; +/** @addtogroup WLAN +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_driver_send_data(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr) + * @brief Send data packet. This is a blocking API. + * @param[in] sockID - Socket descriptor on which data needs to be send + * @param[in] buffer - Pointer to data + * @param[in] length - Data length + * @param[in] destAddr - Pointer to destination socket details + * @return 0 - Success \n + * @return Negative Value - Failure + * + * + */ +/// @private +int32_t rsi_driver_send_data(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr) +{ + return rsi_driver_send_data_non_rom(sockID, buffer, length, destAddr); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_driver_process_recv_data(rsi_pkt_t *pkt) + * @brief Process received data packet. This is a non-blocking API + * @param[in] pkt - Pointer to data packet + * @return 0 - Success \n + * @return Negative Value - Failure + */ +/// @private +int32_t rsi_driver_process_recv_data(rsi_pkt_t *pkt) +{ + return rsi_driver_process_recv_data_non_rom(pkt); +} + +/*====================================================*/ +/** + * @fn int16_t rsi_nwk_register_callbacks(uint32_t callback_id, + * void (*callback_handler_ptr)(uint8_t command_type, uint32_t status, const uint8_t *buffer, const uint32_t length)) + * @brief Register the callback. This is a non-blocking API. + * @param[in] callback_id - This is the Id of the callback function. \n + * Following ids are supported: \n + * 0-RSI_NWK_ERROR_CB, \n + * 1-RSI_WLAN_NWK_URL_REQ_CB, \n + * 2-RSI_WLAN_NWK_JSON_UPDATE_CB, \n + * 3-RSI_WLAN_NWK_FW_UPGRADE_CB, \n + * 4-RSI_WLAN_NWK_JSON_EVENT_CB + * @param[in] callback_handler_ptr - Callback handler which needs to be registered for a given callback + * @param[out] status - Response status. + * @param[out] buffer - Response buffer. + * @param[out] length - Length of the response buffer. + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd) \n + * 1 - If call_back_id is greater than the maximum callbacks to register + * ## prototypes of the callback functions ## + * callback id | Prototype | Description | Parameters + * :----------------------------|:----------------------------------------|:--------------------|:------------------------------------------------------------- + * RSI_NWK_ERROR_CB | void (*nwk_error_call_back_handler)(uint8_t command_type, uint32_t status, const uint8_t *buffer, const uint32_t length); | This callback is used to Register join fail| command_type => command_type of the response\n status => status of the response\n buffer => payload of the response\n length => length of the payload + * RSI_WLAN_NWK_URL_REQ_CB | void (*rsi_webpage_request_handler)(uint8_t type, uint8_t *url_name,uint8_t *post_content_buffer, uint32_t post_content_length, uint32_t status); | This callback is used to Register webpage request| type => type of the handler\n url_name =>url name\n post_content_buffer => Webpage content\n post_content_lenght => length of webpage content\n status => status of the response + * RSI_WLAN_NWK_JSON_UPDATE_CB | void (*rsi_json_object_update_handler)(uint8_t *file_name, uint8_t *json_object, uint32_t length, uint32_t status); | This callback is used to Register json update | file_name => File name \n json_object => Json object\n length: length of the json object\n status => status of the response + * RSI_WLAN_NWK_FW_UPGRADE_CB | void (*rsi_wireless_fw_upgrade_handler)(uint8_t type, uint32_t status); | This callback is used to Register wireless firmware upgrade | type => type of the handler\n status => status of the response + * RSI_WLAN_NWK_JSON_EVENT_CB | void (*rsi_json_object_event_handler)(uint32_t status, uint8_t *json_object_str, uint32_t length); | This callback is used to Register json update | status => status of the response\n json_object_str => json object string\n length => length of the string + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int16_t rsi_nwk_register_callbacks( + uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t command_type, uint32_t status, const uint8_t *buffer, const uint32_t length)) +{ + SL_PRINTF(SL_NWK_REGISTER_CALLBACKS_ENTRY, NETWORK, LOG_INFO); + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + SL_PRINTF(SL_NWK_REGISTER_CALLBACKS_EXCEEDS_MAX_CALLBACKS, NETWORK, LOG_INFO); + return RSI_ERROR_EXCEEDS_MAX_CALLBACKS; + } + if (callback_id == RSI_NWK_ERROR_CB) // check for NULL or not + { + // Register join fail callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.nwk_error_call_back_handler = callback_handler_ptr; + } + SL_PRINTF(SL_NWK_REGISTER_CALLBACKS_EXIT, NETWORK, LOG_INFO); + return RSI_SUCCESS; +} +/** @} */ + +/** @addtogroup NETWORK14 +* @{ +*/ +/*====================================================*/ +/** + * @fn int16_t rsi_wlan_nwk_register_json_update_cb(uint32_t callback_id, + * void (*callback_handler_ptr)(uint8_t *filename, uint8_t *json_object, uint32_t length, uint32_t status)) + * @brief Register the callbacks. This is non blocking API. + * @param[in] callback_id - Callback ID which needs to be registered + * @param[in] callback_handler_ptr - Callback handler which needs to be registered for a given callback + * @param[out] filename - json object filename + * @param[out] json_object - json object data + * @param[out] length - Length of the response buffer. + * @param[out] status - Response status. + * @return 0 - Success \n + * @return Negative Value - Failure + * @note Please refer to Error Codes section for the description of the above error codes \ref error-codes. + */ + +int16_t rsi_wlan_nwk_register_json_update_cb( + uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t *filename, uint8_t *json_object, uint32_t length, uint32_t status)) +{ + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + return RSI_ERROR_EXCEEDS_MAX_CALLBACKS; + } + + // Register json update handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_json_object_update_handler = callback_handler_ptr; + + return RSI_SUCCESS; +} +/*====================================================*/ +/** + * @fn int16_t rsi_wlan_nwk_register_json_event_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint32_t status, + uint8_t *json_object, + uint32_t length)) + * @brief Register the event callbacks. This is non blocking API. + * @param[in] callback_id - Callback ID which needs to be registered + * @param[in] callback_handler_ptr - Callback handler which needs to be registered for a given callback + * @param[out] status - Response status. + * @param[out] json_object - json object data + * @param[out] length - Length of the response buffer. + * @return 0 - Success \n + * @return Positive Value - Failure + */ + +int16_t rsi_wlan_nwk_register_json_event_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint32_t status, + uint8_t *json_object, + uint32_t length)) +{ + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + return RSI_ERROR_EXCEEDS_MAX_CALLBACKS; + } + + // Register json update handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_json_object_event_handler = callback_handler_ptr; + + return RSI_SUCCESS; +} +/*====================================================*/ +/** + * @fn int16_t rsi_wlan_nwk_register_webpage_req_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t type, + uint8_t *url_name, + uint8_t *post_content_buffer, + uint32_t post_content_length, + uint32_t status)) + * @brief Register webpage request callbacks. This is non blocking API. + * @param[in] callback_id - Callback ID which needs to be registered + * @param[in] callback_handler_ptr - Callback handler which needs to be registered for a given callback + * @param[out] type - Command type + * @param[out] url_name - URL address of the domain + * @param[out] post_content_buffer - Response buffer. + * @param[out] post_content_length - Length of the response buffer. + * @param[out] status - Response status. + * @return 0 - Success \n + * @return Positive Value - Failure + */ + +int16_t rsi_wlan_nwk_register_webpage_req_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t type, + uint8_t *url_name, + uint8_t *post_content_buffer, + uint32_t post_content_length, + uint32_t status)) +{ + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + return RSI_ERROR_EXCEEDS_MAX_CALLBACKS; + } + + // Register webpage request handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_webpage_request_handler = callback_handler_ptr; + + return RSI_SUCCESS; +} +/*====================================================*/ +/** + * @fn int16_t rsi_wlan_nwk_register_wireless_fw_upgrade_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t type, uint32_t status)) + * @brief Register wireless firmware upgrade callbacks. This is non blocking API. + * @param[in] callback_id - Callback ID which needs to be registered + * @param[in] callback_handler_ptr - Callback handler which needs to be registered for a given callback + * @param[out] type - Command type + * @param[out] status - Response status. + * @return 0 - Success \n + * @return Positive Value - Failure + */ +int16_t rsi_wlan_nwk_register_wireless_fw_upgrade_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t type, uint32_t status)) +{ + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + return RSI_ERROR_EXCEEDS_MAX_CALLBACKS; + } + + // Register wireless firmware upgrade callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler = callback_handler_ptr; + + return RSI_SUCCESS; +} +/** @} */ +/** @addtogroup DRIVER9 +* @{ +*/ +/*==============================================*/ +/** + * @fn rsi_error_t rsi_wait_on_nwk_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) + * @brief Wait for network semaphore + * @param[in] semaphore - Semaphore handle pointer + * @param[in] timeout_ms - Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait till semaphore is acquired. + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +rsi_error_t rsi_wait_on_nwk_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) +{ + // Wait on wlan semaphore + if (rsi_semaphore_wait(semaphore, timeout_ms) != RSI_ERROR_NONE) { + rsi_wlan_set_nwk_status(RSI_ERROR_RESPONSE_TIMEOUT); +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + if (rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb != NULL) { + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb(RSI_ERROR_RESPONSE_TIMEOUT, NWK_CMD); + } +#endif + return RSI_ERROR_RESPONSE_TIMEOUT; + } + return RSI_ERROR_NONE; +} +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_get_nwk_status(void) + * @brief Return network status. + * @param[in] void + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note **Precondition** - This API should be called after \ref rsi_device_init() + */ + +int32_t rsi_wlan_get_nwk_status(void) +{ + return rsi_driver_cb_non_rom->nwk_status; +} + +/*==============================================*/ +/** + * @fn void rsi_wlan_set_nwk_status(int32_t status) + * @brief Set network status + * @param[in] status - status value to be set + * @return void + */ +/// @private +void rsi_wlan_set_nwk_status(int32_t status) +{ + rsi_driver_cb_non_rom->nwk_status = status; +#ifndef RSI_WLAN_STATUS + rsi_wlan_set_status(status); +#endif +} + +/*==============================================*/ +/** + * @fn int32_t rsi_driver_send_data_non_rom(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr) + * @brief Send data packet + * @param[in] sockID - socket descriptor on which data needs to be send + * @param[in] buffer - pointer to data + * @param[in] length - data length + * @param[in] destAddr - pointer to destination socket details + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +/// @private +int32_t rsi_driver_send_data_non_rom(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr) +{ + int32_t status = RSI_SUCCESS; + uint8_t *host_desc; + uint32_t total_send_size = 0; + uint16_t headerLen; + rsi_req_socket_send_t *send; + rsi_pkt_t *pkt; + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + // Allocate packet to send data + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); + return RSI_SOCK_ERROR; + } + + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED) { + rsi_pkt_free(&rsi_driver_cb->wlan_cb->wlan_tx_pool, pkt); + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); + return RSI_SOCK_ERROR; + } + + // Get data pointer + send = (rsi_req_socket_send_t *)pkt->data; + + // Get host descriptor pointer + host_desc = pkt->desc; + + // Memset host descriptor + memset(host_desc, 0, RSI_HOST_DESC_LENGTH); + + // Memset before filling + memset(send, 0, (sizeof(rsi_req_socket_send_t) - sizeof(send->send_buffer))); + + if (((rsi_socket_pool[sockID].sock_type >> 4) & 0xF) == AF_INET) { + // Fill IP version as 4 + rsi_uint16_to_2bytes(send->ip_version, 4); + + // Fill destination IPv4 address + memcpy((uint8_t *)send->dest_ip_addr.ipv4_address, + (uint8_t *)ntohl(&(((struct rsi_sockaddr_in *)destAddr)->sin_addr.s_addr)), + RSI_IPV4_ADDRESS_LENGTH); + + // Fill destination port + rsi_uint16_to_2bytes(send->dest_port, ntohs(((struct rsi_sockaddr_in *)destAddr)->sin_port)); + + // Calculate header length + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) { + // TCP IPv4 header + headerLen = RSI_TCP_FRAME_HEADER_LEN; + } else { + // UDP IPv4 header + headerLen = RSI_UDP_FRAME_HEADER_LEN; + } + } else { + // Fill IP version as 6 + rsi_uint16_to_2bytes(send->ip_version, 6); + + // Fill destination IPv6 address + memcpy(send->dest_ip_addr.ipv6_address, + (uint8_t *)ntohl(&((struct rsi_sockaddr_in6 *)destAddr)->sin6_addr._S6_un._S6_u8), + RSI_IPV6_ADDRESS_LENGTH); + + // Fill destination port + rsi_uint16_to_2bytes(send->dest_port, ntohs(((struct rsi_sockaddr_in6 *)destAddr)->sin6_port)); + + // Calculate header length + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) { + // TCP IPv6 header length + headerLen = RSI_TCP_V6_FRAME_HEADER_LEN; + } else { + // UDP IPv6 header length + headerLen = RSI_UDP_V6_FRAME_HEADER_LEN; + } + } + + // if it is a web socket, setting web socket data header length + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_WEBS_SUPPORT) { + // If websocket is enabled + headerLen += ((length < 126) ? 6 : 8); + } + + // Fill socket desriptor + send->socket_id[0] = rsi_socket_pool[sockID].sock_id; + + // Fill opcode used in websocket + send->socket_id[1] = rsi_socket_pool[sockID].opcode; + + // Fill send buffer length + rsi_uint16_to_2bytes(send->length, length); + + // Fill data offset + rsi_uint16_to_2bytes(send->data_offset, headerLen); + + // Total send length includes header length and payload length + total_send_size = (headerLen + length); + + headerLen -= (sizeof(rsi_req_socket_send_t) - sizeof(send->send_buffer)); + + // Copy data to be sent + memcpy(&send->send_buffer[headerLen], buffer, length); + + // Fill host descriptor + rsi_uint16_to_2bytes(host_desc, (total_send_size & 0xFFF)); + + // Fill packet type + host_desc[1] |= (RSI_WLAN_DATA_Q << 4); + + // Enqueue packet to WLAN TX queue + rsi_enqueue_pkt(&rsi_driver_cb->wlan_tx_q, pkt); + + // Set TX packet pending event + rsi_set_event(RSI_TX_EVENT); + +#ifdef RSI_UART_INTERFACE +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap |= BIT(0); +#endif + if (rsi_wait_on_socket_semaphore(&rsi_driver_cb_non_rom->send_data_sem, RSI_SEND_DATA_RESPONSE_WAIT_TIME) + != RSI_ERROR_NONE) { + rsi_wlan_socket_set_status(RSI_ERROR_RESPONSE_TIMEOUT, sockID); + + return RSI_SOCK_ERROR; + } +#else +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap |= BIT(2); +#endif + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[sockID].sock_send_sem, RSI_SEND_DATA_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + // get wlan/network command response status + rsi_wlan_socket_set_status(status, sockID); + return RSI_SOCK_ERROR; + } +#endif + + status = rsi_wlan_socket_get_status(sockID); + + // Return status + return status; +} +/*==============================================*/ +/** + * @fn int32_t rsi_driver_process_recv_data_non_rom(rsi_pkt_t *pkt) + * @brief Process received data packet + * @param[in] pkt - pointer to data packet + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int32_t rsi_driver_process_recv_data_non_rom(rsi_pkt_t *pkt) +{ + uint32_t data_length, data_offset; + int32_t sockID; + uint8_t websocket_info = 0; + rsi_socket_info_t *sock_info; + rsi_rsp_socket_recv_t *recv; + uint8_t *host_desc; + uint16_t payload_length; + int32_t frame_type = 0; + int32_t status = RSI_SUCCESS; + + // rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + // Get payload pointer + recv = (rsi_rsp_socket_recv_t *)pkt->data; + + // Get host descriptor + host_desc = pkt->desc; + + frame_type = host_desc[2]; + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + if (frame_type == 0x01) { + rsi_wlan_cb_non_rom->callback_list.raw_data_receive_handler(0, pkt->data, payload_length); + } else { + // Get socket descriptor + sockID = rsi_application_socket_descriptor(recv->socket_id[0]); + + // update the status in wlan_cb + rsi_wlan_socket_set_status(status, sockID); + + // Get web socket information + websocket_info = recv->socket_id[1]; + + if ((sockID < 0) || (sockID >= NUMBER_OF_SOCKETS)) { + return RSI_SOCK_ERROR; + } + + // Get socket info + sock_info = &rsi_socket_pool[sockID]; + + // Get received data length + data_length = rsi_bytes2R_to_uint16(recv->length); + + // Get actual data offset + data_offset = rsi_bytes2R_to_uint16(recv->offset); + + if ((sock_info->sock_type & 0xF) == SOCK_DGRAM) { + // Save destination port number + sock_info->destination_port = rsi_bytes2R_to_uint16(recv->dest_port); + + // Save destination IP address + if ((sock_info->sock_type >> 4) == AF_INET) { + memcpy(sock_info->destination_ip_addr.ipv4, recv->dest_ip_addr.ipv4_address, RSI_IPV4_ADDRESS_LENGTH); + } else { + memcpy(sock_info->destination_ip_addr.ipv6, recv->dest_ip_addr.ipv6_address, RSI_IPV6_ADDRESS_LENGTH); + } + } + + if (!(sock_info->sock_bitmap & RSI_SOCKET_FEAT_SYNCHRONOUS)) { + + if (sock_info->sock_receive_callback != NULL) { + if ((sock_info->sock_bitmap & RSI_SOCKET_FEAT_WEBS_SUPPORT)) { + *(uint8_t *)(recv + data_offset - 1) = websocket_info; + + // Call registered callback if asynchronous callback + sock_info->sock_receive_callback(sockID, ((uint8_t *)recv + data_offset - 1), data_length + 1); + } else { + // Call registered callback if asynchronous callback + sock_info->sock_receive_callback(sockID, ((uint8_t *)recv + data_offset), data_length); + } + } + return RSI_SUCCESS; + } + + if (global_cb_p->rx_buffer_mem_copy == 1) { + // If socket receive available length is still present + if (sock_info->sock_recv_available_length != 0) { + return RSI_SOCK_ERROR; + } + + // Memcopy to socket receive buffer + sock_info->sock_recv_buffer = ((uint8_t *)recv + data_offset); + + // Increase socket recieve available length + sock_info->sock_recv_available_length = data_length; + } else { + if (sock_info->recv_buffer) { +#ifdef RSI_PROCESS_MAX_RX_DATA + if (sock_info->sock_type & SOCK_STREAM) { + // Memcopy to socket receive buffer + memcpy((sock_info->recv_buffer + sock_info->recv_buffer_length), + ((uint8_t *)recv + data_offset), + data_length); + sock_info->recv_buffer_length += data_length; + } else { + // Memcopy to socket receive buffer + memcpy(sock_info->recv_buffer, ((uint8_t *)recv + data_offset), data_length); + sock_info->recv_buffer_length = data_length; + } +#else + // Memcopy to socket receive buffer + memcpy(sock_info->recv_buffer, ((uint8_t *)recv + data_offset), data_length); + sock_info->recv_buffer_length = data_length; +#endif + } else { + sock_info->recv_buffer_length = 0; + } + } + +#ifdef RSI_PROCESS_MAX_RX_DATA + if (sock_info->sock_type & SOCK_STREAM) { + if (recv->more_data_pending) { + rsi_socket_pool_non_rom[sockID].more_rx_data_pending = 1; + } + } + if (recv->end_of_the_data || !(sock_info->sock_type & SOCK_STREAM)) +#endif + { +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(1); +#endif + rsi_socket_pool_non_rom[sockID].recv_pending_bit |= BIT(0); + // signal the wlan semaphore + RSI_SEMAPHORE_POST(&rsi_socket_pool_non_rom[sockID].sock_recv_sem); + } + } + return RSI_SUCCESS; +} +/*==============================================*/ +/** + * @fn void rsi_post_waiting_nwk_semaphore() + * @brief Post the network semaphore which is on wait + * @param[in] void + * @return Void + */ +/// @private +#ifndef RSI_NWK_SEM_BITMAP +void rsi_post_waiting_nwk_semaphore() +{ + if (rsi_driver_cb_non_rom->nwk_wait_bitmap & BIT(0)) { + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_sem); + } + if (rsi_driver_cb_non_rom->nwk_wait_bitmap & BIT(1)) { + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_cmd_send_sem); + } + rsi_driver_cb_non_rom->nwk_wait_bitmap = 0; +} +#else +void rsi_post_waiting_nwk_semaphore() +{ + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_sem); + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_cmd_send_sem); +} +#endif +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_nwk_rom.c b/wiseconnect/sapi/driver/rsi_nwk_rom.c new file mode 100644 index 00000000..54d97550 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_nwk_rom.c @@ -0,0 +1,29 @@ +/******************************************************************************* +* @file rsi_nwk_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + * */ +#include "rsi_driver.h" +#ifndef ROM_WIRELESS + +#endif diff --git a/wiseconnect/sapi/driver/rsi_os_none.c b/wiseconnect/sapi/driver/rsi_os_none.c new file mode 100644 index 00000000..0ab24f26 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_os_none.c @@ -0,0 +1,267 @@ +/******************************************************************************* +* @file rsi_os_none.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#include +#ifndef RSI_WITH_OS +/* + Include files + */ + +/** @addtogroup DRIVER16 +* @{ +*/ +/*==============================================*/ +/** + * @fn rsi_reg_flags_t rsi_critical_section_entry(void) + */ + +rsi_reg_flags_t rsi_critical_section_entry(void) +{ + rsi_reg_flags_t xflags; + // hold interrupt status before entering critical section + // disable interrupts +#ifdef RSI_M4_INTERFACE + xflags = NVIC_GetIRQEnable((IRQn_Type)M4_ISR_IRQ); + NVIC_DisableIRQ((IRQn_Type)M4_ISR_IRQ); +#else + xflags = rsi_hal_critical_section_entry(); +#endif + + // return stored interrupt status + return (xflags); +} +/*==============================================*/ +/** + * @fn void rsi_critical_section_exit(rsi_reg_flags_t xflags) + * + */ + +void rsi_critical_section_exit(rsi_reg_flags_t xflags) +{ + // restore interrupts while exiting critical section + if (xflags != 0) { +#ifdef RSI_M4_INTERFACE + // restore interrupts while exiting critical section + NVIC_EnableIRQ((IRQn_Type)M4_ISR_IRQ); +#else + rsi_hal_critical_section_exit(); +#endif + } +} +/*==============================================*/ +/** + * @fn void * rsi_virtual_to_physical_address(void *virtual_address) + * @brief Map virtual address to physical address + * @param[in] virtual_address - pointer to virtual address + * @return void + */ +/// @private +void *rsi_virtual_to_physical_address(void *virtual_address) +{ + return (virtual_address); +} +/*==============================================*/ +/** + * @fn void *rsi_physical_to_virtual_address(void *physical_address) + * @brief Map physical address to virtual address + * @param[in] physical_address - pointer to physical_address + * @return void + * + */ +/// @private +void *rsi_physical_to_virtual_address(void *physical_address) +{ + return (physical_address); +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex) + * + */ + +rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex) +{ + /* Create dummy mutxe pointer because OS not present */ + RSI_NO_OS_ATOMIC_MUTEX_SET(*mutex, RSI_NO_OS_MUTEX_UNLOCKED); + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex) + * + */ + +rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex) +{ + while (RSI_NO_OS_ATOMIC_MUTEX_CHECK(*mutex, RSI_NO_OS_MUTEX_LOCKED)) + ; + RSI_NO_OS_ATOMIC_MUTEX_SET(*mutex, RSI_NO_OS_MUTEX_LOCKED); + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex) + */ + +rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex) +{ + RSI_NO_OS_ATOMIC_MUTEX_SET(*mutex, RSI_NO_OS_MUTEX_UNLOCKED); + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex) + * + */ + +rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex) +{ + UNUSED_PARAMETER(mutex); //This statement is added only to resolve compilation warning, value is unchanged + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore,uint32_t count) + * + */ + +rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore, uint32_t count) +{ + *semaphore = count; + return (RSI_ERROR_NONE); +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore) + * + */ + +rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore) +{ + *semaphore = 0; + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore) + * @brief Checks whether the semaphore is created and destroys the semaphore instance, if its created + * @param[in] semaphore - Semaphore handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +/// @private +rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore) +{ + if (rsi_semaphore_destroy(semaphore) != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_DESTROY_FAILED; + } + return (RSI_ERROR_NONE); +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms ) + * + */ + +rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) +{ + volatile uint32_t *event; + rsi_timer_instance_t timer_instance; + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + event = (uint32_t *)semaphore; + if (0UL != *event) { + RSI_ATOMIC_DECREMENT(*event); + return (RSI_ERROR_NONE); + } + if (0UL == timeout_ms) { + while (0UL == *event) { + // if any events pending + // call rsi schedular + rsi_scheduler(&rsi_driver_cb->scheduler_cb); + } + RSI_ATOMIC_DECREMENT(*event); + return (RSI_ERROR_NONE); + } + rsi_init_timer(&timer_instance, timeout_ms); + while ((0UL != timeout_ms) && (0UL == *event)) { + // if any events pending + // call rsi schedular + rsi_scheduler(&rsi_driver_cb->scheduler_cb); + if (rsi_timer_expired(&timer_instance)) { + break; + } + } + if (0UL == *event || (0UL == timeout_ms)) { + return (RSI_ERROR_TIMEOUT); + } else { + RSI_ATOMIC_DECREMENT(*event); + } + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore) + * + */ + +rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore) +{ + volatile uint32_t *event; + + event = (uint32_t *)semaphore; + RSI_ATOMIC_INCREMENT(*event); + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore) + * + */ + +rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore) +{ + volatile uint32_t *event; + + event = (uint32_t *)semaphore; + RSI_ATOMIC_INCREMENT(*event); + return (RSI_ERROR_NONE); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore) + * + */ + +rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore) +{ + volatile uint32_t *event; + + event = (uint32_t *)semaphore; + *event = 0; + return (RSI_ERROR_NONE); +} + +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_pkt_mgmt.c b/wiseconnect/sapi/driver/rsi_pkt_mgmt.c new file mode 100644 index 00000000..5752175e --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_pkt_mgmt.c @@ -0,0 +1,108 @@ +/******************************************************************************* +* @file rsi_pkt_mgmt.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +/** @addtogroup DRIVER5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_pkt_pool_init(rsi_pkt_pool_t *pool_cb, uint8_t *buffer, uint32_t total_size, uint32_t pkt_size) + * @brief Initialize/create packet pool from the provided buffer + * @param[in] pool_cb - packet pool pointer which needs to be initialized \n + * @param[in] buffer - buffer pointer to create pool \n + * @param[in] total_size - size of pool to create \n + * @param[in] pkt_size - size of each packet in pool \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +///@private +int32_t rsi_pkt_pool_init(rsi_pkt_pool_t *pool_cb, uint8_t *buffer, uint32_t total_size, uint32_t pkt_size) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_pkt_pool_init(global_cb_p, pool_cb, buffer, total_size, pkt_size); +#else + return api_wl->rsi_pkt_pool_init(global_cb_p, pool_cb, buffer, total_size, pkt_size); +#endif +} + +/*==============================================*/ +/** + * @fn rsi_pkt_t *rsi_pkt_alloc(rsi_pkt_pool_t *pool_cb) + * @brief Allocate packet from a given packet pool + * @param[in] pool_cb - packet pool pointer from which packet needs to be allocated + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +///@private +rsi_pkt_t *rsi_pkt_alloc(rsi_pkt_pool_t *pool_cb) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_pkt_alloc(global_cb_p, pool_cb); +#else + return api_wl->rsi_pkt_alloc(global_cb_p, pool_cb); +#endif +} + +/*==============================================*/ +/** + * @fn int32_t rsi_pkt_free(rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt) + * @brief Free the packet + * @param[in] pool_cb - packet pool to which packet needs to be freed + * @param[in] pkt - packet pointer which needs to be freed + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +///@private +int32_t rsi_pkt_free(rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_pkt_free(global_cb_p, pool_cb, pkt); +#else + return api_wl->rsi_pkt_free(global_cb_p, pool_cb, pkt); +#endif +} + +/*==============================================*/ +/** + * @fn uint32_t rsi_is_pkt_available(rsi_pkt_pool_t *pool_cb) + * @brief Number of available packets in pool + * @param[in] pool_cb - pool pointer to check available packet count + * @return Number of packets in pool (>=0) + * + */ +///@private +uint32_t rsi_is_pkt_available(rsi_pkt_pool_t *pool_cb) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_is_pkt_available(global_cb_p, pool_cb); +#else + return api_wl->rsi_is_pkt_available(global_cb_p, pool_cb); +#endif +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_pkt_mgmt_rom.c b/wiseconnect/sapi/driver/rsi_pkt_mgmt_rom.c new file mode 100644 index 00000000..01e51e03 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_pkt_mgmt_rom.c @@ -0,0 +1,326 @@ +/******************************************************************************* +* @file rsi_pkt_mgmt_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +#ifndef ROM_WIRELESS + +/** @addtogroup DRIVER5 +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t ROM_WL_rsi_pkt_pool_init(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, + * uint8_t *buffer, uint32_t total_size, uint32_t pkt_size) + * @brief Initialize/create packet pool from the provided buffer + * @param[in] global_cb_p - pointer to the global control block + * @param[in] pool_cb - packet pool pointer which needs to be initialized + * @param[in] buffer - buffer pointer to create pool + * @param[in] total_size - size of pool to create + * @param[in] pkt_size - size of each packet in pool + * @return 0 - Success \n + * @return Negative value - Failure + */ +/// @private +int32_t ROM_WL_rsi_pkt_pool_init(global_cb_t *global_cb_p, + rsi_pkt_pool_t *pool_cb, + uint8_t *buffer, + uint32_t total_size, + uint32_t pkt_size) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + uint32_t pool_size; + uint32_t number_of_pkts; + uint32_t buffer_index = 1; + + // Memset pool structure + memset(pool_cb, 0, sizeof(rsi_pkt_pool_t)); + + // Calculate number of packets can be created with given buffer + number_of_pkts = (total_size / pkt_size); + + // Increase number of packet by 1 to not use zeroth index + number_of_pkts++; + + if ((total_size - (number_of_pkts * 4)) < pkt_size) { + // If atleast one packet accomadation is not possible then return error + return -1; + } + + // Save pool pointer + pool_cb->pool = (void *)buffer; + + // Calculate pool array size + pool_size = (number_of_pkts * 4); + + // Increase buffer pointer by pool size + // Buffer contains pool array then actual buffer + buffer += pool_size; + + // Decrease total size by pool size + total_size -= pool_size; + + // While total size is available fill pool array + while (total_size > pkt_size) { + // Fill buffer pointer to current index + pool_cb->pool[buffer_index++] = buffer; + + // Increase available count + pool_cb->avail++; + + // Increase pool size + pool_cb->size++; + + // Move buffer pointer to point next buffer + buffer += pkt_size; + + // Decrease total size by packet size + total_size -= pkt_size; + } + if (RSI_SEMAPHORE_CREATE(&pool_cb->pkt_sem, 0) != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + RSI_SEMAPHORE_POST(&pool_cb->pkt_sem); + // Return success + return 0; +} + +/*==============================================*/ +/** + * @fn rsi_pkt_t * ROM_WL_rsi_pkt_alloc_non_blocking(global_cb_t *global_cb_p,rsi_pkt_pool_t *pool_cb) + * @brief Allocate packet from a given packet pool + * @param[in] global_cb_p - pointer to the global control block + * @param[in] pool_cb - packet pool pointer from which packet needs to be allocated + * @return Allocated packet pointer - Success \n + * @return NULL - Failure + * + */ +/// @private +rsi_pkt_t *ROM_WL_rsi_pkt_alloc_non_blocking(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + rsi_reg_flags_t flags; + rsi_pkt_t *pkt = NULL; + /* + // Wait on wlan semaphore + if(RSI_SEMAPHORE_WAIT(&pool_cb->pkt_sem,RSI_PKT_ALLOC_RESPONSE_WAIT_TIME) != RSI_ERROR_NONE) + { + return NULL; + } +*/ + // Disable interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + if (pool_cb->avail == 0) { + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // If available count is zero return NULL + return NULL; + } + + // If packets are available then return packet pointer from pool + pkt = (rsi_pkt_t *)(pool_cb->pool[pool_cb->avail]); + + // Decrease available count + pool_cb->avail--; + + // initialize next with NULL + pkt->next = NULL; + + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // Return pakcet pointer + return pkt; +} + +/*==============================================*/ +/** + * @fn int32_t ROM_WL_rsi_pkt_free_non_blocking(global_cb_t *global_cb_p,rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt) + * @brief Free the packet + * @param[in] global_cb_p - pointer to the global control block + * @param[in] pool_cb - packet pool pointer from which packet needs to be allocated + * @param[in] pkt - packet pointer which needs to be freed + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t ROM_WL_rsi_pkt_free_non_blocking(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + rsi_reg_flags_t flags; + + // Disable interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + if (pool_cb->avail == pool_cb->size) { + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // If available and size are equal then return an error + return -1; + } + + // Increase pool available count + pool_cb->avail++; + + // Fill packet pinter into pool array + pool_cb->pool[pool_cb->avail] = pkt; + + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + /* + // Release mutex lock + RSI_SEMAPHORE_POST(&pool_cb->pkt_sem); +*/ + return RSI_SUCCESS; +} + +/*==============================================*/ +/** + * @fn rsi_pkt_t * ROM_WL_rsi_pkt_alloc(global_cb_t *global_cb_p,rsi_pkt_pool_t *pool_cb) + * @brief Allocate packet from a given packet pool + * @param[in] global_cb_p - pointer to the global control block + * @param[in] pool_cb - packet pool pointer from which packet needs to be allocated + * @return Allocated packet pointer - Success \n + * @return NULL - Failure + * + */ +/// @private +rsi_pkt_t *ROM_WL_rsi_pkt_alloc(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + rsi_reg_flags_t flags; + rsi_pkt_t *pkt = NULL; + + // Wait on wlan semaphore + if (RSI_SEMAPHORE_WAIT(&pool_cb->pkt_sem, RSI_PKT_ALLOC_RESPONSE_WAIT_TIME) != RSI_ERROR_NONE) { + return NULL; + } + + // Disable interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + if (pool_cb->avail == 0) { + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // If available count is zero return NULL + return NULL; + } + + // If packets are available then return packet pointer from pool + pkt = (rsi_pkt_t *)(pool_cb->pool[pool_cb->avail]); + + // Decrease available count + pool_cb->avail--; + + // initialize next with NULL + pkt->next = NULL; + + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // Return pakcet pointer + return pkt; +} + +/*==============================================*/ +/** + * @fn int32_t ROM_WL_rsi_pkt_free(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt) + * @brief Free the packet + * @param[in] global_cb_p - pointer to the global control block + * @param[in] pool_cb - packet pool to which packet needs to be freed + * @param[in] pkt - packet pointer which needs to be freed + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +int32_t ROM_WL_rsi_pkt_free(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + rsi_reg_flags_t flags; + + // Disable interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + if (pool_cb->avail == pool_cb->size) { + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // If available and size are equal then return an error + return -1; + } + + // Increase pool available count + pool_cb->avail++; + + // Fill packet pinter into pool array + pool_cb->pool[pool_cb->avail] = pkt; + + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // Release mutex lock + RSI_SEMAPHORE_POST(&pool_cb->pkt_sem); + + return RSI_SUCCESS; +} + +/*==============================================*/ +/** + * @fn uint32_t ROM_WL_rsi_is_pkt_available(global_cb_t *global_cb_p,rsi_pkt_pool_t *pool_cb) + * @brief Number of available packets in pool + * @param[in] global_cb_p - pointer to the global control block + * @param[in] pool_cb - pool pointer to check available pakcets count + * @return Number of packets in pool + */ +/// @private +uint32_t ROM_WL_rsi_is_pkt_available(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + rsi_reg_flags_t flags; + uint32_t available_count = 0; + + // Disable interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + // Get available packet count + available_count = pool_cb->avail; + + // Retore interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + // Return available count + return available_count; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_queue.c b/wiseconnect/sapi/driver/rsi_queue.c new file mode 100644 index 00000000..6d9a0d50 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_queue.c @@ -0,0 +1,137 @@ +/******************************************************************************* +* @file rsi_queue.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/*==============================================*/ +/* + Include files + */ +#include "rsi_driver.h" +/** @addtogroup DRIVER16 +* @{ +*/ +/*==============================================*/ +/** + * + * @fn void rsi_queues_init(rsi_queue_cb_t *queue) + * @brief Initialize queue + * @param[in] queue - pointer to queue + * @return void + * + */ +// the below group is mentioned for hiding below internal API. +/// @private +void rsi_queues_init(rsi_queue_cb_t *queue) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_queues_init(global_cb_p, queue); +#else + api_wl->rsi_queues_init(global_cb_p, queue); +#endif +} +/*==============================================*/ +/** + * @fn void rsi_enqueue_pkt(rsi_queue_cb_t *queue, rsi_pkt_t *pkt) + * @brief Enqueue packet into queue + * @param[in] queue - pointer to queue cb + * @param[in] pkt - packet pointer which needs to be queued + * @return void + * + */ +/// @private +void rsi_enqueue_pkt(rsi_queue_cb_t *queue, rsi_pkt_t *pkt) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_enqueue_pkt(global_cb_p, queue, pkt); +#else + api_wl->rsi_enqueue_pkt(global_cb_p, queue, pkt); +#endif +} +/*==============================================*/ +/** + * @fn rsi_pkt_t *rsi_dequeue_pkt(rsi_queue_cb_t *queue) + * @brief Dequeue packet from queue + * @param[in] queue - queue pointer from which packet needs to be dequeued \n + * @return Allocated pocket pointer - Success \n + * @return NULL - Failure + * + */ +/// @private +rsi_pkt_t *rsi_dequeue_pkt(rsi_queue_cb_t *queue) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_dequeue_pkt(global_cb_p, queue); +#else + return api_wl->rsi_dequeue_pkt(global_cb_p, queue); +#endif +} +/*==============================================*/ +/** + * @fn uint32_t rsi_check_queue_status(rsi_queue_cb_t *queue) + * @brief Return packet pending count in queue + * @param[in] queue - pointer to queue + * @return 0 - If queue masked \n + * @return Number of packets pending - If queue is not masked + */ +/// @private +uint32_t rsi_check_queue_status(rsi_queue_cb_t *queue) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_check_queue_status(global_cb_p, queue); +#else + return api_wl->rsi_check_queue_status(global_cb_p, queue); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_block_queue(rsi_queue_cb_t *queue) + * @brief Block the queue. + * @param[in] queue - pointer to queue + * @return void + */ +/// @private +void rsi_block_queue(rsi_queue_cb_t *queue) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_block_queue(global_cb_p, queue); +#else + api_wl->rsi_block_queue(global_cb_p, queue); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_unblock_queue(rsi_queue_cb_t *queue) + * @brief Unblock the queue. + * @param[in] queue - pointer to queue + * @return void + */ +/// @private +void rsi_unblock_queue(rsi_queue_cb_t *queue) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_unblock_queue(global_cb_p, queue); +#else + api_wl->rsi_unblock_queue(global_cb_p, queue); +#endif +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_queue_rom.c b/wiseconnect/sapi/driver/rsi_queue_rom.c new file mode 100644 index 00000000..01c88980 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_queue_rom.c @@ -0,0 +1,260 @@ +/******************************************************************************* +* @file rsi_queue_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/*==============================================*/ +/* + Include files + */ +#include "rsi_driver.h" +#ifndef ROM_WIRELESS + +/** @addtogroup DRIVER16 +* @{ +*/ +/*==============================================*/ +/** + * + * @fn void ROM_WL_rsi_queues_init(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) + * @brief Initialize queue + * @param[in] queue - pointer to queue + * @param[in] global_cb_p - pointer to the global control block + * @return void + * + */ +/// @private +void ROM_WL_rsi_queues_init(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + //! Initialize head pointer to NULL + queue->head = NULL; + + // Initialize tail pointer to NULL + queue->tail = NULL; + + // Initialize pending packet count to zero + queue->pending_pkt_count = 0; + + // Initialize queue mask to zero + queue->queue_mask = 0; + + // Mutex for queues + RSI_MUTEX_CREATE(&queue->queue_mutex); +} + +/*==============================================*/ +/** + * @fn void ROM_WL_rsi_enqueue_pkt(global_cb_t *global_cb_p, rsi_queue_cb_t *queue,rsi_pkt_t *pkt) + * @brief Enqueue packet into queue + * @param[in] global_cb_p - pointer to the global control block + * @param[in] queue - pointer to queue cb + * @param[in] pkt - packet pointer which needs to be queued + * @return void + */ + +void ROM_WL_rsi_enqueue_pkt(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + //! take lock on queue + RSI_MUTEX_LOCK(&queue->queue_mutex); + + // check queue is empty + if (!queue->pending_pkt_count) { + // if empty then add packet as first packet (head & tail point to first packet) + queue->head = queue->tail = pkt; + } else { + // if not empty append the packet to list at tail + queue->tail->next = pkt; + + // Make packet as tail + queue->tail = pkt; + } + + // increment packet pending count + queue->pending_pkt_count++; + + // Unlock the queue + RSI_MUTEX_UNLOCK(&queue->queue_mutex); +} +/*==============================================*/ +/** + * @fn rsi_pkt_t *ROM_WL_rsi_dequeue_pkt(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) + * @brief Dequeue packet from queue + * @param[in] global_cb_p - pointer to the global control block + * @param[in] queue - queue pointer from which packet needs to be dequeued + * @return Allocated packet pointer - Success \n + * @return NULL - Failure + */ +/// @private +rsi_pkt_t *ROM_WL_rsi_dequeue_pkt(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + rsi_pkt_t *pkt; + + // lock the mutex + RSI_MUTEX_LOCK(&queue->queue_mutex); + + // check queue is empty + if (!queue->pending_pkt_count) { + + RSI_MUTEX_UNLOCK(&queue->queue_mutex); + // return NULL if queue is empty + return NULL; + } + + // dequeue the packet from queue + pkt = queue->head; + + // update the queue head and decrement pending count + queue->head = queue->head->next; + + // Decrease pending packet count + queue->pending_pkt_count--; + + // if pending count is zero, then reset head and tail + if (!queue->pending_pkt_count) { + queue->head = NULL; + queue->tail = NULL; + } + + // Unlock the mutex + RSI_MUTEX_UNLOCK(&queue->queue_mutex); + + // return the packet + return pkt; +} +/*==============================================*/ +/** + * @fn uint32_t ROM_WL_rsi_check_queue_status(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) + * @brief Return packet pending count in queue + * @param[in] global_cb_p - pointer to the global control block + * @param[in] queue - pointer to queue + * @return 0 - If queue masked \n + * @return Number of packets pending - If queue is not masked + */ +/// @private +uint32_t ROM_WL_rsi_check_queue_status(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + uint32_t pkt_count = 0; + + // lock the mutex + RSI_MUTEX_LOCK(&queue->queue_mutex); + + // check whether queue is masked or not + if (queue->queue_mask) { + + // Unlock the mutex + RSI_MUTEX_UNLOCK(&queue->queue_mutex); + + // if queue masked return 0 + return 0; + } else { + pkt_count = queue->pending_pkt_count; + + // Unlock the mutex + RSI_MUTEX_UNLOCK(&queue->queue_mutex); + + // if queue is not masked return number of packets pending + return pkt_count; + } +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_block_queue(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) + * @brief Block the queue. + * @param[in] global_cb_p - pointer to the global control block + * @param[in] queue - pointer to queue + * @return void + */ +/// @private +void ROM_WL_rsi_block_queue(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + // lock the mutex + RSI_MUTEX_LOCK(&queue->queue_mutex); + + // Mask the queue + queue->queue_mask = 1; + + // Unlock the mutex + RSI_MUTEX_UNLOCK(&queue->queue_mutex); +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_unblock_queue(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) + * @brief Unblock the queue. + * @param[in] global_cb_p - pointer to the global control block + * @param[in] queue - pointer to queue + * @return void + */ +/// @private +void ROM_WL_rsi_unblock_queue(global_cb_t *global_cb_p, rsi_queue_cb_t *queue) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + // lock the mutex + RSI_MUTEX_LOCK(&queue->queue_mutex); + + // Unmask the queue + queue->queue_mask = 0; + + // Unlock the mutex + RSI_MUTEX_UNLOCK(&queue->queue_mutex); +} +#endif + +/*==============================================*/ +/** + * @fn void ROM_WL_rsi_enqueue_pkt_from_isr(global_cb_t *global_cb_p, rsi_queue_cb_t *queue,rsi_pkt_t *pkt) + * @brief Enqueue packet from ISR into queue + * @param[in] global_cb_p - pointer to the global control block + * @param[in] queue - pointer to queue cb + * @param[in] pkt - packet pointer which needs to be queued + * @return void + */ +/// @private +void ROM_WL_rsi_enqueue_pkt_from_isr(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt) +{ + UNUSED_PARAMETER(global_cb_p); //This statement is added only to resolve compilation warning, value is unchanged + // check queue is empty + if (!queue->pending_pkt_count) { + // if empty then add packet as first packet (head & tail point to first packet) + queue->head = queue->tail = pkt; + } else { + // if not empty append the packet to list at tail + queue->tail->next = pkt; + + // Make packet as tail + queue->tail = pkt; + } + + // increment packet pending count + queue->pending_pkt_count++; +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_scheduler.c b/wiseconnect/sapi/driver/rsi_scheduler.c new file mode 100644 index 00000000..d078b898 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_scheduler.c @@ -0,0 +1,187 @@ +/******************************************************************************* +* @file rsi_scheduler.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ +#include "rsi_driver.h" +#ifdef SLEEP_WAKEUP_LOGGING +#include "sleep_wakeup_logging.h" +#endif +/* + Global Variables + */ + +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) +volatile uint32_t rsi_driver_eventmap; +#endif +#if defined(FW_LOGGING_ENABLE) && !defined(RSI_WITH_OS) +void sl_fw_log_task(void); +#endif +uint8_t rsi_get_intr_status(void); +/** @addtogroup DRIVER15 +* @{ +*/ +/*====================================================*/ +/** + * @fn void rsi_scheduler_init(rsi_scheduler_cb_t *scheduler_cb) + * @brief Initialize scheduler + * @param[in] scheduler_cb - pointer to scheduler control block structure + * @return void + */ +/// @private +void rsi_scheduler_init(rsi_scheduler_cb_t *scheduler_cb) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_scheduler_init(global_cb_p, scheduler_cb); +#else + api_wl->rsi_scheduler_init(global_cb_p, scheduler_cb); +#endif + return; +} +/*====================================================*/ +/** + * @fn uint32_t rsi_get_event(rsi_scheduler_cb_t *scheduler_cb) + * @brief Get an event + * @param[in] scheduler_cb - pointer to scheduler cb structure + * @return Current event map + */ +/// @private +uint32_t rsi_get_event(rsi_scheduler_cb_t *scheduler_cb) +{ +#if ((defined RSI_SPI_INTERFACE) || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + return rsi_get_event_non_rom(scheduler_cb); +#elif (defined(ROM_WIRELESS)) + return ROMAPI_WL->rsi_get_event(global_cb_p, scheduler_cb); +#else + return api_wl->rsi_get_event(global_cb_p, scheduler_cb); +#endif +} + +/*====================================================*/ +/** + * @fn void rsi_scheduler(rsi_scheduler_cb_t *scheduler_cb) + * @brief Handles events + * @param[in] scheduler_cb - pointer to scheduler cb structure + * @return void + */ +/// @private +void rsi_scheduler(rsi_scheduler_cb_t *scheduler_cb) +{ +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) + rsi_scheduler_non_rom(scheduler_cb); +#elif (defined(ROM_WIRELESS)) + ROMAPI_WL->rsi_scheduler(global_cb_p, scheduler_cb); +#else + api_wl->rsi_scheduler(global_cb_p, scheduler_cb); +#if defined(FW_LOGGING_ENABLE) && !defined(RSI_WITH_OS) + sl_fw_log_task(); +#endif +#if defined(SLEEP_WAKEUP_LOGGING) && !defined(RSI_WITH_OS) + sl_sleepwakeup_log_task(); +#endif +#endif +} +/*====================================================*/ +/** + * @fn uint32_t rsi_get_event_non_rom(rsi_scheduler_cb_t *scheduler_cb) + * @brief Get an event on ROM + * @param[in] scheduler_cb - pointer to scheduler cb structure + * @return Current event map + */ +/// @private +uint32_t rsi_get_event_non_rom(rsi_scheduler_cb_t *scheduler_cb) +{ + uint32_t active_int_event_map; + + rsi_reg_flags_t flags; + + // Disable all the interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + // Get current event map after applying mask + active_int_event_map = (scheduler_cb->event_map & scheduler_cb->mask_map); +#if ((defined RSI_SPI_INTERFACE) || ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM))) + + if (rsi_get_intr_status() && (!(active_int_event_map & BIT(RSI_RX_EVENT)))) { + // Disable the interrupt + rsi_hal_intr_mask(); + // Set event RX pending from device + rsi_set_event(RSI_RX_EVENT); + } +#endif + + // Enable all the interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + return active_int_event_map; +} + +#if (defined(RSI_WITH_OS) && (RSI_TASK_NOTIFY)) +/*====================================================*/ +/** + * @fn void rsi_scheduler_non_rom(rsi_scheduler_cb_t *scheduler_cb) + * @brief Handles events + * @param[in] scheduler_cb - pointer to scheduler cb structure \n + * @return void + */ + +void rsi_scheduler_non_rom(rsi_scheduler_cb_t *scheduler_cb) +{ + uint32_t event_no; + rsi_event_cb_t *temp_event; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + uint32_t max_block_time = 0xFFFFFFFF; + rsi_base_type_t retval; + // Wait for events + + retval = rsi_task_notify_wait(0, /* Don't clear bits on entry. */ + max_block_time, /* Clear all bits on exit. */ + (uint32_t *)&rsi_driver_eventmap, /* Stores the notified value. */ + max_block_time); + if (retval == 1) { + while (rsi_get_event(scheduler_cb)) { + // Find event event + + event_no = rsi_find_event((scheduler_cb->event_map & scheduler_cb->mask_map)); + + // Get event handler + temp_event = &rsi_driver_cb->event_list[event_no]; + + if (temp_event->event_handler) { + // Call event handler + temp_event->event_handler(); + } else { + + rsi_clear_event(event_no); //Clear unregistered events + global_cb_p->rsi_driver_cb->unregistered_event_callback(event_no); + } + + if (global_cb_p->os_enabled != 1) { + break; + } + } + } +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_scheduler_rom.c b/wiseconnect/sapi/driver/rsi_scheduler_rom.c new file mode 100644 index 00000000..44aa6c7d --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_scheduler_rom.c @@ -0,0 +1,134 @@ +/******************************************************************************* +* @file rsi_scheduler_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ +#include "rsi_driver.h" +#ifndef ROM_WIRELESS +/* + Global Variables + */ + +/** @addtogroup DRIVER15 +* @{ +*/ +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_scheduler_init(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb) + * @brief Initialize scheduler + * @param[in] global_cb_p - pointer to the global control block + * @param[in] scheduler_cb - pointer to scheduler structure + * @return void + */ +/// @private +void ROM_WL_rsi_scheduler_init(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb) +{ + // Set no event + scheduler_cb->event_map = 0x0; + + // Set no mask + scheduler_cb->mask_map = 0xFFFFFFFF; + + if (global_cb_p->os_enabled == 1) { + // create semaphore + RSI_SEMAPHORE_CREATE(&scheduler_cb->scheduler_sem, 0); + } + + return; +} +/*====================================================*/ +/** + * @fn uint32_t ROM_WL_rsi_get_event(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb) + * @brief Get an event + * @param[in] global_cb_p - pointer to the global control block + * @param[in] scheduler_cb - pointer to scheduler structure + * @return Current event map + */ +/// @private +uint32_t ROM_WL_rsi_get_event(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + uint32_t active_int_event_map; + + rsi_reg_flags_t flags; + + // Disable all the interrupts + flags = RSI_CRITICAL_SECTION_ENTRY(); + + // Get current event map after applying mask + active_int_event_map = (scheduler_cb->event_map & scheduler_cb->mask_map); + + // Enable all the interrupts + RSI_CRITICAL_SECTION_EXIT(flags); + + return active_int_event_map; +} + +/*====================================================*/ +/** + * @fn void ROM_WL_rsi_scheduler(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb) + * @brief Handles events + * @param[in] global_cb_p - pointer to the global control block + * @param[in] scheduler_cb - pointer to scheduler cb structure + * @return void + */ +/// @private +void ROM_WL_rsi_scheduler(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb) +{ + uint32_t event_no; + rsi_event_cb_t *temp_event; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; +#ifdef RSI_M4_INTERFACE + while (ROM_WL_rsi_get_event(global_cb_p, scheduler_cb)) +#else + while (rsi_get_event(scheduler_cb)) +#endif + { + // Find event event + event_no = ROM_WL_rsi_find_event(global_cb_p, (scheduler_cb->event_map & scheduler_cb->mask_map)); + + // Get event handler + temp_event = &rsi_driver_cb->event_list[event_no]; + + if (temp_event->event_handler) { + // Call event handler + temp_event->event_handler(); + } else { + + ROM_WL_rsi_clear_event(global_cb_p, event_no); //Clear unregistered events + global_cb_p->rsi_driver_cb->unregistered_event_callback(event_no); + } + + if (global_cb_p->os_enabled != 1) { + break; + } + } + + if (global_cb_p->os_enabled == 1) { + RSI_SEMAPHORE_WAIT(&scheduler_cb->scheduler_sem, 0); + } +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_setregion_countryinfo.c b/wiseconnect/sapi/driver/rsi_setregion_countryinfo.c new file mode 100644 index 00000000..083a61eb --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_setregion_countryinfo.c @@ -0,0 +1,197 @@ +/******************************************************************************* +* @file rsi_setregion_countryinfo.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Includes + */ + +#include "rsi_setregion_countryinfo.h" + +#if RSI_SET_REGION_AP_FROM_USER + +/** @addtogroup DRIVER10 +* @{ +*/ +/*====================================================*/ +/** + * @fn void extract_setregionap_country_info(rsi_req_set_region_ap_t *rsi_set_region_ap) + * @brief Initialize the global parameter structure with parameters used in set region ap command based on the region. + * @param[in] ptr_setreg_ap - Pointer to the global parameter structure + * @return void + */ +///@private +void extract_setregionap_country_info(rsi_req_set_region_ap_t *rsi_set_region_ap) +{ + // The given domain rules are generic rules for some of the countries + // USER can configure the domain regulations for the respective countries + uint8_t region_code; + + if (!strcmp(RSI_COUNTRY_CODE, "US ")) + region_code = REGION_US; + else if (!strcmp(RSI_COUNTRY_CODE, "EU ")) + region_code = REGION_EU; + else if (!strcmp(RSI_COUNTRY_CODE, "JP ")) + region_code = REGION_JP; + else if (!strcmp(RSI_COUNTRY_CODE, "SG ")) + region_code = REGION_SINGAPORE; + else if (!strcmp(RSI_COUNTRY_CODE, "KR ")) + region_code = REGION_KOREA; + + switch (region_code) { + case REGION_US: { + + if (RSI_BAND == RSI_BAND_2P4GHZ) { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 1; + rsi_set_region_ap->channel_info[0].no_of_channels = 11; + rsi_set_region_ap->channel_info[0].max_tx_power = 27; + } else { + rsi_set_region_ap->no_of_rules[0] = 5; + rsi_set_region_ap->channel_info[0].first_channel = 36; + rsi_set_region_ap->channel_info[0].no_of_channels = 4; + rsi_set_region_ap->channel_info[0].max_tx_power = 16; + rsi_set_region_ap->channel_info[1].first_channel = 52; + rsi_set_region_ap->channel_info[1].no_of_channels = 4; + rsi_set_region_ap->channel_info[1].max_tx_power = 23; + rsi_set_region_ap->channel_info[2].first_channel = 100; + rsi_set_region_ap->channel_info[2].no_of_channels = 5; + rsi_set_region_ap->channel_info[2].max_tx_power = 23; + rsi_set_region_ap->channel_info[3].first_channel = 132; + rsi_set_region_ap->channel_info[3].no_of_channels = 3; + rsi_set_region_ap->channel_info[3].max_tx_power = 23; + rsi_set_region_ap->channel_info[4].first_channel = 149; + rsi_set_region_ap->channel_info[4].no_of_channels = 5; + rsi_set_region_ap->channel_info[4].max_tx_power = 29; + } + } break; + case REGION_EU: { + if (RSI_BAND == RSI_BAND_2P4GHZ) { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 1; + rsi_set_region_ap->channel_info[0].no_of_channels = 13; + rsi_set_region_ap->channel_info[0].max_tx_power = 20; + } else { + rsi_set_region_ap->no_of_rules[0] = 3; + rsi_set_region_ap->channel_info[0].first_channel = 36; + rsi_set_region_ap->channel_info[0].no_of_channels = 4; + rsi_set_region_ap->channel_info[0].max_tx_power = 23; + rsi_set_region_ap->channel_info[1].first_channel = 52; + rsi_set_region_ap->channel_info[1].no_of_channels = 4; + rsi_set_region_ap->channel_info[1].max_tx_power = 23; + rsi_set_region_ap->channel_info[2].first_channel = 100; + rsi_set_region_ap->channel_info[2].no_of_channels = 11; + rsi_set_region_ap->channel_info[2].max_tx_power = 30; + } + + } break; + case REGION_JP: { + if (RSI_BAND == RSI_BAND_2P4GHZ) { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 1; + rsi_set_region_ap->channel_info[0].no_of_channels = 14; + rsi_set_region_ap->channel_info[0].max_tx_power = 20; + } else { + rsi_set_region_ap->no_of_rules[0] = 3; + rsi_set_region_ap->channel_info[0].first_channel = 36; + rsi_set_region_ap->channel_info[0].no_of_channels = 4; + rsi_set_region_ap->channel_info[0].max_tx_power = 20; + rsi_set_region_ap->channel_info[1].first_channel = 52; + rsi_set_region_ap->channel_info[1].no_of_channels = 4; + rsi_set_region_ap->channel_info[1].max_tx_power = 20; + rsi_set_region_ap->channel_info[2].first_channel = 100; + rsi_set_region_ap->channel_info[2].no_of_channels = 11; + rsi_set_region_ap->channel_info[2].max_tx_power = 30; + } + + } break; + + case REGION_SINGAPORE: + + { + if (RSI_BAND == RSI_BAND_2P4GHZ) { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 1; + rsi_set_region_ap->channel_info[0].no_of_channels = 13; + rsi_set_region_ap->channel_info[0].max_tx_power = 27; + } else { + rsi_set_region_ap->no_of_rules[0] = 5; + rsi_set_region_ap->channel_info[0].first_channel = 36; + rsi_set_region_ap->channel_info[0].no_of_channels = 4; + rsi_set_region_ap->channel_info[0].max_tx_power = 16; + rsi_set_region_ap->channel_info[1].first_channel = 52; + rsi_set_region_ap->channel_info[1].no_of_channels = 4; + rsi_set_region_ap->channel_info[1].max_tx_power = 23; + rsi_set_region_ap->channel_info[2].first_channel = 100; + rsi_set_region_ap->channel_info[2].no_of_channels = 5; + rsi_set_region_ap->channel_info[2].max_tx_power = 23; + rsi_set_region_ap->channel_info[3].first_channel = 132; + rsi_set_region_ap->channel_info[3].no_of_channels = 3; + rsi_set_region_ap->channel_info[3].max_tx_power = 23; + rsi_set_region_ap->channel_info[4].first_channel = 149; + rsi_set_region_ap->channel_info[4].no_of_channels = 4; + rsi_set_region_ap->channel_info[4].max_tx_power = 29; + } + } break; + case REGION_KOREA: { + if (RSI_BAND == RSI_BAND_2P4GHZ) { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 1; + rsi_set_region_ap->channel_info[0].no_of_channels = 13; + rsi_set_region_ap->channel_info[0].max_tx_power = 27; + } else { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 149; + rsi_set_region_ap->channel_info[0].no_of_channels = 4; + rsi_set_region_ap->channel_info[0].max_tx_power = 29; + } + } + + break; + default: { + if (RSI_BAND == RSI_BAND_2P4GHZ) { + rsi_set_region_ap->no_of_rules[0] = 1; + rsi_set_region_ap->channel_info[0].first_channel = 1; + rsi_set_region_ap->channel_info[0].no_of_channels = 11; + rsi_set_region_ap->channel_info[0].max_tx_power = 27; + } else { + rsi_set_region_ap->no_of_rules[0] = 5; + rsi_set_region_ap->channel_info[0].first_channel = 36; + rsi_set_region_ap->channel_info[0].no_of_channels = 4; + rsi_set_region_ap->channel_info[0].max_tx_power = 16; + rsi_set_region_ap->channel_info[1].first_channel = 52; + rsi_set_region_ap->channel_info[1].no_of_channels = 4; + rsi_set_region_ap->channel_info[1].max_tx_power = 23; + rsi_set_region_ap->channel_info[2].first_channel = 100; + rsi_set_region_ap->channel_info[2].no_of_channels = 5; + rsi_set_region_ap->channel_info[2].max_tx_power = 23; + rsi_set_region_ap->channel_info[3].first_channel = 132; + rsi_set_region_ap->channel_info[3].no_of_channels = 3; + rsi_set_region_ap->channel_info[3].max_tx_power = 23; + rsi_set_region_ap->channel_info[4].first_channel = 149; + rsi_set_region_ap->channel_info[4].no_of_channels = 5; + rsi_set_region_ap->channel_info[4].max_tx_power = 29; + } + } break; + } +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_timer.c b/wiseconnect/sapi/driver/rsi_timer.c new file mode 100644 index 00000000..4b06f349 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_timer.c @@ -0,0 +1,117 @@ +/******************************************************************************* +* @file rsi_timer.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +#include "rsi_timer.h" +#include "rsi_hal.h" + +/** @addtogroup DRIVER11 +* @{ +*/ +/*==============================================*/ +/** + * @fn void rsi_timer_expiry_interrupt_handler(void) + * @brief Called for every millisecond and increments the timer counter. + * @param[in] void + * @return void + * + */ + +void rsi_timer_expiry_interrupt_handler(void) +{ + rsi_driver_cb_non_rom->timer_counter++; +#ifdef RSI_SPI_INTERFACE +#ifdef RSI_HWTIMER + rsi_driver_cb_non_rom->rsi_spiTimer2++; + rsi_driver_cb_non_rom->rsi_spiTimer1++; + rsi_driver_cb_non_rom->rsi_spiTimer3++; +#endif +#endif +} + +/*==============================================*/ +/** + * @fn uint32_t rsi_timer_read_counter() + * @brief Read the timer counter value + * @param[in] void + * @return Timer counter value in milliseconds + * + */ + +uint32_t rsi_timer_read_counter(void) +{ + return rsi_hal_gettickcount(); +} + +/*==============================================*/ +/** + * @fn void rsi_init_timer(rsi_timer_instance_t *rsi_timer, uint32_t duration) + * @brief Initialize the timer instance + * @param[in] rsi_timer - timer instance + * @param[in] duration - duration in milli seconds + * @return Void + * + */ + +void rsi_init_timer(rsi_timer_instance_t *rsi_timer, uint32_t duration) +{ + rsi_timer->start_time = rsi_timer_read_counter(); + rsi_timer->timeout = duration; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_timer_expired(rsi_timer_instance_t *timer) + * @brief Check if the timer instance is expired + * @param[in] rsi_timer - timer instance + * @return 1 - if timer is expired \n + * @return 0 - if timer is not expired + * + */ + +int32_t rsi_timer_expired(rsi_timer_instance_t *timer) +{ + if ((rsi_timer_read_counter() - (timer->start_time)) > (timer->timeout)) + return 1; + else + return 0; +} + +/*==============================================*/ +/** + * @fn uint32_t rsi_timer_left(rsi_timer_instance_t *timer) + * @brief Get the remaining time for timer expiry. + * @param[in] rsi_timer - timer instance + * @return Positive value - Time left to expire \n + * @return 0 - Timer is expired + * + */ + +uint32_t rsi_timer_left(rsi_timer_instance_t *timer) +{ + int32_t left = (timer->timeout) - (rsi_timer_read_counter() - (timer->start_time)); + return (left < 0) ? 0 : left; +} +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_utils.c b/wiseconnect/sapi/driver/rsi_utils.c new file mode 100644 index 00000000..41cdf712 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_utils.c @@ -0,0 +1,667 @@ +/******************************************************************************* +* @file rsi_utils.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +#include +/* + Global defines + */ +/** @addtogroup DRIVER12 +* @{ +*/ +/*=============================================================================*/ +/** + * @fn void rsi_uint16_to_2bytes(uint8_t *dBuf, uint16_t val) + * @brief Convert uint16 to two byte array. + * @param[in] dBuf - Pointer to buffer to put the data in + * @param[in] val - Data to convert + * @return void + */ +void rsi_uint16_to_2bytes(uint8_t *dBuf, uint16_t val) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_uint16_to_2bytes(global_cb_p, dBuf, val); +#else + api_wl->rsi_uint16_to_2bytes(global_cb_p, dBuf, val); +#endif +} + +/*=============================================================================*/ +/** + * @fn void rsi_uint32_to_4bytes(uint8_t *dBuf, uint32_t val) + * @brief Convert uint32 to four byte array. + * @param[in] dBuf - Pointer to buffer to put the data in + * @param[in] val - Data to convert + * @return void + */ + +void rsi_uint32_to_4bytes(uint8_t *dBuf, uint32_t val) +{ +#ifdef ROM_WIRELESS + ROMAPI_WL->rsi_uint32_to_4bytes(global_cb_p, dBuf, val); +#else + api_wl->rsi_uint32_to_4bytes(global_cb_p, dBuf, val); +#endif +} + +/*=============================================================================*/ +/** + * @fn uint16_t rsi_bytes2R_to_uint16(uint8_t *dBuf) + * @brief Convert a 2 byte array to uint16, first byte in array is LSB. + * @param[in] dBuf - Pointer to a buffer to get the data from + * @return Converted 16 bit data + */ +uint16_t rsi_bytes2R_to_uint16(uint8_t *dBuf) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_bytes2R_to_uint16(global_cb_p, dBuf); +#else + return api_wl->rsi_bytes2R_to_uint16(global_cb_p, dBuf); +#endif +} + +/*=============================================================================*/ +/** + * @fn uint32_t rsi_bytes4R_to_uint32(uint8_t *dBuf) + * @brief Convert a 4 byte array to uint32, first byte in array is LSB. + * @param[in] dBuf - Pointer to a buffer to get the data from + * @return Converted 32 bit data + */ + +uint32_t rsi_bytes4R_to_uint32(uint8_t *dBuf) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->rsi_bytes4R_to_uint32(global_cb_p, dBuf); +#else + return api_wl->rsi_bytes4R_to_uint32(global_cb_p, dBuf); +#endif +} +/*==============================================*/ +/** + * @fn int8_t rsi_ascii_hex2num(int8_t ascii_hex_in) + * @brief ASCII to HEX conversion. + * @param[in] ascii_hex_in - ASCII HEX input + * @return HEX number + */ + +int8_t rsi_ascii_hex2num(int8_t ascii_hex_in) +{ + if ((ascii_hex_in >= '0') && (ascii_hex_in <= '9')) + return (ascii_hex_in - '0'); + if ((ascii_hex_in >= 'A') && (ascii_hex_in <= 'F')) + return (ascii_hex_in - 'A' + 10); + if ((ascii_hex_in >= 'a') && (ascii_hex_in <= 'f')) + return (ascii_hex_in - 'a' + 10); + + return RSI_SUCCESS; +} +/*=============================================================================*/ +/** + * @fn int8 rsi_char_hex2dec(int8_t *cBuf) + * @brief Convert given ASCII HEX notation to decimal notation (used for MAC address). + * @param[in] cBuf - ASCII HEX notation string + * @return Integer Value + */ + +int8_t rsi_char_hex2dec(int8_t *cBuf) +{ + int8_t k = 0; + uint8_t i; + for (i = 0; i < strlen((char *)cBuf); i++) { + k = ((k * 16) + rsi_ascii_hex2num(cBuf[i])); + } + return k; +} + +/*=============================================================================*/ +/** + * @fn uint8_t *rsi_ascii_dev_address_to_6bytes_rev(uint8_t *hex_addr, int8_t *ascii_mac_address) + * @brief Convert notation MAC address to a 6-byte HEX address. + * @param[in] asciiMacFormatAddress - Source address to convert, must be a null terminated string. + * @param[out] hex_addr - Converted HEX address. + * @return HEX address + */ + +uint8_t *rsi_ascii_dev_address_to_6bytes_rev(uint8_t *hex_addr, int8_t *ascii_mac_address) +{ + uint8_t i; // loop counter + uint8_t cBufPos; // which char in the ASCII representation + uint8_t byteNum; // which byte in the 32Bithex_address + int8_t cBuf[6]; // temporary buffer + + byteNum = 5; + cBufPos = 0; + for (i = 0; i < strlen((char *)ascii_mac_address); i++) { + // this will take care of the first 5 octets + if (ascii_mac_address[i] == ':') { // we are at the end of the address octet + cBuf[cBufPos] = 0; // terminate the string + cBufPos = 0; // reset for the next char + hex_addr[byteNum--] = (uint8_t)rsi_char_hex2dec((int8_t *)cBuf); // convert the strint to an integer + } else { + cBuf[cBufPos++] = ascii_mac_address[i]; + } + } + // handle the last octet // we are at the end of the string with no . + cBuf[cBufPos] = 0x00; // terminate the string + hex_addr[byteNum] = (uint8_t)rsi_char_hex2dec((int8_t *)cBuf); // convert the strint to an integer + + return hex_addr; +} + +/*=============================================================================*/ +/** + * @fn int8_t hex_to_ascii(uint8_t hex_num) + * @brief Hex to ascii conversion. + * @param[in] hex_num - HEX number + * @return Ascii value for given HEX value + */ + +int8_t hex_to_ascii(uint8_t hex_num) +{ + uint8_t ascii = 0; + + switch (hex_num & 0x0F) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ascii = (hex_num & 0x0F) + '0'; + return ascii; + + case 0xa: + case 0xb: + case 0xc: + case 0xd: + case 0xe: + case 0xf: + ascii = (hex_num & 0x0F) - 10 + 'A'; + return ascii; + // break; + default: + break; + } + + return ascii; +} + +/*=============================================================================*/ +/** + * @fn int8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, uint8_t *hex_addr) + * @brief Convert given 6-byte HEX address to ASCII Mac address. + * @param[in] hex_addr - HEX address input. + * @param[out] asciiMacFormatAddress - Converted ASCII mac address is returned here. + * @return Converted ASCII mac address + */ + +uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, uint8_t *hex_addr) +{ + int8_t i; // loop counter + uint8_t cBufPos; // which char in the ASCII representation + + //byteNum = 5; + cBufPos = 0; + for (i = 5; i >= 0; i--) { + ascii_mac_address[cBufPos++] = hex_to_ascii(hex_addr[i] >> 4); + ascii_mac_address[cBufPos++] = hex_to_ascii(hex_addr[i]); + if (i != 0) { + ascii_mac_address[cBufPos++] = ':'; + } + } + return ascii_mac_address; +} + +/*==============================================*/ +/** + * @fn uint8_t lmac_crc8_c(uint8_t crc8_din, uint8_t crc8_state, uint8_t end) + * @brief Calculate CRC for a given byte and accumulate CRC. + * @param[in] crc8_din - CRC byte input + * @param[in] crc8_state - accumulated CRC + * @param[in] end - last byte CRC + * @return CRC value + * + */ +///@private +uint8_t lmac_crc8_c(uint8_t crc8_din, uint8_t crc8_state, uint8_t end) +{ + uint8_t din[8]; + uint8_t state[8]; + uint8_t state_c[8]; + uint8_t crc8_out; + + din[0] = ((crc8_din & BIT(7)) >> 7); + din[1] = ((crc8_din & BIT(6)) >> 6); + din[2] = ((crc8_din & BIT(5)) >> 5); + din[3] = ((crc8_din & BIT(4)) >> 4); + din[4] = ((crc8_din & BIT(3)) >> 3); + din[5] = ((crc8_din & BIT(2)) >> 2); + din[6] = ((crc8_din & BIT(1)) >> 1); + din[7] = ((crc8_din & BIT(0)) >> 0); + + state[0] = ((crc8_state & BIT(0)) >> 0); + state[1] = ((crc8_state & BIT(1)) >> 1); + state[2] = ((crc8_state & BIT(2)) >> 2); + state[3] = ((crc8_state & BIT(3)) >> 3); + state[4] = ((crc8_state & BIT(4)) >> 4); + state[5] = ((crc8_state & BIT(5)) >> 5); + state[6] = ((crc8_state & BIT(6)) >> 6); + state[7] = ((crc8_state & BIT(7)) >> 7); + + state_c[7] = (state[7] ^ din[7]) ^ (state[6] ^ din[6]) ^ (state[5] ^ din[5]); + + state_c[6] = (state[6] ^ din[6]) ^ (state[5] ^ din[5]) ^ (state[4] ^ din[4]); + + state_c[5] = (state[5] ^ din[5]) ^ (state[4] ^ din[4]) ^ (state[3] ^ din[3]); + + state_c[4] = (state[4] ^ din[4]) ^ (state[3] ^ din[3]) ^ (state[2] ^ din[2]); + + state_c[3] = (state[1] ^ din[1]) ^ (state[2] ^ din[2]) ^ (state[3] ^ din[3]) ^ (state[7] ^ din[7]); + + state_c[2] = (state[0] ^ din[0]) ^ (state[1] ^ din[1]) ^ (state[2] ^ din[2]) ^ (state[6] ^ din[6]); + + state_c[1] = (state[0] ^ din[0]) ^ (state[1] ^ din[1]) ^ (state[6] ^ din[6]); + + state_c[0] = (state[0] ^ din[0]) ^ (state[7] ^ din[7]) ^ (state[6] ^ din[6]); + if (!end) { + crc8_out = ((state_c[0] & BIT(0)) << 0) | ((state_c[1] & BIT(0)) << 1) | ((state_c[2] & BIT(0)) << 2) + | ((state_c[3] & BIT(0)) << 3) | ((state_c[4] & BIT(0)) << 4) | ((state_c[5] & BIT(0)) << 5) + | ((state_c[6] & BIT(0)) << 6) | ((state_c[7] & BIT(0)) << 7); + } else { + crc8_out = ((state_c[7] & BIT(0)) << 0) | ((state_c[6] & BIT(0)) << 1) | ((state_c[5] & BIT(0)) << 2) + | ((state_c[4] & BIT(0)) << 3) | ((state_c[3] & BIT(0)) << 4) | ((state_c[2] & BIT(0)) << 5); + + crc8_out = ~crc8_out; + crc8_out &= 0x3f; + } + return (crc8_out); +} + +/*==============================================*/ +/** + * @fn uint8_t multicast_mac_hash(uint8_t *mac) + * @brief Calculate 6-bit hash value for given MAC address + * @param[in] mac - pointer to MAC address + * @return 6-bit Hash value + * + */ +/// @private +uint8_t multicast_mac_hash(uint8_t *mac) +{ + uint8_t i, crc = 0xff; + for (i = 0; i < 6; i++) { + crc = lmac_crc8_c(mac[i], crc, ((i == 5) ? 1 : 0)); + } + return (crc); +} + +/*=========================================================================*/ +/** + * @fn uint8_t convert_lower_case_to_upper_case(uint8_t lwrcase) + * @brief Convert the given lower-case character to upper case. + * @param[in] lwrcase - Lower case character to convert + * @return Converted Upper case character + */ + +uint8_t convert_lower_case_to_upper_case(uint8_t lwrcase) +{ + uint8_t digit = (lwrcase >= 'a' && lwrcase <= 'f') ? (lwrcase - 0x20) : lwrcase; + return (digit >= 'A' && digit <= 'F') ? digit - 0x37 : digit - '0'; +} + +/*=========================================================================*/ +/** + * @fn void string2array(uint8_t *dst, uint8_t *src, uint32_t length) + * @brief Convert the given string to array. + * @param[in] dst - Pointer to destination array + * @param[in] src - Pointer to source string + * @param[in] length - Length of the string + * @return Void + */ + +void string2array(uint8_t *dst, uint8_t *src, uint32_t length) +{ + uint32_t i = 0, j = 0; + for (i = 0, j = 0; i < (length * 2) && j < length; i += 2, j++) + if (src[i] && src[i + 1]) { + dst[j] = ((uint16_t)convert_lower_case_to_upper_case(src[i])) * 16; + dst[j] += convert_lower_case_to_upper_case(src[i + 1]); + } else { + dst[j] = 0; + } +} +/*=========================================================================*/ +/** + * @fn uint8_t *rsi_itoa(uint32_t val, uint8_t *str) + * @brief Convert integer value into null-terminated string and stores it. + * @param[in] val - Value to be converted to a string + * @param[in] str - Array in memory where to store the resulting null-terminated string + * @return Null-terminated string + */ + +uint8_t *rsi_itoa(uint32_t val, uint8_t *str) +{ + int16_t ii = 0, jj = 0; + uint8_t tmp[10]; + if (val == 0) { + // if value is zero then handling + str[jj] = '0'; + jj++; + str[jj] = '\0'; + return str; + } + + while (val) { + tmp[ii] = '0' + (val % 10); + val /= 10; + ii++; + } + + for (jj = 0, ii--; ii >= 0; ii--, jj++) { + str[jj] = tmp[ii]; + } + str[jj] = '\0'; + + return str; +} + +/*=========================================================================*/ +/** + * @fn int32_t rsi_atoi(const int8_t *str) + * @brief Convert string to an integer. + * @param[in] str - String to be converted to integer + * @return Converted Integer + */ +int32_t rsi_atoi(const int8_t *str) +{ + int32_t res = 0; + int32_t i = 0; + uint32_t negative_number = 0; + + if (str[i] == '-') { + negative_number = 1; + i++; + } + for (; (str[i] >= '0') && (str[i] <= '9'); ++i) + res = res * 10 + str[i] - '0'; + + if (negative_number) { + res *= -1; + } + return res; +} + +/*=============================================================================*/ +/** + * @fn int8_t asciihex_2_num(int8_t ascii_hex_in) + * @brief ASCII to hex conversion. + * @param[in] ascii_hex_in - ASCII hex input + * @return HEX number + */ +int8_t asciihex_2_num(int8_t ascii_hex_in) +{ + if ((ascii_hex_in >= '0') && (ascii_hex_in <= '9')) + return (ascii_hex_in - '0'); + if ((ascii_hex_in >= 'A') && (ascii_hex_in <= 'F')) + return (ascii_hex_in - 'A' + 10); + if ((ascii_hex_in >= 'a') && (ascii_hex_in <= 'f')) + return (ascii_hex_in - 'a' + 10); + + return RSI_SUCCESS; +} + +/*=============================================================================*/ +/** + * @fn int8_t rsi_charhex_2_dec(int8_t *cBuf) + * @brief Convert given ASCII HEX notation to decimal notation (used for mac address). + * @param[in] cBuf - ASCII HEX notation string. + * @return Integer value + */ +int8_t rsi_charhex_2_dec(int8_t *cBuf) +{ + int8_t k = 0; + uint8_t i; + for (i = 0; i < strlen((char *)cBuf); i++) { + k = ((k * 16) + asciihex_2_num(cBuf[i])); + } + return k; +} + +/*=============================================================================*/ +/** + * @fn void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress) + * @brief Convert ASCII notation MAC address to a 6-byte HEX address. + * @param[in] asciiMacFormatAddress - Source address to convert, must be a null terminated string. + * @param[out] hexAddr - Converted HEX address is returned here. + * @return Void + */ +void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress) +{ + uint8_t i; // loop counter + uint8_t cBufPos; // which char in the ASCII representation + uint8_t byteNum; // which byte in the 32BitHexAddress + int8_t cBuf[6]; // temporary buffer + + byteNum = 0; + cBufPos = 0; + for (i = 0; i < strlen((char *)asciiMacAddress); i++) { + // this will take care of the first 5 octets + if (asciiMacAddress[i] == ':') { // we are at the end of the address octet + cBuf[cBufPos] = 0; // terminate the string + cBufPos = 0; // reset for the next char + hexAddr[byteNum++] = (uint8_t)rsi_charhex_2_dec((int8_t *)cBuf); // convert the strint to an integer + } else { + cBuf[cBufPos++] = asciiMacAddress[i]; + } + } + // handle the last octet // we are at the end of the string with no . + cBuf[cBufPos] = 0x00; // terminate the string + hexAddr[byteNum] = (uint8_t)rsi_charhex_2_dec((int8_t *)cBuf); // convert the strint to an integer +} + +/*=============================================================================*/ +/** + * @fn void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress) + * @brief Convert ASCII notation network address to 4-byte HEX address. + * @param[in] asciiDotAddress - Source address to convert, must be a null terminated string. + * @param[out] hexAddr - Output value is passed back in the 4-byte HEX Address. + * @return Void + */ +void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress) +{ + uint8_t i; + // loop counter + uint8_t cBufPos; + // which char in the ASCII representation + uint8_t byteNum; + // which byte in the 32BitHexAddress + int8_t cBuf[4]; + // character buffer + + byteNum = 0; + cBufPos = 0; + for (i = 0; i < strlen((char *)asciiDotAddress); i++) { + // this will take care of the first 3 octets + if (asciiDotAddress[i] == '.') { + // we are at the end of the address octet + cBuf[cBufPos] = 0; + // terminate the string + cBufPos = 0; + // reset for the next char + hexAddr[byteNum++] = (uint8_t)rsi_atoi(cBuf); + // convert the strint to an integer + } else { + cBuf[cBufPos++] = asciiDotAddress[i]; + } + } + // handle the last octet + // we are at the end of the string with no . + cBuf[cBufPos] = 0x00; + // terminate the string + // convert the strint to an integer + hexAddr[byteNum] = (uint8_t)rsi_atoi(cBuf); +} +/*=============================================================================*/ +/** + * @fn uint64_t ip_to_reverse_hex(char *ip) + * @brief Convert IP address to reverse HEX format. + * @param[in] ip - IP address to convert. + * @return IP address in reverse HEX format + */ +uint64_t ip_to_reverse_hex(char *ip) +{ + uint32_t ip1, ip2, ip3, ip4; + uint64_t ip_hex; + uint32_t status; + + status = sscanf(ip, "%u.%u.%u.%u", &ip1, &ip2, &ip3, &ip4); + if (status != 4) { + return 0x00000000; // Problem if we actually pass 0.0.0.0 + } + + ip_hex = (uint64_t)ip1; + ip_hex |= (uint64_t)(ip2 << 8); + ip_hex |= (uint64_t)(ip3 << 16); + ip_hex |= (uint64_t)(ip4 << 24); + + return ip_hex; +} +/*=============================================================================*/ +/** + * @fn uint32_t rsi_ntohl(uint32_t a) + * @brief Converts the unsigned integer from network byte order to host byte order. + * @param[in] a - Unsigned integer to convert. + * @return Unsigned integer in host byte order + */ +// network to host long +uint32_t rsi_ntohl(uint32_t a) +{ + return ((((a)&0xff000000) >> 24) | (((a)&0x00ff0000) >> 8) | (((a)&0x0000ff00) << 8) | (((a)&0x000000ff) << 24)); +} +/*=============================================================================*/ +/** + * @fn uint8_t ascii_to_dec(uint8_t *num) + * @brief Convert ASCII to Decimal Value. + * @param[in] num - ASCII input + * @return dec_val - value after conversion + */ +uint8_t ascii_to_dec(uint8_t *num) +{ + uint8_t dec_val = 0, i = 0; + while (num[i] != '\0') { + dec_val = dec_val * 10 + (num[i] - '0'); + i++; + } + return dec_val; +} + +#if defined(FLOAT_PRINT_BYPASS) +/*=============================================================================*/ +/** + * @fn void rsi_reverse(char *str, int len) + * @brief Reverses the given string. + * @param[in] str - string to be reversed + * @param[in] len - the length of the given string + * @return void + */ + +void rsi_reverse(char *str, int len) +{ + int i = 0, j = len - 1, temp; + while (i < j) { + temp = str[i]; + str[i] = str[j]; + str[j] = temp; + i++; + j--; + } +} + +/*=============================================================================*/ +/** + * @fn int rsi_intToStr(int x, char str[], int d) + * @brief converts the integer into a string. + * @param[in] x - given interger to be made into a string + * @param[in] str - the string that stores the final string corresponding to the integer + * @param[in] d - the number of digits required in the output, should be less than 6. If d is more than the number of digits in x, then 0s are added at the beginning. + * @return the lenght of the string + */ +int rsi_intToStr(int x, char str[], int d) +{ + int i = 0; + while (x) { + str[i++] = (x % 10) + '0'; + x = x / 10; + } + + // If number of digits required is more, then + // add 0s at the beginning + while (i < d) + str[i++] = '0'; + + rsi_reverse(str, i); + str[i] = '\0'; + return i; +} + +/*=============================================================================*/ +/** + * @fn int rsi_intToStr(int x, char str[], int d) + * @brief Converts a floating-point/double number to a string. + * @param[in] res - the string in which the result must be stored + * @param[in] n - the float number that needs to be converted into a string + * @param[in] afterpoint - the number of points after the decimal that needs to be printed, should be less than 6. + * @return void + */ +void rsi_ftoa(char *res, float n, int afterpoint) +{ + float fpart; + // Extract integer part + int ipart = (int)n; + + // Extract floating part + fpart = n - (float)ipart; + + // convert integer part to string + int i = rsi_intToStr(ipart, res, 0); + + // check for display option after point + if (afterpoint != 0) { + res[i] = '.'; // add dot + int mult = 1; + for (int i = 0; i < afterpoint; i++) + mult *= 10; + fpart = fpart * mult; // supports 6 digits for now. + + rsi_intToStr((int)fpart, res + i + 1, afterpoint); + } +} +#endif + +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_utils_rom.c b/wiseconnect/sapi/driver/rsi_utils_rom.c new file mode 100644 index 00000000..cc636f46 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_utils_rom.c @@ -0,0 +1,140 @@ +/******************************************************************************* +* @file rsi_utils_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ +#include "rsi_driver.h" +#ifndef ROM_WIRELESS +/* + Global defines + */ + +/** @addtogroup DRIVER12 +* @{ +*/ +/*=============================================================================*/ +/** + * @fn void ROM_WL_rsi_uint16_to_2bytes(global_cb_t *global_cb_p, uint8_t *dBuf, uint16_t val) + * @brief Convert uint16 to two byte array + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] dBuf - pointer to buffer to put the data in + * @param[in] val - data to convert + * @return void + */ +/// @private +void ROM_WL_rsi_uint16_to_2bytes(global_cb_t *global_cb_p, uint8_t *dBuf, uint16_t val) +{ + if (global_cb_p->endian == IS_LITTLE_ENDIAN) { + dBuf[0] = val & 0x00ff; + dBuf[1] = (val >> 8) & 0x00ff; + } else { + dBuf[1] = val & 0x00ff; + dBuf[0] = (val >> 8) & 0x00ff; + } +} + +/*=============================================================================*/ +/** + * @fn void ROM_WL_rsi_uint32_to_4bytes(global_cb_t *global_cb_p, uint8_t *dBuf, uint32_t val) + * @brief Convert uint32 to four byte array + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] dBuf - pointer to the buffer to put the data in + * @param[in] val - data to convert + * @return void + */ +/// @private +void ROM_WL_rsi_uint32_to_4bytes(global_cb_t *global_cb_p, uint8_t *dBuf, uint32_t val) +{ + if (global_cb_p->endian == IS_LITTLE_ENDIAN) { + dBuf[0] = val & 0x000000ff; + dBuf[1] = (val >> 8) & 0x000000ff; + dBuf[2] = (val >> 16) & 0x000000ff; + dBuf[3] = (val >> 24) & 0x000000ff; + } else { + dBuf[3] = val & 0x000000ff; + dBuf[2] = (val >> 8) & 0x000000ff; + dBuf[1] = (val >> 16) & 0x000000ff; + dBuf[0] = (val >> 24) & 0x000000ff; + } +} + +/*=============================================================================*/ +/** + * @fn uint16_t ROM_WL_rsi_bytes2R_to_uint16(global_cb_t *global_cb_p, uint8_t *dBuf) + * @brief Convert a 2 byte array to uint16, first byte in array is LSB + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] dBuf - pointer to a buffer to get the data from + * @return Converted data + */ +/// @private +uint16_t ROM_WL_rsi_bytes2R_to_uint16(global_cb_t *global_cb_p, uint8_t *dBuf) +{ + uint16_t val; + if (global_cb_p->endian == IS_LITTLE_ENDIAN) { + val = dBuf[1]; + val <<= 8; + val |= dBuf[0] & 0x000000ff; + } else { + val = dBuf[0]; + val <<= 8; + val |= dBuf[1] & 0x000000ff; + } + return val; +} + +/*=============================================================================*/ +/** + * @fn uint32_t ROM_WL_rsi_bytes4R_to_uint32(global_cb_t *global_cb_p, uint8_t *dBuf) + * @brief Convert a 4 byte array to uint32, first byte in array is LSB + * @param[in] global_cb_p - pointer to the common buffer + * @param[in] dBuf - pointer to buffer to get the data from + * @return Converted data + */ +/// @private +uint32_t ROM_WL_rsi_bytes4R_to_uint32(global_cb_t *global_cb_p, uint8_t *dBuf) +{ + // the 32-bit value to return + uint32_t val; + + if (global_cb_p->endian == IS_LITTLE_ENDIAN) { + val = dBuf[3]; + val <<= 8; + val |= dBuf[2] & 0x000000ff; + val <<= 8; + val |= dBuf[1] & 0x000000ff; + val <<= 8; + val |= dBuf[0] & 0x000000ff; + } else { + val = dBuf[0]; + val <<= 8; + val |= dBuf[1] & 0x000000ff; + val <<= 8; + val |= dBuf[2] & 0x000000ff; + val <<= 8; + val |= dBuf[3] & 0x000000ff; + } + + return val; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/driver/rsi_wlan.c b/wiseconnect/sapi/driver/rsi_wlan.c new file mode 100644 index 00000000..b5338887 --- /dev/null +++ b/wiseconnect/sapi/driver/rsi_wlan.c @@ -0,0 +1,3442 @@ +/******************************************************************************* +* @file rsi_wlan.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + Include files + */ + +#include "rsi_driver.h" +#include "rsi_wlan_non_rom.h" +/* + Global Variables + * */ +extern rsi_driver_cb_t *rsi_driver_cb; +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; +extern rsi_socket_select_info_t *rsi_socket_select_info; +uint32_t scan_bitmap = RSI_SCAN_FEAT_BITMAP; +struct wpa_scan_results_arr *scan_results_array = NULL; +#ifdef PROCESS_SCAN_RESULTS_AT_HOST +int process_scan_results(uint8_t *buf, uint16_t len, int8_t rssi, uint8_t channel, uint16_t freq); +#endif +/** @addtogroup DRIVER13 +* @{ +*/ +/*==============================================*/ +/** + * @fn int8_t rsi_wlan_cb_init(rsi_wlan_cb_t *wlan_cb) + * @brief Initialize the WLAN control block structure. + * @param[in] wlan_cb - Pointer to WLAN cb structure + * @return 0 - Success \n + * @return Non Zero Value - Failure + */ +/// @private +int8_t rsi_wlan_cb_init(rsi_wlan_cb_t *wlan_cb) +{ + int8_t retval = RSI_ERR_NONE; + + // validate input parameter + if (wlan_cb == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + + // initialize wlan control block with default values + wlan_cb->state = RSI_WLAN_STATE_NONE; + wlan_cb->status = 0; + + // Create wlan mutex + rsi_mutex_create(&wlan_cb->wlan_mutex); + // Create wlan mutex + wlan_cb->expected_response = RSI_WLAN_RSP_CLEAR; + + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->nwk_cmd_send_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->wlan_cmd_send_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->send_data_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_cmd_send_sem); + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + // Create wlan semaphore + retval = rsi_semaphore_create(&wlan_cb->wlan_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->wlan_cmd_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + retval = rsi_semaphore_create(&rsi_driver_cb_non_rom->nwk_sem, 0); + if (retval != RSI_ERROR_NONE) { + return RSI_ERROR_SEMAPHORE_CREATE_FAILED; + } + wlan_cb->app_buffer = 0; + + return retval; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_driver_wlan_send_cmd(rsi_wlan_cmd_request_t cmd, rsi_pkt_t *pkt) + * @brief Fill the command information and place it in the WLAN TX queue + * @param[in] cmd - Type of the command to send + * @param[in] pkt - Pointer of the packet to send + * @return 0 - Success \n + * @return Non Zero Value - Failure + * + */ + +/// @private +int32_t rsi_driver_wlan_send_cmd(rsi_wlan_cmd_request_t cmd, rsi_pkt_t *pkt) +{ + uint16_t payload_size = 0; + int32_t status = RSI_SUCCESS; + uint8_t cmd_type = 0; + uint16_t multicast_bitmap = 0; + uint32_t mqtt_command_type; + // Get host descriptor pointer + uint8_t *host_desc = (pkt->desc); + switch (cmd) { + + case RSI_WLAN_REQ_BAND: { + rsi_req_band_t *rsi_band = (rsi_req_band_t *)pkt->data; + + // fill band value + rsi_band->band_value = RSI_BAND; + + // fill payload size + payload_size = sizeof(rsi_req_band_t); + + } break; + case RSI_WLAN_REQ_SELECT_REQUEST: { + payload_size = sizeof(rsi_req_socket_select_t); + } break; + case RSI_WLAN_REQ_UPDATE_TCP_WINDOW: { + payload_size = sizeof(rsi_req_tcp_window_update_t); + } break; +#if RSI_WLAN_CONFIG_ENABLE + case RSI_WLAN_REQ_CONFIG: { + rsi_req_config_t *rsi_config = (rsi_req_config_t *)pkt->data; + + // fill configuration type + rsi_config->config_type = CONFIG_RTSTHRESHOLD; + + // fill rtsthreshold value + rsi_config->value = RSI_RTS_THRESHOLD; + + // fill payload size + payload_size = sizeof(rsi_req_config_t); + } break; +#endif + + case RSI_WLAN_REQ_SET_MAC_ADDRESS: { + rsi_req_mac_address_t *rsi_set_mac = (rsi_req_mac_address_t *)pkt->data; + + // fill mac address + memcpy(rsi_set_mac->mac_address, rsi_driver_cb->wlan_cb->mac_address, 6); + + // fill payload size + payload_size = sizeof(rsi_req_mac_address_t); + + } break; + case RSI_WLAN_REQ_SET_MULTICAST_FILTER: { + + rsi_req_multicast_filter_info_t *multicast_filter; + + multicast_filter = (rsi_req_multicast_filter_info_t *)pkt->data; + + cmd_type = multicast_filter->cmd_type; + + multicast_bitmap = (uint16_t)cmd_type; + + /* not supported + if ((cmd_type == RSI_MULTICAST_MAC_ADD_BIT) || (cmd_type == RSI_MULTICAST_MAC_CLEAR_BIT)) { + multicast_bitmap |= (multicast_mac_hash((uint8_t *)multicast_filter->mac_address) << 8); + }*/ + + // memset the pkt + memset(&pkt->data, 0, 2); + + // copy processed payload in to buffer + rsi_uint16_to_2bytes((uint8_t *)&pkt->data, multicast_bitmap); + + // fill payload size + payload_size = 2; + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_SET_MULTICAST_FILTER; + + } break; + case RSI_WLAN_REQ_SET_REGION: { + rsi_req_set_region_t *rsi_set_region = (rsi_req_set_region_t *)pkt->data; + + // select set region code from user or from beacon + rsi_set_region->set_region_code_from_user_cmd = RSI_SET_REGION_FROM_USER_OR_BEACON; + + // fill region code + rsi_set_region->region_code = RSI_REGION_CODE; + + // fill module type + rsi_uint16_to_2bytes(rsi_set_region->module_type, RSI_MODULE_TYPE); + + // fill payload size + payload_size = sizeof(rsi_req_set_region_t); + + } break; + case RSI_WLAN_REQ_SET_REGION_AP: { + rsi_req_set_region_ap_t *rsi_set_region_ap = (rsi_req_set_region_ap_t *)pkt->data; + + // select set region code from user or flash + rsi_set_region_ap->set_region_code_from_user_cmd = RSI_SET_REGION_AP_FROM_USER; + + // fill region code + rsi_strcpy(rsi_set_region_ap->country_code, RSI_COUNTRY_CODE); + +#if RSI_SET_REGION_AP_FROM_USER + // extract set region ap information + extract_setregionap_country_info(rsi_set_region_ap); +#endif + + // fill payload size + payload_size = sizeof(rsi_req_set_region_ap_t); + + } break; + case RSI_WLAN_REQ_REJOIN_PARAMS: { + rsi_req_rejoin_params_t *rsi_rejoin = (rsi_req_rejoin_params_t *)pkt->data; + + // fill rejoin retry count + rsi_uint32_to_4bytes(rsi_rejoin->max_retry, RSI_REJOIN_MAX_RETRY); + + // fill rejoin retry scan interval + rsi_uint32_to_4bytes(rsi_rejoin->scan_interval, RSI_REJOIN_SCAN_INTERVAL); + + // fill beacon missed count + rsi_uint32_to_4bytes(rsi_rejoin->beacon_missed_count, RSI_REJOIN_BEACON_MISSED_COUNT); + + // fill rejoin first time retry enable or disable + rsi_uint32_to_4bytes(rsi_rejoin->first_time_retry_enable, RSI_REJOIN_FIRST_TIME_RETRY); + + // fill payload size + payload_size = sizeof(rsi_req_rejoin_params_t); + + } break; + case RSI_WLAN_REQ_11AX_PARAMS: { + wlan_11ax_config_params_t *config = (wlan_11ax_config_params_t *)pkt->data; + config->guard_interval = GUARD_INTERVAL; + config->nominal_pe = NOMINAL_PE; + config->dcm_enable = DCM_ENABLE; + config->ldpc_enable = LDPC_ENABLE; + config->ng_cb_enable = NG_CB_ENABLE; + config->ng_cb_values = NG_CB_VALUES; + config->uora_enable = UORA_ENABLE; + config->trigger_rsp_ind = TRIGGER_RESP_IND; + config->ipps_valid_value = IPPS_VALID_VALUE; + config->tx_only_on_ap_trig = TX_ONLY_ON_AP_TRIG; + config->twt_support = TWT_SUPPORT; + config->config_er_su = CONFIG_ER_SU; + + // fill payload size + payload_size = sizeof(wlan_11ax_config_params_t); + } break; + case RSI_WLAN_REQ_TWT_PARAMS: { + // fill payload size + payload_size = sizeof(rsi_twt_req_t); + } break; + case RSI_WLAN_REQ_EAP_CONFIG: { + rsi_req_eap_config_t *rsi_eap_req = (rsi_req_eap_config_t *)pkt->data; + + // copy enterprise configuratiomn data + rsi_strcpy((int8_t *)rsi_eap_req->eap_method, RSI_EAP_METHOD); + rsi_strcpy((int8_t *)rsi_eap_req->inner_method, RSI_EAP_INNER_METHOD); + rsi_uint32_to_4bytes((uint8_t *)rsi_eap_req->okc_enable, OKC_VALUE); + rsi_strcpy((int8_t *)rsi_eap_req->private_key_password, RSI_PRIVATE_KEY_PASSWORD); + + // fill payload size + payload_size = sizeof(rsi_req_eap_config_t); + + } break; + case RSI_WLAN_REQ_SCAN: { + // Scan Parameters + rsi_req_scan_t *rsi_scan = (rsi_req_scan_t *)pkt->data; + + // Sets channel bitmap for 2.4GHz + if (RSI_BAND == RSI_DUAL_BAND) { + rsi_uint16_to_2bytes(rsi_scan->channel_bit_map_2_4, RSI_SCAN_CHANNEL_BIT_MAP_2_4); + rsi_uint32_to_4bytes(rsi_scan->channel_bit_map_5, RSI_SCAN_CHANNEL_BIT_MAP_5); + } else if (RSI_BAND == RSI_BAND_5GHZ) { + // Set channel bitmap for 5GHz + rsi_uint32_to_4bytes(rsi_scan->channel_bit_map_5, RSI_SCAN_CHANNEL_BIT_MAP_5); + } else { + rsi_uint16_to_2bytes(rsi_scan->channel_bit_map_2_4, RSI_SCAN_CHANNEL_BIT_MAP_2_4); + } + + if (rsi_scan->scan_feature_bitmap == 0) + rsi_scan->scan_feature_bitmap = RSI_SCAN_FEAT_BITMAP; + +#ifdef PROCESS_SCAN_RESULTS_AT_HOST + if (rsi_scan->scan_feature_bitmap == 0) + rsi_scan->scan_feature_bitmap = RSI_SCAN_FEAT_BITMAP; +#else + rsi_scan->scan_feature_bitmap = RSI_SCAN_FEAT_BITMAP; +#endif + payload_size = sizeof(rsi_req_scan_t); + } break; + case RSI_WLAN_REQ_JOIN: { + // Join Parameters + rsi_req_join_t *rsi_join = (rsi_req_join_t *)pkt->data; + + rsi_join->data_rate = RSI_DATA_RATE; + rsi_join->power_level = RSI_POWER_LEVEL; + rsi_join->join_feature_bitmap = RSI_JOIN_FEAT_BIT_MAP; + rsi_uint32_to_4bytes(rsi_join->listen_interval, RSI_LISTEN_INTERVAL); + memcpy(rsi_join->join_bssid, rsi_wlan_cb_non_rom->join_bssid_non_rom, 6); + + payload_size = sizeof(rsi_req_join_t); + /* In concurrent mode, no need to update the expected response */ + if (rsi_driver_cb->wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE) { + rsi_driver_cb->wlan_cb->expected_response = (rsi_wlan_cmd_response_t)RSI_WLAN_REQ_JOIN; + } + + } break; + + case RSI_WLAN_REQ_GAIN_TABLE: { + rsi_gain_table_info_t *gain_table = (rsi_gain_table_info_t *)pkt->data; + // payload of gain table parameters + payload_size = sizeof(rsi_gain_table_info_t) + (gain_table->size) - 1; // -1 is for gain_table->gain_table + } break; + + case RSI_WLAN_REQ_CONFIGURE_P2P: { + // payload of p2p parameters + payload_size = sizeof(rsi_req_configure_p2p_t); + } break; + case RSI_WLAN_REQ_HOST_PSK: { + // PSK and PMK parameters + payload_size = sizeof(rsi_req_psk_t); + } break; + case RSI_WLAN_REQ_BG_SCAN: { + rsi_req_bg_scan_t *rsi_bg_scan = (rsi_req_bg_scan_t *)pkt->data; + + if (pkt->data[0] == 0xAB) { + if (pkt->data[1] == 1) { + // Enable or Disable bg scan + rsi_uint16_to_2bytes(rsi_bg_scan->bgscan_enable, 1); + + // Enable or Disable instant bg scan + rsi_uint16_to_2bytes(rsi_bg_scan->enable_instant_bgscan, 1); + } + + } else { + // Enable or Disable bg scan + rsi_uint16_to_2bytes(rsi_bg_scan->bgscan_enable, RSI_BG_SCAN_ENABLE); + + // Enable or Disable instant bg scan + rsi_uint16_to_2bytes(rsi_bg_scan->enable_instant_bgscan, RSI_INSTANT_BG); + } + // bg scan threshold value + rsi_uint16_to_2bytes(rsi_bg_scan->bgscan_threshold, RSI_BG_SCAN_THRESHOLD); + + // tolerance threshold + rsi_uint16_to_2bytes(rsi_bg_scan->rssi_tolerance_threshold, RSI_RSSI_TOLERANCE_THRESHOLD); + + // periodicity + rsi_uint16_to_2bytes(rsi_bg_scan->bgscan_periodicity, RSI_BG_SCAN_PERIODICITY); + + // active scan duration + rsi_uint16_to_2bytes(rsi_bg_scan->active_scan_duration, RSI_ACTIVE_SCAN_DURATION); + + // passive scan duration + rsi_uint16_to_2bytes(rsi_bg_scan->passive_scan_duration, RSI_PASSIVE_SCAN_DURATION); + + // Enable multi probe + rsi_bg_scan->multi_probe = RSI_MULTIPROBE; + + // fill payload size + payload_size = sizeof(rsi_req_bg_scan_t); + + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_BG_SCAN; + } break; + case RSI_WLAN_REQ_TIMEOUT: { + // fill payload size + payload_size = sizeof(rsi_req_timeout_t); + } break; + case RSI_WLAN_REQ_ROAM_PARAMS: { + rsi_req_roam_params_t *rsi_roam_params = (rsi_req_roam_params_t *)pkt->data; + + // Enable or Disable bg scan + rsi_uint32_to_4bytes(rsi_roam_params->roam_enable, RSI_ROAMING_SUPPORT); + + // Enable or Disable instant bg scan + rsi_uint32_to_4bytes(rsi_roam_params->roam_threshold, RSI_ROAMING_THRESHOLD); + + // bg scan threshold value + rsi_uint32_to_4bytes(rsi_roam_params->roam_hysteresis, RSI_ROAMING_HYSTERISIS); + + // fill payload size + payload_size = sizeof(rsi_req_roam_params_t); + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_ROAM_PARAMS; + + } break; + case RSI_WLAN_REQ_WPS_METHOD: { + // fill payload size for wps method + payload_size = sizeof(rsi_req_wps_method_t); + + } break; + case RSI_WLAN_REQ_DISCONNECT: { + // fill payload size for disconnect parameters + payload_size = sizeof(rsi_req_disassoc_t); + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_DISCONNECT; + + } break; + case RSI_WLAN_REQ_TX_TEST_MODE: { + rsi_req_tx_test_info_t *rsi_tx_test_info = (rsi_req_tx_test_info_t *)pkt->data; + + // Enable or Disable transmit test mode + rsi_uint16_to_2bytes(rsi_tx_test_info->rate_flags, RSI_TX_TEST_RATE_FLAGS); + + // Enable or Disable transmit test mode + rsi_uint16_to_2bytes(rsi_tx_test_info->channel_bw, RSI_TX_TEST_PER_CH_BW); + + // Enable or Disable transmit test mode + rsi_uint16_to_2bytes(rsi_tx_test_info->aggr_enable, RSI_TX_TEST_AGGR_ENABLE); + + // Enable or Disable transmit test mode + rsi_uint16_to_2bytes(rsi_tx_test_info->reserved, 0); + + // Enable or Disable transmit test mode + rsi_uint16_to_2bytes(rsi_tx_test_info->no_of_pkts, RSI_TX_TEST_NUM_PKTS); + + // Enable or Disable transmit test mode + rsi_uint16_to_2bytes(rsi_tx_test_info->delay, RSI_TX_TEST_DELAY); + + // fill payload size tx test mode parameters + payload_size = sizeof(rsi_req_tx_test_info_t); + + } break; + case RSI_WLAN_REQ_RX_STATS: { + // fill payload size rx stats parameters + payload_size = sizeof(rsi_req_rx_stats_t); + + } break; + case RSI_WLAN_REQ_PING_PACKET: { + // PING parameters + payload_size = sizeof(rsi_req_ping_t); + } break; + + case RSI_WLAN_REQ_DYNAMIC_POOL: { + // fill payload size + payload_size = sizeof(rsi_udynamic); + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_DYNAMIC_POOL; + } break; + + case RSI_WLAN_REQ_SOCKET_CREATE: { + payload_size = sizeof(rsi_req_socket_t); + + } break; + case RSI_WLAN_REQ_SOCKET_READ_DATA: { + payload_size = sizeof(rsi_req_socket_read_t); + } break; + case RSI_WLAN_REQ_SET_CERTIFICATE: { + rsi_req_set_certificate_t *set_certificate = (rsi_req_set_certificate_t *)pkt->data; + + if (set_certificate->cert_info.more_chunks) { + payload_size = RSI_MAX_CERT_SEND_SIZE; + } else { + payload_size = + rsi_bytes2R_to_uint16(set_certificate->cert_info.certificate_length) + sizeof(struct rsi_cert_info_s); + } + } break; + case RSI_WLAN_REQ_SET_WEP_KEYS: { + payload_size = sizeof(rsi_wep_keys_t); + } break; + case RSI_WLAN_REQ_IPCONFV4: { + payload_size = sizeof(rsi_req_ipv4_parmas_t); + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_IPCONFV4; + } break; + case RSI_WLAN_REQ_IPCONFV6: { + payload_size = sizeof(rsi_req_ipv6_parmas_t); + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_IPCONFV6; + } break; + case RSI_WLAN_REQ_MDNSD: + case RSI_WLAN_REQ_HTTP_OTAF: + case RSI_WLAN_REQ_HTTP_CLIENT_POST: + case RSI_WLAN_REQ_HTTP_CLIENT_GET: + case RSI_WLAN_REQ_HTTP_CLIENT_POST_DATA: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_HTTP_CREDENTIALS: { + payload_size = sizeof(rsi_req_http_credentials_t); + } break; + case RSI_WLAN_REQ_SMTP_CLIENT: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_SOCKET_ACCEPT: { + payload_size = sizeof(rsi_req_socket_accept_t); + } break; +#ifndef RSI_M4_INTERFACE + case RSI_WLAN_REQ_CERT_VALID: { + payload_size = sizeof(rsi_req_cert_valid_t); + } break; +#endif + case RSI_WLAN_REQ_DNS_QUERY: { + payload_size = sizeof(rsi_req_dns_query_t); + } break; + case RSI_WLAN_REQ_DNS_UPDATE: { + payload_size = sizeof(rsi_req_dns_update_t); + } break; + case RSI_WLAN_REQ_DNS_SERVER_ADD: { + payload_size = sizeof(rsi_req_dns_server_add_t); + } break; + case RSI_WLAN_REQ_DHCP_USER_CLASS: { + payload_size = sizeof(rsi_dhcp_user_class_t); + } break; + case RSI_WLAN_REQ_SOCKET_CLOSE: { + payload_size = sizeof(rsi_req_socket_close_t); + } break; + + case RSI_WLAN_REQ_AP_CONFIGURATION: { + rsi_req_ap_config_t *ap_config = (rsi_req_ap_config_t *)pkt->data; +#if RSI_AP_KEEP_ALIVE_ENABLE + // copy AP keep alive type + ap_config->ap_keepalive_type = RSI_AP_KEEP_ALIVE_TYPE; + + // copy AP keep alive period + ap_config->ap_keepalive_period = RSI_AP_KEEP_ALIVE_PERIOD; +#endif + // copy max station supported by uint16 to 2 bytes conversion + rsi_uint16_to_2bytes(ap_config->max_sta_support, RSI_MAX_STATIONS_SUPPORT); + + payload_size = sizeof(rsi_req_ap_config_t); + + } break; + case RSI_WLAN_REQ_HT_CAPABILITIES: { + rsi_req_ap_ht_caps_t *ap_ht_caps = (rsi_req_ap_ht_caps_t *)pkt->data; + + rsi_uint16_to_2bytes(ap_ht_caps->mode_11n_enable, RSI_MODE_11N_ENABLE); + + rsi_uint16_to_2bytes(ap_ht_caps->ht_caps_bitmap, RSI_HT_CAPS_BIT_MAP); + + payload_size = sizeof(rsi_req_ap_ht_caps_t); + + } break; + case RSI_WLAN_REQ_FTP: { + rsi_ftp_file_ops_t *file_ops = (rsi_ftp_file_ops_t *)pkt->data; + + switch (file_ops->command_type) { + case RSI_FTP_CREATE: + case RSI_FTP_DISCONNECT: + case RSI_FTP_DESTROY: + case RSI_FTP_FILE_WRITE: + case RSI_FTP_FILE_READ: + case RSI_FTP_FILE_DELETE: + case RSI_FTP_DIRECTORY_SET: + case RSI_FTP_DIRECTORY_DELETE: + case RSI_FTP_DIRECTORY_LIST: + case RSI_FTP_DIRECTORY_CREATE: { + payload_size = sizeof(rsi_ftp_file_ops_t); + } break; + case RSI_FTP_COMMAND_MODE_SET: { + payload_size = sizeof(rsi_ftp_mode_params_t); + } break; +#ifdef CHIP_9117 + case RSI_FTP_COMMAND_FILE_SIZE_SET: { + payload_size = sizeof(rsi_ftp_file_size_set_params_t); + } break; +#endif + case RSI_FTP_CONNECT: { + payload_size = sizeof(rsi_ftp_connect_t); + } break; + case RSI_FTP_FILE_RENAME: { + payload_size = sizeof(rsi_ftp_file_rename_t); + } break; + case RSI_FTP_FILE_WRITE_CONTENT: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + default: { + } + } + + } break; + case RSI_WLAN_REQ_WMM_PS: { + // wmmps parameters + rsi_wmm_ps_parms_t *wmm_ps = (rsi_wmm_ps_parms_t *)pkt->data; + + // set wmm enable or disable + rsi_uint16_to_2bytes(wmm_ps->wmm_ps_enable, RSI_WMM_PS_ENABLE); + + // set wmm enable or disable + // 0- TX BASED 1 - PERIODIC + rsi_uint16_to_2bytes(wmm_ps->wmm_ps_type, RSI_WMM_PS_TYPE); + + // set wmm wake up interval + rsi_uint32_to_4bytes(wmm_ps->wmm_ps_wakeup_interval, RSI_WMM_PS_WAKE_INTERVAL); + + // set wmm UAPSD bitmap + // Resetting this bit as it is affecting throughput in COEX scenarios + wmm_ps->wmm_ps_uapsd_bitmap = 0; //RSI_WMM_PS_UAPSD_BITMAP; + + //fill payload size wmm ps parameters + payload_size = sizeof(rsi_wmm_ps_parms_t); + + } break; + case RSI_WLAN_REQ_MULTICAST: { + payload_size = sizeof(rsi_req_multicast_t); + } break; + case RSI_WLAN_REQ_FWUP: { + rsi_req_fwup_t *fwup = (rsi_req_fwup_t *)pkt->data; + + // Get packet length + uint16_t length = rsi_bytes2R_to_uint16(fwup->length); + + // Content length + 2bytes type + 2bytes length + payload_size = (length + 4); + } break; + case RSI_WLAN_REQ_WEBPAGE_LOAD: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_JSON_LOAD: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_WEBPAGE_ERASE: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_JSON_OBJECT_ERASE: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_WEBPAGE_CLEAR_ALL: { + + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_HOST_WEBPAGE_SEND: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_POP3_CLIENT: { + payload_size = sizeof(rsi_req_pop3_client_t); + } break; + case RSI_WLAN_REQ_HTTP_CLIENT_PUT: { + + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_OTA_FWUP: { + payload_size = sizeof(rsi_req_ota_fwup_t); + } break; + case RSI_WLAN_REQ_SET_PROFILE: { + payload_size = rsi_bytes2R_to_uint16(host_desc); + } break; + case RSI_WLAN_REQ_GET_PROFILE: + case RSI_WLAN_REQ_DELETE_PROFILE: { + payload_size = sizeof(rsi_profile_req_t); + } break; + case RSI_WLAN_REQ_AUTO_CONFIG_ENABLE: { + payload_size = sizeof(rsi_auto_config_enable_t); + } break; + case RSI_WLAN_REQ_SOCKET_CONFIG: { + // fill payload size + payload_size = sizeof(rsi_socket_config_t); + } break; +#ifdef RSI_WAC_MFI_ENABLE + case RSI_WLAN_REQ_ADD_MFI_IE: { + rsi_req_add_mfi_ie_t *rsi_mfi_ie = (rsi_req_add_mfi_ie_t *)pkt->data; + // fill payload size + payload_size = rsi_mfi_ie->mfi_ie_len + 1; + } break; +#endif + case RSI_WLAN_REQ_FILTER_BCAST_PACKETS: { + // fill payload size + payload_size = sizeof(rsi_req_wlan_filter_bcast_t); + + } break; + case RSI_WLAN_REQ_SNTP_CLIENT: { + // fill payload size + payload_size = sizeof(rsi_sntp_client_t); + } break; + + case RSI_WLAN_REQ_USER_STORE_CONFIG: { + // fill payload size + payload_size = sizeof(rsi_user_store_config_t); + + } break; + case RSI_WLAN_REQ_SET_SLEEP_TIMER: { + // fill payload size + payload_size = sizeof(rsi_set_sleep_timer_t); + + } break; + case RSI_WLAN_REQ_RADIO: { + // fill payload size + payload_size = sizeof(rsi_wlan_req_radio_t); + + } break; + case RSI_WLAN_REQ_FREQ_OFFSET: { + payload_size = sizeof(rsi_freq_offset_t); + } break; + case RSI_WLAN_REQ_CALIB_WRITE: { + payload_size = sizeof(rsi_calib_write_t); + } break; + case RSI_WLAN_REQ_CALIB_READ: { + payload_size = sizeof(rsi_calib_read_t); + } break; + case RSI_WLAN_REQ_GET_CSI_DATA: { + rsi_csi_config_t *csi_config = (rsi_csi_config_t *)pkt->data; + payload_size = sizeof(rsi_csi_config_t) + (csi_config->num_of_mac_addr * RSI_MAC_ADDR_LEN) + - RSI_MAC_ADDR_LEN; // -6 is for csi_config->mac_addresses + } break; + case RSI_WLAN_REQ_EMB_MQTT_CLIENT: { + rsi_req_emb_mqtt_command_t *mqtt_cmd = (rsi_req_emb_mqtt_command_t *)pkt->data; + mqtt_command_type = rsi_bytes4R_to_uint32(mqtt_cmd->command_type); + switch (mqtt_command_type) { + case RSI_EMB_MQTT_CLIENT_INIT: { + payload_size = sizeof(rsi_emb_mqtt_client_init_t); + } break; + case RSI_EMB_MQTT_CONNECT: { + payload_size = sizeof(rsi_emb_mqtt_connect_t); + } break; + case RSI_EMB_MQTT_SUBSCRIBE: { + payload_size = sizeof(rsi_emb_mqtt_sub_t); + } break; + case RSI_EMB_MQTT_SND_PUB_PKT: { + + rsi_emb_mqtt_snd_pub_t *mqtt_pub_cmd = (rsi_emb_mqtt_snd_pub_t *)pkt->data; + uint16_t length = rsi_bytes2R_to_uint16(mqtt_pub_cmd->msg_len); + payload_size = sizeof(rsi_emb_mqtt_snd_pub_t) + length; + } break; + case RSI_EMB_MQTT_UNSUBSCRIBE: { + payload_size = sizeof(rsi_emb_mqtt_unsub_t); + } break; + case RSI_EMB_MQTT_DISCONNECT: + case RSI_EMB_MQTT_COMMAND_DESTROY: { + payload_size = sizeof(rsi_req_emb_mqtt_command_t); + } break; + default: { + } + } + } break; + case RSI_WLAN_REQ_INIT: + case RSI_WLAN_REQ_QUERY_NETWORK_PARAMS: + case RSI_WLAN_REQ_CFG_SAVE: + case RSI_WLAN_REQ_GET_CFG: + case RSI_WLAN_REQ_RSSI: + case RSI_WLAN_REQ_FW_VERSION: + case RSI_WLAN_REQ_MAC_ADDRESS: + case RSI_WLAN_REQ_QUERY_GO_PARAMS: + case RSI_WLAN_REQ_CONNECTION_STATUS: + case RSI_WLAN_REQ_WIRELESS_FWUP: + case RSI_WLAN_REQ_HTTP_ABORT: + case RSI_WLAN_REQ_FTP_FILE_WRITE: + case RSI_WLAN_REQ_GET_RANDOM: + case RSI_WLAN_REQ_GET_STATS: + case RSI_WLAN_REQ_EXT_STATS: + break; + + default: { + break; + } + } + // Memset host descriptor + memset(host_desc, 0, RSI_HOST_DESC_LENGTH); + + // Fill payload length + rsi_uint16_to_2bytes(host_desc, (payload_size & 0xFFF)); + + // Fill frame type + host_desc[1] |= (RSI_WLAN_MGMT_Q << 4); + + // Fill frame type + host_desc[2] = cmd; + + // Enqueue packet to WLAN TX queue + rsi_enqueue_pkt(&rsi_driver_cb->wlan_tx_q, pkt); + + // Set TX packet pending event + rsi_set_event(RSI_TX_EVENT); + + // Return status + return status; +} + +/*==============================================*/ +/** + * @fn uint8_t *rsi_extract_filename(uint8_t *json, uint8_t *buffer) + * @brief Extract file name from the received JSON data + * @param[in] json - json object data string + * @param[in] buffer - contains file name + * @return File name extracted + * + * + */ + +/* This function is used to extract filename out of the received json update data. */ +uint8_t *rsi_extract_filename(uint8_t *json, uint8_t *buffer) +{ + uint8_t c; + uint8_t i = 0; + + while (i < 24) { + + /* Get character */ + c = json[i]; + + if (c != ',') + buffer[i] = c; + else + break; + + ++i; + } + + buffer[i] = '\0'; + + return &json[i + 1]; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_driver_process_wlan_recv_cmd(rsi_pkt_t *pkt) + * @brief Process received WLAN commands. + * @param[in] pkt - Pointer to received RX packet + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * @note Memory allocation for the pointer is from receive handler, after processing, it will be freed. + * + */ +/// @private +int32_t rsi_driver_process_wlan_recv_cmd(rsi_pkt_t *pkt) +{ + uint8_t cmd_type = 0; + uint8_t ip_version = 0, sock_id = 0, accept_sock_id = 0, socket_type = 0; + int32_t sockID = 0; + int32_t status = RSI_SUCCESS; + uint16_t copy_length = 0; + uint8_t *host_desc = NULL; + uint8_t *payload = NULL; + uint16_t payload_length = 0; + uint16_t length = 0; + uint8_t buffers_freed = 0; + int8_t wlan_pkt_pending = 0; + uint8_t type = 0; + uint8_t i = 0; + uint8_t j = 0; + rsi_rsp_socket_select_t *socket_select_rsp = NULL; + uint16_t status_code = 0; +#ifdef PROCESS_SCAN_RESULTS_AT_HOST + uint16_t recv_freq = 0; + int8_t rssi = 0; + uint8_t channel = 0; +#endif + // Get wlan cb struct pointer + rsi_wlan_cb_t *rsi_wlan_cb = rsi_driver_cb->wlan_cb; + + // Get common cb pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + // Get host descriptor + host_desc = pkt->desc; + + // Get command type + cmd_type = pkt->desc[2]; + + // Get payload pointer + payload = pkt->data; + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + + // check for packet pending in wlan queue + wlan_pkt_pending = rsi_check_queue_status(&rsi_driver_cb->wlan_tx_q); + + switch (cmd_type) { + case RSI_WLAN_RSP_DNS_UPDATE: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dns_update_rsp_handler != NULL) { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dns_update_rsp_handler(status); + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending &= ~(DNS_RESPONSE_PENDING); + } + } break; + case RSI_WLAN_RSP_BAND: { + // if success, update state wlan_cb state to band done + if (status == RSI_SUCCESS) { + rsi_wlan_cb->state = RSI_WLAN_STATE_BAND_DONE; + } + } break; + case RSI_WLAN_RSP_SELECT_REQUEST: { + rsi_fd_set *fd_read = NULL; + rsi_fd_set *fd_write = NULL; + rsi_fd_set *fd_except = NULL; + rsi_rsp_socket_select_t *socket_select_rsp = (rsi_rsp_socket_select_t *)payload; + j = socket_select_rsp->select_id; + if (rsi_socket_select_info[j].sock_select_callback == NULL) { + fd_read = (rsi_fd_set *)rsi_socket_select_info[j].rsi_sel_read_fds; + fd_write = (rsi_fd_set *)rsi_socket_select_info[j].rsi_sel_write_fds; + } else { + fd_read = &rsi_socket_select_info[j].rsi_sel_read_fds_var; + fd_write = &rsi_socket_select_info[j].rsi_sel_write_fds_var; + fd_except = &rsi_socket_select_info[j].rsi_sel_exception_fds_var; + } + if (fd_read != NULL) { + //clear the read fd set + RSI_FD_ZERO(fd_read); + fd_read->fd_count = 0; + } + if (fd_write != NULL) { + //clear the write fd set + RSI_FD_ZERO(fd_write); + fd_write->fd_count = 0; + } + if (fd_except != NULL) { + //clear the except fd set + RSI_FD_ZERO(fd_except); + fd_except->fd_count = 0; + } + if (payload_length > 0) { + //set the readfd and writefd with the updated value from firmware response + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + //set the readfd + if ((socket_select_rsp->rsi_read_fds.fd_array[0])) { + if ((socket_select_rsp->rsi_read_fds.fd_array[0]) & BIT(rsi_socket_pool[i].sock_id)) { + fd_read->fd_count++; + RSI_FD_SET(i, fd_read); + } + } + //set the writefd + if ((socket_select_rsp->rsi_write_fds.fd_array[0])) { + if ((socket_select_rsp->rsi_write_fds.fd_array[0]) & BIT(rsi_socket_pool[i].sock_id)) { + fd_write->fd_count++; + RSI_FD_SET(i, fd_write); + } + } + //set the terminated bit in socket pool + if ((socket_select_rsp->socket_terminate_bitmap) & BIT(rsi_socket_pool[i].sock_id)) { + rsi_socket_pool_non_rom[i].socket_terminate_indication = 1; + } + } + } + //call back + if (rsi_socket_select_info[j].sock_select_callback != NULL) { + rsi_socket_select_info[j].sock_select_callback( + (rsi_fd_set *)&rsi_socket_select_info[j].rsi_sel_read_fds_var, + (rsi_fd_set *)&rsi_socket_select_info[j].rsi_sel_write_fds_var, + (rsi_fd_set *)&rsi_socket_select_info[j].rsi_sel_exception_fds_var, + status); + rsi_socket_select_info[j].sock_select_callback = NULL; + rsi_socket_select_info[j].select_state = RSI_SOCKET_SELECT_STATE_INIT; + return RSI_SUCCESS; + } + + } break; + + case RSI_WLAN_RSP_INIT: { + + // update state wlan_cb state to init done + if (status == RSI_SUCCESS) { + rsi_wlan_cb->state = RSI_WLAN_STATE_INIT_DONE; + rsi_wlan_cb->sta_state = RSI_WLAN_STATE_INIT_DONE; + rsi_wlan_cb->ap_state = RSI_WLAN_STATE_INIT_DONE; + common_cb->ps_coex_mode = (common_cb->ps_coex_mode | BIT(0)); + } + + } break; + case RSI_WLAN_RSP_WPS_METHOD: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy generated wps pin + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_CONNECTION_STATUS: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy connection status + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_RSSI: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy rssi value + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_FW_VERSION: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy firmware version + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_MAC_ADDRESS: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy mac address + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_QUERY_NETWORK_PARAMS: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + + if (rsi_wlan_cb->query_cmd == RSI_WLAN_INFO) { + // copy wlan related information in to output buffer + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? sizeof(rsi_rsp_wireless_info_t) + : (rsi_wlan_cb->app_buffer_length); + + ((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->wlan_state = + (uint16_t)((rsi_rsp_nw_params_t *)payload)->wlan_state; + ((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->channel_number = + (uint16_t)((rsi_rsp_nw_params_t *)payload)->channel_number; + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->ssid, + ((rsi_rsp_nw_params_t *)payload)->ssid, + RSI_SSID_LEN); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->mac_address, + ((rsi_rsp_nw_params_t *)payload)->mac_address, + 6); + ((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->sec_type = + ((rsi_rsp_nw_params_t *)payload)->sec_type; + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->psk, + ((rsi_rsp_nw_params_t *)payload)->psk, + 64); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->ipv4_address, + ((rsi_rsp_nw_params_t *)payload)->ipv4_address, + 4); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->ipv6_address, + ((rsi_rsp_nw_params_t *)payload)->ipv6_address, + 16); + } + + } else if (rsi_wlan_cb->query_cmd == RSI_SOCKETS_INFO) { + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? sizeof(rsi_rsp_sockets_info_t) + : (rsi_wlan_cb->app_buffer_length); + + memcpy(((rsi_rsp_sockets_info_t *)rsi_wlan_cb->app_buffer)->num_open_socks, + ((rsi_rsp_nw_params_t *)payload)->num_open_socks, + 2); + memcpy(((rsi_rsp_sockets_info_t *)rsi_wlan_cb->app_buffer)->socket_info, + ((rsi_rsp_nw_params_t *)payload)->socket_info, + sizeof(rsi_sock_info_query_t) * RSI_MN_NUM_SOCKETS); + } + } + rsi_wlan_cb->app_buffer = NULL; + } + } + } break; + case RSI_WLAN_RSP_GET_STATS: { + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + + if (rsi_wlan_cb->query_cmd == RSI_GET_WLAN_STATS) { + // copy wlan related information in to output buffer + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? sizeof(rsi_rsp_wireless_info_t) + : (rsi_wlan_cb->app_buffer_length); + + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + } + } + } + rsi_wlan_cb->app_buffer = NULL; + } + } break; + case RSI_WLAN_RATE_RSP_STATS: { + int ii; + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy scan results + LOG_PRINT(" RATE INFO RECEIVED \n"); + if ((payload != NULL) && (payload_length >= 25)) { + LOG_PRINT(" Chip Temperature :%d\n", (payload[0] - 40)); + LOG_PRINT(" 2G OFDM Temp power offset :%d\n", payload[2]); + LOG_PRINT(" 2G 11B Temp power offset :%d\n", payload[3]); + LOG_PRINT(" 5G Temp power offset :%d\n", payload[4]); + for (ii = 5; ii < 25; ii++) + LOG_PRINT(" PowerIndex For Rate %d :%d\n", ii, payload[ii]); + } + } + } break; + case RSI_WLAN_RSP_EXT_STATS: { + if (status == RSI_SUCCESS) { + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + + if (rsi_wlan_cb->query_cmd == RSI_WLAN_EXT_STATS) { + // copy wlan related information in to output buffer + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? sizeof(rsi_wlan_ext_stats_t) + : (rsi_wlan_cb->app_buffer_length); + + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + } + } + } + rsi_wlan_cb->app_buffer = NULL; + } + } break; + case RSI_WLAN_RSP_QUERY_GO_PARAMS: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + + if (rsi_wlan_cb->query_cmd == RSI_WLAN_INFO) { + + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? sizeof(rsi_rsp_wireless_info_t) + : (rsi_wlan_cb->app_buffer_length); + + ((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->wlan_state = + rsi_bytes2R_to_uint16(((rsi_rsp_go_params_t *)payload)->sta_count); + ((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->channel_number = + rsi_bytes2R_to_uint16(((rsi_rsp_go_params_t *)payload)->channel_number); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->ssid, + ((rsi_rsp_go_params_t *)payload)->ssid, + RSI_SSID_LEN); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->mac_address, + ((rsi_rsp_go_params_t *)payload)->mac_address, + 6); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->psk, + ((rsi_rsp_go_params_t *)payload)->psk, + 64); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->ipv4_address, + ((rsi_rsp_go_params_t *)payload)->ipv4_address, + 4); + memcpy(((rsi_rsp_wireless_info_t *)rsi_wlan_cb->app_buffer)->ipv6_address, + ((rsi_rsp_go_params_t *)payload)->ipv6_address, + 16); + } + } else if (rsi_wlan_cb->query_cmd == RSI_STATIONS_INFO) { + + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? sizeof(rsi_rsp_wireless_info_t) + : (rsi_wlan_cb->app_buffer_length); + + memcpy(((rsi_rsp_stations_info_t *)rsi_wlan_cb->app_buffer)->sta_count, + ((rsi_rsp_go_params_t *)payload)->sta_count, + 2); + memcpy(((rsi_rsp_stations_info_t *)rsi_wlan_cb->app_buffer)->sta_info, + ((rsi_rsp_go_params_t *)payload)->sta_info, + sizeof(rsi_go_sta_info_t) * RSI_MAX_STATIONS); + } + } + rsi_wlan_cb->app_buffer = NULL; + } + } + } break; + case RSI_WLAN_RSP_SMTP_CLIENT: { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + if ((host_desc[5] == RSI_SMTP_CLIENT_MAIL_SEND) + && (rsi_wlan_cb_non_rom->nwk_callbacks.smtp_client_mail_response_handler != NULL)) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.smtp_client_mail_response_handler(status, host_desc[5]); + } else if ((host_desc[5] == RSI_SMTP_CLIENT_DEINIT) + && (rsi_wlan_cb_non_rom->nwk_callbacks.smtp_client_delete_response_handler != NULL)) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.smtp_client_delete_response_handler(status, host_desc[5]); + } + rsi_wlan_set_nwk_status(status); + return RSI_SUCCESS; + } + // no break + case RSI_WLAN_RSP_P2P_CONNECTION_REQUEST: { + if (rsi_wlan_cb_non_rom->callback_list.wlan_wfd_connection_request_notify_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_wfd_connection_request_notify_handler(status, payload, payload_length); + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_WFD_DEVICE: { + if (rsi_wlan_cb_non_rom->callback_list.wlan_wfd_discovery_notify_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_wfd_discovery_notify_handler(status, payload, payload_length); + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_CLIENT_CONNECTED: { + if (rsi_wlan_cb_non_rom->callback_list.stations_connect_notify_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.stations_connect_notify_handler(status, payload, payload_length); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_CLIENT_DISCONNECTED: { + if (rsi_wlan_cb_non_rom->callback_list.stations_disconnect_notify_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.stations_disconnect_notify_handler(status, payload, payload_length); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_SCAN: { + if (rsi_wlan_cb_non_rom->scan_results_to_host) { + rsi_wlan_cb_non_rom->scan_results_to_host = 0; + if (scan_results_array->num == 0) { + status = RSI_AP_NOT_FOUND; + } + } + // update state wlan_cb state to scan done + if (status == RSI_SUCCESS) { + // Check for AP mode, and don't update scan done state + if (rsi_wlan_cb->opermode != RSI_WLAN_ACCESS_POINT_MODE) { + rsi_wlan_cb->state = RSI_WLAN_STATE_SCAN_DONE; + } + + if (rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler != NULL) { + + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler(status, payload, payload_length); + rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler = NULL; + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + return RSI_SUCCESS; + } else { + // check the length of application buffer and copy scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + } else { + if (rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler(status, NULL, 0); + rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler = NULL; + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + return RSI_SUCCESS; + } + } + // Check for Auto config state + if (rsi_wlan_cb->auto_config_state == RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON) { + // Set auto config state to failed + rsi_driver_cb->wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_FAILED; + rsi_wlan_cb->state = RSI_WLAN_STATE_SCAN_DONE; + + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_FAILED); + } + } + } break; + case RSI_WLAN_RSP_BG_SCAN: { + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy bg scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + } break; + case RSI_WLAN_RSP_JOIN: { + // update state wlan_cb state to connected + if (status == RSI_SUCCESS) { + if (rsi_wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + rsi_wlan_cb->state = RSI_WLAN_STATE_IP_CONFIG_DONE; + } else if (rsi_wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE) { + if (payload_length) { + if (payload[0] == 'C') { + rsi_wlan_cb->sta_state = RSI_WLAN_STATE_CONNECTED; + } else if (payload[0] == 'G') { + rsi_wlan_cb->ap_state = RSI_WLAN_STATE_CONNECTED; + } + } + } else { + rsi_wlan_cb->state = RSI_WLAN_STATE_CONNECTED; + } + // Check for Auto config done + if (host_desc[15] & RSI_AUTO_CONFIG_DONE) { + // Set auto config state to done + rsi_driver_cb->wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_DONE; + + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_DONE); + } + } + + } + // Check for Auto config state + else if (rsi_wlan_cb->auto_config_state == RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON) { + rsi_driver_cb->wlan_cb->state = RSI_WLAN_STATE_BAND_DONE; + // Set auto config state to failed + rsi_driver_cb->wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_FAILED; + + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_FAILED); + } + } else { + + //Reset powe save mode as join fails + common_cb->power_save.current_ps_mode = 0; + + // Reset module state as join fails + common_cb->power_save.module_state = 0; + + if (status != RSI_WPS_NOT_SUPPORTED) { + rsi_wlan_cb->state = RSI_WLAN_STATE_BAND_DONE; + if (rsi_wlan_cb->expected_response != cmd_type) { + if (rsi_wlan_cb_non_rom->callback_list.join_fail_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.join_fail_handler(status, payload, payload_length); + rsi_wlan_cb_non_rom->callback_list.join_fail_handler = NULL; + } + + if ((wlan_pkt_pending == 0) && rsi_wlan_check_waiting_wlan_cmd()) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(1); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + } + if (rsi_driver_cb_non_rom->wlan_wait_bitmap & BIT(0)) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_sem); + } + rsi_post_waiting_semaphore(); + rsi_wlan_set_status(status); + return RSI_SUCCESS; + } + } + } + if (rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler(status, payload, payload_length); + rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler = NULL; + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Clear expected response + rsi_wlan_cb->expected_response = RSI_WLAN_RSP_CLEAR; + rsi_wlan_set_status(status); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_IPCONFV6: + case RSI_WLAN_RSP_IPCONFV4: { + // if success, update state wlan_cb state to scan done + if (status == RSI_SUCCESS) { + if (cmd_type == RSI_WLAN_RSP_IPCONFV4) { + rsi_wlan_cb->state = RSI_WLAN_STATE_IP_CONFIG_DONE; + } else { + rsi_wlan_cb->state = RSI_WLAN_STATE_IPV6_CONFIG_DONE; + } + + // Check for Auto config done + if (host_desc[15] & RSI_AUTO_CONFIG_DONE) { + // Set auto config state to done + rsi_wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_DONE; + + // Call auto config response handler + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_DONE); + } + } + + // check the length of application buffer and copy scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + + // Clear expected response + rsi_wlan_cb->expected_response = RSI_WLAN_RSP_CLEAR; + } + // Check for Auto config state + else if (rsi_wlan_cb->auto_config_state == RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON) { + // Set auto config state to failed + rsi_driver_cb->wlan_cb->auto_config_state = RSI_WLAN_STATE_AUTO_CONFIG_FAILED; + + if (rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler) { + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler(status, RSI_AUTO_CONFIG_FAILED); + } + } else { + if (rsi_wlan_cb->expected_response != cmd_type) { + if (rsi_wlan_cb_non_rom->callback_list.ip_renewal_fail_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.ip_renewal_fail_handler(status, payload, payload_length); + } + + if (wlan_pkt_pending == 0 && rsi_wlan_check_waiting_wlan_cmd()) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(1); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + } + // Post the semaphore which is waiting on socket/wlan/nwk + rsi_post_waiting_semaphore(); + + return RSI_SUCCESS; + } + } + } break; + case RSI_WLAN_RSP_GET_RANDOM: { + // if success, update state wlan_cb state to scan done + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy scan results + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + } + } + rsi_wlan_cb->app_buffer = NULL; + } break; + case RSI_WLAN_RSP_PING_PACKET: { + if (rsi_wlan_cb_non_rom->callback_list.wlan_ping_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_ping_response_handler(status, payload, payload_length); + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending &= ~(PING_RESPONSE_PENDING); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_RX_STATS: { + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler(status, payload, payload_length); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_DISCONNECT: { + // if success, update state wlan_cb state to band done + if (status == RSI_SUCCESS) { +#if (RSI_HAND_SHAKE_TYPE == MSG_BASED) + if (common_cb->power_save.module_state == RSI_SLP_ACK_SENT) { + rsi_unmask_event(RSI_TX_EVENT); + } +#endif +#ifdef CONC_STA_AP_DYN_SWITCH_EN + if (rsi_wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE) + rsi_wlan_cb->state = RSI_WLAN_STATE_BAND_DONE; + else + rsi_wlan_cb->state = RSI_WLAN_STATE_INIT_DONE; +#else + rsi_wlan_cb->state = RSI_WLAN_STATE_BAND_DONE; +#endif + //Reset powe save mode as Disconnect received + common_cb->power_save.current_ps_mode = 0; + + // Reset module state as Disconnect received + common_cb->power_save.module_state = 0; + + // Post the semaphore which is waiting on socket/wlan/nwk + rsi_post_waiting_semaphore(); + } + } break; + case RSI_WLAN_RSP_DYNAMIC_POOL: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + } break; + + case RSI_WLAN_RSP_SOCKET_CREATE: { + rsi_rsp_socket_create_t *socket_rsp = (rsi_rsp_socket_create_t *)payload; + + if (rsi_bytes2R_to_uint16(socket_rsp->socket_type) == RSI_SOCKET_TCP_SERVER) { + // Get waiting socket ID + sockID = rsi_get_app_socket_descriptor(socket_rsp->module_port); + } else { + // Get IP version + ip_version = rsi_bytes2R_to_uint16(socket_rsp->ip_version); + + if (ip_version == 4) { + sockID = rsi_get_socket_descriptor(socket_rsp->module_port, + socket_rsp->dst_port, + socket_rsp->dest_ip_addr.ipv4_addr, + ip_version, + rsi_bytes2R_to_uint16(socket_rsp->socket_id)); + } else { + sockID = rsi_get_socket_descriptor(socket_rsp->module_port, + socket_rsp->dst_port, + socket_rsp->dest_ip_addr.ipv6_addr, + ip_version, + rsi_bytes2R_to_uint16(socket_rsp->socket_id)); + } + } + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + if (status == RSI_SUCCESS) { + sock_id = rsi_bytes2R_to_uint16(socket_rsp->socket_id); + socket_type = rsi_bytes2R_to_uint16(socket_rsp->socket_type); + ip_version = rsi_bytes2R_to_uint16(socket_rsp->ip_version); + + rsi_socket_pool[sockID].source_port = rsi_bytes2R_to_uint16(socket_rsp->module_port); + rsi_socket_pool[sockID].destination_port = rsi_bytes2R_to_uint16(socket_rsp->dst_port); + rsi_socket_pool_non_rom[sockID].mss = rsi_bytes2R_to_uint16(socket_rsp->mss); + + // Save socket id + if (socket_type != RSI_SOCKET_TCP_SERVER) { + rsi_socket_pool[sockID].sock_id = sock_id; + } + if (socket_type == RSI_SOCKET_TCP_SERVER) { + // Update state to listen is success + rsi_socket_pool[sockID].sock_state = RSI_SOCKET_STATE_LISTEN; + + } else { + if (!rsi_socket_pool_non_rom[sockID].wait_to_connect) { + rsi_socket_pool[sockID].sock_state = RSI_SOCKET_STATE_CONNECTED; + } else { + rsi_socket_pool_non_rom[sockID].wait_to_connect = 0; +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(0); +#endif + // Wait on select semaphore + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].socket_sem); + } + } + } +#ifndef RSI_M4_INTERFACE + if (rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler != NULL) { + // Changing the callback response f/w socket id to app socket id. + rsi_uint16_to_2bytes(socket_rsp->socket_id, sockID); + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending &= ~BIT(sockID); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler(status, payload, payload_length); + } +#endif + + } break; + case RSI_WLAN_RSP_UPDATE_TCP_WINDOW: { + rsi_rsp_tcp_window_update_t *tcp_window = (rsi_rsp_tcp_window_update_t *)payload; + sockID = rsi_get_application_socket_descriptor(tcp_window->socket_id); + if ((sockID < 0) || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + rsi_socket_pool_non_rom[sockID].window_size = tcp_window->window_size; + rsi_wlan_socket_set_status(status, sockID); + if (rsi_socket_pool_non_rom[sockID].socket_wait_bitmap & BIT(0)) { +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(0); +#endif + // Wait on select semaphore + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].socket_sem); + } + } break; + case RSI_WLAN_RSP_CONN_ESTABLISH: { + if (status == RSI_SUCCESS) { + rsi_rsp_ltcp_est_t *ltcp = (rsi_rsp_ltcp_est_t *)payload; + + // Get IP version + ip_version = rsi_bytes2R_to_uint16(ltcp->ip_version); + + // Get socket descriptor from response + sock_id = rsi_bytes2R_to_uint16(ltcp->socket_id); + + // Get waiting socket ID + sockID = rsi_get_app_socket_descriptor(ltcp->src_port_num); + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + rsi_socket_pool_non_rom[sockID].mss = rsi_bytes2R_to_uint16(ltcp->mss); + if ((sockID >= 0) && (sockID < NUMBER_OF_SOCKETS)) { + if (rsi_socket_pool_non_rom[sockID].accept_call_back_handler != NULL) { + // Get the actual source socket descriptor + accept_sock_id = rsi_get_primary_socket_id(ltcp->src_port_num); + + // Increase backlog current count + rsi_socket_pool[accept_sock_id].backlog_current_count++; + } + } + + // Update the state as connected + rsi_socket_pool[sockID].sock_state = RSI_SOCKET_STATE_CONNECTED; + // Save socket id + rsi_socket_pool[sockID].sock_id = sock_id; + + // Save destination port number + rsi_socket_pool[sockID].destination_port = rsi_bytes2R_to_uint16(ltcp->dest_port); + + // Save destination IP addess + if (ip_version == 4) { + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv4, + ltcp->dest_ip_addr.ipv4_address, + RSI_IPV4_ADDRESS_LENGTH); + } else { + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv6, + ltcp->dest_ip_addr.ipv6_address, + RSI_IPV6_ADDRESS_LENGTH); + } + + // In case of asynchronous accept call the callback + if (rsi_socket_pool_non_rom[sockID].accept_call_back_handler != NULL) { + rsi_socket_pool_non_rom[sockID].accept_call_back_handler(sockID, + rsi_socket_pool[sockID].destination_port, + rsi_socket_pool[sockID].destination_ip_addr.ipv4, + ip_version); + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending &= ~BIT(sockID); + } + } + } break; + case RSI_WLAN_RSP_REMOTE_TERMINATE: { + rsi_rsp_socket_close_t *close = (rsi_rsp_socket_close_t *)payload; + + // Get application socket ID + sockID = rsi_get_application_socket_descriptor(rsi_bytes2R_to_uint16(close->socket_id)); + + // Need to set reason for remote terminate + + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + // Clear socket info + if (rsi_wlan_cb_non_rom->callback_list.remote_socket_terminate_handler != NULL) { + // Changing the callback response f/w socket id to app socket id. + rsi_uint16_to_2bytes(close->socket_id, sockID); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.remote_socket_terminate_handler(status, payload, payload_length); + } + + if ((RSI_TCP_IP_FEATURE_BIT_MAP & TCP_IP_FEAT_EXTENSION_VALID) + && (RSI_EXT_TCPIP_FEATURE_BITMAP & EXT_TCP_IP_WAIT_FOR_SOCKET_CLOSE)) { + rsi_socket_pool_non_rom[sockID].socket_terminate_indication = 1; + //Do not clear the sock info, RSI_WLAN_RSP_SOCKET_CLOSE will handle + } else + rsi_clear_sockets(sockID); + + rsi_wlan_socket_set_status(status, sockID); + // post on semaphore + rsi_post_waiting_socket_semaphore(sockID); + } break; + case RSI_WLAN_RSP_SOCKET_CLOSE: { + rsi_rsp_socket_close_t *close = (rsi_rsp_socket_close_t *)payload; + if (rsi_bytes2R_to_uint16(close->socket_id)) { + // Normal socket close + // Get socket descriptor + sockID = rsi_get_application_socket_descriptor(rsi_bytes2R_to_uint16(close->socket_id)); + } else { + sockID = rsi_get_socket_id(rsi_bytes2R_to_uint16(close->port_number), 0); + } + + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + + rsi_wlan_socket_set_status(status, sockID); + // post on semaphore +#ifndef RSI_SOCK_SEM_BITMAP + rsi_post_waiting_socket_semaphore(sockID); +#else + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].socket_sem); +#endif + } break; + + case RSI_WLAN_RSP_IPV4_CHANGE: { + if (rsi_wlan_cb_non_rom->callback_list.ip_change_notify_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.ip_change_notify_handler(status, payload, payload_length); + } + + if (wlan_pkt_pending == 0 && rsi_wlan_check_waiting_wlan_cmd()) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(1); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + } + // Post the semaphore which is waiting on socket/wlan/nwk + rsi_post_waiting_semaphore(); + + return RSI_SUCCESS; + } + // no break + case RSI_WLAN_RSP_HTTP_CLIENT_POST: + case RSI_WLAN_RSP_HTTP_CLIENT_GET: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // more data + uint16_t moredata = rsi_bytes2R_to_uint16(payload); +#if RSI_HTTP_STATUS_INDICATION_EN + // HTTP status code + uint16_t status_code = rsi_bytes2R_to_uint16(payload + 2); +#else + USED_PARAMETER(status_code); +#endif + + // Adjust payload length + payload_length -= RSI_HTTP_OFFSET; + + if (status == RSI_SUCCESS) { + // Call asynchronous response handler to indicate to host +#if RSI_HTTP_STATUS_INDICATION_EN + rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler(status, + (payload + RSI_HTTP_OFFSET), + payload_length, + (uint32_t)moredata, + status_code); +#else + rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler(status, + (payload + RSI_HTTP_OFFSET), + payload_length, + moredata); +#endif + } else { + // Call asynchronous response handler to indicate to host +#if RSI_HTTP_STATUS_INDICATION_EN + rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler(status, + (payload + RSI_HTTP_OFFSET), + payload_length, + 0, + 0); +#else + rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler(status, + (payload + RSI_HTTP_OFFSET), + payload_length, + 0); +#endif + } + } + rsi_wlan_set_nwk_status(status); + return RSI_SUCCESS; + } + + case RSI_WLAN_RSP_HTTP_CLIENT_POST_DATA: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_post_data_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + if (status == RSI_SUCCESS) { + // more data + uint16_t moredata = rsi_bytes2R_to_uint16(payload); + // HTTP status code +#if RSI_HTTP_STATUS_INDICATION_EN + // HTTP status code + uint16_t status_code = rsi_bytes2R_to_uint16(payload + 2); +#else + USED_PARAMETER(status_code); +#endif + + // Adjust payload length + payload_length -= RSI_HTTP_OFFSET; + + // Call asynchronous response handler to indicate to host +#if RSI_HTTP_STATUS_INDICATION_EN + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_post_data_response_handler(status, + (payload + RSI_HTTP_OFFSET), + payload_length, + (uint32_t)moredata, + status_code); +#else + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_post_data_response_handler(status, + (payload + RSI_HTTP_OFFSET), + payload_length, + moredata); +#endif + } else { + // Call asynchronous response handler to indicate to host +#if RSI_HTTP_STATUS_INDICATION_EN + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_post_data_response_handler(status, + payload, + payload_length, + 0, + 0); +#else + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_post_data_response_handler(status, + payload, + payload_length, + 0); +#endif + } + } + rsi_wlan_set_nwk_status(status); + return RSI_SUCCESS; + } + case RSI_WLAN_RSP_HTTP_OTAF: { + + if (rsi_wlan_cb_non_rom->nwk_callbacks.http_otaf_response_handler != NULL) { + // more data + // uint16_t moredata = rsi_bytes2R_to_uint16(payload); + // HTTP status code + //uint16_t status_code = rsi_bytes2R_to_uint16(payload + 2); + + // Adjust payload length + payload_length -= RSI_HTTP_OFFSET; + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + if (status == RSI_SUCCESS) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.http_otaf_response_handler(status, (payload + RSI_HTTP_OFFSET)); + } else { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.http_otaf_response_handler(status, (payload + RSI_HTTP_OFFSET)); + } + } + return RSI_SUCCESS; + } + // no break + case RSI_WLAN_RSP_URL_REQUEST: { + rsi_urlReqFrameRcv *postcontent = (rsi_urlReqFrameRcv *)payload; + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_webpage_request_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + if (status == RSI_SUCCESS) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_webpage_request_handler(type, + postcontent->url_name, + postcontent->post_data, + (uintptr_t)postcontent->post_content_length, + status); + // to avoid compiler warning replace uint32_t with uintptr_t + } + } + return RSI_SUCCESS; + } + // no break + case RSI_WLAN_RSP_DNS_QUERY: { + + if (status == RSI_SUCCESS) { + if ((rsi_driver_cb_non_rom->nwk_app_buffer != NULL) && (rsi_driver_cb_non_rom->nwk_app_buffer_length != 0)) { + copy_length = (payload_length < rsi_driver_cb_non_rom->nwk_app_buffer_length) + ? (payload_length) + : (rsi_driver_cb_non_rom->nwk_app_buffer_length); + memcpy(rsi_driver_cb_non_rom->nwk_app_buffer, payload, copy_length); + } + } + rsi_driver_cb_non_rom->nwk_app_buffer = NULL; + + } break; + case RSI_WLAN_RSP_FTP: { + rsi_ftp_file_rsp_t *ftp_file_rsp = (rsi_ftp_file_rsp_t *)payload; + + if (ftp_file_rsp->command_type == RSI_FTP_FILE_READ) { + if (status == RSI_SUCCESS) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.ftp_file_read_call_back_handler(status, + ftp_file_rsp->data_content, + ftp_file_rsp->data_length, + !(ftp_file_rsp->more)); + if (!ftp_file_rsp->more) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.ftp_file_read_call_back_handler(status, NULL, 0, 1); + } + return RSI_SUCCESS; + } else if (ftp_file_rsp->command_type == RSI_FTP_DIRECTORY_LIST) { + if (status == RSI_SUCCESS) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.ftp_directory_list_call_back_handler(status, + ftp_file_rsp->data_content, + ftp_file_rsp->data_length, + !(ftp_file_rsp->more)); + if (!ftp_file_rsp->more) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.ftp_directory_list_call_back_handler(status, NULL, 0, 1); + } + return RSI_SUCCESS; + } + + } break; + + case RSI_WLAN_RSP_TCP_ACK_INDICATION: { + rsi_rsp_tcp_ack_t *tcp_ack = (rsi_rsp_tcp_ack_t *)payload; + + // Get the socket ID from response and get application sockID from it + sockID = rsi_get_application_socket_descriptor(tcp_ack->socket_id); + + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + + // Get the length from response + length = rsi_bytes2R_to_uint16(tcp_ack->length); + + // Calculate the buffers can be freed with this length + buffers_freed = calculate_buffers_required(rsi_socket_pool[sockID].sock_type, length); + + // Increase the current available buffer count + rsi_socket_pool[sockID].current_available_buffer_count += buffers_freed; + + // If current count exceeds max count + if (rsi_socket_pool[sockID].current_available_buffer_count > rsi_socket_pool[sockID].max_available_buffer_count) { + rsi_socket_pool[sockID].current_available_buffer_count = rsi_socket_pool[sockID].max_available_buffer_count; + } + + // Call registered callback + if (rsi_wlan_cb_non_rom->nwk_callbacks.data_transfer_complete_handler) { + rsi_wlan_cb_non_rom->nwk_callbacks.data_transfer_complete_handler(sockID, length); + } + + rsi_wlan_socket_set_status(status, sockID); +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(2); +#endif + // Wait on select semaphore + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].sock_send_sem); + + } break; + case RSI_WLAN_RSP_WIRELESS_FWUP_OK: + case RSI_WLAN_RSP_WIRELESS_FWUP_DONE: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler(cmd_type, status); + + return RSI_SUCCESS; + } + } break; + + case RSI_WLAN_RSP_DHCP_USER_CLASS: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dhcp_usr_cls_rsp_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dhcp_usr_cls_rsp_handler(status); + } + } break; + + case RSI_WLAN_RSP_JSON_UPDATE: { + uint8_t filename[24] = { '\0' }; + + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_json_object_update_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Extract the filename from the received json object data payload + rsi_extract_filename(payload, filename); + + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_json_object_update_handler(filename, + payload, + strlen((const char *)payload), + RSI_SUCCESS); + } + } break; + case RSI_WLAN_RSP_SOCKET_READ_DATA: { + // we get the socket id in the response payload if it is error + sockID = rsi_get_application_socket_descriptor(payload[0]); + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } +#ifdef RSI_PROCESS_MAX_RX_DATA + if ((rsi_socket_pool[sockID].recv_buffer_length) && (rsi_socket_pool[sockID].sock_type & SOCK_STREAM)) { + rsi_wlan_socket_set_status(0, sockID); + } else { + rsi_wlan_socket_set_status(status, sockID); + } +#else + rsi_wlan_socket_set_status(status, sockID); +#endif +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(1); +#endif + // Wait on select semaphore + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].sock_recv_sem); + } break; + case RSI_WLAN_RSP_JSON_EVENT: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_json_object_event_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_json_object_event_handler(RSI_SUCCESS, + payload, + strlen((const char *)payload)); + } + } break; + case RSI_WLAN_RSP_OTA_FWUP: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_ota_fw_up_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + if (status == RSI_SUCCESS) { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_ota_fw_up_response_handler(status, 0); + } else { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_ota_fw_up_response_handler(status, *(uint16_t *)payload); + } + + return RSI_SUCCESS; + } + + } break; + case RSI_WLAN_RSP_HTTP_CLIENT_PUT: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_put_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + if (status == RSI_SUCCESS) { + uint8_t end_of_file = 0; + uint8_t http_cmd_type = *payload; + rsi_http_client_put_pkt_rsp_t *put_pkt_rsp = (rsi_http_client_put_pkt_rsp_t *)payload; + http_Put_Data_t *http_put_pkt = (http_Put_Data_t *)payload; + + // Check for HTTP_CLIENT_PUT_PKT command + if (http_cmd_type == HTTP_CLIENT_PUT_PKT) { + payload_length = 0; + end_of_file = put_pkt_rsp->end_of_file; + } + // Check for HTTP Client PUT response from server + else if (http_cmd_type == HTTP_CLIENT_PUT_OFFSET_PKT) { + payload_length = http_put_pkt->data_len; + end_of_file = *(payload + 4); + } + // Call HTTP client PUT asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_put_response_handler(status, + (uint8_t)*payload, + payload + RSI_HTTP_PUT_OFFSET, + payload_length, + end_of_file); + } else { + // Call POP3 client asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_put_response_handler(status, + host_desc[5], + payload + RSI_HTTP_PUT_OFFSET, + payload_length, + 0); + } + rsi_wlan_set_nwk_status(status); + return RSI_SUCCESS; + } + } break; + case RSI_WLAN_RSP_GET_PROFILE: { + // check the length of application buffer and copy get profile response + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } break; + case RSI_WLAN_RSP_POP3_CLIENT: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_pop3_client_mail_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + if (status == RSI_SUCCESS) { + // Call POP3 client asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_pop3_client_mail_response_handler(status, (uint8_t)*payload, payload); + } else { + // Call POP3 client asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_pop3_client_mail_response_handler(status, host_desc[5], payload); + } + rsi_wlan_set_nwk_status(status); + return RSI_SUCCESS; + } + } break; +#ifdef RSI_UART_INTERFACE + case RSI_WLAN_RSP_UART_DATA_ACK: { + if (!(rsi_socket_pool[rsi_wlan_cb_non_rom->rsi_uart_data_ack_check].sock_bitmap + & RSI_SOCKET_FEAT_TCP_ACK_INDICATION)) { + // check wlan_cb for any task is waiting for response + if (rsi_wlan_cb->expected_response != cmd_type) { + // Previous TX packet has dropped in module +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(2); +#endif + // signal the wlan semaphore + rsi_semaphore_post(&rsi_wlan_cb->wlan_sem); + } + } + + rsi_wlan_socket_set_status(status, rsi_wlan_cb_non_rom->rsi_uart_data_ack_check); +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->send_data_sem); + } break; +#endif + case RSI_WLAN_RSP_SOCKET_CONFIG: { + // check status + status = rsi_bytes2R_to_uint16(host_desc + RSI_STATUS_OFFSET); + if (rsi_wlan_cb_non_rom->callback_list.rsi_max_available_rx_window) { + rsi_wlan_cb_non_rom->callback_list.rsi_max_available_rx_window(status, payload, payload_length); + } + } break; +#ifdef RSI_WAC_MFI_ENABLE + case RSI_WLAN_RSP_ADD_MFI_IE: { + if (status == RSI_SUCCESS) { + rsi_wlan_cb->state = RSI_WLAN_STATE_BAND_DONE; + } + } break; +#endif + case RSI_WLAN_RSP_HOST_PSK: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy generated wps pin + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_SNTP_SERVER: + case RSI_WLAN_RSP_SNTP_CLIENT: { + if (status == RSI_SUCCESS) { + if ((rsi_driver_cb_non_rom->nwk_app_buffer != NULL) && (rsi_driver_cb_non_rom->nwk_app_buffer_length != 0)) { + copy_length = (payload_length < rsi_driver_cb_non_rom->nwk_app_buffer_length) + ? (payload_length) + : (rsi_driver_cb_non_rom->nwk_app_buffer_length); + memcpy(rsi_driver_cb_non_rom->nwk_app_buffer, payload, copy_length); + } + } + rsi_driver_cb_non_rom->nwk_app_buffer = NULL; + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_sntp_client_create_response_handler != NULL) { + if (((uint8_t)*payload == RSI_SNTP_CREATE) || ((uint8_t)*payload == RSI_SNTP_DELETE) + || ((uint8_t)*payload == RSI_SNTP_SERVER_ASYNC_RSP) || ((uint8_t)*payload == RSI_SNTP_GETSERVER_ADDRESS)) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Call SNTP client asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_sntp_client_create_response_handler(status, + (uint8_t)*payload, + payload); + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending &= ~(SNTP_RESPONSE_PENDING); + rsi_wlan_set_nwk_status(status); + return RSI_SUCCESS; + } + } + } break; + case RSI_WLAN_RSP_RADIO: { + if (status == RSI_SUCCESS) { + if (rsi_wlan_cb->state == RSI_WLAN_STATE_SCAN_DONE + && rsi_wlan_cb_non_rom->wlan_radio == RSI_WLAN_RADIO_DEREGISTER) { + rsi_wlan_cb->state = RSI_WLAN_STATE_INIT_DONE; + } + } + + } break; + + // this switch case copy for response buffer to user space. + case RSI_WLAN_RSP_GET_CFG: { + + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy firmware version + if ((rsi_wlan_cb->app_buffer != NULL) && (rsi_wlan_cb->app_buffer_length != 0)) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + + } break; + case RSI_WLAN_RSP_TWT_ASYNC: { + if (rsi_wlan_cb_non_rom->callback_list.twt_response_handler != NULL) { + rsi_wlan_cb_non_rom->callback_list.twt_response_handler(status, payload, payload_length); + } + } break; +#ifndef RSI_M4_INTERFACE + case RSI_WLAN_RSP_CERT_VALID: { + if (status == RSI_SUCCESS) { + + rsi_cert_recv_t *cert_recev = (rsi_cert_recv_t *)payload; + + // Get IP version + ip_version = rsi_bytes2R_to_uint16(cert_recev->ip_version); + + if (ip_version == 4) { + sockID = rsi_get_socket_descriptor(cert_recev->src_port, + cert_recev->dst_port, + cert_recev->ip_address.ipv4_address, + ip_version, + rsi_bytes2R_to_uint16(cert_recev->sock_desc)); + } else { + sockID = rsi_get_socket_descriptor(cert_recev->src_port, + cert_recev->dst_port, + cert_recev->ip_address.ipv6_address, + ip_version, + rsi_bytes2R_to_uint16(cert_recev->sock_desc)); + } + if (sockID < 0 || (sockID >= RSI_NUMBER_OF_SOCKETS)) { + break; + } + + if ((rsi_socket_pool[sockID].recv_buffer_length) < (*(uint16_t *)(cert_recev->total_len))) { + status = RSI_ERROR_INSUFFICIENT_BUFFER; + rsi_wlan_socket_set_status(status, sockID); + } + } + if (rsi_wlan_cb_non_rom->callback_list.certificate_response_handler != NULL) { + //Changing the nwk state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.certificate_response_handler(status, payload, payload_length); + } + } break; + case RSI_WLAN_RSP_MODULE_STATE: { + if (status == RSI_SUCCESS) { + if (rsi_wlan_cb_non_rom->callback_list.wlan_async_module_state != NULL) { + rsi_wlan_cb_non_rom->callback_list.wlan_async_module_state(status, payload, payload_length); + } + } + } break; +#endif +#ifdef PROCESS_SCAN_RESULTS_AT_HOST + case RSI_WLAN_RSP_SCAN_RESULTS: { + + if (status == RSI_SUCCESS) { + + recv_freq = pkt->desc[9]; + recv_freq = recv_freq << 8 | pkt->desc[8]; + rssi = pkt->desc[10]; + channel = pkt->desc[11]; + + process_scan_results(payload, payload_length, rssi, channel, recv_freq); + return RSI_SUCCESS; + } + + } break; +#endif + case RSI_WLAN_RSP_EMB_MQTT_CLIENT: { + if (status == RSI_ERROR_MQTT_PING_TIMEOUT) { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_keep_alive_timeout_callback != NULL) { + // This should not post semaphore + rsi_wlan_set_nwk_status(status); + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_keep_alive_timeout_callback(status, + pkt->data, + payload_length); + return RSI_SUCCESS; + } + } + } break; + case RSI_WLAN_RSP_MQTT_REMOTE_TERMINATE: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_remote_terminate_handler != NULL) { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_remote_terminate_handler(status, pkt->data, payload_length); + } + } break; + case RSI_WLAN_RSP_EMB_MQTT_PUBLISH_PKT: { + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_publish_message_callback != NULL) { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_publish_message_callback(status, pkt->data, payload_length); + } + } break; + case RSI_WLAN_RSP_GET_CSI_DATA: { + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_csi_data_response_handler != NULL) { + rsi_wlan_cb_non_rom->callback_list.wlan_receive_csi_data_response_handler(status, pkt->data, payload_length); + } + } break; + case RSI_WLAN_RSP_CALIB_READ: { + if (status == RSI_SUCCESS) { + // check the length of application buffer and copy received + if (rsi_wlan_cb->app_buffer != NULL) { + copy_length = (payload_length < rsi_wlan_cb->app_buffer_length) ? (payload_length) + : (rsi_wlan_cb->app_buffer_length); + memcpy(rsi_wlan_cb->app_buffer, payload, copy_length); + rsi_wlan_cb->app_buffer = NULL; + } + } + } break; + + default: + break; + } + if (cmd_type == RSI_WLAN_REQ_SELECT_REQUEST) { + + socket_select_rsp = (rsi_rsp_socket_select_t *)payload; + j = socket_select_rsp->select_id; + // update the status in wlan_cb + rsi_select_set_status(status, j); + if (rsi_socket_select_info[j].select_state == RSI_SOCKET_SELECT_STATE_CREATE) { + // Wait on select semaphore + rsi_semaphore_post(&rsi_socket_select_info[j].select_sem); + } + } else if ((cmd_type == RSI_WLAN_REQ_HTTP_CLIENT_POST) || (cmd_type == RSI_WLAN_REQ_DNS_SERVER_ADD) + || (cmd_type == RSI_WLAN_REQ_DHCP_USER_CLASS) || (cmd_type == RSI_WLAN_REQ_HTTP_CLIENT_GET) + || (cmd_type == RSI_WLAN_REQ_POP3_CLIENT) || (cmd_type == RSI_WLAN_REQ_WEBPAGE_LOAD) + || (cmd_type == RSI_WLAN_REQ_HTTP_ABORT) || (cmd_type == RSI_WLAN_REQ_MULTICAST) + || (cmd_type == RSI_WLAN_REQ_JSON_LOAD) || (cmd_type == RSI_WLAN_REQ_HTTP_CLIENT_PUT) + || (cmd_type == RSI_WLAN_REQ_WIRELESS_FWUP) || (cmd_type == RSI_WLAN_REQ_JSON_OBJECT_ERASE) + || (cmd_type == RSI_WLAN_REQ_HTTP_CLIENT_POST_DATA) || (cmd_type == RSI_WLAN_REQ_HTTP_CREDENTIALS) + || (cmd_type == RSI_WLAN_REQ_HOST_WEBPAGE_SEND) || (cmd_type == RSI_WLAN_REQ_SMTP_CLIENT) + || (cmd_type == RSI_WLAN_RSP_DNS_SERVER_ADD) || (cmd_type == RSI_WLAN_REQ_DNS_QUERY) + || (cmd_type == RSI_WLAN_REQ_FTP) || (cmd_type == RSI_WLAN_REQ_MDNSD) + || (cmd_type == RSI_WLAN_REQ_DNS_UPDATE) || (cmd_type == RSI_WLAN_REQ_SNTP_CLIENT) + || (cmd_type == RSI_WLAN_REQ_OTA_FWUP) || (cmd_type == RSI_WLAN_REQ_WEBPAGE_CLEAR_ALL) + || (cmd_type == RSI_WLAN_REQ_FWUP) || (cmd_type == RSI_WLAN_RSP_WIRELESS_FWUP_OK) + || (cmd_type == RSI_WLAN_RSP_WIRELESS_FWUP_DONE) || (cmd_type == RSI_WLAN_REQ_EMB_MQTT_CLIENT) + || (cmd_type == RSI_WLAN_REQ_PING_PACKET)) { + rsi_wlan_set_nwk_status(status); +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap &= ~BIT(0); +#endif + // post on nwk semaphore + rsi_semaphore_post(&rsi_driver_cb_non_rom->nwk_sem); + + } else if ((cmd_type == RSI_WLAN_REQ_SET_MAC_ADDRESS) || (cmd_type == RSI_WLAN_REQ_BAND) + || (cmd_type == RSI_WLAN_REQ_TIMEOUT) || (cmd_type == RSI_WLAN_REQ_INIT) + || (cmd_type == RSI_WLAN_REQ_SET_WEP_KEYS) || (cmd_type == RSI_WLAN_REQ_GET_RANDOM) + || (cmd_type == RSI_WLAN_REQ_SET_REGION) || (cmd_type == RSI_WLAN_REQ_HOST_PSK) + || (cmd_type == RSI_WLAN_REQ_DISCONNECT) || (cmd_type == RSI_WLAN_REQ_CONFIG) + || (cmd_type == RSI_WLAN_REQ_REJOIN_PARAMS) || (cmd_type == RSI_WLAN_REQ_IPCONFV4) + || (cmd_type == RSI_WLAN_REQ_SCAN) || (cmd_type == RSI_WLAN_REQ_JOIN) + || (cmd_type == RSI_WLAN_REQ_SET_CERTIFICATE) || (cmd_type == RSI_WLAN_REQ_WMM_PS) + || (cmd_type == RSI_WLAN_REQ_BG_SCAN) || (cmd_type == RSI_WLAN_REQ_RSSI) + || (cmd_type == RSI_WLAN_REQ_EAP_CONFIG) || (cmd_type == RSI_WLAN_REQ_ROAM_PARAMS) + || (cmd_type == RSI_WLAN_REQ_MAC_ADDRESS) || (cmd_type == RSI_WLAN_REQ_WPS_METHOD) + || (cmd_type == RSI_WLAN_REQ_GET_CFG) || (cmd_type == RSI_WLAN_REQ_CONNECTION_STATUS) + || (cmd_type == RSI_WLAN_REQ_QUERY_GO_PARAMS) || (cmd_type == RSI_WLAN_REQ_USER_STORE_CONFIG) + || (cmd_type == RSI_WLAN_REQ_CONFIGURE_P2P) || (cmd_type == RSI_WLAN_REQ_QUERY_NETWORK_PARAMS) + || (cmd_type == RSI_WLAN_REQ_AP_CONFIGURATION) || (cmd_type == RSI_WLAN_REQ_SET_MULTICAST_FILTER) + || (cmd_type == RSI_WLAN_REQ_HT_CAPABILITIES) || (cmd_type == RSI_WLAN_REQ_SET_PROFILE) + || (cmd_type == RSI_WLAN_REQ_CFG_SAVE) || (cmd_type == RSI_WLAN_REQ_TX_TEST_MODE) + || (cmd_type == RSI_WLAN_REQ_GET_PROFILE) || (cmd_type == RSI_WLAN_REQ_FREQ_OFFSET) + || (cmd_type == RSI_WLAN_REQ_CALIB_WRITE) || (cmd_type == RSI_WLAN_REQ_CALIB_READ) + || (cmd_type == RSI_WLAN_REQ_DELETE_PROFILE) || (cmd_type == RSI_WLAN_REQ_SET_SLEEP_TIMER) + || (cmd_type == RSI_WLAN_REQ_FILTER_BCAST_PACKETS) || (cmd_type == RSI_WLAN_REQ_AUTO_CONFIG_ENABLE) + || (cmd_type == RSI_WLAN_REQ_SOCKET_CONFIG) || (cmd_type == RSI_WLAN_RSP_IPCONFV6) + || (cmd_type == RSI_WLAN_REQ_SET_REGION_AP) || (cmd_type == RSI_WLAN_REQ_DYNAMIC_POOL) + || (cmd_type == RSI_WLAN_REQ_GAIN_TABLE) || (cmd_type == RSI_WLAN_REQ_RX_STATS) + || (cmd_type == RSI_WLAN_REQ_RADIO) || (cmd_type == RSI_WLAN_REQ_GET_STATS) + || (cmd_type == RSI_WLAN_REQ_11AX_PARAMS) || (cmd_type == RSI_WLAN_REQ_TWT_PARAMS) + || (cmd_type == RSI_WLAN_REQ_EXT_STATS) +#ifdef RSI_WAC_MFI_ENABLE + || (cmd_type == RSI_WLAN_REQ_ADD_MFI_IE) +#endif + ) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(0); +#endif + rsi_wlan_set_status(status); + // post on nwk semaphore + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_sem); + + } else if (cmd_type == RSI_WLAN_RSP_SOCKET_CREATE || cmd_type == RSI_WLAN_RSP_CONN_ESTABLISH) { + if (sockID >= 0) { + rsi_wlan_socket_set_status(status, sockID); + if (rsi_socket_pool_non_rom[sockID].socket_wait_bitmap & BIT(0)) { +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(0); +#endif + // Wait on select semaphore + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].socket_sem); + } + } + } + + return RSI_SUCCESS; +} + +/** @} */ +/** @addtogroup WLAN +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_radio_init(void) + * @brief Initializes WLAN radio and supplicant parameters. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0x0021) \n + * @note **Precondition** - \ref rsi_wireless_init() API must be called before this API. + * @note rsi_wlan_radio_init() is used if user wants to configure any other parameters, which are supposed to be given before rsi_wlan_scan() or rsi_wlan_scan_async() API + */ + +int32_t rsi_wlan_radio_init(void) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + int32_t allow = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_RADIO_INIT_ENTRY, WLAN, LOG_INFO); + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state <= RSI_WLAN_STATE_BAND_DONE) { + allow = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + } + if (allow == RSI_SUCCESS) { + switch (wlan_cb->state) { + case RSI_WLAN_STATE_OPERMODE_DONE: { + if (wlan_cb->field_valid_bit_map & RSI_SET_MAC_BIT) { + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + SL_PRINTF(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_mac_address_t)); + + // Memcpy data + memcpy(&pkt->data, wlan_cb->mac_address, sizeof(rsi_req_mac_address_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send set mac command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_MAC_ADDRESS, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_MAC_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } + +#if HE_PARAMS_SUPPORT + status = rsi_wlan_11ax_config(GUARD_INTERVAL); + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_2, WLAN, LOG_INFO, "status: %4x", status); + return status; + } +#endif + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + SL_PRINTF(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_band_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send band command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BAND, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BAND_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // If BAND command fails + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_3, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } + //no break + //fall through + case RSI_WLAN_STATE_BAND_DONE: { +#if RSI_TIMEOUT_SUPPORT + status = send_timeout(RSI_TIMEOUT_BIT_MAP, RSI_TIMEOUT_VALUE); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_4, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + SL_PRINTF(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send init command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_INIT, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_INIT_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_5, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#if RSI_SET_REGION_AP_SUPPORT + if (wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + SL_PRINTF(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_5, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_ap_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send set region AP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION_AP, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_AP_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_6, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } +#endif +#if RSI_SET_REGION_SUPPORT + if (wlan_cb->opermode != RSI_WLAN_ACCESS_POINT_MODE) { + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + SL_PRINTF(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_6, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send set region command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_7, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } +#endif + } break; + /* These cases are added to resolve compilation warning*/ + case RSI_WLAN_STATE_NONE: + case RSI_WLAN_STATE_INIT_DONE: + case RSI_WLAN_STATE_SCAN_DONE: + case RSI_WLAN_STATE_CONNECTED: + case RSI_WLAN_STATE_IP_CONFIG_DONE: + case RSI_WLAN_STATE_IPV6_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON: + case RSI_WLAN_STATE_AUTO_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_FAILED: + //fall through + + default: { + if (rsi_wlan_cb_non_rom->wlan_radio == RSI_WLAN_RADIO_DEREGISTER) { + // req for wlan radio + status = rsi_wlan_req_radio(RSI_ENABLE); + } + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_8, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + // no break + } + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // return wlan command error + SL_PRINTF(SL_WLAN_RADIO_INIT_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "Allow:%4x", allow); + return allow; + } + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_INIT_EXIT_9, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_filter_broadcast(uint16_t beacon_drop_threshold, + uint8_t filter_bcast_in_tim, + uint8_t filter_bcast_tim_till_next_cmd) + * @brief Program the ignore threshold levels of the broadcast packet when station is in power save and is used to achieve low current consumption in standby associated mode. + * This is blocking API + * @param[in] beacon_drop_threshold - LMAC beacon drop threshold(ms): The amount of time that FW waits to receive full beacon.Default value is 5000ms. + * @param[in] filter_bcast_in_tim - If this bit is set, then from the next dtim any broadcast data pending bit in TIM indicated will be ignored valid values: 0 - 1 \n + * Validity of this bit is dependent on the filter_bcast_tim_till_next_cmd. + * @param[in] filter_bcast_tim_till_next_cmd - 0 - filter_bcast_in_tim is valid till disconnect of the STA. \n + * 1 - filter_bcast_in_tim is valid till next update by giving the same command. \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0x0021) \n + */ +int32_t rsi_wlan_filter_broadcast(uint16_t beacon_drop_threshold, + uint8_t filter_bcast_in_tim, + uint8_t filter_bcast_tim_till_next_cmd) +{ + rsi_pkt_t *pkt; + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_FILTER_BROADCAST_ENTRY, WLAN, LOG_INFO); + rsi_req_wlan_filter_bcast_t *rsi_filter_bcast; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + SL_PRINTF(SL_WLAN_FILTER_BROADCAST_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_wlan_filter_bcast_t)); + + rsi_filter_bcast = (rsi_req_wlan_filter_bcast_t *)pkt->data; + + rsi_uint16_to_2bytes(rsi_filter_bcast->beacon_drop_threshold, beacon_drop_threshold); + + rsi_filter_bcast->filter_bcast_in_tim = filter_bcast_in_tim; + + rsi_filter_bcast->filter_bcast_tim_till_next_cmd = filter_bcast_tim_till_next_cmd; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send band command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FILTER_BCAST_PACKETS, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_FILTER_BROADCAST_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // return nwk command error + SL_PRINTF(SL_WLAN_FILTER_BROADCAST_NWK_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return the status if error in sending command occurs + SL_PRINTF(SL_WLAN_FILTER_BROADCAST_COMMAND_SEN_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ +/** @addtogroup DRIVER13 +* @{ +*/ +/*==============================================*/ +/** + * + * @fn uint32_t rsi_check_wlan_state(void) + * @brief Get WLAN status. + * @param[in] void + * @return Wlan block status \n + * @return 0 - RSI_WLAN_STATE_NONE \n + * @return 1 - RSI_WLAN_STATE_OPERMODE_DONE \n + * @return 2 - RSI_WLAN_STATE_BAND_DONE \n + * @return 3 - RSI_WLAN_STATE_INIT_DONE \n + * @return 4 - RSI_WLAN_STATE_SCAN_DONE \n + * @return 5 - RSI_WLAN_STATE_CONNECTED \n + * @return 6 - RSI_WLAN_STATE_IP_CONFIG_DONE \n + * @return 7 - RSI_WLAN_STATE_IPV6_CONFIG_DONE \n + * @return 8 - RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON \n + * @return 9 - RSI_WLAN_STATE_AUTO_CONFIG_DONE \n + * @return 10- RSI_WLAN_STATE_AUTO_CONFIG_FAILED + * + * + * + */ +/// @private +uint32_t rsi_check_wlan_state(void) +{ + return rsi_driver_cb->wlan_cb->state; +} + +/*==============================================*/ +/** + * @fn void rsi_wlan_set_status(int32_t status) + * @brief Set the WLAN status. + * @param[in] status - Status value to be set + * @return void + * + * + */ +/// @private +void rsi_wlan_set_status(int32_t status) +{ + rsi_driver_cb->wlan_cb->status = status; +} +/*==============================================*/ +/** + * @fn int32_t rsi_post_waiting_semaphore(void) + * @brief Post on a waiting semaphore. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +/// @private +int32_t rsi_post_waiting_semaphore(void) +{ + int i = 0; + rsi_rsp_socket_create_t socket_rsp; + rsi_wlan_set_nwk_status(RSI_ERROR_IN_WLAN_CMD); + rsi_call_asynchronous_callback(); + rsi_post_waiting_nwk_semaphore(); + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + // post socket semaphores + if (rsi_socket_pool[i].sock_state > RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_IN_WLAN_CMD, i); + +#ifdef SOCKET_CLOSE_WAIT + rsi_socket_pool_non_rom[i].close_pending = 1; +#endif + if (rsi_wlan_cb_non_rom->socket_cmd_rsp_pending & BIT(i)) { + memset(&socket_rsp, 0, sizeof(rsi_rsp_socket_create_t)); + if (rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler != NULL) { + // Changing the callback response f/w socket id to app socket id. + rsi_uint16_to_2bytes(socket_rsp.socket_id, i); + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler((uint16_t)RSI_ERROR_IN_WLAN_CMD, + (uint8_t *)&socket_rsp, + sizeof(rsi_rsp_socket_create_t)); + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending &= ~BIT(i); + } + if (rsi_socket_pool_non_rom[i].accept_call_back_handler != NULL) { + rsi_socket_pool_non_rom[i].accept_call_back_handler(i, 0, 0, 0); + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending &= ~BIT(i); + } + } + // post on semaphore + rsi_post_waiting_socket_semaphore(i); + } + } +#ifndef SOCKET_CLOSE_WAIT + // Clear all sockets info + rsi_clear_sockets(RSI_CLEAR_ALL_SOCKETS); +#endif + for (i = 0; i < RSI_NUMBER_OF_SELECTS; i++) { + if (rsi_socket_select_info[i].select_state == RSI_SOCKET_SELECT_STATE_CREATE) { + if (rsi_socket_select_info[i].sock_select_callback == NULL) { + // update the status in wlan_cb + rsi_select_set_status(RSI_ERROR_IN_WLAN_CMD, i); + rsi_semaphore_post(&rsi_socket_select_info[i].select_sem); + } else { + //clear the read fd set + RSI_FD_ZERO(&rsi_socket_select_info[i].rsi_sel_read_fds_var); + rsi_socket_select_info[i].rsi_sel_read_fds_var.fd_count = 0; + + //clear the write fd set + RSI_FD_ZERO(&rsi_socket_select_info[i].rsi_sel_write_fds_var); + rsi_socket_select_info[i].rsi_sel_write_fds_var.fd_count = 0; + + //clear the exception fd set + RSI_FD_ZERO(&rsi_socket_select_info[i].rsi_sel_exception_fds_var); + rsi_socket_select_info[i].rsi_sel_exception_fds_var.fd_count = 0; + + rsi_socket_select_info[i].sock_select_callback( + (rsi_fd_set *)&rsi_socket_select_info[i].rsi_sel_read_fds_var, + (rsi_fd_set *)&rsi_socket_select_info[i].rsi_sel_write_fds_var, + (rsi_fd_set *)&rsi_socket_select_info[i].rsi_sel_exception_fds_var, + -1); + + rsi_socket_select_info[i].sock_select_callback = NULL; + + rsi_socket_select_info[i].select_state = RSI_SOCKET_SELECT_STATE_INIT; + } + } + } + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending = 0; + return RSI_SUCCESS; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_check_waiting_socket_cmd(void) + * @brief Check if any socket command is in waiting state. + * @param[in] void + * @return 0 - No socket command is in waiting state \n + * @return 1 - Socket command is in waiting state + * + */ +/// @private +int32_t rsi_wlan_check_waiting_socket_cmd(void) +{ + + // Get wlan cb struct pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((wlan_cb->expected_response == RSI_WLAN_RSP_SOCKET_ACCEPT) + || (wlan_cb->expected_response == RSI_WLAN_RSP_SOCKET_CREATE) + || (wlan_cb->expected_response == RSI_WLAN_RSP_SOCKET_READ_DATA) + || (wlan_cb->expected_response == RSI_WLAN_RSP_SOCKET_CLOSE) + || (wlan_cb->expected_response == RSI_WLAN_RSP_CONN_ESTABLISH) + || (wlan_cb->expected_response == RSI_WLAN_RSP_TCP_ACK_INDICATION)) { + return 1; + } else { + return 0; + } +} + +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_check_waiting_wlan_cmd(void) + * @brief Check if any WLAN command is in waiting state. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * + */ +/// @private +int32_t rsi_wlan_check_waiting_wlan_cmd(void) +{ + // Get wlan cb struct pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((wlan_cb->expected_response == RSI_WLAN_RSP_IPCONFV4) || (wlan_cb->expected_response == RSI_WLAN_RSP_DISCONNECT) + || (wlan_cb->expected_response == RSI_WLAN_RSP_IPCONFV6) + || (wlan_cb->expected_response == RSI_WLAN_RSP_ROAM_PARAMS) + || (wlan_cb->expected_response == RSI_WLAN_RSP_BG_SCAN) + || (wlan_cb->expected_response == RSI_WLAN_RSP_DYNAMIC_POOL) + || (wlan_cb->expected_response == RSI_WLAN_RSP_SET_MULTICAST_FILTER)) + + { + return 1; + } else { + return RSI_SUCCESS; + } +} +/*==============================================*/ +/** + * @fn void rsi_wlan_process_raw_data(rsi_pkt_t *pkt) + * @brief Receive raw data packet from module. + * @param[in] pkt - pointer to RX pkt + * @return Void + * @note Memory allocation for the pointer is from receive handler ,after processing, it will be freed. + * + * + */ + +void rsi_wlan_process_raw_data(rsi_pkt_t *pkt) +{ + uint8_t *host_desc; + uint8_t *payload; + uint16_t payload_length; + + // Get wlan cb struct pointer + // rsi_wlan_cb_t *rsi_wlan_cb = rsi_driver_cb->wlan_cb; + + // Get host descriptor + host_desc = pkt->desc; + + // Get payload pointer + payload = pkt->data; + + // Get payoad length + payload_length = (rsi_bytes2R_to_uint16(host_desc) & 0xFFF); + + if (rsi_wlan_cb_non_rom->callback_list.wlan_data_receive_handler != NULL) { + // Call asynchronous data receive handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_data_receive_handler(0, payload, payload_length); + } +} + +/*==============================================*/ +/** + * @fn void rsi_wlan_packet_transfer_done(rsi_pkt_t *pkt) + * @brief Handle packet transfer completion. + * @param[in] pkt - pointer to packet + * @return void + * + */ +/// @private +void rsi_wlan_packet_transfer_done(rsi_pkt_t *pkt) +{ + // uint8_t queueno = 0xff; +#ifndef RSI_UART_INTERFACE + uint8_t queueno; // To avoid warning for unused variable 'queueno' added the macros. + uint8_t frame_type; + uint8_t *buf_ptr; + rsi_req_socket_send_t *send; + int32_t sockID; +#endif + +#ifndef RSI_UART_INTERFACE + buf_ptr = (uint8_t *)pkt->desc; + + // Get Frame type + frame_type = buf_ptr[2]; + + // Get data pointer + send = (rsi_req_socket_send_t *)pkt->data; + + // Get protocol type + queueno = (buf_ptr[1] & 0xf0) >> 4; +#endif + + // Set wlan status as success + rsi_wlan_set_status(RSI_SUCCESS); +#ifndef RSI_UART_INTERFACE + if (queueno == RSI_WLAN_DATA_Q) { + if (frame_type == 0x1) { +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->send_data_sem); + } else if (rsi_driver_cb->wlan_cb->expected_response != RSI_WLAN_RSP_TCP_ACK_INDICATION) { + sockID = rsi_get_application_socket_descriptor(send->socket_id[0]); + if ((sockID >= 0) && (sockID < RSI_NUMBER_OF_SOCKETS)) { + rsi_wlan_socket_set_status(RSI_SUCCESS, sockID); +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(2); + RSI_SEMAPHORE_POST(&rsi_socket_pool_non_rom[sockID].sock_send_sem); +#else + RSI_SEMAPHORE_POST(&rsi_socket_pool_non_rom[sockID].sock_send_sem); +#endif + } + } + } +#endif + // Free the wlan tx pkt + rsi_pkt_free(&rsi_driver_cb->wlan_cb->wlan_tx_pool, pkt); +} + +/*==============================================*/ +/** + * @fn void rsi_check_wlan_buffer_full(rsi_pkt_t *pkt) + * @brief Clear TX packet, if TX buffer is full + * @param[in] pkt - Buffer pointer + * @note BUFFER_FULL_HANDLING macro should be enabled. + * @return Void + * + */ +/// @private +void rsi_check_wlan_buffer_full(rsi_pkt_t *pkt) +{ + uint8_t queueno = 0xff; + uint8_t *buf_ptr; + int32_t sockID; + uint8_t frame_type; + rsi_req_socket_send_t *send; + + buf_ptr = (uint8_t *)pkt->desc; + // Get Frame type + frame_type = buf_ptr[2]; + + // Get data pointer + send = (rsi_req_socket_send_t *)pkt->data; + // Get protocol type + queueno = (buf_ptr[1] & 0xf0) >> 4; + // Set wlan status as TX buffer full + rsi_wlan_set_status(RSI_TX_BUFFER_FULL); + if (queueno == RSI_WLAN_DATA_Q) { + if (frame_type == 0x1) { +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap &= ~BIT(0); +#endif + rsi_semaphore_post(&rsi_driver_cb_non_rom->send_data_sem); + } else if (rsi_driver_cb->wlan_cb->expected_response != RSI_WLAN_RSP_TCP_ACK_INDICATION) { + sockID = rsi_get_application_socket_descriptor(send->socket_id[0]); + if (sockID >= 0) { + rsi_wlan_socket_set_status(RSI_SUCCESS, sockID); +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap &= ~BIT(2); +#endif + RSI_SEMAPHORE_POST(&rsi_socket_pool_non_rom[sockID].sock_send_sem); + } + } + } + // Free the wlan tx pkt + rsi_pkt_free(&rsi_driver_cb->wlan_cb->wlan_tx_pool, pkt); +} + +/*==============================================*/ +/** + * @fn void rsi_check_common_buffer_full(rsi_pkt_t *pkt) + * @brief Check if the common buffer is full. + * @param[in] pkt - Buffer pointer + * @return void + * + */ +/// @private +void rsi_check_common_buffer_full(rsi_pkt_t *pkt) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(pkt); + // Set wlan status as TX buffer full + rsi_wlan_set_status(RSI_TX_BUFFER_FULL); +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap &= ~BIT(2); +#endif + + // Post the semaphore which is waiting on socket send + rsi_semaphore_post(&rsi_driver_cb->wlan_cb->wlan_sem); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_wait_on_wlan_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms ) + * @brief Wait for WLAN semaphore + * @param[in] Semaphore - Semaphore handle pointer + * @param[in] timeout_ms - Maximum time to wait to acquire semaphore. \n If timeout_ms is 0, then wait till semaphore is acquired + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +/// @private +rsi_error_t rsi_wait_on_wlan_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) +{ + // Wait on wlan semaphore + if (rsi_semaphore_wait(semaphore, timeout_ms) != RSI_ERROR_NONE) { + rsi_wlan_set_status(RSI_ERROR_RESPONSE_TIMEOUT); +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + if (rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb != NULL) { + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb(RSI_ERROR_RESPONSE_TIMEOUT, WLAN_CMD); + } +#endif + return RSI_ERROR_RESPONSE_TIMEOUT; + } + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn void rsi_update_wlan_cmd_state_to_free_state(void) + * @brief Update the WLAN command state to free state. + * @param[in] void + * @return Void + * + */ + +void rsi_update_wlan_cmd_state_to_free_state(void) +{ + rsi_driver_cb_non_rom->wlan_cmd_state = RSI_WLAN_CMD_IN_FREE_STATE; +} + +/*==============================================*/ +/** + * @fn void rsi_update_wlan_cmd_state_to_progress_state(void) + * @brief Update the WLAN command state to progress state + * @param[in] void + * @return Void + */ +/// @private +void rsi_update_wlan_cmd_state_to_progress_state(void) +{ + rsi_driver_cb_non_rom->wlan_cmd_state = RSI_WLAN_CMD_IN_PROGRESS; +} +/*==============================================*/ +/** + * @fn int32_t rsi_post_waiting_wlan_semaphore(void) + * @brief Posts all waiting WLAN semaphores. This API is typically used to reset the semaphore states. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * + */ +/// @private +#ifndef RSI_WLAN_SEM_BITMAP +void rsi_post_waiting_wlan_semaphore(void) +{ + if (rsi_driver_cb_non_rom->wlan_wait_bitmap & BIT(0)) { + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_sem); + } + if (rsi_driver_cb_non_rom->wlan_wait_bitmap & BIT(1)) { + rsi_semaphore_post(&rsi_driver_cb_non_rom->wlan_cmd_send_sem); + } + if (rsi_driver_cb_non_rom->wlan_wait_bitmap & BIT(2)) { + rsi_semaphore_post(&rsi_driver_cb->wlan_cb->wlan_sem); + } + rsi_driver_cb_non_rom->wlan_wait_bitmap = 0; +} +#endif +void rsi_call_asynchronous_callback() +{ + if ((rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending & (PING_RESPONSE_PENDING)) + && rsi_wlan_cb_non_rom->callback_list.wlan_ping_response_handler != NULL) { + // Call asynchronous response handler to indicate to host + rsi_wlan_cb_non_rom->callback_list.wlan_ping_response_handler((uint16_t)RSI_ERROR_IN_WLAN_CMD, NULL, 0); + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending &= ~(PING_RESPONSE_PENDING); + } + + if ((rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending & (DNS_RESPONSE_PENDING)) + && rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dns_update_rsp_handler != NULL) { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dns_update_rsp_handler((uint16_t)RSI_ERROR_IN_WLAN_CMD); + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending &= ~(DNS_RESPONSE_PENDING); + } + if ((rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending & (SNTP_RESPONSE_PENDING)) + && rsi_wlan_cb_non_rom->nwk_callbacks.rsi_sntp_client_create_response_handler != NULL) { + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_sntp_client_create_response_handler((uint16_t)RSI_ERROR_IN_WLAN_CMD, + 0, + NULL); + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending &= ~(SNTP_RESPONSE_PENDING); + } + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending = 0; +} +/** @} */ +#ifdef PROCESS_SCAN_RESULTS_AT_HOST + +/** @addtogroup DRIVER13 +* @{ +*/ +/*==============================================*/ +/** + * + * @fn void sort_index_based_on_rssi(struct wpa_scan_results_arr *scan_results_array) + * @brief Sort the scan list based on rssi value. + * @param[in] scan_results_array - Pointer to scan results array + * @return void + */ +/// @private +void sort_index_based_on_rssi(struct wpa_scan_results_arr *scan_results_array) +{ + uint16_t scan[MAX_SCAN_COUNT]; + struct wpa_scan_res *sc = &scan_results_array->res[0]; + uint16_t i, j; + uint16_t min; + for (i = 0; i < scan_results_array->num; i++, sc++) { + scan[i] = sc->rssiVal; + } + for (i = 0; i < scan_results_array->num; i++) { + min = scan[0]; + scan_results_array->sort_index[i] = 0; + for (j = 1; j < scan_results_array->num; j++) { + if (min > scan[j]) { + scan_results_array->sort_index[i] = j; + min = scan[j]; + } + } + scan[scan_results_array->sort_index[i]] = 0xFF; + } +} + +/*==============================================*/ +/** + * + * @fn get_akm_suites_info + * @brief This function lists the AKM suites supported by AP. + * @param[in] akmcnt - AKM count. + * @param[in] ie_data - pointer to IE buffer. + * @return key_mgmt value. + * + * @section description + * This function returns list of AKM suites supported by AP. + * + */ + +static unsigned int get_akm_suites_info(const uint16_t akmcnt, const uint8_t *ie_data) +{ + int i; + unsigned int key_mgmt = 0; + uint32_t oui_type; + + if (!ie_data) { + return 0; + } + + for (i = 0; i < akmcnt; i++) { + oui_type = (*(uint32_t *)&ie_data[(RSN_SELECTOR_LEN * i)]); + switch (oui_type) { + case RSN_AUTH_KEY_MGMT_UNSPEC_802_1X: + key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA | WPA_DRIVER_CAPA_KEY_MGMT_WPA2; + break; + case RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X: + key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; + break; + case RSN_AUTH_KEY_MGMT_802_1X_SHA256: + key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256; + break; + case RSN_AUTH_KEY_MGMT_PSK_SHA256: + key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256; + break; + case RSN_AUTH_KEY_MGMT_SAE: + key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_SAE; + break; + } + } + return key_mgmt; +} +/*==============================================*/ +/** + * + * @fn int process_scan_results(uint8_t *buf, uint16_t len, int8_t rssi, uint8_t channel, uint16_t freq) + * @brief Process received beacons and probe responses. + * @param[in] buf - Received frame. + * @param[in] len - Length of the buffer. + * @param[in] rssi - RSSI value + * @param[in] channel - Channel in which the frame is received + * @param[in] freq - Frequency of the channel + * @return 0 - Success \n + * @return Non-Zero Value - failure + * + * + * + * + */ +/// @private +int process_scan_results(uint8_t *buf, uint16_t len, int8_t rssi, uint8_t channel, uint16_t freq) +{ + uint8_t subtype; + uint16_t i; + uint16_t ies_len; + uint8_t *bssid; + uint16_t pairwise_cipher_count = 0; + const uint8_t *ssid_; + uint8_t ssid_len; + uint8_t *bss = NULL; + uint8_t *end = NULL; + uint16_t caps; + uint8_t WLAN_WIFI_OUI_RSN[3]; + uint8_t WLAN_WIFI_OUI[3]; + + struct wpa_scan_results_arr *scan_res = scan_results_array; + struct wpa_scan_res *result = NULL; + uint16_t *index = NULL; + + WLAN_WIFI_OUI_RSN[0] = 0x00; + WLAN_WIFI_OUI_RSN[1] = 0x0F; + WLAN_WIFI_OUI_RSN[2] = 0xAC; + + WLAN_WIFI_OUI[0] = 0x00; + WLAN_WIFI_OUI[1] = 0x50; + WLAN_WIFI_OUI[2] = 0xF2; + + /* if memory is not allocated to hold scan results break */ + if (scan_res == NULL) { + return RSI_FAILURE; + } + if ((len == 0)) { + return RSI_FAILURE; + } + + index = &scan_results_array->sort_index[0]; + + bssid = &buf[BSSID_OFFSET]; + + subtype = buf[0] & IEEE80211_FC0_SUBTYPE_MASK; + + switch (subtype) { + case IEEE80211_FC0_SUBTYPE_BEACON: + case IEEE80211_FC0_SUBTYPE_PROBE_RESP: { + if (len <= MINIMUM_FRAME_LENGTH) + return RSI_FAILURE; + + ies_len = len - MINIMUM_FRAME_LENGTH; + + /* Find if there is an entry already with same bssid */ + for (i = 0; i < scan_res->num; i++) { + if ((memcmp(scan_res->res[i].bssid, bssid, ETH_ALEN) == 0) + && (strncmp((const char *)scan_res->res[i].ssid, (const char *)&buf[SSID_OFFSET], scan_res->res[i].ssid_len) + == 0)) { + /* entry exist with same bssid, need to replace with new information*/ + result = &scan_res->res[i]; + break; + } + } + + if (result == NULL) { + /* Try to get entry to hold new information from beacon & probe response */ + if (scan_res->num >= MAX_SCAN_COUNT) { + sort_index_based_on_rssi(scan_results_array); + + /* if already maximum limit reached create space by deleting existing entry with low rssi */ + if ((scan_res->res[index[scan_res->num - 1]].level < rssi)) { + result = &scan_res->res[scan_res->sort_index[scan_res->num - 1]]; + } + + if (result == NULL) { + break; + } + } else { + result = &scan_res->res[scan_res->num]; + scan_res->num++; + } + } + + if (freq == 0) + return RSI_FAILURE; + /* copy bssid */ + memcpy((uint8_t *)&result->bssid, bssid, ETH_ALEN); + + result->freq = freq; + result->channel_no = channel; + + caps = *(uint16_t *)&buf[CAPABILITIES_OFFSET]; + result->level = rssi; + result->rssiVal = -rssi; + if (((caps & BIT(0)) == 1) && ((caps & BIT(1)) == 0)) + result->uNetworkType = 1; + else + result->uNetworkType = 0; + if ((caps & BIT(4))) { + result->security_mode = SME_WEP; + } else { + result->security_mode = SME_OPEN; + } + bss = &buf[IES_OFFSET]; + ssid_ = (uint8_t *)""; + ssid_len = 0; + memset((uint8_t *)&result->ssid, 0, RSI_SSID_LEN); + end = bss + ies_len; + while (bss + 1 < end) { + + if (bss + IE_POS + bss[IE_LEN] > end) + break; + + switch (bss[IE_TYPE]) { + case WLAN_EID_SSID: + ssid_len = bss[IE_LEN]; + ssid_ = bss + IE_POS; + memcpy((uint8_t *)&result->ssid, ssid_, ssid_len); + result->ssid_len = ssid_len; + break; + + case WLAN_EID_VENDOR_SPECIFIC: + if (((!memcmp(&bss[IE_POS], WLAN_WIFI_OUI, 3)) && bss[IE_POS + 3] == 0x01) + && (result->security_mode == SME_OPEN || result->security_mode == SME_WEP)) { + result->security_mode = SME_WPA; + pairwise_cipher_count = *(uint16_t *)&bss[12]; + if (bss[19 + pairwise_cipher_count * 4] == 1) { + result->security_mode = SME_WPA_ENTERPRISE; + } + } + break; + case WLAN_EID_RSN: + if (!memcmp((uint8_t *)&bss[WIFI_OUI_RSN], WLAN_WIFI_OUI_RSN, 3)) { + result->security_mode = SME_WPA2; /* WPA2 psk */ + pairwise_cipher_count = *(uint16_t *)&bss[8]; + uint16_t akmcnt = *(uint16_t *)&bss[RSN_AKM_OFFSET + (RSN_SELECTOR_LEN * pairwise_cipher_count)]; + unsigned int key_mgmt = + get_akm_suites_info(akmcnt, &bss[RSN_AKM_OFFSET + (RSN_SELECTOR_LEN * pairwise_cipher_count)]); + if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) /* WPA3 psk */ + { + if (akmcnt == 1) { + result->security_mode = SME_WPA3; + } else { + if ((key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) + || (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) + result->security_mode = SME_WPA3_TRANSITION; + } + } + } + break; + default: + break; + } + bss += IE_POS + bss[IE_LEN]; + } + + break; + } + + default: + + break; + } + return 0; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/include/debug_auto_gen.h b/wiseconnect/sapi/include/debug_auto_gen.h new file mode 100644 index 00000000..63cf4270 --- /dev/null +++ b/wiseconnect/sapi/include/debug_auto_gen.h @@ -0,0 +1,4213 @@ +//! This is an Auto Generated Header file +//! do not modifiy this file directly +#ifndef DEBUGS_AUTOGEN_H +#define DEBUGS_AUTOGEN_H +#define SL_LOG_VERSION "2023/06/01-15:03:39" + +enum { +SL_RSI_BT_AVRCP_INIT, +SL_RSI_BT_AVRCP_CONNECT_TRIGGER, +SL_RSI_BT_AVRCP_DISCONNECT_TRIGGER, +SL_RSI_BT_AVRCP_PLAY_TRIGGER, +SL_RSI_BT_AVRCP_PAUSE_TRIGGER, +SL_RSI_BT_AVRCP_STOP_TRIGGER, +SL_RSI_BT_AVRCP_NEXT_TRIGGER, +SL_RSI_BT_AVRCP_PREV_TRIGGER, +SL_RSI_BT_AVRCP_VOL_UP_TRIGGER, +SL_RSI_BT_AVRCP_VOL_DOWN_TRIGGER, +SL_RSI_BT_AVRCP_GET_CAPABILITES_TRIGGER, +SL_RSI_BT_GET_ATT_LIST_TRIGGER, +SL_RSI_BT_GET_ATT_VALS_LIST_TRIGGER, +SL_RSI_BT_GET_CURR_ATT_VAL_TRIGGER, +SL_RSI_BT_SET_CURR_ATT_VAL_TRIGGER, +SL_RSI_BT_GET_ELEM_ATT_TRIGGER, +SL_RSI_BT_GET_PLAY_STATUS_TRIGGER, +SL_RSI_BT_REG_NOTIFICATION_TRIGGER, +SL_RSI_BT_GET_REMOTE_VERSION_TRIGGER, +SL_RSI_BT_GET_ATT_TEXT_TRIGGER, +SL_RSI_BT_AVRCP_GET_ATT_VAL_TEXT_TRIGGER, +SL_RSI_BT_AVRCP_BATT_STATUS_TRIGGER, +SL_RSI_BT_AVRCP_SUPP_CHAR_SETS_TRIGGER, +SL_RSI_BT_AVRCP_SEND_ABS_VOLUME_TRIGGER, +SL_RSI_BT_SEND_DEVICE_CAPABILITES_TRIGGER, +SL_RSI_BT_AVRCP_ATT_LIST_RESP_TRIGGER, +SL_RSI_BT_AVRCP_ATT_VAL_LIST_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_CURR_ATT_VAL_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_SET_CURR_ATT_VAL_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_ELE_ATT_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_PLAY_STATUS_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_REG_NOTIFY_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_ATT_TEXT_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_ATT_VALS_TEXT_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_BATT_STATUS_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_CHAR_SET_STATUS_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_NOTIFY_TRIGGER, +SL_RSI_BT_AVRCP_CMD_REJECT_TRIGGER, +SL_RSI_BT_AVRCP_SET_ABS_VOL_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_SET_ADDR_PLAYER_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_GET_FOLDER_ITEMS_RESPONSE_TRIGGER, +SL_RSI_BT_AVRCP_GET_TOTAL_NUM_ITEMS_RESPONSE_TRIGGER, +SL_RSI_BT_SPP_INIT_TRIGGER, +SL_RSI_BT_SPP_CONN_TRIGGER, +SL_RSI_BT_SPP_DISCONNECT_TRIGGER, +SL_RSI_BT_SET_BD_ADDRESS, +SL_RSI_ERROR_INVALID_PARAMETER, +SL_RSI_BT_BER_ENABLE_OR_DISABLE, +SL_RSI_BT_SET_LOCAL_NAME, +SL_RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE, +SL_RSI_BT_GET_LOCAL_NAME, +SL_RSI_BT_GET_RSSI, +SL_RSI_BT_GET_LOCAL_DEVICE_ADDRESS, +SL_RSI_BT_STACK_VERSION, +SL_RSI_BT_INIT_TRIGGER, +SL_RSI_BT_DEINIT_TRIGGER, +SL_RSI_BT_SET_ANTENNA, +SL_RSI_SET_FEATURE_MAP, +SL_RSI_BT_SET_ANTENNA_TX_POWER_LEVEL, +SL_RSI_BT_POWER_SAVE_PROILE, +SL_RSI_BT_REQUEST_LOCAL_DEVICE, +SL_RSI_PER_CW_MODE, +SL_RSI_BT_VENDOR_AVDTP_STATS_ENABLE, +SL_RSI_BT_VENDOR_AR_ENABLE, +SL_RSI_BT_VENDOR_DYNAMIC_POWER, +SL_RSI_MEMORY_STATS_ENABLE, +SL_RSI_BT_L2CAP_CONNECT_TRIGGER, +SL_RSI_BT_L2CAP_DISCONNECT_TRIGGER, +SL_RSI_BT_L2CAP_INIT_TRIGGER, +SL_RSI_BT_L2CAP_SEND_DATA_REMOTE_DEVICE_TRIGGER, +SL_RSI_BT_L2CAP_CREATE_ERTM_CHANNEL_TRIGGER, +SL_RSI_BT_A2DP_INIT_TRIGGER, +SL_RSI_BT_A2DP_CONNECT_TRIGGER, +SL_RSI_BT_A2DP_DISCONNECT_TRIGGER, +SL_RSI_BT_A2DP_SEND_PCM_MP3_DATA_TRIGGER, +SL_RSI_BT_A2DP_SEND_SBC_AAC_DATA_TRIGGER, +SL_RSI_BT_A2DP_START, +SL_RSI_BT_A2DP_SUSPEND, +SL_RSI_BT_A2DP_CLOSE, +SL_RSI_BT_A2DP_ABORT, +SL_RSI_BT_A2DP_GET_CONFIG, +SL_RSI_BT_A2DP_SET_CONFIG, +SL_RSI_CONVERT_DB_TO_POWERINDEX_TRIGGER, +SL_RSI_SET_RANDOM_TRIGGER, +SL_RSI_SET_RANDOM_ADDRESS_WITH_VALUE_TRIGGER, +SL_RSI_BLE_START_ADV_TRIGGER, +SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER, +SL_RSI_BLE_ENCRYPT_TRIGGER, +SL_RSI_BLE_STOP_ADV_TRIGGER, +SL_RSI_BLE_SET_ADV_DATA_TRIGGER, +SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER, +SL_RSI_BLE_START_SCANNING_TRIGGER, +SL_RSI_BLE_START_SCANNING_WITH_VALUES_TRIGGER, +SL_RSI_BLE_STOP_SCANNING_TRIGGER, +SL_RSI_BLE_CONNECT_WITH_PARAMS_TRIGGER, +SL_RSI_BLE_CONNECT_PARAMS_SCAN, +SL_RSI_BLE_CONNECT_PARAMS_CONNECT, +SL_RSI_BLE_CONNECT, +SL_RSI_BLE_CONNECT_CANCEL, +SL_RSI_BLE_DISCONNECT, +SL_RSI_BLE_GET_DEVICE_STATE, +SL_RSI_BLE_SET_SMP_PAIRING_CAP_DATA, +SL_RSI_BLE_SET_LOCAL_IRK_VALUE, +SL_RSI_BLE_CONN_PARAM_RESPONSE, +SL_RSI_BLE_SMP_PAIR_REQUEST, +SL_RSI_BLE_LTK_REQ_REPLY, +SL_RSI_BLE_SMP_PAIR_RESPONSE, +SL_RSI_BLE_SMP_PASSKEY, +SL_RSI_BLE_GET_LE_PING_TIMEOUT, +SL_RSI_BLE_SET_LE_PING_TIMEOUT, +SL_RSI_BLE_CLEAR_WHITELIST_TRIGGER, +SL_RSI_BLE_ADD_TO_WHITELIST, +SL_RSI_BLE_DELETEFROM_WHITELIST, +SL_RSI_BLE_RESOLVLIST, +SL_RSI_BLE_GET_RESOLVING_LIST_SIZE, +SL_RSI_BLE_SET_ADDR_RESOULTION_ENABLE, +SL_RSI_BLE_SET_PRIVACY_MODE, +SL_RSI_BLE_READPHY, +SL_RSI_SETPHY_TRIGGER, +SL_RSI_BLE_CONN_PARMS_UPDATE, +SL_RSI_BLE_SET_DATA_LEN, +SL_RSI_BLE_READ_MAX_DATA_LEN_TRIGGER, +SL_RSI_BLE_RX_TEST_MODE_TRIGGER, +SL_RSI_BLE_TX_TEST_MODE_TRIGGER, +SL_RSI_BLE_END_TEST_MODE_TRIGGER, +SL_RSI_BLE_INIT_PER_TRANSMIT_MODE_TRIGGER, +SL_RSI_BLE_PER_RECIEVE_TRIGGER, +SL_RSI_BLE_VENDOR_RF_TRIGGER, +SL_RSI_BLE_WHITELIST_USING_ADV_DATA, +SL_RSI_BLE_AD_PACKET_EXTRACT, +SL_RSI_BLE_UPDATE_DIRECTED_ADDRESS_TRIGGER, +SL_RSI_BLE_ENCRYPTION_TRIGGER, +SL_RSI_BLE_SET_BLE_TX_POWER, +SL_RSI_BT_SET_LOCAL_CLASS_OF_DEVICE_TRIGGER, +SL_RSI_BT_GET_LOCAL_CLASS_OF_DEVICE_TRIGGER, +SL_RSI_BT_DISCOVERY_MODE_TRIGGER, +SL_RSI_BT_LIMITED_DISCOVERY_MODE_TRIGGER, +SL_RSI_BLE_GET_PROFILES_HANDLE_ASYNC, +SL_RSI_BLE_GET_PROFILES_UUID_ASYNC, +SL_RSI_BLE_CHAR_SERVICES_ASYNC, +SL_RSI_BLE_GET_INC_SERVICES_ASYNC, +SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_ASYNC, +SL_RSI_BLE_GET_ATT_DESCRIPTORS_ASYNC, +SL_RSI_BLE_GET_ATT_VALUE_ASYNC, +SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC, +SL_RSI_BLE_GET_LONG_ATT_VALUE_ASYNC, +SL_RSI_BLE_SET_ATT_VALUE_ASYNC, +SL_RSI_BLE_PREPARE_WRITE_ASYNC, +SL_RSI_BLE_EXECUTE_WRITE_ASYNC, +SL_RSI_BLE_GET_PROFILES, +SL_RSI_BLE_GET_PROFILE, +SL_RSI_BLE_GET_CHAR_SERVICES, +SL_RSI_BLE_GET_INC_SERVICES, +SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID, +SL_RSI_BLE_GET_ATT_DESCRIPTORS, +SL_RSI_BLE_GET_ATT_VALUE, +SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES, +SL_RSI_BLE_GET_LONG_ATT_VALUE, +SL_RSI_BLE_SET_ATT_VALUE, +SL_RSI_BLE_SET_ATT_COMMAND, +SL_RSI_BLE_SET_LONG_ATT_VALUE, +SL_RSI_BLE_PREPARE_WRITE, +SL_RSI_BLE_EXECUTABLE_WRITE, +SL_RSI_BLE_ADD_SERVICE, +SL_RSI_BLE_ADD_ATTRIBUTE, +SL_RSI_BLE_SET_LOCAL_ATT_VALUE, +SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO, +SL_RSI_BLE_NOTIFY_VALUE_TRIGGER, +SL_RSI_BLE_INDICATE_VOLUME_TRIGGER, +SL_RSI_BLE_INDICATE_VALUE_SYNC, +SL_RSI_BLE_INDICATE_CONFIRM, +SL_RSI_BLE_GET_LOCAL_ATT_VALUE, +SL_RSI_BLE_GATT_READ_RESPONSE, +SL_RSI_BLE_REMOVE_GATT_SERVICE, +SL_RSI_BLE_REMOVE_GATT_ATTRIBUTE, +SL_RSI_BLE_ATT_ERROR_RESPONSE, +SL_RSI_BLE_MTU_EXCHANGE_EVENT, +SL_RSI_BLE_GATT_WRITE_RESPONSE, +SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE, +SL_RSI_BT_ADD_PAKCET_TO_LIST, +SL_RSI_BT_DELETE_PAKCET_FROM_LIST, +SL_RSI_BT_FREE_DATA_PACKET, +SL_RSI_BT_ALLOC_DATA_PACKET, +SL_RSI_BT_EVT_A2DP_DISCONNECT, +SL_RSI_APP_ERR_INVALID_INPUT, +SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW, +SL_RSI_INVALID_SBC_PACKET, +SL_RSI_BT_CMD_A2DP_PCM_MP3_DATA, +SL_RSI_BT_CMD_SBC_INIT_SUCCESS, +SL_RSI_BT_FREQUENCY_MISMATCH, +SL_RSI_BT_BLOCK_LENGTH_MISMATCH, +SL_RSI_BT_SUBBANDS_MISMATCH, +SL_RSI_BT_CHANNEL_MODE_MISMATCH, +SL_RSI_BT_ALLOCATION_METHOD_MISMATCH, +SL_RSI_SBC_ENCODE, +SL_WEB_SOCKET_CREATE_ENTRY, +SL_WEB_SOCKET_CREATE_SOCK_ERROR_1, +SL_WEB_SOCKET_CREATE_SOCK_ERROR_2, +SL_WEB_SOCKET_CREATE_EXIT_1, +SL_WEB_SOCKET_CREATE_SOCK_ERROR_3, +SL_WEB_SOCKET_CREATE_SOCK_ERROR_4, +SL_WEB_SOCKET_CREATE_SOCK_ERROR_5, +SL_WEB_SOCKET_CREATE_SOCK_ERROR_6, +SL_WEB_SOCKET_CREATE_EXIT_2, +SL_WEB_SOCKET_CREATE_EXIT9, +SL_WEB_SOCKET_SEND_ASYNC_ENTRY, +SL_WEB_SOCKET_SEND_ASYNC_EXIT, +SL_WEB_SOCKET_CLOSE_ENTRY, +SL_WEB_SOCKET_CLOSE_EXIT, +SL_MQTT_CLIENT_INIT_ENTRY, +SL_MQTT_CLIENT_INIT_COMMAND_ERROR, +SL_MQTT_CLIENT_INIT_INSUFFICIENT_BUFFER_LENGTH, +SL_MQTT_CLIENT_INIT_EXIT, +SL_MQTT_CLIENT_CONNECT_ENTRY, +SL_MQTT_CLIENT_CONNECT_INVALID_PARAM, +SL_MQTT_CLIENT_CONNECT_EXIT_1, +SL_MQTT_CLIENT_CONNECT_EXIT_2, +SL_MQTT_CLIENT_DISCONNECT_ENTRY, +SL_MQTT_CLIENT_DISCONNECT_INVALID_PARAM, +SL_MQTT_CLIENT_DISCONNECT_EXIT, +SL_MQTT_PUBLISH_ENTRY, +SL_MQTT_PUBLISH_INVALID_PARAM, +SL_MQTT_PUBLISH_EXIT, +SL_MQTT_SUBSCRIBE_ENTRY, +SL_MQTT_SUBSCRIBE_INVALID_PARAM_1, +SL_MQTT_SUBSCRIBE_INVALID_PARAM_2, +SL_MQTT_SUBSCRIBE_EXIT, +SL_MQTT_UNSUBSCRIBE_ENTRY, +SL_MQTT_SUBSCRIBE_INVALID_PARAM, +SL_MQTT_UNSUBSCRIBE_EXIT, +SL_MQTT_POLL_FOR_RECV_DATA_INVALID_PARAM, +SL_MQTT_POLL_FOR_RECV_DATA_EXIT, +SL_HTTP_CLIENT_ASYNC_ENTRY, +SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_HTTP_CLIENT_ASYNC_NVALID_PARAM, +SL_HTTP_CLIENT_ASYNC_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_ASYNC_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_ASYNC_EXIT, +SL_HTTP_CLIENT_ABORT_ENTRY, +SL_HTTP_CLIENT_ABORT_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_ABORT_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_ABORT_ERROR_IN_SENDING_COMMAND, +SL_HTTP_CLIENT_PUT_CREATE_ENTRY, +SL_HTTP_CLIENT_PUT_CREATE_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_PUT_CREATE_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_PUT_CREATE_EXIT, +SL_HTTP_CLIENT_PUT_DELETE_ENTRY, +SL_HTTP_CLIENT_PUT_DELETE_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_PUT_DELETE_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_PUT_DELETE_EXIT, +SL_HTTP_CLIENT_PUT_START_ENTRY, +SL_HTTP_CLIENT_PUT_START_INVALID_PARAM, +SL_HTTP_CLIENT_PUT_START_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_PUT_START_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_PUT_START_EXIT, +SL_HTTP_CLIENT_PUT_PKT_ENTRY, +SL_HTTP_CLIENT_PUT_PKT_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_PUT_PKT_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_PUT_PKT_EXIT, +SL_HTTP_CLIENT_POST_DATA_ENTRY, +SL_HTTP_CLIENT_POST_DATA_INVALID_PARAM, +SL_HTTP_CLIENT_POST_DATA_PKT_ALLOCATION_FAILURE, +SL_HTTP_CLIENT_POST_DATA_NWK_COMMAND_ERROR, +SL_HTTP_CLIENT_POST_DATA_EXIT, +SL_MULTICAST_ENTRY, +SL_MULTICAST_PKT_ALLOCATION_FAILURE, +SL_MULTICAST_NWK_COMMAND_ERROR, +SL_MULTICAST_EXIT, +SL_MULTICAST_JOIN_ENTRY, +SL_MULTICAST_JOIN_EXIT, +SL_MULTICAST_LEAVE_ENTRY, +SL_MULTICAST_LEAVE_EXIT, +SL_HTTP_OTAF_ASYNC_ENTRY, +SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_HTTP_OTAF_ASYNC_INVALID_PARAM, +SL_HTTP_OTAF_ASYNC_PKT_ALLOCATION_FAILURE, +SL_HTTP_OTAF_ASYNC_NWK_CMD_IN_PROGRESS, +SL_HTTP_OTAF_ASYNC_EXIT, +SL_DNS_REQ_ENTRY, +SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_DNS_REQ_INVALID_PARAM_1, +SL_DNS_REQ_INVALID_PARAM_2, +SL_DNS_REQ_PKT_ALLOCATION_FAILURE_1, +SL_DNS_REQ_EXIT_1, +SL_DNS_REQ_PKT_ALLOCATION_FAILURE_2, +SL_DNS_REQ_EXIT_COMMAND_ERROR, +SL_DNS_REQ_EXIT_2, +SL_DNS_UPDATE_ENTRY, +SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_DNS_UPDATE_INVALID_PARAM_1, +SL_DNS_UPDATE_INVALID_PARAM_2, +SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_1, +SL_DNS_UPDATE_EXIT_1, +SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_2, +SL_DNS_UPDATE_COMMAND_ERROR, +SL_DNS_UPDATE_EXIT_2, +SL_DHCP_USER_CLASS_ENTRY, +SL_DHCP_USER_CLASS_COMMAND_GIVEN_IN_WRONG_STATE, +SL_DHCP_USER_CLASS_INVALID_PARAM, +SL_DHCP_USER_CLASS_PKT_ALLOCATION_FAILURE, +SL_DHCP_USER_CLASS_COMMAND_ERROR, +SL_DHCP_USER_CLASS_EXIT, +SL_SNTP_CLIENT_CREATE_ASYNC_ENTRY, +SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SNTP_CLIENT_CREATE_ASYNC_INVALID_PARAM, +SL_SNTP_CLIENT_CREATE_ASYNC_PKT_ALLOCATION_FAILURE, +SL_SNTP_CLIENT_CREATE_ASYNC_NWK_COMMAND_ERROR, +SL_SNTP_CLIENT_CREATE_ASYNC_EXIT, +SL_SNTP_CLIENT_GETTIME_ENTRY, +SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SNTP_CLIENT_GETTIME_PKT_ALLOCATION_FAILURE, +SL_SNTP_CLIENT_GETTIME_NWK_COMMAND_ERROR, +SL_SNTP_CLIENT_GETTIME_EXIT, +SL_SNTP_CLIENT_GETTIME_DATE_ENTRY, +SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SNTP_CLIENT_GETTIME_DATE_PKT_ALLOCATION_FAILURE, +SL_SNTP_CLIENT_GETTIME_DATE_NWK_COMMAND_ERROR, +SL_SNTP_CLIENT_GETTIME_DATE_EXIT, +SL_SNTP_CLIENT_SERVER_INFO_ENTRY, +SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SNTP_CLIENT_SERVER_INFO_PKT_ALLOCATION_FAILURE, +SL_SNTP_CLIENT_SERVER_INFO_NWK_COMMAND_ERROR, +SL_SNTP_CLIENT_SERVER_INFO_EXIT, +SL_SNTP_CLIENT_DELETE_ASYNC_ENTRY, +SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SNTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE, +SL_SNTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR, +SL_SNTP_CLIENT_DELETE_ASYNC_EXIT, +SL_EMB_MQTT_CLIENT_INIT_ENTRY, +SL_EMB_MQTT_CLIENT_INIT_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_CLIENT_INIT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_CLIENT_INIT_INVALID_PARAM, +SL_EMB_MQTT_CLIENT_INIT_PARAMTER_LENGTH_EXCEEDS_MAX_VAL, +SL_EMB_MQTT_CLIENT_INIT_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_CLIENT_INIT_COMMAND_ERROR, +SL_EMB_MQTT_CLIENT_INIT_EXIT, +SL_EMB_MQTT_CONNECT_ENTRY, +SL_EMB_MQTT_CONNECT_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_CONNECT_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_CONNECT_COMMAND_ERROR, +SL_EMB_MQTT_CONNECT_EXIT, +SL_EMB_MQTT_PUBLISH_ENTRY, +SL_EMB_MQTT_PUBLISH_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_PUBLISH_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_PUBLISH_INVALID_PARAM, +SL_EMB_MQTT_PUBLISH_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_1, +SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_2, +SL_EMB_MQTT_PUBLISH_NWK_COMMAND_ERROR, +SL_EMB_MQTT_PUBLISH_COMMAND_SEND_ERROR, +SL_EMB_MQTT_SUBSCRIBE_ENTRY, +SL_EMB_MQTT_SUBSCRIBE_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_SUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_SUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL, +SL_EMB_MQTT_SUBSCRIBE_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_SUBSCRIBE_NWK_COMMAND_ERROR, +SL_EMB_MQTT_SUBSCRIBE_COMMAND_SEND_ERROR, +SL_EMB_MQTT_UNSUBSCRIBE_ENTRY, +SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_UNSUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL, +SL_EMB_MQTT_UNSUBSCRIBE_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_UNSUBSCRIBE_NWK_COMMAND_ERROR, +SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_SEND_ERROR, +SL_EMB_MQTT_DISCONNECT_ENTRY, +SL_EMB_MQTT_DISCONNECT_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_DISCONNECT_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_DISCONNECT_NWK_COMMAND_ERROR, +SL_EMB_MQTT_DISCONNECT_COMMAND_SEND_ERROR, +SL_EMB_MQTT_DESTROY_ENTRY, +SL_EMB_MQTT_DESTROY_COMMAND_NOT_SUPPORTED, +SL_EMB_MQTT_DESTROY_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EMB_MQTT_DESTROY_PKT_ALLOCATION_FAILURE, +SL_EMB_MQTT_DESTROY_NWK_COMMAND_ERROR, +SL_EMB_MQTT_DESTROY_COMMAND_SEN_ERROR, +SL_EMB_MQTT_REGISTER_CALL_BACK_ENTRY, +SL_EMB_MQTT_REGISTER_CALL_BACK_EXCEEDS_MAX_CALLBACKS, +SL_EMB_MQTT_REGISTER_CALL_BACK_INVALID_PARAM, +SL_EMB_MQTT_REGISTER_CALL_BACK_EXIT, +SL_CAL_MQTT_PACKET_LEN_ENTRY, +SL_CAL_MQTT_PACKET_LEN_EXIT, +SL_FWUP_ENTRY, +SL_FWUP_INVALID_PARAM, +SL_FWUP_PKT_ALLOCATION_FAILURE, +SL_FWUP_COMMAND_ERROR, +SL_FWUP_EXIT, +SL_FWUP_START_ENTRY, +SL_FWUP_START_EXIT, +SL_FWUP_LOAD_ENTRY, +SL_FWUP_LOAD_EXIT, +SL_SEND_RAW_DATA_ENTRY, +SL_SEND_RAW_DATA_INVALID_PARAM, +SL_SEND_RAW_DATA_PKT_ALLOCATION_FAILURE, +SL_SEND_RAW_DATA_EXIT, +SL_FTP_CONNECT_ENTRY, +SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_1, +SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_1, +SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_2, +SL_FTP_CONNECT_NWK_COMMAND_ERROR, +SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_2, +SL_FTP_DISCONNECT_ENTRY, +SL_FTP_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_1, +SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_1, +SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_2, +SL_FTP_DISCONNECT_NWK_COMMAND_ERROR, +SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_2, +SL_FTP_FILE_WRITE_ENTRY, +SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_FILE_WRITE_PKT_ALLOCATION_FAILURE, +SL_FTP_FILE_WRITE_NWK_COMMAND_ERROR, +SL_FTP_FILE_WRITE_ERROR_IN_SENDING_COMMAND, +SL_FTP_FILE_WRITE_CONTENT_ENTRY, +SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_FILE_WRITE_CONTENT_PKT_ALLOCATION_FAILURE, +SL_FTP_FILE_WRITE_CONTENT_NWK_COMMAND_ERROR, +SL_FTP_FILE_WRITE_CONTENT_ERROR_IN_SENDING_COMMAND, +SL_FTP_FILE_READ_ASYNC_ENTRY, +SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_FILE_READ_ASYNC_INVALID_PARAM, +SL_FTP_FILE_READ_ASYNC_PKT_ALLOCATION_FAILURE, +SL_FTP_FILE_READ_ASYNC_NWK_COMMAND_ERROR, +SL_FTP_FILE_READ_ASYNC_ERROR_IN_SENDING_COMMAND, +SL_FTP_FILE_DELETE_ENTRY, +SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_FILE_DELETE_PKT_ALLOCATION_FAILURE, +SL_FTP_FILE_DELETE_NWK_COMMAND_ERROR, +SL_FTP_FILE_DELETE_ERROR_IN_SENDING_COMMAND, +SL_FTP_FILE_RENAME_ENTRY, +SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_FILE_RENAME_PKT_ALLOCATION_FAILURE, +SL_FTP_FILE_RENAME_NWK_COMMAND_ERROR, +SL_FTP_FILE_RENAME_ERROR_IN_SENDING_COMMAND, +SL_FTP_DIRECTORY_CREATE_ENTRY, +SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_DIRECTORY_CREATE_PKT_ALLOCATION_FAILURE, +SL_FTP_DIRECTORY_CREATE_NWK_COMMAND_ERROR, +SL_FTP_DIRECTORY_CREATE_ERROR_IN_SENDING_COMMAND, +SL_FTP_DIRECTORY_DELETE_ENTRY, +SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_DIRECTORY_DELETE_PKT_ALLOCATION_FAILURE, +SL_FTP_DIRECTORY_DELETE_NWK_COMMAND_ERROR, +SL_FTP_DIRECTORY_DELETE_ERROR_IN_SENDING_COMMAND, +SL_FTP_DIRECTORY_SET_ENTRY, +SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_DIRECTORY_SET_PKT_ALLOCATION_FAILURE, +SL_FTP_DIRECTORY_SET_NWK_COMMAND_ERROR, +SL_FTP_DIRECTORY_SET_ERROR_IN_SENDING_COMMAND, +SL_FTP_DIRECTORY_LIST_ASYNC_ENTRY, +SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_DIRECTORY_LIST_ASYNC_INVALID_PARAM, +SL_FTP_DIRECTORY_LIST_ASYNC_PKT_ALLOCATION_FAILURE, +SL_FTP_DIRECTORY_LIST_ASYNC_NWK_COMMAND_ERROR, +SL_FTP_DIRECTORY_LIST_ASYNC_ERROR_IN_SENDING_COMMAND, +SL_FTP_MODE_SET_ENTRY, +SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_MODE_SET_PKT_ALLOCATION_FAILURE, +SL_FTP_MODE_SET_NWK_COMMAND_ERROR, +SL_FTP_MODE_SET_ERROR_IN_SENDING_COMMAND, +SL_FTP_FILE_SIZE_SET_ENTRY, +SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_FTP_FILE_SIZE_SET_PKT_ALLOCATION_FAILURE, +SL_FTP_FILE_SIZE_SET_NWK_COMMAND_ERROR, +SL_FTP_FILE_SIZE_SET_ERROR_IN_SENDING_COMMAND, +SL_SMTP_CLIENT_CREATE_ENTRY, +SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SMTP_CLIENT_CREATE_INVALID_PARAM, +SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_1, +SL_SMTP_CLIENT_CREATE_EXIT_1, +SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_2, +SL_SMTP_CLIENT_CREATE_NWK_COMMAND_ERROR, +SL_SMTP_CLIENT_CREATE_EXIT_2, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_ENTRY, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_1, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_2, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_PKT_ALLOCATION_FAILURE, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_NWK_COMMAND_ERROR, +SL_SMTP_CLIENT_MAIL_SEND_ASYNC_EXIT, +SL_SMTP_CLIENT_DELETE_ASYNC_ENTRY, +SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, +SL_SMTP_CLIENT_DELETE_ASYNC_INVALID_PARAM, +SL_SMTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE, +SL_SMTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR, +SL_SMTP_CLIENT_DELETE_ASYNC_EXIT, +SL_MSNSD_INIT_ENTRY, +SL_MSNSD_INIT_INSUFFICIENT_BUFFER, +SL_MSNSD_INIT_PKT_ALLOCATION_FAILURE, +SL_MSNSD_INIT_NWK_COMMAND_ERROR, +SL_MSNSD_INIT_EXIT, +SL_MSNSD_REGISTER_SERVICE_ENTRY, +SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER, +SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE, +SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR, +SL_MSNSD_REGISTER_SERVICE_EXIT, +SL_MSNSD_DEINIT_ENTRY, +SL_MSNSD_DEINIT_PKT_ALLOCATION_FAILURE, +SL_HTTP_WEBPAGE_LOAD_ENTRY, +SL_HTTP_WEBPAGE_LOAD_PKT_ALLOCATION_FAILURE, +SL_HTTP_WEBPAGE_LOAD_NWK_COMMAND_ERROR, +SL_HTTP_WEBPAGE_LOAD_EXIT, +SL_HTTP_WEBPAGE_ERASE_ENTRY, +SL_HTTP_WEBPAGE_ERASE_PKT_ALLOCATION_FAILURE, +SL_HTTP_WEBPAGE_ERASE_NWK_COMMAND_ERROR, +SL_HTTP_WEBPAGE_ERASE_EXIT, +SL_HTTP_JSON_OBJECT_DELETE_ENTRY, +SL_HTTP_JSON_OBJECT_DELETE_PKT_ALLOCATION_FAILURE, +SL_HTTP_JSON_OBJECT_DELETE_NWK_COMMAND_ERROR, +SL_HTTP_JSON_OBJECT_DELETE_EXIT, +SL_HTTP_WEBPAGE_SEND_ENTRY, +SL_HTTP_WEBPAGE_SEND_COMMAND_GIVEN_IN_WRONG_STATE, +SL_HTTP_WEBPAGE_SEND_PKT_ALLOCATION_FAILURE, +SL_HTTP_WEBPAGE_SEND_NWK_COMMAND_ERROR, +SL_HTTP_WEBPAGE_SEND_EXIT, +SL_REQ_WIRELESS_FWUP_ENTER, +SL_REQ_WIRELESS_FWUP_EERROR_PKT_ALLOCATION_FAILURE, +SL_REQ_WIRELESS_FWUP_NWK_COMMAND_ERROR, +SL_REQ_WIRELESS_FWUP_EXIT, +SL_HTTP_CREDENTIALS_ENTRY, +SL_HTTP_CREDENTIALS_COMMAND_GIVEN_IN_WRONG_STATE, +SL_HTTP_CREDENTIALS_PKT_ALLOCATION_FAILURE, +SL_HTTP_CREDENTIALS_NWK_COMMAND_ERROR, +SL_HTTP_CREDENTIALS_EXIT, +SL_FD_ISSET_ENTRY, +SL_SET_FD_ENTRY, +SL_FD_CLR_ENTRY, +SL_SOCKET_ASYNC_ENTRY, +SL_SOCKET_ENTRY, +SL_SOCKET_EXIT, +SL_BIND_ENTRY, +SL_CONNECT_ENTRY, +SL_LISTEN_ENTRY, +SL_ACCEPT_NON_ROM_ENTRY, +SL_ACCEPT_NON_ROM_SOCK_ERROR_1, +SL_ACCEPT_NON_ROM_SOCK_ERROR_2, +SL_ACCEPT_NON_ROM_SOCK_ERROR_3, +SL_ACCEPT_NON_ROM_SOCK_ERROR_4, +SL_ACCEPT_NON_ROM_EXIT5, +SL_ACCEPT_NON_ROM_SOCK_ERROR_6, +SL_ACCEPT_NON_ROM_SOCK_ERROR_7, +SL_ACCEPT_NON_ROM_SOCK_ERROR_8, +SL_ACCEPT_NON_ROM_SOCK_ERROR_9, +SL_ACCEPT_NON_ROM_SOCK_ERROR_10, +SL_ACCEPT_NON_ROM_SOCK_ERROR_11, +SL_ACCEPT_NON_ROM_EXIT, +SL_ACCEPT_ENTRY, +SL_RECV_LARGE_DATA_SYNC_ENTRY, +SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_1, +SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_2, +SL_RECV_LARGE_DATA_SYNC_EXIT, +SL_RECV_FROM_ENTRY, +SL_RECV_FROM_EXIT_1, +SL_RECV_FROM_EXIT_2, +SL_RECV_FROM_EXIT_3, +SL_RECV_ENTRY, +SL_RECV_EXIT_1, +SL_RECV_EXIT_2, +SL_RECV_EXIT_3, +SL_SENDTO_ENTRY, +SL_SENDTO_ASYNC_NON_ROM_ENTRY, +SL_SEND_ENTRY, +SL_SEND_EXIT_1, +SL_SEND_EXIT_2, +SL_RESET_PER_SOCKET_INFO_ENTRY, +SL_SEND_LARGE_DATA_SYNC_ENTRY, +SL_SEND_LARGE_DATA_SYNC_SOCK_ERROR_1, +SL_SEND_LARGE_DATA_SYNC_EXIT, +SL_CHUNK_DATA_TX_DONE_CB_ENTRY, +SL_SEND_LARGE_DATA_ASYNC_ENTRY, +SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_1, +SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_2, +SL_SEND_LARGE_DATA_ASYNC_EXIT_1, +SL_SEND_LARGE_DATA_ASYNC_EXIT_2, +SL_FIND_SOCKET_DATA_PENDING_ENTRY, +SL_FIND_SOCKET_DATA_PENDING_EXIT, +SL_SOCKET_EVENT_HANDLER_ENTRY, +SL_SEND_ASYNC_ENTRY, +SL_GET_APPLICATON_SOCKET_DESCRIPTOR_ENTRY, +SL_CLEAR_SOCKETS_ENTRY, +SL_FILL_TLS_EXTENSION_ENTRY, +SL_FILL_TLS_EXTENSION_INSUFFICIENT_BUFFER, +SL_FILL_TLS_EXTENSION_EXIT, +SL_SETSOCKOPT_ENTRY, +SL_SETSOCKOPT_SOCK_ERROR_1, +SL_SETSOCKOPT_SOCK_ERROR_2, +SL_SETSOCKOPT_SOCK_ERROR_3, +SL_SETSOCKOPT_EXIT_1, +SL_SETSOCKOPT_EXIT_2, +SL_SETSOCKOPT_EXIT_3, +SL_SETSOCKOPT_EXIT_4, +SL_SETSOCKOPT_EXIT_5, +SL_SETSOCKOPT_EXIT_6, +SL_SETSOCKOPT_EXIT_7, +SL_SETSOCKOPT_EXIT_8, +SL_SETSOCKOPT_EXIT_9, +SL_SETSOCKOPT_EXIT_10, +SL_SETSOCKOPT_EXIT_11, +SL_SETSOCKOPT_EXIT_12, +SL_SETSOCKOPT_EXIT_13, +SL_SETSOCKOPT_EXIT_14, +SL_SETSOCKOPT_EXIT_15, +SL_SETSOCKOPT_EXIT_16, +SL_SETSOCKOPT_EXIT_17, +SL_SETSOCKOPT_EXIT_18, +SL_SETSOCKOPT_EXIT_19, +SL_SETSOCKOPT_SOCK_ERROR_6, +SL_SETSOCKOPT_EXIT_20, +SL_SETSOCKOPT_SOCK_ERROR_4, +SL_SETSOCKOPT_SOCK_ERROR_5, +SL_SETSOCKOPT_EXIT21, +SL_GETSOCKOPT_EXIT1, +SL_GETSOCKOPT_SOCK_ERROR_1, +SL_GETSOCKOPT_SOCK_ERROR_2, +SL_GETSOCKOPT_SOCK_ERROR_3, +SL_GETSOCKOPT_SOCK_ERROR_4, +SL_GETSOCKOPT_EXIT, +SL_SELECT_ENTRY, +SL_SELECT_SOCK_ERROR_1, +SL_SELECT_SOCK_ERROR_2, +SL_SELECT_SOCK_ERROR_3, +SL_SELECT_SOCK_ERROR_4, +SL_SELECT_SOCK_ERROR_5, +SL_SELECT_SOCK_ERROR_6, +SL_SELECT_SOCK_ERROR_7, +SL_SELECT_SOCK_ERROR_8, +SL_SELECT_SOCK_ERROR_9, +SL_SELECT_SOCK_ERROR_10, +SL_SELECT_SOCK_ERROR_11, +SL_ACCEPT_ASYNC_ENTRY, +SL_ACCEPT_ASYNC_SOCK_ERROR_1, +SL_ACCEPT_ASYNC_SOCK_ERROR_2, +SL_ACCEPT_ASYNC_SOCK_ERROR_3, +SL_ACCEPT_ASYNC_SOCK_ERROR_4, +SL_ACCEPT_ASYNC_SOCK_ERROR_5, +SL_ACCEPT_ASYNC_SOCK_ERROR_6, +SL_ACCEPT_ASYNC_SOCK_ERROR_7, +SL_ACCEPT_ASYNC_SOCK_ERROR_8, +SL_ACCEPT_ASYNC_SOCK_ERROR_9, +SL_ACCEPT_ASYNC_SOCK_ERROR_10, +SL_ACCEPT_ASYNC_EXIT, +SL_GET_APP_SOCKET_DESCRIPTOR_ENTRY, +SL_GET_APP_SOCKET_DESCRIPTOR_SOCK_ERROR_1, +SL_GET_APP_SOCKET_DESCRIPTOR_EXIT, +SL_GET_SOCKET_ID_ENTRY, +SL_GET_SOCKET_ID_SOCK_ERROR_1, +SL_GET_SOCKET_ID_EXIT, +SL_GET_PRIMARY_SOCKET_ID_ENTRY, +SL_GET_PRIMARY_SOCKET_ID_SOCK_ERROR_1, +SL_GET_PRIMARY_SOCKET_ID_EXIT, +SL_CERTIFICATE_VALID_ENTRY, +SL_CERTIFICATE_VALID_SOCK_ERROR_1, +SL_CERTIFICATE_VALID_SOCK_ERROR_2, +SL_CERTIFICATE_VALID_SOCK_ERROR_3, +SL_CERTIFICATE_VALID_EXIT, +SL_SOCKET_CREATE_ASYNC_ENTRY, +SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_1, +SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_2, +SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_3, +SL_SOCKET_CREATE_ASYNC_EXIT, +SL_TCP_WINDOW_UPDATE_ENTRY, +SL_TCP_WINDOW_UPDATE_SOCK_ERROR_1, +SL_TCP_WINDOW_UPDATE_SOCK_ERROR_2, +SL_TCP_WINDOW_UPDATE_SOCK_ERROR_3, +SL_TCP_WINDOW_UPDATE_SOCK_ERROR_4, +SL_TCP_WINDOW_UPDATE_SOCK_ERROR_5, +SL_TCP_WINDOW_UPDATE_SOCK_ERROR_6, +SL_TCP_WINDOW_UPDATE_EXIT, +SL_GET_SOCKET_DESCRIPTOR_ENTRY, +SL_GET_SOCKET_DESCRIPTOR_SOCK_ERROR, +SL_GET_SOCKET_DESCRIPTOR_EXIT, +SL_SOCKET_ASYNC_NONO_ROM_ENTRY, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_1, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_2, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3, +SL_SOCKET_ASYNC_NONO_ROM_EXIT4, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_6, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_7, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_8, +SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_9, +SL_SOCKET_ASYNC_NONO_ROM_EXIT, +SL_SOCKET_CONNECT_ENTRY, +SL_SOCKET_CONNECT_SOCK_ERROR_1, +SL_SOCKET_CONNECT_SOCK_ERROR_2, +SL_SOCKET_CONNECT_SOCK_ERROR_3, +SL_SOCKET_CONNECT_SOCK_ERROR_4, +SL_SOCKET_CONNECT_SOCK_ERROR_5, +SL_SOCKET_CONNECT_SOCK_ERROR_6, +SL_SOCKET_CONNECT_SOCK_ERROR_7, +SL_SOCKET_CONNECT_EXIT, +SL_SOCKET_RECVFROM_ENTRY, +SL_SOCKET_RECVFROM_SOCK_ERROR_1, +SL_SOCKET_RECVFROM_SOCK_ERROR_2, +SL_SOCKET_RECVFROM_SOCK_ERROR_3, +SL_SOCKET_RECVFROM_SOCK_ERROR_4, +SL_SOCKET_RECVFROM_EXIT_1, +SL_SOCKET_RECVFROM_SOCK_ERROR_6, +SL_SOCKET_RECVFROM_SOCK_ERROR_7, +SL_SOCKET_RECVFROM_EXIT_2, +SL_SOCKET_LISTEN_ENTRY, +SL_SOCKET_LISTEN_SOCK_ERROR_1, +SL_SOCKET_LISTEN_SOCK_ERROR_2, +SL_SOCKET_LISTEN_SOCK_ERROR_3, +SL_SOCKET_LISTEN_SOCK_ERROR_4, +SL_SOCKET_LISTEN_SOCK_ERROR_5, +SL_SOCKET_LISTEN_EXIT, +SL_SOCKET_SHUTDOWN_ENTRY, +SL_SOCKET_SHUTDOWN_SOCK_ERROR_1, +SL_SOCKET_SHUTDOWN_SOCK_ERROR_2, +SL_SOCKET_SHUTDOWN_EXIT_1, +SL_SOCKET_SHUTDOWN_SOCK_ERROR_3, +SL_SOCKET_SHUTDOWN_EXIT_2, +SL_SOCKET_SHUTDOWN_SOCK_ERROR_4, +SL_SOCKET_SHUTDOWN_SOCK_ERROR_5, +SL_SOCKET_SHUTDOWN_SOCK_ERROR_6, +SL_SOCKET_SHUTDOWN_EXIT_3, +SL_SOCKET_BIND_ENTRY, +SL_SOCKET_BIND_SOCK_ERROR_1, +SL_SOCKET_BIND_SOCK_ERROR_2, +SL_SOCKET_BIND_SOCK_ERROR_3, +SL_SOCKET_BIND_SOCK_ERROR_4, +SL_SOCKET_BIND_SOCK_ERROR_5, +SL_SOCKET_BIND_SOCK_ERROR_6, +SL_SOCKET_BIND_SOCK_ERROR_7, +SL_SOCKET_BIND_SOCK_ERROR_8, +SL_SOCKET_BIND_SOCK_ERROR_9, +SL_SOCKET_BIND_EXIT, +SL_WAIT_ON_SOCKET_SEMAPHORE_ENTRY, +SL_WAIT_ON_SOCKET_SEMAPHORE_RESPONSE_TIMEOUT, +SL_WAIT_ON_SOCKET_SEMAPHORE_ERROR_NONE, +SL_APPLICATION_SOCKET_DESCRIPTOR_ENTRY, +SL_APPLICATION_SOCKET_DESCRIPTOR_SOCK_ERROR_1, +SL_APPLICATION_SOCKET_DESCRIPTOR_EXIT, +SL_WLAN_SOCKET_GET_STATUS_ENTRY, +SL_WLAN_SOCKET_SET_STATUS_ENTRY, +SL_SELECT_GET_STATUS_ENTRY, +SL_SELECT_SET_STATUS_ENTRY, +SL_SEND_ASYNC_NON_ROM_ENTRY, +SL_SEND_ASYNC_NON_ROM_SOCK_ERROR, +SL_SEND_ASYNC_NON_ROM_EXIT, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_1, +SL_SENDTO_ASYNC_NON_ROM_ERROR_EBADF, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_2, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_3, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_4, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_5, +SL_SENDTO_ASYNC_NON_ROM_EXIT_1, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_6, +SL_SENDTO_ASYNC_NON_ROM_EXIT_2, +SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_7, +SL_CLEAR_SOCKET_NON_ROM_ENTRY, +SL_DRIVER_INIT_MAX_SOCKETS_ERROR, +SL_DRIVER_INIT_INSUFFICIENT_BUFFER_2, +SL_DRIVER_INIT_UART_INIT_ERROR, +SL_DRIVER_INIT_EXIT, +SL_WIRELESS_INIT_ENTRY, +SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WIRELESS_INIT_CARD_READY_TIMEOUT, +SL_WIRELESS_INIT_RESPONSE_TIMEOUT, +SL_WIRELESS_INIT_EXIT1, +SL_WIRELESS_INIT_EXIT2, +SL_WIRELESS_INIT_PKT_ALLOCATION_FAILURE, +SL_WIRELESS_INIT_COMMAND_ERROR, +SL_WIRELESS_INIT_EXIT3, +SL_CMD_UART_FLOW_CTRL_ENTRY, +SL_CMD_UART_FLOW_CTRL_PKT_ALLOCATION_FAILURE, +SL_CMD_UART_FLOW_CTRL_COMMAND_ERROR, +SL_CMD_UART_FLOW_CTRL_EXIT, +SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY, +SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE, +SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR, +SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT, +SL_WIRELESS_DEINIT_ENTRY, +SL_WIRELESS_DEINIT_PKT_ALLOCATION_FAILURE, +SL_WIRELESS_DEINIT_COMMAND_ERROR, +SL_WIRELESS_DEINIT_DRIVER_INIT_ERROR_1, +SL_WIRELESS_DEINIT_DEVICE_INIT_ERROR_2, +SL_WIRELESS_DEINIT_EXIT, +SL_WIRELESS_ANTENNA_ENTRY, +SL_WIRELESS_ANTENNA_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WIRELESS_ANTENNA_PKT_ALLOCATION_FAILURE, +SL_WIRELESS_ANTENNA_COMMAND_ERROR, +SL_WIRELESS_ANTENNA_EXIT, +SL_SEND_FEATURE_FRAME_ENTRY, +SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE, +SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE, +SL_SEND_FEATURE_FRAME_COMMAND_ERROR, +SL_SEND_FEATURE_FRAME_EXIT, +SL_GET_FW_VERSION_ENTRY, +SL_GET_FW_VERSION_PKT_ALLOCATION_FAILURE, +SL_GET_FW_VERSION_COMMAND_ERROR, +SL_GET_FW_VERSION_EXIT, +SL_COMMON_DEBUG_LOG_ENTRY, +SL_COMMON_DEBUG_LOG_COMMAND_GIVEN_IN_WRONG_STATE, +SL_COMMON_DEBUG_LOG_INVALID_PARAM, +SL_COMMON_DEBUG_LOG_PKT_ALLOCATION_FAILURE, +SL_COMMON_DEBUG_LOG_COMMAND_ERROR, +SL_COMMON_DEBUG_LOG_EXIT, +SL_SWITCH_PROTO_ENTRY, +SL_SWITCH_PROTO_INVALID_PARAM, +SL_SWITCH_PROTO_COMMAND_GIVEN_IN_WRONG_STATE, +SL_SWITCH_PROTO_PKT_ALLOCATION_FAILURE, +SL_SWITCH_PROTO_COMMAND_ERROR, +SL_SWITCH_PROTO_EXIT, +SL_WIRELESS_DRIVER_TASK_ENTRY, +SL_WIRELESS_DRIVER_TASK_EXIT, +SL_DRIVER_DEINIT_ENTRY, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_1, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_2, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_3, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_4, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_5, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_6, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_7, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_8, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_9, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_10, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_11, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_12, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_13, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_14, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_15, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_16, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_17, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_18, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_19, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_20, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_21, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_22, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_23, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_24, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_25, +SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_26, +SL_DRIVER_DEINIT_TASK_DESTROY_ENTRY, +SL_DRIVER_DEINIT_TASK_DESTROY_EXIT, +SL_DRIVER_VERSION_ENTRY, +SL_DRIVER_VERSION_EXIT, +SL_SET_RTC_TIMER_ENTRY, +SL_SET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE, +SL_SET_RTC_TIMER_PKT_ALLOCATION_FAILURE, +SL_SET_RTC_TIMER_COMMAND_ERROR, +SL_SET_RTC_TIMER_EXIT, +SL_GET_RAM_LOG_ENTRY, +SL_GET_RAM_LOG_EXIT1, +SL_GET_RAM_LOG_PKT_ALLOCATION_FAILURE, +SL_GET_RAM_LOG_COMMAND_ERROR, +SL_GET_RAM_LOG_EXIT, +SL_UNREGISTER_EVENTS_CALLBACK_ENTRY, +SL_UNREGISTER_EVENTS_CALLBACK_EXIT, +SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_ENTRY, +SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_EXIT, +SL_GET_RTC_TIMER_ENTRY, +SL_GET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE, +SL_GET_RTC_TIMER_PKT_ALLOCATION_FAILURE, +SL_GET_RTC_TIMER_COMMAND_ERROR, +SL_GET_RTC_TIMER_EXIT, +SL_ASSERT_ENTRY, +SL_ASSERT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_ASSERT_PKT_ALLOCATION_FAILURE, +SL_ASSERT_COMMAND_ERROR, +SL_ASSERT_EXIT, +SL_GPIO_PININIT_ENTRY, +SL_GPIO_PININIT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_GPIO_PININIT_PKT_ALLOCATION_FAILURE, +SL_GPIO_PININIT_COMMAND_ERROR, +SL_GPIO_PININIT_EXIT, +SL_GPIO_WRITEPIN_ENTRY, +SL_GPIO_WRITEPIN_COMMAND_GIVEN_IN_WRONG_STATE, +SL_GPIO_WRITEPIN_PKT_ALLOCATION_FAILURE, +SL_GPIO_WRITEPIN_COMMAND_ERROR, +SL_GPIO_WRITEPIN_EXIT, +SL_GPIO_READPIN_ENTRY, +SL_GPIO_READPIN_COMMAND_GIVEN_IN_WRONG_STATE, +SL_GPIO_READPIN_PKT_ALLOCATION_FAILURE, +SL_GPIO_READPIN_COMMAND_ERROR, +SL_GPIO_READPIN_EXIT, +SL_DEVICE_INIT_ENTRY, +SL_DEVICE_INIT_EXIT_1, +SL_DEVICE_INIT_EXIT_2, +SL_DEVICE_INIT_EXIT_3, +SL_DEVICE_INIT_EXIT_4, +SL_DEVICE_INIT_MODULE_POWER_CYCLE_FAILURE, +SL_DEVICE_INIT_SPI_INIT_FAILURE, +SL_DEVICE_INIT_BL_WAIT_FOR_BOARD_READY_ERROR, +SL_DEVICE_INIT_BOARD_READY_TIMEOUT, +SL_DEVICE_INIT_SET_INTR_TYPE_ERROR, +SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR, +SL_DEVICE_INIT_BL_SELECT_OPTION_ERROR, +SL_DEVICE_INIT_HIGH_SPEED_ENABLE_ERROR, +SL_DEVICE_INIT_EXIT_5, +SL_DEVICE_DEINIT_ENTRY, +SL_DEVICE_DEINIT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_DEVICE_INIT_EXIT, +SL_BL_WAITFOR_BOARDREADY_ENTRY, +SL_BL_WAITFOR_BOARDREADY_EXIT, +SL_BL_WAITFOR_BOARDREADY_BOOTLOADER_VERSION_NOT_MATCHING, +SL_BL_WAITFOR_BOARDREADY_SUCCESS, +SL_BL_WAITFOR_BOARDREADY_WAITING_FOR_BOARD_READY, +SL_BL_UPGRADE_FIRMWARE_ENTRY, +SL_BL_UPGRADE_FIRMWARE_EXIT1, +SL_BL_UPGRADE_FIRMWARE_EXIT2, +SL_BL_UPGRADE_FIRMWARE_EXIT3, +SL_BL_UPGRADE_FIRMWARE_EXIT4, +SL_BL_UPGRADE_FIRMWARE_EXIT5, +SL_BL_UPGRADE_FIRMWARE_EXIT6, +SL_SET_FAST_FW_UP_ENTRY, +SL_SDIO_IFACE_INIT_EXIT_1, +SL_SDIO_IFACE_INIT_EXIT_2, +SL_SDIO_IFACE_INIT_EXIT_3, +SL_GET_ROM_VERSION_ENTRY, +SL_GET_RAM_DUMP_ENTRY, +SL_SET_RTC_TIMER_NULL_BUFFER, +SL_SET_RTC_TIMER_BUFFER_LENGTH_ERROR, +SL_BL_MODULE_POWER_CYCLE_ENTRY, +SL_BL_MODULE_POWER_CYCLE_EXIT, +SL_NWK_REGISTER_CALLBACKS_ENTRY, +SL_NWK_REGISTER_CALLBACKS_EXCEEDS_MAX_CALLBACKS, +SL_NWK_REGISTER_CALLBACKS_EXIT, +SL_WLAN_RADIO_INIT_ENTRY, +SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_RADIO_INIT_EXIT_1, +SL_WLAN_RADIO_INIT_EXIT_2, +SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_RADIO_INIT_EXIT_3, +SL_WLAN_RADIO_INIT_EXIT_4, +SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_4, +SL_WLAN_RADIO_INIT_EXIT_5, +SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_5, +SL_WLAN_RADIO_INIT_EXIT_6, +SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_6, +SL_WLAN_RADIO_INIT_EXIT_7, +SL_WLAN_RADIO_INIT_EXIT_8, +SL_WLAN_RADIO_INIT_WLAN_COMMAND_ERROR, +SL_WLAN_RADIO_INIT_EXIT_9, +SL_WLAN_FILTER_BROADCAST_ENTRY, +SL_WLAN_FILTER_BROADCAST_PKT_ALLOCATION_FAILURE, +SL_WLAN_FILTER_BROADCAST_NWK_COMMAND_ERROR, +SL_WLAN_FILTER_BROADCAST_COMMAND_SEN_ERROR, +SL_RSI_ERROR_TIMEOUT, +SL_RSI_ERROR_TIMEOUT_FRAME_TYPE, +SL_RSI_ERROR_TIMEOUT_READ, +SL_RSI_BT_CLEAR_WAIT_BITMAP_TRIGGER, +SL_RSI_BT_SET_WAIT_BITMAP_TRIGGER, +SL_RSI_BT_GET_ACL_TYPE_TRIGGER, +SL_RSI_BT_GET_PROTO_TYPE_TRIGGER, +SL_RSI_BT_GET_TIMEOUT_TRIGGER, +SL_RSI_BT_COMMON_TX_DONE, +SL_RSI_BT_STATE_TRIGGER, +SL_RSI_BT_SET_STATUS_TRIGGER, +SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER, +SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER, +SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER, +SL_RSI_DRIVER_PROCESS_BT_RESPONSE_TRIGGER, +SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER, +SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER, +SL_RSI_BT_CB_INIT_TRIGGER, +SL_RSI_BT_GLOBAL_CB_INIT_TRIGGER, +SL_RSI_BT_COMMON_INIT_TRIGGER, +SL_RSI_BT_GAP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_GATT_EXTENDED_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_AVDTP_EVENTS_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_PKT_CHANGE_EVENTS_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_CHIP_MEMORY_STATUS_CALLBACKS_TRIGGER, +SL_RSI_BT_AR_EVENTS_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_L2CAP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_HID_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_SPP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_A2DP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_AVRCP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_AVRCP_TARGET_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_HFP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_PBAP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_IAP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BT_CALLBACKS_HANDLER_TRIGGER, +SL_RSI_BT_CALLBACKS_HANDLER_STATUS, +SL_RSI_BLE_GAP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BLE_GAP_EXTENDED_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BLE_SMP_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BLE_GATT_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BLE_L2CAP_CBSC_REGISTER_CALLBACKS_TRIGGER, +SL_RSI_BLE_CALLBACKS_HANDLER_TRIGGER, +SL_RSI_BLE_CALLBACKS_HANDLER_STATUS, +SL_RSI_BLE_CHIP_MEMORY_STATUS_CALLBACKS_REGISTER, +SL_RSI_BT_PREPARE_COMMON_PACKET_TRIGGER, +SL_RSI_BT_PREPARE_CLASSIC_PKT_TRIGGER, +SL_RSI_BT_PREPARE_LE_PKT_TRIGGER, +SL_RSI_BT_SEND_CMD_TRIGGER, +SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE, +SL_RSI_BT_SEND_CMD_PROTOCOL_TYPE, +SL_RSI_ERROR_PACKET_ALLOCATION_FAILURE, +SL_RSI_ERROR_BT_BLE_CMD_IN_PROGRESS, +SL_RSI_ERROR_PKT_ALLOCATION_FAILURE, +SL_RSI_BLE_ERROR, +SL_RSI_SEMAPHORE_TIMEOUT, +SL_RSI_BT_COMMAND_RESPONSE_STATUS, +SL_RSI_INIT_BT_STACK, +SL_POWERSAVE_GPIO_INIT_ENTRY, +SL_POWERSAVE_GPIO_INIT_EXIT, +SL_SPI_IFACE_INIT_ENTRY, +SL_SPI_IFACE_INIT_EXIT, +SL_SDIO_IFACE_INIT_ENTRY, +SL_SDIO_IFACE_INIT_EXIT_4, +SL_SDIO_IFACE_INIT_EXIT_5, +SL_SDIO_IFACE_INIT_EXIT_6, +SL_UART_INIT_ENTRY, +SL_UART_INIT_EXIT, +SL_SORT_SCAN_RESULTS_ENTRY, +SL_SORT_SCAN_RESULTS_EXIT, +SL_WLAN_SCAN_BITMAP_ENTRY, +SL_WLAN_SCAN_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SCAN_BITMAP_ERROR_IN_SENDING_COMMAND, +SL_WLAN_SCAN_BITMAP_WLAN_COMMAND_ERROR, +SL_WLAN_SCAN_BITMAP_EXIT, +SL_WLAN_SCAN_ASYNC_BITMAP_ENTRY, +SL_WLAN_SCAN_ASYNC_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_3, +SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_4, +SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_4, +SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_5, +SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_5, +SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_6, +SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_6, +SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_7, +SL_WLAN_SCAN_ASYNC_BITMAP_WLAN_COMMAND_ERROR, +SL_WLAN_SCAN_ASYNC_BITMAP_EXIT, +SL_WLAN_SCAN_ENTRY, +SL_WLAN_SCAN_ERROR_IN_SENDING_COMMAND, +SL_WLAN_SCAN_WLAN_COMMAND_ERROR, +SL_WLAN_SCAN_EXIT, +SL_WLAN_SCAN_ASYNC_ENTRY, +SL_WLAN_SCAN_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_3, +SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_3, +SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_4, +SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_4, +SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_5, +SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_5, +SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_6, +SL_WLAN_SCAN_ASYNC_WLAN_COMMAND_ERROR, +SL_WLAN_SCAN_ASYNC_EXIT, +SL_WLAN_CONNECT_ENTRY, +SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_CONNECT_EXIT, +SL_WLAN_CONNECT_ASYNC_ENTRY, +SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_1, +SL_WLAN_CONNECT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, +SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_2, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_CONNECT_ASYNC_HE_PARAMS_SUPPORT, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_3, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_4, +SL_WLAN_CONNECT_ASYNC_WLAN_CMD_STATE_CHANGED_TO_ALLOW, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_5, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_4, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_6, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_5, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_7, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_6, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_8, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_7, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_9, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_8, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_10, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_9, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_11, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_10, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_12, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_11, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_13, +SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_12, +SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_14, +SL_WLAN_CONNECT_ASYNC_WLAN_COMMAND_ERROR, +SL_WLAN_CONNECT_ASYNC_EXIT, +SL_WLAN_BGSCAN_PROFILE_ENTRY, +SL_WLAN_BGSCAN_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_BGSCAN_PROFILE_PKT_ALLOCATION_FAILURE, +SL_WLAN_BGSCAN_PROFILE_WLAN_COMMAND_ERROR, +SL_WLAN_BGSCAN_PROFILE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ENRTY, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_NWK_COMMAND_ERROR, +SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_WPS_PUSH_BUTTON_EVENT_ENRTY, +SL_WLAN_WPS_PUSH_BUTTON_EVENT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_WPS_PUSH_BUTTON_EVENT_PKT_ALLOCATION_FAILURE, +SL_WLAN_WPS_PUSH_BUTTON_EVENT_WLAN_COMMAND_ERROR, +SL_WLAN_WPS_PUSH_BUTTON_EVENT_ERROR_IN_SENDING_COMMAND, +SL_WLAN_SEND_FREQ_OFFSET_ENTRY, +SL_WLAN_SEND_FREQ_OFFSET_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SEND_FREQ_OFFSET_PKT_ALLOCATION_FAILURE, +SL_WLAN_SEND_FREQ_OFFSET_WLAN_COMMAND_ERROR, +SL_WLAN_SEND_FREQ_OFFSET_ERROR_IN_SENDING_COMMAND, +SL_WLAN_CALIB_WRITE_ENTRY, +SL_WLAN_CALIB_WRITE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_CALIB_WRITE_PKT_ALLOCATION_FAILURE, +SL_WLAN_CALIB_WRITE_WLAN_COMMAND_ERROR, +SL_WLAN_CALIB_WRITE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_CALIB_READ_ENTRY, +SL_WLAN_CALIB_READ_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_CALIB_READ_PKT_ALLOCATION_FAILURE, +SL_WLAN_CALIB_READ_WLAN_COMMAND_ERROR, +SL_WLAN_CALIB_READ_ERROR_IN_SENDING_COMMAND, +SL_WLAN_WPS_GENERATE_PIN_ENTRY, +SL_WLAN_WPS_GENERATE_PIN_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_WPS_GENERATE_PIN_PKT_ALLOCATION_FAILURE, +SL_WLAN_WPS_GENERATE_PIN_WLAN_COMMAND_ERROR, +SL_WLAN_WPS_GENERATE_PIN_ERROR_IN_SENDING_COMMAND, +SL_WLAN_WPS_ENTER_PIN_ENTRY, +SL_WLAN_WPS_ENTER_PIN_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_WPS_ENTER_PIN_PKT_ALLOCATION_FAILURE, +SL_WLAN_WPS_ENTER_PIN_WLAN_COMMAND_ERROR, +SL_WLAN_WPS_ENTER_PIN_ERROR_IN_SENDING_COMMAND, +SL_WLAN_GET_RANDOM_BYTES_ENTRY, +SL_WLAN_GET_RANDOM_BYTES_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_GET_RANDOM_BYTES_PKT_ALLOCATION_FAILURE, +SL_WLAN_GET_RANDOM_BYTES_WLAN_COMMAND_ERROR, +SL_WLAN_GET_RANDOM_BYTES_ERROR_IN_SENDING_COMMAND, +SL_WLAN_DISCONNECT_ENTRY, +SL_WLAN_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_DISCONNECT_PKT_ALLOCATION_FAILURE, +SL_WLAN_DISCONNECT_WLAN_COMMAND_ERROR, +SL_WLAN_DISCONNECT_ERROR_IN_SENDING_COMMAND, +SL_WLAN_DISCONNECT_STATIONS_ENTRY, +SL_WLAN_DISCONNECT_STATIONS_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_DISCONNECT_STATIONS_PKT_ALLOCATION_FAILURE, +SL_WLAN_DISCONNECT_STATIONS_WLAN_COMMAND_ERROR, +SL_WLAN_DISCONNECT_STATIONS_ERROR_IN_SENDING_COMMAND, +SL_WLAN_CONFIG_IPADDRESS_ENTRY, +SL_WLAN_CONFIG_IPADDRESS_ERROR_IN_SENDING_COMMAND, +SL_WLAN_CONFIG_IPADDRESS_PKT_ALLOCATION_FAILURE, +SL_WLAN_CONFIG_IPADDRESS_CHANGE_WLAN_CMD_STATE_TO_ALLOW, +SL_WLAN_CONFIG_IPADDRESS_WLAN_COMMAND_ERROR, +SL_WLAN_CONFIG_IPADDRESS_EXIT, +SL_WLAN_SET_CERTIFICATE_INDEX_ENTRY, +SL_WLAN_SET_CERTIFICATE_INDEX_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SET_CERTIFICATE_INDEX_INVALID_PARAM, +SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_3, +SL_WLAN_SET_CERTIFICATE_INDEX_WLAN_COMMAND_ERROR, +SL_WLAN_SET_CERTIFICATE_INDEX_EXIT, +SL_WLAN_SET_CERTIFICATE_EXIT, +SL_WLAN_GET_STATUS_EXIT, +SL_WLAN_GET_ENTRY, +SL_WLAN_GET_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_GET_FW_VERSION_QUERY_REQ, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_3, +SL_WLAN_GET_INSUFFICIENT_BUFFER_1, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_4, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_5, +SL_WLAN_GET_INSUFFICIENT_BUFFER_2, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_6, +SL_WLAN_GET_INSUFFICIENT_BUFFER_3, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_7, +SL_WLAN_GET_INSUFFICIENT_BUFFER_4, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_8, +SL_WLAN_GET_INSUFFICIENT_BUFFER_5, +SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9, +SL_WLAN_GET_WLAN_COMMAND_ERROR, +SL_WLAN_GET_EXIT, +SL_WLAN_SET_ENTRY, +SL_WLAN_SET_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SET_NVALID_PARAM, +SL_WLAN_SET_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_SET_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_SET_PKT_ALLOCATION_FAILURE_3, +SL_WLAN_SET_WLAN_COMMAND_ERROR, +SL_WLAN_SET_EXIT, +SL_WLAN_BUFFER_CONFIG_ENTRY, +SL_WLAN_BUFFER_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_BUFFER_CONFIG_PKT_ALLOCATION_FAILURE, +SL_WLAN_BUFFER_CONFIG_WLAN_COMMAND_ERROR, +SL_WLAN_BUFFER_CONFIG_EXIT, +SL_WLAN_AP_START_ENTRY, +SL_WLAN_AP_START_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_1, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_2, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_3, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_3, +SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_4, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_5, +SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_5, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_6, +SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_6, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_7, +SL_WLAN_AP_START_NWK_COMMAND_ERROR, +SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_8, +SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_ENTRY, +SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_EXIT, +SL_WLAN_POWER_SAVE_PROFILE_EXIT, +SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ENTRY, +SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_POWER_SAVE_DISABLE_ENABLE_EXIT, +SL_WLAN_TX_TEXT_START_ENTRY, +SL_WLAN_TX_TEXT_START_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_TX_TEXT_START_PKT_ALLOCATION_FAILURE, +SL_WLAN_TX_TEXT_START_WLAN_COMMAND_ERROR, +SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_TX_TEXT_STOP_ENTRY, +SL_WLAN_TX_TEXT_STOP_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_TX_TEXT_STOP_PKT_ALLOCATION_FAILURE, +SL_WLAN_TX_TEXT_STOP_WLAN_COMMAND_ERROR, +SL_WLAN_TX_TEXT_STOP_ERROR_IN_SENDING_COMMAND, +SL_WLAN_RX_STATS_START_ENTRY, +SL_WLAN_RX_STATS_START_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_RX_STATS_START_PKT_ALLOCATION_FAILURE, +SL_WLAN_RX_STATS_START_WLAN_COMMAND_ERROR, +SL_WLAN_RX_STATS_START_ERROR_IN_SENDING_COMMAND, +SL_WLAN_RX_STATS_STOP_ENTRY, +SL_WLAN_RX_STATS_STOP_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_RX_STATS_STOP_PKT_ALLOCATION_FAILURE, +SL_WLAN_RX_STATS_STOP_WLAN_COMMAND_ERROR, +SL_WLAN_RX_STATS_STOP_ERROR_IN_SENDING_COMMAND, +SL_WLAN_WFD_START_DISCOVERY_ENTRY, +SL_WLAN_WFD_START_DISCOVERY_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_1, +SL_WLAN_WFD_START_DISCOVERY_PKT_ALLOCATION_FAILURE, +SL_WLAN_WFD_START_DISCOVERY_WLAN_COMMAND_ERROR, +SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_2, +SL_WLAN_WFD_CONNECT_ENTRY, +SL_WLAN_WFD_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_WFD_CONNECT_PKT_ALLOCATION_FAILURE, +SL_WLAN_WFD_CONNECT_WLAN_COMMAND_ERROR, +SL_WLAN_WFD_CONNECT_ERROR_IN_SENDING_COMMAND, +SL_WLAN_SEND_DATA_ENTRY, +SL_WLAN_SEND_DATA_INVALID_PARAM, +SL_WLAN_SEND_DATA_PKT_ALLOCATION_FAILURE, +SL_WLAN_SEND_DATA_EXIT, +SL_WLAN_PING_ASYNC_ENTRY, +SL_WLAN_PING_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_PING_ASYNC_INVALID_PARAM, +SL_WLAN_PING_ASYNC_PKT_ALLOCATION_FAILURE, +SL_WLAN_PING_ASYNC_WLAN_COMMAND_ERROR, +SL_WLAN_PING_ASYNC_ERROR_IN_SENDING_COMMAND, +SL_WLAN_REGISTER_AUTO_CONFIG_RSP_HANDLER_EXIT, +SL_WLAN_ADD_PROFILE_ENTRY, +SL_WLAN_ADD_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_ADD_PROFILE_PKT_ALLOCATION_FAILURE, +SL_WLAN_ADD_PROFILE_WLAN_COMMAND_ERROR, +SL_WLAN_ADD_PROFILE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_GET_STATE_EXIT, +SL_WLAN_GET_PROFILE_ENTRY, +SL_WLAN_GET_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_GET_PROFILE_PKT_ALLOCATION_FAILURE, +SL_WLAN_GET_PROFILE_WLAN_COMMAND_ERROR, +SL_WLAN_GET_PROFILE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_FILL_CONFIG_PROFILE_ENTRY, +SL_WLAN_FILL_CONFIG_PROFILE_EXIT, +SL_WLAN_DELETE_PROFILE_ENTRY, +SL_WLAN_DELETE_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_DELETE_PROFILE_PKT_ALLOCATION_FAILURE, +SL_WLAN_DELETE_PROFILE_WLAN_COMMAND_ERROR, +SL_WLAN_DELETE_PROFILE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_ENABLE_AUTO_CONFIG_ENTRY, +SL_WLAN_ENABLE_AUTO_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_ENABLE_AUTO_CONFIG_PKT_ALLOCATION_FAILURE, +SL_WLAN_ENABLE_AUTO_CONFIG_WLAN_COMMAND_ERROR, +SL_WLAN_ENABLE_AUTO_CONFIG_ERROR_IN_SENDING_COMMAND, +SL_WLAN_PMK_GENERATE_ENTRY, +SL_WLAN_PMK_GENERATE_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_PMK_GENERATE_PKT_ALLOCATION_FAILURE, +SL_WLAN_PMK_GENERATE_WLAN_COMMAND_ERROR, +SL_WLAN_PMK_GENERATE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_SET_SLEEP_TIMER_ENTRY, +SL_WLAN_SET_SLEEP_TIMER_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_SET_SLEEP_TIMER_PKT_ALLOCATION_FAILURE, +SL_WLAN_SET_SLEEP_TIMER_WLAN_COMMAND_ERROR, +SL_WLAN_SET_SLEEP_TIMER_ERROR_IN_SENDING_COMMAND, +SL_WLAN_REGISTER_CALLBACKS_ENTRY, +SL_WLAN_REGISTER_CALLBACKS_NUMBER_EXCEEDS_MAX_NUM_CALLBACKS_OR_CALLBACK_ALREADY_REG, +SL_WLAN_REGISTER_CALLBACKS_EXIT, +SL_WLAN_REQ_RADIO_ENTRY, +SL_WLAN_REQ_RADIO_COMMAND_GIVEN_IN_WRONG_STATE, +SL_WLAN_REQ_RADIO_PKT_ALLOCATION_FAILURE, +SL_WLAN_REQ_RADIO_WLAN_COMMAND_ERROR, +SL_WLAN_REQ_RADIO_ERROR_IN_SENDING_COMMAND, +SL_WLAN_RADIO_DEINIT_ERROR_IN_SENDING_COMMAND, +SL_WLAN_ADD_MFI_IE_ENTRY, +SL_WLAN_ADD_MFI_IE_PKT_ALLOCATION_FAILURE, +SL_WLAN_ADD_MFI_IE_WLAN_COMMAND_ERROR, +SL_WLAN_ADD_MFI_IE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_UPDATE_GAIN_TABLE_ENTRY, +SL_WLAN_UPDATE_GAIN_TABLE_INVALID_PARAM, +SL_WLAN_UPDATE_GAIN_TABLE_PKT_ALLOCATION_FAILURE, +SL_WLAN_UPDATE_GAIN_TABLE_WLAN_COMMAND_ERROR, +SL_WLAN_UPDATE_GAIN_TABLE_ERROR_IN_SENDING_COMMAND, +SL_WLAN_CSI_CONFIG_ENTRY, +SL_WLAN_CSI_CONFIG_PKT_ALLOCATION_FAILURE, +SL_WLAN_CSI_CONFIG_WLAN_COMMAND_ERROR, +SL_WLAN_CSI_CONFIG_ERROR_IN_SENDING_COMMAND, +SL_SHA_PEN_ENTRY, +SL_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE, +SL_SHA_PEN_INVALID_PARAM_1, +SL_SHA_PEN_INVALID_PARAM_2, +SL_SHA_PEN_PKT_ALLOCATION_FAILURE, +SL_SHA_PEN_COMMAND_ERROR, +SL_SHA_PEN_EXIT, +SL_SHA_ENTRY, +SL_SHA_CHUNK_LENGTH_MSG_ERROR, +SL_SHA_EXIT, +SL_HMAC_SHA_PEN_ENTRY, +SL_HMAC_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE, +SL_HMAC_SHA_PEN_INVALID_PARAM_1, +SL_HMAC_SHA_PEN_INVALID_PARAM_2, +SL_HMAC_SHA_PEN_PKT_ALLOCATION_FAILURE, +SL_HMAC_SHA_PEN_COMMAND_ERROR, +SL_HMAC_SHA_PEN_EXIT, +SL_HMAC_SHA_ENTRY, +SL_HMAC_SHA_CHUNK_LENGTH_MSG_ERROR, +SL_HMAC_SHA_EXIT, +SL_AES_ENTRY, +SL_AES_CHUNK_LENGTH_MSG_ERROR, +SL_AES_EXIT, +SL_AES_PEN_ENTRY, +SL_AES_PEN_INVALID_PARAM_1, +SL_AES_PEN_INVALID_PARAM_2, +SL_AES_PEN_PKT_ALLOCATION_FAILURE, +SL_AES_PEN_COMMAND_ERROR, +SL_AES_PEN_EXIT, +SL_EXPONENTIATION_ENTRY, +SL_EXPONENTIATION_COMMAND_GIVEN_IN_WRONG_STATE, +SL_EXPONENTIATION_INVALID_PARAM, +SL_EXPONENTIATION_PKT_ALLOCATION_FAILURE, +SL_EXPONENTIATION_COMMAND_ERROR, +SL_EXPONENTIATION_EXIT, +SL_ECDH_POINT_MULTIPLICATION_ENTRY, +SL_ECDH_POINT_MULTIPLICATION_INVALID_PARAM, +SL_ECDH_POINT_MULTIPLICATION_PKT_ALLOCATION_FAILURE, +SL_ECDH_POINT_MULTIPLICATION_COMMAND_ERROR, +SL_ECDH_POINT_MULTIPLICATION_EXIT, +SL_ECDH_POINT_ADDITION_ENTRY, +SL_ECDH_POINT_ADDITION_INVALID_PARAM, +SL_ECDH_POINT_ADDITION_PKT_ALLOCATION_FAILURE, +SL_ECDH_POINT_ADDITION_COMMON_CMD_IN_PROGRESS, +SL_ECDH_POINT_ADDITION_EXIT, +SL_ECDH_POINT_SUBTRACTION_ENTRY, +SL_ECDH_POINT_SUBTRACTION_INVALID_PARAM, +SL_ECDH_POINT_SUBTRACTION_PKT_ALLOCATION_FAILURE, +SL_ECDH_POINT_SUBTRACTION_COMMAND_ERROR, +SL_ECDH_POINT_SUBTRACTION_EXIT, +SL_ECDH_POINT_DOUBLE_ENTRY, +SL_ECDH_POINT_DOUBLE_INVALID_PARAM, +SL_ECDH_POINT_DOUBLE_PKT_ALLOCATION_FAILURE, +SL_ECDH_POINT_DOUBLE_COMMAND_ERROR, +SL_ECDH_POINT_DOUBLE_EXIT, +SL_ECDH_POINT_AFFINE_ENTRY, +SL_ECDH_POINT_AFFINE_INVALID_PARAM, +SL_ECDH_POINT_AFFINE_PKT_ALLOCATION_FAILURE, +SL_ECDH_POINT_AFFINE_COMMAND_ERROR +}; + +#define SL_PRINTF(DEBUG_ID, component, level,...) SL_PRINTF_##DEBUG_ID(DEBUG_ID, component, level, ##__VA_ARGS__) + +#define SL_RSI_BT_AVRCP_INIT_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_INIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_CONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_CONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_DISCONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_DISCONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_PLAY_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_PLAY_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_PAUSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_PAUSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_STOP_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_STOP_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_NEXT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_NEXT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_PREV_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_PREV_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_VOL_UP_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_VOL_UP_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_VOL_DOWN_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_VOL_DOWN_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_GET_CAPABILITES_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_GET_CAPABILITES_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_ATT_LIST_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_ATT_LIST_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_ATT_VALS_LIST_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_ATT_VALS_LIST_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_CURR_ATT_VAL_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_CURR_ATT_VAL_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_CURR_ATT_VAL_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SET_CURR_ATT_VAL_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_ELEM_ATT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_ELEM_ATT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_PLAY_STATUS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_PLAY_STATUS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_REG_NOTIFICATION_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_REG_NOTIFICATION_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_REMOTE_VERSION_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_REMOTE_VERSION_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_ATT_TEXT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_ATT_TEXT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_GET_ATT_VAL_TEXT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_GET_ATT_VAL_TEXT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_BATT_STATUS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_BATT_STATUS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_SUPP_CHAR_SETS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_SUPP_CHAR_SETS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_SEND_ABS_VOLUME_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_SEND_ABS_VOLUME_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SEND_DEVICE_CAPABILITES_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SEND_DEVICE_CAPABILITES_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_ATT_LIST_RESP_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_ATT_LIST_RESP_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_ATT_VAL_LIST_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_ATT_VAL_LIST_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_CURR_ATT_VAL_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_CURR_ATT_VAL_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_SET_CURR_ATT_VAL_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_SET_CURR_ATT_VAL_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_ELE_ATT_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_ELE_ATT_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_PLAY_STATUS_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_PLAY_STATUS_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_REG_NOTIFY_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_REG_NOTIFY_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_ATT_TEXT_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_ATT_TEXT_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_ATT_VALS_TEXT_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_ATT_VALS_TEXT_RESPONSE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_BATT_STATUS_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_BATT_STATUS_RESPONSE_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_CHAR_SET_STATUS_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_CHAR_SET_STATUS_RESPONSE_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_NOTIFY_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_NOTIFY_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_CMD_REJECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_CMD_REJECT_TRIGGER & 0xfff) | (0 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_SET_ABS_VOL_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_SET_ABS_VOL_RESPONSE_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_SET_ADDR_PLAYER_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_SET_ADDR_PLAYER_RESPONSE_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_GET_FOLDER_ITEMS_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_GET_FOLDER_ITEMS_RESPONSE_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_GET_TOTAL_NUM_ITEMS_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_GET_TOTAL_NUM_ITEMS_RESPONSE_TRIGGER & 0xfff) | (0 << 12) | (1 << 14) | (3 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SPP_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SPP_INIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SPP_CONN_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SPP_CONN_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SPP_DISCONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SPP_DISCONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_BD_ADDRESS_SIGNATURE(component, level) ((SL_RSI_BT_SET_BD_ADDRESS & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_INVALID_PARAMETER_SIGNATURE(component, level) ((SL_RSI_ERROR_INVALID_PARAMETER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_BER_ENABLE_OR_DISABLE_SIGNATURE(component, level) ((SL_RSI_BT_BER_ENABLE_OR_DISABLE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_LOCAL_NAME_SIGNATURE(component, level) ((SL_RSI_BT_SET_LOCAL_NAME & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE_SIGNATURE(component, level) ((SL_RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_LOCAL_NAME_SIGNATURE(component, level) ((SL_RSI_BT_GET_LOCAL_NAME & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_RSSI_SIGNATURE(component, level) ((SL_RSI_BT_GET_RSSI & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_LOCAL_DEVICE_ADDRESS_SIGNATURE(component, level) ((SL_RSI_BT_GET_LOCAL_DEVICE_ADDRESS & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_STACK_VERSION_SIGNATURE(component, level) ((SL_RSI_BT_STACK_VERSION & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_INIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_DEINIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_DEINIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_ANTENNA_SIGNATURE(component, level) ((SL_RSI_BT_SET_ANTENNA & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_SET_FEATURE_MAP_SIGNATURE(component, level) ((SL_RSI_SET_FEATURE_MAP & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_ANTENNA_TX_POWER_LEVEL_SIGNATURE(component, level) ((SL_RSI_BT_SET_ANTENNA_TX_POWER_LEVEL & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_POWER_SAVE_PROILE_SIGNATURE(component, level) ((SL_RSI_BT_POWER_SAVE_PROILE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_REQUEST_LOCAL_DEVICE_SIGNATURE(component, level) ((SL_RSI_BT_REQUEST_LOCAL_DEVICE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_PER_CW_MODE_SIGNATURE(component, level) ((SL_RSI_PER_CW_MODE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_VENDOR_AVDTP_STATS_ENABLE_SIGNATURE(component, level) ((SL_RSI_BT_VENDOR_AVDTP_STATS_ENABLE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_VENDOR_AR_ENABLE_SIGNATURE(component, level) ((SL_RSI_BT_VENDOR_AR_ENABLE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_VENDOR_DYNAMIC_POWER_SIGNATURE(component, level) ((SL_RSI_BT_VENDOR_DYNAMIC_POWER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_MEMORY_STATS_ENABLE_SIGNATURE(component, level) ((SL_RSI_MEMORY_STATS_ENABLE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_L2CAP_CONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_L2CAP_CONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_L2CAP_DISCONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_L2CAP_DISCONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_L2CAP_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_L2CAP_INIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_L2CAP_SEND_DATA_REMOTE_DEVICE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_L2CAP_SEND_DATA_REMOTE_DEVICE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_L2CAP_CREATE_ERTM_CHANNEL_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_L2CAP_CREATE_ERTM_CHANNEL_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_INIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_CONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_CONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_DISCONNECT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_DISCONNECT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_SEND_PCM_MP3_DATA_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_SEND_PCM_MP3_DATA_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_SEND_SBC_AAC_DATA_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_SEND_SBC_AAC_DATA_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_START_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_START & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_SUSPEND_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_SUSPEND & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_CLOSE_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_CLOSE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_ABORT_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_ABORT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_GET_CONFIG_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_GET_CONFIG & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_SET_CONFIG_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_SET_CONFIG & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_CONVERT_DB_TO_POWERINDEX_TRIGGER_SIGNATURE(component, level) ((SL_RSI_CONVERT_DB_TO_POWERINDEX_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_SET_RANDOM_TRIGGER_SIGNATURE(component, level) ((SL_RSI_SET_RANDOM_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_SET_RANDOM_ADDRESS_WITH_VALUE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_SET_RANDOM_ADDRESS_WITH_VALUE_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_START_ADV_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_START_ADV_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ENCRYPT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_ENCRYPT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_STOP_ADV_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_STOP_ADV_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_ADV_DATA_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_SET_ADV_DATA_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_START_SCANNING_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_START_SCANNING_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_START_SCANNING_WITH_VALUES_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_START_SCANNING_WITH_VALUES_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_STOP_SCANNING_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_STOP_SCANNING_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONNECT_WITH_PARAMS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_CONNECT_WITH_PARAMS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONNECT_PARAMS_SCAN_SIGNATURE(component, level) ((SL_RSI_BLE_CONNECT_PARAMS_SCAN & 0xfff) | (1 << 12) | (1 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONNECT_PARAMS_CONNECT_SIGNATURE(component, level) ((SL_RSI_BLE_CONNECT_PARAMS_CONNECT & 0xfff) | (1 << 12) | (1 << 14) | (1 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONNECT_SIGNATURE(component, level) ((SL_RSI_BLE_CONNECT & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONNECT_CANCEL_SIGNATURE(component, level) ((SL_RSI_BLE_CONNECT_CANCEL & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_DISCONNECT_SIGNATURE(component, level) ((SL_RSI_BLE_DISCONNECT & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_DEVICE_STATE_SIGNATURE(component, level) ((SL_RSI_BLE_GET_DEVICE_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_SMP_PAIRING_CAP_DATA_SIGNATURE(component, level) ((SL_RSI_BLE_SET_SMP_PAIRING_CAP_DATA & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_LOCAL_IRK_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_SET_LOCAL_IRK_VALUE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONN_PARAM_RESPONSE_SIGNATURE(component, level) ((SL_RSI_BLE_CONN_PARAM_RESPONSE & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SMP_PAIR_REQUEST_SIGNATURE(component, level) ((SL_RSI_BLE_SMP_PAIR_REQUEST & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_LTK_REQ_REPLY_SIGNATURE(component, level) ((SL_RSI_BLE_LTK_REQ_REPLY & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SMP_PAIR_RESPONSE_SIGNATURE(component, level) ((SL_RSI_BLE_SMP_PAIR_RESPONSE & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SMP_PASSKEY_SIGNATURE(component, level) ((SL_RSI_BLE_SMP_PASSKEY & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_LE_PING_TIMEOUT_SIGNATURE(component, level) ((SL_RSI_BLE_GET_LE_PING_TIMEOUT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_LE_PING_TIMEOUT_SIGNATURE(component, level) ((SL_RSI_BLE_SET_LE_PING_TIMEOUT & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CLEAR_WHITELIST_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_CLEAR_WHITELIST_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ADD_TO_WHITELIST_SIGNATURE(component, level) ((SL_RSI_BLE_ADD_TO_WHITELIST & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_DELETEFROM_WHITELIST_SIGNATURE(component, level) ((SL_RSI_BLE_DELETEFROM_WHITELIST & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_RESOLVLIST_SIGNATURE(component, level) ((SL_RSI_BLE_RESOLVLIST & 0xfff) | (0 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_RESOLVING_LIST_SIZE_SIGNATURE(component, level) ((SL_RSI_BLE_GET_RESOLVING_LIST_SIZE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_ADDR_RESOULTION_ENABLE_SIGNATURE(component, level) ((SL_RSI_BLE_SET_ADDR_RESOULTION_ENABLE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_PRIVACY_MODE_SIGNATURE(component, level) ((SL_RSI_BLE_SET_PRIVACY_MODE & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_READPHY_SIGNATURE(component, level) ((SL_RSI_BLE_READPHY & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_SETPHY_TRIGGER_SIGNATURE(component, level) ((SL_RSI_SETPHY_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CONN_PARMS_UPDATE_SIGNATURE(component, level) ((SL_RSI_BLE_CONN_PARMS_UPDATE & 0xfff) | (1 << 12) | (1 << 14) | (1 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_DATA_LEN_SIGNATURE(component, level) ((SL_RSI_BLE_SET_DATA_LEN & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_READ_MAX_DATA_LEN_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_READ_MAX_DATA_LEN_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_RX_TEST_MODE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_RX_TEST_MODE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_TX_TEST_MODE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_TX_TEST_MODE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_END_TEST_MODE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_END_TEST_MODE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_INIT_PER_TRANSMIT_MODE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_INIT_PER_TRANSMIT_MODE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_PER_RECIEVE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_PER_RECIEVE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_VENDOR_RF_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_VENDOR_RF_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_WHITELIST_USING_ADV_DATA_SIGNATURE(component, level) ((SL_RSI_BLE_WHITELIST_USING_ADV_DATA & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_AD_PACKET_EXTRACT_SIGNATURE(component, level) ((SL_RSI_BLE_AD_PACKET_EXTRACT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_UPDATE_DIRECTED_ADDRESS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_UPDATE_DIRECTED_ADDRESS_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ENCRYPTION_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_ENCRYPTION_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_BLE_TX_POWER_SIGNATURE(component, level) ((SL_RSI_BLE_SET_BLE_TX_POWER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_LOCAL_CLASS_OF_DEVICE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SET_LOCAL_CLASS_OF_DEVICE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_LOCAL_CLASS_OF_DEVICE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_LOCAL_CLASS_OF_DEVICE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_DISCOVERY_MODE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_DISCOVERY_MODE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_LIMITED_DISCOVERY_MODE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_LIMITED_DISCOVERY_MODE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_PROFILES_HANDLE_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_PROFILES_HANDLE_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_PROFILES_UUID_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_PROFILES_UUID_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CHAR_SERVICES_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_CHAR_SERVICES_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_INC_SERVICES_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_INC_SERVICES_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_ATT_DESCRIPTORS_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_ATT_DESCRIPTORS_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_ATT_VALUE_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_ATT_VALUE_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_LONG_ATT_VALUE_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_GET_LONG_ATT_VALUE_ASYNC & 0xfff) | (1 << 12) | (1 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_ATT_VALUE_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_SET_ATT_VALUE_ASYNC & 0xfff) | (1 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_PREPARE_WRITE_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_PREPARE_WRITE_ASYNC & 0xfff) | (1 << 12) | (1 << 14) | (0 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_EXECUTE_WRITE_ASYNC_SIGNATURE(component, level) ((SL_RSI_BLE_EXECUTE_WRITE_ASYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_PROFILES_SIGNATURE(component, level) ((SL_RSI_BLE_GET_PROFILES & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_PROFILE_SIGNATURE(component, level) ((SL_RSI_BLE_GET_PROFILE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_CHAR_SERVICES_SIGNATURE(component, level) ((SL_RSI_BLE_GET_CHAR_SERVICES & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_INC_SERVICES_SIGNATURE(component, level) ((SL_RSI_BLE_GET_INC_SERVICES & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_SIGNATURE(component, level) ((SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_ATT_DESCRIPTORS_SIGNATURE(component, level) ((SL_RSI_BLE_GET_ATT_DESCRIPTORS & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_ATT_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_GET_ATT_VALUE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_SIGNATURE(component, level) ((SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_LONG_ATT_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_GET_LONG_ATT_VALUE & 0xfff) | (1 << 12) | (1 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_ATT_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_SET_ATT_VALUE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_ATT_COMMAND_SIGNATURE(component, level) ((SL_RSI_BLE_SET_ATT_COMMAND & 0xfff) | (1 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_LONG_ATT_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_SET_LONG_ATT_VALUE & 0xfff) | (1 << 12) | (0 << 14) | (1 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_PREPARE_WRITE_SIGNATURE(component, level) ((SL_RSI_BLE_PREPARE_WRITE & 0xfff) | (1 << 12) | (0 << 14) | (1 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_EXECUTABLE_WRITE_SIGNATURE(component, level) ((SL_RSI_BLE_EXECUTABLE_WRITE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ADD_SERVICE_SIGNATURE(component, level) ((SL_RSI_BLE_ADD_SERVICE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ADD_ATTRIBUTE_SIGNATURE(component, level) ((SL_RSI_BLE_ADD_ATTRIBUTE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_LOCAL_ATT_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_SET_LOCAL_ATT_VALUE & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO_SIGNATURE(component, level) ((SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO & 0xfff) | (0 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_NOTIFY_VALUE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_NOTIFY_VALUE_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_INDICATE_VOLUME_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_INDICATE_VOLUME_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_INDICATE_VALUE_SYNC_SIGNATURE(component, level) ((SL_RSI_BLE_INDICATE_VALUE_SYNC & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_INDICATE_CONFIRM_SIGNATURE(component, level) ((SL_RSI_BLE_INDICATE_CONFIRM & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GET_LOCAL_ATT_VALUE_SIGNATURE(component, level) ((SL_RSI_BLE_GET_LOCAL_ATT_VALUE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GATT_READ_RESPONSE_SIGNATURE(component, level) ((SL_RSI_BLE_GATT_READ_RESPONSE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_REMOVE_GATT_SERVICE_SIGNATURE(component, level) ((SL_RSI_BLE_REMOVE_GATT_SERVICE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_REMOVE_GATT_ATTRIBUTE_SIGNATURE(component, level) ((SL_RSI_BLE_REMOVE_GATT_ATTRIBUTE & 0xfff) | (3 << 12) | (1 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ATT_ERROR_RESPONSE_SIGNATURE(component, level) ((SL_RSI_BLE_ATT_ERROR_RESPONSE & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_MTU_EXCHANGE_EVENT_SIGNATURE(component, level) ((SL_RSI_BLE_MTU_EXCHANGE_EVENT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GATT_WRITE_RESPONSE_SIGNATURE(component, level) ((SL_RSI_BLE_GATT_WRITE_RESPONSE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE_SIGNATURE(component, level) ((SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE & 0xfff) | (1 << 12) | (1 << 14) | (1 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_BT_ADD_PAKCET_TO_LIST_SIGNATURE(component, level) ((SL_RSI_BT_ADD_PAKCET_TO_LIST & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_DELETE_PAKCET_FROM_LIST_SIGNATURE(component, level) ((SL_RSI_BT_DELETE_PAKCET_FROM_LIST & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_FREE_DATA_PACKET_SIGNATURE(component, level) ((SL_RSI_BT_FREE_DATA_PACKET & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_ALLOC_DATA_PACKET_SIGNATURE(component, level) ((SL_RSI_BT_ALLOC_DATA_PACKET & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_EVT_A2DP_DISCONNECT_SIGNATURE(component, level) ((SL_RSI_BT_EVT_A2DP_DISCONNECT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_APP_ERR_INVALID_INPUT_SIGNATURE(component, level) ((SL_RSI_APP_ERR_INVALID_INPUT & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW_SIGNATURE(component, level) ((SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_INVALID_SBC_PACKET_SIGNATURE(component, level) ((SL_RSI_INVALID_SBC_PACKET & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CMD_A2DP_PCM_MP3_DATA_SIGNATURE(component, level) ((SL_RSI_BT_CMD_A2DP_PCM_MP3_DATA & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CMD_SBC_INIT_SUCCESS_SIGNATURE(component, level) ((SL_RSI_BT_CMD_SBC_INIT_SUCCESS & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_FREQUENCY_MISMATCH_SIGNATURE(component, level) ((SL_RSI_BT_FREQUENCY_MISMATCH & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_BLOCK_LENGTH_MISMATCH_SIGNATURE(component, level) ((SL_RSI_BT_BLOCK_LENGTH_MISMATCH & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SUBBANDS_MISMATCH_SIGNATURE(component, level) ((SL_RSI_BT_SUBBANDS_MISMATCH & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CHANNEL_MODE_MISMATCH_SIGNATURE(component, level) ((SL_RSI_BT_CHANNEL_MODE_MISMATCH & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_ALLOCATION_METHOD_MISMATCH_SIGNATURE(component, level) ((SL_RSI_BT_ALLOCATION_METHOD_MISMATCH & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_SBC_ENCODE_SIGNATURE(component, level) ((SL_RSI_SBC_ENCODE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_ENTRY_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_EXIT_1_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_EXIT_2_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CREATE_EXIT9_SIGNATURE(component, level) ((SL_WEB_SOCKET_CREATE_EXIT9 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_SEND_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_WEB_SOCKET_SEND_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_SEND_ASYNC_EXIT_SIGNATURE(component, level) ((SL_WEB_SOCKET_SEND_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CLOSE_ENTRY_SIGNATURE(component, level) ((SL_WEB_SOCKET_CLOSE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WEB_SOCKET_CLOSE_EXIT_SIGNATURE(component, level) ((SL_WEB_SOCKET_CLOSE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_INIT_ENTRY_SIGNATURE(component, level) ((SL_MQTT_CLIENT_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_INIT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_MQTT_CLIENT_INIT_COMMAND_ERROR & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_INIT_INSUFFICIENT_BUFFER_LENGTH_SIGNATURE(component, level) ((SL_MQTT_CLIENT_INIT_INSUFFICIENT_BUFFER_LENGTH & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_INIT_EXIT_SIGNATURE(component, level) ((SL_MQTT_CLIENT_INIT_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_MQTT_CLIENT_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_CONNECT_INVALID_PARAM_SIGNATURE(component, level) ((SL_MQTT_CLIENT_CONNECT_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_CONNECT_EXIT_1_SIGNATURE(component, level) ((SL_MQTT_CLIENT_CONNECT_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_CONNECT_EXIT_2_SIGNATURE(component, level) ((SL_MQTT_CLIENT_CONNECT_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_DISCONNECT_ENTRY_SIGNATURE(component, level) ((SL_MQTT_CLIENT_DISCONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_DISCONNECT_INVALID_PARAM_SIGNATURE(component, level) ((SL_MQTT_CLIENT_DISCONNECT_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_CLIENT_DISCONNECT_EXIT_SIGNATURE(component, level) ((SL_MQTT_CLIENT_DISCONNECT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_PUBLISH_ENTRY_SIGNATURE(component, level) ((SL_MQTT_PUBLISH_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_PUBLISH_INVALID_PARAM_SIGNATURE(component, level) ((SL_MQTT_PUBLISH_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_PUBLISH_EXIT_SIGNATURE(component, level) ((SL_MQTT_PUBLISH_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_SUBSCRIBE_ENTRY_SIGNATURE(component, level) ((SL_MQTT_SUBSCRIBE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_SUBSCRIBE_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_MQTT_SUBSCRIBE_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_SUBSCRIBE_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_MQTT_SUBSCRIBE_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_SUBSCRIBE_EXIT_SIGNATURE(component, level) ((SL_MQTT_SUBSCRIBE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_UNSUBSCRIBE_ENTRY_SIGNATURE(component, level) ((SL_MQTT_UNSUBSCRIBE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_SUBSCRIBE_INVALID_PARAM_SIGNATURE(component, level) ((SL_MQTT_SUBSCRIBE_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_UNSUBSCRIBE_EXIT_SIGNATURE(component, level) ((SL_MQTT_UNSUBSCRIBE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MQTT_POLL_FOR_RECV_DATA_INVALID_PARAM_SIGNATURE(component, level) ((SL_MQTT_POLL_FOR_RECV_DATA_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_MQTT_POLL_FOR_RECV_DATA_EXIT_SIGNATURE(component, level) ((SL_MQTT_POLL_FOR_RECV_DATA_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_NVALID_PARAM_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_NVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ASYNC_EXIT_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ABORT_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ABORT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ABORT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ABORT_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ABORT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ABORT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_ABORT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_HTTP_CLIENT_ABORT_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_CREATE_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_CREATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_CREATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_CREATE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_CREATE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_CREATE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_CREATE_EXIT_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_CREATE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_DELETE_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_DELETE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_DELETE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_DELETE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_DELETE_EXIT_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_DELETE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_START_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_START_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_START_INVALID_PARAM_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_START_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_START_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_START_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_START_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_START_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_START_EXIT_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_START_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_PKT_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_PKT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_PKT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_PKT_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_PKT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_PKT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_PUT_PKT_EXIT_SIGNATURE(component, level) ((SL_HTTP_CLIENT_PUT_PKT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_POST_DATA_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CLIENT_POST_DATA_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_POST_DATA_INVALID_PARAM_SIGNATURE(component, level) ((SL_HTTP_CLIENT_POST_DATA_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_POST_DATA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CLIENT_POST_DATA_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_POST_DATA_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CLIENT_POST_DATA_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CLIENT_POST_DATA_EXIT_SIGNATURE(component, level) ((SL_HTTP_CLIENT_POST_DATA_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MULTICAST_ENTRY_SIGNATURE(component, level) ((SL_MULTICAST_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MULTICAST_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_MULTICAST_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_MULTICAST_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_MULTICAST_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MULTICAST_EXIT_SIGNATURE(component, level) ((SL_MULTICAST_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MULTICAST_JOIN_ENTRY_SIGNATURE(component, level) ((SL_MULTICAST_JOIN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MULTICAST_JOIN_EXIT_SIGNATURE(component, level) ((SL_MULTICAST_JOIN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MULTICAST_LEAVE_ENTRY_SIGNATURE(component, level) ((SL_MULTICAST_LEAVE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MULTICAST_LEAVE_EXIT_SIGNATURE(component, level) ((SL_MULTICAST_LEAVE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_INVALID_PARAM_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_NWK_CMD_IN_PROGRESS_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_NWK_CMD_IN_PROGRESS & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_OTAF_ASYNC_EXIT_SIGNATURE(component, level) ((SL_HTTP_OTAF_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_ENTRY_SIGNATURE(component, level) ((SL_DNS_REQ_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_DNS_REQ_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_DNS_REQ_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_DNS_REQ_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_EXIT_1_SIGNATURE(component, level) ((SL_DNS_REQ_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_DNS_REQ_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_EXIT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_DNS_REQ_EXIT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DNS_REQ_EXIT_2_SIGNATURE(component, level) ((SL_DNS_REQ_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_ENTRY_SIGNATURE(component, level) ((SL_DNS_UPDATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_DNS_UPDATE_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_DNS_UPDATE_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_EXIT_1_SIGNATURE(component, level) ((SL_DNS_UPDATE_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_COMMAND_ERROR_SIGNATURE(component, level) ((SL_DNS_UPDATE_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DNS_UPDATE_EXIT_2_SIGNATURE(component, level) ((SL_DNS_UPDATE_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DHCP_USER_CLASS_ENTRY_SIGNATURE(component, level) ((SL_DHCP_USER_CLASS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DHCP_USER_CLASS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_DHCP_USER_CLASS_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_DHCP_USER_CLASS_INVALID_PARAM_SIGNATURE(component, level) ((SL_DHCP_USER_CLASS_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_DHCP_USER_CLASS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_DHCP_USER_CLASS_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_DHCP_USER_CLASS_COMMAND_ERROR_SIGNATURE(component, level) ((SL_DHCP_USER_CLASS_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DHCP_USER_CLASS_EXIT_SIGNATURE(component, level) ((SL_DHCP_USER_CLASS_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_INVALID_PARAM_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_CREATE_ASYNC_EXIT_SIGNATURE(component, level) ((SL_SNTP_CLIENT_CREATE_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_ENTRY_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_EXIT_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_DATE_ENTRY_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_DATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_DATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_DATE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_DATE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_DATE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_GETTIME_DATE_EXIT_SIGNATURE(component, level) ((SL_SNTP_CLIENT_GETTIME_DATE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_SERVER_INFO_ENTRY_SIGNATURE(component, level) ((SL_SNTP_CLIENT_SERVER_INFO_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_SERVER_INFO_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SNTP_CLIENT_SERVER_INFO_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_SERVER_INFO_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SNTP_CLIENT_SERVER_INFO_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_SERVER_INFO_EXIT_SIGNATURE(component, level) ((SL_SNTP_CLIENT_SERVER_INFO_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_DELETE_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SNTP_CLIENT_DELETE_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SNTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SNTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SNTP_CLIENT_DELETE_ASYNC_EXIT_SIGNATURE(component, level) ((SL_SNTP_CLIENT_DELETE_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_INVALID_PARAM_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_PARAMTER_LENGTH_EXCEEDS_MAX_VAL & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CLIENT_INIT_EXIT_SIGNATURE(component, level) ((SL_EMB_MQTT_CLIENT_INIT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CONNECT_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_CONNECT_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_CONNECT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CONNECT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_CONNECT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_CONNECT_EXIT_SIGNATURE(component, level) ((SL_EMB_MQTT_CONNECT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_INVALID_PARAM_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_1_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_2_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_PUBLISH_COMMAND_SEND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_PUBLISH_COMMAND_SEND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_SUBSCRIBE_COMMAND_SEND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_SUBSCRIBE_COMMAND_SEND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_SEND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_SEND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DISCONNECT_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_DISCONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DISCONNECT_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_DISCONNECT_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DISCONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_DISCONNECT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DISCONNECT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_DISCONNECT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DISCONNECT_COMMAND_SEND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_DISCONNECT_COMMAND_SEND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DESTROY_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_DESTROY_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DESTROY_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level) ((SL_EMB_MQTT_DESTROY_COMMAND_NOT_SUPPORTED & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DESTROY_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EMB_MQTT_DESTROY_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DESTROY_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EMB_MQTT_DESTROY_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DESTROY_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_DESTROY_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_DESTROY_COMMAND_SEN_ERROR_SIGNATURE(component, level) ((SL_EMB_MQTT_DESTROY_COMMAND_SEN_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_REGISTER_CALL_BACK_ENTRY_SIGNATURE(component, level) ((SL_EMB_MQTT_REGISTER_CALL_BACK_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_REGISTER_CALL_BACK_EXCEEDS_MAX_CALLBACKS_SIGNATURE(component, level) ((SL_EMB_MQTT_REGISTER_CALL_BACK_EXCEEDS_MAX_CALLBACKS & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_REGISTER_CALL_BACK_INVALID_PARAM_SIGNATURE(component, level) ((SL_EMB_MQTT_REGISTER_CALL_BACK_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_EMB_MQTT_REGISTER_CALL_BACK_EXIT_SIGNATURE(component, level) ((SL_EMB_MQTT_REGISTER_CALL_BACK_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_CAL_MQTT_PACKET_LEN_ENTRY_SIGNATURE(component, level) ((SL_CAL_MQTT_PACKET_LEN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_CAL_MQTT_PACKET_LEN_EXIT_SIGNATURE(component, level) ((SL_CAL_MQTT_PACKET_LEN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FWUP_ENTRY_SIGNATURE(component, level) ((SL_FWUP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FWUP_INVALID_PARAM_SIGNATURE(component, level) ((SL_FWUP_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_FWUP_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FWUP_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FWUP_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FWUP_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FWUP_EXIT_SIGNATURE(component, level) ((SL_FWUP_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FWUP_START_ENTRY_SIGNATURE(component, level) ((SL_FWUP_START_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FWUP_START_EXIT_SIGNATURE(component, level) ((SL_FWUP_START_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FWUP_LOAD_ENTRY_SIGNATURE(component, level) ((SL_FWUP_LOAD_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FWUP_LOAD_EXIT_SIGNATURE(component, level) ((SL_FWUP_LOAD_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SEND_RAW_DATA_ENTRY_SIGNATURE(component, level) ((SL_SEND_RAW_DATA_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_RAW_DATA_INVALID_PARAM_SIGNATURE(component, level) ((SL_SEND_RAW_DATA_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_RAW_DATA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SEND_RAW_DATA_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_RAW_DATA_EXIT_SIGNATURE(component, level) ((SL_SEND_RAW_DATA_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_FTP_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_CONNECT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_ENTRY_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_ENTRY_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_CONTENT_ENTRY_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_CONTENT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_CONTENT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_CONTENT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_CONTENT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_CONTENT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_WRITE_CONTENT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_FILE_WRITE_CONTENT_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_INVALID_PARAM_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_READ_ASYNC_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_FILE_READ_ASYNC_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_DELETE_ENTRY_SIGNATURE(component, level) ((SL_FTP_FILE_DELETE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_FILE_DELETE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_FILE_DELETE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_DELETE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_FILE_DELETE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_RENAME_ENTRY_SIGNATURE(component, level) ((SL_FTP_FILE_RENAME_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_RENAME_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_FILE_RENAME_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_RENAME_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_FILE_RENAME_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_RENAME_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_FILE_RENAME_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_CREATE_ENTRY_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_CREATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_CREATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_CREATE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_CREATE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_CREATE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_CREATE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_CREATE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_DELETE_ENTRY_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_DELETE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_DELETE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_DELETE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_DELETE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_DELETE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_SET_ENTRY_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_SET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_SET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_SET_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_SET_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_SET_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_SET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_SET_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_INVALID_PARAM_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_DIRECTORY_LIST_ASYNC_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_DIRECTORY_LIST_ASYNC_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_MODE_SET_ENTRY_SIGNATURE(component, level) ((SL_FTP_MODE_SET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_MODE_SET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_MODE_SET_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_MODE_SET_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_MODE_SET_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_MODE_SET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_MODE_SET_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_SIZE_SET_ENTRY_SIGNATURE(component, level) ((SL_FTP_FILE_SIZE_SET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_SIZE_SET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_FTP_FILE_SIZE_SET_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_SIZE_SET_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_FTP_FILE_SIZE_SET_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FTP_FILE_SIZE_SET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_FTP_FILE_SIZE_SET_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_ENTRY_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_INVALID_PARAM_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_EXIT_1_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_CREATE_EXIT_2_SIGNATURE(component, level) ((SL_SMTP_CLIENT_CREATE_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_MAIL_SEND_ASYNC_EXIT_SIGNATURE(component, level) ((SL_SMTP_CLIENT_MAIL_SEND_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_INVALID_PARAM_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SMTP_CLIENT_DELETE_ASYNC_EXIT_SIGNATURE(component, level) ((SL_SMTP_CLIENT_DELETE_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_INIT_ENTRY_SIGNATURE(component, level) ((SL_MSNSD_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MSNSD_INIT_INSUFFICIENT_BUFFER_SIGNATURE(component, level) ((SL_MSNSD_INIT_INSUFFICIENT_BUFFER & 0xfff) | (component << 18) | (level << 21)) +#define SL_MSNSD_INIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_MSNSD_INIT_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_INIT_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_MSNSD_INIT_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_INIT_EXIT_SIGNATURE(component, level) ((SL_MSNSD_INIT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_REGISTER_SERVICE_ENTRY_SIGNATURE(component, level) ((SL_MSNSD_REGISTER_SERVICE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER_SIGNATURE(component, level) ((SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER & 0xfff) | (component << 18) | (level << 21)) +#define SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_REGISTER_SERVICE_EXIT_SIGNATURE(component, level) ((SL_MSNSD_REGISTER_SERVICE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_MSNSD_DEINIT_ENTRY_SIGNATURE(component, level) ((SL_MSNSD_DEINIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_MSNSD_DEINIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_MSNSD_DEINIT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_LOAD_ENTRY_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_LOAD_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_LOAD_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_LOAD_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_LOAD_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_LOAD_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_LOAD_EXIT_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_LOAD_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_ERASE_ENTRY_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_ERASE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_ERASE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_ERASE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_ERASE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_ERASE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_ERASE_EXIT_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_ERASE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_JSON_OBJECT_DELETE_ENTRY_SIGNATURE(component, level) ((SL_HTTP_JSON_OBJECT_DELETE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_JSON_OBJECT_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_JSON_OBJECT_DELETE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_JSON_OBJECT_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_JSON_OBJECT_DELETE_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_JSON_OBJECT_DELETE_EXIT_SIGNATURE(component, level) ((SL_HTTP_JSON_OBJECT_DELETE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_SEND_ENTRY_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_SEND_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_SEND_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_SEND_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_SEND_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_SEND_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_SEND_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_SEND_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_WEBPAGE_SEND_EXIT_SIGNATURE(component, level) ((SL_HTTP_WEBPAGE_SEND_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_REQ_WIRELESS_FWUP_ENTER_SIGNATURE(component, level) ((SL_REQ_WIRELESS_FWUP_ENTER & 0xfff) | (component << 18) | (level << 21)) +#define SL_REQ_WIRELESS_FWUP_EERROR_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_REQ_WIRELESS_FWUP_EERROR_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_REQ_WIRELESS_FWUP_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_REQ_WIRELESS_FWUP_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_REQ_WIRELESS_FWUP_EXIT_SIGNATURE(component, level) ((SL_REQ_WIRELESS_FWUP_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CREDENTIALS_ENTRY_SIGNATURE(component, level) ((SL_HTTP_CREDENTIALS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CREDENTIALS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_HTTP_CREDENTIALS_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CREDENTIALS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HTTP_CREDENTIALS_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HTTP_CREDENTIALS_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HTTP_CREDENTIALS_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HTTP_CREDENTIALS_EXIT_SIGNATURE(component, level) ((SL_HTTP_CREDENTIALS_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_FD_ISSET_ENTRY_SIGNATURE(component, level) ((SL_FD_ISSET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_FD_ENTRY_SIGNATURE(component, level) ((SL_SET_FD_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FD_CLR_ENTRY_SIGNATURE(component, level) ((SL_FD_CLR_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_EXIT_SIGNATURE(component, level) ((SL_SOCKET_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_BIND_ENTRY_SIGNATURE(component, level) ((SL_BIND_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_LISTEN_ENTRY_SIGNATURE(component, level) ((SL_LISTEN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_ENTRY_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_EXIT5_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_EXIT5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_8_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_9_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_10_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_10 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_SOCK_ERROR_11_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_SOCK_ERROR_11 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_NON_ROM_EXIT_SIGNATURE(component, level) ((SL_ACCEPT_NON_ROM_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ENTRY_SIGNATURE(component, level) ((SL_ACCEPT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_LARGE_DATA_SYNC_ENTRY_SIGNATURE(component, level) ((SL_RECV_LARGE_DATA_SYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_LARGE_DATA_SYNC_EXIT_SIGNATURE(component, level) ((SL_RECV_LARGE_DATA_SYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RECV_FROM_ENTRY_SIGNATURE(component, level) ((SL_RECV_FROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_FROM_EXIT_1_SIGNATURE(component, level) ((SL_RECV_FROM_EXIT_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_FROM_EXIT_2_SIGNATURE(component, level) ((SL_RECV_FROM_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_FROM_EXIT_3_SIGNATURE(component, level) ((SL_RECV_FROM_EXIT_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_ENTRY_SIGNATURE(component, level) ((SL_RECV_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_EXIT_1_SIGNATURE(component, level) ((SL_RECV_EXIT_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_EXIT_2_SIGNATURE(component, level) ((SL_RECV_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RECV_EXIT_3_SIGNATURE(component, level) ((SL_RECV_EXIT_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ENTRY_SIGNATURE(component, level) ((SL_SENDTO_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_ENTRY_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_ENTRY_SIGNATURE(component, level) ((SL_SEND_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_EXIT_1_SIGNATURE(component, level) ((SL_SEND_EXIT_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_EXIT_2_SIGNATURE(component, level) ((SL_SEND_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_RESET_PER_SOCKET_INFO_ENTRY_SIGNATURE(component, level) ((SL_RESET_PER_SOCKET_INFO_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_SYNC_ENTRY_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_SYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_SYNC_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_SYNC_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_SYNC_EXIT_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_SYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_CHUNK_DATA_TX_DONE_CB_ENTRY_SIGNATURE(component, level) ((SL_CHUNK_DATA_TX_DONE_CB_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_ASYNC_EXIT_1_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_ASYNC_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SEND_LARGE_DATA_ASYNC_EXIT_2_SIGNATURE(component, level) ((SL_SEND_LARGE_DATA_ASYNC_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_FIND_SOCKET_DATA_PENDING_ENTRY_SIGNATURE(component, level) ((SL_FIND_SOCKET_DATA_PENDING_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FIND_SOCKET_DATA_PENDING_EXIT_SIGNATURE(component, level) ((SL_FIND_SOCKET_DATA_PENDING_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_EVENT_HANDLER_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_EVENT_HANDLER_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SEND_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_APPLICATON_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level) ((SL_GET_APPLICATON_SOCKET_DESCRIPTOR_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_CLEAR_SOCKETS_ENTRY_SIGNATURE(component, level) ((SL_CLEAR_SOCKETS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FILL_TLS_EXTENSION_ENTRY_SIGNATURE(component, level) ((SL_FILL_TLS_EXTENSION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_FILL_TLS_EXTENSION_INSUFFICIENT_BUFFER_SIGNATURE(component, level) ((SL_FILL_TLS_EXTENSION_INSUFFICIENT_BUFFER & 0xfff) | (component << 18) | (level << 21)) +#define SL_FILL_TLS_EXTENSION_EXIT_SIGNATURE(component, level) ((SL_FILL_TLS_EXTENSION_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_ENTRY_SIGNATURE(component, level) ((SL_SETSOCKOPT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SETSOCKOPT_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SETSOCKOPT_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SETSOCKOPT_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_1_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_2_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_3_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_4_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_5_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_6_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_7_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_8_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_9_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_10_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_10 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_11_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_11 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_12_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_12 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_13_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_13 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_14_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_14 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_15_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_15 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_16_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_16 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_17_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_17 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_18_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_18 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_19_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_19 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SETSOCKOPT_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT_20_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT_20 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SETSOCKOPT_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SETSOCKOPT_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SETSOCKOPT_EXIT21_SIGNATURE(component, level) ((SL_SETSOCKOPT_EXIT21 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GETSOCKOPT_EXIT1_SIGNATURE(component, level) ((SL_GETSOCKOPT_EXIT1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GETSOCKOPT_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_GETSOCKOPT_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GETSOCKOPT_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_GETSOCKOPT_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GETSOCKOPT_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_GETSOCKOPT_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GETSOCKOPT_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_GETSOCKOPT_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GETSOCKOPT_EXIT_SIGNATURE(component, level) ((SL_GETSOCKOPT_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_ENTRY_SIGNATURE(component, level) ((SL_SELECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_8_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_9_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_10_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_10 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SOCK_ERROR_11_SIGNATURE(component, level) ((SL_SELECT_SOCK_ERROR_11 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_8_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_9_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_SOCK_ERROR_10_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_SOCK_ERROR_10 & 0xfff) | (component << 18) | (level << 21)) +#define SL_ACCEPT_ASYNC_EXIT_SIGNATURE(component, level) ((SL_ACCEPT_ASYNC_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_APP_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level) ((SL_GET_APP_SOCKET_DESCRIPTOR_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_APP_SOCKET_DESCRIPTOR_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_GET_APP_SOCKET_DESCRIPTOR_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_APP_SOCKET_DESCRIPTOR_EXIT_SIGNATURE(component, level) ((SL_GET_APP_SOCKET_DESCRIPTOR_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_SOCKET_ID_ENTRY_SIGNATURE(component, level) ((SL_GET_SOCKET_ID_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_SOCKET_ID_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_GET_SOCKET_ID_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_SOCKET_ID_EXIT_SIGNATURE(component, level) ((SL_GET_SOCKET_ID_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_PRIMARY_SOCKET_ID_ENTRY_SIGNATURE(component, level) ((SL_GET_PRIMARY_SOCKET_ID_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_PRIMARY_SOCKET_ID_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_GET_PRIMARY_SOCKET_ID_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_PRIMARY_SOCKET_ID_EXIT_SIGNATURE(component, level) ((SL_GET_PRIMARY_SOCKET_ID_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_CERTIFICATE_VALID_ENTRY_SIGNATURE(component, level) ((SL_CERTIFICATE_VALID_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_CERTIFICATE_VALID_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_CERTIFICATE_VALID_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_CERTIFICATE_VALID_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_CERTIFICATE_VALID_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_CERTIFICATE_VALID_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_CERTIFICATE_VALID_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_CERTIFICATE_VALID_EXIT_SIGNATURE(component, level) ((SL_CERTIFICATE_VALID_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SOCKET_CREATE_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_CREATE_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CREATE_ASYNC_EXIT_SIGNATURE(component, level) ((SL_SOCKET_CREATE_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_ENTRY_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_SOCK_ERROR_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_SOCK_ERROR_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_TCP_WINDOW_UPDATE_EXIT_SIGNATURE(component, level) ((SL_TCP_WINDOW_UPDATE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level) ((SL_GET_SOCKET_DESCRIPTOR_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_SOCKET_DESCRIPTOR_SOCK_ERROR_SIGNATURE(component, level) ((SL_GET_SOCKET_DESCRIPTOR_SOCK_ERROR & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_SOCKET_DESCRIPTOR_EXIT_SIGNATURE(component, level) ((SL_GET_SOCKET_DESCRIPTOR_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_EXIT4_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_EXIT4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_8_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_9_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_ASYNC_NONO_ROM_EXIT_SIGNATURE(component, level) ((SL_SOCKET_ASYNC_NONO_ROM_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_CONNECT_EXIT_SIGNATURE(component, level) ((SL_SOCKET_CONNECT_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_EXIT_1_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_RECVFROM_EXIT_2_SIGNATURE(component, level) ((SL_SOCKET_RECVFROM_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_LISTEN_EXIT_SIGNATURE(component, level) ((SL_SOCKET_LISTEN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_EXIT_1_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_EXIT_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_EXIT_2_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_SHUTDOWN_EXIT_3_SIGNATURE(component, level) ((SL_SOCKET_SHUTDOWN_EXIT_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_ENTRY_SIGNATURE(component, level) ((SL_SOCKET_BIND_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_8_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_SOCK_ERROR_9_SIGNATURE(component, level) ((SL_SOCKET_BIND_SOCK_ERROR_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SOCKET_BIND_EXIT_SIGNATURE(component, level) ((SL_SOCKET_BIND_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WAIT_ON_SOCKET_SEMAPHORE_ENTRY_SIGNATURE(component, level) ((SL_WAIT_ON_SOCKET_SEMAPHORE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WAIT_ON_SOCKET_SEMAPHORE_RESPONSE_TIMEOUT_SIGNATURE(component, level) ((SL_WAIT_ON_SOCKET_SEMAPHORE_RESPONSE_TIMEOUT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WAIT_ON_SOCKET_SEMAPHORE_ERROR_NONE_SIGNATURE(component, level) ((SL_WAIT_ON_SOCKET_SEMAPHORE_ERROR_NONE & 0xfff) | (component << 18) | (level << 21)) +#define SL_APPLICATION_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level) ((SL_APPLICATION_SOCKET_DESCRIPTOR_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_APPLICATION_SOCKET_DESCRIPTOR_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_APPLICATION_SOCKET_DESCRIPTOR_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_APPLICATION_SOCKET_DESCRIPTOR_EXIT_SIGNATURE(component, level) ((SL_APPLICATION_SOCKET_DESCRIPTOR_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SOCKET_GET_STATUS_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SOCKET_GET_STATUS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SOCKET_SET_STATUS_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SOCKET_SET_STATUS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_GET_STATUS_ENTRY_SIGNATURE(component, level) ((SL_SELECT_GET_STATUS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SELECT_SET_STATUS_ENTRY_SIGNATURE(component, level) ((SL_SELECT_SET_STATUS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_ASYNC_NON_ROM_ENTRY_SIGNATURE(component, level) ((SL_SEND_ASYNC_NON_ROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_ASYNC_NON_ROM_SOCK_ERROR_SIGNATURE(component, level) ((SL_SEND_ASYNC_NON_ROM_SOCK_ERROR & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_ASYNC_NON_ROM_EXIT_SIGNATURE(component, level) ((SL_SEND_ASYNC_NON_ROM_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_1_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_ERROR_EBADF_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_ERROR_EBADF & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_2_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_3_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_4_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_5_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_EXIT_1_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_EXIT_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_6_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_EXIT_2_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_EXIT_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_7_SIGNATURE(component, level) ((SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_CLEAR_SOCKET_NON_ROM_ENTRY_SIGNATURE(component, level) ((SL_CLEAR_SOCKET_NON_ROM_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DRIVER_INIT_MAX_SOCKETS_ERROR_SIGNATURE(component, level) ((SL_DRIVER_INIT_MAX_SOCKETS_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_INIT_INSUFFICIENT_BUFFER_2_SIGNATURE(component, level) ((SL_DRIVER_INIT_INSUFFICIENT_BUFFER_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_INIT_UART_INIT_ERROR_SIGNATURE(component, level) ((SL_DRIVER_INIT_UART_INIT_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_INIT_EXIT_SIGNATURE(component, level) ((SL_DRIVER_INIT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_ENTRY_SIGNATURE(component, level) ((SL_WIRELESS_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_CARD_READY_TIMEOUT_SIGNATURE(component, level) ((SL_WIRELESS_INIT_CARD_READY_TIMEOUT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_RESPONSE_TIMEOUT_SIGNATURE(component, level) ((SL_WIRELESS_INIT_RESPONSE_TIMEOUT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_EXIT1_SIGNATURE(component, level) ((SL_WIRELESS_INIT_EXIT1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_EXIT2_SIGNATURE(component, level) ((SL_WIRELESS_INIT_EXIT2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WIRELESS_INIT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WIRELESS_INIT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_INIT_EXIT3_SIGNATURE(component, level) ((SL_WIRELESS_INIT_EXIT3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_CMD_UART_FLOW_CTRL_ENTRY_SIGNATURE(component, level) ((SL_CMD_UART_FLOW_CTRL_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_CMD_UART_FLOW_CTRL_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_CMD_UART_FLOW_CTRL_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_CMD_UART_FLOW_CTRL_COMMAND_ERROR_SIGNATURE(component, level) ((SL_CMD_UART_FLOW_CTRL_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_CMD_UART_FLOW_CTRL_EXIT_SIGNATURE(component, level) ((SL_CMD_UART_FLOW_CTRL_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY_SIGNATURE(component, level) ((SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT_SIGNATURE(component, level) ((SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DEINIT_ENTRY_SIGNATURE(component, level) ((SL_WIRELESS_DEINIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DEINIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WIRELESS_DEINIT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DEINIT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WIRELESS_DEINIT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DEINIT_DRIVER_INIT_ERROR_1_SIGNATURE(component, level) ((SL_WIRELESS_DEINIT_DRIVER_INIT_ERROR_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DEINIT_DEVICE_INIT_ERROR_2_SIGNATURE(component, level) ((SL_WIRELESS_DEINIT_DEVICE_INIT_ERROR_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DEINIT_EXIT_SIGNATURE(component, level) ((SL_WIRELESS_DEINIT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_ANTENNA_ENTRY_SIGNATURE(component, level) ((SL_WIRELESS_ANTENNA_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_ANTENNA_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WIRELESS_ANTENNA_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_ANTENNA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WIRELESS_ANTENNA_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_ANTENNA_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WIRELESS_ANTENNA_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_ANTENNA_EXIT_SIGNATURE(component, level) ((SL_WIRELESS_ANTENNA_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SEND_FEATURE_FRAME_ENTRY_SIGNATURE(component, level) ((SL_SEND_FEATURE_FRAME_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SEND_FEATURE_FRAME_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SEND_FEATURE_FRAME_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SEND_FEATURE_FRAME_EXIT_SIGNATURE(component, level) ((SL_SEND_FEATURE_FRAME_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_FW_VERSION_ENTRY_SIGNATURE(component, level) ((SL_GET_FW_VERSION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_FW_VERSION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_GET_FW_VERSION_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_FW_VERSION_COMMAND_ERROR_SIGNATURE(component, level) ((SL_GET_FW_VERSION_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_FW_VERSION_EXIT_SIGNATURE(component, level) ((SL_GET_FW_VERSION_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_COMMON_DEBUG_LOG_ENTRY_SIGNATURE(component, level) ((SL_COMMON_DEBUG_LOG_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_COMMON_DEBUG_LOG_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_COMMON_DEBUG_LOG_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_COMMON_DEBUG_LOG_INVALID_PARAM_SIGNATURE(component, level) ((SL_COMMON_DEBUG_LOG_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_COMMON_DEBUG_LOG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_COMMON_DEBUG_LOG_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_COMMON_DEBUG_LOG_COMMAND_ERROR_SIGNATURE(component, level) ((SL_COMMON_DEBUG_LOG_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_COMMON_DEBUG_LOG_EXIT_SIGNATURE(component, level) ((SL_COMMON_DEBUG_LOG_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SWITCH_PROTO_ENTRY_SIGNATURE(component, level) ((SL_SWITCH_PROTO_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SWITCH_PROTO_INVALID_PARAM_SIGNATURE(component, level) ((SL_SWITCH_PROTO_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_SWITCH_PROTO_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_SWITCH_PROTO_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SWITCH_PROTO_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SWITCH_PROTO_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SWITCH_PROTO_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SWITCH_PROTO_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SWITCH_PROTO_EXIT_SIGNATURE(component, level) ((SL_SWITCH_PROTO_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DRIVER_TASK_ENTRY_SIGNATURE(component, level) ((SL_WIRELESS_DRIVER_TASK_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WIRELESS_DRIVER_TASK_EXIT_SIGNATURE(component, level) ((SL_WIRELESS_DRIVER_TASK_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_ENTRY_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_1_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_2_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_3_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_4_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_5_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_6_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_7_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_7 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_8_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_8 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_9_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_9 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_10_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_10 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_11_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_11 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_12_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_12 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_13_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_13 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_14_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_14 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_15_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_15 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_16_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_16 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_17_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_17 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_18_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_18 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_19_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_19 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_20_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_20 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_21_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_21 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_22_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_22 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_23_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_23 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_24_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_24 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_25_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_25 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_26_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_26 & 0xfff) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_TASK_DESTROY_ENTRY_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_TASK_DESTROY_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DRIVER_DEINIT_TASK_DESTROY_EXIT_SIGNATURE(component, level) ((SL_DRIVER_DEINIT_TASK_DESTROY_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DRIVER_VERSION_ENTRY_SIGNATURE(component, level) ((SL_DRIVER_VERSION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DRIVER_VERSION_EXIT_SIGNATURE(component, level) ((SL_DRIVER_VERSION_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_ENTRY_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_EXIT_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_RAM_LOG_ENTRY_SIGNATURE(component, level) ((SL_GET_RAM_LOG_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_RAM_LOG_EXIT1_SIGNATURE(component, level) ((SL_GET_RAM_LOG_EXIT1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_RAM_LOG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_GET_RAM_LOG_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_RAM_LOG_COMMAND_ERROR_SIGNATURE(component, level) ((SL_GET_RAM_LOG_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_RAM_LOG_EXIT_SIGNATURE(component, level) ((SL_GET_RAM_LOG_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_UNREGISTER_EVENTS_CALLBACK_ENTRY_SIGNATURE(component, level) ((SL_UNREGISTER_EVENTS_CALLBACK_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_UNREGISTER_EVENTS_CALLBACK_EXIT_SIGNATURE(component, level) ((SL_UNREGISTER_EVENTS_CALLBACK_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_ENTRY_SIGNATURE(component, level) ((SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_EXIT_SIGNATURE(component, level) ((SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_RTC_TIMER_ENTRY_SIGNATURE(component, level) ((SL_GET_RTC_TIMER_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_GET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_RTC_TIMER_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_GET_RTC_TIMER_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_RTC_TIMER_COMMAND_ERROR_SIGNATURE(component, level) ((SL_GET_RTC_TIMER_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_RTC_TIMER_EXIT_SIGNATURE(component, level) ((SL_GET_RTC_TIMER_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ASSERT_ENTRY_SIGNATURE(component, level) ((SL_ASSERT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ASSERT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_ASSERT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ASSERT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_ASSERT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_ASSERT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_ASSERT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ASSERT_EXIT_SIGNATURE(component, level) ((SL_ASSERT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_PININIT_ENTRY_SIGNATURE(component, level) ((SL_GPIO_PININIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GPIO_PININIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_GPIO_PININIT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_PININIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_GPIO_PININIT_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_GPIO_PININIT_COMMAND_ERROR_SIGNATURE(component, level) ((SL_GPIO_PININIT_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_PININIT_EXIT_SIGNATURE(component, level) ((SL_GPIO_PININIT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_WRITEPIN_ENTRY_SIGNATURE(component, level) ((SL_GPIO_WRITEPIN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GPIO_WRITEPIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_GPIO_WRITEPIN_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_WRITEPIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_GPIO_WRITEPIN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_GPIO_WRITEPIN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_GPIO_WRITEPIN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_WRITEPIN_EXIT_SIGNATURE(component, level) ((SL_GPIO_WRITEPIN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_READPIN_ENTRY_SIGNATURE(component, level) ((SL_GPIO_READPIN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GPIO_READPIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_GPIO_READPIN_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_READPIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_GPIO_READPIN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_GPIO_READPIN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_GPIO_READPIN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GPIO_READPIN_EXIT_SIGNATURE(component, level) ((SL_GPIO_READPIN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_ENTRY_SIGNATURE(component, level) ((SL_DEVICE_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_EXIT_1_SIGNATURE(component, level) ((SL_DEVICE_INIT_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_EXIT_2_SIGNATURE(component, level) ((SL_DEVICE_INIT_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_EXIT_3_SIGNATURE(component, level) ((SL_DEVICE_INIT_EXIT_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_EXIT_4_SIGNATURE(component, level) ((SL_DEVICE_INIT_EXIT_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_MODULE_POWER_CYCLE_FAILURE_SIGNATURE(component, level) ((SL_DEVICE_INIT_MODULE_POWER_CYCLE_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_SPI_INIT_FAILURE_SIGNATURE(component, level) ((SL_DEVICE_INIT_SPI_INIT_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_BL_WAIT_FOR_BOARD_READY_ERROR_SIGNATURE(component, level) ((SL_DEVICE_INIT_BL_WAIT_FOR_BOARD_READY_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_BOARD_READY_TIMEOUT_SIGNATURE(component, level) ((SL_DEVICE_INIT_BOARD_READY_TIMEOUT & 0xfff) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_SET_INTR_TYPE_ERROR_SIGNATURE(component, level) ((SL_DEVICE_INIT_SET_INTR_TYPE_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR_SIGNATURE(component, level) ((SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_BL_SELECT_OPTION_ERROR_SIGNATURE(component, level) ((SL_DEVICE_INIT_BL_SELECT_OPTION_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_HIGH_SPEED_ENABLE_ERROR_SIGNATURE(component, level) ((SL_DEVICE_INIT_HIGH_SPEED_ENABLE_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_EXIT_5_SIGNATURE(component, level) ((SL_DEVICE_INIT_EXIT_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_DEINIT_ENTRY_SIGNATURE(component, level) ((SL_DEVICE_DEINIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_DEVICE_DEINIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_DEVICE_DEINIT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_DEVICE_INIT_EXIT_SIGNATURE(component, level) ((SL_DEVICE_INIT_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_WAITFOR_BOARDREADY_ENTRY_SIGNATURE(component, level) ((SL_BL_WAITFOR_BOARDREADY_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_WAITFOR_BOARDREADY_EXIT_SIGNATURE(component, level) ((SL_BL_WAITFOR_BOARDREADY_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_BL_WAITFOR_BOARDREADY_BOOTLOADER_VERSION_NOT_MATCHING_SIGNATURE(component, level) ((SL_BL_WAITFOR_BOARDREADY_BOOTLOADER_VERSION_NOT_MATCHING & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_WAITFOR_BOARDREADY_SUCCESS_SIGNATURE(component, level) ((SL_BL_WAITFOR_BOARDREADY_SUCCESS & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_WAITFOR_BOARDREADY_WAITING_FOR_BOARD_READY_SIGNATURE(component, level) ((SL_BL_WAITFOR_BOARDREADY_WAITING_FOR_BOARD_READY & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_ENTRY_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_EXIT1_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_EXIT1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_EXIT2_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_EXIT2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_EXIT3_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_EXIT3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_EXIT4_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_EXIT4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_EXIT5_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_EXIT5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_BL_UPGRADE_FIRMWARE_EXIT6_SIGNATURE(component, level) ((SL_BL_UPGRADE_FIRMWARE_EXIT6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_FAST_FW_UP_ENTRY_SIGNATURE(component, level) ((SL_SET_FAST_FW_UP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_EXIT_1_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_EXIT_2_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_EXIT_3_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_EXIT_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_GET_ROM_VERSION_ENTRY_SIGNATURE(component, level) ((SL_GET_ROM_VERSION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_GET_RAM_DUMP_ENTRY_SIGNATURE(component, level) ((SL_GET_RAM_DUMP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_NULL_BUFFER_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_NULL_BUFFER & 0xfff) | (component << 18) | (level << 21)) +#define SL_SET_RTC_TIMER_BUFFER_LENGTH_ERROR_SIGNATURE(component, level) ((SL_SET_RTC_TIMER_BUFFER_LENGTH_ERROR & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_MODULE_POWER_CYCLE_ENTRY_SIGNATURE(component, level) ((SL_BL_MODULE_POWER_CYCLE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_BL_MODULE_POWER_CYCLE_EXIT_SIGNATURE(component, level) ((SL_BL_MODULE_POWER_CYCLE_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_NWK_REGISTER_CALLBACKS_ENTRY_SIGNATURE(component, level) ((SL_NWK_REGISTER_CALLBACKS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_NWK_REGISTER_CALLBACKS_EXCEEDS_MAX_CALLBACKS_SIGNATURE(component, level) ((SL_NWK_REGISTER_CALLBACKS_EXCEEDS_MAX_CALLBACKS & 0xfff) | (component << 18) | (level << 21)) +#define SL_NWK_REGISTER_CALLBACKS_EXIT_SIGNATURE(component, level) ((SL_NWK_REGISTER_CALLBACKS_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_ENTRY_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_1_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_2_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_3_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_4_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_5_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_6_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_7_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_7 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_8_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_8 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_INIT_EXIT_9_SIGNATURE(component, level) ((SL_WLAN_RADIO_INIT_EXIT_9 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_FILTER_BROADCAST_ENTRY_SIGNATURE(component, level) ((SL_WLAN_FILTER_BROADCAST_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_FILTER_BROADCAST_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_FILTER_BROADCAST_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_FILTER_BROADCAST_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_FILTER_BROADCAST_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_FILTER_BROADCAST_COMMAND_SEN_ERROR_SIGNATURE(component, level) ((SL_WLAN_FILTER_BROADCAST_COMMAND_SEN_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_TIMEOUT_SIGNATURE(component, level) ((SL_RSI_ERROR_TIMEOUT & 0xfff) | (3 << 12) | (1 << 14) | (0 << 16) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_TIMEOUT_FRAME_TYPE_SIGNATURE(component, level) ((SL_RSI_ERROR_TIMEOUT_FRAME_TYPE & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_TIMEOUT_READ_SIGNATURE(component, level) ((SL_RSI_ERROR_TIMEOUT_READ & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CLEAR_WAIT_BITMAP_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_CLEAR_WAIT_BITMAP_TRIGGER & 0xfff) | (1 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_WAIT_BITMAP_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SET_WAIT_BITMAP_TRIGGER & 0xfff) | (1 << 12) | (0 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_ACL_TYPE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_ACL_TYPE_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_PROTO_TYPE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_PROTO_TYPE_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GET_TIMEOUT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GET_TIMEOUT_TRIGGER & 0xfff) | (1 << 12) | (1 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BT_COMMON_TX_DONE_SIGNATURE(component, level) ((SL_RSI_BT_COMMON_TX_DONE & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_STATE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_STATE_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SET_STATUS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SET_STATUS_TRIGGER & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER_SIGNATURE(component, level) ((SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER_SIGNATURE(component, level) ((SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_DRIVER_PROCESS_BT_RESPONSE_TRIGGER_SIGNATURE(component, level) ((SL_RSI_DRIVER_PROCESS_BT_RESPONSE_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER_SIGNATURE(component, level) ((SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CB_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_CB_INIT_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GLOBAL_CB_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GLOBAL_CB_INIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_COMMON_INIT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_COMMON_INIT_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GAP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_GATT_EXTENDED_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_GATT_EXTENDED_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVDTP_EVENTS_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVDTP_EVENTS_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_PKT_CHANGE_EVENTS_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_PKT_CHANGE_EVENTS_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CHIP_MEMORY_STATUS_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_CHIP_MEMORY_STATUS_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AR_EVENTS_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AR_EVENTS_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_L2CAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_L2CAP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_HID_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_HID_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SPP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SPP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_A2DP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_A2DP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_AVRCP_TARGET_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_AVRCP_TARGET_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_HFP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_HFP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_PBAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_PBAP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_IAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_IAP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CALLBACKS_HANDLER_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_CALLBACKS_HANDLER_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_CALLBACKS_HANDLER_STATUS_SIGNATURE(component, level) ((SL_RSI_BT_CALLBACKS_HANDLER_STATUS & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_GAP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GAP_EXTENDED_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_GAP_EXTENDED_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_SMP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_SMP_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_GATT_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_GATT_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_L2CAP_CBSC_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_L2CAP_CBSC_REGISTER_CALLBACKS_TRIGGER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CALLBACKS_HANDLER_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BLE_CALLBACKS_HANDLER_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CALLBACKS_HANDLER_STATUS_SIGNATURE(component, level) ((SL_RSI_BLE_CALLBACKS_HANDLER_STATUS & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_CHIP_MEMORY_STATUS_CALLBACKS_REGISTER_SIGNATURE(component, level) ((SL_RSI_BLE_CHIP_MEMORY_STATUS_CALLBACKS_REGISTER & 0xfff) | (component << 18) | (level << 21)) +#define SL_RSI_BT_PREPARE_COMMON_PACKET_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_PREPARE_COMMON_PACKET_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_PREPARE_CLASSIC_PKT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_PREPARE_CLASSIC_PKT_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_PREPARE_LE_PKT_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_PREPARE_LE_PKT_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SEND_CMD_TRIGGER_SIGNATURE(component, level) ((SL_RSI_BT_SEND_CMD_TRIGGER & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE_SIGNATURE(component, level) ((SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BT_SEND_CMD_PROTOCOL_TYPE_SIGNATURE(component, level) ((SL_RSI_BT_SEND_CMD_PROTOCOL_TYPE & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_PACKET_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_RSI_ERROR_PACKET_ALLOCATION_FAILURE & 0xfff) | (1 << 12) | (1 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_BT_BLE_CMD_IN_PROGRESS_SIGNATURE(component, level) ((SL_RSI_ERROR_BT_BLE_CMD_IN_PROGRESS & 0xfff) | (1 << 12) | (3 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_ERROR_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_RSI_ERROR_PKT_ALLOCATION_FAILURE & 0xfff) | (1 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_BLE_ERROR_SIGNATURE(component, level) ((SL_RSI_BLE_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_SEMAPHORE_TIMEOUT_SIGNATURE(component, level) ((SL_RSI_SEMAPHORE_TIMEOUT & 0xfff) | (1 << 12) | (3 << 14) | (component << 18) | (level << 21)) +#define SL_RSI_BT_COMMAND_RESPONSE_STATUS_SIGNATURE(component, level) ((SL_RSI_BT_COMMAND_RESPONSE_STATUS & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_RSI_INIT_BT_STACK_SIGNATURE(component, level) ((SL_RSI_INIT_BT_STACK & 0xfff) | (0 << 12) | (component << 18) | (level << 21)) +#define SL_POWERSAVE_GPIO_INIT_ENTRY_SIGNATURE(component, level) ((SL_POWERSAVE_GPIO_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_POWERSAVE_GPIO_INIT_EXIT_SIGNATURE(component, level) ((SL_POWERSAVE_GPIO_INIT_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SPI_IFACE_INIT_ENTRY_SIGNATURE(component, level) ((SL_SPI_IFACE_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SPI_IFACE_INIT_EXIT_SIGNATURE(component, level) ((SL_SPI_IFACE_INIT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_ENTRY_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_EXIT_4_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_EXIT_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_EXIT_5_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_EXIT_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SDIO_IFACE_INIT_EXIT_6_SIGNATURE(component, level) ((SL_SDIO_IFACE_INIT_EXIT_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_UART_INIT_ENTRY_SIGNATURE(component, level) ((SL_UART_INIT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_UART_INIT_EXIT_SIGNATURE(component, level) ((SL_UART_INIT_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_SORT_SCAN_RESULTS_ENTRY_SIGNATURE(component, level) ((SL_SORT_SCAN_RESULTS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SORT_SCAN_RESULTS_EXIT_SIGNATURE(component, level) ((SL_SORT_SCAN_RESULTS_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_BITMAP_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SCAN_BITMAP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SCAN_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_BITMAP_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_SCAN_BITMAP_ERROR_IN_SENDING_COMMAND & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_BITMAP_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SCAN_BITMAP_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_BITMAP_EXIT_SIGNATURE(component, level) ((SL_WLAN_SCAN_BITMAP_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_6_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_7_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_WLAN_COMMAND_ERROR & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_BITMAP_EXIT_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_BITMAP_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SCAN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_SCAN_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SCAN_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_EXIT_SIGNATURE(component, level) ((SL_WLAN_SCAN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SCAN_ASYNC_EXIT_SIGNATURE(component, level) ((SL_WLAN_SCAN_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_EXIT_SIGNATURE(component, level) ((SL_WLAN_CONNECT_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_HE_PARAMS_SUPPORT_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_HE_PARAMS_SUPPORT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_3 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_WLAN_CMD_STATE_CHANGED_TO_ALLOW_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_WLAN_CMD_STATE_CHANGED_TO_ALLOW & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_4 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_5 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_7_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_6_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_6 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_8_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_7_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_7 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_9_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_8_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_8 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_10_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_10 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_9_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_9 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_11_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_11 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_10_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_10 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_12_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_12 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_11_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_11 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_13_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_13 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_12_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_12 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_14_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_14 & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_WLAN_COMMAND_ERROR & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONNECT_ASYNC_EXIT_SIGNATURE(component, level) ((SL_WLAN_CONNECT_ASYNC_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_BGSCAN_PROFILE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_BGSCAN_PROFILE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_BGSCAN_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_BGSCAN_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_BGSCAN_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_BGSCAN_PROFILE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_BGSCAN_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_BGSCAN_PROFILE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_BGSCAN_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_BGSCAN_PROFILE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ENRTY_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ENRTY & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_PUSH_BUTTON_EVENT_ENRTY_SIGNATURE(component, level) ((SL_WLAN_WPS_PUSH_BUTTON_EVENT_ENRTY & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_PUSH_BUTTON_EVENT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_WPS_PUSH_BUTTON_EVENT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_PUSH_BUTTON_EVENT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_WPS_PUSH_BUTTON_EVENT_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_PUSH_BUTTON_EVENT_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_WPS_PUSH_BUTTON_EVENT_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_PUSH_BUTTON_EVENT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_WPS_PUSH_BUTTON_EVENT_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_FREQ_OFFSET_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SEND_FREQ_OFFSET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_FREQ_OFFSET_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SEND_FREQ_OFFSET_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_FREQ_OFFSET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_SEND_FREQ_OFFSET_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_FREQ_OFFSET_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SEND_FREQ_OFFSET_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_FREQ_OFFSET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_SEND_FREQ_OFFSET_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_WRITE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_CALIB_WRITE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_CALIB_WRITE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_WRITE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_CALIB_WRITE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_WRITE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_CALIB_WRITE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_WRITE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_CALIB_WRITE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_READ_ENTRY_SIGNATURE(component, level) ((SL_WLAN_CALIB_READ_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_READ_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_CALIB_READ_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_READ_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_CALIB_READ_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_READ_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_CALIB_READ_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CALIB_READ_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_CALIB_READ_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_GENERATE_PIN_ENTRY_SIGNATURE(component, level) ((SL_WLAN_WPS_GENERATE_PIN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_GENERATE_PIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_WPS_GENERATE_PIN_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_GENERATE_PIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_WPS_GENERATE_PIN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_GENERATE_PIN_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_WPS_GENERATE_PIN_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_GENERATE_PIN_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_WPS_GENERATE_PIN_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_ENTER_PIN_ENTRY_SIGNATURE(component, level) ((SL_WLAN_WPS_ENTER_PIN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_ENTER_PIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_WPS_ENTER_PIN_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_ENTER_PIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_WPS_ENTER_PIN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_ENTER_PIN_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_WPS_ENTER_PIN_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WPS_ENTER_PIN_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_WPS_ENTER_PIN_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_RANDOM_BYTES_ENTRY_SIGNATURE(component, level) ((SL_WLAN_GET_RANDOM_BYTES_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_RANDOM_BYTES_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_GET_RANDOM_BYTES_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_RANDOM_BYTES_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_GET_RANDOM_BYTES_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_RANDOM_BYTES_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_GET_RANDOM_BYTES_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_RANDOM_BYTES_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_GET_RANDOM_BYTES_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_ENTRY_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_STATIONS_ENTRY_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_STATIONS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_STATIONS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_STATIONS_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_STATIONS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_STATIONS_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_STATIONS_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_STATIONS_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DISCONNECT_STATIONS_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_DISCONNECT_STATIONS_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONFIG_IPADDRESS_ENTRY_SIGNATURE(component, level) ((SL_WLAN_CONFIG_IPADDRESS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CONFIG_IPADDRESS_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_CONFIG_IPADDRESS_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONFIG_IPADDRESS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_CONFIG_IPADDRESS_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONFIG_IPADDRESS_CHANGE_WLAN_CMD_STATE_TO_ALLOW_SIGNATURE(component, level) ((SL_WLAN_CONFIG_IPADDRESS_CHANGE_WLAN_CMD_STATE_TO_ALLOW & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONFIG_IPADDRESS_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_CONFIG_IPADDRESS_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CONFIG_IPADDRESS_EXIT_SIGNATURE(component, level) ((SL_WLAN_CONFIG_IPADDRESS_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_INVALID_PARAM_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_INDEX_EXIT_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_INDEX_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_CERTIFICATE_EXIT_SIGNATURE(component, level) ((SL_WLAN_SET_CERTIFICATE_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_STATUS_EXIT_SIGNATURE(component, level) ((SL_WLAN_GET_STATUS_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_ENTRY_SIGNATURE(component, level) ((SL_WLAN_GET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_GET_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_FW_VERSION_QUERY_REQ_SIGNATURE(component, level) ((SL_WLAN_GET_FW_VERSION_QUERY_REQ & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_INSUFFICIENT_BUFFER_1_SIGNATURE(component, level) ((SL_WLAN_GET_INSUFFICIENT_BUFFER_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_INSUFFICIENT_BUFFER_2_SIGNATURE(component, level) ((SL_WLAN_GET_INSUFFICIENT_BUFFER_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_INSUFFICIENT_BUFFER_3_SIGNATURE(component, level) ((SL_WLAN_GET_INSUFFICIENT_BUFFER_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_7_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_7 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_INSUFFICIENT_BUFFER_4_SIGNATURE(component, level) ((SL_WLAN_GET_INSUFFICIENT_BUFFER_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_8_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_8 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_INSUFFICIENT_BUFFER_5_SIGNATURE(component, level) ((SL_WLAN_GET_INSUFFICIENT_BUFFER_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9_SIGNATURE(component, level) ((SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_GET_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_EXIT_SIGNATURE(component, level) ((SL_WLAN_GET_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SET_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SET_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_NVALID_PARAM_SIGNATURE(component, level) ((SL_WLAN_SET_NVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_SET_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_SET_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level) ((SL_WLAN_SET_PKT_ALLOCATION_FAILURE_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SET_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_EXIT_SIGNATURE(component, level) ((SL_WLAN_SET_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_BUFFER_CONFIG_ENTRY_SIGNATURE(component, level) ((SL_WLAN_BUFFER_CONFIG_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_BUFFER_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_BUFFER_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_BUFFER_CONFIG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_BUFFER_CONFIG_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_BUFFER_CONFIG_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_BUFFER_CONFIG_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_BUFFER_CONFIG_EXIT_SIGNATURE(component, level) ((SL_WLAN_BUFFER_CONFIG_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ENTRY_SIGNATURE(component, level) ((SL_WLAN_AP_START_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_AP_START_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level) ((SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level) ((SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level) ((SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_3 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level) ((SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_4 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level) ((SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_5 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_6_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level) ((SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_6 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_7_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_7 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_NWK_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_AP_START_NWK_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_8_SIGNATURE(component, level) ((SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_8 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_ENTRY_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_EXIT_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_PROFILE_EXIT_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_PROFILE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_POWER_SAVE_DISABLE_ENABLE_EXIT_SIGNATURE(component, level) ((SL_WLAN_POWER_SAVE_DISABLE_ENABLE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_START_ENTRY_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_START_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_START_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_START_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_START_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_START_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_START_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_START_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_STOP_ENTRY_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_STOP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_STOP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_STOP_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_STOP_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_STOP_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_STOP_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_STOP_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_TX_TEXT_STOP_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_TX_TEXT_STOP_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_START_ENTRY_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_START_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_START_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_START_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_START_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_START_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_START_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_START_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_START_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_START_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_STOP_ENTRY_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_STOP_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_STOP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_STOP_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_STOP_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_STOP_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_STOP_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_STOP_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RX_STATS_STOP_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_RX_STATS_STOP_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_START_DISCOVERY_ENTRY_SIGNATURE(component, level) ((SL_WLAN_WFD_START_DISCOVERY_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_START_DISCOVERY_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_WFD_START_DISCOVERY_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level) ((SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_1 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_START_DISCOVERY_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_WFD_START_DISCOVERY_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_START_DISCOVERY_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_WFD_START_DISCOVERY_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level) ((SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_2 & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_CONNECT_ENTRY_SIGNATURE(component, level) ((SL_WLAN_WFD_CONNECT_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_WFD_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_CONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_WFD_CONNECT_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_CONNECT_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_WFD_CONNECT_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_WFD_CONNECT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_WFD_CONNECT_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_DATA_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SEND_DATA_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_DATA_INVALID_PARAM_SIGNATURE(component, level) ((SL_WLAN_SEND_DATA_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_DATA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_SEND_DATA_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SEND_DATA_EXIT_SIGNATURE(component, level) ((SL_WLAN_SEND_DATA_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PING_ASYNC_ENTRY_SIGNATURE(component, level) ((SL_WLAN_PING_ASYNC_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_PING_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_PING_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PING_ASYNC_INVALID_PARAM_SIGNATURE(component, level) ((SL_WLAN_PING_ASYNC_INVALID_PARAM & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PING_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_PING_ASYNC_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PING_ASYNC_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_PING_ASYNC_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PING_ASYNC_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_PING_ASYNC_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_REGISTER_AUTO_CONFIG_RSP_HANDLER_EXIT_SIGNATURE(component, level) ((SL_WLAN_REGISTER_AUTO_CONFIG_RSP_HANDLER_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_PROFILE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_ADD_PROFILE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_ADD_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_ADD_PROFILE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_ADD_PROFILE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_ADD_PROFILE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_STATE_EXIT_SIGNATURE(component, level) ((SL_WLAN_GET_STATE_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PROFILE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_GET_PROFILE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_GET_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_GET_PROFILE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_GET_PROFILE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_GET_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_GET_PROFILE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_FILL_CONFIG_PROFILE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_FILL_CONFIG_PROFILE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_FILL_CONFIG_PROFILE_EXIT_SIGNATURE(component, level) ((SL_WLAN_FILL_CONFIG_PROFILE_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_DELETE_PROFILE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_DELETE_PROFILE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_DELETE_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_DELETE_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DELETE_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_DELETE_PROFILE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DELETE_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_DELETE_PROFILE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_DELETE_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_DELETE_PROFILE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ENABLE_AUTO_CONFIG_ENTRY_SIGNATURE(component, level) ((SL_WLAN_ENABLE_AUTO_CONFIG_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_ENABLE_AUTO_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_ENABLE_AUTO_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_ENABLE_AUTO_CONFIG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_ENABLE_AUTO_CONFIG_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ENABLE_AUTO_CONFIG_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_ENABLE_AUTO_CONFIG_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ENABLE_AUTO_CONFIG_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_ENABLE_AUTO_CONFIG_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PMK_GENERATE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_PMK_GENERATE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_PMK_GENERATE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_PMK_GENERATE_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_PMK_GENERATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_PMK_GENERATE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PMK_GENERATE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_PMK_GENERATE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_PMK_GENERATE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_PMK_GENERATE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_SLEEP_TIMER_ENTRY_SIGNATURE(component, level) ((SL_WLAN_SET_SLEEP_TIMER_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_SLEEP_TIMER_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_SET_SLEEP_TIMER_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_SLEEP_TIMER_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_SET_SLEEP_TIMER_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_SLEEP_TIMER_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_SET_SLEEP_TIMER_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_SET_SLEEP_TIMER_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_SET_SLEEP_TIMER_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_REGISTER_CALLBACKS_ENTRY_SIGNATURE(component, level) ((SL_WLAN_REGISTER_CALLBACKS_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_REGISTER_CALLBACKS_NUMBER_EXCEEDS_MAX_NUM_CALLBACKS_OR_CALLBACK_ALREADY_REG_SIGNATURE(component, level) ((SL_WLAN_REGISTER_CALLBACKS_NUMBER_EXCEEDS_MAX_NUM_CALLBACKS_OR_CALLBACK_ALREADY_REG & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_REGISTER_CALLBACKS_EXIT_SIGNATURE(component, level) ((SL_WLAN_REGISTER_CALLBACKS_EXIT & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_REQ_RADIO_ENTRY_SIGNATURE(component, level) ((SL_WLAN_REQ_RADIO_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_REQ_RADIO_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_WLAN_REQ_RADIO_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_REQ_RADIO_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_REQ_RADIO_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_REQ_RADIO_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_REQ_RADIO_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_REQ_RADIO_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_REQ_RADIO_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_RADIO_DEINIT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_RADIO_DEINIT_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_MFI_IE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_ADD_MFI_IE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_MFI_IE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_ADD_MFI_IE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_MFI_IE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_ADD_MFI_IE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_ADD_MFI_IE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_ADD_MFI_IE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_UPDATE_GAIN_TABLE_ENTRY_SIGNATURE(component, level) ((SL_WLAN_UPDATE_GAIN_TABLE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_UPDATE_GAIN_TABLE_INVALID_PARAM_SIGNATURE(component, level) ((SL_WLAN_UPDATE_GAIN_TABLE_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_UPDATE_GAIN_TABLE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_UPDATE_GAIN_TABLE_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_UPDATE_GAIN_TABLE_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_UPDATE_GAIN_TABLE_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_UPDATE_GAIN_TABLE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_UPDATE_GAIN_TABLE_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CSI_CONFIG_ENTRY_SIGNATURE(component, level) ((SL_WLAN_CSI_CONFIG_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_WLAN_CSI_CONFIG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_WLAN_CSI_CONFIG_PKT_ALLOCATION_FAILURE & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CSI_CONFIG_WLAN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_WLAN_CSI_CONFIG_WLAN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_WLAN_CSI_CONFIG_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level) ((SL_WLAN_CSI_CONFIG_ERROR_IN_SENDING_COMMAND & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_ENTRY_SIGNATURE(component, level) ((SL_SHA_PEN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_SHA_PEN_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_SHA_PEN_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_SHA_PEN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_SHA_PEN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SHA_PEN_EXIT_SIGNATURE(component, level) ((SL_SHA_PEN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SHA_ENTRY_SIGNATURE(component, level) ((SL_SHA_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_SHA_CHUNK_LENGTH_MSG_ERROR_SIGNATURE(component, level) ((SL_SHA_CHUNK_LENGTH_MSG_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_SHA_EXIT_SIGNATURE(component, level) ((SL_SHA_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_ENTRY_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_PEN_EXIT_SIGNATURE(component, level) ((SL_HMAC_SHA_PEN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_ENTRY_SIGNATURE(component, level) ((SL_HMAC_SHA_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_CHUNK_LENGTH_MSG_ERROR_SIGNATURE(component, level) ((SL_HMAC_SHA_CHUNK_LENGTH_MSG_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_HMAC_SHA_EXIT_SIGNATURE(component, level) ((SL_HMAC_SHA_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_AES_ENTRY_SIGNATURE(component, level) ((SL_AES_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_AES_CHUNK_LENGTH_MSG_ERROR_SIGNATURE(component, level) ((SL_AES_CHUNK_LENGTH_MSG_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_AES_EXIT_SIGNATURE(component, level) ((SL_AES_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_AES_PEN_ENTRY_SIGNATURE(component, level) ((SL_AES_PEN_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_AES_PEN_INVALID_PARAM_1_SIGNATURE(component, level) ((SL_AES_PEN_INVALID_PARAM_1 & 0xfff) | (component << 18) | (level << 21)) +#define SL_AES_PEN_INVALID_PARAM_2_SIGNATURE(component, level) ((SL_AES_PEN_INVALID_PARAM_2 & 0xfff) | (component << 18) | (level << 21)) +#define SL_AES_PEN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_AES_PEN_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_AES_PEN_COMMAND_ERROR_SIGNATURE(component, level) ((SL_AES_PEN_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_AES_PEN_EXIT_SIGNATURE(component, level) ((SL_AES_PEN_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EXPONENTIATION_ENTRY_SIGNATURE(component, level) ((SL_EXPONENTIATION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_EXPONENTIATION_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level) ((SL_EXPONENTIATION_COMMAND_GIVEN_IN_WRONG_STATE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EXPONENTIATION_INVALID_PARAM_SIGNATURE(component, level) ((SL_EXPONENTIATION_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_EXPONENTIATION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_EXPONENTIATION_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_EXPONENTIATION_COMMAND_ERROR_SIGNATURE(component, level) ((SL_EXPONENTIATION_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_EXPONENTIATION_EXIT_SIGNATURE(component, level) ((SL_EXPONENTIATION_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_MULTIPLICATION_ENTRY_SIGNATURE(component, level) ((SL_ECDH_POINT_MULTIPLICATION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_MULTIPLICATION_INVALID_PARAM_SIGNATURE(component, level) ((SL_ECDH_POINT_MULTIPLICATION_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_MULTIPLICATION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_ECDH_POINT_MULTIPLICATION_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_MULTIPLICATION_COMMAND_ERROR_SIGNATURE(component, level) ((SL_ECDH_POINT_MULTIPLICATION_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_MULTIPLICATION_EXIT_SIGNATURE(component, level) ((SL_ECDH_POINT_MULTIPLICATION_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_ADDITION_ENTRY_SIGNATURE(component, level) ((SL_ECDH_POINT_ADDITION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_ADDITION_INVALID_PARAM_SIGNATURE(component, level) ((SL_ECDH_POINT_ADDITION_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_ADDITION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_ECDH_POINT_ADDITION_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_ADDITION_COMMON_CMD_IN_PROGRESS_SIGNATURE(component, level) ((SL_ECDH_POINT_ADDITION_COMMON_CMD_IN_PROGRESS & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_ADDITION_EXIT_SIGNATURE(component, level) ((SL_ECDH_POINT_ADDITION_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_SUBTRACTION_ENTRY_SIGNATURE(component, level) ((SL_ECDH_POINT_SUBTRACTION_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_SUBTRACTION_INVALID_PARAM_SIGNATURE(component, level) ((SL_ECDH_POINT_SUBTRACTION_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_SUBTRACTION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_ECDH_POINT_SUBTRACTION_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_SUBTRACTION_COMMAND_ERROR_SIGNATURE(component, level) ((SL_ECDH_POINT_SUBTRACTION_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_SUBTRACTION_EXIT_SIGNATURE(component, level) ((SL_ECDH_POINT_SUBTRACTION_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_DOUBLE_ENTRY_SIGNATURE(component, level) ((SL_ECDH_POINT_DOUBLE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_DOUBLE_INVALID_PARAM_SIGNATURE(component, level) ((SL_ECDH_POINT_DOUBLE_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_DOUBLE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_ECDH_POINT_DOUBLE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_DOUBLE_COMMAND_ERROR_SIGNATURE(component, level) ((SL_ECDH_POINT_DOUBLE_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_DOUBLE_EXIT_SIGNATURE(component, level) ((SL_ECDH_POINT_DOUBLE_EXIT & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_AFFINE_ENTRY_SIGNATURE(component, level) ((SL_ECDH_POINT_AFFINE_ENTRY & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_AFFINE_INVALID_PARAM_SIGNATURE(component, level) ((SL_ECDH_POINT_AFFINE_INVALID_PARAM & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_AFFINE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level) ((SL_ECDH_POINT_AFFINE_PKT_ALLOCATION_FAILURE & 0xfff) | (component << 18) | (level << 21)) +#define SL_ECDH_POINT_AFFINE_COMMAND_ERROR_SIGNATURE(component, level) ((SL_ECDH_POINT_AFFINE_COMMAND_ERROR & 0xfff) | (3 << 12) | (component << 18) | (level << 21)) + +#define SL_PRINTF_SL_RSI_BT_AVRCP_INIT(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_INIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_CONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_CONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_DISCONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_DISCONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_PLAY_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_PLAY_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_PAUSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_PAUSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_STOP_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_STOP_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_NEXT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_NEXT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_PREV_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_PREV_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_VOL_UP_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_VOL_UP_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_VOL_DOWN_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_VOL_DOWN_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_GET_CAPABILITES_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_GET_CAPABILITES_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_ATT_LIST_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_ATT_LIST_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_ATT_VALS_LIST_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_ATT_VALS_LIST_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_CURR_ATT_VAL_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_CURR_ATT_VAL_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_CURR_ATT_VAL_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_CURR_ATT_VAL_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_ELEM_ATT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_ELEM_ATT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_PLAY_STATUS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_PLAY_STATUS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_REG_NOTIFICATION_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_REG_NOTIFICATION_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_REMOTE_VERSION_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_REMOTE_VERSION_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_ATT_TEXT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_ATT_TEXT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_GET_ATT_VAL_TEXT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_GET_ATT_VAL_TEXT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_BATT_STATUS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_BATT_STATUS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_SUPP_CHAR_SETS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_SUPP_CHAR_SETS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_SEND_ABS_VOLUME_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_SEND_ABS_VOLUME_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SEND_DEVICE_CAPABILITES_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SEND_DEVICE_CAPABILITES_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_ATT_LIST_RESP_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_ATT_LIST_RESP_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_ATT_VAL_LIST_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_ATT_VAL_LIST_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_CURR_ATT_VAL_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_CURR_ATT_VAL_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_SET_CURR_ATT_VAL_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_SET_CURR_ATT_VAL_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_ELE_ATT_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_ELE_ATT_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_PLAY_STATUS_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_PLAY_STATUS_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_REG_NOTIFY_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_REG_NOTIFY_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_ATT_TEXT_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_ATT_TEXT_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_ATT_VALS_TEXT_RESPONSE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_ATT_VALS_TEXT_RESPONSE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_BATT_STATUS_RESPONSE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_AVRCP_BATT_STATUS_RESPONSE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_AVRCP_CHAR_SET_STATUS_RESPONSE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_AVRCP_CHAR_SET_STATUS_RESPONSE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_AVRCP_NOTIFY_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_NOTIFY_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_CMD_REJECT_TRIGGER(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BT_AVRCP_CMD_REJECT_TRIGGER_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BT_AVRCP_SET_ABS_VOL_RESPONSE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_AVRCP_SET_ABS_VOL_RESPONSE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_AVRCP_SET_ADDR_PLAYER_RESPONSE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_AVRCP_SET_ADDR_PLAYER_RESPONSE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_AVRCP_GET_FOLDER_ITEMS_RESPONSE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_AVRCP_GET_FOLDER_ITEMS_RESPONSE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_AVRCP_GET_TOTAL_NUM_ITEMS_RESPONSE_TRIGGER(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BT_AVRCP_GET_TOTAL_NUM_ITEMS_RESPONSE_TRIGGER_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BT_SPP_INIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SPP_INIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SPP_CONN_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SPP_CONN_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SPP_DISCONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SPP_DISCONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_BD_ADDRESS(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_BD_ADDRESS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_ERROR_INVALID_PARAMETER(debug_id, component, level) sl_log_no_args(SL_RSI_ERROR_INVALID_PARAMETER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_BER_ENABLE_OR_DISABLE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_BER_ENABLE_OR_DISABLE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_LOCAL_NAME(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_LOCAL_NAME_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_LOCAL_NAME(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_LOCAL_NAME_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_RSSI(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_RSSI_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_LOCAL_DEVICE_ADDRESS(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_LOCAL_DEVICE_ADDRESS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_STACK_VERSION(debug_id, component, level) sl_log_no_args(SL_RSI_BT_STACK_VERSION_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_INIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_INIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_DEINIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_DEINIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_ANTENNA(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_ANTENNA_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_SET_FEATURE_MAP(debug_id, component, level) sl_log_no_args(SL_RSI_SET_FEATURE_MAP_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_ANTENNA_TX_POWER_LEVEL(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_ANTENNA_TX_POWER_LEVEL_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_POWER_SAVE_PROILE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_POWER_SAVE_PROILE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_REQUEST_LOCAL_DEVICE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_REQUEST_LOCAL_DEVICE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_PER_CW_MODE(debug_id, component, level) sl_log_no_args(SL_RSI_PER_CW_MODE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_VENDOR_AVDTP_STATS_ENABLE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_VENDOR_AVDTP_STATS_ENABLE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_VENDOR_AR_ENABLE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_VENDOR_AR_ENABLE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_VENDOR_DYNAMIC_POWER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_VENDOR_DYNAMIC_POWER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_MEMORY_STATS_ENABLE(debug_id, component, level) sl_log_no_args(SL_RSI_MEMORY_STATS_ENABLE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_L2CAP_CONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_L2CAP_CONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_L2CAP_DISCONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_L2CAP_DISCONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_L2CAP_INIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_L2CAP_INIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_L2CAP_SEND_DATA_REMOTE_DEVICE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_L2CAP_SEND_DATA_REMOTE_DEVICE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_L2CAP_CREATE_ERTM_CHANNEL_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_L2CAP_CREATE_ERTM_CHANNEL_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_INIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_INIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_CONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_CONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_DISCONNECT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_DISCONNECT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_SEND_PCM_MP3_DATA_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_SEND_PCM_MP3_DATA_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_SEND_SBC_AAC_DATA_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_SEND_SBC_AAC_DATA_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_START(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_START_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_SUSPEND(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_SUSPEND_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_CLOSE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_CLOSE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_ABORT(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_ABORT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_GET_CONFIG(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_GET_CONFIG_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_SET_CONFIG(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_SET_CONFIG_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_CONVERT_DB_TO_POWERINDEX_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_CONVERT_DB_TO_POWERINDEX_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_SET_RANDOM_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_SET_RANDOM_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_SET_RANDOM_ADDRESS_WITH_VALUE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_SET_RANDOM_ADDRESS_WITH_VALUE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_START_ADV_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_START_ADV_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_ENCRYPT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_ENCRYPT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_STOP_ADV_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_STOP_ADV_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_ADV_DATA_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_ADV_DATA_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_START_SCANNING_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_START_SCANNING_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_START_SCANNING_WITH_VALUES_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_START_SCANNING_WITH_VALUES_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_STOP_SCANNING_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_STOP_SCANNING_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_CONNECT_WITH_PARAMS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_CONNECT_WITH_PARAMS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_CONNECT_PARAMS_SCAN(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_CONNECT_PARAMS_SCAN_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_CONNECT_PARAMS_CONNECT(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BLE_CONNECT_PARAMS_CONNECT_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BLE_CONNECT(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_CONNECT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_CONNECT_CANCEL(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_CONNECT_CANCEL_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_DISCONNECT(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_DISCONNECT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_GET_DEVICE_STATE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_DEVICE_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_SMP_PAIRING_CAP_DATA(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_SMP_PAIRING_CAP_DATA_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_LOCAL_IRK_VALUE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_LOCAL_IRK_VALUE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_CONN_PARAM_RESPONSE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_CONN_PARAM_RESPONSE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_SMP_PAIR_REQUEST(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_SMP_PAIR_REQUEST_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_LTK_REQ_REPLY(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_LTK_REQ_REPLY_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_SMP_PAIR_RESPONSE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_SMP_PAIR_RESPONSE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_SMP_PASSKEY(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_SMP_PASSKEY_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_GET_LE_PING_TIMEOUT(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_LE_PING_TIMEOUT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_LE_PING_TIMEOUT(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_SET_LE_PING_TIMEOUT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_CLEAR_WHITELIST_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_CLEAR_WHITELIST_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_ADD_TO_WHITELIST(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_ADD_TO_WHITELIST_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_DELETEFROM_WHITELIST(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_DELETEFROM_WHITELIST_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_RESOLVLIST(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_RESOLVLIST_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_GET_RESOLVING_LIST_SIZE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_RESOLVING_LIST_SIZE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_ADDR_RESOULTION_ENABLE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_ADDR_RESOULTION_ENABLE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_PRIVACY_MODE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_SET_PRIVACY_MODE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_READPHY(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_READPHY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_SETPHY_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_SETPHY_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_CONN_PARMS_UPDATE(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BLE_CONN_PARMS_UPDATE_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BLE_SET_DATA_LEN(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_DATA_LEN_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_READ_MAX_DATA_LEN_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_READ_MAX_DATA_LEN_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_RX_TEST_MODE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_RX_TEST_MODE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_TX_TEST_MODE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_TX_TEST_MODE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_END_TEST_MODE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_END_TEST_MODE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_INIT_PER_TRANSMIT_MODE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_INIT_PER_TRANSMIT_MODE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_PER_RECIEVE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_PER_RECIEVE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_VENDOR_RF_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_VENDOR_RF_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_WHITELIST_USING_ADV_DATA(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_WHITELIST_USING_ADV_DATA_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_AD_PACKET_EXTRACT(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_AD_PACKET_EXTRACT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_UPDATE_DIRECTED_ADDRESS_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_UPDATE_DIRECTED_ADDRESS_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_ENCRYPTION_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_ENCRYPTION_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_BLE_TX_POWER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_BLE_TX_POWER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_LOCAL_CLASS_OF_DEVICE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SET_LOCAL_CLASS_OF_DEVICE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GET_LOCAL_CLASS_OF_DEVICE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GET_LOCAL_CLASS_OF_DEVICE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_DISCOVERY_MODE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_DISCOVERY_MODE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_LIMITED_DISCOVERY_MODE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_LIMITED_DISCOVERY_MODE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_PROFILES_HANDLE_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_PROFILES_HANDLE_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_PROFILES_UUID_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_PROFILES_UUID_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_CHAR_SERVICES_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_CHAR_SERVICES_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_INC_SERVICES_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_INC_SERVICES_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_ATT_DESCRIPTORS_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_ATT_DESCRIPTORS_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_ATT_VALUE_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_ATT_VALUE_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_GET_LONG_ATT_VALUE_ASYNC(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_GET_LONG_ATT_VALUE_ASYNC_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_SET_ATT_VALUE_ASYNC(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_SET_ATT_VALUE_ASYNC_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_PREPARE_WRITE_ASYNC(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BLE_PREPARE_WRITE_ASYNC_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BLE_EXECUTE_WRITE_ASYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_EXECUTE_WRITE_ASYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_PROFILES(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_PROFILES_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_PROFILE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_PROFILE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_CHAR_SERVICES(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_CHAR_SERVICES_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_INC_SERVICES(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_INC_SERVICES_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_CHAR_VALUE_BY_UUID_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_ATT_DESCRIPTORS(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_ATT_DESCRIPTORS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_ATT_VALUE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_ATT_VALUE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_GET_LONG_ATT_VALUE(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_GET_LONG_ATT_VALUE_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_SET_ATT_VALUE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SET_ATT_VALUE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_ATT_COMMAND(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_SET_ATT_COMMAND_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_SET_LONG_ATT_VALUE(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BLE_SET_LONG_ATT_VALUE_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BLE_PREPARE_WRITE(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BLE_PREPARE_WRITE_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BLE_EXECUTABLE_WRITE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_EXECUTABLE_WRITE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_ADD_SERVICE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_ADD_SERVICE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_ADD_ATTRIBUTE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_ADD_ATTRIBUTE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SET_LOCAL_ATT_VALUE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_SET_LOCAL_ATT_VALUE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_NOTIFY_VALUE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_NOTIFY_VALUE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_INDICATE_VOLUME_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_INDICATE_VOLUME_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_INDICATE_VALUE_SYNC(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_INDICATE_VALUE_SYNC_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_INDICATE_CONFIRM(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_INDICATE_CONFIRM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GET_LOCAL_ATT_VALUE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GET_LOCAL_ATT_VALUE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GATT_READ_RESPONSE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GATT_READ_RESPONSE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_REMOVE_GATT_SERVICE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_REMOVE_GATT_SERVICE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_REMOVE_GATT_ATTRIBUTE(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BLE_REMOVE_GATT_ATTRIBUTE_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BLE_ATT_ERROR_RESPONSE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_ATT_ERROR_RESPONSE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_MTU_EXCHANGE_EVENT(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_MTU_EXCHANGE_EVENT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GATT_WRITE_RESPONSE(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GATT_WRITE_RESPONSE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_BT_ADD_PAKCET_TO_LIST(debug_id, component, level) sl_log_no_args(SL_RSI_BT_ADD_PAKCET_TO_LIST_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_DELETE_PAKCET_FROM_LIST(debug_id, component, level) sl_log_no_args(SL_RSI_BT_DELETE_PAKCET_FROM_LIST_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_FREE_DATA_PACKET(debug_id, component, level) sl_log_no_args(SL_RSI_BT_FREE_DATA_PACKET_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_ALLOC_DATA_PACKET(debug_id, component, level) sl_log_no_args(SL_RSI_BT_ALLOC_DATA_PACKET_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_EVT_A2DP_DISCONNECT(debug_id, component, level) sl_log_no_args(SL_RSI_BT_EVT_A2DP_DISCONNECT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_APP_ERR_INVALID_INPUT(debug_id, component, level) sl_log_no_args(SL_RSI_APP_ERR_INVALID_INPUT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW(debug_id, component, level) sl_log_no_args(SL_RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_INVALID_SBC_PACKET(debug_id, component, level) sl_log_no_args(SL_RSI_INVALID_SBC_PACKET_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_CMD_A2DP_PCM_MP3_DATA(debug_id, component, level) sl_log_no_args(SL_RSI_BT_CMD_A2DP_PCM_MP3_DATA_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_CMD_SBC_INIT_SUCCESS(debug_id, component, level) sl_log_no_args(SL_RSI_BT_CMD_SBC_INIT_SUCCESS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_FREQUENCY_MISMATCH(debug_id, component, level) sl_log_no_args(SL_RSI_BT_FREQUENCY_MISMATCH_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_BLOCK_LENGTH_MISMATCH(debug_id, component, level) sl_log_no_args(SL_RSI_BT_BLOCK_LENGTH_MISMATCH_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SUBBANDS_MISMATCH(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SUBBANDS_MISMATCH_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_CHANNEL_MODE_MISMATCH(debug_id, component, level) sl_log_no_args(SL_RSI_BT_CHANNEL_MODE_MISMATCH_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_ALLOCATION_METHOD_MISMATCH(debug_id, component, level) sl_log_no_args(SL_RSI_BT_ALLOCATION_METHOD_MISMATCH_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_SBC_ENCODE(debug_id, component, level) sl_log_no_args(SL_RSI_SBC_ENCODE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_WEB_SOCKET_CREATE_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_EXIT_2(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CREATE_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CREATE_EXIT9(debug_id, component, level, format, a) sl_log_1_args(SL_WEB_SOCKET_CREATE_EXIT9_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WEB_SOCKET_SEND_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_SEND_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_SEND_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WEB_SOCKET_SEND_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WEB_SOCKET_CLOSE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WEB_SOCKET_CLOSE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WEB_SOCKET_CLOSE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WEB_SOCKET_CLOSE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_CLIENT_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_INIT_COMMAND_ERROR(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_INIT_COMMAND_ERROR_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_INIT_INSUFFICIENT_BUFFER_LENGTH(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_INIT_INSUFFICIENT_BUFFER_LENGTH_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_INIT_EXIT(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_INIT_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_CONNECT_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_CONNECT_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_CONNECT_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_CLIENT_CONNECT_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_CLIENT_CONNECT_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_CLIENT_CONNECT_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_CLIENT_DISCONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_MQTT_CLIENT_DISCONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_CLIENT_DISCONNECT_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_CLIENT_DISCONNECT_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_CLIENT_DISCONNECT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_CLIENT_DISCONNECT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_PUBLISH_ENTRY(debug_id, component, level) sl_log_no_args(SL_MQTT_PUBLISH_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_PUBLISH_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_MQTT_PUBLISH_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_PUBLISH_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_PUBLISH_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_SUBSCRIBE_ENTRY(debug_id, component, level) sl_log_no_args(SL_MQTT_SUBSCRIBE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_SUBSCRIBE_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_MQTT_SUBSCRIBE_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_SUBSCRIBE_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_MQTT_SUBSCRIBE_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_SUBSCRIBE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_SUBSCRIBE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_UNSUBSCRIBE_ENTRY(debug_id, component, level) sl_log_no_args(SL_MQTT_UNSUBSCRIBE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_SUBSCRIBE_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_MQTT_SUBSCRIBE_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_UNSUBSCRIBE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MQTT_UNSUBSCRIBE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MQTT_POLL_FOR_RECV_DATA_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_MQTT_POLL_FOR_RECV_DATA_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MQTT_POLL_FOR_RECV_DATA_EXIT(debug_id, component, level) sl_log_no_args(SL_MQTT_POLL_FOR_RECV_DATA_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_NVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ASYNC_NVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_ABORT_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_ABORT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_ABORT_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ABORT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_ABORT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ABORT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_ABORT_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_ABORT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_CREATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_PUT_CREATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_CREATE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_CREATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_CREATE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_CREATE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_CREATE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_CREATE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_DELETE_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_PUT_DELETE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_DELETE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_DELETE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_DELETE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_DELETE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_START_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_PUT_START_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_START_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_START_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_START_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_START_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_START_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_START_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_START_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_START_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_PKT_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_PUT_PKT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_PKT_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_PKT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_PKT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_PKT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_PUT_PKT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_PUT_PKT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_POST_DATA_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CLIENT_POST_DATA_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CLIENT_POST_DATA_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_POST_DATA_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_POST_DATA_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_POST_DATA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_POST_DATA_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_POST_DATA_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CLIENT_POST_DATA_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CLIENT_POST_DATA_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MULTICAST_ENTRY(debug_id, component, level) sl_log_no_args(SL_MULTICAST_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MULTICAST_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_MULTICAST_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MULTICAST_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_MULTICAST_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MULTICAST_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MULTICAST_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MULTICAST_JOIN_ENTRY(debug_id, component, level) sl_log_no_args(SL_MULTICAST_JOIN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MULTICAST_JOIN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MULTICAST_JOIN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MULTICAST_LEAVE_ENTRY(debug_id, component, level) sl_log_no_args(SL_MULTICAST_LEAVE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MULTICAST_LEAVE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MULTICAST_LEAVE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_OTAF_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_HTTP_OTAF_ASYNC_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_HTTP_OTAF_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_NWK_CMD_IN_PROGRESS(debug_id, component, level) sl_log_no_args(SL_HTTP_OTAF_ASYNC_NWK_CMD_IN_PROGRESS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_OTAF_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_OTAF_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DNS_REQ_ENTRY(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_PKT_ALLOCATION_FAILURE_1(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_DNS_REQ_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DNS_REQ_PKT_ALLOCATION_FAILURE_2(debug_id, component, level) sl_log_no_args(SL_DNS_REQ_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_REQ_EXIT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DNS_REQ_EXIT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DNS_REQ_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_DNS_REQ_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DNS_UPDATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_1(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_DNS_UPDATE_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_2(debug_id, component, level) sl_log_no_args(SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DNS_UPDATE_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DNS_UPDATE_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DNS_UPDATE_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_DNS_UPDATE_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DHCP_USER_CLASS_ENTRY(debug_id, component, level) sl_log_no_args(SL_DHCP_USER_CLASS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DHCP_USER_CLASS_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_DHCP_USER_CLASS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DHCP_USER_CLASS_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_DHCP_USER_CLASS_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DHCP_USER_CLASS_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_DHCP_USER_CLASS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DHCP_USER_CLASS_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DHCP_USER_CLASS_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DHCP_USER_CLASS_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_DHCP_USER_CLASS_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_CREATE_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_CREATE_ASYNC_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_CREATE_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_CREATE_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_CREATE_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_CREATE_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_ENTRY(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_GETTIME_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_GETTIME_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_GETTIME_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_GETTIME_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_DATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_GETTIME_DATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_DATE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_GETTIME_DATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_DATE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_GETTIME_DATE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_GETTIME_DATE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_GETTIME_DATE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_SERVER_INFO_ENTRY(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_SERVER_INFO_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_SERVER_INFO_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_SERVER_INFO_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_SERVER_INFO_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_SERVER_INFO_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_SERVER_INFO_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_SERVER_INFO_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_DELETE_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_DELETE_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SNTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SNTP_CLIENT_DELETE_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SNTP_CLIENT_DELETE_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CLIENT_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CLIENT_INIT_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CLIENT_INIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CLIENT_INIT_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_PARAMTER_LENGTH_EXCEEDS_MAX_VAL(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CLIENT_INIT_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CLIENT_INIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_CLIENT_INIT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_CLIENT_INIT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_CLIENT_INIT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CONNECT_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CONNECT_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CONNECT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_CONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_CONNECT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_CONNECT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_CONNECT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_CONNECT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_1(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_2(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_PUBLISH_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_PUBLISH_COMMAND_SEND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_PUBLISH_COMMAND_SEND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_SUBSCRIBE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_SUBSCRIBE_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_SUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_SUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_SUBSCRIBE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_SUBSCRIBE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_SUBSCRIBE_COMMAND_SEND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_SUBSCRIBE_COMMAND_SEND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_UNSUBSCRIBE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_UNSUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_UNSUBSCRIBE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_UNSUBSCRIBE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_SEND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_SEND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_DISCONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DISCONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DISCONNECT_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DISCONNECT_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DISCONNECT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DISCONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DISCONNECT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_DISCONNECT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_DISCONNECT_COMMAND_SEND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_DISCONNECT_COMMAND_SEND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_DESTROY_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DESTROY_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DESTROY_COMMAND_NOT_SUPPORTED(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DESTROY_COMMAND_NOT_SUPPORTED_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DESTROY_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DESTROY_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DESTROY_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_DESTROY_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_DESTROY_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_DESTROY_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_DESTROY_COMMAND_SEN_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EMB_MQTT_DESTROY_COMMAND_SEN_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EMB_MQTT_REGISTER_CALL_BACK_ENTRY(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_REGISTER_CALL_BACK_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_REGISTER_CALL_BACK_EXCEEDS_MAX_CALLBACKS(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_REGISTER_CALL_BACK_EXCEEDS_MAX_CALLBACKS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_REGISTER_CALL_BACK_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_REGISTER_CALL_BACK_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EMB_MQTT_REGISTER_CALL_BACK_EXIT(debug_id, component, level) sl_log_no_args(SL_EMB_MQTT_REGISTER_CALL_BACK_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CAL_MQTT_PACKET_LEN_ENTRY(debug_id, component, level) sl_log_no_args(SL_CAL_MQTT_PACKET_LEN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CAL_MQTT_PACKET_LEN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_CAL_MQTT_PACKET_LEN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FWUP_ENTRY(debug_id, component, level) sl_log_no_args(SL_FWUP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FWUP_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_FWUP_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FWUP_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FWUP_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FWUP_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FWUP_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FWUP_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_FWUP_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FWUP_START_ENTRY(debug_id, component, level) sl_log_no_args(SL_FWUP_START_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FWUP_START_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_FWUP_START_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FWUP_LOAD_ENTRY(debug_id, component, level) sl_log_no_args(SL_FWUP_LOAD_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FWUP_LOAD_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_FWUP_LOAD_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SEND_RAW_DATA_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_RAW_DATA_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_RAW_DATA_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_SEND_RAW_DATA_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_RAW_DATA_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_SEND_RAW_DATA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_RAW_DATA_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SEND_RAW_DATA_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DISCONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_DISCONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_FTP_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_1(debug_id, component, level) sl_log_no_args(SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_2(debug_id, component, level) sl_log_no_args(SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DISCONNECT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DISCONNECT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_WRITE_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_WRITE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_WRITE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_WRITE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_WRITE_CONTENT_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_CONTENT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_CONTENT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_WRITE_CONTENT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_WRITE_CONTENT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_WRITE_CONTENT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_WRITE_CONTENT_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_WRITE_CONTENT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_READ_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_READ_ASYNC_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_READ_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_READ_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_READ_ASYNC_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_READ_ASYNC_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_DELETE_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_DELETE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_DELETE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_DELETE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_DELETE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_DELETE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_RENAME_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_RENAME_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_RENAME_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_RENAME_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_RENAME_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_RENAME_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_RENAME_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_RENAME_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_CREATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_CREATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_CREATE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_CREATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_CREATE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_CREATE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_CREATE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_CREATE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_DELETE_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_DELETE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_DELETE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_DELETE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_DELETE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_DELETE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_SET_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_SET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_SET_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_SET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_SET_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_SET_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_SET_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_SET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_LIST_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_LIST_ASYNC_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_LIST_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_LIST_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_DIRECTORY_LIST_ASYNC_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_DIRECTORY_LIST_ASYNC_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_MODE_SET_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_MODE_SET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_MODE_SET_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_MODE_SET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_MODE_SET_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_MODE_SET_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_MODE_SET_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_MODE_SET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_SIZE_SET_ENTRY(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_SIZE_SET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FTP_FILE_SIZE_SET_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_SIZE_SET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_SIZE_SET_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_SIZE_SET_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FTP_FILE_SIZE_SET_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_FTP_FILE_SIZE_SET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_CREATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_CREATE_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_CREATE_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_CREATE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_CREATE_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_CREATE_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_2(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_MAIL_SEND_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_DELETE_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2(debug_id, component, level) sl_log_no_args(SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_DELETE_ASYNC_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SMTP_CLIENT_DELETE_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SMTP_CLIENT_DELETE_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_MSNSD_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MSNSD_INIT_INSUFFICIENT_BUFFER(debug_id, component, level) sl_log_no_args(SL_MSNSD_INIT_INSUFFICIENT_BUFFER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MSNSD_INIT_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_MSNSD_INIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_INIT_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_MSNSD_INIT_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_INIT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MSNSD_INIT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_REGISTER_SERVICE_ENTRY(debug_id, component, level) sl_log_no_args(SL_MSNSD_REGISTER_SERVICE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER(debug_id, component, level) sl_log_no_args(SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_REGISTER_SERVICE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_MSNSD_REGISTER_SERVICE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_MSNSD_DEINIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_MSNSD_DEINIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_MSNSD_DEINIT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_MSNSD_DEINIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_WEBPAGE_LOAD_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_WEBPAGE_LOAD_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_WEBPAGE_LOAD_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_LOAD_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_LOAD_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_LOAD_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_LOAD_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_LOAD_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_ERASE_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_WEBPAGE_ERASE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_WEBPAGE_ERASE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_ERASE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_ERASE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_ERASE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_ERASE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_ERASE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_JSON_OBJECT_DELETE_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_JSON_OBJECT_DELETE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_JSON_OBJECT_DELETE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_JSON_OBJECT_DELETE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_JSON_OBJECT_DELETE_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_JSON_OBJECT_DELETE_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_JSON_OBJECT_DELETE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_JSON_OBJECT_DELETE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_SEND_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_WEBPAGE_SEND_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_WEBPAGE_SEND_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_HTTP_WEBPAGE_SEND_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_WEBPAGE_SEND_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_SEND_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_SEND_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_SEND_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_WEBPAGE_SEND_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_WEBPAGE_SEND_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_REQ_WIRELESS_FWUP_ENTER(debug_id, component, level) sl_log_no_args(SL_REQ_WIRELESS_FWUP_ENTER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_REQ_WIRELESS_FWUP_EERROR_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_REQ_WIRELESS_FWUP_EERROR_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_REQ_WIRELESS_FWUP_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_REQ_WIRELESS_FWUP_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_REQ_WIRELESS_FWUP_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_REQ_WIRELESS_FWUP_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CREDENTIALS_ENTRY(debug_id, component, level) sl_log_no_args(SL_HTTP_CREDENTIALS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CREDENTIALS_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_HTTP_CREDENTIALS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CREDENTIALS_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_HTTP_CREDENTIALS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HTTP_CREDENTIALS_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CREDENTIALS_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HTTP_CREDENTIALS_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HTTP_CREDENTIALS_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_FD_ISSET_ENTRY(debug_id, component, level) sl_log_no_args(SL_FD_ISSET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_FD_ENTRY(debug_id, component, level) sl_log_no_args(SL_SET_FD_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FD_CLR_ENTRY(debug_id, component, level) sl_log_no_args(SL_FD_CLR_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_EXIT(debug_id, component, level) sl_log_no_args(SL_SOCKET_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BIND_ENTRY(debug_id, component, level) sl_log_no_args(SL_BIND_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_LISTEN_ENTRY(debug_id, component, level) sl_log_no_args(SL_LISTEN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_EXIT5(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_EXIT5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_8(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_9(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_10(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_10_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_SOCK_ERROR_11(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_SOCK_ERROR_11_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_NON_ROM_EXIT(debug_id, component, level) sl_log_no_args(SL_ACCEPT_NON_ROM_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ENTRY(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_LARGE_DATA_SYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_RECV_LARGE_DATA_SYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_LARGE_DATA_SYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_RECV_LARGE_DATA_SYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RECV_FROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_RECV_FROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_FROM_EXIT_1(debug_id, component, level) sl_log_no_args(SL_RECV_FROM_EXIT_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_FROM_EXIT_2(debug_id, component, level) sl_log_no_args(SL_RECV_FROM_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_FROM_EXIT_3(debug_id, component, level) sl_log_no_args(SL_RECV_FROM_EXIT_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_ENTRY(debug_id, component, level) sl_log_no_args(SL_RECV_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_EXIT_1(debug_id, component, level) sl_log_no_args(SL_RECV_EXIT_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_EXIT_2(debug_id, component, level) sl_log_no_args(SL_RECV_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RECV_EXIT_3(debug_id, component, level) sl_log_no_args(SL_RECV_EXIT_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ENTRY(debug_id, component, level) sl_log_no_args(SL_SENDTO_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_EXIT_1(debug_id, component, level) sl_log_no_args(SL_SEND_EXIT_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_EXIT_2(debug_id, component, level) sl_log_no_args(SL_SEND_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RESET_PER_SOCKET_INFO_ENTRY(debug_id, component, level) sl_log_no_args(SL_RESET_PER_SOCKET_INFO_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_SYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_LARGE_DATA_SYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_SYNC_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SEND_LARGE_DATA_SYNC_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_SYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SEND_LARGE_DATA_SYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_CHUNK_DATA_TX_DONE_CB_ENTRY(debug_id, component, level) sl_log_no_args(SL_CHUNK_DATA_TX_DONE_CB_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_LARGE_DATA_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_LARGE_DATA_ASYNC_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_SEND_LARGE_DATA_ASYNC_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SEND_LARGE_DATA_ASYNC_EXIT_2(debug_id, component, level) sl_log_no_args(SL_SEND_LARGE_DATA_ASYNC_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FIND_SOCKET_DATA_PENDING_ENTRY(debug_id, component, level) sl_log_no_args(SL_FIND_SOCKET_DATA_PENDING_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FIND_SOCKET_DATA_PENDING_EXIT(debug_id, component, level) sl_log_no_args(SL_FIND_SOCKET_DATA_PENDING_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_EVENT_HANDLER_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_EVENT_HANDLER_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_APPLICATON_SOCKET_DESCRIPTOR_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_APPLICATON_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CLEAR_SOCKETS_ENTRY(debug_id, component, level) sl_log_no_args(SL_CLEAR_SOCKETS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FILL_TLS_EXTENSION_ENTRY(debug_id, component, level) sl_log_no_args(SL_FILL_TLS_EXTENSION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FILL_TLS_EXTENSION_INSUFFICIENT_BUFFER(debug_id, component, level) sl_log_no_args(SL_FILL_TLS_EXTENSION_INSUFFICIENT_BUFFER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_FILL_TLS_EXTENSION_EXIT(debug_id, component, level) sl_log_no_args(SL_FILL_TLS_EXTENSION_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_ENTRY(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_1(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_2(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_3(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_4(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_5(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_6(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_7(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_8(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_9(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_10(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_10_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_11(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_11_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_12(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_12_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_13(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_13_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_14(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_14_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_15(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_15_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_16(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_16_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_17(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_17_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_18(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_18_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_19(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_19_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT_20(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT_20_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SETSOCKOPT_EXIT21(debug_id, component, level) sl_log_no_args(SL_SETSOCKOPT_EXIT21_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GETSOCKOPT_EXIT1(debug_id, component, level) sl_log_no_args(SL_GETSOCKOPT_EXIT1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GETSOCKOPT_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_GETSOCKOPT_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GETSOCKOPT_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_GETSOCKOPT_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GETSOCKOPT_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_GETSOCKOPT_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GETSOCKOPT_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_GETSOCKOPT_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GETSOCKOPT_EXIT(debug_id, component, level) sl_log_no_args(SL_GETSOCKOPT_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_SELECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_6(debug_id, component, level, format, a) sl_log_1_args(SL_SELECT_SOCK_ERROR_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_8(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_9(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_10(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_10_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SOCK_ERROR_11(debug_id, component, level) sl_log_no_args(SL_SELECT_SOCK_ERROR_11_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_8(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_9(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_SOCK_ERROR_10(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_SOCK_ERROR_10_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ACCEPT_ASYNC_EXIT(debug_id, component, level) sl_log_no_args(SL_ACCEPT_ASYNC_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_APP_SOCKET_DESCRIPTOR_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_APP_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_APP_SOCKET_DESCRIPTOR_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_GET_APP_SOCKET_DESCRIPTOR_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_APP_SOCKET_DESCRIPTOR_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GET_APP_SOCKET_DESCRIPTOR_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_SOCKET_ID_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_SOCKET_ID_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_SOCKET_ID_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_GET_SOCKET_ID_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_SOCKET_ID_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GET_SOCKET_ID_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_PRIMARY_SOCKET_ID_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_PRIMARY_SOCKET_ID_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_PRIMARY_SOCKET_ID_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_GET_PRIMARY_SOCKET_ID_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_PRIMARY_SOCKET_ID_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GET_PRIMARY_SOCKET_ID_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_CERTIFICATE_VALID_ENTRY(debug_id, component, level) sl_log_no_args(SL_CERTIFICATE_VALID_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CERTIFICATE_VALID_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_CERTIFICATE_VALID_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CERTIFICATE_VALID_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_CERTIFICATE_VALID_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CERTIFICATE_VALID_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_CERTIFICATE_VALID_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CERTIFICATE_VALID_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_CERTIFICATE_VALID_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SOCKET_CREATE_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_CREATE_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CREATE_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SOCKET_CREATE_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_TCP_WINDOW_UPDATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_SOCK_ERROR_5(debug_id, component, level, format, a) sl_log_1_args(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_SOCK_ERROR_6(debug_id, component, level, format, a) sl_log_1_args(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_TCP_WINDOW_UPDATE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_TCP_WINDOW_UPDATE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_SOCKET_DESCRIPTOR_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_SOCKET_DESCRIPTOR_SOCK_ERROR(debug_id, component, level) sl_log_no_args(SL_GET_SOCKET_DESCRIPTOR_SOCK_ERROR_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_SOCKET_DESCRIPTOR_EXIT(debug_id, component, level) sl_log_no_args(SL_GET_SOCKET_DESCRIPTOR_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_EXIT4(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_EXIT4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_8(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_9(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_ASYNC_NONO_ROM_EXIT(debug_id, component, level) sl_log_no_args(SL_SOCKET_ASYNC_NONO_ROM_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_CONNECT_EXIT(debug_id, component, level) sl_log_no_args(SL_SOCKET_CONNECT_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_SOCKET_RECVFROM_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SOCKET_RECVFROM_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_SOCKET_RECVFROM_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_RECVFROM_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_SOCKET_RECVFROM_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SOCKET_LISTEN_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_LISTEN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_LISTEN_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_LISTEN_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_LISTEN_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_LISTEN_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_LISTEN_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_LISTEN_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_LISTEN_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SOCKET_LISTEN_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_LISTEN_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SOCKET_LISTEN_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_LISTEN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SOCKET_LISTEN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_EXIT_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_EXIT_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_EXIT_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SOCKET_SHUTDOWN_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_SHUTDOWN_EXIT_3(debug_id, component, level, format, a) sl_log_1_args(SL_SOCKET_SHUTDOWN_EXIT_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SOCKET_BIND_ENTRY(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_8(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_SOCK_ERROR_9(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_SOCK_ERROR_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SOCKET_BIND_EXIT(debug_id, component, level) sl_log_no_args(SL_SOCKET_BIND_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WAIT_ON_SOCKET_SEMAPHORE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WAIT_ON_SOCKET_SEMAPHORE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WAIT_ON_SOCKET_SEMAPHORE_RESPONSE_TIMEOUT(debug_id, component, level) sl_log_no_args(SL_WAIT_ON_SOCKET_SEMAPHORE_RESPONSE_TIMEOUT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WAIT_ON_SOCKET_SEMAPHORE_ERROR_NONE(debug_id, component, level) sl_log_no_args(SL_WAIT_ON_SOCKET_SEMAPHORE_ERROR_NONE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_APPLICATION_SOCKET_DESCRIPTOR_ENTRY(debug_id, component, level) sl_log_no_args(SL_APPLICATION_SOCKET_DESCRIPTOR_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_APPLICATION_SOCKET_DESCRIPTOR_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_APPLICATION_SOCKET_DESCRIPTOR_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_APPLICATION_SOCKET_DESCRIPTOR_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_APPLICATION_SOCKET_DESCRIPTOR_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SOCKET_GET_STATUS_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SOCKET_GET_STATUS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SOCKET_SET_STATUS_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SOCKET_SET_STATUS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_GET_STATUS_ENTRY(debug_id, component, level) sl_log_no_args(SL_SELECT_GET_STATUS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SELECT_SET_STATUS_ENTRY(debug_id, component, level) sl_log_no_args(SL_SELECT_SET_STATUS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_ASYNC_NON_ROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_ASYNC_NON_ROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_ASYNC_NON_ROM_SOCK_ERROR(debug_id, component, level) sl_log_no_args(SL_SEND_ASYNC_NON_ROM_SOCK_ERROR_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_ASYNC_NON_ROM_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SEND_ASYNC_NON_ROM_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_1(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_ERROR_EBADF(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_ERROR_EBADF_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_2(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_3(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_4(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_5(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_EXIT_1(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_EXIT_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_6(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_EXIT_2(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_EXIT_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_7(debug_id, component, level) sl_log_no_args(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CLEAR_SOCKET_NON_ROM_ENTRY(debug_id, component, level) sl_log_no_args(SL_CLEAR_SOCKET_NON_ROM_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DRIVER_INIT_MAX_SOCKETS_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_INIT_MAX_SOCKETS_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_INIT_INSUFFICIENT_BUFFER_2(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_INIT_INSUFFICIENT_BUFFER_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_INIT_UART_INIT_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_INIT_UART_INIT_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_INIT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_INIT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_WIRELESS_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WIRELESS_INIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_INIT_CARD_READY_TIMEOUT(debug_id, component, level) sl_log_no_args(SL_WIRELESS_INIT_CARD_READY_TIMEOUT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_INIT_RESPONSE_TIMEOUT(debug_id, component, level) sl_log_no_args(SL_WIRELESS_INIT_RESPONSE_TIMEOUT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_INIT_EXIT1(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_INIT_EXIT1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_INIT_EXIT2(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_INIT_EXIT2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_INIT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WIRELESS_INIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_INIT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_INIT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_INIT_EXIT3(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_INIT_EXIT3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_CMD_UART_FLOW_CTRL_ENTRY(debug_id, component, level) sl_log_no_args(SL_CMD_UART_FLOW_CTRL_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_CMD_UART_FLOW_CTRL_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_CMD_UART_FLOW_CTRL_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_CMD_UART_FLOW_CTRL_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_CMD_UART_FLOW_CTRL_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_CMD_UART_FLOW_CTRL_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_CMD_UART_FLOW_CTRL_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY(debug_id, component, level) sl_log_no_args(SL_CMD_M4_TA_SECURE_HANDSHAKE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SI_CMD_M4_TA_SECURE_HANDSHAKE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_DEINIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_WIRELESS_DEINIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_DEINIT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WIRELESS_DEINIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_DEINIT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_DEINIT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_DEINIT_DRIVER_INIT_ERROR_1(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_DEINIT_DRIVER_INIT_ERROR_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_DEINIT_DEVICE_INIT_ERROR_2(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_DEINIT_DEVICE_INIT_ERROR_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_DEINIT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_DEINIT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_ANTENNA_ENTRY(debug_id, component, level) sl_log_no_args(SL_WIRELESS_ANTENNA_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_ANTENNA_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WIRELESS_ANTENNA_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_ANTENNA_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WIRELESS_ANTENNA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_ANTENNA_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_ANTENNA_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_ANTENNA_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WIRELESS_ANTENNA_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SEND_FEATURE_FRAME_ENTRY(debug_id, component, level) sl_log_no_args(SL_SEND_FEATURE_FRAME_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_SEND_FEATURE_FRAME_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_SEND_FEATURE_FRAME_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SEND_FEATURE_FRAME_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SEND_FEATURE_FRAME_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SEND_FEATURE_FRAME_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SEND_FEATURE_FRAME_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_FW_VERSION_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_FW_VERSION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_FW_VERSION_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_GET_FW_VERSION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_FW_VERSION_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_GET_FW_VERSION_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_FW_VERSION_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GET_FW_VERSION_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_COMMON_DEBUG_LOG_ENTRY(debug_id, component, level) sl_log_no_args(SL_COMMON_DEBUG_LOG_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_COMMON_DEBUG_LOG_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_COMMON_DEBUG_LOG_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_COMMON_DEBUG_LOG_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_COMMON_DEBUG_LOG_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_COMMON_DEBUG_LOG_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_COMMON_DEBUG_LOG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_COMMON_DEBUG_LOG_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_COMMON_DEBUG_LOG_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_COMMON_DEBUG_LOG_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_COMMON_DEBUG_LOG_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SWITCH_PROTO_ENTRY(debug_id, component, level) sl_log_no_args(SL_SWITCH_PROTO_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SWITCH_PROTO_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_SWITCH_PROTO_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SWITCH_PROTO_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_SWITCH_PROTO_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SWITCH_PROTO_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_SWITCH_PROTO_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SWITCH_PROTO_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SWITCH_PROTO_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SWITCH_PROTO_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SWITCH_PROTO_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WIRELESS_DRIVER_TASK_ENTRY(debug_id, component, level) sl_log_no_args(SL_WIRELESS_DRIVER_TASK_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WIRELESS_DRIVER_TASK_EXIT(debug_id, component, level) sl_log_no_args(SL_WIRELESS_DRIVER_TASK_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DRIVER_DEINIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_DRIVER_DEINIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_1(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_2(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_3(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_4(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_5(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_6(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_7(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_7_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_8(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_8_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_9(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_9_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_10(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_10_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_11(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_11_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_12(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_12_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_13(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_13_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_14(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_14_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_15(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_15_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_16(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_16_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_17(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_17_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_18(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_18_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_19(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_19_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_20(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_20_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_21(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_21_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_22(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_22_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_23(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_23_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_24(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_24_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_25(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_25_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_26(debug_id, component, level) sl_log_no_args(SL_DRIVER_DEINIT_SEMAPHORE_DESTROY_FAILED_26_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DRIVER_DEINIT_TASK_DESTROY_ENTRY(debug_id, component, level) sl_log_no_args(SL_DRIVER_DEINIT_TASK_DESTROY_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DRIVER_DEINIT_TASK_DESTROY_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_DRIVER_DEINIT_TASK_DESTROY_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DRIVER_VERSION_ENTRY(debug_id, component, level) sl_log_no_args(SL_DRIVER_VERSION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DRIVER_VERSION_EXIT(debug_id, component, level) sl_log_no_args(SL_DRIVER_VERSION_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_RTC_TIMER_ENTRY(debug_id, component, level) sl_log_no_args(SL_SET_RTC_TIMER_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_SET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SET_RTC_TIMER_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_SET_RTC_TIMER_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_RTC_TIMER_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SET_RTC_TIMER_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SET_RTC_TIMER_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SET_RTC_TIMER_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_RAM_LOG_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_RAM_LOG_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_RAM_LOG_EXIT1(debug_id, component, level, format, a) sl_log_1_args(SL_GET_RAM_LOG_EXIT1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_RAM_LOG_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_GET_RAM_LOG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_RAM_LOG_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_GET_RAM_LOG_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_RAM_LOG_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GET_RAM_LOG_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_UNREGISTER_EVENTS_CALLBACK_ENTRY(debug_id, component, level) sl_log_no_args(SL_UNREGISTER_EVENTS_CALLBACK_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_UNREGISTER_EVENTS_CALLBACK_EXIT(debug_id, component, level) sl_log_no_args(SL_UNREGISTER_EVENTS_CALLBACK_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_ENTRY(debug_id, component, level) sl_log_no_args(SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_EXIT(debug_id, component, level) sl_log_no_args(SL_REGISTER_WAIT_TIMEOUT_ERROR_CALLBACKS_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_RTC_TIMER_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_RTC_TIMER_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_GET_RTC_TIMER_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_RTC_TIMER_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_GET_RTC_TIMER_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_RTC_TIMER_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_GET_RTC_TIMER_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_RTC_TIMER_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GET_RTC_TIMER_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ASSERT_ENTRY(debug_id, component, level) sl_log_no_args(SL_ASSERT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ASSERT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_ASSERT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ASSERT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_ASSERT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ASSERT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_ASSERT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ASSERT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_ASSERT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_PININIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_GPIO_PININIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GPIO_PININIT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_PININIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_PININIT_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_GPIO_PININIT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GPIO_PININIT_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_PININIT_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_PININIT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_PININIT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_WRITEPIN_ENTRY(debug_id, component, level) sl_log_no_args(SL_GPIO_WRITEPIN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GPIO_WRITEPIN_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_WRITEPIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_WRITEPIN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_GPIO_WRITEPIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GPIO_WRITEPIN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_WRITEPIN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_WRITEPIN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_WRITEPIN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_READPIN_ENTRY(debug_id, component, level) sl_log_no_args(SL_GPIO_READPIN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GPIO_READPIN_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_READPIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_READPIN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_GPIO_READPIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GPIO_READPIN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_READPIN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GPIO_READPIN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_GPIO_READPIN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_DEVICE_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DEVICE_INIT_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_EXIT_3(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_EXIT_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_EXIT_4(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_EXIT_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_MODULE_POWER_CYCLE_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_MODULE_POWER_CYCLE_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_SPI_INIT_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_SPI_INIT_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_BL_WAIT_FOR_BOARD_READY_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_BL_WAIT_FOR_BOARD_READY_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_BOARD_READY_TIMEOUT(debug_id, component, level) sl_log_no_args(SL_DEVICE_INIT_BOARD_READY_TIMEOUT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DEVICE_INIT_SET_INTR_TYPE_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_SET_INTR_TYPE_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_SET_FAST_FIRMWARE_UP_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_BL_SELECT_OPTION_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_BL_SELECT_OPTION_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_HIGH_SPEED_ENABLE_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_HIGH_SPEED_ENABLE_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_EXIT_5(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_INIT_EXIT_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_DEINIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_DEVICE_DEINIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_DEVICE_DEINIT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_DEVICE_DEINIT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_DEVICE_INIT_EXIT(debug_id, component, level) sl_log_no_args(SL_DEVICE_INIT_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_WAITFOR_BOARDREADY_ENTRY(debug_id, component, level) sl_log_no_args(SL_BL_WAITFOR_BOARDREADY_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_WAITFOR_BOARDREADY_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_BL_WAITFOR_BOARDREADY_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_BL_WAITFOR_BOARDREADY_BOOTLOADER_VERSION_NOT_MATCHING(debug_id, component, level) sl_log_no_args(SL_BL_WAITFOR_BOARDREADY_BOOTLOADER_VERSION_NOT_MATCHING_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_WAITFOR_BOARDREADY_SUCCESS(debug_id, component, level) sl_log_no_args(SL_BL_WAITFOR_BOARDREADY_SUCCESS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_WAITFOR_BOARDREADY_WAITING_FOR_BOARD_READY(debug_id, component, level) sl_log_no_args(SL_BL_WAITFOR_BOARDREADY_WAITING_FOR_BOARD_READY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_ENTRY(debug_id, component, level) sl_log_no_args(SL_BL_UPGRADE_FIRMWARE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_EXIT1(debug_id, component, level, format, a) sl_log_1_args(SL_BL_UPGRADE_FIRMWARE_EXIT1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_EXIT2(debug_id, component, level, format, a) sl_log_1_args(SL_BL_UPGRADE_FIRMWARE_EXIT2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_EXIT3(debug_id, component, level) sl_log_no_args(SL_BL_UPGRADE_FIRMWARE_EXIT3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_EXIT4(debug_id, component, level, format, a) sl_log_1_args(SL_BL_UPGRADE_FIRMWARE_EXIT4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_EXIT5(debug_id, component, level, format, a) sl_log_1_args(SL_BL_UPGRADE_FIRMWARE_EXIT5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_BL_UPGRADE_FIRMWARE_EXIT6(debug_id, component, level) sl_log_no_args(SL_BL_UPGRADE_FIRMWARE_EXIT6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_FAST_FW_UP_ENTRY(debug_id, component, level) sl_log_no_args(SL_SET_FAST_FW_UP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_SDIO_IFACE_INIT_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_SDIO_IFACE_INIT_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_EXIT_3(debug_id, component, level, format, a) sl_log_1_args(SL_SDIO_IFACE_INIT_EXIT_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_GET_ROM_VERSION_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_ROM_VERSION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_GET_RAM_DUMP_ENTRY(debug_id, component, level) sl_log_no_args(SL_GET_RAM_DUMP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_RTC_TIMER_NULL_BUFFER(debug_id, component, level) sl_log_no_args(SL_SET_RTC_TIMER_NULL_BUFFER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SET_RTC_TIMER_BUFFER_LENGTH_ERROR(debug_id, component, level) sl_log_no_args(SL_SET_RTC_TIMER_BUFFER_LENGTH_ERROR_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_MODULE_POWER_CYCLE_ENTRY(debug_id, component, level) sl_log_no_args(SL_BL_MODULE_POWER_CYCLE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_BL_MODULE_POWER_CYCLE_EXIT(debug_id, component, level) sl_log_no_args(SL_BL_MODULE_POWER_CYCLE_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_NWK_REGISTER_CALLBACKS_ENTRY(debug_id, component, level) sl_log_no_args(SL_NWK_REGISTER_CALLBACKS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_NWK_REGISTER_CALLBACKS_EXCEEDS_MAX_CALLBACKS(debug_id, component, level) sl_log_no_args(SL_NWK_REGISTER_CALLBACKS_EXCEEDS_MAX_CALLBACKS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_NWK_REGISTER_CALLBACKS_EXIT(debug_id, component, level) sl_log_no_args(SL_NWK_REGISTER_CALLBACKS_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_RADIO_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_6(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_6(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_7(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_7_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_8(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_8_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_INIT_EXIT_9(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_INIT_EXIT_9_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_FILTER_BROADCAST_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_FILTER_BROADCAST_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_FILTER_BROADCAST_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_FILTER_BROADCAST_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_FILTER_BROADCAST_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_FILTER_BROADCAST_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_FILTER_BROADCAST_COMMAND_SEN_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_FILTER_BROADCAST_COMMAND_SEN_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_ERROR_TIMEOUT(debug_id, component, level, format, a, b, c) sl_log_3_args(SL_RSI_ERROR_TIMEOUT_SIGNATURE(component, level), a, b, c) +#define SL_PRINTF_SL_RSI_ERROR_TIMEOUT_FRAME_TYPE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_ERROR_TIMEOUT_FRAME_TYPE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_ERROR_TIMEOUT_READ(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_ERROR_TIMEOUT_READ_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_CLEAR_WAIT_BITMAP_TRIGGER(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BT_CLEAR_WAIT_BITMAP_TRIGGER_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BT_SET_WAIT_BITMAP_TRIGGER(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BT_SET_WAIT_BITMAP_TRIGGER_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BT_GET_ACL_TYPE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_GET_ACL_TYPE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_GET_PROTO_TYPE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_GET_PROTO_TYPE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_GET_TIMEOUT_TRIGGER(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_BT_GET_TIMEOUT_TRIGGER_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BT_COMMON_TX_DONE(debug_id, component, level) sl_log_no_args(SL_RSI_BT_COMMON_TX_DONE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_STATE_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_STATE_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SET_STATUS_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_SET_STATUS_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_DRIVER_PROCESS_BT_RESPONSE_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_DRIVER_PROCESS_BT_RESPONSE_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_CB_INIT_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_CB_INIT_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_GLOBAL_CB_INIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GLOBAL_CB_INIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_COMMON_INIT_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_COMMON_INIT_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GAP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_GATT_EXTENDED_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_GATT_EXTENDED_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVDTP_EVENTS_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVDTP_EVENTS_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_PKT_CHANGE_EVENTS_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_PKT_CHANGE_EVENTS_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_CHIP_MEMORY_STATUS_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_CHIP_MEMORY_STATUS_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AR_EVENTS_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AR_EVENTS_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_L2CAP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_L2CAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_HID_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_HID_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_SPP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_SPP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_A2DP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_A2DP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_AVRCP_TARGET_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_AVRCP_TARGET_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_HFP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_HFP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_PBAP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_PBAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_IAP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BT_IAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_CALLBACKS_HANDLER_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_CALLBACKS_HANDLER_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_CALLBACKS_HANDLER_STATUS(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_CALLBACKS_HANDLER_STATUS_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_GAP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GAP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GAP_EXTENDED_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GAP_EXTENDED_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_SMP_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_SMP_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_GATT_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_GATT_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_L2CAP_CBSC_REGISTER_CALLBACKS_TRIGGER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_L2CAP_CBSC_REGISTER_CALLBACKS_TRIGGER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BLE_CALLBACKS_HANDLER_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_CALLBACKS_HANDLER_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_CALLBACKS_HANDLER_STATUS(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_CALLBACKS_HANDLER_STATUS_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_CHIP_MEMORY_STATUS_CALLBACKS_REGISTER(debug_id, component, level) sl_log_no_args(SL_RSI_BLE_CHIP_MEMORY_STATUS_CALLBACKS_REGISTER_SIGNATURE(component, level)) +#define SL_PRINTF_SL_RSI_BT_PREPARE_COMMON_PACKET_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_PREPARE_COMMON_PACKET_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_PREPARE_CLASSIC_PKT_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_PREPARE_CLASSIC_PKT_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_PREPARE_LE_PKT_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_PREPARE_LE_PKT_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_SEND_CMD_TRIGGER(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_SEND_CMD_TRIGGER_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_ERROR_COMMAND_GIVEN_IN_WORNG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BT_SEND_CMD_PROTOCOL_TYPE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_SEND_CMD_PROTOCOL_TYPE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_ERROR_PACKET_ALLOCATION_FAILURE(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_ERROR_PACKET_ALLOCATION_FAILURE_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_ERROR_BT_BLE_CMD_IN_PROGRESS(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_ERROR_BT_BLE_CMD_IN_PROGRESS_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_ERROR_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_ERROR_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_BLE_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BLE_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_SEMAPHORE_TIMEOUT(debug_id, component, level, format, a, b) sl_log_2_args(SL_RSI_SEMAPHORE_TIMEOUT_SIGNATURE(component, level), a, b) +#define SL_PRINTF_SL_RSI_BT_COMMAND_RESPONSE_STATUS(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_BT_COMMAND_RESPONSE_STATUS_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_RSI_INIT_BT_STACK(debug_id, component, level, format, a) sl_log_1_args(SL_RSI_INIT_BT_STACK_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_POWERSAVE_GPIO_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_POWERSAVE_GPIO_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_POWERSAVE_GPIO_INIT_EXIT(debug_id, component, level) sl_log_no_args(SL_POWERSAVE_GPIO_INIT_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SPI_IFACE_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_SPI_IFACE_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SPI_IFACE_INIT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SPI_IFACE_INIT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_SDIO_IFACE_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_EXIT_4(debug_id, component, level, format, a) sl_log_1_args(SL_SDIO_IFACE_INIT_EXIT_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_EXIT_5(debug_id, component, level, format, a) sl_log_1_args(SL_SDIO_IFACE_INIT_EXIT_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SDIO_IFACE_INIT_EXIT_6(debug_id, component, level, format, a) sl_log_1_args(SL_SDIO_IFACE_INIT_EXIT_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_UART_INIT_ENTRY(debug_id, component, level) sl_log_no_args(SL_UART_INIT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_UART_INIT_EXIT(debug_id, component, level) sl_log_no_args(SL_UART_INIT_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SORT_SCAN_RESULTS_ENTRY(debug_id, component, level) sl_log_no_args(SL_SORT_SCAN_RESULTS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SORT_SCAN_RESULTS_EXIT(debug_id, component, level) sl_log_no_args(SL_SORT_SCAN_RESULTS_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_BITMAP_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_BITMAP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_BITMAP_ERROR_IN_SENDING_COMMAND(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_BITMAP_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_BITMAP_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_BITMAP_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_BITMAP_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_BITMAP_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_1(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_2(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_3(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_4(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_4(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_5(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_5(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_6(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_6(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_7(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_WLAN_COMMAND_ERROR(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_BITMAP_WLAN_COMMAND_ERROR_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_BITMAP_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_BITMAP_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SCAN_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_6(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SCAN_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SCAN_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONNECT_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONNECT_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_1(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_HE_PARAMS_SUPPORT(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_HE_PARAMS_SUPPORT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_2(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_3(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_4(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_WLAN_CMD_STATE_CHANGED_TO_ALLOW(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_WLAN_CMD_STATE_CHANGED_TO_ALLOW_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_5(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_4(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_6(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_5(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_7(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_6(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_6_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_8(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_7(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_7_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_9(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_8(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_8_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_10(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_10_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_9(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_9_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_11(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_11_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_10(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_10_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_12(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_12_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_11(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_11_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_13(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_13_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_12(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_12_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_14(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_14_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_WLAN_COMMAND_ERROR(debug_id, component, level) sl_log_no_args(SL_WLAN_CONNECT_ASYNC_WLAN_COMMAND_ERROR_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONNECT_ASYNC_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONNECT_ASYNC_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_BGSCAN_PROFILE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_BGSCAN_PROFILE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_BGSCAN_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_BGSCAN_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_BGSCAN_PROFILE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WLAN_BGSCAN_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_BGSCAN_PROFILE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_BGSCAN_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_BGSCAN_PROFILE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_BGSCAN_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ENRTY(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ENRTY_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_PUSH_BUTTON_EVENT_ENRTY(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_PUSH_BUTTON_EVENT_ENRTY_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_PUSH_BUTTON_EVENT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_PUSH_BUTTON_EVENT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_PUSH_BUTTON_EVENT_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_PUSH_BUTTON_EVENT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_PUSH_BUTTON_EVENT_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_PUSH_BUTTON_EVENT_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_PUSH_BUTTON_EVENT_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_PUSH_BUTTON_EVENT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_FREQ_OFFSET_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SEND_FREQ_OFFSET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SEND_FREQ_OFFSET_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_FREQ_OFFSET_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_FREQ_OFFSET_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_FREQ_OFFSET_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_FREQ_OFFSET_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_FREQ_OFFSET_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_FREQ_OFFSET_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_FREQ_OFFSET_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_WRITE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_CALIB_WRITE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CALIB_WRITE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_WRITE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_WRITE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_WRITE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_WRITE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_WRITE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_WRITE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_READ_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_CALIB_READ_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CALIB_READ_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_READ_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_READ_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_READ_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_READ_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_READ_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CALIB_READ_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CALIB_READ_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_GENERATE_PIN_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_WPS_GENERATE_PIN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WPS_GENERATE_PIN_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_WPS_GENERATE_PIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WPS_GENERATE_PIN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WLAN_WPS_GENERATE_PIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WPS_GENERATE_PIN_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_GENERATE_PIN_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_GENERATE_PIN_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_GENERATE_PIN_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_ENTER_PIN_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_WPS_ENTER_PIN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WPS_ENTER_PIN_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_WPS_ENTER_PIN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WPS_ENTER_PIN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WLAN_WPS_ENTER_PIN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WPS_ENTER_PIN_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_ENTER_PIN_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WPS_ENTER_PIN_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WPS_ENTER_PIN_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_RANDOM_BYTES_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_RANDOM_BYTES_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_RANDOM_BYTES_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_RANDOM_BYTES_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_RANDOM_BYTES_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_RANDOM_BYTES_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_RANDOM_BYTES_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_RANDOM_BYTES_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_RANDOM_BYTES_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_RANDOM_BYTES_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_DISCONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_DISCONNECT_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_STATIONS_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_DISCONNECT_STATIONS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_DISCONNECT_STATIONS_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_STATIONS_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_STATIONS_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_STATIONS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_STATIONS_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_STATIONS_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DISCONNECT_STATIONS_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DISCONNECT_STATIONS_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONFIG_IPADDRESS_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_CONFIG_IPADDRESS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CONFIG_IPADDRESS_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONFIG_IPADDRESS_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONFIG_IPADDRESS_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONFIG_IPADDRESS_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONFIG_IPADDRESS_CHANGE_WLAN_CMD_STATE_TO_ALLOW(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONFIG_IPADDRESS_CHANGE_WLAN_CMD_STATE_TO_ALLOW_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONFIG_IPADDRESS_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONFIG_IPADDRESS_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CONFIG_IPADDRESS_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CONFIG_IPADDRESS_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SET_CERTIFICATE_INDEX_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_INDEX_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_CERTIFICATE_INDEX_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_CERTIFICATE_EXIT(debug_id, component, level) sl_log_no_args(SL_WLAN_SET_CERTIFICATE_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_STATUS_EXIT(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_STATUS_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_FW_VERSION_QUERY_REQ(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_FW_VERSION_QUERY_REQ_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_INSUFFICIENT_BUFFER_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_INSUFFICIENT_BUFFER_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_INSUFFICIENT_BUFFER_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_INSUFFICIENT_BUFFER_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_6(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_INSUFFICIENT_BUFFER_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_INSUFFICIENT_BUFFER_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_7(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_7_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_INSUFFICIENT_BUFFER_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_INSUFFICIENT_BUFFER_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_8(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_8_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_INSUFFICIENT_BUFFER_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_INSUFFICIENT_BUFFER_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SET_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SET_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_NVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_NVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_PKT_ALLOCATION_FAILURE_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_BUFFER_CONFIG_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_BUFFER_CONFIG_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_BUFFER_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_BUFFER_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_BUFFER_CONFIG_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_BUFFER_CONFIG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_BUFFER_CONFIG_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_BUFFER_CONFIG_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_BUFFER_CONFIG_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_BUFFER_CONFIG_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_AP_START_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_AP_START_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_3(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_3_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_4(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_4_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_5(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_5_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_6(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_6(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_6_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_7(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_7_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_NWK_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_NWK_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_8(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_8_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_PROFILE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_POWER_SAVE_PROFILE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_POWER_SAVE_DISABLE_ENABLE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_START_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_TX_TEXT_START_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_TX_TEXT_START_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_START_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_START_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_START_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_START_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_START_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_STOP_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_TX_TEXT_STOP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_TX_TEXT_STOP_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_STOP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_STOP_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_STOP_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_STOP_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_STOP_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_TX_TEXT_STOP_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_TX_TEXT_STOP_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_START_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_RX_STATS_START_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_RX_STATS_START_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_START_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_START_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_START_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_START_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_START_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_START_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_START_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_STOP_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_RX_STATS_STOP_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_RX_STATS_STOP_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_STOP_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_STOP_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_STOP_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_STOP_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_STOP_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RX_STATS_STOP_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RX_STATS_STOP_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_START_DISCOVERY_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_WFD_START_DISCOVERY_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WFD_START_DISCOVERY_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_START_DISCOVERY_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_1(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_1_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_START_DISCOVERY_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_START_DISCOVERY_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_START_DISCOVERY_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_START_DISCOVERY_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_2(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_2_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_CONNECT_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_WFD_CONNECT_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_WFD_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_CONNECT_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_CONNECT_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_CONNECT_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_CONNECT_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_WFD_CONNECT_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_WFD_CONNECT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_DATA_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SEND_DATA_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SEND_DATA_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_DATA_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_DATA_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_DATA_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SEND_DATA_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SEND_DATA_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PING_ASYNC_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_PING_ASYNC_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_PING_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PING_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PING_ASYNC_INVALID_PARAM(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PING_ASYNC_INVALID_PARAM_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PING_ASYNC_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PING_ASYNC_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PING_ASYNC_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PING_ASYNC_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PING_ASYNC_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PING_ASYNC_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_REGISTER_AUTO_CONFIG_RSP_HANDLER_EXIT(debug_id, component, level) sl_log_no_args(SL_WLAN_REGISTER_AUTO_CONFIG_RSP_HANDLER_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_ADD_PROFILE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_ADD_PROFILE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_ADD_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ADD_PROFILE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ADD_PROFILE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ADD_PROFILE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_STATE_EXIT(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_STATE_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_PROFILE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_GET_PROFILE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_GET_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PROFILE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PROFILE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_GET_PROFILE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_GET_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_FILL_CONFIG_PROFILE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_FILL_CONFIG_PROFILE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_FILL_CONFIG_PROFILE_EXIT(debug_id, component, level) sl_log_no_args(SL_WLAN_FILL_CONFIG_PROFILE_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_DELETE_PROFILE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_DELETE_PROFILE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_DELETE_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DELETE_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DELETE_PROFILE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DELETE_PROFILE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DELETE_PROFILE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DELETE_PROFILE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_DELETE_PROFILE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_DELETE_PROFILE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ENABLE_AUTO_CONFIG_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_ENABLE_AUTO_CONFIG_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_ENABLE_AUTO_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_ENABLE_AUTO_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_ENABLE_AUTO_CONFIG_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ENABLE_AUTO_CONFIG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ENABLE_AUTO_CONFIG_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ENABLE_AUTO_CONFIG_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ENABLE_AUTO_CONFIG_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ENABLE_AUTO_CONFIG_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PMK_GENERATE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_PMK_GENERATE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_PMK_GENERATE_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_PMK_GENERATE_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_PMK_GENERATE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PMK_GENERATE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PMK_GENERATE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PMK_GENERATE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_PMK_GENERATE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_PMK_GENERATE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_SLEEP_TIMER_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_SET_SLEEP_TIMER_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SET_SLEEP_TIMER_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_SET_SLEEP_TIMER_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_SET_SLEEP_TIMER_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_SLEEP_TIMER_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_SLEEP_TIMER_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_SLEEP_TIMER_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_SET_SLEEP_TIMER_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_SET_SLEEP_TIMER_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_REGISTER_CALLBACKS_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_REGISTER_CALLBACKS_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_REGISTER_CALLBACKS_NUMBER_EXCEEDS_MAX_NUM_CALLBACKS_OR_CALLBACK_ALREADY_REG(debug_id, component, level) sl_log_no_args(SL_WLAN_REGISTER_CALLBACKS_NUMBER_EXCEEDS_MAX_NUM_CALLBACKS_OR_CALLBACK_ALREADY_REG_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_REGISTER_CALLBACKS_EXIT(debug_id, component, level) sl_log_no_args(SL_WLAN_REGISTER_CALLBACKS_EXIT_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_REQ_RADIO_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_REQ_RADIO_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_REQ_RADIO_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_WLAN_REQ_RADIO_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_REQ_RADIO_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_REQ_RADIO_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_REQ_RADIO_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_REQ_RADIO_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_REQ_RADIO_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_REQ_RADIO_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_RADIO_DEINIT_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_RADIO_DEINIT_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ADD_MFI_IE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_ADD_MFI_IE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_ADD_MFI_IE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_MFI_IE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ADD_MFI_IE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_MFI_IE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_ADD_MFI_IE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_ADD_MFI_IE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_UPDATE_GAIN_TABLE_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_UPDATE_GAIN_TABLE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_UPDATE_GAIN_TABLE_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_WLAN_UPDATE_GAIN_TABLE_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_UPDATE_GAIN_TABLE_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_UPDATE_GAIN_TABLE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_UPDATE_GAIN_TABLE_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_UPDATE_GAIN_TABLE_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_UPDATE_GAIN_TABLE_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_UPDATE_GAIN_TABLE_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CSI_CONFIG_ENTRY(debug_id, component, level) sl_log_no_args(SL_WLAN_CSI_CONFIG_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_WLAN_CSI_CONFIG_PKT_ALLOCATION_FAILURE(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CSI_CONFIG_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CSI_CONFIG_WLAN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CSI_CONFIG_WLAN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_WLAN_CSI_CONFIG_ERROR_IN_SENDING_COMMAND(debug_id, component, level, format, a) sl_log_1_args(SL_WLAN_CSI_CONFIG_ERROR_IN_SENDING_COMMAND_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SHA_PEN_ENTRY(debug_id, component, level) sl_log_no_args(SL_SHA_PEN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SHA_PEN_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_SHA_PEN_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SHA_PEN_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_SHA_PEN_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SHA_PEN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_SHA_PEN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SHA_PEN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SHA_PEN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SHA_PEN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SHA_PEN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SHA_ENTRY(debug_id, component, level) sl_log_no_args(SL_SHA_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_SHA_CHUNK_LENGTH_MSG_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_SHA_CHUNK_LENGTH_MSG_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_SHA_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_SHA_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HMAC_SHA_PEN_ENTRY(debug_id, component, level) sl_log_no_args(SL_HMAC_SHA_PEN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HMAC_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_HMAC_SHA_PEN_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HMAC_SHA_PEN_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_HMAC_SHA_PEN_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HMAC_SHA_PEN_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_HMAC_SHA_PEN_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HMAC_SHA_PEN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_HMAC_SHA_PEN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HMAC_SHA_PEN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HMAC_SHA_PEN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HMAC_SHA_PEN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HMAC_SHA_PEN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HMAC_SHA_ENTRY(debug_id, component, level) sl_log_no_args(SL_HMAC_SHA_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_HMAC_SHA_CHUNK_LENGTH_MSG_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_HMAC_SHA_CHUNK_LENGTH_MSG_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_HMAC_SHA_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_HMAC_SHA_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_AES_ENTRY(debug_id, component, level) sl_log_no_args(SL_AES_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_AES_CHUNK_LENGTH_MSG_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_AES_CHUNK_LENGTH_MSG_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_AES_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_AES_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_AES_PEN_ENTRY(debug_id, component, level) sl_log_no_args(SL_AES_PEN_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_AES_PEN_INVALID_PARAM_1(debug_id, component, level) sl_log_no_args(SL_AES_PEN_INVALID_PARAM_1_SIGNATURE(component, level)) +#define SL_PRINTF_SL_AES_PEN_INVALID_PARAM_2(debug_id, component, level) sl_log_no_args(SL_AES_PEN_INVALID_PARAM_2_SIGNATURE(component, level)) +#define SL_PRINTF_SL_AES_PEN_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_AES_PEN_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_AES_PEN_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_AES_PEN_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_AES_PEN_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_AES_PEN_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EXPONENTIATION_ENTRY(debug_id, component, level) sl_log_no_args(SL_EXPONENTIATION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EXPONENTIATION_COMMAND_GIVEN_IN_WRONG_STATE(debug_id, component, level) sl_log_no_args(SL_EXPONENTIATION_COMMAND_GIVEN_IN_WRONG_STATE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EXPONENTIATION_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_EXPONENTIATION_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EXPONENTIATION_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_EXPONENTIATION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_EXPONENTIATION_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_EXPONENTIATION_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_EXPONENTIATION_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_EXPONENTIATION_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_MULTIPLICATION_ENTRY(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_MULTIPLICATION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_MULTIPLICATION_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_MULTIPLICATION_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_MULTIPLICATION_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_MULTIPLICATION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_MULTIPLICATION_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_MULTIPLICATION_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_MULTIPLICATION_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_MULTIPLICATION_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_ADDITION_ENTRY(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_ADDITION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_ADDITION_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_ADDITION_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_ADDITION_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_ADDITION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_ADDITION_COMMON_CMD_IN_PROGRESS(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_ADDITION_COMMON_CMD_IN_PROGRESS_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_ADDITION_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_ADDITION_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_SUBTRACTION_ENTRY(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_SUBTRACTION_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_SUBTRACTION_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_SUBTRACTION_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_SUBTRACTION_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_SUBTRACTION_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_SUBTRACTION_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_SUBTRACTION_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_SUBTRACTION_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_SUBTRACTION_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_DOUBLE_ENTRY(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_DOUBLE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_DOUBLE_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_DOUBLE_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_DOUBLE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_DOUBLE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_DOUBLE_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_DOUBLE_COMMAND_ERROR_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_DOUBLE_EXIT(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_DOUBLE_EXIT_SIGNATURE(component, level), a) +#define SL_PRINTF_SL_ECDH_POINT_AFFINE_ENTRY(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_AFFINE_ENTRY_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_AFFINE_INVALID_PARAM(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_AFFINE_INVALID_PARAM_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_AFFINE_PKT_ALLOCATION_FAILURE(debug_id, component, level) sl_log_no_args(SL_ECDH_POINT_AFFINE_PKT_ALLOCATION_FAILURE_SIGNATURE(component, level)) +#define SL_PRINTF_SL_ECDH_POINT_AFFINE_COMMAND_ERROR(debug_id, component, level, format, a) sl_log_1_args(SL_ECDH_POINT_AFFINE_COMMAND_ERROR_SIGNATURE(component, level), a) +#endif diff --git a/wiseconnect/sapi/include/rsi_apis_rom.h b/wiseconnect/sapi/include/rsi_apis_rom.h new file mode 100644 index 00000000..25adabd6 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_apis_rom.h @@ -0,0 +1,445 @@ +/******************************************************************************* +* @file rsi_apis_rom.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef __SAPIS_ROM_H__ +#define __SAPIS_ROM_H__ + +#include "rsi_driver.h" +#ifdef RSI_M4_INTERFACE +#include "rsi_m4.h" +#endif + +#define IS_LITTLE_ENDIAN 0 +#define IS_BIG_ENDIAN 1 +struct rsi_driver_cb_s; +struct rsi_socket_info_s; +struct rsi_m4ta_desc_s; + +#define SAPIS_M4_DEBUG_OUT 0x0000 +#define SAPIS_M4_RX_BUFF_ADDR_NULL 0x0001 +#define SAPIS_M4_RX_BUFF_ALREDY_VALID 0x0002 +#define SAPIS_M4_RX_BUFF_NULL_RECIEVED 0x0004 +#define SAPIS_M4_ISR_UNEXPECTED_INTR 0x0005 +#define SAPIS_M4_TX_INVALID_DESC 0x0006 + +#define RSI_WLAN_SET_STATUS(x) global_cb_p->rsi_driver_cb->wlan_cb->status = x +#define RSI_CHECK_WLAN_STATE() rsi_driver_cb->wlan_cb->state +#define RSI_WLAN_GET_STATUS() rsi_driver_cb->wlan_cb->status +#define TCP_LISTEN_MIN_BACKLOG global_cb_p->rsi_tcp_listen_min_backlog +#define NUMBER_OF_SOCKETS global_cb_p->no_of_sockets + +#ifdef APIS_ROM +#define RSI_MUTEX_CREATE global_cb_p->rom_apis_p->rsi_mutex_create +#define RSI_MUTEX_LOCK global_cb_p->rom_apis_p->rsi_mutex_lock +#define RSI_MUTEX_UNLOCK global_cb_p->rom_apis_p->rsi_mutex_unlock +#define RSI_SEMAPHORE_CREATE global_cb_p->rom_apis_p->rsi_semaphore_create +#define RSI_SEMAPHORE_WAIT global_cb_p->rom_apis_p->rsi_semaphore_wait +#define RSI_SEMAPHORE_POST global_cb_p->rom_apis_p->rsi_semaphore_post +#define RSI_CRITICAL_SECTION_ENTRY global_cb_p->rom_apis_p->rsi_critical_section_entry +#define RSI_CRITICAL_SECTION_EXIT global_cb_p->rom_apis_p->rsi_critical_section_exit +#define RSI_DRIVER_WLAN_SEND_CMD global_cb_p->rom_apis_p->rsi_driver_wlan_send_cmd +#define RSI_DRIVER_SEND_DATA global_cb_p->rom_apis_p->rsi_driver_send_data +#define RSI_DELAY_MS global_cb_p->rom_apis_p->rsi_delay_ms +#define RSI_ASSERTION global_cb_p->rom_apis_p->rsi_assertion +#define RSI_SEMAPHORE_POST_FROM_ISR global_cb_p->rom_apis_p->rsi_semaphore_post_from_isr +#define RSI_MASK_TA_INTERRUPT global_cb_p->rom_apis_p->rsi_mask_ta_interrupt +#define RSI_UNMASK_TA_INTERRUPT global_cb_p->rom_apis_p->rsi_unmask_ta_interrupt + +#else +#define RSI_MUTEX_CREATE rsi_mutex_create +#define RSI_MUTEX_LOCK rsi_mutex_lock +#define RSI_MUTEX_UNLOCK rsi_mutex_unlock +#define RSI_SEMAPHORE_CREATE rsi_semaphore_create +#define RSI_SEMAPHORE_WAIT rsi_semaphore_wait +#define RSI_SEMAPHORE_POST rsi_semaphore_post +#define RSI_CRITICAL_SECTION_ENTRY rsi_critical_section_entry +#define RSI_CRITICAL_SECTION_EXIT rsi_critical_section_exit +#define RSI_DRIVER_WLAN_SEND_CMD rsi_driver_wlan_send_cmd +#define RSI_DRIVER_SEND_DATA rsi_driver_send_data +#define RSI_DELAY_MS rsi_delay_ms +#define RSI_ASSERTION rsi_assertion +#define RSI_SEMAPHORE_POST_FROM_ISR rsi_semaphore_post_from_isr +#define RSI_MASK_TA_INTERRUPT rsi_mask_ta_interrupt +#define RSI_UNMASK_TA_INTERRUPT rsi_unmask_ta_interrupt +#endif + +struct global_cb_s; + +typedef struct rom_apis_s { + // OS porting APIs + rsi_error_t (*rsi_mutex_create)(rsi_mutex_handle_t *mutex); + + rsi_error_t (*rsi_mutex_lock)(volatile rsi_mutex_handle_t *mutex); + + rsi_error_t (*rsi_mutex_unlock)(volatile rsi_mutex_handle_t *mutex); + + rsi_error_t (*rsi_semaphore_create)(rsi_semaphore_handle_t *semaphore, uint32_t count); + + rsi_error_t (*rsi_semaphore_wait)(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms); + + rsi_error_t (*rsi_semaphore_post)(rsi_semaphore_handle_t *semaphore); + + rsi_reg_flags_t (*rsi_critical_section_entry)(void); + + void (*rsi_critical_section_exit)(rsi_reg_flags_t xflags); + + int32_t (*rsi_driver_wlan_send_cmd)(rsi_wlan_cmd_request_t cmd, rsi_pkt_t *pkt); + + int32_t (*rsi_driver_send_data)(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr); + + void (*rsi_delay_ms)(uint32_t delay_ms); + + void (*rsi_assertion)(uint16_t assertion_val, const char *); + + int32_t (*ROM_WL_rsi_socket_create)(struct global_cb_s *global_cb_p, int32_t sockID, int32_t type, int32_t backlog); + + uint16_t (*ROM_WL_calculate_length_to_send)(struct global_cb_s *global_cb_p, uint8_t type, uint8_t buffers); + + rsi_error_t (*rsi_semaphore_post_from_isr)(rsi_semaphore_handle_t *semaphore); + + void (*rsi_mask_ta_interrupt)(void); + + void (*rsi_unmask_ta_interrupt)(void); + +} rom_apis_t; + +typedef struct global_cb_s { + struct rsi_driver_cb_s *rsi_driver_cb; + + // Socket information pool pointer + struct rsi_socket_info_s *rsi_socket_pool; + + rom_apis_t *rom_apis_p; + + uint8_t no_of_sockets; + + uint8_t endian; + + uint8_t rx_buffer_mem_copy; + + uint8_t rsi_tcp_listen_min_backlog; + + uint8_t os_enabled; + + uint8_t rsi_max_num_events; + + struct rsi_m4ta_desc_s *tx_desc; + + struct rsi_m4ta_desc_s *rx_desc; + + volatile uint8_t submit_rx_pkt_to_ta; + +} global_cb_t; + +extern global_cb_t *global_cb_p; +extern rom_apis_t *rom_apis_p; +extern rsi_socket_info_t *rsi_socket_pool; +#ifdef RSI_M4_INTERFACE +extern rsi_m4ta_desc_t tx_desc[2]; +extern rsi_m4ta_desc_t rx_desc[2]; +#endif + +#if defined(A11_ROM) +const typedef struct ROM_WL_API_S { + +#ifdef RSI_WLAN_ENABLE + // Socket APIs + int32_t (*rsi_get_application_socket_descriptor)(global_cb_t *global_cb_p, int32_t sock_id); + uint8_t (*calculate_buffers_required)(global_cb_t *global_cb_p, uint8_t type, uint16_t length); + uint16_t (*calculate_length_to_send)(struct global_cb_s *global_cb_p, uint8_t type, uint8_t buffers); +#endif + + // Scheduler + void (*rsi_scheduler_init)(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + uint32_t (*rsi_get_event)(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + void (*rsi_scheduler)(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + + // Packet allocation management + int32_t (*rsi_pkt_pool_init)(global_cb_t *global_cb_p, + rsi_pkt_pool_t *pool_cb, + uint8_t *buffer, + uint32_t total_size, + uint32_t pkt_size); + rsi_pkt_t *(*rsi_pkt_alloc)(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); + int32_t (*rsi_pkt_free)(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt); + uint32_t (*rsi_is_pkt_available)(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); + + // Queue Management + void (*rsi_queues_init)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_enqueue_pkt)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt); + rsi_pkt_t *(*rsi_dequeue_pkt)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + uint32_t (*rsi_check_queue_status)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_block_queue)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_unblock_queue)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_enqueue_pkt_from_isr)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt); + + // Events + void (*rsi_set_event)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_clear_event)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_mask_event)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_unmask_event)(global_cb_t *global_cb_p, uint32_t event_num); + uint32_t (*rsi_find_event)(global_cb_t *global_cb_p, uint32_t event_map); + uint16_t (*rsi_register_event)(global_cb_t *global_cb_p, uint32_t event_id, void (*event_handler_ptr)(void)); + void (*rsi_set_event_from_isr)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_unmask_event_from_isr)(global_cb_t *global_cb_p, uint32_t event_num); + + // Utils + void (*rsi_uint16_to_2bytes)(global_cb_t *global_cb_p, uint8_t *dBuf, uint16_t val); + void (*rsi_uint32_to_4bytes)(global_cb_t *global_cb_p, uint8_t *dBuf, uint32_t val); + uint16_t (*rsi_bytes2R_to_uint16)(global_cb_t *global_cb_p, uint8_t *dBuf); + uint32_t (*rsi_bytes4R_to_uint32)(global_cb_t *global_cb_p, uint8_t *dBuf); +#ifdef RSI_M4_INTERFACE + // M4 HAL + void (*rsi_m4_interrupt_isr)(global_cb_t *global_cb_p); + void (*mask_ta_interrupt)(uint32_t interrupt_no); + void (*unmask_ta_interrupt)(uint32_t interrupt_no); + rsi_pkt_t *(*rsi_frame_read)(global_cb_t *global_cb_p); + int16_t (*rsi_frame_write)(global_cb_t *global_cb_p, + rsi_frame_desc_t *uFrameDscFrame, + uint8_t *payloadparam, + uint16_t size_param); + int (*rsi_submit_rx_pkt)(global_cb_t *global_cb_p); +#endif + +} ROM_WL_API_T; + +#ifndef ROMAPI_WL +#define ROMAPI_WL ((ROM_WL_API_T *)(*(uint32_t *)(0x300100 + (18 * 4)))) +#endif + +#else +typedef const struct ROM_WL_API_S { + + // Socket APIs + int32_t (*socket_async)(global_cb_t *global_cb_p, + int32_t protocolFamily, + int32_t type, + int32_t protocol, + void (*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length)); + int32_t (*socket)(global_cb_t *global_cb_p, int32_t protocolFamily, int32_t type, int32_t protocol); + int32_t (*bind)(global_cb_t *global_cb_p, int32_t sockID, struct rsi_sockaddr *localAddress, int32_t addressLength); + int32_t (*connect)(global_cb_t *global_cb_p, + int32_t sockID, + struct rsi_sockaddr *remoteAddress, + int32_t addressLength); + int32_t (*listen)(global_cb_t *global_cb_p, int32_t sockID, int32_t backlog); + int32_t (*accept)(global_cb_t *global_cb_p, + int32_t sockID, + struct rsi_sockaddr *ClientAddress, + int32_t *addressLength); + int32_t (*recvfrom)(global_cb_t *global_cb_p, + int32_t sockID, + int8_t *buffer, + int32_t buffersize, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen); + int32_t (*recv)(global_cb_t *global_cb_p, int32_t sockID, void *rcvBuffer, int32_t bufferLength, int32_t flags); + int32_t (*sendto)(global_cb_t *global_cb_p, + int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen); + int32_t (*sendto_async)(global_cb_t *global_cb_p, + int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen, + void (*data_transfer_complete_handler)(uint8_t sockID, uint16_t length)); + int32_t (*send)(global_cb_t *global_cb_p, int32_t sockID, const int8_t *msg, int32_t msgLength, int32_t flags); + int32_t (*send_async)(global_cb_t *global_cb_p, + int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*data_transfer_complete_handler)(uint8_t sockID, uint16_t length)); + int32_t (*shutdown)(global_cb_t *global_cb_p, int32_t sockID, int32_t how); + int32_t (*rsi_get_application_socket_descriptor)(global_cb_t *global_cb_p, int32_t sock_id); + void (*rsi_clear_sockets)(global_cb_t *global_cb_p, uint8_t sockID); + uint8_t (*calculate_buffers_required)(global_cb_t *global_cb_p, uint8_t type, uint16_t length); + int32_t (*rsi_socket_create)(struct global_cb_s *global_cb_p, int32_t sockID, int32_t type, int32_t backlog); + uint16_t (*calculate_length_to_send)(struct global_cb_s *global_cb_p, uint8_t type, uint8_t buffers); + + // Scheduler + void (*rsi_scheduler_init)(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + uint32_t (*rsi_get_event)(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + void (*rsi_scheduler)(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + + // Packet allocation management + int32_t (*rsi_pkt_pool_init)(global_cb_t *global_cb_p, + rsi_pkt_pool_t *pool_cb, + uint8_t *buffer, + uint32_t total_size, + uint32_t pkt_size); + rsi_pkt_t *(*rsi_pkt_alloc)(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); + int32_t (*rsi_pkt_free)(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt); + uint32_t (*rsi_is_pkt_available)(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); + + // Queue Management + void (*rsi_queues_init)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_enqueue_pkt)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt); + rsi_pkt_t *(*rsi_dequeue_pkt)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + uint32_t (*rsi_check_queue_status)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_block_queue)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + void (*rsi_unblock_queue)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); + + int32_t (*rsi_driver_send_data)(global_cb_t *global_cb_p, + uint32_t sockID, + uint8_t *buffer, + uint32_t length, + struct rsi_sockaddr *destAddr); + int32_t (*rsi_driver_process_recv_data)(global_cb_t *global_cb_p, rsi_pkt_t *pkt); + + // Events + void (*rsi_set_event)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_clear_event)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_mask_event)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_unmask_event)(global_cb_t *global_cb_p, uint32_t event_num); + uint32_t (*rsi_find_event)(global_cb_t *global_cb_p, uint32_t event_map); + uint16_t (*rsi_register_event)(global_cb_t *global_cb_p, uint32_t event_id, void (*event_handler_ptr)(void)); + + // Utils + void (*rsi_uint16_to_2bytes)(global_cb_t *global_cb_p, uint8_t *dBuf, uint16_t val); + void (*rsi_uint32_to_4bytes)(global_cb_t *global_cb_p, uint8_t *dBuf, uint32_t val); + uint16_t (*rsi_bytes2R_to_uint16)(global_cb_t *global_cb_p, uint8_t *dBuf); + uint32_t (*rsi_bytes4R_to_uint32)(global_cb_t *global_cb_p, uint8_t *dBuf); +#ifdef RSI_M4_INTERFACE + // M4 HAL + void (*rsi_m4_interrupt_isr)(global_cb_t *global_cb_p); + void (*mask_ta_interrupt)(uint32_t interrupt_no); + void (*unmask_ta_interrupt)(uint32_t interrupt_no); + rsi_pkt_t *(*rsi_frame_read)(global_cb_t *global_cb_p); + int16_t (*rsi_frame_write)(global_cb_t *global_cb_p, + rsi_frame_desc_t *uFrameDscFrame, + uint8_t *payloadparam, + uint16_t size_param); + int (*rsi_submit_rx_pkt)(global_cb_t *global_cb_p); +#endif + + void (*rsi_enqueue_pkt_from_isr)(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt); + void (*rsi_set_event_from_isr)(global_cb_t *global_cb_p, uint32_t event_num); + void (*rsi_unmask_event_from_isr)(global_cb_t *global_cb_p, uint32_t event_num); + +} ROM_WL_API_T; + +#define ROMAPI_WL ((ROM_WL_API_T *)(*(uint32_t *)(0x300100 + (20 * 4)))) +#endif +extern ROM_WL_API_T *api_wl; +// Proto types +rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex); +rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex); +void rsi_mutex_lock_from_isr(volatile rsi_mutex_handle_t *mutex); +rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex); +void rsi_mutex_unlock_from_isr(volatile rsi_mutex_handle_t *mutex); +rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore, uint32_t count); +rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms); +rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore); +rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore); +rsi_reg_flags_t rsi_critical_section_entry(void); +void rsi_critical_section_exit(rsi_reg_flags_t xflags); +void rsi_mask_ta_interrupt(void); +void rsi_unmask_ta_interrupt(void); + +rsi_pkt_t *rsi_pkt_alloc(rsi_pkt_pool_t *pool_cb); +int32_t rsi_pkt_free(rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt); +int32_t rsi_driver_wlan_send_cmd(rsi_wlan_cmd_request_t cmd, rsi_pkt_t *pkt); +int32_t rsi_driver_send_data(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr); +uint32_t rsi_find_event(uint32_t event_map); +void rsi_delay_ms(uint32_t delay_ms); +void rsi_assertion(uint16_t assertion_val, const char *string); + +int32_t ROM_WL_rsi_get_application_socket_descriptor(global_cb_t *global_cb_p, int32_t sock_id); +int32_t ROM_WL_rsi_get_primary_socket_id(global_cb_t *global_cb_p, uint16_t port_number); +uint8_t ROM_WL_calculate_buffers_required(global_cb_t *global_cb_p, uint8_t type, uint16_t length); +uint16_t ROM_WL_calculate_length_to_send(global_cb_t *global_cb_p, uint8_t type, uint8_t buffers); + +// Scheduler +void ROM_WL_rsi_scheduler_init(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); +uint32_t ROM_WL_rsi_get_event(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); +void ROM_WL_rsi_scheduler(global_cb_t *global_cb_p, rsi_scheduler_cb_t *scheduler_cb); + +// Packet allocation management +int32_t ROM_WL_rsi_pkt_pool_init(global_cb_t *global_cb_p, + rsi_pkt_pool_t *pool_cb, + uint8_t *buffer, + uint32_t total_size, + uint32_t pkt_size); +rsi_pkt_t *ROM_WL_rsi_pkt_alloc(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); +int32_t ROM_WL_rsi_pkt_free(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt); +uint32_t ROM_WL_rsi_is_pkt_available(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); + +// Queue Management +void ROM_WL_rsi_queues_init(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); +void ROM_WL_rsi_enqueue_pkt(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt); +rsi_pkt_t *ROM_WL_rsi_dequeue_pkt(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); +uint32_t ROM_WL_rsi_check_queue_status(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); +void ROM_WL_rsi_block_queue(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); +void ROM_WL_rsi_unblock_queue(global_cb_t *global_cb_p, rsi_queue_cb_t *queue); +void ROM_WL_rsi_enqueue_pkt_from_isr(global_cb_t *global_cb_p, rsi_queue_cb_t *queue, rsi_pkt_t *pkt); + +int32_t ROM_WL_rsi_driver_send_data(global_cb_t *global_cb_p, + uint32_t sockID, + uint8_t *buffer, + uint32_t length, + struct rsi_sockaddr *destAddr); +int32_t ROM_WL_rsi_driver_process_recv_data(global_cb_t *global_cb_p, rsi_pkt_t *pkt); + +// Events +void ROM_WL_rsi_set_event(global_cb_t *global_cb_p, uint32_t event_num); +void ROM_WL_rsi_clear_event(global_cb_t *global_cb_p, uint32_t event_num); +void ROM_WL_rsi_mask_event(global_cb_t *global_cb_p, uint32_t event_num); +void ROM_WL_rsi_unmask_event(global_cb_t *global_cb_p, uint32_t event_num); +uint32_t ROM_WL_rsi_find_event(global_cb_t *global_cb_p, uint32_t event_map); +uint16_t ROM_WL_rsi_register_event(global_cb_t *global_cb_p, uint32_t event_id, void (*event_handler_ptr)(void)); +void ROM_WL_rsi_set_event_from_isr(global_cb_t *global_cb_p, uint32_t event_num); +void ROM_WL_rsi_unmask_event_from_isr(global_cb_t *global_cb_p, uint32_t event_num); +// Utils +void ROM_WL_rsi_uint16_to_2bytes(global_cb_t *global_cb_p, uint8_t *dBuf, uint16_t val); +void ROM_WL_rsi_uint32_to_4bytes(global_cb_t *global_cb_p, uint8_t *dBuf, uint32_t val); +uint16_t ROM_WL_rsi_bytes2R_to_uint16(global_cb_t *global_cb_p, uint8_t *dBuf); +uint32_t ROM_WL_rsi_bytes4R_to_uint32(global_cb_t *global_cb_p, uint8_t *dBuf); +void rom_init(void); + +#ifdef RSI_M4_INTERFACE +// M4 HAL +void ROM_WL_rsi_m4_interrupt_isr(global_cb_t *global_cb_p); +void ROM_WL_rsi_raise_pkt_pending_interrupt_to_ta(void); +void ROM_WL_mask_ta_interrupt(uint32_t interrupt_no); +void ROM_WL_unmask_ta_interrupt(uint32_t interrupt_no); +rsi_pkt_t *ROM_WL_rsi_frame_read(global_cb_t *global_cb_p); +int16_t ROM_WL_rsi_frame_write(global_cb_t *global_cb_p, + rsi_frame_desc_t *uFrameDscFrame, + uint8_t *payloadparam, + uint16_t size_param); +int ROM_WL_rsi_submit_rx_pkt(global_cb_t *global_cb_p); +void ROM_WL_rsi_receive_from_ta_done_isr(global_cb_t *global_cb_p); +void ROM_WL_rsi_pkt_pending_from_ta_isr(global_cb_t *global_cb_p); +void ROM_WL_rsi_transfer_to_ta_done_isr(global_cb_t *global_cb_p); + +#endif +rsi_pkt_t *ROM_WL_rsi_pkt_alloc_non_blocking(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb); +int32_t ROM_WL_rsi_pkt_free_non_blocking(global_cb_t *global_cb_p, rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt); +#endif diff --git a/wiseconnect/sapi/include/rsi_ble.h b/wiseconnect/sapi/include/rsi_ble.h new file mode 100644 index 00000000..67433413 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_ble.h @@ -0,0 +1,1637 @@ +/******************************************************************************* +* @file rsi_ble.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_BLE_H +#define RSI_BLE_H + +#include +#include +#include + +/****************************************************** + * * Macros + * ******************************************************/ + +#define RSI_BLE_STATE_NONE 0x00 +#define RSI_BLE_STATE_CONNECTION 0x01 +#define RSI_BLE_STATE_DSICONNECT 0x02 +#define RSI_BLE_MAX_REQ_LIST 0x05 + +#define RSI_BLE_LEGACY_CMD_USED (1 << 0) //BIT(0) +#define RSI_BLE_ADV_EXT_CMD_USED (1 << 1) //BIT(1) +#define RSI_BLE_CHECK_CMD (1 << 15) //BIT(15) + +#define SI_LE_BUFFER_AVL 0 +#define SI_LE_BUFFER_FULL 1 +#define SI_LE_BUFFER_IN_PROGRESS 2 + +#define BLE_VENDOR_RF_TYPE_CMD_OPCODE 0xFC14 +#define BLE_VENDOR_WHITELIST_USING_ADV_DATA_PAYLOAD 0xFC1B + +#define RSI_BLE_MAX_NUM_GAP_EXT_CALLBACKS 1 +#define RSI_BLE_MAX_NUM_ADV_EXT_EVENT_CALLBACKS 0x08 + +/****************************************************** + * * Constants + * ******************************************************/ + +/****************************************************** + * * Enumerations + * ******************************************************/ +// enumeration for BLE command request codes +typedef enum RSI_BLE_CMD_AE_opcode_e { + RSI_BLE_GET_AE_MAX_NO_OF_ADV_SETS = 0x0001, + RSI_BLE_GET_AE_MAX_ADV_DATA_LEN = 0x0002, + RSI_BLE_SET_AE_SET_RANDOM_ADDR = 0x0003, + RSI_BLE_SET_AE_PARAMS = 0x0004, + RSI_BLE_SET_AE_DATA = 0x0005, + RSI_BLE_SET_AE_ENABLE = 0x006, + RSI_BLE_ADV_SET_CLEAR_OR_REMOVE = 0x0007, + RSI_BLE_SET_AE_PERIODIC_ADV_PARAMS = 0x0008, + RSI_BLE_SET_AE_PERIODIC_ADV_ENABLE = 0x0009, + RSI_BLE_SET_AE_SCAN_PARAMS = 0x000A, + RSI_BLE_SET_AE_SCAN_ENABLE = 0x000B, + RSI_BLE_SET_AE_PERIODIC_SYNC = 0x000C, + RSI_BLE_AE_DEV_TO_PERIODIC_LIST = 0x000D, + RSI_BLE_AE_READ_PERIODIC_LIST_SIZE = 0x000E, + RSI_BLE_AE_EXTENDED_CREATE_CONNECT = 0x000F, + +} RSI_BLE_CMD_AE_opcode_t; + +// enumeration for BLE command request codes +typedef enum rsi_ble_cmd_request_e { + RSI_BLE_REQ_ADV = 0x0075, + RSI_BLE_REQ_SCAN = 0x0076, + RSI_BLE_REQ_CONN = 0x0077, + RSI_BLE_REQ_DISCONNECT = 0x0078, + RSI_BLE_GET_DEV_STATE = 0x0079, + RSI_BLE_CMD_CONN_PARAMS_UPDATE = 0x007A, + RSI_BLE_REQ_START_ENCRYPTION = 0x007B, + RSI_BLE_REQ_SMP_PAIR = 0x007C, + RSI_BLE_SMP_PAIR_RESPONSE = 0x007D, + RSI_BLE_SMP_PASSKEY = 0x007E, + RSI_BLE_REQ_PROFILES = 0x007F, + RSI_BLE_REQ_PROFILE = 0x0080, + RSI_BLE_REQ_CHAR_SERVICES = 0x0081, + RSI_BLE_REQ_INC_SERVICES = 0x0082, + RSI_BLE_REQ_READ_BY_UUID = 0x0083, + RSI_BLE_REQ_DESC = 0x0084, + RSI_BLE_REQ_READ_VAL = 0x0085, + RSI_BLE_REQ_MULTIPLE_READ = 0x0086, + RSI_BLE_REQ_LONG_READ = 0x0087, + RSI_BLE_REQ_WRITE = 0x0088, + RSI_BLE_REQ_WRITE_NO_ACK = 0x0089, + RSI_BLE_REQ_LONG_WRITE = 0x008A, + RSI_BLE_REQ_PREPARE_WRITE = 0x008B, + RSI_BLE_REQ_EXECUTE_WRITE = 0x008C, + RSI_BLE_ADD_SERVICE = 0x0092, + RSI_BLE_ADD_ATTRIBUTE = 0x0093, + RSI_BLE_SET_LOCAL_ATT_VALUE = 0x0094, + RSI_BLE_GET_LOCAL_ATT_VALUE = 0x0095, + RSI_BLE_CMD_NOTIFY = 0x0096, + RSI_BLE_CMD_INDICATE = 0x0097, + RSI_BLE_SET_ADVERTISE_DATA = 0x009C, + RSI_BLE_GET_LE_PING = 0x00A1, + RSI_BLE_SET_LE_PING = 0x00A2, + RSI_BLE_SET_RANDOM_ADDRESS = 0x00A3, + RSI_BLE_ENCRYPT = 0x00A4, + RSI_BLE_CMD_READ_RESP = 0x00A5, + RSI_BLE_SET_SCAN_RESPONSE_DATA = 0x00A8, + RSI_BLE_LE_WHITE_LIST = 0x00AA, + RSI_BLE_CMD_REMOVE_SERVICE = 0x00AB, + RSI_BLE_CMD_REMOVE_ATTRIBUTE = 0x00AC, + RSI_BLE_PROCESS_RESOLV_LIST = 0x00AD, + RSI_BLE_GET_RESOLVING_LIST_SIZE = 0x00AE, + RSI_BLE_SET_ADDRESS_RESOLUTION_ENABLE = 0x00AF, + RSI_BLE_REQ_READ_PHY = 0x00B0, + RSI_BLE_REQ_SET_PHY = 0x00B1, + RSI_BLE_SET_DATA_LEN = 0x00B2, + RSI_BLE_READ_MAX_DATA_LEN = 0X00B3, + RSI_BLE_SET_PRIVACY_MODE = 0x00B4, + RSI_BLE_CBFC_CONN_REQ = 0x00B5, + RSI_BLE_CBFC_CONN_RESP = 0x00B6, + RSI_BLE_CBFC_TX_DATA = 0x00B7, + RSI_BLE_CBFC_DISCONN = 0x00B8, + RSI_BLE_LE_LTK_REQ_REPLY = 0X00BA, + RSI_BLE_RX_TEST_MODE = 0x00BB, + RSI_BLE_TX_TEST_MODE = 0x00BC, + RSI_BLE_END_TEST_MODE = 0x00BD, + RSI_BLE_PER_TX_MODE = 0x00BF, + RSI_BLE_PER_RX_MODE = 0x00C0, + RSI_BLE_CMD_ATT_ERROR = 0x00C1, + RSI_BLE_REQ_PROFILES_ASYNC = 0x00F2, + RSI_BLE_REQ_PROFILE_ASYNC = 0x00F3, + RSI_BLE_GET_CHARSERVICES_ASYNC = 0x00F4, + RSI_BLE_GET_INCLUDESERVICES_ASYNC = 0x00F5, + RSI_BLE_READCHARVALUEBYUUID_ASYNC = 0x00F6, + RSI_BLE_GET_ATTRIBUTE_ASYNC = 0x00F7, + RSI_BLE_GET_DESCRIPTORVALUE_ASYNC = 0x00F8, + RSI_BLE_GET_MULTIPLEVALUES_ASYNC = 0x00F9, + RSI_BLE_GET_LONGDESCVALUES_ASYNC = 0x00FA, + RSI_BLE_SET_DESCVALUE_ASYNC = 0x00FB, + RSI_BLE_SET_PREPAREWRITE_ASYNC = 0x00FC, + RSI_BLE_EXECUTE_LONGDESCWRITE_ASYNC = 0x00FD, + RSI_BLE_SET_SMP_PAIRING_CAPABILITY_DATA = 0x0101, + RSI_BLE_CONN_PARAM_RESP_CMD = 0x0105, + RSI_BLE_CMD_INDICATE_CONFIRMATION = 0x0106, + RSI_BLE_MTU_EXCHANGE_REQUEST = 0x0107, + RSI_BLE_CMD_SET_WWO_RESP_NOTIFY_BUF_INFO = 0x0108, + RSI_BLE_CMD_WRITE_RESP = 0x010A, + RSI_BLE_CMD_PREPARE_WRITE_RESP = 0x010B, + RSI_BLE_CMD_SET_LOCAL_IRK = 0x010C, + RSI_BLE_REQ_SMP_PAIRING_FAILED = 0x0111, + RSI_BLE_CMD_SET_PROP_PROTOCOL_BLE_BANDEDGE_TXPOWER = 0x012A, + RSI_BLE_CMD_MTU_EXCHANGE_RESP = 0x012B, + RSI_BLE_CMD_SET_BLE_TX_POWER = 0x012D, + RSI_BLE_CMD_INDICATE_SYNC = 0x016F, +#ifdef RSI_PROP_PROTOCOL_ENABLE + RSI_PROP_PROTOCOL_CMD = 0xE000, + RSI_PROP_PROTOCOL_CMD_PER = 0xE001, +#endif + RSI_BLE_CMD_AE = 0x0171, + RSI_BLE_CMD_READ_TRANSMIT_POWER = 0x0172, + RSI_BLE_CMD_READ_RF_PATH_COMP = 0x0173, + RSI_BLE_CMD_WRITE_RF_PATH_COMP = 0x0174, + + RSI_BLE_REQ_CONN_ENHANCE = 0x1FFF, //Please add new cmd ids above this cmd id. +} rsi_ble_cmd_request_t; + +// enumeration for BLE command response codes +typedef enum rsi_ble_cmd_resp_e { + RSI_BLE_RSP_ADVERTISE = 0x0075, + RSI_BLE_RSP_SCAN = 0x0076, + RSI_BLE_RSP_CONNECT = 0x0077, + RSI_BLE_RSP_DISCONNECT = 0x0078, + RSI_BLE_RSP_QUERY_DEVICE_STATE = 0x0079, + RSI_BLE_RSP_CONN_PARAMS_UPDATE = 0x007A, + RSI_BLE_RSP_START_ENCRYPTION = 0x007B, + RSI_BLE_RSP_SMP_PAIR = 0x007C, + RSI_BLE_RSP_SMP_PAIR_RESPONSE = 0x007D, + RSI_BLE_RSP_SMP_PASSKEY = 0x007E, + RSI_BLE_RSP_PROFILES = 0x007F, + RSI_BLE_RSP_PROFILE = 0x0080, + RSI_BLE_RSP_CHAR_SERVICES = 0x0081, + RSI_BLE_RSP_INC_SERVICES = 0x0082, + RSI_BLE_RSP_READ_BY_UUID = 0x0083, + RSI_BLE_RSP_DESC = 0x0084, + RSI_BLE_RSP_READ_VAL = 0x0085, + RSI_BLE_RSP_MULTIPLE_READ = 0x0086, + RSI_BLE_RSP_LONG_READ = 0x0087, + RSI_BLE_RSP_WRITE = 0x0088, + RSI_BLE_RSP_WRITE_NO_ACK = 0x0089, + RSI_BLE_RSP_LONG_WRITE = 0x008A, + RSI_BLE_RSP_PREPARE_WRITE = 0x008B, + RSI_BLE_RSP_EXECUTE_WRITE = 0x008C, + RSI_BLE_RSP_INIT = 0x008D, + RSI_BLE_RSP_DEINIT = 0x008E, + RSI_BLE_RSP_SET_ANTENNA = 0x008F, + RSI_BLE_RSP_ADD_SERVICE = 0x0092, + RSI_BLE_RSP_ADD_ATTRIBUTE = 0x0093, + RSI_BLE_RSP_SET_LOCAL_ATT_VALUE = 0x0094, + RSI_BLE_RSP_GET_LOCAL_ATT_VALUE = 0x0095, + RSI_BLE_RSP_NOTIFY = 0x0096, + RSI_BLE_RSP_GET_LE_PING = 0x00A1, + RSI_BLE_RSP_SET_LE_PING = 0x00A2, + RSI_BLE_RSP_SET_RANDOM_ADDRESS = 0x00A3, + RSI_BLE_RSP_ENCRYPT = 0x00A4, + RSI_BLE_RSP_READ_RESP = 0x00A5, + RSI_BLE_RSP_LE_WHITE_LIST = 0x00AA, + RSI_BLE_RSP_REMOVE_SERVICE = 0x00AB, + RSI_BLE_RSP_REMOVE_ATTRIBUTE = 0x00AC, + RSI_BLE_RSP_PROCESS_RESOLV_LIST = 0x00AD, + RSI_BLE_RSP_GET_RESOLVING_LIST_SIZE = 0x00AE, + RSI_BLE_RSP_SET_ADDRESS_RESOLUTION_ENABLE = 0x00AF, + RSI_BLE_RSP_READ_PHY = 0x00B0, + RSI_BLE_RSP_SET_PHY = 0x00B1, + RSI_BLE_RSP_SET_DATA_LEN = 0x00B2, + RSI_BLE_RSP_READ_MAX_DATA_LEN = 0X00B3, + RSI_BLE_RSP_PRIVACY_MODE = 0x00B4, + RSI_BLE_RSP_CBFC_CONN_REQ = 0x00B5, + RSI_BLE_RSP_CBFC_CONN_RESP = 0x00B6, + RSI_BLE_RSP_CBFC_TX_DATA = 0x00B7, + RSI_BLE_RSP_CBFC_DISCONN = 0x00B8, + + RSI_BLE_RSP_LE_LTK_REQ_REPLY = 0X00BA, + RSI_BLE_RSP_RX_TEST_MODE = 0x00BB, + RSI_BLE_RSP_TX_TEST_MODE = 0x00BC, + RSI_BLE_RSP_END_TEST_MODE = 0x00BD, + RSI_BLE_RSP_PER_TX_MODE = 0x00BE, + RSI_BLE_RSP_PER_RX_MODE = 0x00BF, + + RSI_BLE_RSP_ATT_ERROR = 0x00C1, + + RSI_BLE_RSP_PROFILES_ASYNC = 0x00F2, + RSI_BLE_RSP_PROFILE_ASYNC = 0x00F3, + RSI_BLE_RSP_GET_CHARSERVICES_ASYNC = 0x00F4, + RSI_BLE_RSP_GET_INCLUDESERVICES_ASYNC = 0x00F5, + RSI_BLE_RSP_READCHARVALUEBYUUID_ASYNC = 0x00F6, + RSI_BLE_RSP_GET_ATTRIBUTE_ASYNC = 0x00F7, + RSI_BLE_RSP_GET_DESCRIPTORVALUE_ASYNC = 0x00F8, + RSI_BLE_RSP_GET_MULTIPLEVALUES_ASYNC = 0x00F9, + RSI_BLE_RSP_GET_LONGDESCVALUES_ASYNC = 0x00FA, + RSI_BLE_RSP_SET_DESCVALUE_ASYNC = 0x00FB, + RSI_BLE_RSP_SET_PREPAREWRITE_ASYNC = 0x00FC, + RSI_BLE_RSP_EXECUTE_LONGDESCWRITE_ASYNC = 0x00FD, + + RSI_BLE_RSP_SET_SMP_PAIRING_CAPABILITY_DATA = 0x0101, + RSI_BLE_RSP_CONN_PARAM_RESP = 0x0105, + RSI_BLE_RSP_INDICATE_CONFIRMATION = 0x0106, + RSI_BLE_RSP_MTU_EXCHANGE_REQUEST = 0x0107, + RSI_BLE_RSP_SET_WWO_RESP_NOTIFY_BUF_INFO = 0x0108, + RSI_BLE_RSP_SET_LOCAL_IRK = 0x010C, + RSI_BLE_RSP_SMP_PAIRING_FAILED = 0x0111, + RSI_BLE_RSP_SET_PROP_PROTOCOL_BLE_BANDEDGE_TXPOWER = 0x012A, + RSI_BLE_RSP_MTU_EXCHANGE_RESP = 0x012B, + RSI_BLE_RSP_SET_BLE_TX_POWER = 0x012D, +#ifdef RSI_PROP_PROTOCOL_ENABLE + RSI_PROP_PROTOCOL_CMD_RSP = 0xE000, + RSI_PROP_PROTOCOL_CMD_RSP_PER = 0xE001, +#endif + + RSI_BLE_RSP_AE = 0x0171, + RSI_BLE_RSP_READ_TRANSMIT_POWER = 0x0172, + RSI_BLE_RSP_READ_RF_PATH_COMP = 0x0173, + RSI_BLE_RSP_WRITE_RF_PATH_COMP = 0x0174, +} rsi_ble_cmd_resp_t; + +// enumeration for BLE command response codes +typedef enum rsi_ble_event_e { + RSI_BLE_EVENT_DISCONNECT = 0x1006, + RSI_BLE_EVENT_GATT_ERROR_RESPONSE = 0x1500, + RSI_BLE_EVENT_GATT_DESC_VAL_RESPONSE = 0x1501, + RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_BY_UUID = 0x1502, + RSI_BLE_EVENT_GATT_READ_CHAR_SERVS = 0x1503, //read by type: read char, include serivces and read value by uuid. + RSI_BLE_EVENT_GATT_READ_INC_SERVS = 0x1504, //read by type: read char, include serivces and read value by uuid. + RSI_BLE_EVENT_GATT_READ_VAL_BY_UUID = 0x1505, //read by type: read char, include serivces and read value by uuid. + RSI_BLE_EVENT_GATT_READ_RESP = 0x1506, + RSI_BLE_EVENT_GATT_READ_BLOB_RESP = 0x1507, + RSI_BLE_EVENT_GATT_READ_MULTIPLE_RESP = 0x1508, + RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_LIST = 0x1509, + RSI_BLE_EVENT_GATT_WRITE_RESP = 0x150A, + RSI_BLE_EVENT_GATT_PREPARE_WRITE_RESP = 0x150B, + RSI_BLE_EVENT_GATT_EXECUTE_WRITE_RESP = 0x150C, + RSI_BLE_EVENT_GATT_INDICATE_CONFIRMATION = 0x150D, + RSI_BLE_EVENT_ADV_REPORT = 0x150E, + RSI_BLE_EVENT_CONN_STATUS = 0x150F, + RSI_BLE_EVENT_SMP_REQUEST = 0x1510, + RSI_BLE_EVENT_SMP_RESPONSE = 0x1511, + RSI_BLE_EVENT_SMP_PASSKEY = 0x1512, + RSI_BLE_EVENT_SMP_FAILED = 0x1513, + RSI_BLE_EVENT_GATT_NOTIFICATION = 0x1514, + RSI_BLE_EVENT_GATT_INDICATION = 0x1515, + RSI_BLE_EVENT_ENCRYPT_STARTED = 0x1516, + RSI_BLE_EVENT_GATT_WRITE = 0x1517, + RSI_BLE_EVENT_LE_PING_TIME_EXPIRED = 0x1518, + RSI_BLE_EVENT_PREPARE_WRITE = 0x1519, + RSI_BLE_EVENT_EXECUTE_WRITE = 0x151A, + RSI_BLE_EVENT_READ_REQ = 0x151B, + RSI_BLE_EVENT_MTU = 0x151C, + RSI_BLE_EVENT_SMP_PASSKEY_DISPLAY_EVENT = 0x151D, + RSI_BLE_EVENT_PHY_UPDATE_COMPLETE = 0x151E, + RSI_BLE_EVENT_DATA_LENGTH_UPDATE_COMPLETE = 0x151F, + RSI_BLE_EVENT_SC_PASSKEY = 0x1520, + RSI_BLE_EVENT_ENHANCE_CONN_STATUS = 0x1521, + RSI_BLE_EVENT_DIRECTED_ADV_REPORT = 0x1522, + RSI_BLE_EVENT_SECURITY_KEYS = 0x1523, + RSI_BLE_EVENT_PSM_CONN_REQ = 0x1524, + RSI_BLE_EVENT_PSM_CONN_COMPLETE = 0x1525, + RSI_BLE_EVENT_PSM_RX_DATA = 0x1526, + RSI_BLE_EVENT_PSM_DISCONNECT = 0x1527, + RSI_BLE_EVENT_LE_LTK_REQUEST = 0x152A, + RSI_BLE_EVENT_CONN_UPDATE_COMPLETE = 0x152B, + RSI_BLE_EVENT_REMOTE_FEATURES = 0x152C, + RSI_BLE_EVENT_LE_MORE_DATA_REQ = 0x152D, + RSI_BLE_EVENT_REMOTE_CONN_PARAMS_REQUEST = 0x153C, + RSI_BLE_EVENT_CLI_SMP_RESPONSE = 0x153D, + RSI_BLE_EVENT_CHIP_MEMORY_STATS = 0x1530, + RSI_BLE_EVENT_SC_METHOD = 0x1540, + RSI_BLE_EVENT_MTU_EXCHANGE_INFORMATION = 0x1541, + RSI_BLE_EVENT_CTKD = 0x1542, + RSI_BLE_EVENT_REMOTE_DEVICE_INFORMATION = 0x1543, + RSI_BLE_EVENT_AE_ADVERTISING_REPORT = 0x1544, + RSI_BLE_EVENT_PER_ADV_SYNC_ESTBL = 0x1545, + RSI_BLE_EVENT_PER_ADV_REPORT = 0x1546, + RSI_BLE_EVENT_PER_ADV_SYNC_LOST = 0x1547, + RSI_BLE_EVENT_SCAN_TIMEOUT = 0x1548, + RSI_BLE_EVENT_ADV_SET_TERMINATED = 0x1549, + RSI_BLE_EVENT_SCAN_REQ_RECVD = 0x154a, + +} rsi_ble_event_t; + +typedef enum { + RSI_SMP_PAIRING_NOT_SUPPORTED = 0x05, + RSI_SMP_UNSPECIFIED_REASON = 0x08, + RSI_SMP_REPEATED_ATTEMPTS = 0x09, +} smp_failure_error; + +// enumerations for call back types +typedef enum rsi_ble_callback_id_e { + RSI_BLE_ON_CTKD = 1, + RSI_BLE_ON_ADV_EXT_ADVERTISE_REPORT_EVENT = 2, + RSI_BLE_ON_ADV_EXT_PERIODIC_ADV_SYNC_ESTBL_EVENT = 3, + RSI_BLE_ON_ADV_EXT_PERIODIC_ADVERTISE_REPORT_EVENT = 4, + RSI_BLE_ON_ADV_EXT_PERIODIC_ADV_SYNC_LOST_EVENT = 5, + RSI_BLE_ON_ADV_EXT_SCAN_TIMEOUT_EVENT = 6, + RSI_BLE_ON_ADV_EXT_ADVERTISE_SET_TERMINATED_EVENT = 7, + RSI_BLE_ON_ADV_EXT_SCAN_REQUEST_RECEIVED_EVENT = 8, +} rsi_ble_callback_id_t; + +/******************************************************** + * * Structure Definitions + * ******************************************************/ + +// GAP command structures +typedef struct rsi_ble_req_rand_s { + //uint8, random address of the device to be set + uint8_t rand_addr[RSI_DEV_ADDR_LEN]; +} rsi_ble_req_rand_t; + +// Advertising command structure +typedef struct rsi_ble_req_adv_s { + /** Advertising Status \n + 0 - disable \n 1 - enable*/ + uint8_t status; + /** Advertising type used during advertising \n + 1. Advertising will be visible(discoverable) to all the devices. Scanning/Connection is also accepted from all devices. \n + #define UNDIR_CONN 0x80 \n + 2. Advertising will be visible(discoverable) to the particular device mentioned in RSI_BLE_ADV_DIR_ADDR only. \n + Scanning and Connection will be accepted from that device only. \n + #define DIR_CONN 0x81 \n + 3. Advertising will be visible(discoverable) to all the devices. Scanning will be accepted from all the devices. \n + Connection will be not be accepted from any device. \n + #define UNDIR_SCAN 0x82 \n + 4. Advertising will be visible(discoverable) to all the devices. Scanning and Connection will not be accepted from any device. \n + #define UNDIR_NON_CONN 0x83 \n + 5. Advertising will be visible(discoverable) to the particular device mentioned in RSI_BLE_ADV_DIR_ADDR only. \n + Scanning and Connection will be accepted from that device only. \n + #define DIR_CONN_LOW_DUTY_CYCLE 0x84 */ + uint8_t adv_type; + /** Advertising filter type \n + #define ALLOW_SCAN_REQ_ANY_CONN_REQ_ANY 0x00 \n + #define ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_ANY 0x01 \n + #define ALLOW_SCAN_REQ_ANY_CONN_REQ_WHITE_LIST 0x02 \n + #define ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_WHITE_LIST 0x03 */ + uint8_t filter_type; + /** Address type of the device to which directed advertising has to be done \n + #define LE_PUBLIC_ADDRESS 0x00 \n + #define LE_RANDOM_ADDRESS 0x01 \n + #define LE_RESOLVABLE_PUBLIC_ADDRESS 0x02 \n + #define LE_RESOLVABLE_RANDOM_ADDRESS 0x03 */ + uint8_t direct_addr_type; + /** Address of the device to which directed advertising has to be done */ + uint8_t direct_addr[RSI_DEV_ADDR_LEN]; + + /** Advertising interval min 0x0020 to 0x4000 */ + uint16_t adv_int_min; + + /** Advertising interval max 0x0020 to 0x4000 */ + uint16_t adv_int_max; + + /** Address of the local device. \n + #define LE_PUBLIC_ADDRESS 0x00 \n + #define LE_RANDOM_ADDRESS 0x01 \n + #define LE_RESOLVABLE_PUBLIC_ADDRESS 0x02 \n + #define LE_RESOLVABLE_RANDOM_ADDRESS 0x03 */ + uint8_t own_addr_type; + + /** Advertising channel map. \n + #define RSI_BLE_ADV_CHANNEL_MAP 0x01 or 0x03 or 0x07 */ + uint8_t adv_channel_map; +} rsi_ble_req_adv_t; + +// Advertising data command structure +typedef struct rsi_ble_req_adv_data_s { + //uint8, advertising data length + uint8_t data_len; + //uint8, advertising data + uint8_t adv_data[31]; +} rsi_ble_req_adv_data_t; + +// Adv data payload for whitelisting based on the payload +typedef struct rsi_ble_req_whitelist_using_payload_s { + uint8_t opcode[2]; + uint8_t enable; + uint8_t total_len; + uint8_t data_compare_index; + uint8_t len_for_compare_data; + uint8_t adv_data_payload[31]; +} rsi_ble_req_whitelist_using_payload_t; + +#define BLE_PROTOCOL 0x01 +#define PROP_PROTOCOL 0x02 +// Set BLE PROTOCOL and PROP_PROTOCOL bandedge tx power cmd_ix=0x012A +typedef struct rsi_ble_set_prop_protocol_ble_bandedge_tx_power_s { + uint8_t protocol; + int8_t tx_power; +} rsi_ble_set_prop_protocol_ble_bandedge_tx_power_t; + +#define ADV_ROLE 0x01 +#define SCAN_AND_CENTRAL_ROLE 0x02 +#define PERIPHERAL_ROLE 0x03 +#define CONN_ROLE 0x04 +// Set BLE tx power per role cmd_ix=0x012D +typedef struct rsi_ble_set_ble_tx_power_s { + uint8_t role; + //Address of the device + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t tx_power; +} rsi_ble_set_ble_tx_power_t; + +//Scan response data command structure +typedef struct rsi_ble_req_scanrsp_data_s { + //uint8, scanresponse data length + uint8_t data_len; + //uint8, scanresponse data + uint8_t scanrsp_data[31]; +} rsi_ble_req_scanrsp_data_t; + +//Scan command structure +typedef struct rsi_ble_req_scan_s { + + /** Scanning Status \n + 0 - disable \n 1 - enable*/ + uint8_t status; + + /** Scanning type \n + #define SCAN_TYPE_ACTIVE 0x01 \n + #define SCAN_TYPE_PASSIVE 0x00 */ + uint8_t scan_type; + + /** To filter incoming advertising reports \n + FILTERING_DISABLED = 0 (default) \n + WHITELIST_FILTERING = 1 + @note In order to allow only whitelisted devices, need to add bd_addr + into whitelist by calling @ref rsi_ble_addto_whitelist() API */ + uint8_t filter_type; + + /** Address type of the local device \n + #define LE_PUBLIC_ADDRESS 0x00 \n + #define LE_RANDOM_ADDRESS 0x01 \n + #define LE_RESOLVABLE_PUBLIC_ADDRESS 0x02 \n + #define LE_RESOLVABLE_RANDOM_ADDRESS 0x03 */ + uint8_t own_addr_type; + + /** Scan interval \n + This is defined as the time interval from when the Controller started + its last LE scan until it begins the subsequent LE scan. \n + Range: 0x0004 to 0x4000 */ + uint16_t scan_int; + + /** Scan window \n + The duration of the LE scan. LE_Scan_Window shall be less than or equal to LE_Scan_Interval \n + Range: 0x0004 to 0x4000 */ + uint16_t scan_win; + +} rsi_ble_req_scan_t; + +//ENCRYPT COMMAND STRUCTURE + +typedef struct rsi_ble_encrypt_s { + + uint8_t key[16]; + uint8_t data[16]; + +} rsi_ble_encrypt_t; + +//White list structure +typedef struct rsi_ble_white_list_s { + //This bit is used to add or delet the address form/to whit list + uint8_t addordeltowhitlist; + //Address of the device + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //Address type + uint8_t bdaddressType; + +} rsi_ble_white_list_t; + +//Connect command structure +typedef struct rsi_ble_req_conn_s { + //uint8, address type of the device to connect + uint8_t dev_addr_type; + //uint8[6], address of the device to connect + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint16, scan interval + uint16_t le_scan_interval; + //uint16, scan window + uint16_t le_scan_window; + //uint16, minimum connection interval + uint16_t conn_interval_min; + //uint16, maximum connection interval + uint16_t conn_interval_max; + //uint16, connection latency + uint16_t conn_latency; + //uint16, supervision timeout + uint16_t supervision_tout; +} rsi_ble_req_conn_t; + +typedef struct rsi_ble_req_enhance_conn_s { + //uint8, address type of the device to connect + uint8_t dev_addr_type; + //uint8[6], address of the device to connect + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8, filter policy + uint8_t filter_policy; + //uint8, own address type + uint8_t own_addr_type; + //uint16, scan interval + uint16_t le_scan_interval; + //uint16, scan window + uint16_t le_scan_window; + //uint16, minimum connection interval + uint16_t conn_interval_min; + //uint16, maximum connection interval + uint16_t conn_interval_max; + //uint16, connection latency + uint16_t conn_latency; + //uint16, supervision timeout + uint16_t supervision_tout; + //uint16, minimum connection event length + uint16_t min_ce_length; + //uint16, maximum connection event length + uint16_t max_ce_length; +} rsi_ble_req_enhance_conn_t; + +//Disconnect command structure +typedef struct rsi_ble_req_disconnect_s { + //uint8[6], address of the device to disconnect + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +#define COMPATABILITY 0 +#define BLE_CONNECT_CANCEL 1 +#define BLE_DISCONNECT 2 + uint8_t type; +} rsi_ble_req_disconnect_t; + +//SMP protocol structures + +//start encryption cmd structures +typedef struct rsi_ble_start_encryption_s { + //uint8[6], address of the connected device + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint16, remote device ediv value + uint16_t ediv; + //uint8[8], remote device rand value + uint8_t rand[8]; + //uint8[16], remote device ltk value + uint8_t ltk[16]; +} rsi_ble_strat_encryption_t; + +//SMP Pair Request command structure = 0x007C +typedef struct rsi_ble_req_smp_pair_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t io_capability; + uint8_t mitm_req; +} rsi_ble_req_smp_pair_t; + +//SMP Response command structure = 0x007D +typedef struct rsi_ble_smp_response_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t io_capability; + uint8_t mitm_req; +} rsi_ble_smp_response_t; + +//SMP Passkey command structure, cmd_ix - 0x007E +typedef struct rsi_ble_smp_passkey_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + uint32_t passkey; +} rsi_ble_smp_passkey_t; + +//LE ping get auth payload timeout command structure, cmd_ix - 0x00A1 +typedef struct rsi_ble_get_le_ping_timeout_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_ble_get_le_ping_timeout_t; + +//LE ping get auth payload timeout command structure, cmd_ix - 0x00A2 +typedef struct rsi_ble_rsp_get_le_ping_timeout_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t time_out; +} rsi_ble_rsp_get_le_ping_timeout_t; + +//LE ping get auth payload timeout command structure, cmd_ix - 0x00A2 +typedef struct rsi_ble_set_le_ping_timeout_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t time_out; +} rsi_ble_set_le_ping_timeout_t; + +//LE Add Device to resolvlist command structure, cmd_ix - 0x00AD +typedef struct rsi_ble_resolvlist_s { + uint8_t process_type; + uint8_t remote_dev_addr_type; + uint8_t remote_dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t peer_irk[16]; + uint8_t local_irk[16]; +} rsi_ble_resolvlist_t; + +//LE Get resolvlist size command structure, cmd_ix - 0x00AE +typedef struct rsi_ble_get_resolving_list_size_s { + + uint8_t size; +} rsi_ble_get_resolving_list_size_t; + +//LE Set address resolution enable command structure, cmd_ix - 0x00AF +typedef struct rsi_ble_set_addr_resolution_enable_s { + + uint8_t enable; + uint8_t reserved; + uint16_t tout; +} rsi_ble_set_addr_resolution_enable_t; + +//LE conn params update command structure, cmd_ix - 0x007A +typedef struct rsi_ble_cmd_conn_params_update_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t min_interval; + uint16_t max_interval; + uint16_t latency; + uint16_t timeout; +} rsi_ble_cmd_conn_params_update_t; + +//LE read phy request command structure, cmd_ix - 0x00B0 +typedef struct rsi_ble_req_read_phy_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_ble_req_read_phy_t; + +//LE set phy command reasponse structure, cmd_ix - 0x00B1 +typedef struct rsi_ble_set_phy_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t all_phy; + uint8_t tx_phy; + uint8_t rx_phy; + uint8_t reserved; + uint16_t phy_options; +} rsi_ble_set_phy_t; + +//LE set data length command reasponse structure, cmd_ix - 0x00B2 +typedef struct rsi_ble_setdatalength_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t txoctets; + uint16_t txtime; +} rsi_ble_setdatalength_t; + +//LE set privacy mode command structure, cmd_ix - 0x00B4 +typedef struct rsi_ble_set_privacy_mode_s { + uint8_t remote_dev_addr_type; + uint8_t remote_dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t privacy_mode; +} rsi_ble_set_privacy_mode_t; + +//LE cbfc connection req command structure, cmd_ix - 0x00B5 +typedef struct rsi_ble_cbfc_conn_req_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t psm; +} rsi_ble_cbfc_conn_req_t; + +//LE cbfc connection resp command structure, cmd_ix - 0x00B6 +typedef struct rsi_ble_cbfc_conn_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t lcid; + uint8_t result; +} rsi_ble_cbfc_conn_resp_t; + +//LE cbfc data TX command structure, cmd_ix - 0x00B7 +typedef struct rsi_ble_cbfc_data_tx_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t lcid; + uint16_t len; + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_cbfc_data_tx_t; + +//LE cbfc disconn command structure, cmd_ix - 0x00B8 +typedef struct rsi_ble_cbfc_disconn_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t lcid; +} rsi_ble_cbfc_disconn_t; + +//LE RX text mode (cmd), cmd_ix = 0x00BB +typedef struct rsi_ble_rx_test_mode_s { + uint8_t rx_channel; + uint8_t phy; + uint8_t modulation; +} rsi_ble_rx_test_mode_t; + +//LE TX test mode (cmd), cmd_ix = 0x00BC +typedef struct rsi_ble_tx_test_mode_s { + uint8_t tx_channel; + uint8_t phy; + uint8_t tx_len; + uint8_t tx_data_mode; +} rsi_ble_tx_test_mode_t; + +//LE End test mode (cmd), cmd_ix = 0x00BD +typedef struct rsi_ble_end_test_mode_s { + uint16_t num_of_pkts; +} rsi_ble_end_test_mode_t; + +typedef struct rsi_ble_set_le_ltkreqreply_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t replytype; + uint8_t localltk[16]; +} rsi_ble_set_le_ltkreqreply_t; + +//SMP Pairing Failed (cmd), cmd_ix = 0x0111 +typedef struct rsi_ble_req_smp_pair_failed_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reason; +} rsi_ble_req_smp_pair_failed_t; + +// GATT structures + +// GATT Profiles list request structure +typedef struct rsi_ble_req_profiles_list_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], profiles search will be start from start_handle. + uint16_t start_handle; + //uint8[2], profile search will stop with end_handle. + uint16_t end_handle; +} rsi_ble_req_profiles_list_t; + +// GATT Profile request structure +typedef struct rsi_ble_req_profile_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], reserved. + uint8_t reserved[2]; + //uint8[20], profile UUID. + uuid_t profile_uuid; +} rsi_ble_req_profile_t; + +// GATT Profile response structure +//profile_descriptors_t; + +// GATT multiple characteristic services request structure +typedef struct rsi_ble_req_char_services_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], search will be start from start_handle. + uint8_t start_handle[2]; + //uint8[2], search will be end with end_handle. + uint8_t end_handle[2]; +} rsi_ble_req_char_services_t; + +// GATT include service query request structure +typedef struct rsi_ble_req_inc_services_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], search will be start from start_handle. + uint8_t start_handle[2]; + //uint8[2], search will be end with end_handle. + uint8_t end_handle[2]; +} rsi_ble_req_inc_services_t; + +// GATT read value by UUID request structure +typedef struct rsi_ble_req_char_val_by_uuid_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], search will be start from start_handle. + uint8_t start_handle[2]; + //uint8[2], search will be end with end_handle. + uint8_t end_handle[2]; + //uint8[2], reserved. + uint8_t reserved[2]; + //uint8[20], search UUID value. + uuid_t char_uuid; +} rsi_ble_req_char_val_by_uuid_t; + +// GATT read value by UUID response structure +//rsi_ble_resp_att_value_t + +// GATT multiple attribute descriptors request structure +typedef struct rsi_ble_req_att_descs_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], search will be start from start_handle. + uint8_t start_handle[2]; + //uint8[2], search will be end with end_handle. + uint8_t end_handle[2]; +} rsi_ble_req_att_descs_t; + +// GATT attribute value request structure +typedef struct rsi_ble_req_att_value_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint8_t handle[2]; +} rsi_ble_req_att_value_t; + +// GATT multiple attribute values request structure +typedef struct rsi_ble_req_multiple_att_val_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8, number of attributes handles. + uint8_t num_of_handles; + //uint8, reserved + uint8_t reserved; + //(uint16 * 5), list of attributes handles. + uint16_t handles[RSI_BLE_MAX_RESP_LIST]; + +} rsi_ble_req_multi_att_values_t; + +// GATT multiple attribute values response structure +//rsi_ble_resp_att_value_t + +// GATT long attribute value request structure +typedef struct rsi_ble_req_long_att_value_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint16_t handle; + //uint16, attribute value offset . + uint16_t offset; +} rsi_ble_req_long_att_value_t; + +// GATT long attribute value response structure +//rsi_ble_resp_att_value_t + +// GATT write attribute value request structure +typedef struct rsi_ble_set_att_val_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint8_t handle[2]; + //uint8, length of attribute value. + uint8_t length; + //uint8[25], attribute value. + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_set_att_value_t; + +// GATT write attribute value without ack request structure +typedef struct rsi_ble_set_att_cmd_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint8_t handle[2]; + //uint8, length of attribute value. + uint8_t length; + //uint8[25], attribute value. + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_set_att_cmd_t; + +// GATT write long attribute value request structure +typedef struct rsi_ble_set_long_att_val_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint8_t handle[2]; + //uint8[2], attribute value offset. + uint8_t offset[2]; + //uint8, length of attribute value. + uint8_t length; + //uint8[40], attribute value. + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_set_long_att_value_t; + +// GATT prepare write value request structure +typedef struct rsi_ble_req_prepare_write_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint8_t handle[2]; + //uint8[2], attribute value offset. + uint8_t offset[2]; + //uint8, length of attribute value. + uint8_t length; + //uint8[40], attribute value. + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_req_prepare_write_t; + +// GATT execute write request structure +typedef struct rsi_ble_req_execute_write_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8, execute flag(write/don't write). + uint8_t flag; +} rsi_ble_req_execute_write_t; + +//RSI_BLE_CONN_PARAM_RESP_CMD, cmd_id: 0x0105 +typedef struct rsi_ble_cmd_conn_param_resp { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8, accept or reject the remote conn param request + uint8_t status; +} rsi_ble_cmd_conn_param_resp_t; + +//GATT Events + +//GATT Service +// add new GATT service request structure +typedef struct rsi_ble_req_add_serv_s { + //uint8[20], service_uuid. + uuid_t service_uuid; + //uint8, number of attribute in the service need to use. + uint8_t num_of_attributes; + //uint8, total attributes value(data) size. + uint8_t total_att_datasize; +} rsi_ble_req_add_serv_t; + +// write or change local attribute value request structure +typedef struct rsi_ble_set_local_att_value_s { + //uint8[2], attribute handle. + uint16_t handle; + //uint8[2], attribute value length. + uint16_t data_len; + //uint8[31], attribute value (data). + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_set_local_att_value_t; + +// write or change local attribute value request structure +typedef struct rsi_ble_notify_att_value_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + uint16_t handle; + //uint8[2], attribute value length. + uint16_t data_len; + //uint8[31], attribute value (data). + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_notify_att_value_t; + +// set wo_resp and notify buffer info +typedef struct rsi_ble_set_wo_resp_notify_buf_info_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + // uint8_t buffer config mode 0. small buf mode, 1. big buf mode + uint8_t buf_mode; + // uint8_t buffer count + uint8_t buf_count; + +} rsi_ble_set_wo_resp_notify_buf_info_t; + +// indicate confirmation structure +typedef struct rsi_ble_indicate_confirm_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_ble_indicate_confirm_t; + +// read local attribute value request structure +typedef struct rsi_ble_get_local_att_value_s { + //uint8[2], attribute handle. + uint16_t handle; +} rsi_ble_get_local_att_value_t; + +typedef struct rsi_ble_gatt_read_response_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8[2], attribute handle. + // uint16_t handle; + // uint16_t offset; + uint8_t type; + uint8_t reserved; + //uint8[2], attribute value length. + uint16_t data_len; + //uint8[31], attribute value (data). + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_gatt_read_response_t; + +// Att write/ execute write respomse cmd = 0x010A +typedef struct rsi_ble_gatt_write_response_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + // uint8_t response type + uint8_t type; +} rsi_ble_gatt_write_response_t; + +// Att prepare write response cmd = 0x010B +typedef struct rsi_ble_gatt_prepare_write_response_s { + //uint8[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t handle; + uint16_t offset; + uint16_t data_len; + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_gatt_prepare_write_response_t; + +// BLE Set local irk cmd id = 0x010C +typedef struct rsi_ble_set_local_irk_s { + // uint8[16], local device irk + uint8_t irk[16]; +} rsi_ble_set_local_irk_t; + +// BLE GAP extended callback ids +typedef enum rsi_ble_gap_extended_callbacks_s { + RSI_BLE_ON_REMOTE_DEVICE_INFORMATION = 1, + +} rsi_ble_gap_extended_callbacks_t; + +//attribute codes +#define RSI_BLE_ATT_EXCHANGE_MTU_REQUEST 0x02 +#define RSI_BLE_ATT_FIND_INFORMATION_REQUEST 0x04 +#define RSI_BLE_ATT_FIND_BY_TYPE_VALUE_REQUEST 0x06 +#define RSI_BLE_ATT_READ_BY_TYPE_REQUEST 0x08 +#define RSI_BLE_ATT_READ_REQUEST 0x0A +#define RSI_BLE_ATT_READ_BLOB_REQUEST 0x0C +#define RSI_BLE_ATT_READ_MULTIPLE_REQUEST 0x0E +#define RSI_BLE_ATT_READ_BY_GROUP_TYPE_REQUEST 0x10 +#define RSI_BLE_ATT_WRITE_REQUEST 0x12 +#define RSI_BLE_ATT_PREPARE_WRITE_REQUEST 0x16 +#define RSI_BLE_ATT_EXECUTE_WRITE_REQUEST 0x18 + +// Att error response cmd = 0x00C1 +typedef struct rsi_ble_att_error_response_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t req_opcode; + uint16_t att_handle; + uint8_t err_code; +} rsi_ble_att_error_response_t; + +//white list(cmd), cmd_ix = 0x00AB +typedef struct rsi_ble_gatt_remove_serv_s { + uint32_t serv_hndler; +} rsi_ble_gatt_remove_serv_t; + +//white list(cmd), cmd_ix = 0x00AC +typedef struct rsi_ble_gatt_remove_att_s { + uint32_t serv_hndler; + uint16_t att_hndl; +} rsi_ble_gatt_remove_att_t; + +// rf type command structure +typedef struct rsi_ble_vendor_rf_type_s { + uint8_t opcode[2]; + uint8_t ble_power_index; +} rsi_ble_vendor_rf_type_t; + +// rf type command structure +typedef struct rsi_ble_mtu_exchange_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t req_mtu_size; +} rsi_ble_mtu_exchange_t; + +// mtu exchange resp command structure +typedef struct rsi_ble_mtu_exchange_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t req_mtu_size; +} rsi_ble_mtu_exchange_resp_t; + +typedef struct rsi_ble_ae_get_supported_no_of_adv_sets_s { + uint16_t reserved; //sets_cnt; +} __attribute__((__packed__)) rsi_ble_ae_get_supported_no_of_adv_sets_t; + +typedef struct rsi_ble_ae_read_supported_max_adv_data_s { + uint16_t reserved; //max_adv_data_len; +} __attribute__((__packed__)) rsi_ble_ae_read_supported_max_adv_data_t; + +// AE Set Random Address (cmd), cmd_ix = +typedef struct rsi_ble_ae_set_random_address_s { + /** uint8_t Advertising_Handle, Used to identify an advertising set , Range : 0x00 to 0xEF */ + uint8_t adv_handle; + /** uint8[6] Random_Address , The Random Address may be of either Static Address or Private Address */ + uint8_t addr[RSI_DEV_ADDR_LEN]; +} __attribute__((__packed__)) rsi_ble_ae_set_random_address_t; + +//! AE Advertising Params +typedef struct ae_adv_params_s { + /** uint8_t, Advertising Handle, Used to identify an Advertising set , Range : 0x00 to 0xEF */ + uint8_t adv_handle; + /** + * uint16_t, Advertising Event Properties, inidicates the properties of Advertising Event + * --------------------------------------------------------------------------------------------------------- + * | Bit Number | Parameter Description | + * ----------------------|----------------------------------------------------------------------------------- + * | 0 | Connectable Advertising | + * | 1 | Scannable Advertising | + * | 2 | Direct Advertising | + * | 3 | High Duty cycle Directed Connectable advertising (≤ 3.75 ms Advertising interval)| + * | 4 | Use legacy advertising PDUs | + * | 5 | Omit advertiser's address from all PDUs("anonymous advertising") | + * | 6 | Include Tx Power in the extended header of at least one advertising PDU | + * */ + uint16_t adv_event_prop; + /** uint32_t, Primary Advertising Interval Minimum, Minimum advertising interval for undirected and low duty cycle directed advertising */ + uint32_t primary_adv_intterval_min : 24; + /** uint32_t, Primary Advertising Interval Maximum, Maximum advertising interval for undirected and low duty cycle directed advertising + primary_adv_intterval_min <= primary_adv_intterval_max */ + uint32_t primary_adv_intterval_max : 24; + /** uint8_t, Primary Advertising Channel Map, It specifies on which channel it shall advertise + Bit Number Parameter Description + 0 Channel 37 shall be used + 1 Channel 38 Shall be used + 2 Channel 39 shall be used + */ + uint8_t primary_adv_chnl_map; + /** + uint8_t, Own_Address_type, Indicates the type of the Address + 0x00 - Public Device Address + 0x01 - Random Device Address + 0x02 - Controller generates the Resolvable Private Address based on the local + IRK from the resolving list. If the resolving list contains no matching + entry, use the public address + 0x03 - Controller generates the Resolvable Private Address based on the local + IRK from the resolving list. If the resolving list contains no matching + entry, use the random address from LE_Set_Advertising_Set_Random_Address + */ + uint8_t own_addr_type; + /** uint8_t, Peer_Address_Type, Specifies Peer Address Type + 0x00 - Public Device Address or Public Identity Address + 0x01 - Random Device Address or Random (static) Identity Address + */ + uint8_t peer_addr_type; + /** uint8[6], Peer_Device_Address, Address of the Peer_Address_Type */ + uint8_t peer_dev_addr[RSI_DEV_ADDR_LEN]; + /** uint8_t, Advertising_Filter_Policy + 0x00 - Process scan and connection requests from all devices (i.e., the Filter Accept List is not in use) + 0x01 - Process connection requests from all devices and scan requests only from devices that are in the Filter Accept List. + 0x02 - Process scan requests from all devices and connection requests only from devices that are in the Filter Accept List. + 0x03 - Process scan and connection requests only from devices in the Filter Accept List. + */ + uint8_t adv_filter_policy; + /** uint8_t Advertising_TX_Power, Advertising TX Power ranges from -127 to +20 and units are in dBm */ + uint8_t adv_tx_power; + /** uint8_t Primary_Advertising_PHY, This parameter specifies the PHY used for the periodic advertising. + 0x01 - Advertiser PHY is LE 1M + 0x03 - Advertiser PHY is LE Coded + */ + uint8_t primary_adv_phy; + /** uint8_t Secondary_Advertising_Max_Skip + 0x00 AUX_ADV_IND shall be sent prior to the next advertising event + 0x01 to 0xFF Maximum advertising events the Controller can skip before sending the AUX_ADV_IND packets on the secondary advertising physical channel + */ + uint8_t sec_adv_max_skip; + /** uint8_t Secondary_Advertising_PHY, This parameter specifies the PHY used for the periodic advertising. + 0x01 - Advertiser PHY is LE 1M + 0x02 - Advertiser PHY is LE 2M + 0x03 - Advertiser PHY is LE Coded + */ + uint8_t sec_adv_phy; + /** uint8_t Advertising_Sid, Value of the Advertising SID subfield in the ADI field of the PDU, Range : 0x00 to 0x0F */ + uint8_t adv_sid; + /** uint8_t Scan Request Notification Enable + 0x00 Scan request notifications disabled + 0x01 Scan request notifications enabled + */ + uint8_t scan_req_notify_enable; + +} __attribute__((__packed__)) rsi_ble_ae_adv_params_t; + +// AE adv,scan_rsp and periodic data +typedef struct rsi_ble_ae_data_s { + +#define AE_ADV_DATA 0x01 +#define AE_SCAN_RSP_DATA 0x02 + /** AE_ADV_DATA_TYPE  1 + AE_PERIODIC_ADV_DATA_TYPE 2 + AE_SCAN_RSP_DATA_TYPE     3 */ + uint8_t type; + /** uint8_t Advertising Handle, used to identify an Advertising set, Ranges from 0x00 to 0xEF */ + uint8_t adv_handle; + /** uint8_t Operation + 0x00 - Intermediate fragment of fragmented extended advertising data + 0x01 - First fragment of fragmented extended advertising data + 0x02 - Last fragment of fragmented extended advertising data + 0x03 - Complete extended advertising data + 0x04 - Unchanged data (just update the Advertising DID) + */ + uint8_t operation; + /** + uint8_t Fragment_Preference, Specifies the controller on where to fragment the Host advertising Data + 0x00 - The Controller may fragment all Host advertising data + 0x01 - The Controller should not fragment or should minimize fragmentation of Host advertising data + */ + uint8_t frag_pref; + /** uint8_t Data Length, Specifies Advertising_Data_Length , This parameter ranges from 0 to 251 */ + uint8_t data_len; + /** uint8_t Data ,Specifies Advertising_Data. */ + uint8_t data[0xC8]; //FIXME +} __attribute__((__packed__)) rsi_ble_ae_data_t; + +//! AE Advertising enable +typedef struct rsi_ble_ae_adv_enabel_s { + /** + uint8_t Enable, This parameter specifies whether to disable or Enable Advertising + 0x00 - Advertising is disabled + 0x01 - Advertising is Enabled + */ + uint8_t enable; + /** + uint8_t Num_of_Sets , Inidcates on how many Advertising sets to be disabled or enabled for Advertising + 0x00 - Disable all advertising sets + 0x01 to 0x3F - Number of advertising sets to enable or disable + */ + uint8_t no_of_sets; + /** uint8_t Advertising_Handle, used to identify Advertising set, Ranges from 0x00 to 0xEF */ + uint8_t adv_handle; + /** + uint16_t Duration, specifies the duration to continue advertising + 0x00 - No Advertising + 0x0001 to 0xFFFF , Advertising Duration + */ + uint16_t duration; + /** uint8_t Maximum Extended Advertising Events, It specifies the Maximum number of extended advertising events the Controller shall + attempt to send prior to terminating the extended advertising */ + uint8_t max_ae_events; +} __attribute__((__packed__)) rsi_ble_ae_adv_enable_t; + +//AE adv set clear/remove +typedef struct rsi_ble_ae_adv_set_clear_or_remove_s { + /** + type - Specifies whether to remove or clear the advertising sets. + {1} - clear + {2} - remove + */ + uint8_t type; + /** uint8_t Advertising_Handle, used to identify Advertising set, Ranges from 0x00 to 0xEF */ + uint8_t adv_handle; +} __attribute__((__packed__)) rsi_ble_ae_adv_set_clear_or_remove_t; + +//AE periodic adv params +typedef struct ae_periodic_adv_params { + /** uint8_t, Advertising Handle , this parameter identifies the advertising set whose periodic advertising parameters are being configured + * Rang : 0x00 to 0xEF */ + uint8_t adv_handle; + /** uint16_t, Minimum Interval,Minimum advertising interval for periodic advertising.Range: 0x0006 to 0xFFFF */ + uint16_t min_interval; + /**uint16_t, Maximum Interval,Maximum advertising interval for periodic advertising.Range: 0x0006 to 0xFFFF */ + uint16_t max_interval; + /** uint16_t, Periodic Advertising Properties, this parameter indicates which fields should be included in the advertising packet + * Bit Number, 6: Include TxPower in the advertising PDU + * All other Values - Reserved For future use */ + uint16_t properties; +} __attribute__((__packed__)) rsi_ble_ae_periodic_adv_params_t; + +//AE periodic adv enable +typedef struct ae_periodic_adv_enable { + /** uint8_t, enable, If this parameter is set Periodic Advertising starts + * 0 - Enable Periodic Advertising + * 1 - Include the ADI field in AUX_SYNC_IND PDUs +*/ + uint8_t enable; + /** uint8_t, Advertising Handle, Used to identify an advertising set + * Range : 0x00 to 0xEF +*/ + uint8_t adv_handle; +} __attribute__((__packed__)) rsi_ble_ae_periodic_adv_enable_t; + +typedef struct ae_scan_params_s { + /** uint8_t, Scan Type, this parameter specifies the type of scan to perform + * 0x00 - Passive Scanning. No scan request PDUs shall be sent. + * 0x01 - Active Scanning. Scan request PDUs may be sent. +*/ + uint8_t ScanType; + /** uint16_t, Scan Interval, this parameter is a recommendation from the Host on how frequently the Controller should scan + * Range : 0x0004 to 0xFFFF */ + uint16_t ScanInterval; + /** uint16_t, Scan Window, this parameter is a recommendation from the Host on how long the Controller should scan + * Range : 0x0004 to 0xFFFF */ + uint16_t ScanWindow; +} __attribute__((__packed__)) ae_scan_params_t; + +//AE set sacn params +#define SUPPORTED_SCNNING_PHYS 2 +typedef struct rsi_ble_ae_set_scan_params_s { + /** unit8_t,The Own Address Type parameter indicates the type of address being used in the scan request packets + * Value Parameter Description + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 Controller generates the Resolvable Private Address based on the local IRK from the resolving list. + * If the resolving list contains no matching entry, then use the public address. + * 0x03 Controller generates the Resolvable Private Address based on the local IRK from the resolving list. + * If the resolving list contains no matching entry, then use the random address from LE_Set_Random_Address. + * All other values Reserved for future use + * + */ + uint8_t own_addr_type; + /** uint8_t, It is used to determine whether the Filter Accept List is used + * + * 0x00 Basic unfiltered scanning filter policy + * 0x01 Basic filtered scanning filter policy + * 0x02 Extended unfiltered scanning filter policy + * 0x03 Extended filtered scanning filter policy + * All other values Reserved for future use + */ + uint8_t scanning_filter_policy; + /** uint8_t, The Scanning_PHYs parameter indicates the PHY(s) on which the advertising packets should be + received on the primary advertising physical channel. + * + * 0 Scan advertisements on the LE 1M PHY + * 2 Scan advertisements on the LE Coded PHY + * All other bits Reserved for future use + */ + uint8_t scanning_phys; + /** ScanParams is an array of variable of structure ae_scan_params_s */ + ae_scan_params_t ScanParams[SUPPORTED_SCNNING_PHYS]; +} __attribute__((__packed__)) rsi_ble_ae_set_scan_params_t; + +//AE set scan enable +typedef struct rsi_ble_ae_set_scan_enable_s { + /** uint8_t, Enable, this Parameter determines whether scanning is enabled or disabled + * + * 0x00 Scanning disabled + * 0x01 Scanning enabled + * All other values Reserved for future use + */ + uint8_t enable; + /** uint8_t, Filter duplicates, this parameter controls whether the Link Layer should filter out duplicate advertising reports + * to the Host or if the Link Layer should generate advertising reports for each packet received + * + * 0x00 Duplicate Filtering Disabled + * 0x01 Duplicate Filtering Enabled + * 0x02 Duplicate filtering enabled, reset for each scan period + * All other Values Reserved for future use + */ + uint8_t filter_duplicates; + /** uint16_t, Duration, The duration of a scan period refers to the time spent scanning on both the primary and secondary advertising physical channels + * Range : 0x0001 to 0xFFFF + */ + uint16_t duration; + /** uint16_t, Period , Time interval from when the Controller started its last Scan_Duration until it begins the subsequent Scan_Duration + * Range : 0x0001 to 0xFFFF +*/ + uint16_t period; +} __attribute__((__packed__)) rsi_ble_ae_set_scan_enable_t; + +//#pragma pack(push, 1) +typedef struct rsi_ble_ae_set_periodic_adv_create_sync_s { + + uint8_t fil_policy; + /** uint8_t, Advertising SID subfield in the ADI field used to identify the Periodic Advertising . + * Range : 0x00 to 0x0F, All other bits - Reserved for future use +*/ + uint8_t adv_sid; + /** uint8_t, Advertiser Address Type, this parameter indicates the type of address being used in the connection request packets + * + * 0x00 Public Device Address or Public Identity Address + * 0x01 Random Device Address or Random (static) Identity Address + * All other values Reserved for future use + */ + uint8_t adv_addr_type; + /** uint8_t, Advertiser Address[6]*/ + uint8_t adv_addr[RSI_DEV_ADDR_LEN]; + /** uint16_t, Skip,The maximum number of periodic advertising events that can be skipped after a successful receive + * Range : 0x0000 to 0x01F3 */ + uint16_t skip; + /** uint16_t, Sync Timeout, Synchronization timeout for the periodic advertising train + * Range : 0x000A to 0x4000 */ + uint16_t sync_timeout; + uint8_t reserved; +} __attribute__((__packed__)) rsi_ble_ae_set_periodic_adv_create_sync_t; + +typedef struct rsi_ble_ae_set_periodic_adv_terminate_sync_s { + /** uint16_t, Sync Handle, identifies the periodic Advertising Train + * Range : 0x0000 to 0x0EFF*/ + uint16_t sync_handle; +} __attribute__((__packed__)) rsi_ble_ae_set_periodic_adv_terminate_sync_t; + +//AE set periodic sync(create/terminate or cancel) params +typedef struct rsi_ble_ae_set_periodic_sync_s { + +#define BLE_AE_PERIODIC_SYNC_CREATE 0x01 +#define BLE_AE_PERIODIC_SYNC_CREATE_CANCEL 0x02 +#define BLE_AE_PERIODIC_SYNC_TERMINATE 0x03 + uint8_t type; + union { + rsi_ble_ae_set_periodic_adv_create_sync_t create_sync; + rsi_ble_ae_set_periodic_adv_terminate_sync_t terminate_sync; + } __attribute__((__packed__)) sync_type; +} __attribute__((__packed__)) rsi_ble_ae_set_periodic_sync_t; +//#pragma pack(pop) +// AE add/remove/clear dev to/from periodic adv list +typedef struct rsi_ble_ae_dev_to_periodic_list_s { + /** uint8_t, Type + * Type Values Description + * 1 Adding Device to Periodic Advertising list + * 2 Removing Device from Periodic Advertising list + * 3 Clearing Periodic Advertising List +*/ + uint8_t type; + /** uint8_t, Advertiser Address Type, this parameter indicates the type of address being used in the connection request packets + * + * 0x00 Public Device Address or Public Identity Address + * 0x01 Random Device Address or Random (static) Identity Address + * All other values Reserved for future use +*/ + uint8_t adv_addr_type; + /** uint8_t, Advertiser Address[6]*/ + uint8_t adv_addr[RSI_DEV_ADDR_LEN]; + /** uint8_t, Advertising_Sid, Value of the Advertising SID subfield in the ADI field of the PDU, Range : 0x00 to 0x0F*/ + uint8_t adv_sid; +} __attribute__((__packed__)) rsi_ble_ae_dev_to_periodic_list_t; + +typedef struct rsi_ble_initiation_params_s { + /** uint16_t, ScanInterval, It is the Time interval from when the Controller started its last scan until it begins the subsequent scan on the primary + * advertising physical channel. Range : 0x0004 to 0xFFFF */ + uint16_t ScanInterval; + /** uint16_t, Scan Window parameter is a recommendation from the host on how long the controller should scan. + * Range : 0x0004 to 0xFFFF */ + uint16_t ScanWindow; + /** uint16_t, Connection interval minimum parameter defines the minimum allowed connection interval. + * Range: 0x0006 to 0x0C80 */ + uint16_t ConnIntervalMin; + /** uint16_t, Connection interval maximum parameter defines the maximum allowed connection interval. + * Range: 0x0006 to 0x0C80*/ + uint16_t ConnIntervalMax; + /** uint16_t, Connection Latency or Maximum Latency parameter defines the maximum allowed Peripheral latency. + * Range: 0x0000 to 0x01F3 */ + uint16_t ConnLatency; + /** uint16_t,Connection Timeout or Supervision Timeout parameter defines the link supervision timeout for the connection. + * Range: 0x000A to 0x0C80*/ + uint16_t ConnSTO; //SuperVisionTimeout + /** uint16_t,The Min CE Length parameter provide the Controller with the expected minimum length of the connection events. + * Range: 0x0000 to 0xFFFF */ + uint16_t MinCELen; + /** uint16_t,The Max CE Length parameter provide the controller with the expected maximum length of the connection events. + * Range: 0x0000 to 0xFFFF */ + uint16_t MaxCELen; +} __attribute__((__packed__)) rsi_ble_initiation_params_t; + +// AE extended create connect +typedef struct rsi_ble_ae_extended_create_connect_s { + /** uint8_t, Initiator Filter Policy,It is used to determine whether the Filter Accept List is used + * Value Parameter Descripton + * 0x00 Filter Accept List is not used to determine which advertiser to connect to Peer_Address_Type and Peer_Address shall be used. + * 0x01 Filter Accept List is used to determine which advertiser to connect to Peer_Address_Type and Peer_Address shall be ignored. + * All other values Reserved for future use + */ + uint8_t initiator_filter_policy; + /** uint8_t, Own Address Type, this parameter indicates the type of address being used in the connection request packets + * + * Value Parameter Description + * 0x00 Public Device Address + * 0x01 Random Device Address + * 0x02 Controller generates the Resolvable Private Address based on the local IRK from the resolving list. + * If the resolving list contains no matching entry, then use the public address. + * 0x03 Controller generates the Resolvable Private Address based on the local IRK from the resolving list. + * If the resolving list contains no matching entry, then use the random address from the most recent successful + * HCI_LE_Set_Random_Address command. + * All other values Reserved for future use + */ + uint8_t own_addr_type; + /** uint8_t, Remote Address Type or Peer Address Type, this paramater indicates the type of address used in the + connectable advertisement sent by the peer + * Value Parameter Description + * 0x00 Public Device Address or Public Identity Address + * 0x01 Random Device Address or Random (static) Identity Address + * All other values Reserved for future use + */ + uint8_t remote_addr_type; + /** uint8_t, Remote Address or Peer Address, this parameter indicates the Peer’s Public Device Address, + Random (static) Device Address, Non-Resolvable Private Address, or Resolvable Private Address depending on the Peer_Address_Type parameter */ + uint8_t remote_addr[RSI_DEV_ADDR_LEN]; + /** uint8_t, Initiating PHYs, this parameter indicates the PHY(s) on which the advertising packets should be received on the + primary advertising physical channel and the PHYs for which connection parameters have been specifiedn + * + * Bit number Parameter Description + * 0 Scan connectable advertisements on the LE 1M PHY. Connection parameters for the LE 1M PHY are provided. + * 1 Connection parameters for the LE 2M PHY are provided. + * 2 Scan connectable advertisements on the LE Coded PHY. Connection parameters for the LE Coded PHY are provided. + * All other bits Reserved for future use + */ + uint8_t init_phys; + /** init_params is an array of Variable of Structure rsi_ble_initiation_params_s */ + rsi_ble_initiation_params_t init_params[3]; +} __attribute__((__packed__)) rsi_ble_ae_extended_create_connect_t; + +// LE Read Transmit Power +typedef struct rsi_ble_tx_pwr_s { + /** int8_t, Minimum TX Power, Range: -127 to +20 */ + int8_t min_tx_pwr; + /** int8_t, Maximum TX Power, Range: -127 to +20 */ + int8_t max_tx_pwr; +} __attribute__((__packed__)) rsi_ble_tx_pwr_t; + +// Query Rf Path Compensation +typedef struct rsi_ble_query_rf_path_comp_s { + /** int16_t, RF TX Path Compensation Value, Range: -128.0 dB (0xFB00) to 128.0 dB (0x0500) */ + int16_t tx_path_value; + /** int16_t, RF RX Path Compensation Value, Range: -128.0 dB (0xFB00) to 128.0 dB (0x0500) */ + int16_t rx_path_value; +} __attribute__((__packed__)) rsi_ble_query_rf_path_comp_t; + +// write Rf Path Compensation +typedef struct rsi_ble_write_rf_path_comp_s { + /** int16_t, RF TX Path Compensation Value, Range: -128.0 dB (0xFB00) to 128.0 dB (0x0500) */ + int16_t tx_path_value; + /** int16_t, RF RX Path Compensation Value, Range: -128.0 dB (0xFB00) to 128.0 dB (0x0500)*/ + int16_t rx_path_value; +} __attribute__((__packed__)) rsi_ble_write_rf_path_comp_t; + +typedef struct rsi_ble_ae_pdu { + uint16_t cmd_sub_opcode; + union { + rsi_ble_ae_get_supported_no_of_adv_sets_t ae_supported_no_of_sets; + rsi_ble_ae_read_supported_max_adv_data_t ae_supported_max_data; + rsi_ble_ae_set_random_address_t ae_random_address; + rsi_ble_ae_adv_params_t ae_adv_params; + rsi_ble_ae_data_t ae_adv_or_scn_rsp_data; + rsi_ble_ae_adv_enable_t ae_adv_enable; + rsi_ble_ae_adv_set_clear_or_remove_t ae_adv_set_clear_or_remove; + rsi_ble_ae_periodic_adv_params_t ae_periodic_adv_params; + rsi_ble_ae_periodic_adv_enable_t ae_periodic_adv_enable; + + rsi_ble_ae_set_scan_params_t ae_scan_params; + rsi_ble_ae_set_scan_enable_t ae_scan_enable; + + rsi_ble_ae_set_periodic_sync_t ae_periodic_sync; + rsi_ble_ae_dev_to_periodic_list_t dev_to_periodic_list; + + rsi_ble_ae_extended_create_connect_t extended_create_conn; + + //uint8_t data[1]; + } __attribute__((__packed__)) pdu_type; +} __attribute__((__packed__)) rsi_ble_ae_pdu_t; + +// Driver BLE control block +struct rsi_ble_cb_s { + // GAP Callbacks + rsi_ble_on_adv_report_event_t ble_on_adv_report_event; + rsi_ble_on_connect_t ble_on_conn_status_event; + rsi_ble_on_disconnect_t ble_on_disconnect_event; + rsi_ble_on_le_ping_payload_timeout_t ble_on_le_ping_time_expired_event; + rsi_ble_on_conn_update_complete_t ble_on_conn_update_complete_event; + rsi_ble_on_remote_features_t ble_on_remote_features_event; + rsi_ble_on_remote_device_info_t ble_on_remote_device_info_event; + rsi_ble_on_le_more_data_req_t ble_on_le_more_data_req_event; + rsi_ble_on_remote_conn_params_request_t ble_on_remote_conn_params_request_event; + + //SMP Callbackes + rsi_ble_on_smp_request_t ble_on_smp_request_event; + rsi_ble_on_smp_response_t ble_on_smp_response_event; + rsi_ble_on_smp_response_t ble_on_cli_smp_response_event; + rsi_ble_on_smp_passkey_t ble_on_smp_passkey_event; + rsi_ble_on_smp_failed_t ble_on_smp_fail_event; + rsi_ble_on_encrypt_started_t ble_on_smp_encrypt_started; + rsi_ble_on_sc_method_t ble_on_sc_method_event; + + // GATT Callbacks + rsi_ble_on_profiles_list_resp_t ble_on_profiles_list_resp; + rsi_ble_on_profile_resp_t ble_on_profile_resp; + rsi_ble_on_char_services_resp_t ble_on_char_services_resp; + rsi_ble_on_inc_services_resp_t ble_on_inc_services_resp; + rsi_ble_on_att_desc_resp_t ble_on_att_desc_resp; + rsi_ble_on_read_resp_t ble_on_read_resp; + rsi_ble_on_write_resp_t ble_on_write_resp; + rsi_ble_on_gatt_write_event_t ble_on_gatt_events; + rsi_ble_on_gatt_prepare_write_event_t ble_on_prepare_write_event; + rsi_ble_on_execute_write_event_t ble_on_execute_write_event; + rsi_ble_on_read_req_event_t ble_on_read_req_event; + rsi_ble_on_mtu_event_t ble_on_mtu_event; + rsi_ble_on_gatt_error_resp_t ble_on_gatt_error_resp_event; + rsi_ble_on_gatt_desc_val_event_t ble_on_gatt_desc_val_resp_event; + rsi_ble_on_event_profiles_list_t ble_on_profiles_list_event; + rsi_ble_on_event_profile_by_uuid_t ble_on_profile_by_uuid_event; + rsi_ble_on_event_read_by_char_services_t ble_on_read_by_char_services_event; + rsi_ble_on_event_read_by_inc_services_t ble_on_read_by_inc_services_event; + rsi_ble_on_event_read_att_value_t ble_on_read_att_value_event; + rsi_ble_on_event_read_resp_t ble_on_read_resp_event; + rsi_ble_on_event_write_resp_t ble_on_write_resp_event; + rsi_ble_on_event_indicate_confirmation_t ble_on_indicate_confirmation_event; + rsi_ble_on_event_prepare_write_resp_t ble_on_prepare_write_resp_event; + + rsi_ble_on_mtu_exchange_info_t ble_on_mtu_exchange_info_event; + + rsi_ble_on_phy_update_complete_t ble_on_phy_update_complete_event; + rsi_ble_on_data_length_update_t rsi_ble_on_data_length_update_event; + + rsi_ble_on_enhance_connect_t ble_on_enhance_conn_status_event; + rsi_ble_on_directed_adv_report_event_t ble_on_directed_adv_report_event; + rsi_ble_on_le_ltk_req_event_t ble_on_le_ltk_req_event; + rsi_ble_on_smp_passkey_display_t ble_on_smp_passkey_display; + rsi_ble_on_sc_passkey_t ble_on_sc_passkey; + rsi_ble_on_le_security_keys_t ble_on_le_security_keys_event; + + //L2CAP CBFC callbacks + rsi_ble_on_cbfc_conn_req_event_t ble_on_cbfc_conn_req_event; + rsi_ble_on_cbfc_conn_complete_event_t ble_on_cbfc_conn_complete_event; + rsi_ble_on_cbfc_rx_data_event_t ble_on_cbfc_rx_data_event; + rsi_ble_on_cbfc_disconn_event_t ble_on_cbfc_disconn_event; + chip_ble_buffers_stats_handler_t ble_on_chip_memory_status_event; + + // AE events callbacks + rsi_ble_ae_report_complete_t ble_ae_report_complete_event; + rsi_ble_ae_per_adv_sync_estbl_t ble_ae_per_adv_sync_estbl_event; + rsi_ble_ae_per_adv_report_t ble_ae_per_adv_report_event; + rsi_ble_ae_per_adv_sync_lost_t ble_ae_per_adv_sync_lost_event; + rsi_ble_ae_scan_timeout_t ble_ae_scan_timeout_event; + rsi_ble_ae_adv_set_terminated_t ble_ae_adv_set_terminated_event; + rsi_ble_ae_scan_req_recvd_t ble_ae_scan_req_recvd_event; +}; + +/****************************************************** + * * BLE internal function declarations + * ******************************************************/ + +void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t *payload, uint16_t payload_length); +int32_t rsi_ble_driver_send_cmd(uint16_t cmd, void *cmd_struct, void *resp); +int32_t rsi_ble_white_list_using_adv_data(uint8_t enable, + uint8_t data_compare_index, + uint8_t len_for_compare_data, + uint8_t *payload); +int32_t rsi_ble_get_multiple_att_values(uint8_t *dev_addr, + uint8_t num_of_handlers, + uint16_t *handles, + rsi_ble_resp_att_value_t *p_att_vals); +#endif diff --git a/wiseconnect/sapi/include/rsi_ble_apis.h b/wiseconnect/sapi/include/rsi_ble_apis.h new file mode 100644 index 00000000..d5965476 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_ble_apis.h @@ -0,0 +1,2827 @@ +/******************************************************************************* +* @file rsi_ble_apis.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_BLE_APIS_H +#define RSI_BLE_APIS_H + +#include +#include +#include + +/****************************************************** + * * Macros + * ******************************************************/ + +#define RSI_BLE_MAX_RESP_LIST 0x05 +#define RSI_MAX_ADV_REPORT_SIZE 31 +#define BLE_PASSKEY_SIZE 6 + +#ifndef BLE_OUTPUT_POWER_FRONT_END_LOSS +#define BLE_OUTPUT_POWER_FRONT_END_LOSS 0 /* db */ +#endif + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures +******************************************************/ + +// GAP Event structures + +//Advertise report event structure +typedef struct rsi_ble_event_adv_report_s { + /**Address type of the advertising device */ + uint8_t dev_addr_type; + /**Address of the advertising device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**Raw advertisement data length*/ + uint8_t adv_data_len; + /**advertisement data*/ + uint8_t adv_data[RSI_MAX_ADV_REPORT_SIZE]; + /**Signal strength*/ + int8_t rssi; + /** Report type \n + 0x00 Connectable and scannable undirected advertising (ADV_IND) \n + 0x01 Connectable directed advertising (ADV_DIRECT_IND) \n + 0x02 Scannable undirected advertising (ADV_SCAN_IND) \n + 0x03 Non connectable undirected advertising (ADV_NONCONN_IND) \n + 0x04 Scan Response (SCAN_RSP) \n + All other values Reserved for future use*/ + uint8_t report_type; +} rsi_ble_event_adv_report_t; + +//Connection status event structure +typedef struct rsi_ble_event_conn_status_s { + /**Address type of the connected device*/ + uint8_t dev_addr_type; + /**Address of the connected device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**status of the connection - success/failure*/ + uint8_t status; + +} rsi_ble_event_conn_status_t; + +//enhance connection status event structure +typedef struct rsi_ble_event_enhnace_conn_status_s { + /**Device address type of the Connected Remote Device*/ + uint8_t dev_addr_type; + /**Device address of the remote device.*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**Local Device resolvable address*/ + uint8_t local_resolvlable_addr[RSI_DEV_ADDR_LEN]; + /**Remote Device resolvable address*/ + uint8_t peer_resolvlable_addr[RSI_DEV_ADDR_LEN]; + /**The role of the device - master/ slave*/ + uint8_t role; + /**Connection interval used on this connection. Range: 0x0006 to 0x0C80*/ + uint16_t conn_interval; + /**Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3*/ + uint16_t conn_latency; + /**Connection supervision timeout. Range: 0x000A to 0x0C80*/ + uint16_t supervision_timeout; + /**Only applicable for slave ,for master this value is set to 0x00*/ + uint8_t master_clock_accuracy; + /**Status of the Connection - success/failure*/ + uint8_t status; +} rsi_ble_event_enhance_conn_status_t; + +//Disconnect event structure +typedef struct rsi_ble_event_disconnect_s { + /**device address of the disconnected device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**device type (Classic/LE) in lower nibble and remote address type in the upper nibble*/ + uint8_t dev_type; + +} rsi_ble_event_disconnect_t; + +//le ping timeout expired event structure +typedef struct rsi_ble_event_le_ping_time_expired_s { + /**Device address of the disconnected device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + +} rsi_ble_event_le_ping_time_expired_t; + +//le ltk request event Structure +typedef struct rsi_bt_event_le_ltk_request_s { + /**BD Address of the remote device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**ediv of local device*/ + uint16_t localediv; + /**rand of local device*/ + uint8_t localrand[8]; + /**Address type of remote device*/ + uint8_t dev_addr_type; +} rsi_bt_event_le_ltk_request_t; + +//le security keys event Structure +typedef struct rsi_bt_event_le_security_keys_s { + /**BD Address of the remote device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**16 byte irk of the local device*/ + uint8_t local_irk[16]; + /**16 byte irk of the remote device*/ + uint8_t remote_irk[16]; + /**remote device ediv value*/ + uint16_t remote_ediv; + /**remote device rand value*/ + uint8_t remote_rand[16]; + /**remote device ltk value*/ + uint8_t remote_ltk[16]; + /**Identity address type - public/random \n + 0x00 --> Public Identity Address \n + 0x01 --> Random (static) Identity Address \n + All other values Reserved for future use*/ + uint8_t Identity_addr_type; + /**Identity address which is resolved after security keys exchange*/ + uint8_t Identity_addr[6]; + /**Device address type*/ + uint8_t dev_addr_type; +} rsi_bt_event_le_security_keys_t; + +//encryption enabled structure +typedef struct rsi_bt_event_encryption_enabled_s { + /**Remote device Address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**Status of the Encryption \n + ENCRYPT_ENABLED BIT(0) --> To indicate or set encryption is enabled AUTH_LTK_OR_STK_ENC \n + BIT(1) --> To indicate or set Authenticated Pairing and Encryption UN_AUTH_LTK_OR_STK_ENC \n + BIT(2) --> To indicate or set UnAuthenticated pairing and Encryption AUTH_LTK_WITH_LE_SC_ENC \n + BIT(3) --> To indicate or set Authenticated Pairing and Enc with LE SC */ + uint8_t enabled; + /**BLE Secure Connections Enable/disable indication \n + 0 --> Disable \n + 1 --> Enable */ + uint8_t sc_enable; + /**Local device EDIV*/ + uint16_t localediv; + /**Local RAND*/ + uint8_t localrand[8]; + /**Local Long term Key*/ + uint8_t localltk[16]; + /**Remote Device Address type*/ + uint8_t dev_addr_type; +} rsi_bt_event_encryption_enabled_t; + +//SMP protocol structure +//SMP Request event structure +typedef struct rsi_bt_event_smp_req_s { + /**address of remote device*/ + uint8_t dev_addr[6]; +} rsi_bt_event_smp_req_t; + +//SMP Response event structure +typedef struct rsi_bt_event_smp_resp_s { + /**address of remote device*/ + uint8_t dev_addr[6]; + /**Device input output capability \n + 0x00 - Display Only \n + 0x01 - Display Yes/No \n + 0x02 - Keyboard Only \n + 0x03 - No Input No Output + 0x04 - Keyboard Dispaly*/ + uint8_t io_cap; + /**Out Of the Band data*/ + uint8_t oob_data; + /**Authentication Request contains bonding type \n + MITM Request - BIT(2) \n + Secure Connections - BIT(3) \n + Keypress - BIT(4) \n + CT2 - BIT(5)*/ + uint8_t auth_req; + /**Minimum required key size*/ + uint8_t min_req_key_size; + /** Initiator generates/requires the no .of keys after successful paring \n + BIT(0) - EncKey: Initiator shall distribute LTK followed by EDIV and Rand \n + BIT(1) - IdKey : Initiator shall distribute IRK followed by its address \n + BIT(2) - Sign : Initiator shall distribute CSRK \n + BIT(3) - BIT(7): Reserved for future use */ + uint8_t ini_key_distrb; + /** Responder generates/requires the no .of keys after successful paring \n + BIT(0) - EncKey: Responder shall distribute LTK followed by EDIV and Rand \n + BIT(1) - IdKey : Responder shall distribute IRK followed by its address \n + BIT(2) - Sign : Responder shall distribute CSRK \n + BIT(3) - BIT(7): Reserved for future use */ + uint8_t resp_key_distrb; +} rsi_bt_event_smp_resp_t; + +//SMP passkey event structure +typedef struct rsi_bt_event_smp_passkey_s { + /**address of remote device*/ + uint8_t dev_addr[6]; +} rsi_bt_event_smp_passkey_t; + +//SMP passkey display event structure +typedef struct rsi_bt_event_smp_passkey_display_s { + /**address of remote device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**This is the key required in pairing process( 6 bytes)*/ + uint8_t passkey[BLE_PASSKEY_SIZE]; +} rsi_bt_event_smp_passkey_display_t; + +//SMP passkey display event structure +typedef struct rsi_bt_event_sc_passkey_s { + /**address of remote device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + /**This is the key required in pairing process*/ + uint32_t passkey; +} rsi_bt_event_sc_passkey_t; + +//SMP failed event structure +typedef struct rsi_bt_event_smp_failed_s { + /**device address of the disconnected device*/ + uint8_t dev_addr[6]; +} rsi_bt_event_smp_failed_t; + +//Security Methods event structure +typedef struct rsi_bt_event_sc_method_s { + /**Security Method --> Justworks or Passkey \n + RSI_BT_LE_SC_JUST_WORKS 0x01 \n + RSI_BT_LE_SC_PASSKEY 0x02 */ + uint8_t sc_method; +} rsi_bt_event_sc_method_t; + +typedef struct rsi_bt_event_ctkd_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t key[16]; +} rsi_ble_event_ctkd_t; + +// phy update complete event +typedef struct rsi_ble_event_phy_update_s { + /**Device address of the remote device.*/ + uint8_t dev_addr[6]; + /**Transmitission phy rate(1 byte) \n + BIT(0) - The Host prefers to use the LE 1M transmitter PHY (possibly among others) \n + BIT(1) - The Host prefers to use the LE 2M transmitter PHY (possibly among others) \n + BIT(2) - The Host prefers to use the LE Coded transmitter PHY (possibly among others) \n + BIT(3) - BIT(7) Reserved for future use */ + uint8_t TxPhy; + /**Reception phy rate(1 byte) \n + BIT(0) - The Host prefers to use the LE 1M transmitter PHY (possibly among others) \n + BIT(1) - The Host prefers to use the LE 2M transmitter PHY (possibly among others) \n + BIT(2) - The Host prefers to use the LE Coded transmitter PHY (possibly among others) \n + BIT(3) - BIT(7) Reserved for future use */ + uint8_t RxPhy; +} rsi_ble_event_phy_update_t; + +// conn update complete event +typedef struct rsi_ble_event_conn_update_s { + /**Device address of the remote device*/ + uint8_t dev_addr[6]; + /**Connection Interval*/ + uint16_t conn_interval; + /**Connection Latency*/ + uint16_t conn_latency; + /**Supervision Timeout*/ + uint16_t timeout; +} rsi_ble_event_conn_update_t; + +// remote conn params request event //event_id : 0x152E +typedef struct rsi_ble_event_remote_conn_param_req_s { + /**Device address of the remote device*/ + uint8_t dev_addr[6]; + /**Minimum connection interval*/ + uint16_t conn_interval_min; + /**Maximum connection interval*/ + uint16_t conn_interval_max; + /**Connection Latency*/ + uint16_t conn_latency; + /**Supervision Timeout*/ + uint16_t timeout; +} rsi_ble_event_remote_conn_param_req_t; + +// remote features event +typedef struct rsi_ble_event_remote_features_s { + /**Remote device address*/ + uint8_t dev_addr[6]; + /**Remote device supported features \n + @note please refer spec for the supported features list */ + uint8_t remote_features[8]; +} rsi_ble_event_remote_features_t; + +// remote device version information event +typedef struct rsi_ble_event_remote_device_info_s { + /** BD address of the remote device */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /** BLE version of the remote device */ + uint8_t remote_version; + /** Company ID of the remote device */ + uint16_t remote_company_id; + /** Sub-Version of the remote device */ + uint16_t remote_sub_version; +} rsi_ble_event_remote_device_info_t; + +// LE Device Buffer Indication +typedef struct rsi_ble_event_le_dev_buf_ind_s { + /**Remote device address*/ + uint8_t remote_dev_bd_addr[RSI_DEV_ADDR_LEN]; + /**No. of Available buffer*/ + uint8_t avail_buf_cnt; +} rsi_ble_event_le_dev_buf_ind_t; + +// phy update complete event +typedef struct rsi_ble_event_data_length_update_s { + /**Device address of the remote device.*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**Maximum Tx Octets to be transmitted*/ + uint16_t MaxTxOctets; + /**Maximu Tx time to transmit the MaxTxOctets*/ + uint16_t MaxTxTime; + /**Maximum Rx Octets to be received*/ + uint16_t MaxRxOctets; + /**Maximum Rx time to receive the MaxRxOctets*/ + uint16_t MaxRxTime; +} rsi_ble_event_data_length_update_t; + +// Basic GATT structures + +// 128 bit UUID format structure +typedef struct uuid128_s { + + uint32_t data1; + uint16_t data2; + uint16_t data3; + uint8_t data4[8]; +} uuid128_t; + +// 16 bit UUID format structure +typedef uint16_t uuid16_t; + +// 32 bit UUID format structure +typedef uint32_t uuid32_t; + +// UUID format structure +typedef struct uuid_s { + /** Size of uuid */ + uint8_t size; + /** Reserved */ + uint8_t reserved[3]; + /** Value of one of the 3 types (128 bit, 32 bit or 16 bit) of UUIDs. */ + union uuid_t { + /** uint8_t[16], 128 bit(16 byte) UUID value*/ + uuid128_t val128; + /**uint8_t[4], 32 bit(4 bytes) UUID value*/ + uuid32_t val32; + /**uint8_t[2], 16 bit(2 bytes) UUID value*/ + uuid16_t val16; + } val; +} uuid_t; + +// profile descriptor/primary service structure +typedef struct profile_descriptor_s { + /** Start handle. */ + uint8_t start_handle[2]; + /** End handle. */ + uint8_t end_handle[2]; + /** profile uuid. */ + uuid_t profile_uuid; +} profile_descriptors_t; + +// GATT attribute descriptor structure +typedef struct att_desc_s { + /**attribute handle*/ + uint8_t handle[2]; + uint8_t reserved[2]; + /**attribute uuid (attribute type)*/ + uuid_t att_type_uuid; +} att_desc_t; + +//characteristic service attribute value structure +typedef struct char_serv_data_s { + /**characteristic value property*/ + uint8_t char_property; + uint8_t reserved; + /**characteristic value handle*/ + uint16_t char_handle; + /**characteristic value attributes uuid*/ + uuid_t char_uuid; +} char_serv_data_t; + +//characteristic service attribute structure +typedef struct char_serv_s { + /**characteristic service attribute handle*/ + uint16_t handle; + uint8_t reserved[2]; + /**characteristic service attribute value*/ + char_serv_data_t char_data; +} char_serv_t; + +//include service attribute value structure +typedef struct inc_serv_data_s { + /**include service start handle*/ + uint16_t start_handle; + /**include service end handle*/ + uint16_t end_handle; + /**UUID value of the included service*/ + uuid_t uuid; +} inc_serv_data_t; + +// include service attribute structure +typedef struct inc_serv_s { + /**include service attribute handle*/ + uint16_t handle; + uint8_t reserved[2]; + /**include service attribute data structure*/ + inc_serv_data_t inc_serv; +} inc_serv_t; + +// GATT Request structures + +// add new attributes to service request structure +typedef struct rsi_ble_req_add_att_s { + /** service handler */ + void *serv_handler; + /** Attribute handle */ + uint16_t handle; + /** If this variable is 1, Host has to maintain attributes and records in the application. \n + If 0, Stack will maintain the attributes and records */ + uint16_t config_bitmap; + /** Attribute type UUID */ + uuid_t att_uuid; + /** Attribute property */ + uint8_t property; + /** Attribute data length */ + uint16_t data_len; + /** Attribute data. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_req_add_att_t; + +// GATT Response structures + +//Presentation Format descriptor structure +// actual value = char value * 10 ^ exponent; +typedef struct rsi_ble_presentation_format { + /**Format of the data*/ + uint8_t format; + /**Exponent of the data*/ + uint8_t exponent; + /**uints of the data*/ + uint16_t unit; + /**name space of the data*/ + uint8_t name_space; + /**Description for data*/ + uint16_t description; +} rsi_ble_pesentation_format_t; + +//RSI_BLE_EVENT_GATT_ERROR_RESP, event_id: 0x1500 +typedef struct rsi_ble_event_error_resp_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint8_t handle[2]; + /**Error indicates the type of Gatt Error*/ + uint8_t error[2]; +} rsi_ble_event_error_resp_t; + +//RSI_BLE_EVENT_GATT_CHAR_DESC - event_ix = 1501 +typedef struct rsi_ble_event_gatt_desc_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**number of descriptors found*/ + uint8_t num_of_att; + uint8_t reserved; + /**Attribute descriptors list. The maximum value is 5*/ + att_desc_t att_desc[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_event_gatt_desc_t; + +//RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_LIST, event_id: 0x1509 +typedef struct rsi_ble_event_profiles_list_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**number of profiles found*/ + uint8_t number_of_profiles; + uint8_t reserved; + /**list of found profiles. The maximum value is 5*/ + profile_descriptors_t profile_desc[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_event_profiles_list_t; +//RSI_BLE_EVENT_GATT_PRIMARY_SERVICE_BY_UUID, event_id = 0x1502 +typedef struct rsi_ble_event_profile_by_uuid_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**profile start handle*/ + uint8_t start_handle[2]; + /**profile end handle*/ + uint8_t end_handle[2]; +} rsi_ble_event_profile_by_uuid_t; + +//RSI_BLE_EVENT_GATT_READ_CHAR_SERVS, event_id = 0x1503 +typedef struct rsi_ble_event_read_by_type1_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**number of characteristic services found*/ + uint8_t num_of_services; + uint8_t reserved; + /**It contains the characteristic service list. The maximum value is 5*/ + char_serv_t char_services[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_event_read_by_type1_t; + +//RSI_BLE_EVENT_GATT_READ_INC_SERVS, event_id = 0x1504 +typedef struct rsi_ble_event_read_by_type2_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**number of characteristic services found*/ + uint8_t num_of_services; + uint8_t reserved; + /**list of included services. The maximum value is 5*/ + inc_serv_t services[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_event_read_by_type2_t; + +//RSI_BLE_EVENT_GATT_READ_VAL_BY_UUID, event_id = 0x1505 +typedef struct rsi_ble_event_read_by_type3_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint8_t handle[2]; + /**length of attribute value*/ + uint16_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_event_read_by_type3_t; + +//RSI_BLE_EVENT_GATT_READ_RESP , evet_id = 0x1506,0x1507,0x1508 +typedef struct rsi_ble_event_att_value_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**length of attribute value*/ + uint16_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_event_att_value_t; + +//RSI_BLE_EVENT_GATT_WRITE_RESP, event_id: 0x150A,0x150C +typedef struct rsi_ble_set_att_resp_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_ble_set_att_resp_t; + +//RSI_BLE_EVENT_GATT_PREPARE_WRITE_RESP, event_id: 0x150B +typedef struct rsi_ble_prepare_write_resp_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint8_t handle[2]; + /**attribute value offset*/ + uint8_t offset[2]; + /**length of attribute value*/ + uint16_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_prepare_write_resp_t; + +// GATT Profiles list response structure +typedef struct rsi_ble_resp_profiles_list_s { + /** Number of profiles found */ + uint8_t number_of_profiles; + /** Reserved */ + uint8_t reserved[3]; + /** List of found profiles \n + The maximum value is 5 */ + profile_descriptors_t profile_desc[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_resp_profiles_list_t; + +typedef struct rsi_ble_resp_query_profile_descriptor_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**List of found profiles \n + The maximum value is 5 */ + profile_descriptors_t profile_desc[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_resp_query_profile_descriptor_t; + +// GATT characteristic query service response structure +typedef struct rsi_ble_resp_char_serv_s { + /** The number of profiles found */ + uint8_t num_of_services; + /** Reserved */ + uint8_t reserved[3]; + /** Characteristic service array. \n + The maximum value is 5. */ + char_serv_t char_services[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_resp_char_services_t; + +// GATT include service response structure +typedef struct rsi_ble_resp_inc_serv { + /** Number of profiles found */ + uint8_t num_of_services; + /** Reserved */ + uint8_t reserved[3]; + /** Include service list. \n + The maximum value is 5. */ + inc_serv_t services[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_resp_inc_services_t; + +// GATT attribute value response structure +typedef struct rsi_ble_resp_att_value_s { + /** Length of attribute value */ + uint8_t len; + /** Attribute values list. \n + Each attribute value is maximum of size 240, please refer RSI_DEV_ATT_LEN Macro */ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_resp_att_value_t; + +// GATT attribute descriptors response structure +typedef struct rsi_ble_resp_att_descs_s { + /** Number of descriptors found */ + uint8_t num_of_att; + /** Reserved */ + uint8_t reserved[3]; + /** Attribute descriptors list. \n + The maximum value is 5. */ + att_desc_t att_desc[RSI_BLE_MAX_RESP_LIST]; +} rsi_ble_resp_att_descs_t; + +// add new service response structure +typedef struct rsi_ble_resp_add_serv_s { + /** Contains the address of the service record stored in the Silicon Labs stack. */ + void *serv_handler; + /** The handle from where the service starts. */ + uint16_t start_handle; +} rsi_ble_resp_add_serv_t; + +// read local attribute value response structure +typedef struct rsi_ble_resp_local_att_value_s { + /** Attribute handle */ + uint16_t handle; + /** Attribute value length */ + uint16_t data_len; + /** Attribute value (data). The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro */ + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_resp_local_att_value_t; + +// GATT Event structures + +// GATT Write event structure +typedef struct rsi_ble_event_write_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved; +#define RSI_BLE_WRITE_CMD_EVENT 0x01 +#define RSI_BLE_WRITE_REQUEST_EVENT 0x02 +#define RSI_BLE_NOTIFICATION_EVENT 0x03 +#define RSI_BLE_INDICATION_EVENT 0x04 + /**Type of the event received from the remote device \n + RSI_BLE_WRITE_CMD_EVENT 0x01 \n + RSI_BLE_WRITE_REQUEST_EVENT 0x02 \n + RSI_BLE_NOTIFICATION_EVENT 0x03 \n + RSI_BLE_INDICATION_EVENT 0x04 */ + uint8_t pkt_type; + /**attribute handle*/ + uint8_t handle[2]; + /**length of attribute value*/ + uint8_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_event_write_t; + +// GATT prepare Write event structure +typedef struct rsi_ble_event_prepare_write_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint8_t handle[2]; + /**attribute value offset*/ + uint8_t offset[2]; + /**length of attribute value*/ + uint16_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_event_prepare_write_t; + +// GATT execuite Write event structure +typedef struct rsi_ble_execute_write_s { + //uint8_t[6], remote device address. + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + //uint8_t, execute write flag. + uint8_t exeflag; +} rsi_ble_execute_write_t; + +// GATT execuite Write event structure +typedef struct rsi_ble_read_req_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint16_t handle; + /**0 � Read request \n + 1 � Read Blob request*/ + uint8_t type; + uint8_t reserved; + /**offset of attribute value to be read*/ + uint16_t offset; +} rsi_ble_read_req_t; + +// GATT execuite Write event structure +typedef struct rsi_ble_event_mtu_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**MTU size*/ + uint16_t mtu_size; +} rsi_ble_event_mtu_t; + +#define PEER_DEVICE_INITATED_MTU_EXCHANGE 0x1 +#define LOCAL_DEVICE_INITATED_MTU_EXCHANGE 0x2 +//MTU Exchange Information event structure +typedef struct rsi_ble_event_mtu_exchange_information_s { + /**uint8_t[6], remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**uint8_t[2], Remote MTU Size*/ + uint16_t remote_mtu_size; + /**uint8_t[2], Local MTU Size*/ + uint16_t local_mtu_size; + /**uint8_t Initiated role, who initiated mtu exchange \n + PEER_DEVICE_INITATED_MTU_EXCHANGE 0x01 \n + LOCAL_DEVICE_INITATED_MTU_EXCHANGE 0x02 */ + uint8_t initiated_role; +} rsi_ble_event_mtu_exchange_information_t; +// GATT Notification event structure +typedef struct rsi_ble_event_notify_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint8_t handle[2]; + /**length of attribute value*/ + uint8_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_event_notify_t; + +// GATT Indication event structure +typedef struct rsi_ble_event_indication_s { + /**remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**attribute handle*/ + uint8_t handle[2]; + /**length of attribute value*/ + uint8_t length; + /**This contains the attribute value. The maximum value is 240, please refer RSI_DEV_ATT_LEN Macro*/ + uint8_t att_value[RSI_DEV_ATT_LEN]; +} rsi_ble_event_indication_t; + +typedef struct rsi_ble_event_directedadv_report_s { + /**Event type \n + 0x01 Connectable directed advertising (ADV_DIRECT_IND) */ + uint16_t event_type; + /**Address type of remote device*/ + uint8_t dev_addr_type; + /**Address of the remote device*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /**Directed address type*/ + uint8_t directed_addr_type; + /**Directed device address*/ + uint8_t directed_dev_addr[RSI_DEV_ADDR_LEN]; + /**rssi value*/ + int8_t rssi; +} rsi_ble_event_directedadv_report_t; + +typedef struct rsi_ble_event_cbfc_conn_req_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t psm; + uint16_t lcid; +} rsi_ble_event_cbfc_conn_req_t; + +typedef struct rsi_ble_event_cbfc_conn_complete_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t psm; + uint16_t mtu; + uint16_t mps; + uint16_t lcid; +} rsi_ble_event_cbfc_conn_complete_t; + +typedef struct rsi_ble_event_cbfc_rx_data_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t lcid; + uint16_t len; + uint8_t data[RSI_DEV_ATT_LEN]; +} rsi_ble_event_cbfc_rx_data_t; + +typedef struct rsi_ble_event_cbfc_disconn_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t lcid; +} rsi_ble_event_cbfc_disconn_t; + +// SMP pairing capabilities cmd_ix = 0x00FE +typedef struct rsi_ble_set_smp_pairing_capabilty_data { + + /**Device input output capability \n + 0x00 - Display Only \n + 0x01 - Display Yes/No \n + 0x02 - Keyboard Only \n + 0x03 - No Input No Output + 0x04 - Keyboard Dispaly*/ + uint8_t io_capability; + /** oob_data_flag \n + 0 - disable \n 1 - enable */ + uint8_t oob_data_flag; + /** Authentication Request contains bonding type \n + MITM Request - BIT(2) \n + Secure Connections - BIT(3) \n + Keypress - BIT(4) \n + CT2 - BIT(5) */ + uint8_t auth_req; + /** Supported Encryption key size 7 to 16 bytes */ + uint8_t enc_key_size; + /** Initiator generates/requires the no .of keys after successful paring \n + BIT(0) - EncKey: Initiator shall distribute LTK followed by EDIV and Rand \n + BIT(1) - IdKey : Initiator shall distribute IRK followed by its address \n + BIT(2) - Sign : Initiator shall distribute CSRK \n + BIT(3) - BIT(7): Reserved for future use */ + uint8_t ini_key_distribution; + /** Responder generates/requires the no .of keys after successful paring \n + BIT(0) - EncKey: Responder shall distribute LTK followed by EDIV and Rand \n + BIT(1) - IdKey : Responder shall distribute IRK followed by its address \n + BIT(2) - Sign : Responder shall distribute CSRK \n + BIT(3) - BIT(7): Reserved for future use */ + uint8_t rsp_key_distribution; + +} rsi_ble_set_smp_pairing_capabilty_data_t; +//LE read phy request command reasponse structure, cmd_ix - 0x00B0 +typedef struct rsi_ble_resp_read_phy_s { + /** Remote device Bluetooth Address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + /** TX PHY Rate \n + 0x01 The transmitter PHY for the connection is LE 1M \n + 0x02 The transmitter PHY for the connection is LE 2M \n + 0x03 The transmitter PHY for the connection is LE Coded \n + All other values Reserved for future use*/ + uint8_t tx_phy; + /** RX PHY Rate \n + 0x01 The receiver PHY for the connection is LE 1M \n + 0x02 The receiver PHY for the connection is LE 2M \n + 0x03 The receiver PHY for the connection is LE Coded \n + All other values Reserved for future use*/ + uint8_t rx_phy; +} rsi_ble_resp_read_phy_t; + +//LE read max data length command reasponse structure, cmd_ix - 0x00B3 +typedef struct rsi_ble_resp_read_max_data_length_s { + /** maxtxoctets \n + Preferred maximum number of payload octets that the local Controller should + include in a single Link Layer packet on this connection. */ + uint16_t maxtxoctets; + /** maxtxtime \n + Preferred maximum number of microseconds that the local Controller + should use to transmit a single Link Layer packet on this connection */ + uint16_t maxtxtime; + /** maxrxoctets \n + Maximum number of payload octets that the local Controller supports + for reception of a single Link Layer packet on a data connection */ + uint16_t maxrxoctets; + /** maxrxtime \n + Maximum time, in microseconds, that the local Controller supports for + reception of a single Link Layer packet on a data connection. */ + uint16_t maxrxtime; +} rsi_ble_read_max_data_length_t; + +//LE Per Transmit mode, cmd_ix = 0x00BE +typedef struct rsi_ble_per_transmit_s { + /** Command ID \n + Takes per BLE_TRANSMIT_CMD_ID of value 0x13*/ + uint8_t cmd_ix; + /** Enables/disables the ble per transmit mode \n + 1 PER Transmit Enable \n + 0 PER Transmit Disable */ + uint8_t transmit_enable; + /** Access address with which packets are transmitted */ + uint8_t access_addr[4]; + /** Phy rate at which packets are transmitted \n + 1 1Mbps \n + 2 2 Mbps \n + 4 125 Kbps Coded \n + 8 500 Kbps Coded */ + uint8_t phy_rate; + /** Rx channel number (0 - 39) */ + uint8_t rx_chnl_num; + /** Tx channel number (0 - 39) */ + uint8_t tx_chnl_num; + /** Initial seed to be used for whitening. It should be set to �0� in order to disable whitening. \n + In order to enable, one should give the scrambler seed value which is used on the receive side */ + uint8_t scrambler_seed; + /** LE channel type (data or advertise channel) \n + 0x00 Advertise Channel \n + 0x01 Data Channel (to be used by Default) */ + uint8_t le_chnl_type; + /** Frequency hopping type to be used \n + 0 No Hopping \n + 1 Fixed Hopping \n + 2 Random Hopping (rx_chnl_num, tx_chnl_num parameters are unused in this mode) */ + uint8_t freq_hop_en; + /** Select the antenna to be used. Refer to the datasheet for your hardware to check whether or not it contains an onboard antenna. \n + 2 ONBOARD_ANT_SEL \n + 3 EXT_ANT_SEL */ + uint8_t ant_sel; + /** pll_mode type to be used \n + 0 PLL_MODE0 (to be used by Default) \n + 1 PLL_MODE1 */ + uint8_t pll_mode; + /** Selection of RF type (internal/external) \n + 0 BT_EXTERNAL_RF \n + 1 BT_INTERNAL_RF (to be used by Default) + @note The above macros are applicable for both BT and BLE */ + uint8_t rf_type; + /** Selection of RF Chain (HP/LP) to be used \n + 0 BT_HP_CHAIN \n + 1 BT_LP_CHAIN + @note The above macros are applicable for both BT and BLE */ + uint8_t rf_chain; + /** Length of the packet to be transmitted*/ + uint8_t pkt_len[2]; + /** Type of payload data sequence \n + 0x00 PRBS9 sequence �11111111100000111101... \n + 0x01 Repeated �11110000� \n + 0x02 Repeated �10101010� \n + 0x03 PRBS15 \n + 0x04 Repeated �11111111� \n + 0x05 Repeated �00000000� \n + 0x06 Repeated '00001111' \n + 0x07 Repeated '01010101' */ + uint8_t payload_type; + /** Transmit Power \n + Transmit power value for the rf_chain parameter set to the HP chain the values for the tx power indexes are 0 - 20. \n + Transmit power value for the rf chain parameter set to LP chain and values are: \n + 0 -31 o/p power equation is -2+10log10(power_index/31) \n + 32-63 o/p power equation is \n + 6 + 10log10((power_index -32)/31) \n + TX power for the BLE LP Chain :1 to 31 (0dBm Mode), 33 to 63 ( 10dBm Mode) \n + TX power for the BLE HP chain : 64 to 79 */ + uint8_t tx_power; + /** Transmit mode to be used either Burst/Continuous \n + 0 BURST_MODE \n + 1 CONTINUOUS_MODE \n + 2 CONTINUOUS_WAVE_MODE (CW_MODE) */ + uint8_t transmit_mode; + /** This field takes the value of inter packet gap. \n + Number of slots to be skipped between two packets - Each slot will be 1250usec */ + uint8_t inter_pkt_gap; + /** This field defines the number of packets to be transmitted, default to zero for continuous transmission */ + uint8_t num_pkts[4]; +} rsi_ble_per_transmit_t; + +//LE Per Receive mode, cmd_ix = 0x00BF +typedef struct rsi_ble_per_receive_s { + /** Command ID \n + Takes per BLE_RECEIVE_CMD_ID of value 0x14*/ + uint8_t cmd_ix; + /** Enables/disables the ble per receive mode \n + 1 PER Receive Enable \n + 0 PER Receive Disable */ + uint8_t receive_enable; + /** Access address with which packets are received */ + uint8_t access_addr[4]; + /** Phy rate at which packets are received \n + 1 1Mbps \n + 2 2 Mbps \n + 4 125 Kbps Coded \n + 8 500 Kbps Coded */ + uint8_t phy_rate; + /** Rx channel number (0 - 39) */ + uint8_t rx_chnl_num; + /** Tx channel number (0 - 39) */ + uint8_t tx_chnl_num; + /** Initial seed to be used for whitening. It should be set to �0� in order to disable whitening. \n + In order to enable, one should give the scrambler seed value which is used on the transmit side */ + uint8_t scrambler_seed; + /** LE channel type (data or advertise channel) \n + 0x00 Advertise Channel \n + 0x01 Data Channel (to be used by Default) */ + uint8_t le_chnl_type; + /** Frequency hopping type to be used \n + 0 No Hopping \n + 1 Fixed Hopping \n + 2 Random Hopping (rx_chnl_num, tx_chnl_num parameters are unused in this mode) */ + uint8_t freq_hop_en; + /** Select the antenna to be used. Refer to the datasheet for your hardware to check whether or not it contains an onboard antenna. \n + 2 ONBOARD_ANT_SEL \n + 3 EXT_ANT_SEL */ + uint8_t ant_sel; + /** pll_mode type to be used \n + 0 PLL_MODE0 (to be used by Default) \n + 1 PLL_MODE1 */ + uint8_t pll_mode; + /** Selection of RF type (internal/external) \n + 0 BT_EXTERNAL_RF \n + 1 BT_INTERNAL_RF (to be used by Default) + @note The above macros are applicable for both BT and BLE */ + uint8_t rf_type; + /** Selection of RF Chain (HP/LP) to be used \n + 0 BT_HP_CHAIN \n + 1 BT_LP_CHAIN + @note The above macros are applicable for both BT and BLE */ + uint8_t rf_chain; + /** This field enables/disables the extended data length \n + 0 Extended Data length disabled \n + 1 Extended Data length enabled */ + uint8_t ext_data_len_indication; + /** This field defines the loopback to be enable or disable \n + 0 LOOP_BACK_MODE_DISABLE \n + 1 LOOP_BACK_MODE_ENABLE*/ + uint8_t loop_back_mode; + /** This field enables/disables the duty cycling \n + 0 Duty Cycling Disabled (to be used by Default) \n + 1 Duty Cycling Enabled */ + uint8_t duty_cycling_en; +} rsi_ble_per_receive_t; + +#define ADV_DATA_LEN 210 +#define DEVICE_ADDR_LEN 6 + +//! ae adv report event +typedef struct rsi_ble_ae_adv_report_s { + /** + * ----------------------------------------------------------------------------------------- + * | Bit Number | Parameter Description | + * ----------------------|------------------------------------------------------------------- + * | 0 | Connectable Advertising | + * | 1 | Scannable Advertising | + * | 2 | Direct Advertising | + * | 3 | Scan Response | + * | 4 | Legacy Advertising PDUs used | + * | 5 to 6 | Data status : \n | + * | | 0b00 = complete \n | + * | | 0b01 = Incomplete, more data to come \n | + * | | 0b10 = Incomplete, data truncated, no more to come \n| + * | | 0b11 = Reserved for future use | + */ + uint16_t event_type; + /** + uint8_t Remote Address Type, Indicates the type of the Address + 0x00 - Public Device Adrdress + 0x01 - Random Device Address + 0x02 - Public Identity Address (corresponds to Resolved Private Address) + 0x03 - Random (static) Identity Address (corresponds to Resolved Private Address) + */ + uint8_t remote_addr_type; + /** uint8[6] remote_Address : Address of the remote address Type */ + uint8_t remote_addr[DEVICE_ADDR_LEN]; + /** + uint8_t Primary Phy + 0x01 - Advertiser PHY is LE 1M + 0x03 - Advertiser PHY is LE Coded + */ + uint8_t pri_phy; + /** + uint8_t Secondary PHY + 0x00 - No packets on the secondary advertising physical channel + 0x01 - Advertiser PHY is LE 1M + 0x02 - Advertiser PHY is LE 2M + 0x03 - Advertiser PHY is LE Coded + */ + uint8_t sec_phy; + /** uint8_t Advertising_SID + * --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * | Value | Parameter Description | + * ----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * | 0x00 to 0x0F | Value of the Advertising SID subfield in the ADI field of the PDU or, \n for scan responses, in the ADI field of the original scannable advertisement | + * | 0xFF | No ADI field provided | + * + */ + uint8_t SID; + /** + uint8_t TX_Power, It shall be set based on the AUX_SYNC_IND PDU + TX_Power ranges from -127 to +20 and it's units is in dBm + */ + uint8_t tx_power; + /** + uint8_t RSSI , this parameter contains the RSSI value, excluding any constant tone Extension. + RSSI ranges from -127 to +20 and it's units is in dBm + */ + uint8_t RSSI; + /** uint16_t Periodic_Advertising_Interval , This parameter specifies the interval between the periodic advertising events */ + uint16_t per_adv_interval; + /** + uint8_t Direct Address Type ,Indicates the type of the Address + 0x00 - Public Device Adrdress + 0x01 - Random Device Address + 0x02 - Public Identity Address (corresponds to Resolved Private Address) + 0x03 - Random (static) Identity Address (corresponds to Resolved Private Address) + 0xFE - Resolves Private Address + */ + uint8_t direct_addr_type; + /** uint8[6] Direct_Address, Direct_Address of the Advertsier type */ + uint8_t direct_addr[DEVICE_ADDR_LEN]; + /** uint8_t Data _length , Length of the Data field for each device which responded , ranges from 0 to 229 */ + uint8_t data_len; + /** uint8[256] Data */ + uint8_t data[ADV_DATA_LEN]; +} rsi_ble_ae_adv_report_t; + +//! ae periodic sync estabilisment report event +typedef struct rsi_ble_per_adv_sync_estbl_s { + /** + uint8_t status , It indicates whether Periodic Advetising is Successful or not + 0 - Periodic advertising sync successful + !0 - Periodic advertising sync failed + */ + uint8_t status; + /** uint16_t Sync_Handle, It identifies the periodic Advertising train. Range : 0x0000 to 0x0EFF */ + uint16_t sync_handle; + /** uint8_t Advertising_SID, Value of the Advertising SID subfield in the ADI field of the PDU, Range : 0x00 to 0x0F */ + uint8_t adv_sid; + /** + uint8_t Advertiser_Address_Type : Indicates the type of the Address + 0x00 - Public Device Adrdress + 0x01 - Random Device Address + 0x02 - Public Identity Address (corresponds to Resolved Private Address) + 0x03 - Random (static) Identity Address (corresponds to Resolved Private Address) + */ + uint8_t advertiser_addr_type; + /** uint8[6], Advertiser_Address of the Advertsier type */ + uint8_t advertiser_addr[DEVICE_ADDR_LEN]; + /** + uint8_t Advertiser_PHY , This parameter specifies the PHY used for the periodic advertising. + 0x01 - Advertiser PHY is LE 1M + 0x02 - Advertiser PHY is LE 2M + 0x03 - Advertiser PHY is LE Coded + */ + uint8_t advertiser_phy; + /** uint16_t Periodic_Advertising_Interval , This parameter specifies the interval between the periodic advertising events */ + uint16_t per_adv_interval; + /** + uint16_t Advertiser_Clock_Accuracy, This parameter specifies the accuracy of the periodic advertiser's clock. + 0x00 - 500ppm + 0x01 - 250ppm + 0x02 - 150ppm + 0x03 - 100 ppm + 0x04 - 75 ppm + 0x05 - 50 ppm + 0x06 - 30 ppm + 0x07 - 20 ppm + */ + uint16_t advertiser_clock_accuracy; +} rsi_ble_per_adv_sync_estbl_t; + +//! ae periodic adv report event +typedef struct rsi_ble_per_adv_report_s { + /** uint16_t Sync_Handle, It identifies the periodic Advertising train. Range : 0x0000 to 0x0EFF */ + uint16_t sync_handle; + /** int8_t TX_Power, It shall be set based on the AUX_SYNC_IND PDU + TX_Power ranges from -127 to +20 and it's units is in dBm + */ + int8_t tx_power; + /** int8_t RSSI , this parameter contains the RSSI value, excluding any constant tone Extension. + RSSI ranges from -127 to +20 and it's units is in dBm + */ + int8_t RSSI; + uint8_t unused; + /** + uint8_t Data_Status, It specifies about the staus of the Data sent + 0x00 - Data Complete + 0x01 - Data Incomplete, more Data to come + */ + uint8_t data_status; + /** uint8_t Data_Length ,Length of the Data Field, Ranges from 0 to 247 */ + uint8_t data_len; + /** uint8[256] Data, Data received from a Periodic Advertisisng Packet */ + uint8_t data[ADV_DATA_LEN]; +} rsi_ble_per_adv_report_t; + +//! ae periodic sync lost report event +typedef struct rsi_ble_per_adv_sync_lost_s { + /** uint16_t Sync_Handle, It identifies the periodic Advertising train. Range : 0x0000 to 0x0EFF */ + uint16_t sync_handle; +} rsi_ble_per_adv_sync_lost_t; + +//! ae scan timeout report event +typedef struct rsi_ble_scan_timeout_s { + /** uint8_t status , Status indicates that scanning has ended because the duration has expired */ + uint8_t status; +} rsi_ble_scan_timeout_t; + +//! ae adv set terminated report event +typedef struct rsi_ble_adv_set_terminated_s { + /** uint8_t status : Status shows the status on how the Advertising ended + 0 - Advertising successfully ended with a connection being created + !0 - Advertising ended for another reason and ususally error codes would be listed + */ + uint8_t status; + /** uint8_t Advertising_Handle : Advertising_Handle in which Advertising has ended, Range : 0x00 to 0xEF */ + uint8_t adv_handle; + /** uint16_t Connection_Handle : It is the Connection Handle of the connection whose creation ended the advertising, Range : 0x00 to 0xEF */ + uint16_t conn_handle; + /** + uint8_t Num_Completed_Extended_Advertising_Events + Number of completed extended advertising events transmitted by the Controller + */ + uint8_t num_completed_ae_events; +} rsi_ble_adv_set_terminated_t; + +//! ae scan request recvd report event +typedef struct rsi_ble_scan_req_recvd_s { + /** uint8_t Advertising_Handle : Used to identify an Advertising set , Range : 0x00 to 0xEF */ + uint8_t adv_handle; + /** + uint8_t Scanner_Address_Type : Indicates the type of the Address + 0x00 - Public Device Adrdress + 0x01 - Random Device Address + 0x02 - Public Identity Address (corresponds to Resolved Private Address) + 0x03 - Random (static) Identity Address (corresponds to Resolved Private Address) + */ + uint8_t scanner_addr_type; + /** uint8[6] Scanner_Address : Address of the Advertising Type */ + uint8_t scanner_addr[DEVICE_ADDR_LEN]; +} rsi_ble_scan_req_recvd_t; + +/****************************************************** + * * Global Variables + * ******************************************************/ + +typedef struct chip_ble_buffers_stats_s { + uint8_t acl_buffer_utilization; + uint8_t cp_buffer_utilization; +} chip_ble_buffers_stats_t; + +/****************************************************** + * * GAP API's Declarations + * ******************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif +//*==============================================*/ +/** + * @fn rsi_convert_db_to_powindex + * */ +uint8_t rsi_convert_db_to_powindex(int8_t tx_power_in_dBm); + +//*==============================================*/ +/** + * @fn rsi_ble_start_advertising + * */ +int32_t rsi_ble_start_advertising(void); + +/*==============================================*/ +/** + * @fn rsi_ble_start_advertising_with_values + * */ +int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv); + +/** + * @fn rsi_ble_update_direct_address + * @brief request for update direct address + * @param[in] remote_dev_addr + * @return void + * @section description + * This function requests for update direct address + * */ +void rsi_ble_update_directed_address(uint8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_ble_encrypt + * */ +int32_t rsi_ble_encrypt(uint8_t *, uint8_t *, uint8_t *); + +/*==============================================*/ +/** + * @fn rsi_ble_stop_advertising + * */ +int32_t rsi_ble_stop_advertising(void); + +/*==============================================*/ +/** + * @fn rsi_ble_set_advertise_data + * */ +int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len); + +/*========================================================*/ +/** + * @fn rsi_ble_set_scan_response_data + * */ +int32_t rsi_ble_set_scan_response_data(uint8_t *data, uint16_t data_len); + +/*==============================================*/ +/** + * @fn rsi_ble_start_scanning + * */ +int32_t rsi_ble_start_scanning(void); + +/*==============================================*/ +/** + * @fn rsi_ble_start_scanning_with_values + * */ +int32_t rsi_ble_start_scanning_with_values(void *rsi_ble_scan_params); + +/*==============================================*/ +/** + * @fn rsi_ble_stop_scanning + * */ +int32_t rsi_ble_stop_scanning(void); + +/*==============================================*/ +/** + * @fn rsi_ble_connect + * */ +int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, int8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_ble_connect_with_params + * */ +int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, + int8_t *remote_dev_addr, + uint16_t scan_interval, + uint16_t scan_window, + uint16_t conn_interval_max, + uint16_t conn_interval_min, + uint16_t conn_latency, + uint16_t supervision_tout); + +/*==============================================*/ +/** + * @fn rsi_ble_enhance_connect_with_params + * */ +int32_t rsi_ble_enhance_connect_with_params(void *ble_enhance_conn_params); + +/*==============================================*/ +/** + * @fn rsi_ble_connect_cancel + * + * */ +int32_t rsi_ble_connect_cancel(int8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_ble_disconnect + * */ +int32_t rsi_ble_disconnect(int8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_ble_get_device_state + */ +int32_t rsi_ble_get_device_state(uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_ble_add_dev_to_resolvlist + * + */ +int32_t rsi_ble_resolvlist(uint8_t process_type, + uint8_t remote_dev_addr_type, + uint8_t *remote_dev_address, + uint8_t *peer_irk, + uint8_t *local_irk); + +/*==============================================*/ +/** + * @fn rsi_ble_get_resolving_list_size + */ +int32_t rsi_ble_get_resolving_list_size(uint8_t *resp); +/*==============================================*/ +/** + * @fn rsi_ble_set_addr_resolution_enable + */ +int32_t rsi_ble_set_addr_resolution_enable(uint8_t enable, uint16_t tout); +/*==============================================*/ +/** + * @fn rsi_ble_ltk_req_reply + */ +int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, uint8_t reply_type, uint8_t *ltk); +/*==============================================*/ +/** + * @fn rsi_ble_set_privacy_mode + */ +int32_t rsi_ble_set_privacy_mode(uint8_t remote_dev_addr_type, uint8_t *remote_dev_address, uint8_t privacy_mode); +/*==============================================*/ +/** + * @fn rsi_ble_get_max_adv_data_len + */ +int32_t rsi_ble_get_max_adv_data_len(uint8_t *resp); +/*==============================================*/ +/** + * @fn rsi_ble_get_max_no_of_supp_adv_sets + */ +int32_t rsi_ble_get_max_no_of_supp_adv_sets(uint8_t *resp); +/*==============================================*/ +/** + * @fn rsi_ble_set_ae_set_random_address + */ +int32_t rsi_ble_set_ae_set_random_address(uint8_t handle, uint8_t *rand_addr); +/*==============================================*/ +/** + * @fn rsi_ble_set_ae_data + */ +int32_t rsi_ble_set_ae_data(void *ble_ae_data); +/*==============================================*/ +/** + * @fn rsi_ble_set_ae_params + */ +int32_t rsi_ble_set_ae_params(void *ble_ae_params, int8_t *sel_tx_pwr); +/*==============================================*/ +/** + * @fn rsi_ble_start_ae_advertising + */ +int32_t rsi_ble_start_ae_advertising(void *adv_enable); +/*==============================================*/ +/** + * @fn rsi_ble_app_adv_set_clear_or_remove + */ +int32_t rsi_ble_app_adv_set_clear_or_remove(uint8_t type, uint8_t handle); +/*==============================================*/ +/** + * @fn rsi_ble_app_set_periodic_ae_params + */ +int32_t rsi_ble_app_set_periodic_ae_params(void *periodic_adv_params); +/*==============================================*/ +/** + * @fn rsi_ble_app_set_periodic_ae_enable + */ +int32_t rsi_ble_app_set_periodic_ae_enable(uint8_t enable, uint8_t handle); +/*==============================================*/ +/** + * @fn rsi_ble_ae_set_scan_params + */ +int32_t rsi_ble_ae_set_scan_params(void *ae_scan_params); +/*==============================================*/ +/** + * @fn rsi_ble_ae_set_scan_enable + */ +int32_t rsi_ble_ae_set_scan_enable(void *ae_scan_enable); +/*==============================================*/ +/** + * @fn rsi_ble_ae_set_periodic_sync + */ +int32_t rsi_ble_ae_set_periodic_sync(uint8_t type, void *periodic_sync_data); +/*==============================================*/ +/** + * @fn rsi_ble_ae_dev_to_periodic_list + */ +int32_t rsi_ble_ae_dev_to_periodic_list(void *dev_to_list); +/*==============================================*/ +/** + * @fn rsi_ble_ae_read_periodic_adv_list_size + */ +int32_t rsi_ble_ae_read_periodic_adv_list_size(uint8_t *resp); +/*==============================================*/ +/** + * @fn rsi_ble_extended_connect_with_params + */ +int32_t rsi_ble_extended_connect_with_params(void *ext_create_conn); + +/*==============================================*/ +/** + * @fn rsi_ble_read_transmit_power + */ +int32_t rsi_ble_read_transmit_power(void *resp); +/*==============================================*/ +/** + * @fn rsi_ble_read_rf_path_compensation + */ +int32_t rsi_ble_read_rf_path_compensation(void *resp); +/*==============================================*/ +/** + * @fn rsi_ble_write_rf_path_compensation + */ +int32_t rsi_ble_write_rf_path_compensation(uint16_t tx_path_value, uint16_t rx_path_value); + +/****************************************************** + * * GATT Client API's Declarations + * ******************************************************/ +/*==============================================*/ +/** + * @fn rsi_ble_get_profiles_async + */ + +int32_t rsi_ble_get_profiles_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_profiles_list_t *p_prof_list); + +/*==============================================*/ +/** + * @fn rsi_ble_get_profile_async + */ +int32_t rsi_ble_get_profile_async(uint8_t *dev_addr, uuid_t profile_uuid, profile_descriptors_t *p_profile); + +/*==============================================*/ +/** + * @fn rsi_ble_get_char_services_async + */ +int32_t rsi_ble_get_char_services_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_char_services_t *p_char_serv_list); +/*==============================================*/ +/** + * @fn rsi_ble_get_inc_services_async + */ +int32_t rsi_ble_get_inc_services_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_inc_services_t *p_inc_serv_list); +/*==============================================*/ +/** + * @fn rsi_ble_get_char_value_by_uuid_async + */ +int32_t rsi_ble_get_char_value_by_uuid_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + uuid_t char_uuid, + rsi_ble_resp_att_value_t *p_char_val); +/*==============================================*/ +/** + * @fn rsi_ble_get_att_descriptors_async + */ +int32_t rsi_ble_get_att_descriptors_async(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_att_descs_t *p_att_desc); +/*==============================================*/ +/** + * @fn rsi_ble_get_att_value_async + */ +int32_t rsi_ble_get_att_value_async(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_att_value_t *p_att_val); +/*==============================================*/ +/** + * @fn rsi_ble_get_multiple_att_values_async + */ + +int32_t rsi_ble_get_multiple_att_values_async(uint8_t *dev_addr, + uint8_t num_of_handlers, + uint16_t *handles, + rsi_ble_resp_att_value_t *p_att_vals); +/*==============================================*/ +/** + * @fn rsi_ble_get_long_att_value_async + */ + +int32_t rsi_ble_get_long_att_value_async(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + rsi_ble_resp_att_value_t *p_att_vals); + +/*==============================================*/ +/** + * @fn rsi_ble_set_att_value_async + */ +int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data); + +/*==============================================*/ +/** + * @fn rsi_ble_prepare_write_async + */ + +int32_t rsi_ble_prepare_write_async(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint8_t data_len, + uint8_t *p_data); +/*==============================================*/ +/** + * @fn rsi_ble_execute_write_async + */ + +int32_t rsi_ble_execute_write_async(uint8_t *dev_addr, uint8_t exe_flag); + +/** + * @fn rsi_ble_get_profiles + * + * + */ +int32_t rsi_ble_get_profiles(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_profiles_list_t *p_prof_list); + +/** + * @fn rsi_ble_get_profile + * + */ +int32_t rsi_ble_get_profile(uint8_t *dev_addr, uuid_t profile_uuid, profile_descriptors_t *p_profile); + +/** + * @fn rsi_ble_get_char_services + * + * + */ +int32_t rsi_ble_get_char_services(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_char_services_t *p_char_serv_list); + +/** + * @fn rsi_ble_get_inc_services + */ +int32_t rsi_ble_get_inc_services(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_inc_services_t *p_inc_serv_list); + +/** + * @fn rsi_ble_get_att_descriptors + */ +int32_t rsi_ble_get_att_descriptors(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + rsi_ble_resp_att_descs_t *p_att_desc); + +/** + * @fn rsi_ble_get_char_value_by_uuid + */ +int32_t rsi_ble_get_char_value_by_uuid(uint8_t *dev_addr, + uint16_t start_handle, + uint16_t end_handle, + uuid_t char_uuid, + rsi_ble_resp_att_value_t *p_char_val); + +/** + * @fn rsi_ble_get_att_value + */ +int32_t rsi_ble_get_att_value(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_att_value_t *p_att_val); + +/** + * @fn rsi_ble_get_multiple_att_values + */ +int32_t rsi_ble_get_multiple_att(uint8_t *dev_addr, + uint8_t num_handles, + uint16_t *handles, + rsi_ble_resp_att_value_t *p_att_vals); + +/** + * @fn rsi_ble_get_long_att_value + * + */ +int32_t rsi_ble_get_long_att_value(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + rsi_ble_resp_att_value_t *p_att_vals); + +/** + * @fn rsi_ble_set_att_value + */ +int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data); + +/** + * @fn rsi_ble_set_att_cmd + */ +int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data); + +/** + * @fn rsi_ble_req_set_long_att_value + */ +int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint8_t data_len, + uint8_t *p_data); + +/** + * @fn rsi_ble_prepare_write + */ +int32_t rsi_ble_prepare_write(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, uint8_t *p_data); + +/** + * @fn rsi_ble_execute_write + */ +int32_t rsi_ble_execute_write(uint8_t *dev_addr, uint8_t exe_flag); + +/****************************************************** + * * GATT Server API's Declarations + * ******************************************************/ +/** + * @fn rsi_ble_add_service + */ +int32_t rsi_ble_add_service(uuid_t serv_uuid, rsi_ble_resp_add_serv_t *p_resp_serv); + +/** + * @fn rsi_ble_add_attribute + */ +int32_t rsi_ble_add_attribute(rsi_ble_req_add_att_t *p_attribute); + +/** + * @fn rsi_ble_set_local_att_value + */ +int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, uint8_t *p_data); + +/** + * @fn rsi_ble_get_local_att_value + */ +int32_t rsi_ble_get_local_att_value(uint16_t handle, rsi_ble_resp_local_att_value_t *p_resp_local_att_val); + +/** + * @fn rsi_ble_set_local_irk_value + + * */ +int32_t rsi_ble_set_local_irk_value(uint8_t *local_irk); + +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_ble_tx_power + */ +int32_t rsi_ble_set_ble_tx_power(uint8_t role, uint8_t *remote_dev_address, int8_t tx_power); +/*==============================================*/ +/** + * @fn int32_t rsi_ble_set_prop_protocol_ble_bandedge_tx_power(uint8_t protocol, int8_t bandedge_tx_power) + * @brief Set the Proprietary Protocol and BLE protocol bandedge tx power + */ + +int32_t rsi_ble_set_prop_protocol_ble_bandedge_tx_power(uint8_t protocol, int8_t bandedge_tx_power); + +/** + * @fn rsi_ble_gatt_read_response + */ +int32_t rsi_ble_gatt_read_response(uint8_t *dev_addr, + uint8_t read_type, + uint16_t handle, + uint16_t offset, + uint16_t length, + uint8_t *p_data); + +/** + * @fn rsi_ble_smp_pair_request + */ +int32_t rsi_ble_smp_pair_request(uint8_t *remote_dev_address, uint8_t io_capability, uint8_t mitm_req); + +/** + * @fn rsi_ble_smp_pair_failed + */ +int32_t rsi_ble_smp_pair_failed(uint8_t *remote_dev_address, uint8_t reason); + +/** + * @fn rsi_ble_smp_pair_response + */ +int32_t rsi_ble_smp_pair_response(uint8_t *remote_dev_address, uint8_t io_capability, uint8_t mitm_req); + +/** + * @fn rsi_ble_smp_passkey + */ +int32_t rsi_ble_smp_passkey(uint8_t *remote_dev_address, uint32_t passkey); + +/*==============================================*/ +/** + * @fn rsi_ble_cbfc_connreq + */ +uint32_t rsi_ble_cbfc_connreq(uint8_t *dev_addr, uint16_t psm); + +/*==============================================*/ +/** + * @fn rsi_ble_cbfc_connresp + */ +uint32_t rsi_ble_cbfc_connresp(uint8_t *dev_addr, uint16_t lcid, uint8_t result); + +/*==============================================*/ +/** + * @fn rsi_ble_cbfc_data_tx + */ +uint32_t rsi_ble_cbfc_data_tx(uint8_t *dev_addr, uint16_t lcid, uint16_t len, uint8_t *p_data); + +/*==============================================*/ +/** + * @fn rsi_ble_cbfc_disconnect + */ +uint32_t rsi_ble_cbfc_disconnect(uint8_t *dev_addr, uint16_t lcid); + +/****************************************************** + * * BLE GAP Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-LOW-ENERGY8 +* @{ +*/ +/** + * @typedef void (*rsi_ble_on_adv_report_event_t)(rsi_ble_event_adv_report_t *rsi_ble_event_adv); + * @brief The callback function will be called if advertise report event is received + * @param[out] rsi_ble_event_adv contains the advertise report information. Please refer rsi_ble_event_adv_report_s for more info. + * @return void + * @section description + * This callback function will be called if the advertise event report is received from the module \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_adv_report_event_t)(rsi_ble_event_adv_report_t *rsi_ble_event_adv); + +/** + * @typedef void (*rsi_ble_on_connect_t)(rsi_ble_event_conn_status_t *rsi_ble_event_conn); + * @brief The callback function will be called if BLE connection status is received + * @param[out] rsi_ble_event_conn contains the BLE connection status. Please refer rsi_ble_event_conn_status_s for more info. + * @return void + * @section description + * This callback function will be called if the BLE connection status is received from the module. For BLE 4.1 and lower version this callback will be called \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_connect_t)(rsi_ble_event_conn_status_t *rsi_ble_event_conn); + +/** + * @typedef void (*rsi_ble_on_enhance_connect_t)(rsi_ble_event_enhance_conn_status_t *rsi_ble_event_enhance_conn); + * @brief The callback function will be called if BLE connection status is received + * @param[out] rsi_ble_event_conn contains the BLE connection status. Please refer rsi_ble_event_enhance_conn_status_s for more info. + * @return void + * @section description + * This callback function will be called if the BLE connection status is received from the module. For BLE 4.2 and above version this callback will be called \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_enhance_connect_t)(rsi_ble_event_enhance_conn_status_t *rsi_ble_event_enhance_conn); + +/** + * @typedef void (*rsi_ble_on_disconnect_t)(rsi_ble_event_disconnect_t *rsi_ble_event_disconnect, uint16_t reason); + * @brief The callback function will be called if disconnect event is received + * @param[out] rsi_ble_event_disconnect contains the disconnect status. Please refer rsi_ble_event_disconnect_s for more info. + * @param[out] reason contains reason for failure. \n + * @note Few reason for failure are given below \n + * 0x4E13 Remote user terminated connection \n + * 0x4E14 Remote device terminated connection due to low resources \n + * 0x4E15 Remote device terminated connection due to power off \n + * 0x4E3D Connection terminated due to MIC failure \n + * 0x4E3E Connection Failed to be Established \n + * 0x4E60 Invalid Handle Range + * @return void + * @section description + * This callback function will be called if the disconnect status event is received from the module \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_disconnect_t)(rsi_ble_event_disconnect_t *rsi_ble_event_disconnect, uint16_t reason); + +/** + * @typedef void (*rsi_ble_on_le_ping_payload_timeout_t)(rsi_ble_event_le_ping_time_expired_t *rsi_ble_event_timeout_expired); + * @brief The callback function will be called if le ping payload timeout expired event is received + * @param[out] rsi_ble_event_disconnect contains the disconnect status. Please refer rsi_ble_event_le_ping_time_expired_s for more info. + * @return void + * @section description + * This callback function will be called if the le ping time expired event is received from the module \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_le_ping_payload_timeout_t)( + rsi_ble_event_le_ping_time_expired_t *rsi_ble_event_timeout_expired); + +/** + * @typedef void (*rsi_ble_on_le_ltk_req_event_t)(rsi_bt_event_le_ltk_request_t *rsi_ble_event_le_ltk_request); + * @brief The callback function will be called if le ltk request event is received + * @param[out] rsi_ble_event_le_ltk_request contains the ltk request info. Please refer rsi_bt_event_le_ltk_request_s for more info + * @return void + * @section description + * This callback function will be called if le ltk request event is received from the module \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_le_ltk_req_event_t)(rsi_bt_event_le_ltk_request_t *rsi_ble_event_le_ltk_request); + +/** + * @typedef void (*rsi_ble_on_le_security_keys_t)(rsi_bt_event_le_security_keys_t *rsi_ble_event_le_security_keys); + * @brief The callback function will be called if le security keys event is received + * @param[out] rsi_bt_event_le_security_keys_t contains security keys. Please refer rsi_bt_event_le_security_keys_s for more info + * @return void + * @section description + * This callback function will be called if le security keys event is received from the module \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_le_security_keys_t)(rsi_bt_event_le_security_keys_t *rsi_ble_event_le_security_keys); +/** @} */ +/****************************************************** + * * BLE SMP EVENT Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-LOW-ENERGY8 +* @{ +*/ +/** + * @typedef void (*rsi_ble_on_smp_request_t)(rsi_bt_event_smp_req_t *remote_dev_address); + * @brief The callback function will be called if smp request is received in Master mode + * @param[out] resp_status contains the response status (Success or Error code) + * @param[out] remote_dev_address contains the smp requested device address. Please refer rsi_bt_event_smp_req_s for more info. + * @return void + * @section description + * This callback function will be called if the smp request is received from the remote device \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_smp_request_t)(rsi_bt_event_smp_req_t *remote_dev_address); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_smp_response_t)(rsi_bt_event_smp_resp_t *remote_dev_address); + * @brief The callback function will be called if smp request is received in slave mode + * @param[out] remote_dev_address contains the smp resp information. please refer rsi_bt_event_smp_resp_s for more info + * @return void + * @section description + * This callback function will be called if the smp request is received from the remote device \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_smp_response_t)(rsi_bt_event_smp_resp_t *remote_dev_address); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_smp_passkey_t)(rsi_bt_event_smp_passkey_t *remote_dev_address); + * @brief The callback function will be called if smp passkey event is received from module + * @param[out] resp_status, contains the response status (Success or Error code) + * @param[out] remote_dev_address contains the remote device address. please refer rsi_bt_event_smp_passkey_s for more info + * @return void + * @section description + * This callback function will be called if the smp passkey is received from the module \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_smp_passkey_t)(rsi_bt_event_smp_passkey_t *remote_dev_address); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_smp_passkey_display_t)(rsi_bt_event_smp_passkey_display_t *smp_passkey_display); + * @brief The callback function will be called if smp passkey event is received from module + * @param[out] resp_status contains the response status (Success or Error code) + * @param[out] smp_passkey_display contains the smp passkey display information. Please refer rsi_bt_event_smp_passkey_display_s for more info. + * @return void + * @section description + * This callback function will be called if the smp passkey display is received from the module \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_smp_passkey_display_t)(rsi_bt_event_smp_passkey_display_t *smp_passkey_display); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_smp_failed_t)(uint16_t resp_status, rsi_bt_event_smp_failed_t *remote_dev_address); + * @brief The callback function will be called if smp failed event is received from module + * @param[out] resp_status contains the response status (Success or Error code) \n + * @note Error codes for SMP FAILED are given below \n + * 0x4B01 SMP Passkey entry failed \n + * 0x4B02 SMP OOB not available \n + * 0x4B03 SMP Authentication Requirements \n + * 0x4B04 SMP confirm value failed \n + * 0x4B05 SMP Pairing not supported \n + * 0x4B06 SMP Encryption key size insufficient \n + * 0x4B07 SMP command not supported \n + * 0x4B08 SMP Unspecified Reason \n + * 0x4B09 SMP repeated attempts \n + * 0x4B0C SMP Numeric Comparison Failed \n + * 0x4B0B DHKEY Check Failed + * @param[out] remote_dev_address contains the remote device address. Please refer rsi_bt_event_smp_failed_s for more info. + * @return void + * @section description + * This callback function will be called if the smp process is failed with remote device \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_smp_failed_t)(uint16_t resp_status, rsi_bt_event_smp_failed_t *remote_dev_address); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_sc_method_t)(rsi_bt_event_sc_method_t *scmethod); + * @brief The callback function will be called if security method event is received from module + * @param[out] scmethod contains Security Method 1 means Just works or 2 means Passkey. Please refer rsi_bt_event_sc_method_s for more info. + * @return void + * @section description + * This callback function will be called if the SC method is done with remote device \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_sc_method_t)(rsi_bt_event_sc_method_t *scmethod); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_encrypt_started_t)(uint16_t resp_status, rsi_bt_event_encryption_enabled_t *enc_enabled); + * @brief The callback function will be called if encrypted event is received from module + * @param[out] resp_status contains the response status (Success or Error code) + * @param[out] enc_enabled contains encryption information. Please refer rsi_bt_event_encryption_enabled_s for more info. + * @return void + * @section description + * This callback function will be called if the encryption process is started with remote device \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_encrypt_started_t)(uint16_t resp_status, rsi_bt_event_encryption_enabled_t *enc_enabled); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_sc_passkey_t)(rsi_bt_event_sc_passkey_t *sc_passkey); + * @brief The callback function will be called if BLE Secure connection passkey event received from module + * @param[out] sc_passkey contains LE SC Passkey information. Please refer rsi_bt_event_encryption_enabled_s for more info. + * @return void + * @section description + * This callback function will be called if the BLE Secure connection passkey event received \n + * This callback has to be registered using rsi_ble_smp_register_callbacks API + */ +typedef void (*rsi_ble_on_sc_passkey_t)(rsi_bt_event_sc_passkey_t *sc_passkey); + +/** + * @typedef void (*rsi_ble_on_phy_update_complete_t)(rsi_ble_event_phy_update_t *rsi_ble_event_phy_update_complete); + * @brief The callback function will be called when phy update complete event is received + * @param[out] rsi_ble_event_phy_update_complete contains the controller support phy information. Please refer rsi_ble_event_phy_update_s for more info. + * @return void + * @section description + * This callback function will be called when phy update complete event is received \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_phy_update_complete_t)(rsi_ble_event_phy_update_t *rsi_ble_event_phy_update_complete); + +/** + * @typedef void (*rsi_ble_on_conn_update_complete_t)(rsi_ble_event_conn_update_t *rsi_ble_event_conn_update_complete, + uint16_t resp_status); + * @brief The callback function will be called when conn update complete event is received + * @param[out] rsi_ble_event_conn_update_complete contains the controller support conn information. Please refer rsi_ble_event_conn_update_s for more info. + * @param[out] resp_status contains the response status (Success or Error code) + * @return void + * @section description + * This callback function will be called when conn update complete event is received \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_conn_update_complete_t)(rsi_ble_event_conn_update_t *rsi_ble_event_conn_update_complete, + uint16_t resp_status); +/** + * @typedef void (*rsi_ble_on_remote_conn_params_request_t)( + * rsi_ble_event_remote_conn_param_req_t *rsi_ble_event_remote_conn_param, + * uint16_t resp_status); + * @brief The callback function will be called if remote conn params request is received. + * @param[out] resp_status contains the response status (Success or Error code) + * @param[out] rsi_ble_event_remote_features contains the remote device supported features. Please refer rsi_ble_event_remote_features_s for more info. + * @return void + * @section description + * This callback function will be called when remote conn params request is received \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_remote_conn_params_request_t)( + rsi_ble_event_remote_conn_param_req_t *rsi_ble_event_remote_conn_param, + uint16_t resp_status); + +/** + * @typedef void (*rsi_ble_on_remote_features_t)(rsi_ble_event_remote_features_t *rsi_ble_event_remote_features); + * @brief Callback function to peer device supported features. + * @param[out] rsi_ble_event_remote_features contains the remote device supported features. Please refer rsi_ble_event_remote_features_s for more info. + * @return void + * @section description + * This callback function will be called when conn update complete event is received \n + * This callback has to be registered using rsi_ble_gap_extended_register_callbacks API + */ +typedef void (*rsi_ble_on_remote_features_t)(rsi_ble_event_remote_features_t *rsi_ble_event_remote_features); + +/** + * @typedef void (*rsi_ble_on_le_more_data_req_t)(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_more_data_evt); + * @brief Callback function to le more data request + * @param[out] rsi_ble_more_data_evt contains the LE Device Buffer Indication information. Please refer rsi_ble_event_le_dev_buf_ind_s for more info. + * @return void + * @section description + * This callback function will be called when le more data event is received \n + * This callback has to be registered using rsi_ble_gap_extended_register_callbacks API + */ +typedef void (*rsi_ble_on_le_more_data_req_t)(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_more_data_evt); + +/*==============================================*/ +/** + * @typedef void (*rsi_ble_on_data_length_update_t)(rsi_ble_event_data_length_update_t *remote_dev_address); + * @brief This event is raised when data length is update in controller + * @param[out] remote_dev_address contains the controller support tx and rx length information. Please refer rsi_ble_event_data_length_update_s for more info. + * @return void + * @section description + * This callback function will be called when data length update complete event is received \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_data_length_update_t)(rsi_ble_event_data_length_update_t *remote_dev_address); + +/** + * @typedef void (*rsi_ble_on_directed_adv_report_event_t)(rsi_ble_event_directedadv_report_t *rsi_ble_event_directed); + * @brief The callback function will be called if directed advertise report event is received + * @param[in] rsi_ble_event_directed, contains the advertise report information + * @return void + * @section description + * This callback function will be called if the advertise event report is received from the module \n + * This callback has to be registered using rsi_ble_gap_register_callbacks API + */ +typedef void (*rsi_ble_on_directed_adv_report_event_t)(rsi_ble_event_directedadv_report_t *rsi_ble_event_directed); +/** @} */ +/*==============================================*/ +/** + * @fn rsi_ble_gap_register_callbacks + */ +void rsi_ble_gap_register_callbacks(rsi_ble_on_adv_report_event_t ble_on_adv_report_event, + rsi_ble_on_connect_t ble_on_conn_status_event, + rsi_ble_on_disconnect_t ble_on_disconnect_event, + rsi_ble_on_le_ping_payload_timeout_t timeout_expired_event, + rsi_ble_on_phy_update_complete_t ble_on_phy_update_complete_event, + rsi_ble_on_data_length_update_t ble_on_data_length_update_complete_event, + rsi_ble_on_enhance_connect_t ble_on_enhance_conn_status_event, + rsi_ble_on_directed_adv_report_event_t ble_on_directed_adv_report_event, + rsi_ble_on_conn_update_complete_t ble_on_conn_update_complete_event, + rsi_ble_on_remote_conn_params_request_t ble_on_remote_conn_params_request_event); + +/*==============================================*/ +/** + * @fn rsi_ble_adv_ext_events_register_callbacks + */ +int32_t rsi_ble_adv_ext_events_register_callbacks(uint16_t callback_id, + void (*callback_handler_ptr)(uint16_t status, uint8_t *buffer)); + +/*==============================================*/ +/** + * @fn rsi_ble_smp_register_callbacks + */ +void rsi_ble_smp_register_callbacks(rsi_ble_on_smp_request_t ble_on_smp_request_event, + rsi_ble_on_smp_response_t ble_on_smp_response_event, + rsi_ble_on_smp_passkey_t ble_on_smp_passkey_event, + rsi_ble_on_smp_failed_t ble_on_smp_fail_event, + rsi_ble_on_encrypt_started_t rsi_ble_on_encrypt_started_event, + rsi_ble_on_smp_passkey_display_t ble_on_smp_passkey_display_event, + rsi_ble_on_sc_passkey_t ble_sc_passkey_event, + rsi_ble_on_le_ltk_req_event_t ble_on_le_ltk_req_event, + rsi_ble_on_le_security_keys_t ble_on_le_security_keys_event, + rsi_ble_on_smp_response_t ble_on_cli_smp_response_event, + rsi_ble_on_sc_method_t ble_on_sc_method_event); + +/****************************************************** + * * BLE GATT Response Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-LOW-ENERGY8 +* @{ +*/ +/** + * @typedef void (*rsi_ble_on_gatt_error_resp_t)(uint16_t event_status, rsi_ble_event_error_resp_t *rsi_ble_gatt_error); + * @brief The callback function will be called if gatt error event is received + * @param[out] event_status contains the error response \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A06 - Request not supported \n + * 0x4A0A - Attribute not found \n + * 0x4A05 - Insufficient authentication \n + * 0x4A08 - Insufficient authorization \n + * 0x4A0C - Insufficient encryption key size \n + * 0x4A0F - Insufficient encryption \n + * 0x4A02 - Read not permitted \n + * 0x4A03 - Write not permitted \n + * 0x4A07 - Invalid offset \n + * 0x4A0B - Attribute not Long \n + * @param[out] rsi_ble_gatt_error contains the gatt error information. Please refer rsi_ble_event_error_resp_s for more info + * @return void + * @section description + * This callback function will be called if the gatt error event is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_gatt_error_resp_t)(uint16_t event_status, rsi_ble_event_error_resp_t *rsi_ble_gatt_error); +/** + * @typedef void (*rsi_ble_on_gatt_desc_val_event_t)(uint16_t event_status, + rsi_ble_event_gatt_desc_t *rsi_ble_gatt_desc_val); + * @brief The callback function will be called if attribute descriptors event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_gatt_desc_val contains the profiles list event information. Please refer rsi_ble_event_gatt_desc_s for more info + * @return void + * @section description + * This callback function will be called if the attribute descriptors event is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_gatt_desc_val_event_t)(uint16_t event_status, + rsi_ble_event_gatt_desc_t *rsi_ble_gatt_desc_val); + +/** + * @typedef void (*rsi_ble_on_event_profiles_list_t)(uint16_t event_status, + rsi_ble_event_profiles_list_t *rsi_ble_event_profiles); + * @brief The callback function will be called if profiles list event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_profiles contains the profiles list event information. Please refer rsi_ble_event_profiles_list_s for more info + * @return void + * @section description + * This callback function will be called if the profiles list response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_profiles_list_t)(uint16_t event_status, + rsi_ble_event_profiles_list_t *rsi_ble_event_profiles); + +/** + * @typedef void (*rsi_ble_on_event_profile_by_uuid_t)(uint16_t event_status, + rsi_ble_event_profile_by_uuid_t *rsi_ble_event_profile); + * @brief The callback function will be called if profile event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_profile contains the profile response information. Please refer rsi_ble_event_profile_by_uuid_s for more info. + * @return void + * @section description + * This callback function will be called if the profile response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_profile_by_uuid_t)(uint16_t event_status, + rsi_ble_event_profile_by_uuid_t *rsi_ble_event_profile); +/** + * @typedef void (*rsi_ble_on_event_read_by_char_services_t)(uint16_t event_status, + rsi_ble_event_read_by_type1_t *rsi_ble_event_read_type1); + * @brief The callback function will be called if characteristic services list event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_read_type1 contains the char services event information. Please refer rsi_ble_event_read_by_type1_s for more info. + * @return void + * @section description + * This callback function will be called if the characteristic services list response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_read_by_char_services_t)(uint16_t event_status, + rsi_ble_event_read_by_type1_t *rsi_ble_event_read_type1); + +/** + * @typedef void (*rsi_ble_on_event_read_by_inc_services_t)(uint16_t event_status, + rsi_ble_event_read_by_type2_t *rsi_ble_event_read_type2); + * @brief The callback function will be called if include services list event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_read_type2 contains the inc services information. Please refer rsi_ble_event_read_by_type2_s for more info. + * @return void + * @section description + * This callback function will be called if the include services list response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_read_by_inc_services_t)(uint16_t event_status, + rsi_ble_event_read_by_type2_t *rsi_ble_event_read_type2); +/** + * @typedef void (*rsi_ble_on_event_read_att_value_t)(uint16_t event_status, + rsi_ble_event_read_by_type3_t *rsi_ble_event_read_type3); + * @brief The callback function will be called if attribute value event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_read_type3 contains the char services event information. Please refer rsi_ble_event_read_by_type3_s for more info. + * @return void + * @section description + * This callback function will be called if the attribute value response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_read_att_value_t)(uint16_t event_status, + rsi_ble_event_read_by_type3_t *rsi_ble_event_read_type3); + +/** + * @typedef void (*rsi_ble_on_event_read_resp_t)(uint16_t event_status, rsi_ble_event_att_value_t *rsi_ble_event_att_val); + * @brief The callback function will be called if attribute value event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_att_val contains the profile response information. Please refer rsi_ble_event_att_value_s for more info. + * @return void + * @section description + * This callback function will be called if the attribute value is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_read_resp_t)(uint16_t event_status, rsi_ble_event_att_value_t *rsi_ble_event_att_val); + +/** + * @typedef void (*rsi_ble_on_event_write_resp_t)(uint16_t event_status, rsi_ble_set_att_resp_t *rsi_ble_event_set_att_rsp); + * @brief The callback function will be called if gatt write event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_set_att_rsp contains the profile response information. Please refer rsi_ble_set_att_resp_t for more info. + * @return void + * @section description + * This callback function will be called if the gatt write response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_write_resp_t)(uint16_t event_status, rsi_ble_set_att_resp_t *rsi_ble_event_set_att_rsp); +/** + * @typedef void (*rsi_ble_on_event_indicate_confirmation_t)(uint16_t event_status, + rsi_ble_set_att_resp_t *rsi_ble_event_set_att_rsp); + * @brief The callback function will be called if indication confirmation event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_set_att_rsp contains the profile response information. Please refer rsi_ble_set_att_resp_s for more info. + * @return void + * @section description + * This callback function will be called if the indication confirmation response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_indicate_confirmation_t)(uint16_t event_status, + rsi_ble_set_att_resp_t *rsi_ble_event_set_att_rsp); +/** + * @typedef void (*rsi_ble_on_event_prepare_write_resp_t)(uint16_t event_status, + rsi_ble_prepare_write_resp_t *rsi_ble_event_prepare_write); + * @brief The callback function will be called if GATT prepare event is received + * @param[out] event_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @param[out] rsi_ble_event_prepare_write contains the char services event information. Please refer rsi_ble_prepare_write_resp_s for more info. + * @return void + * @section description + * This callback function will be called if the GATT prepare response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_event_prepare_write_resp_t)(uint16_t event_status, + rsi_ble_prepare_write_resp_t *rsi_ble_event_prepare_write); + +/** + * @typedef void (*rsi_ble_on_profiles_list_resp_t)(uint16_t resp_status, + rsi_ble_resp_profiles_list_t *rsi_ble_resp_profiles); + * @brief The callback function will be called if profiles list response is received + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A0A - Attribute not found \n + * @param[out] rsi_ble_resp_profiles contains the profiles list response information. Please refer rsi_ble_resp_profiles_list_s for more info. + * @return void + * @section description + * This callback function will be called if the profiles list response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_profiles_list_resp_t)(uint16_t resp_status, + rsi_ble_resp_profiles_list_t *rsi_ble_resp_profiles); + +/** + * @typedef void (*rsi_ble_on_profile_resp_t)(uint16_t resp_status, profile_descriptors_t *rsi_ble_resp_profile); + * @brief The callback function will be called if profile response is received + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A06 - Request not supported \n + * 0x4A0A - Attribute not found \n + * @param[out] rsi_ble_resp_profile contains the profile response information. Please refer profile_descriptors_s for more info + * @return void + * @section description + * This callback function will be called if the profile response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_profile_resp_t)(uint16_t resp_status, profile_descriptors_t *rsi_ble_resp_profile); + +/** + * @typedef void (*rsi_ble_on_char_services_resp_t)(uint16_t resp_status, + rsi_ble_resp_char_services_t *rsi_ble_resp_char_serv); + * @brief The callback function will be called if service characteristics response is received + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A06 - Request not supported \n + * 0x4A0A - Attribute not found \n + * 0x4A05 - Insufficient authentication \n + * 0x4A08 - Insufficient authorization \n + * 0x4A0C - Insufficient encryption key size \n + * 0x4A0F - Insufficient encryption \n + * 0x4A02 - Read not permitted \n + * @param[out] rsi_ble_resp_char_serv contains the service characteristics response information. Please refer rsi_ble_resp_char_services_s for more info + * @return void + * @section description + * This callback function will be called if the service characteristics response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_char_services_resp_t)(uint16_t resp_status, + rsi_ble_resp_char_services_t *rsi_ble_resp_char_serv); + +/** + * @typedef void (*rsi_ble_on_inc_services_resp_t)(uint16_t resp_status, + rsi_ble_resp_inc_services_t *rsi_ble_resp_inc_serv); + * @brief The callback function will be called if include services response is received + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A06 - Request not supported \n + * 0x4A0A - Attribute not found \n + * 0x4A05 - Insufficient authentication \n + * 0x4A08 - Insufficient authorization \n + * 0x4A0C - Insufficient encryption key size \n + * 0x4A0F - Insufficient encryption \n + * 0x4A02 - Read not permitted \n + * @param[out] rsi_ble_resp_inc_serv contains the include services response information. Please refer rsi_ble_resp_inc_services_s for more info + * @return void + * @section description + * This callback function will be called if the include service response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_inc_services_resp_t)(uint16_t resp_status, + rsi_ble_resp_inc_services_t *rsi_ble_resp_inc_serv); + +/** + * @typedef void (*rsi_ble_on_att_desc_resp_t)(uint16_t resp_status, rsi_ble_resp_att_descs_t *rsi_ble_resp_att_desc); + * @brief The callback function will be called if attribute descriptors response is received + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A0A - Attribute not found \n + * 0x4A05 - Insufficient authentication \n + * 0x4A08 - Insufficient authorization \n + * 0x4A0C - Insufficient encryption key size \n + * 0x4A0F - Insufficient encryption \n + * 0x4A02 - Read not permitted \n + * @param[out] rsi_ble_resp_att_desc contains the attribute descriptors response information. Please refer rsi_ble_resp_att_descs_s for more info + * @return void + * @section description + * This callback function will be called if the attribute descriptors response is received from the module \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_att_desc_resp_t)(uint16_t resp_status, rsi_ble_resp_att_descs_t *rsi_ble_resp_att_desc); + +/** + * @typedef void (*rsi_ble_on_read_resp_t)(uint16_t resp_status, + uint16_t resp_id, + rsi_ble_resp_att_value_t *rsi_ble_resp_att_val); + * @brief The callback function will be called upon receiving the attribute value + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A0A - Attribute not found \n + * 0x4A05 - Insufficient authentication \n + * 0x4A08 - Insufficient authorization \n + * 0x4A0C - Insufficient encryption key size \n + * 0x4A0F - Insufficient encryption \n + * 0x4A02 - Read not permitted \n + * 0x4A06 - Request not supported \n + * 0x4A07 - Invalid offset \n + * 0x4A0B - Attribute not Long \n + * @param[out] resp_id contains the response id because of which, this callback is called + * response ids: (RSI_BLE_RSP_READ_VAL, RSI_BLE_RSP_READ_BY_UUID, RSI_BLE_RSP_LONG_READ, RSI_BLE_RSP_MULTIPLE_READ) + * @param[out] rsi_ble_resp_att_val contains the attribute value. Please refer rsi_ble_resp_att_value_s for more info + * @return void + * @section description + * This callback function will be called upon receiving the attribute value \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_read_resp_t)(uint16_t resp_status, + uint16_t resp_id, + rsi_ble_resp_att_value_t *rsi_ble_resp_att_val); + +/** + * @typedef void (*rsi_ble_on_write_resp_t)(uint16_t resp_status, uint16_t resp_id); + * @brief The callback function will be called if the attribute set/prepare/execute action is completed + * @param[out] resp_status contains the response status \n + * 0 - Success \n + * Non-Zero Value - Failure \n + * @note Attribute protocol error codes \n + * 0x4A01 - Invalid Handle \n + * 0x4A0A - Attribute not found \n + * 0x4A05 - Insufficient authentication \n + * 0x4A08 - Insufficient authorization \n + * 0x4A0C - Insufficient encryption key size \n + * 0x4A0F - Insufficient encryption \n + * 0x4A03 - Write not permitted \n + * 0x4A07 - Invalid offset \n + * 0x4A0D - Invalid attribute value length \n + * @param[out] resp_id contains the response id because of which, this callback is called + * response ids: (RSI_BLE_RSP_WRITE, RSI_BLE_RSP_WRITE_NO_ACK, RSI_BLE_RSP_LONG_WRITE, RSI_BLE_RSP_EXECUTE_WRITE) + * @return void + * @section description + * This callback function will be called if the attribute set/prepare/execute action is completed \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_write_resp_t)(uint16_t resp_status, uint16_t resp_id); +/** @} */ +/****************************************************** + * * BLE GATT Event Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-LOW-ENERGY8 +* @{ +*/ +/** + * @typedef void (*rsi_ble_on_gatt_write_event_t)(uint16_t event_id, rsi_ble_event_write_t *rsi_ble_write); + * @brief The callback function will be called if the GATT write/notify/indicate events are received + * @param[out] event_id contains the gatt_write event id (RSI_BLE_EVENT_GATT_WRITE) \n + * @param[out] rsi_ble_write contains the GATT event information. Please refer rsi_ble_event_write_s for more info + * @return void + * @section description + * This callback function will be called if the GATT write/notify/indicate events are received \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_gatt_write_event_t)(uint16_t event_id, rsi_ble_event_write_t *rsi_ble_write); + +/** + * @typedef void (*rsi_ble_on_gatt_prepare_write_event_t)(uint16_t event_id, rsi_ble_event_prepare_write_t *rsi_ble_write); + * @brief The callback function will be called if the GATT prepare events are received + * @param[out] event_id contains the gatt_prepare_write event id (RSI_BLE_EVENT_PREPARE_WRITE) \n + + * @param[out] rsi_ble_write contains the GATT prepare event information. Please refer rsi_ble_event_prepare_write_s for more info + * @return void + * @section description + * This callback function will be called if the GATT prepare event is received \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_gatt_prepare_write_event_t)(uint16_t event_id, rsi_ble_event_prepare_write_t *rsi_ble_write); + +/** + * @typedef void (*rsi_ble_on_execute_write_event_t)(uint16_t event_id, rsi_ble_execute_write_t *rsi_ble_execute_write); + * @brief The callback function will be called if the GATT execute events are received + * @param[out] event_id contains the gatt_execute_write event id (RSI_BLE_EVENT_EXECUTE_WRITE) \n + * @param[out] rsi_ble_write contains the GATT event information. Please refer rsi_ble_execute_write_s for more info. + * @return void + * @section description + * This callback function will be called if the GATT execute event is received \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_execute_write_event_t)(uint16_t event_id, rsi_ble_execute_write_t *rsi_ble_execute_write); + +/** + * @typedef void (*rsi_ble_on_read_req_event_t)(uint16_t event_id, rsi_ble_read_req_t *rsi_ble_read_req); + * @brief The callback function will be called if the GATT read request events are received + * @param[out] event_id contains the gatt_read_req_event id (RSI_BLE_EVENT_READ_REQ) \n + + * @param[out] rsi_ble_write contains the GATT event information. Please refer rsi_ble_read_req_s for more info. + * @return void + * @section description + * This callback function will be called if the GATT read request event is received \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_read_req_event_t)(uint16_t event_id, rsi_ble_read_req_t *rsi_ble_read_req); + +/** + * @typedef void (*rsi_ble_on_mtu_event_t)(rsi_ble_event_mtu_t *rsi_ble_event_mtu); + * @brief The callback function will be called if MTU size request is received. + * @param[out] rsi_ble_event_mtu contains the MTU size information. Please refer rsi_ble_event_mtu_s for more info. + * @return void + * @section description + * This callback function will be called when connected to indicate MTU size \n + * This callback has to be registered using rsi_ble_gatt_register_callbacks API + */ +typedef void (*rsi_ble_on_mtu_event_t)(rsi_ble_event_mtu_t *rsi_ble_event_mtu); + +/** + * @typedef void (*rsi_ble_on_mtu_exchange_info_t)(rsi_ble_event_mtu_exchange_information_t *rsi_ble_event_mtu_exchange_info); + * @brief Callback function to indicate MTU size and who initated MTU Exchange Request + * @param[out] rsi_ble_event_mtu_exchange_info contains the MTU exchange information. Please refer rsi_ble_event_mtu_exchange_information_s for more info. + * @return void + * @section description + * This callback function will be called when connected, this event will contain MTU Exchange Information \n + * This callback has to be registered using rsi_ble_gatt_extended_register_callbacks API + */ +typedef void (*rsi_ble_on_mtu_exchange_info_t)( + rsi_ble_event_mtu_exchange_information_t *rsi_ble_event_mtu_exchange_info); + +/** + * @typedef void (*rsi_ble_on_remote_device_info_t)(uint16_t status, rsi_ble_event_remote_device_info_t *resp_buffer); + * @brief Callback function to get peer device information. + * @param[in] status - status of the asynchronous response + * @param[out] resp_buffer - remote device ble version information. Please refer rsi_ble_event_remote_device_info_s for more info. \n + * @return void + * @section description + * This callback function will be called when conn update complete event is received \n + * This callback has to be registered using rsi_ble_enhanced_gap_extended_register_callbacks API \n + */ +typedef void (*rsi_ble_on_remote_device_info_t)(uint16_t status, rsi_ble_event_remote_device_info_t *resp_buffer); + +/** @} */ +/****************************************************** + * * BLE GATT Callbacks register function Declarations + * ******************************************************/ + +/*==============================================*/ +/** + * @fn rsi_ble_gatt_register_callbacks + */ +void rsi_ble_gatt_register_callbacks(rsi_ble_on_profiles_list_resp_t ble_on_profiles_list_resp, + rsi_ble_on_profile_resp_t ble_on_profile_resp, + rsi_ble_on_char_services_resp_t ble_on_char_services_resp, + rsi_ble_on_inc_services_resp_t ble_on_inc_services_resp, + rsi_ble_on_att_desc_resp_t ble_on_att_desc_resp, + rsi_ble_on_read_resp_t ble_on_read_resp, + rsi_ble_on_write_resp_t ble_on_write_resp, + rsi_ble_on_gatt_write_event_t ble_on_gatt_event, + rsi_ble_on_gatt_prepare_write_event_t ble_on_gatt_prepare_write_event, + rsi_ble_on_execute_write_event_t ble_on_execute_write_event, + rsi_ble_on_read_req_event_t ble_on_read_req_event, + rsi_ble_on_mtu_event_t ble_on_mtu_event, + rsi_ble_on_gatt_error_resp_t ble_on_gatt_error_resp_event, + rsi_ble_on_gatt_desc_val_event_t ble_on_gatt_desc_val_resp_event, + rsi_ble_on_event_profiles_list_t ble_on_profiles_list_event, + rsi_ble_on_event_profile_by_uuid_t ble_on_profile_by_uuid_event, + rsi_ble_on_event_read_by_char_services_t ble_on_read_by_char_services_event, + rsi_ble_on_event_read_by_inc_services_t ble_on_read_by_inc_services_event, + rsi_ble_on_event_read_att_value_t ble_on_read_att_value_event, + rsi_ble_on_event_read_resp_t ble_on_read_resp_event, + rsi_ble_on_event_write_resp_t ble_on_write_resp_event, + rsi_ble_on_event_indicate_confirmation_t ble_on_indicate_confirmation_event, + rsi_ble_on_event_prepare_write_resp_t ble_on_prepare_write_resp_event); + +/*==============================================*/ +/** + * @fn rsi_ble_gatt_extended_register_callbacks + */ +void rsi_ble_gatt_extended_register_callbacks(rsi_ble_on_mtu_exchange_info_t ble_on_mtu_exchange_info_event); + +/********************************************************************************* + * * BLE L2CAP Credit based flow control(CBFC) Callbacks register function Declarations + * *******************************************************************************/ + +/** + * @typedef void (*rsi_ble_on_cbfc_conn_req_event_t)(rsi_ble_event_cbfc_conn_req_t *rsi_ble_cbfc_conn_req); + * @brief Callback function to indicate L2CAP CBFC connection request + * @param[in] + * @param[in] rsi_ble_cbfc_conn_req, contains the connection request information + * @return void + * @section description + * This callback function will be called when connected to indicate connection request + * This callback has to be registered using rsi_ble_l2cap_cbfc_callbacks API + */ +typedef void (*rsi_ble_on_cbfc_conn_req_event_t)(rsi_ble_event_cbfc_conn_req_t *rsi_ble_cbfc_conn_req); + +/** + * @typedef void (*rsi_ble_on_cbfc_conn_complete_event_t)(rsi_ble_event_cbfc_conn_complete_t *rsi_ble_cbfc_conn_complete, + * uint16_t status); + * @brief Callback function to indicate L2CAP CBFC connection complete status + * @param[in] + * @param[in] rsi_ble_cbfc_conn_complete, contains the connection completed information + * @return void + * @section description + * This callback function will be called when connected to indicate connection complete status + * This callback has to be registered using rsi_ble_l2cap_cbfc_callbacks API + */ +typedef void (*rsi_ble_on_cbfc_conn_complete_event_t)(rsi_ble_event_cbfc_conn_complete_t *rsi_ble_cbfc_conn_complete, + uint16_t status); + +/** + * @typedef void (*rsi_ble_on_cbfc_rx_data_event_t)(rsi_ble_event_cbfc_rx_data_t *rsi_ble_cbfc_rx_data); + * @brief Callback function to indicate L2CAP CBFC rx data event + * @param[in] + * @param[in] rsi_ble_cbfc_rx_data, contains the received data information + * @return void + * @section description + * This callback function will be called when connected to indicate received data + * This callback has to be registered using rsi_ble_l2cap_cbfc_callbacks API + */ +typedef void (*rsi_ble_on_cbfc_rx_data_event_t)(rsi_ble_event_cbfc_rx_data_t *rsi_ble_cbfc_rx_data); + +/** + * @typedef void (*rsi_ble_on_cbfc_disconn_event_t)(rsi_ble_event_cbfc_disconn_t *rsi_ble_cbfc_disconn); + * @brief Callback function to indicate L2CAP CBFC disconnection evnet + * @param[in] + * @param[in] rsi_ble_cbfc_disconn, contains the disconnect device information + * @return void + * @section description + * This callback function will be called when connected to indicate disconnect l2cap connection + * This callback has to be registered using rsi_ble_l2cap_cbfc_callbacks API + */ +typedef void (*rsi_ble_on_cbfc_disconn_event_t)(rsi_ble_event_cbfc_disconn_t *rsi_ble_cbfc_disconn); + +/*==============================================*/ +/** + * @fn rsi_ble_l2cap_cbsc_register_callbacks + */ +void rsi_ble_l2cap_cbsc_register_callbacks(rsi_ble_on_cbfc_conn_req_event_t ble_on_cbsc_conn_req, + rsi_ble_on_cbfc_conn_complete_event_t ble_on_cbsc_conn_complete, + rsi_ble_on_cbfc_rx_data_event_t ble_on_cbsc_rx_data, + rsi_ble_on_cbfc_disconn_event_t ble_on_cbsc_disconn); + +typedef void (*chip_ble_buffers_stats_handler_t)(chip_ble_buffers_stats_t *chip_ble_buffers_stats); +/** + * @fn rsi_ble_vendor_rf_type + * @brief This api gives vendor specific command to the controller to set rf type. + * RF mode will be decide based on the TXPOWER index. + * @return int32_t + * 0 = success + * !0 = failure + * @section description + * This function is used to issue vendor specific command for setting rf type in controller on given inputs. + * + */ +int32_t rsi_ble_vendor_rf_type(uint8_t ble_power_index); + +/** + * callback rsi_ble_ae_report_complete_t + * @brief Callback function to report the AE Advertisements + * @param[out] rsi_ble_event_ae_report, contains the controller support AE Adv packets information + * @return void + * @section description + * This callback function will be called when AE adv report event is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_report_complete_t)(uint16_t resp_status, rsi_ble_ae_adv_report_t *rsi_ble_event_ae_report); + +/** + * @callback rsi_ble_ae_per_adv_sync_estbl_t + * @brief Callback function to report the AE periodic sync estabilished event + * @param[out] rsi_ble_event_per_adv_sync_estbl, contains the controller support AE periodic sync estabilished information + * @return void + * @section description + * This callback function will be called when AE periodic sync estabilished event is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_per_adv_sync_estbl_t)(uint16_t resp_status, + rsi_ble_per_adv_sync_estbl_t *rsi_ble_event_per_adv_sync_estbl); + +/** + * @callback rsi_ble_ae_per_adv_report_t + * @brief Callback function to report the AE periodic advertisement event + * @param[out] rsi_ble_event_per_adv_report, contains the controller support AE periodic advertisement information + * @return void + * @section description + * This callback function will be called when AE periodic advertisement event is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_per_adv_report_t)(uint16_t resp_status, + rsi_ble_per_adv_report_t *rsi_ble_event_per_adv_report); + +/** + * @callback rsi_ble_ae_per_adv_sync_lost_t + * @brief Callback function to report the AE periodic sync lost event + * @param[out] rsi_ble_event_per_adv_sync_lost, contains the controller support AE periodic sync lost information + * @return void + * @section description + * This callback function will be called when AE periodic sync lost event is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_per_adv_sync_lost_t)(uint16_t resp_status, + rsi_ble_per_adv_sync_lost_t *rsi_ble_event_per_adv_sync_lost); + +/** + * @callback rsi_ble_ae_scan_timeout_t + * @brief Callback function to report the AE scan timeout event + * @param[out] rsi_ble_event_scan_timeout, contains the controller support AE scan timeout information + * @return void + * @section description + * This callback function will be called when AE scan timeout is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_scan_timeout_t)(uint16_t resp_status, rsi_ble_scan_timeout_t *rsi_ble_event_scan_timeout); + +/** + * @callback rsi_ble_ae_adv_set_terminated_t + * @brief Callback function to report the AE advertising set terminated event + * @param[out] rsi_ble_event_adv_set_terminated, contains the controller support AE advertising set terminated information + * @return void + * @section description + * This callback function will be called when AE advertising set terminated is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_adv_set_terminated_t)(uint16_t resp_status, + rsi_ble_adv_set_terminated_t *rsi_ble_event_adv_set_terminated); + +/** + * @callback rsi_ble_ae_scan_req_recvd_t + * @brief Callback function to report the AE scan request received event + * @param[out] rsi_ble_event_scan_req_recvd, contains the controller support AE scan request received information + * @return void + * @section description + * This callback function will be called when AE scan request received is received + * This callback has to be registered using rsi_ble_ae_events_register_callbacks API + */ +typedef void (*rsi_ble_ae_scan_req_recvd_t)(uint16_t resp_status, + rsi_ble_scan_req_recvd_t *rsi_ble_event_scan_req_recvd); + +/*==============================================*/ +/** + * @fn BT_LE_ADPacketExtract + */ +void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len); + +int32_t rsi_ble_set_random_address_with_value(uint8_t *random_addr); +int32_t rsi_ble_set_random_address(void); +int32_t rsi_ble_set_smp_pairing_cap_data(rsi_ble_set_smp_pairing_capabilty_data_t *smp_pair_cap_data); +int32_t rsi_ble_conn_param_resp(uint8_t *remote_dev_address, uint8_t status); +int32_t rsi_ble_get_le_ping_timeout(uint8_t *remote_dev_address, uint16_t *time_out); +int32_t rsi_ble_set_le_ping_timeout(uint8_t *remote_dev_address, uint16_t time_out); +int32_t rsi_ble_clear_whitelist(void); +int32_t rsi_ble_addto_whitelist(int8_t *dev_address, uint8_t dev_addr_type); +int32_t rsi_ble_deletefrom_whitelist(int8_t *dev_address, uint8_t dev_addr_type); +int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp); +int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, uint16_t coded_phy); +int32_t rsi_ble_conn_params_update(uint8_t *remote_dev_address, + uint16_t min_int, + uint16_t max_int, + uint16_t latency, + uint16_t timeout); +int32_t rsi_ble_set_data_len(uint8_t *remote_dev_address, uint16_t tx_octets, uint16_t tx_time); +int32_t rsi_ble_read_max_data_len(rsi_ble_read_max_data_length_t *blereaddatalen); +int32_t rsi_ble_rx_test_mode(uint8_t rx_channel, uint8_t phy, uint8_t modulation); +int32_t rsi_ble_tx_test_mode(uint8_t tx_channel, uint8_t phy, uint8_t tx_len, uint8_t mode); +int32_t rsi_ble_end_test_mode(uint16_t *num_of_pkts); +int32_t rsi_ble_per_transmit(struct rsi_ble_per_transmit_s *rsi_ble_per_tx); +int32_t rsi_ble_per_receive(struct rsi_ble_per_receive_s *rsi_ble_per_rx); +int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, uint8_t *rand, uint8_t *ltk); + +int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data); + +int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data); +int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data); +int32_t rsi_ble_indicate_confirm(uint8_t *dev_addr); +int32_t rsi_ble_remove_gatt_service(uint32_t service_handler); +int32_t rsi_ble_remove_gatt_attibute(uint32_t service_handler, uint16_t att_hndl); +int32_t rsi_ble_att_error_response(uint8_t *dev_addr, uint16_t handle, uint8_t opcode, uint8_t err); + +int32_t rsi_ble_gatt_write_response(uint8_t *dev_addr, uint8_t type); + +int32_t rsi_ble_gatt_prepare_write_response(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint16_t length, + uint8_t *data); + +int32_t rsi_ble_mtu_exchange_event(uint8_t *dev_addr, uint8_t mtu_size); +int32_t rsi_ble_mtu_exchange_resp(uint8_t *dev_addr, uint8_t mtu_size); +void rsi_ble_gap_extended_register_callbacks(rsi_ble_on_remote_features_t ble_on_remote_features_event, + rsi_ble_on_le_more_data_req_t ble_on_le_more_data_req_event); +uint32_t rsi_ble_enhanced_gap_extended_register_callbacks(uint16_t callback_id, + void (*callback_handler_ptr)(uint16_t status, + uint8_t *buffer)); +int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, uint8_t buf_cnt); +#ifdef __cplusplus +} +#endif +#endif diff --git a/wiseconnect/sapi/include/rsi_ble_common_config.h b/wiseconnect/sapi/include/rsi_ble_common_config.h new file mode 100644 index 00000000..3097f009 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_ble_common_config.h @@ -0,0 +1,478 @@ +/******************************************************************************* +* @file rsi_ble_common_config.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_ble_common_config.h + * @version 0.1 + * @date 15 Aug 2018 + * + * + * + * @brief : This file contains user configurable details to configure the device + * + * @section Description This file contains user configurable details to configure the device + * + * + */ +#ifndef RSI_BLE_COMMON_CONFIG_H +#define RSI_BLE_COMMON_CONFIG_H +#include +#include "rsi_data_types.h" + +#ifndef RSI_BLE_SET_RESOLVABLE_PRIV_ADDR_TOUT +#define RSI_BLE_SET_RESOLVABLE_PRIV_ADDR_TOUT 120 +#endif +#ifndef NO_OF_ADV_REPORTS +#define NO_OF_ADV_REPORTS 10 // Maximum number of advertise reports to hold +#endif +#ifndef BLE_CP_BUFF_SIZE_512 +#define BLE_CP_BUFF_SIZE_512 0 // Enabled for BLE PER Test +#endif +/*=======================================================================*/ +// attribute properties +/*=======================================================================*/ +#ifndef RSI_BLE_ATT_PROPERTY_READ +#define RSI_BLE_ATT_PROPERTY_READ 0x02 +#endif +#ifndef RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE +#define RSI_BLE_ATT_PROPERTY_WRITE_NO_RESPONSE 0x04 +#endif +#ifndef RSI_BLE_ATT_PROPERTY_WRITE +#define RSI_BLE_ATT_PROPERTY_WRITE 0x08 +#endif +#ifndef RSI_BLE_ATT_PROPERTY_NOTIFY +#define RSI_BLE_ATT_PROPERTY_NOTIFY 0x10 +#endif +#ifndef RSI_BLE_ATT_PROPERTY_INDICATE +#define RSI_BLE_ATT_PROPERTY_INDICATE 0x20 +#endif + +#ifndef BT_GLOBAL_BUFF_LEN +#define BT_GLOBAL_BUFF_LEN 10000 // Memory length for driver +#endif + +#ifndef BLE_PERIPHERAL_MODE_ENABLE +#define BLE_PERIPHERAL_MODE_ENABLE 1 // Enabling peripheral mode +#endif +/*=======================================================================*/ +// BLE Attribute Security Define +/*=======================================================================*/ +#define ATT_REC_MAINTAIN_IN_HOST BIT(0) /* Att record maintained by the stack */ +#define SEC_MODE_1_LEVEL_1 BIT(1) /* NO Auth & No Enc */ +#define SEC_MODE_1_LEVEL_2 BIT(2) /* UnAUTH with Enc */ +#define SEC_MODE_1_LEVEL_3 BIT(3) /* AUTH with Enc */ +#define SEC_MODE_1_LEVEL_4 BIT(4) /* AUTH LE_SC Pairing with Enc */ +#define ON_BR_EDR_LINK_ONLY BIT(5) +#define ON_LE_LINK_ONLY BIT(6) +/*=======================================================================*/ +// Max Tx data length and Tx timeout values +/*=======================================================================*/ +#ifndef TX_LEN +#define TX_LEN 0x001e +#endif +#ifndef TX_TIME +#define TX_TIME 0x01f4 +#endif +#ifndef RSI_BLE_SMP_IO_CAPABILITY +#define RSI_BLE_SMP_IO_CAPABILITY 0x00 +#endif +#ifndef RSI_BLE_APP_SMP_PASSKEY +#define RSI_BLE_APP_SMP_PASSKEY 0 +#endif +/*=======================================================================*/ +// PHY rate selections +/*=======================================================================*/ +#ifndef TX_PHY_RATE +#define TX_PHY_RATE 0x02 +#endif +#ifndef RX_PHY_RATE +#define RX_PHY_RATE 0x02 +#endif +#ifndef CODDED_PHY_RATE +#define CODDED_PHY_RATE 0x00 +#endif + +/*=======================================================================*/ +// privacy mode 0-Network privacy mode 1-Device privacy mode +/*=======================================================================*/ +#ifndef RSI_BLE_NETWORK_PRIVACY_MODE +#define RSI_BLE_NETWORK_PRIVACY_MODE 0 +#endif +#ifndef RSI_BLE_DEVICE_PRIVACY_MODE +#define RSI_BLE_DEVICE_PRIVACY_MODE 1 +#endif +#ifndef RSI_BLE_PRIVACY_MODE +#define RSI_BLE_PRIVACY_MODE RSI_BLE_DEVICE_PRIVACY_MODE +#endif + +#ifndef RSI_BLE_RESOLVING_LIST_SIZE +#define RSI_BLE_RESOLVING_LIST_SIZE 5 // Resovable list size +#endif +#ifndef RSI_BLE_MAX_DATA_LEN +#define RSI_BLE_MAX_DATA_LEN 20 // max data length +#endif +/*=======================================================================*/ +// process type 1-add device to resolvlist, 2-remove device from resolvlist, 3-clear the resolvlist +/*=======================================================================*/ +#ifndef RSI_BLE_ADD_TO_RESOLVE_LIST +#define RSI_BLE_ADD_TO_RESOLVE_LIST 1 +#endif +#ifndef RSI_BLE_REMOVE_FROM_RESOLVE_LIST +#define RSI_BLE_REMOVE_FROM_RESOLVE_LIST 2 +#endif +#ifndef RSI_BLE_CLEAR_RESOLVE_LIST +#define RSI_BLE_CLEAR_RESOLVE_LIST 3 +#endif +/*=======================================================================*/ +// BLE attribute service types uuid values +/*=======================================================================*/ +#ifndef RSI_BLE_BATTERY_SERVICE_UUID +#define RSI_BLE_BATTERY_SERVICE_UUID 0x180F +#endif +#ifndef RSI_BLE_CHAR_SERV_UUID +#define RSI_BLE_CHAR_SERV_UUID 0x2803 +#endif +#ifndef RSI_BLE_CLIENT_CHAR_UUID +#define RSI_BLE_CLIENT_CHAR_UUID 0x2902 +#endif +#ifndef RSI_BLE_CHAR_PRESENTATION_FORMATE_UUID +#define RSI_BLE_CHAR_PRESENTATION_FORMATE_UUID 0x2904 +#endif +/*=======================================================================*/ +// BLE characteristic service and attribute uuid +/*=======================================================================*/ +#ifndef RSI_BLE_NEW_SERVICE_UUID +#define RSI_BLE_NEW_SERVICE_UUID 0xAABB +#endif +#ifndef RSI_BLE_NEW_SERVICE_UUID2 +#define RSI_BLE_NEW_SERVICE_UUID2 0xCCDD +#endif +#ifndef RSI_BLE_ATTRIBUTE_1_UUID +#define RSI_BLE_ATTRIBUTE_1_UUID 0x1AA1 +#endif +#ifndef RSI_BLE_ATTRIBUTE_2_UUID +#define RSI_BLE_ATTRIBUTE_2_UUID 0x1BB1 +#endif +#ifndef RSI_BLE_ATTRIBUTE_3_UUID +#define RSI_BLE_ATTRIBUTE_3_UUID 0x1CC1 +#endif +#ifndef RSI_BLE_ATTRIBUTE_4_UUID +#define RSI_BLE_ATTRIBUTE_4_UUID 0x1DD1 +#endif + +#ifndef RSI_BLE_SET_RAND_ADDR +#define RSI_BLE_SET_RAND_ADDR "00:23:A7:12:34:56" +#endif + +#ifndef CLEAR_WHITELIST +#define CLEAR_WHITELIST 0x00 +#endif +#ifndef ADD_DEVICE_TO_WHITELIST +#define ADD_DEVICE_TO_WHITELIST 0x01 +#endif +#ifndef DELETE_DEVICE_FROM_WHITELIST +#define DELETE_DEVICE_FROM_WHITELIST 0x02 +#endif + +#ifndef ALL_PHYS +#define ALL_PHYS 0x00 +#endif + +#ifndef RSI_BLE_DEV_ADDR_RESOLUTION_ENABLE +#define RSI_BLE_DEV_ADDR_RESOLUTION_ENABLE 0 +#endif + +#ifndef RSI_OPERMODE_WLAN_BLE +#define RSI_OPERMODE_WLAN_BLE 13 +#endif + +#ifndef RSI_BLE_MAX_NBR_ATT_REC +#define RSI_BLE_MAX_NBR_ATT_REC 80 +#endif +#ifndef RSI_BLE_MAX_NBR_ATT_SERV +#define RSI_BLE_MAX_NBR_ATT_SERV 10 +#endif + +#ifndef RSI_BLE_MAX_NBR_SLAVES +#define RSI_BLE_MAX_NBR_SLAVES 3 +#endif +#ifndef RSI_BLE_MAX_NBR_MASTERS +#define RSI_BLE_MAX_NBR_MASTERS 2 +#endif +#ifndef RSI_BLE_NUM_CONN_EVENTS +#define RSI_BLE_NUM_CONN_EVENTS 20 +#endif + +/* Number of BLE GATT RECORD SIZE IN (n*16 BYTES), eg:(0x40*16)=1024 bytes */ +#ifndef RSI_BLE_NUM_REC_BYTES +#define RSI_BLE_NUM_REC_BYTES 0x40 +#endif +/*=======================================================================*/ +// Advertising command parameters +/*=======================================================================*/ +#ifndef RSI_BLE_ADV_DIR_ADDR +#define RSI_BLE_ADV_DIR_ADDR "00:15:83:6A:64:17" +#endif + +#ifndef RSI_BLE_ADV_CHANNEL_MAP +#define RSI_BLE_ADV_CHANNEL_MAP 0x07 +#endif + +// BLE Tx Power Index On Air +#ifndef RSI_BLE_PWR_INX +#define RSI_BLE_PWR_INX 30 +#endif + +// BLE Tx Power Index On Air per Gap role +#ifndef RSI_BLE_PWR_INX_DBM +#define RSI_BLE_PWR_INX_DBM 0 +#endif + +#ifndef RSI_BLE_START_ADV +#define RSI_BLE_START_ADV 0x01 // Start the advertising process +#endif +#ifndef RSI_BLE_STOP_ADV +#define RSI_BLE_STOP_ADV 0x00 // Stop the advertising process +#endif +/*=======================================================================*/ +// Advertise type +/*=======================================================================*/ +/* Advertising will be visible(discoverable) to all the devices. + * Scanning/Connection is also accepted from all devices + * */ +#ifndef UNDIR_CONN +#define UNDIR_CONN 0x80 +#endif +/* Advertising will be visible(discoverable) to the particular device + * mentioned in RSI_BLE_ADV_DIR_ADDR only. + * Scanning and Connection will be accepted from that device only. + * */ +#ifndef DIR_CONN +#define DIR_CONN 0x81 +#endif +/* Advertising will be visible(discoverable) to all the devices. + * Scanning will be accepted from all the devices. + * Connection will be not be accepted from any device. + * */ +#ifndef UNDIR_SCAN +#define UNDIR_SCAN 0x82 +#endif +/* Advertising will be visible(discoverable) to all the devices. + * Scanning and Connection will not be accepted from any device + * */ +#ifndef UNDIR_NON_CONN +#define UNDIR_NON_CONN 0x83 +#endif +/* Advertising will be visible(discoverable) to the particular device + * mentioned in RSI_BLE_ADV_DIR_ADDR only. + * Scanning and Connection will be accepted from that device only. + * */ +#ifndef DIR_CONN_LOW_DUTY_CYCLE +#define DIR_CONN_LOW_DUTY_CYCLE 0x84 +#endif + +#ifndef RSI_BLE_ADV_TYPE +#define RSI_BLE_ADV_TYPE UNDIR_CONN +#endif +/*=======================================================================*/ +// Advertising flags +/*=======================================================================*/ +#ifndef LE_LIMITED_DISCOVERABLE +#define LE_LIMITED_DISCOVERABLE 0x01 +#endif +#ifndef LE_GENERAL_DISCOVERABLE +#define LE_GENERAL_DISCOVERABLE 0x02 +#endif +#ifndef LE_BR_EDR_NOT_SUPPORTED +#define LE_BR_EDR_NOT_SUPPORTED 0x04 +#endif +/*=======================================================================*/ +// Advertise filters +/*=======================================================================*/ +#ifndef ALLOW_SCAN_REQ_ANY_CONN_REQ_ANY +#define ALLOW_SCAN_REQ_ANY_CONN_REQ_ANY 0x00 +#endif +#ifndef ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_ANY +#define ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_ANY 0x01 +#endif +#ifndef ALLOW_SCAN_REQ_ANY_CONN_REQ_WHITE_LIST +#define ALLOW_SCAN_REQ_ANY_CONN_REQ_WHITE_LIST 0x02 +#endif +#ifndef ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_WHITE_LIST +#define ALLOW_SCAN_REQ_WHITE_LIST_CONN_REQ_WHITE_LIST 0x03 +#endif + +#ifndef RSI_BLE_ADV_FILTER_TYPE +#define RSI_BLE_ADV_FILTER_TYPE ALLOW_SCAN_REQ_ANY_CONN_REQ_ANY +#endif +/*=======================================================================*/ +// Address types +/*=======================================================================*/ +#ifndef LE_PUBLIC_ADDRESS +#define LE_PUBLIC_ADDRESS 0x00 +#endif +#ifndef LE_RANDOM_ADDRESS +#define LE_RANDOM_ADDRESS 0x01 +#endif +#ifndef LE_RESOLVABLE_PUBLIC_ADDRESS +#define LE_RESOLVABLE_PUBLIC_ADDRESS 0x02 +#endif +#ifndef LE_RESOLVABLE_RANDOM_ADDRESS +#define LE_RESOLVABLE_RANDOM_ADDRESS 0x03 +#endif + +#ifndef RSI_BLE_ADV_DIR_ADDR_TYPE +#define RSI_BLE_ADV_DIR_ADDR_TYPE LE_PUBLIC_ADDRESS +#endif +/*=======================================================================*/ +// Connection parameters +/*=======================================================================*/ +#ifndef CONNECTION_LATENCY +#define CONNECTION_LATENCY 0x0000 +#endif +#ifndef SUPERVISION_TIMEOUT +#define SUPERVISION_TIMEOUT 0x07D0 //2000 +#endif + +/*=======================================================================*/ +// Scan command parameters +/*=======================================================================*/ +//Scan status +#ifndef RSI_BLE_START_SCAN +#define RSI_BLE_START_SCAN 0x01 +#endif +#ifndef RSI_BLE_STOP_SCAN +#define RSI_BLE_STOP_SCAN 0x00 +#endif + +//Scan types +#ifndef SCAN_TYPE_ACTIVE +#define SCAN_TYPE_ACTIVE 0x01 +#endif +#ifndef SCAN_TYPE_PASSIVE +#define SCAN_TYPE_PASSIVE 0x00 +#endif + +//Scan filters +#ifndef SCAN_FILTER_TYPE_ALL +#define SCAN_FILTER_TYPE_ALL 0x00 +#endif +#ifndef SCAN_FILTER_TYPE_ONLY_WHITE_LIST +#define SCAN_FILTER_TYPE_ONLY_WHITE_LIST 0x01 +#endif + +#ifndef RSI_BLE_SCAN_TYPE +#define RSI_BLE_SCAN_TYPE SCAN_TYPE_ACTIVE +#endif + +#ifndef RSI_BLE_SCAN_FILTER_TYPE +#define RSI_BLE_SCAN_FILTER_TYPE SCAN_FILTER_TYPE_ALL +#endif +/*-------------------------------------------------------------------------------------------*/ +#ifndef BLE_DISABLE_DUTY_CYCLING +#define BLE_DISABLE_DUTY_CYCLING 0 +#endif +#ifndef BLE_DUTY_CYCLING +#define BLE_DUTY_CYCLING 1 +#endif +#ifndef BLR_DUTY_CYCLING +#define BLR_DUTY_CYCLING 2 +#endif +#ifndef BLE_4X_PWR_SAVE_MODE +#define BLE_4X_PWR_SAVE_MODE 4 +#endif +#ifndef RSI_BLE_PWR_SAVE_OPTIONS +#define RSI_BLE_PWR_SAVE_OPTIONS BLE_DISABLE_DUTY_CYCLING +#endif +/*-------------------------------------------------------------------------------------------*/ +#ifndef RSI_SEL_INTERNAL_ANTENNA +#define RSI_SEL_INTERNAL_ANTENNA 0x00 +#endif +#ifndef RSI_SEL_EXTERNAL_ANTENNA +#define RSI_SEL_EXTERNAL_ANTENNA 0x01 +#endif +#endif + +#ifndef RSI_SEL_ANTENNA +#define RSI_SEL_ANTENNA \ + RSI_SEL_INTERNAL_ANTENNA // Antenna Selection - RSI_SEL_EXTERNAL_ANTENNA / RSI_SEL_INTERNAL_ANTENNA +#endif +/*-------------------------------------------------------------------------------------------*/ +#ifndef RSI_BLE_GATT_ASYNC_ENABLE +#define RSI_BLE_GATT_ASYNC_ENABLE 0 +#endif + +#ifndef RSI_BLE_GATT_INIT +#define RSI_BLE_GATT_INIT 0 +#endif + +#ifndef RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST +#define RSI_BLE_INDICATE_CONFIRMATION_FROM_HOST 0 +#endif + +#ifndef RSI_BLE_MTU_EXCHANGE_FROM_HOST +#define RSI_BLE_MTU_EXCHANGE_FROM_HOST 0 +#endif + +// If user wants to set scan resp data from Application this BIT has to set. +#ifndef RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST +#define RSI_BLE_SET_SCAN_RESP_DATA_FROM_HOST 0 +#endif + +#ifndef RSI_BLE_DISABLE_CODED_PHY_FROM_HOST +#define RSI_BLE_DISABLE_CODED_PHY_FROM_HOST 0 +#endif +/*-------------------------------------------------------------------------------------------*/ +// Advertising command parameters +#ifndef RSI_BLE_ADV_INT_MIN +#define RSI_BLE_ADV_INT_MIN 0x100 +#endif +#ifndef RSI_BLE_ADV_INT_MAX +#define RSI_BLE_ADV_INT_MAX 0x200 +#endif + +#ifndef CONNECTION_INTERVAL_MIN +#define CONNECTION_INTERVAL_MIN 0x00A0 +#endif +#ifndef CONNECTION_INTERVAL_MAX +#define CONNECTION_INTERVAL_MAX 0x00A0 +#endif + +#ifndef LE_SCAN_INTERVAL +#define LE_SCAN_INTERVAL 0x0100 +#endif +#ifndef LE_SCAN_WINDOW +#define LE_SCAN_WINDOW 0x0050 +#endif + +#ifndef RSI_BLE_MTU_EXCHANGE_FROM_HOST +#define RSI_BLE_MTU_EXCHANGE_FROM_HOST 0 +#endif +/*=======================================================================*/ +// Extended Advertising parameters +/*=======================================================================*/ +#ifndef RSI_BLE_ENABLE_ADV_EXTN +#define RSI_BLE_ENABLE_ADV_EXTN 0 // disabled by default +#endif + +#ifndef RSI_BLE_AE_MAX_ADV_SETS +#define RSI_BLE_AE_MAX_ADV_SETS 2 // default number of Advertising sets in extended advertising (Max value = 15) +#endif diff --git a/wiseconnect/sapi/include/rsi_bootup_config.h b/wiseconnect/sapi/include/rsi_bootup_config.h new file mode 100644 index 00000000..20ee09b4 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bootup_config.h @@ -0,0 +1,116 @@ +/******************************************************************************* +* @file rsi_bootup_config.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_BOOTUP_CONFIG_H +#define RSI_BOOTUP_CONFIG_H +/****************************************************** + * * Macros + * ******************************************************/ + +#include + +//Select Default image +#define SELECT_DEFAULT_NWP_FW '5' + +// Check CRC +#define CHECK_NWP_INTEGRITY 'K' + +#define CMD_PASS 0xAA +#define CMD_FAIL 0xCC +#define ENABLE_GPIO_BASED_BYPASS '7' +#define DISABLE_GPIO_BASED_BYPASS '8' +#define INVALID_DEFAULT_IMAGE 0xF5 +#define RSI_HOST_INTF_REG_OUT 0x4105003C +#define RSI_HOST_INTF_REG_IN 0x41050034 +#define RSI_HOST_INTF_STATUS_REG 0x41050004 +#ifdef RSI_M4_INTERFACE +#define RSI_PING_BUFFER_ADDR 0x418000 +#define RSI_PONG_BUFFER_ADDR 0x419000 +#else +#ifdef CHIP_9117 +#define RSI_PING_BUFFER_ADDR 0x59400 +#define RSI_PONG_BUFFER_ADDR 0x5A400 +#else +#define RSI_PING_BUFFER_ADDR 0x18000 +#define RSI_PONG_BUFFER_ADDR 0x19000 +#endif +#endif + +#define RSI_PING_PONG_CHUNK_SIZE 4096 +#define RSI_SDIO_INTF_STATUS_REG 0xF9 +#define RSI_BOARD_READY 0xABCD +#define RSI_REG_READ 0xD1 +#define RSI_REG_WRITE 0xD2 +#define RSI_SEND_RPS_FILE '2' +#define RSI_FWUP_SUCCESSFUL 'S' +#define RSI_EOF_REACHED 'E' +#define RSI_PONG_VALID 'O' +#define RSI_PING_VALID 'I' +#define RSI_PONG_WRITE 0xD4 +#define RSI_PING_WRITE 0xD5 +#define RSI_PONG_AVAIL 'O' +#define RSI_PING_AVAIL 'I' + +#define RSI_MIN_CHUNK_SIZE 4096 +#define RSI_FW_START_OF_FILE BIT(0) +#define RSI_FW_END_OF_FILE BIT(1) + +#define RSI_HOST_INTERACT_REG_VALID (0xAB << 8) +#define RSI_HOST_INTERACT_REG_VALID_FW (0xA0 << 8) + +#define RSI_LOADING_INITIATED '1' + +#define RSI_EOF_REACHED 'E' +#define RSI_BOOTUP_OPTIONS_LAST_CONFIG_NOT_SAVED 0xF1 +#define RSI_BOOTUP_OPTIONS_CHECKSUM_FAIL 0xF2 +#define RSI_INVALID_OPTION 0xF3 +#define RSI_CHECKSUM_SUCCESS 0xAA +#define RSI_CHECKSUM_FAILURE 0xCC +#define RSI_CHECKSUM_INVALID_ADDRESS 0x4C +#define VALID_FIRMWARE_NOT_PRESENT 0x23 +#define RSI_BOOTLOADER_VERSION_1P0 0x10 +#define RSI_BOOTLOADER_VERSION_1P1 0x11 +#define RSI_ROM_VERSION_1P0 1 +#define RSI_ROM_VERSION_1P1 2 + +//SPI Internal Register Offset +#define RSI_SPI_INT_REG_ADDR 0x00 //@ register access method +#define RSI_SPI_MODE_REG_ADDR 0x08 //@ register access method +#define RSI_SPI_LENGTH_REG_ADDR 0x20 + +int16_t rsi_bl_upgrade_firmware(uint8_t *firmware_image, uint32_t fw_image_size, uint8_t flags); +int32_t rsi_device_deinit(void); +int32_t rsi_device_init(uint8_t select_option); +int16_t rsi_bootloader_instructions(uint8_t type, uint16_t *data); +int16_t rsi_bl_waitfor_boardready(void); +int16_t rsi_bl_select_option(uint8_t cmd); +int32_t rsi_bl_module_power_off(void); +int32_t rsi_bl_module_power_on(void); +int16_t rsi_bl_module_power_cycle(void); +int32_t rsi_set_fast_fw_up(void); +int32_t rsi_integrity_check_bypass(void); +int16_t rsi_waitfor_boardready(void); +int16_t rsi_select_option(uint8_t cmd); +int32_t rsi_get_rom_version(void); +int32_t rsi_get_ram_dump(uint32_t addr, uint16_t length, uint8_t *buf); + +#endif diff --git a/wiseconnect/sapi/include/rsi_bt.h b/wiseconnect/sapi/include/rsi_bt.h new file mode 100644 index 00000000..fad91362 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt.h @@ -0,0 +1,1174 @@ +/******************************************************************************* +* @file rsi_bt.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_BT_H1 +#define RSI_BT_H1 + +#include +#include +#include + +/****************************************************** + * * Macros + * ******************************************************/ +#define RSI_MAX_PINCODE_REPLY_SIZE 17 +#define CHANNEL_MAP_LEN 10 + +#define BT_VENDOR_AVDTP_STATS_CMD_OPCODE 0xFC18 +#define BT_VENDOR_MEMORY_STATS_CMD_OPCODE 0xFC19 +#define BT_VENDOR_DYNAMIC_PWR_OPCODE 0xFC1C +#define BT_VENDOR_AR_CMD_OPCODE 0xFC1E +#define BT_VENDOR_AFH_CLASSIFICATION_CMD_OPCODE 0xFC21 + +/* Packet Type/s */ +#define PTYPE_2DH1_MAY_NOT_BE_USED 0x0002 +#define PTYPE_3DH1_MAY_NOT_BE_USED 0x0004 +#define PTYPE_DM1_MAY_BE_USED 0x0008 +#define PTYPE_DH1_MAY_BE_USED 0x0010 +#define PTYPE_2DH3_MAY_NOT_BE_USED 0x0100 +#define PTYPE_3DH3_MAY_NOT_BE_USED 0x0200 +#define PTYPE_DM3_MAY_BE_USED 0x0400 +#define PTYPE_DH3_MAY_BE_USED 0x0800 +#define PTYPE_2DH5_MAY_NOT_BE_USED 0x1000 +#define PTYPE_3DH5_MAY_NOT_BE_USED 0x2000 +#define PTYPE_DM5_MAY_BE_USED 0x4000 +#define PTYPE_DH5_MAY_BE_USED 0x8000 +#define PTYPE_1MBPS_MODE_ONLY \ + (PTYPE_2DH1_MAY_NOT_BE_USED | PTYPE_3DH1_MAY_NOT_BE_USED | PTYPE_2DH3_MAY_NOT_BE_USED | PTYPE_3DH3_MAY_NOT_BE_USED \ + | PTYPE_2DH5_MAY_NOT_BE_USED | PTYPE_3DH5_MAY_NOT_BE_USED) +#define PTYPE_2DH3_MAY_BE_USED \ + (PTYPE_2DH1_MAY_NOT_BE_USED | PTYPE_3DH1_MAY_NOT_BE_USED | PTYPE_3DH3_MAY_NOT_BE_USED | PTYPE_2DH5_MAY_NOT_BE_USED \ + | PTYPE_3DH5_MAY_NOT_BE_USED) +#define PTYPE_2DH5_MAY_BE_USED \ + (PTYPE_2DH1_MAY_NOT_BE_USED | PTYPE_3DH1_MAY_NOT_BE_USED | PTYPE_2DH3_MAY_NOT_BE_USED | PTYPE_3DH3_MAY_NOT_BE_USED \ + | PTYPE_3DH5_MAY_NOT_BE_USED) +#define PTYPE_3DH3_MAY_BE_USED \ + (PTYPE_2DH1_MAY_NOT_BE_USED | PTYPE_3DH1_MAY_NOT_BE_USED | PTYPE_2DH3_MAY_NOT_BE_USED | PTYPE_2DH5_MAY_NOT_BE_USED \ + | PTYPE_3DH5_MAY_NOT_BE_USED) +#define PTYPE_3DH5_MAY_BE_USED \ + (PTYPE_2DH1_MAY_NOT_BE_USED | PTYPE_3DH1_MAY_NOT_BE_USED | PTYPE_2DH3_MAY_NOT_BE_USED | PTYPE_3DH3_MAY_NOT_BE_USED \ + | PTYPE_2DH5_MAY_NOT_BE_USED) +// Packet Sizes +#define BT_DM1_PAYLOAD_MAX_LEN 17 +#define BT_DM3_PAYLOAD_MAX_LEN 121 +#define BT_DM5_PAYLOAD_MAX_LEN 224 +#define BT_DH1_PAYLOAD_MAX_LEN 27 +#define BT_DH3_PAYLOAD_MAX_LEN 183 +#define BT_DH5_PAYLOAD_MAX_LEN 339 +#define BT_2DH1_PAYLOAD_MAX_LEN 54 +#define BT_2DH3_PAYLOAD_MAX_LEN 367 +#define BT_2DH5_PAYLOAD_MAX_LEN 679 +#define BT_3DH1_PAYLOAD_MAX_LEN 83 +#define BT_3DH3_PAYLOAD_MAX_LEN 552 +#define BT_3DH5_PAYLOAD_MAX_LEN 1021 + +/****************************************************** + * * BT classic AFH defines + * ******************************************************/ +#define RSI_WRITE_ASSESSMENT_MODE 0x01 +#define RSI_READ_ASSESSMENT_MODE 0x00 +#define RSI_ASSESSMENT_MODE_DISABLE 0x00 +#define RSI_ASSESSMENT_MODE_ENABLE 0x01 + +#define BT_EDR_3MBPS_DISABLE (1 << 8) +#define BT_EDR_2MBPS_DISABLE (1 << 9) +#define BT_5_SLOT_PACKETS_DISABLE (1 << 10) +#define BT_3_SLOT_PACKETS_DISABLE (1 << 11) + +#define BT_EDR_3MBPS_PACKETS_ONLY BT_EDR_2MBPS_DISABLE +#define BT_EDR_2MBPS_PACKETS_ONLY BT_EDR_3MBPS_DISABLE + +#define BT_EDR_2DH1_PACKETS_ONLY (BT_EDR_2MBPS_PACKETS_ONLY | BT_5_SLOT_PACKETS_DISABLE | BT_3_SLOT_PACKETS_DISABLE) +#define BT_EDR_2DH3_PACKETS_ONLY (BT_EDR_2MBPS_PACKETS_ONLY | BT_5_SLOT_PACKETS_DISABLE) +#define BT_EDR_2DH5_PACKETS_ONLY (BT_EDR_2MBPS_PACKETS_ONLY | BT_3_SLOT_PACKETS_DISABLE) +#define BT_EDR_3DH1_PACKETS_ONLY (BT_EDR_3MBPS_PACKETS_ONLY | BT_5_SLOT_PACKETS_DISABLE | BT_3_SLOT_PACKETS_DISABLE) +#define BT_EDR_3DH3_PACKETS_ONLY (BT_EDR_3MBPS_PACKETS_ONLY | BT_5_SLOT_PACKETS_DISABLE) +#define BT_EDR_3DH5_PACKETS_ONLY (BT_EDR_3MBPS_PACKETS_ONLY | BT_3_SLOT_PACKETS_DISABLE) +/****************************************************** + * * Constants + * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Enumerations + * ******************************************************/ + +#define RSI_BT_MAX_ACCESSORY_INFO_LEN 70 +// enumeration for BT command request codes +typedef enum rsi_bt_cmd_request_e { + RSI_BT_REQ_SET_LOCAL_COD = 0x0003, + RSI_BT_REQ_QUERY_LOCAL_COD = 0x0004, + RSI_BT_REQ_SET_PROFILE_MODE = 0x0008, + RSI_BT_REQ_SET_DISCV_MODE = 0x0009, + RSI_BT_REQ_QUERY_DISCV_MODE = 0x000A, + RSI_BT_REQ_SET_CONNECTABILITY_MODE = 0x000B, + RSI_BT_REQ_QUERY_CONNECTABILITY_MODE = 0x000C, + RSI_BT_REQ_SET_PAIR_MODE = 0x000D, + RSI_BT_REQ_QUERY_PAIR_MODE = 0x000E, + RSI_BT_REQ_REMOTE_NAME_REQUEST = 0x000F, + RSI_BT_REQ_REMOTE_NAME_REQUEST_CANCEL = 0x0010, + RSI_BT_REQ_INQUIRY = 0x0011, + RSI_BT_REQ_INQUIRY_CANCEL = 0x0012, + RSI_BT_REQ_BOND = 0x0013, + RSI_BT_REQ_BOND_CANCEL = 0x0014, + RSI_BT_REQ_UNBOND = 0x0015, + RSI_BT_REQ_USER_CONFIRMATION = 0x0018, + RSI_BT_REQ_PASSKEY_REPLY = 0x0019, + RSI_BT_REQ_PINCODE_REPLY = 0x001A, + RSI_BT_REQ_QUERY_ROLE = 0x001B, + RSI_BT_REQ_SET_ROLE = 0x001C, + RSI_BT_REQ_QUERY_SERVICES = 0x001D, + RSI_BT_REQ_SEARCH_SERVICE = 0x001E, + RSI_BT_REQ_SPP_CONNECT = 0x001F, + RSI_BT_REQ_SPP_DISCONNECT = 0x0020, + RSI_BT_REQ_SPP_TRANSFER = 0x0021, + + RSI_BT_REQ_A2DP_CONNECT = 0x0022, + RSI_BT_REQ_A2DP_DISCONNECT = 0x0023, + + RSI_BT_REQ_AVRCP_CONNECT = 0X0024, + RSI_BT_REQ_AVRCP_DISCONNECT = 0X0025, + RSI_BT_REQ_AVRCP_PLAY = 0X0026, + RSI_BT_REQ_AVRCP_PAUSE = 0X0027, + RSI_BT_REQ_AVRCP_STOP = 0X0028, + RSI_BT_REQ_AVRCP_NEXT = 0X0029, + RSI_BT_REQ_AVRCP_PREVIOUS = 0X002A, + + RSI_BT_REQ_AVRCP_VOL_UP = 0X002B, + RSI_BT_REQ_AVRCP_VOL_DOWN = 0X002C, + + RSI_BT_REQ_HFP_CONNECT = 0x002D, + RSI_BT_REQ_HFP_DISCONNECT = 0x002E, + RSI_BT_REQ_HFP_PHONEOPERATOR = 0x002F, + RSI_BT_REQ_HFP_CALLACCEPT = 0x0030, + RSI_BT_REQ_HFP_CALLREJECT = 0x0031, + RSI_BT_REQ_HFP_DIALNUM = 0x0032, + RSI_BT_REQ_HFP_DIALMEM = 0x0033, + RSI_BT_REQ_HFP_REDIAL = 0x0034, + RSI_BT_REQ_HFP_VOICERECOGNITIONACTIVE = 0x0035, + RSI_BT_REQ_HFP_VOICERECOGNITIONDEACTIVE = 0x0036, + RSI_BT_REQ_HFP_SPKGAIN = 0x0037, + RSI_BT_REQ_HFP_MICGAIN = 0x0038, + RSI_BT_REQ_HFP_GETCALLS = 0x0039, + RSI_BT_REQ_HFP_AUDIOTRANSFER = 0x003A, + + RSI_BT_REQ_PBAP_CONNECT = 0x003B, + RSI_BT_REQ_PBAP_DISCONNECT = 0x003C, + RSI_BT_REQ_PBAP_CONTACTS = 0x003D, + + RSI_BT_REQ_HID_CONNECT = 0x003E, + RSI_BT_REQ_HID_DISCONNECT = 0x003F, + RSI_BT_REQ_HID_PROFILE_DATA = 0x0040, + RSI_BT_REQ_HID_SDP_ATT_INIT = 0x0041, + + RSI_BT_REQ_L2CAP_CONNECT = 0x0042, + RSI_BT_REQ_L2CAP_DISCONNECT = 0x0043, + RSI_BT_REQ_L2CAP_PROTOCOL_DATA = 0x0044, + RSI_BT_REQ_L2CAP_ERTM_CONFIGURE = 0x0045, + + RSI_BT_REQ_ENABLE_AUTH = 0x0046, + RSI_BT_REQ_ENABLE_ENC = 0x0047, + RSI_BT_REQ_DEL_LINKKEYS = 0x0048, + + RSI_BT_REQ_HFP_AUDIODATA = 0x0049, + + RSI_BT_LINK_POLICY_CONFIG = 0x004A, + + RSI_BT_REQ_LINKKEY_REPLY = 0x0091, + RSI_BT_REQ_PER_TX = 0x0098, + RSI_BT_REQ_PER_RX = 0x0099, + RSI_BT_REQ_CW_MODE = 0x009B, + RSI_BT_REQ_SNIFF_MODE = 0x009D, + RSI_BT_REQ_SNIFF_EXIT_MODE = 0x009E, + RSI_BT_REQ_SNIFF_SUBRATING_MODE = 0x009F, + RSI_BT_REQ_SET_SSP_MODE = 0x00A0, + RSI_BT_REQ_SET_EIR = 0X00A9, + + RSI_BT_REQ_A2DP_CLOSE = 0x00CC, + RSI_BT_REQ_A2DP_ABORT = 0x00CD, + RSI_BT_REQ_A2DP_START = 0x00CE, + RSI_BT_REQ_A2DP_SUSPEND = 0x00CF, + RSI_BT_REQ_A2DP_PCM_MP3_DATA = 0x00D0, + RSI_BT_REQ_A2DP_SBC_AAC_DATA = 0x00D1, + + RSI_BT_REQ_SET_AFH_HOST_CHANNEL_CLASSIFICATION = 0x00D2, + + //AVRCP 1.3 controller role commands + RSI_BT_REQ_AVRCP_GET_CAPABILITES = 0X00D3, + RSI_BT_REQ_AVRCP_GET_ATTS_LIST = 0X00D4, + RSI_BT_REQ_AVRCP_GET_ATT_VALS_LIST = 0X00D5, + RSI_BT_REQ_AVRCP_GET_CUR_ATT_VAL = 0X00D6, + RSI_BT_REQ_AVRCP_SET_CUR_ATT_VAL = 0X00D7, + RSI_BT_REQ_AVRCP_GET_ELEMENT_ATT = 0X00D8, + RSI_BT_REQ_AVRCP_GET_PLAY_STATUS = 0X00D9, + RSI_BT_REQ_AVRCP_REG_NOTIFICATION = 0X00DA, + RSI_BT_REQ_AVRCP_REMOTE_VERSION = 0X00DB, + RSI_BT_REQ_AVRCP_ATT_TEXT = 0X00DC, + RSI_BT_REQ_AVRCP_ATT_VALS_TEXT = 0X00DD, + RSI_BT_REQ_AVRCP_BATTERY_STATUS = 0X00DE, + RSI_BT_REQ_AVRCP_CHAR_SETS = 0X00DF, + + //AVRCP target role commands + RSI_BT_REQ_AVRCP_GET_CAPABILITES_RESP = 0X00E0, + RSI_BT_REQ_AVRCP_GET_ATTS_LIST_RESP = 0X00E1, + RSI_BT_REQ_AVRCP_GET_ATT_VALS_LIST_RESP = 0X00E2, + RSI_BT_REQ_AVRCP_GET_CUR_ATT_VAL_RESP = 0X00E3, + RSI_BT_REQ_AVRCP_SET_CUR_ATT_VAL_RESP = 0X00E4, + RSI_BT_REQ_AVRCP_GET_ELEMENT_ATT_RESP = 0X00E5, + RSI_BT_REQ_AVRCP_GET_PLAY_STATUS_RESP = 0X00E6, + RSI_BT_REQ_AVRCP_REG_NOTIFICATION_RESP = 0X00E7, + RSI_BT_REQ_AVRCP_ATT_TEXT_RESP = 0X00E8, + RSI_BT_REQ_AVRCP_ATT_VALS_TEXT_RESP = 0X00E9, + RSI_BT_REQ_AVRCP_BATTERY_STATUS_RESP = 0X00EA, + RSI_BT_REQ_AVRCP_CHAR_SETS_RESP = 0X00EB, + RSI_BT_REQ_AVRCP_NOTIFICATION = 0X00EC, + RSI_BT_REQ_AVRCP_CMD_REJECT = 0X00ED, + + RSI_BT_REQ_ADD_DEVICE_ID = 0x00EE, + RSI_BT_REQ_SET_CURRENT_IAC_LAP = 0x00EF, + + //Testing Commands + RSI_BT_REQ_ENABLE_DEVICE_UNDER_TESTMODE = 0x00F0, + RSI_BT_REQ_BR_EDR_LP_HP_TRANSISTION = 0x00F1, + + RSI_BT_REQ_A2DP_GET_CONFIG = 0x00FE, + RSI_BT_REQ_A2DP_SET_CONFIG = 0x00FF, + + RSI_BT_REQ_AVRCP_SET_ABS_VOL = 0x0102, + RSI_BT_REQ_AVRCP_SET_ABS_VOL_RESP = 0X0103, + RSI_BT_REQ_GATT_CONNECT = 0x0104, + + RSI_BT_REQ_CHANGE_CONNECTION_PKT_TYPE = 0X0109, + RSI_BT_REQ_A2DP_PCM_MP3_DATA_PREFILL_1 = 0x010D, + RSI_BT_REQ_AVRCP_SET_ADDR_PLAYER_RESP = 0x010E, + RSI_BT_REQ_AVRCP_GET_FOLDER_ITEMS_RESP = 0x010F, + RSI_BT_REQ_AVRCP_GET_TOT_NUM_ITEMS_RESP = 0x0110, + + RSI_BT_REQ_IAP_CONN = 0x0130, + RSI_BT_REQ_IAP_DISCONN = 0x0131, + RSI_BT_REQ_IAP_SET_ACCESSORY_INFO = 0x0132, + RSI_BT_REQ_IAP_SET_APP_PROTOCOL_INFO = 0x0133, + RSI_BT_REQ_IAP_FIND_PROTOCOL_TYPE = 0x0134, + RSI_BT_REQ_IAP_SET_PROTOCOL_TYPE = 0X0135, + RSI_BT_REQ_IAP1_IDENTIFICATION = 0X0136, + RSI_BT_REQ_IAP1_DEVICE_AUTHENTICATION = 0X0137, + RSI_BT_REQ_IAP1_SET_ASSISTIVE_TOUCH = 0X0138, + RSI_BT_REQ_IAP1_SET_VOICE_OVER = 0X0139, + RSI_BT_REQ_IAP1_GET_IPOD_INFO = 0X013A, + RSI_BT_REQ_IAP1_SET_EXTENDED_INTFMODE = 0X013B, + RSI_BT_REQ_IAP1_GET_LINGO_PROTOCOL_VERSION = 0X013C, + RSI_BT_REQ_IAP1_SET_IPOD_PREFERENCES = 0X013D, + RSI_BT_REQ_IAP1_GET_IPOD_PREFERENCES = 0X013E, + RSI_BT_REQ_IAP1_SET_UIMODE = 0X013F, + RSI_BT_REQ_IAP1_GET_UIMODE = 0X0140, + RSI_BT_REQ_IAP1_SET_EVENT_NOTIFICATION = 0X0141, + RSI_BT_REQ_IAP1_GET_EVENT_NOTIFICATION = 0X0142, + RSI_BT_REQ_IAP1_GET_IPOD_LINGO_OPTIONS = 0X0143, + RSI_BT_REQ_IAP1_SUPP_EVENT_NOTIFICATIONS = 0X0144, + RSI_BT_REQ_IAP1_LAUNCH_APPLICATION = 0X0145, + RSI_BT_REQ_IAP1_GET_CURRENT_APP_BUNDLE_NAME = 0X0146, + RSI_BT_REQ_IAP1_GET_LOCALIZATION_INFO = 0X0147, + RSI_BT_REQ_IAP1_REQ_WIFI_CONN_INFO = 0X0148, + RSI_BT_REQ_IAP1_APP_DATA_SESSION_ACK = 0X0149, + RSI_BT_REQ_IAP1_APP_ACCESSORY_DATA_TRANSFER = 0X014A, + RSI_BT_REQ_IAP1_GET_VOICE_OVER_PARAMETER = 0X014B, + RSI_BT_REQ_IAP1_SET_VOICE_OVER_PARAMETER = 0X014C, + RSI_BT_REQ_IAP1_SET_VOICE_OVER_CONTEXT = 0X014D, + RSI_BT_REQ_IAP1_VOICE_OVER_EVENT = 0X014E, + RSI_BT_REQ_IAP1_VOICE_OVER_TEXT_EVENT = 0X014F, + RSI_BT_REQ_IAP1_VOICE_OVER_TOUCH_EVENT = 0X0150, + RSI_BT_REQ_IAP1_VOICE_OVER_XYZ = 0X0151, + RSI_BT_REQ_IAP1_CURR_VOICE_OVER_ITEM_PROPERTY = 0X0152, + RSI_BT_REQ_IAP1_CURR_VOICE_OVER_LABEL = 0X0153, + RSI_BT_REQ_IAP1_CURR_VOICE_OVER_VALUE = 0X0154, + RSI_BT_REQ_IAP1_CURR_VOICE_OVER_HINT = 0X0155, + RSI_BT_REQ_IAP1_CURR_VOICE_OVER_TRAIT = 0X0156, + RSI_BT_REQ_IAP1_IPOD_OUT_BUTTON = 0X0157, + RSI_BT_REQ_IAP1_VIDEO_BUTTON = 0X0158, + RSI_BT_REQ_IAP1_AUDIO_BUTTON = 0X0159, + RSI_BT_REQ_IAP1_CONTEXT_BUTTON = 0X015A, + RSI_BT_REQ_IAP1_RADIO_BUTTON = 0X015B, + RSI_BT_REQ_IAP1_CAMERA_BUTTON = 0X015C, + RSI_BT_REQ_IAP1_ROTATION_INPUT = 0X015D, + RSI_BT_REQ_IAP1_REG_HID_DESCRIPTOR = 0X015E, + RSI_BT_REQ_IAP1_SEND_HID_REPORT = 0X015F, + RSI_BT_REQ_IAP1_UNREG_HID_DESCRIPTOR = 0X0160, + RSI_BT_REQ_IAP2_IDENTIFICATION = 0X0161, + RSI_BT_REQ_IAP2_IDENTIFICATION_CANCEL = 0X0162, + RSI_BT_REQ_IAP2_UPDATE_ACCESSORY_INFO = 0X0163, + RSI_BT_REQ_IAP2_DEVICE_AUTHENTICATION = 0X0164, + RSI_BT_REQ_IAP2_NOWPLAYING_UPDATES_START = 0X0165, + RSI_BT_REQ_IAP2_NOWPLAYING_UPDATES_STOP = 0X0166, + RSI_BT_REQ_IAP2_NOW_PLAYING_ARTWORK_FILE_ACTION = 0X0167, + RSI_BT_REQ_IAP2_CONTROL_SESSION_DATA_TX = 0X0168, + RSI_BT_REQ_IAP2_RECV_CMD_LIST = 0X0169, + RSI_BT_REQ_IAP2_SEND_CMD_LIST = 0X016A, + RSI_BT_REQ_IAP2_INIT_FILE_TRANSFER = 0X016B, + RSI_BT_REQ_IAP2_DE_INIT_FILE_TRANSFER = 0X016C, + RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_STATE = 0X016D, + RSI_BT_REQ_IAP2_SEND_FILE_TRANSFER_DATA = 0X016E, +} rsi_bt_cmd_request_t; + +typedef enum rsi_bt_cmd_resp_e { + RSI_BT_RSP_CARD_READY = 0x0505, + RSI_BT_RSP_SET_LOCAL_COD = 0x0003, + RSI_BT_RSP_QUERY_LOCAL_COD = 0x0004, + RSI_BT_RSP_LINKKEY_REPLY = 0x0091, + RSI_BT_RSP_SET_PROFILE_MODE = 0x0008, + RSI_BT_RSP_SET_DISCV_MODE = 0x0009, + RSI_BT_RSP_QUERY_DISCV_MODE = 0x000A, + RSI_BT_RSP_SET_CONNECTABILITY_MODE = 0x000B, + RSI_BT_RSP_QUERY_CONNECTABILITY_MODE = 0x000C, + RSI_BT_RSP_SET_PAIR_MODE = 0x000D, + RSI_BT_RSP_QUERY_PAIR_MODE = 0x000E, + RSI_BT_RSP_REMOTE_NAME_REQUEST = 0x000F, + RSI_BT_RSP_REMOTE_NAME_REQUEST_CANCEL = 0x0010, + RSI_BT_RSP_INQUIRY = 0x0011, + RSI_BT_RSP_INQUIRY_CANCEL = 0x0012, + RSI_BT_RSP_BOND = 0x0013, + RSI_BT_RSP_BOND_CANCEL = 0x0014, + RSI_BT_RSP_UNBOND = 0x0015, + RSI_BT_RSP_USER_CONFIRMATION = 0x0018, + RSI_BT_RSP_PASSKEY_REPLY = 0x0019, + RSI_BT_RSP_PINCODE_REPLY = 0x001A, + RSI_BT_RSP_QUERY_ROLE = 0x001B, + RSI_BT_RSP_QUERY_SERVICES = 0x001D, + RSI_BT_RSP_SEARCH_SERVICE = 0x001E, + RSI_BT_RSP_SPP_CONNECT = 0x001F, + RSI_BT_RSP_SPP_DISCONNECT = 0x0020, + RSI_BT_RSP_SPP_TRANSFER = 0x0021, + + /*pbap responses */ + RSI_BT_RSP_PBAP_CONNECT = 0x003B, + RSI_BT_RSP_PBAP_DISCONNEC = 0x003C, + RSI_BT_RSP_PBAP_CONTACTS = 0x003D, + + RSI_BT_RESP_L2CAP_CONNECT = 0x0042, + RSI_BT_RESP_L2CAP_DISCONNECT = 0x0043, + RSI_BT_RESP_L2CAP_PROTOCOL_DATA = 0x0044, + RSI_BT_RESP_L2CAP_ERTM_CHANNEL = 0x0045, + + RSI_BT_RESP_ENABLE_AUTH = 0x0046, + RSI_BT_RESP_ENABLE_ENC = 0x0047, + RSI_BT_RESP_DEL_LINKKEYS = 0x0049, + + RSI_BT_RSP_PER_TX = 0x0098, + RSI_BT_RSP_PER_RX = 0x0099, + RSI_BT_RSP_PER_STATS = 0x009A, + RSI_BT_RSP_CW_MODE = 0x009B, + + /* sniff responses */ + RSI_BT_RSP_SNIFF_MODE = 0x009D, + RSI_BT_RSP_SNIFF_EXIT_MODE = 0x009E, + RSI_BT_RSP_SNIFF_SUBRATING_MODE = 0x009F, + RSI_BT_RSP_SET_SSP_MODE = 0x00A0, + RSI_BT_RSP_SET_EIR = 0X00A9, + + //AVRCP resp id's + RSI_BT_RSP_AVRCP_GET_CAPABILITES = 0X00D3, + RSI_BT_RSP_AVRCP_GET_ATTS_LIST = 0X00D4, + RSI_BT_RSP_AVRCP_GET_ATT_VALS_LIST = 0X00D5, + RSI_BT_RSP_AVRCP_GET_CUR_ATT_VAL = 0X00D6, + RSI_BT_RSP_AVRCP_SET_CUR_ATT_VAL = 0X00D7, + RSI_BT_RSP_AVRCP_GET_ELEMENT_ATT = 0X00D8, + RSI_BT_RSP_AVRCP_GET_PLAY_STATUS = 0X00D9, + RSI_BT_RSP_AVRCP_REG_NOTIFICATION = 0X00DA, + RSI_BT_RSP_AVRCP_REMOTE_VERSION = 0X00DB, + RSI_BT_RSP_AVRCP_ATT_TEXT = 0X00DC, + RSI_BT_RSP_AVRCP_ATT_VALS_TEXT = 0X00DD, + RSI_BT_RSP_AVRCP_BATTERY_STATUS = 0X00DE, + RSI_BT_RSP_AVRCP_CHAR_SETS = 0X00DF, + + RSI_BT_RESP_ADD_DEVICE_ID = 0x00EE, + RSI_BT_RESP_SET_CURRENT_IAC_LAP = 0x00EF, + + RSI_BT_RESP_AVRCP_SET_ABS_VOL = 0x0102, + RSI_BT_RESP_AVRCP_SET_ABS_VOL_RESP = 0X0103, + RSI_BT_RESP_GATT_CONNECT = 0x0104, + RSI_BT_RESP_A2DP_PCM_MP3_DATA_PREFILL_1 = 0x010D, + RSI_BT_RESP_AVRCP_SET_ADDR_PLAYER_RESP = 0x010E, + RSI_BT_RESP_AVRCP_GET_FOLDER_ITEMS_RESP = 0x010F, + RSI_BT_RESP_AVRCP_GET_TOT_NUM_ITEMS_RESP = 0x0110 +} rsi_bt_cmd_resp_t; + +// Event Frame Codes +typedef enum rsi_bt_event_e { + RSI_BT_EVT_ROLE_CHANGE_STATUS = 0x1000, + RSI_BT_EVT_UNBOND_STATUS = 0x1001, + RSI_BT_EVT_BOND_RESPONSE = 0x1002, + RSI_BT_EVT_INQUIRY_RESPONSE = 0x1003, + RSI_BT_EVT_REMOTE_DEVICE_NAME = 0x1004, + RSI_BT_EVT_REMOTE_NAME_REQUEST_CANCEL = 0x1005, + RSI_BT_EVT_DISCONNECTED = 0x1006, + RSI_BT_EVT_USER_CONFIRMATION_REQUEST = 0x1007, + RSI_BT_EVT_USER_PASKEY_DISPLAY = 0x1008, + RSI_BT_EVT_USER_PINCODE_REQUEST = 0x1009, + RSI_BT_EVT_USER_PASSKEY_REQUEST = 0x100A, + RSI_BT_EVT_INQ_COMPLETE = 0x100B, + RSI_BT_EVT_AUTH_COMPLETE = 0x100C, + RSI_BT_EVT_USER_LINKKEY_REQUEST = 0x100D, + RSI_BT_EVT_USER_LINKKEY_SAVE = 0x100E, + RSI_BT_EVT_SSP_COMPLETE = 0x100F, + + RSI_BT_EVT_MODE_CHANGED = 0x1010, + RSI_BT_EVT_SNIFF_SUBRATING_CHANGED = 0x1011, + + RSI_BT_EVT_USER_PASSKEY_NOTIFY = 0x1012, + RSI_BT_EVT_GATT_CONNECTED = 0x1013, + RSI_BT_EVT_GATT_DISCONNECTED = 0x1014, + /* AVDTP Stats Event */ + RSI_BT_EVT_AVDTP_STATS = 0x1015, + /* Chip Memory Stats Event */ + RSI_BT_EVT_CHIP_MEMORY_STATS = 0x1016, + RSI_BT_EVENT_CONNECTION_INITIATED = 0x1017, + /* Auto rate Stats Event */ + RSI_BT_EVT_AR_STATS = 0x1018, + + /*SPP profile Event ID's*/ + RSI_BT_EVT_SPP_RECEIVE = 0x1100, + RSI_BT_EVT_SPP_CONNECTED = 0x1101, + RSI_BT_EVT_SPP_DISCONNECTED = 0x1102, + + /*A2DP profile Event ID's*/ + RSI_BT_EVT_A2DP_CONNECTED = 0x1200, + RSI_BT_EVT_A2DP_DISCONNECTED = 0x1201, + RSI_BT_EVT_A2DP_CONFIGURED = 0x1202, + RSI_BT_EVT_A2DP_OPEN = 0x1203, + RSI_BT_EVT_A2DP_START = 0x1204, + RSI_BT_EVT_A2DP_SUSPEND = 0x1205, + RSI_BT_EVT_A2DP_ABORT = 0x1206, + RSI_BT_EVT_A2DP_CLOSE = 0x1207, + RSI_BT_EVT_A2DP_ENCODE_DATA = 0x1208, + RSI_BT_EVT_A2DP_PCM_DATA = 0x1209, + RSI_BT_EVT_A2DP_MORE_DATA_REQ = 0x120A, + RSI_BT_EVT_A2DP_CODEC_CFG = 0x120B, + RSI_BT_EVT_A2DP_RECONFIG = 0x120C, + + /*AVRCP profile Event ID's*/ + RSI_BT_EVT_AVRCP_CONNECTED = 0x1300, + RSI_BT_EVT_AVRCP_DISCONNECTED = 0x1301, + RSI_BT_EVT_AVRCP_PLAY = 0x1302, + RSI_BT_EVT_AVRCP_PAUSE = 0x1303, + RSI_BT_EVT_AVRCP_NEXT = 0x1304, + RSI_BT_EVT_AVRCP_PREVIOUS = 0x1305, + RSI_BT_EVT_AVRCP_STOP = 0x1306, + RSI_BT_EVT_AVRCP_VOL_UP = 0x1307, + RSI_BT_EVT_AVRCP_VOL_DOWN = 0x1308, + RSI_BT_EVT_AVRCP_GET_ELEM_RESP = 0x1309, + RSI_BT_EVT_AVRCP_NOTIFY = 0x130A, + + /* AVRCP target EVENT ID's */ + RSI_BT_EVT_AVRCP_GAT_CAPS = 0x1311, + RSI_BT_EVT_AVRCP_GET_APP_SUPP_ATTS = 0x1312, + RSI_BT_EVT_AVRCP_GET_APP_SUUP_ATT_VALS = 0x1313, + RSI_BT_EVT_AVRCP_GET_APP_CUR_ATT_VAL = 0x1314, + RSI_BT_EVT_AVRCP_SET_APP_CUR_ATT_VAL = 0x1315, + RSI_BT_EVT_AVRCP_GET_APP_ATT_TEXT = 0x1316, + RSI_BT_EVT_AVRCP_GET_APP_ATT_VAL_TEXT = 0x1317, + RSI_BT_EVT_AVRCP_INFORM_CHAR_SETS = 0x1318, + RSI_BT_EVT_AVRCP_INFORM_BATT_STATUS = 0x1319, + RSI_BT_EVT_AVRCP_GET_SONG_ATTS = 0x131A, + RSI_BT_EVT_AVRCP_GET_PLAY_STATUS = 0x131B, + RSI_BT_EVT_AVRCP_REG_NOTIFICATION = 0x131C, + RSI_BT_EVT_AVRCP_SET_ABS_VOL = 0x131D, + RSI_BT_EVT_AVRCP_SET_ADDR_PLAYER = 0x131E, + RSI_BT_EVT_AVRCP_GET_FOLDER_ITEMS = 0x131F, + RSI_BT_EVT_AVRCP_GET_TOT_NUM_ITEMS = 0x1320, + /*HFP profile Event ID's*/ + RSI_BT_EVT_HFP_CONN = 0x1400, + RSI_BT_EVT_HFP_DISCONN = 0x1401, + RSI_BT_EVT_HFP_RING = 0x1402, + RSI_BT_EVT_HFP_CALLCALLERID = 0x1403, + RSI_BT_EVT_HFP_AUDIOCONNECTED = 0x1404, + RSI_BT_EVT_HFP_AUDIODISCONNECTED = 0x1405, + RSI_BT_EVT_HFP_DIALCOMPLETE = 0x1406, + RSI_BT_EVT_HFP_ANSWERCOMPLETE = 0x1407, + RSI_BT_EVT_HFP_HANGUPCOMPLETE = 0x1408, + RSI_BT_EVT_HFP_SENDDTMFCOMPLETE = 0x1409, + RSI_BT_EVT_HFP_CALLWAIT = 0x140A, + RSI_BT_EVT_HFP_VOICERECOGDEACTIVATED = 0x140B, + RSI_BT_EVT_HFP_VOICERECOGACTIVATED = 0x140C, + RSI_BT_EVT_HFP_SERVICENOTFOUND = 0x140D, + RSI_BT_EVT_HFP_CALL_STATUS = 0x140E, + RSI_BT_EVT_HFP_SIGNALSTRENGTH = 0x140F, + RSI_BT_EVT_HFP_BATTERYLEVEL = 0x1410, + RSI_BT_EVT_HFP_PHONESERVICE = 0x1411, + RSI_BT_EVT_HFP_ROAMINGSTATUS = 0x1412, + RSI_BT_EVT_HFP_CALLSETUP = 0x1413, + RSI_BT_EVT_HFP_CALLHELDSTATUS = 0x1414, + RSI_BT_EVT_HFP_VOICE_DATA = 0x1415, + RSI_BT_EVT_HFP_AUDIO_CODECSELECT = 0x1416, + + /*PBAP profile Event ID's*/ + RSI_BT_EVT_PBAP_CONN = 0x1450, + RSI_BT_EVT_PBAP_DISCONN = 0x1451, + RSI_BT_EVT_PBAP_DATA = 0x1452, + + //HID profile events + RSI_BT_EVENT_HID_CONN = 0x1460, + RSI_BT_EVENT_HID_RXDATA = 0x1461, + + //L2CAP protocol events + RSI_BT_EVENT_L2CAP_CONN = 0x1480, + RSI_BT_EVENT_L2CAP_RXDATA = 0x1481, + RSI_BT_EVENT_IAP_CONN = 0x152E, + RSI_BT_EVENT_IAP_DISCONN = 0x152F, + RSI_BT_EVENT_IAP_ACC_AUTH_STARTED = 0x1530, + RSI_BT_EVENT_IAP_ACC_AUTH_FAILED = 0x1531, + RSI_BT_EVENT_IAP_ACC_AUTH_COMPLETE = 0x1532, + RSI_BT_EVENT_IAP2_AUTH_START = 0x1533, + RSI_BT_EVENT_IAP2_AUTH_COMPLETE = 0x1534, + RSI_BT_EVENT_IAP2_AUTH_FAILED = 0x1535, + RSI_BT_EVENT_IAP2_IDENTIFICATION_START = 0x1536, + RSI_BT_EVENT_IAP2_IDENTIFICATION_COMPLETE = 0x1537, + RSI_BT_EVENT_IAP2_IDENTIFICATION_REJECT = 0x1538, + RSI_BT_EVENT_IAP2_RX_DATA = 0x1539, + RSI_BT_EVENT_IAP2_RX_FILE_TRANSFER_STATE = 0x153A, + RSI_BT_EVENT_IAP2_RX_FILE_TRANSFER_DATA = 0x153B, + + RSI_BT_EVENT_PKT_CHANGE = 0x153E, + RSI_BT_DISABLED_EVENT = 0x153F +} rsi_bt_event_t; + +/****************************************************** + * * Structures + * ******************************************************/ + +//Set local COD name +typedef struct rsi_bt_req_set_local_cod_s { + uint32_t class_of_device; +} rsi_bt_req_set_local_cod_t; + +#define MAX_HOST_CONFIG_PARAMS_SIZE 50 +// Set Profile mode +typedef struct rsi_bt_req_profile_mode_s { + uint16_t profile_mode; + uint16_t data_len; + uint8_t data[MAX_HOST_CONFIG_PARAMS_SIZE]; +} rsi_bt_req_profile_mode_t; + +// Set Discovery mode +typedef struct rsi_bt_req_set_discv_mode_s { + uint8_t mode; + uint8_t reserved[3]; + int32_t time_out; +} rsi_bt_req_set_discv_mode_t; + +// Query Discovery mode response +typedef struct rsi_bt_resp_query_discv_mode_s { + uint8_t discovery_mode; +} rsi_bt_resp_query_discv_mode_t; + +// Set Connectability mode +typedef struct rsi_bt_req_set_connectability_mode { + uint8_t connectability_mode; +} rsi_bt_req_set_connectability_mode_t; + +// Query Connectability mode response +typedef struct rsi_bt_resp_query_connectability_mode_s { + uint8_t connectability_mode; +} rsi_bt_resp_query_connectability_mode_t; + +// Set pair mode +typedef struct rsi_bt_pair_mode_s { + uint8_t pair_mode; +} rsi_bt_req_set_pair_mode_t; + +// Query pair mode response +typedef struct rsi_bt_resp_query_pair_mode_s { + uint8_t pair_mode; +} rsi_bt_resp_query_pair_mode_t; + +// Remote Name Request +typedef struct rsi_bt_req_remote_name_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_remote_name_t; + +// Remote Name Request Cancel +typedef struct rsi_bt_req_remote_name_cancel_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_remote_name_cancel_t; + +// Inquiry command structure +typedef struct rsi_bt_req_inquiry_s { + uint8_t inquiry_type; + uint8_t lap[3]; + uint32_t duration; + uint8_t maximum_devices_to_find; + uint8_t reserved1[3]; +} rsi_bt_req_inquiry_t; + +// Connect command +typedef struct rsi_bt_req_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_connect_t; + +typedef struct rsi_bt_hid_profile_data_s { +#define MAX_PROFILE_DATA_BUFFER_LEN 1040 + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t channel_id; + uint8_t len[2]; + uint8_t buf[MAX_PROFILE_DATA_BUFFER_LEN]; +} rsi_bt_hid_profile_data_t; + +// Gatt Connect command +typedef struct rsi_bt_req_gatt_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_gatt_connect_t; + +// Connect cancel command +typedef struct rsi_bt_req_connect_cancel_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_connect_cancel_t; + +// Un-bond command +typedef struct rsi_bt_req_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_disconnect_t; + +// User confirmation command structure +typedef struct rsi_bt_req_user_confirmation_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + uint8_t confirmation; +} rsi_bt_req_user_confirmation_t; + +// Passkey request reply command structure +typedef struct rsi_bt_req_passkey_reply_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reply_type; + uint8_t reserved; + uint32_t pass_key; +} rsi_bt_req_passkey_reply_t; + +// Pincode request reply command structure +typedef struct rsi_bt_req_pincode_reply_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reply_type; + uint8_t reserved; + uint8_t pincode[RSI_MAX_PINCODE_REPLY_SIZE]; +} rsi_bt_req_pincode_reply_t; + +// Query Master-Slave role command +typedef struct rsi_bt_req_query_role_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_query_role_t; + +// Set Master-Slave role command +typedef struct rsi_bt_req_set_role_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t role; +} rsi_bt_req_set_role_t; + +// Master-Slave role response +typedef struct rsi_bt_resp_query_role_s { + uint8_t role; +} rsi_bt_resp_query_role_t; + +// Set AFH Host channel classification command +typedef struct rsi_bt_req_set_afh_host_channel_classification_s { + uint8_t channel_assessment_mode; + uint8_t enable; + uint8_t channel_classification[CHANNEL_MAP_LEN]; +} rsi_bt_req_set_afh_host_channel_classification_t; + +// Write Current IAP_LAP command +typedef struct rsi_bt_req_set_current_iap_lap_s { + uint8_t cnt; + uint8_t list[6]; // presently limiting the list to 2 iap_laps +} rsi_bt_req_set_current_iap_lap_t; + +// Search Service command structure +typedef struct rsi_bt_req_search_service_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + uint32_t service_uuid; +} rsi_bt_req_search_service_t; + +// SPP Connect command +typedef struct rsi_bt_req_spp_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_spp_connect_t; + +// SPP disconnect command +typedef struct rsi_bt_req_spp_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_spp_disconnect_t; + +// SPP transfer command stucture +typedef struct rsi_bt_req_spp_transfer_s { + uint16_t data_length; + uint8_t reserved[10]; // acl_hdr(4) + l2cap_hdr(4) + rfcomm_hdr(4) - 2 + uint8_t data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_req_spp_transfer_t; + +// Linkkey request reply command structure +typedef struct rsi_bt_req_linkkey_reply_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reply_type; + uint8_t reserved; + uint8_t linkkey[RSI_LINK_KEY_LEN]; +} rsi_bt_req_linkkey_reply_t; + +//Sniff Mode +typedef struct rsi_bt_req_sniff_mode_s { + uint8_t dev_addr[6]; + uint16_t sniff_max_intv; + uint16_t sniff_min_intv; + uint16_t sniff_attempt; + uint16_t sniff_tout; +} rsi_bt_req_sniff_mode_t; + +//Sniff Exit Mode +typedef struct rsi_bt_req_sniff_exit_mode_s { + uint8_t dev_addr[6]; +} rsi_bt_req_sniff_exit_mode_t; + +//Sniff Subrating Mode +typedef struct rsi_bt_req_sniff_subrating_mode_s { + uint8_t dev_addr[6]; + uint16_t max_latency; + uint16_t min_remote_tout; + uint16_t min_local_tout; +} rsi_bt_req_sniff_subrating_mode_t; + +//Set SSP Mode +typedef struct rsi_bt_req_set_ssp_mode_s { + uint8_t pair_mode; + uint8_t IO_capability; +} rsi_bt_req_set_ssp_mode_t; + +//Link Policy Config +typedef struct rsi_bt_cmd_link_policy_settings_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t link_policy_settings; +} rsi_bt_cmd_link_policy_settings_t; + +//Set EIR data +typedef struct rsi_bt_set_eir_data_s { + uint8_t fec_required; + uint8_t data_len; + uint8_t eir_data[200]; +} rsi_bt_set_eir_data_t; + +// Enable Authentication +typedef struct rsi_bt_cmd_conn_auth_s { + uint8_t dev_addr[6]; +} rsi_bt_cmd_conn_auth_t; + +typedef struct rsi_bt_cmd_conn_enc_s { + uint8_t dev_addr[6]; + uint8_t enable_or_disable; +} rsi_bt_cmd_conn_enc_t; + +typedef struct rsi_bt_cmd_delete_linkkeys_s { + uint8_t dev_addr[6]; + uint8_t delete_linkkeys; +} rsi_bt_cmd_delete_linkkeys_t; + +// LP HP chain change command +typedef struct rsi_bt_ptt_mode_s { + uint8_t mode; +} rsi_bt_ptt_mode_t; + +// packet type change command +typedef struct rsi_bt_ptt_pkt_type_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t pkt_type; +} rsi_bt_ptt_pkt_type_t; + +// L2CAP Connect command +typedef struct rsi_bt_req_l2cap_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t psm; + uint8_t preferred_mode; +} rsi_bt_req_l2cap_connect_t; + +// L2CAP disconnect command +typedef struct rsi_bt_req_l2cap_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_l2cap_disconnect_t; + +// L2CAP Protocol Data command stucture +typedef struct rsi_bt_req_l2cap_data_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved; + uint8_t frame_type; + uint8_t data_length[2]; + uint8_t data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_req_l2cap_data_t; + +typedef struct rsi_bt_l2cap_ertm_channel_s { + // If not mandatory, the use of ERTM can be decided by the remote + uint8_t ertm_mandatory; + + // Number of retransmissions that L2CAP is allowed to try before accepting that a packet and the channel is lost. + uint8_t max_transmit; + + // time before retransmission of i-frame / Recommended : 2000 ms (ACL Flush timeout not used) + uint16_t retransmission_timeout_ms; + + // time after withc s-frames are sent / Recommended: 12000 ms (ACL Flush timeout not used) + uint16_t monitor_timeout_ms; + + // MTU for incoming SDUs + uint16_t local_mtu; + + // Number of buffers for outgoing data + uint8_t num_tx_buffers; + + // Number of packets that can be received out of order (-> our tx_window size) + uint8_t num_rx_buffers; + + // Frame Check Sequence (FCS) Option + uint8_t fcs_option; + +} rsi_bt_l2cap_ertm_channel_t; +typedef struct rsi_bt_req_iap_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t version; +} rsi_bt_req_iap_connect_t; + +typedef struct rsi_bt_req_iap_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t version; +} rsi_bt_req_iap_disconnect_t; + +typedef struct rsi_bt_req_iap_accessory_info_s { + uint8_t info_type; + uint8_t info_len; + uint8_t info_data[RSI_BT_MAX_ACCESSORY_INFO_LEN]; +} rsi_bt_req_iap_accessory_info_t; + +typedef struct rsi_bt_req_iap_set_voice_over_s { + uint8_t mode; + uint8_t restore; +} rsi_bt_req_iap_set_voice_over_t; +typedef struct rsi_bt_req_iap_set_proto_s { + uint8_t type; +} rsi_bt_req_iap_set_proto_t; + +// HFP Connect command +typedef struct rsi_bt_req_hfp_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_connect_t; + +// HFP disconnect command +typedef struct rsi_bt_req_hfp_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_disconnect_t; + +// HFP phone operator command +typedef struct rsi_bt_req_hfp_phoneoperator_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_phoneoperator_t; + +// HFP call reject command +typedef struct rsi_bt_req_hfp_callreject_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_callreject_t; + +// HFP dial num command +typedef struct rsi_bt_req_hfp_dialnum_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t phone_no[10]; +} rsi_bt_req_hfp_dialnum_t; + +// HFP dial mem command +typedef struct rsi_bt_req_hfp_dialmem_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint32_t mem_ix; +} rsi_bt_req_hfp_dialmem_t; + +// HFP voice recognition active command +typedef struct rsi_bt_req_hfp_voicerecognitionactive_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_voicerecognitionactive_t; + +// HFP voice recognition deactive command +typedef struct rsi_bt_req_hfp_voicerecognitiondeactive_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_voicerecognitiondeactive_t; + +// HFP profile command +typedef struct rsi_bt_req_hfp_micgain_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t mic_gain; +} rsi_bt_req_hfp_micgain_t; + +// HFP profile command +typedef struct rsi_bt_req_hfp_spkgain_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t spk_gain; +} rsi_bt_req_hfp_spkgain_t; + +// HFP profile command +typedef struct rsi_bt_req_hfp_getcalls_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_hfp_getcalls_t; + +typedef struct rsi_bt_req_hfp_audiotransfer_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t audio_trans_state; +} rsi_bt_req_hfp_audiotransfer_t; + +// HFP profile command +typedef struct rsi_bt_req_hfp_audio_s { + uint16_t conn_handle; + uint8_t len; + uint8_t encoded_data[60]; +} rsi_bt_req_hfp_audio_t; + +// PBAP Connect command +typedef struct rsi_bt_req_pbap_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_pbap_connect_t; + +// PBAP disconnect command +typedef struct rsi_bt_req_pbap_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_pbap_disconnect_t; +// PBAP contacts command +typedef struct rsi_bt_req_pbap_contacts_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t folder_id; + uint8_t nbr_contacts; + uint16_t start_ix; +} rsi_bt_req_pbap_contacts_t; + +typedef struct rsi_bt_req_add_device_id_s { + uint16_t spec_id; + uint16_t vendor_id; + uint16_t product_id; + uint16_t version; + int primary_rec; + uint16_t vendor_id_source; +} rsi_bt_req_add_device_id_t; + +// avdtp stats command structure +typedef struct rsi_bt_vendor_avdtp_stats_s { + uint8_t opcode[2]; + uint16_t avdtp_stats_enable; + uint32_t avdtp_stats_rate; +} rsi_bt_vendor_avdtp_stats_t; + +// memory stats command structure +typedef struct rsi_bt_vendor_memory_stats_s { + uint8_t opcode[2]; + uint8_t protocol; + uint8_t memory_stats_enable; + uint32_t memory_stats_interval_ms; +} rsi_bt_vendor_memory_stats_t; + +#define STATE_2M_CONTINUOUS_PASS_THRESHOLD 20 +#define STATE_2M_PASS_THRESHOLD 70 +#define STATE_3M_ABSOLUTE_FAIL_THRESHOLD 25 +#define STATE_3M_CONTINUOUS_FAIL_THRESHOLD 5 +#define STATE_3M_RELATIVE_FAIL_THRESHOLD 20 +//! AR command structure +typedef struct rsi_bt_vendor_ar_cmd_s { + uint8_t opcode[2]; + uint16_t ar_enable; + uint16_t _3m_state_continuous_fail_threshold; + uint16_t _3m_state_absolute_fail_threshold; + uint16_t _3m_state_relative_fail_threshold; + uint16_t _2m_state_pass_threshold; + uint16_t _2m_state_continuous_pass_threshold; +} rsi_bt_vendor_ar_cmd_t; + +typedef struct dynamic_pwr_index_s { + uint8_t dynamic_power_enable; + uint8_t pwr_index_br; + uint8_t pwr_index_2m; + uint8_t pwr_index_3m; +} dynamic_pwr_index_t; + +typedef struct rsi_bt_vendor_afh_classification_cmd_s { + uint8_t opcode[2]; + uint16_t afh_min; + uint16_t afh_max; +} rsi_bt_vendor_afh_classification_cmd_t; + +typedef struct set_dynamic_pwr_index_s { + uint8_t remote_dev[RSI_DEV_ADDR_LEN]; + uint16_t reserved; + dynamic_pwr_index_t dynamic_pwr_index; +} set_dynamic_pwr_index_t; + +// Dynamic tx_power_command +typedef struct rsi_bt_vendor_dynamic_pwr_cmd_s { + uint8_t opcode[2]; + uint16_t reserved; + set_dynamic_pwr_index_t set_dynamic_pwr_index; +} rsi_bt_vendor_dynamic_pwr_cmd_t; +// Driver BT Classic control block +struct rsi_bt_classic_cb_s { + // GAP Callbacks + rsi_bt_on_role_change_t bt_on_role_change_status_event; + rsi_bt_on_connect_t bt_on_conn_status_event; + rsi_bt_on_unbond_t bt_on_unbond_status; + rsi_bt_on_disconnect_t bt_on_disconnect_event; + rsi_bt_on_scan_resp_t bt_on_scan_resp_event; + rsi_bt_on_remote_name_resp_t bt_on_remote_name_resp_event; + rsi_bt_on_passkey_display_t bt_on_passkey_display_event; + rsi_bt_on_remote_name_request_cancel_t bt_on_remote_name_request_cancel_event; + rsi_bt_on_confirm_request_t bt_on_confirm_request_event; + rsi_bt_on_pincode_request_t bt_on_pincode_request_event; + rsi_bt_on_passkey_request_t bt_on_passkey_request_event; + rsi_bt_on_inquiry_complete_t bt_on_inquiry_complete_event; + rsi_bt_on_auth_complete_t bt_on_auth_complete_event; + rsi_bt_on_linkkey_request_t bt_on_linkkey_request_event; + rsi_bt_on_ssp_complete_t bt_on_ssp_complete_event; + rsi_bt_on_linkkey_save_t bt_on_linkkey_save_event; + rsi_bt_on_get_services_t bt_on_get_services_event; + rsi_bt_on_search_service_t bt_on_search_service_event; + rsi_bt_on_mode_chnage_t bt_on_mode_change_event; + rsi_bt_on_sniff_subrating_t bt_on_sniff_subrating_event; + rsi_bt_on_connection_initiated_t bt_on_connection_initiated; + + // BT GATT Callbacks + rsi_bt_on_gatt_connection_t bt_on_gatt_connection_event; + rsi_bt_on_gatt_disconnection_t bt_on_gatt_disconnection_event; + + // SPP Callbacks + rsi_bt_on_spp_connect_t bt_on_spp_connect_event; + rsi_bt_on_spp_disconnect_t bt_on_spp_disconnect_event; + rsi_bt_on_spp_rx_data_t bt_on_spp_rx_data_event; + + // A2DP Callbacks + rsi_bt_on_a2dp_connect_t bt_on_a2dp_connect_event; + rsi_bt_on_a2dp_disconnect_t bt_on_a2dp_disconnect_event; + rsi_bt_on_a2dp_configure_t bt_on_a2dp_configure_event; + rsi_bt_on_a2dp_open_t bt_on_a2dp_open_event; + rsi_bt_on_a2dp_start_t bt_on_a2dp_start_event; + rsi_bt_on_a2dp_suspend_t bt_on_a2dp_suspend_event; + rsi_bt_on_a2dp_abort_t bt_on_a2dp_abort_event; + rsi_bt_on_a2dp_close_t bt_on_a2dp_close_event; + rsi_bt_on_a2dp_encode_data_t bt_on_a2dp_encode_data_event; + rsi_bt_on_a2dp_pcm_data_t bt_on_a2dp_pcm_data_event; + rsi_bt_on_a2dp_data_req_t bt_on_a2dp_data_req_event; + rsi_bt_on_a2dp_reconfig_t bt_on_a2dp_reconfig_event; + //AVRCP Callbacks + rsi_bt_on_avrcp_connect_t bt_on_avrcp_connect_event; + rsi_bt_on_avrcp_disconnect_t bt_on_avrcp_disconnect_event; + rsi_bt_on_avrcp_play_t bt_on_avrcp_play_event; + rsi_bt_on_avrcp_pause_t bt_on_avrcp_pause_event; + rsi_bt_on_avrcp_stop_t bt_on_avrcp_stop_event; + rsi_bt_on_avrcp_next_t bt_on_avrcp_next_event; + rsi_bt_on_avrcp_previous_t bt_on_avrcp_previous_event; + rsi_bt_on_avrcp_vol_up_t bt_on_avrcp_vol_up_event; + rsi_bt_on_avrcp_vol_down_t bt_on_avrcp_vol_down_event; + rsi_bt_on_avrcp_get_elem_attr_resp_t bt_on_avrcp_get_elem_attr_resp_event; + rsi_bt_on_avrcp_notify_event_t bt_on_avrcp_notify_event; + + // AVRCP target Callbacks + rsi_bt_on_avrcp_get_cap_event_t bt_on_avrcp_gat_cap; + rsi_bt_on_avrcp_get_app_supp_atts_event_t bt_on_avrcp_get_app_att_list; + rsi_bt_on_avrcp_get_app_suup_att_vals_event_t bt_on_avrcp_get_app_att_vals_list; + rsi_bt_on_avrcp_get_app_cur_att_val_event_t bt_on_avrcp_get_app_cur_att_val; + rsi_bt_on_avrcp_set_app_cur_att_val_event_t bt_on_avrcp_set_app_cur_att_val; + rsi_bt_on_avrcp_get_app_att_text_event_t bt_on_avrcp_get_app_att_text; + rsi_bt_on_avrcp_get_app_att_vals_text_event_t bt_on_avrcp_get_app_att_vals_text; + rsi_bt_on_avrcp_supp_char_sets_event_t bt_on_avrcp_supp_char_sets; + rsi_bt_on_avrcp_batt_status_event_t bt_on_avrcp_batt_status; + rsi_bt_on_avrcp_get_song_atts_event_t bt_on_avrcp_get_song_atts; + rsi_bt_on_avrcp_get_play_status_event_t bt_on_avrcp_get_player_status; + rsi_bt_on_avrcp_reg_notify_event_t bt_on_avrcp_reg_notifivation; + rsi_bt_on_avrcp_set_abs_vol_event_t bt_on_avrcp_set_abs_vol; + rsi_bt_on_avrcp_set_addr_player_event_t bt_on_avrcp_set_addr_player; + rsi_bt_on_avrcp_get_folder_items_event_t bt_on_avrcp_get_folder_items; + rsi_bt_on_avrcp_get_tot_num_items_event_t bt_on_avrcp_get_tot_num_items; + //HFP call backs + rsi_bt_on_hfp_connect_t bt_on_hfp_connect_event; + rsi_bt_on_hfp_disconnect_t bt_on_hfp_disconnect_event; + rsi_bt_on_hfp_ring_t bt_on_hfp_ring_event; + rsi_bt_on_hfp_callcallerid_t bt_on_hfp_callcallerid_event; + rsi_bt_on_hfp_audioconnected_t bt_on_hfp_audioconnected_event; + rsi_bt_on_hfp_audiodisconnected_t bt_on_hfp_audiodisconnected_event; + rsi_bt_on_hfp_dialcomplete_t bt_on_hfp_dialcomplete_event; + rsi_bt_on_hfp_answercomplete_t bt_on_hfp_answercomplete_event; + rsi_bt_on_hfp_hangupcomplete_t bt_on_hfp_hangupcomplete_event; + rsi_bt_on_hfp_senddtmfcomplete_t bt_on_hfp_senddtmfcomplete_event; + rsi_bt_on_hfp_callwait_t bt_on_hfp_callwait_event; + rsi_bt_on_hfp_callvoicerecogdeactivated_t bt_on_hfp_callvoicerecogdeactivated_event; + rsi_bt_on_hfp_callvoicerecogactivated_t bt_on_hfp_callvoicerecogactivated_event; + rsi_bt_on_hfp_servicenotfound_t bt_on_hfp_servicenotfound_event; + rsi_bt_app_on_hfp_callstatus_t bt_on_hfp_callstatus_event; + rsi_bt_app_on_hfp_signalstrength_t bt_on_hfp_signalstrength_event; + rsi_bt_app_on_hfp_batterylevel_t bt_on_hfp_batterylevel_event; + rsi_bt_app_on_hfp_phoneservice_t bt_on_hfp_phoneservice_event; + rsi_bt_app_on_hfp_roamingstatus_t bt_on_hfp_roamingstatus_event; + rsi_bt_app_on_hfp_callsetup_t bt_on_hfp_callsetup_event; + rsi_bt_app_on_hfp_callheld_t bt_on_hfp_callheld_event; + rsi_bt_app_on_hfp_voice_data_t bt_on_hfp_voice_data_event; + rsi_bt_app_on_hfp_audio_codecselect_t bt_on_hfp_audio_codecselect_event; + + //PBAP call backs + rsi_bt_on_pbap_connect_t bt_on_pbap_connect_event; + rsi_bt_on_pbap_disconnect_t bt_on_pbap_disconnect_event; + rsi_bt_on_pbap_data_t bt_on_pbap_data_event; + + /* AVDTP STATS Callbacks */ + rsi_bt_on_avdtp_stats_t bt_on_avdtp_stats_event; + // HID Callbacks + rsi_bt_on_hid_connect_t bt_on_hid_connect_event; + rsi_bt_on_hid_rx_data_t bt_on_hid_rx_data_event; + rsi_bt_on_hid_handshake_t bt_on_hid_handshake_event; + rsi_bt_on_hid_control_t bt_on_hid_control_event; + rsi_bt_on_hid_get_report_t bt_on_hid_get_report; + rsi_bt_on_hid_set_report_t bt_on_hid_set_report; + rsi_bt_on_hid_get_protocol_t bt_on_hid_get_proto; + rsi_bt_on_hid_set_protocol_t bt_on_hid_set_proto; + rsi_bt_on_l2cap_connect_t bt_on_l2cap_connect_event; + rsi_bt_on_l2cap_rx_data_t bt_on_l2cap_rx_data_event; + + /* CHIP Memory Stats */ + rsi_bt_on_chip_memory_stats_handler_t bt_on_chip_memory_stats_event; + rsi_bt_pkt_change_stats_t bt_pkt_change_stats_event; + + rsi_bt_app_iap_conn_t bt_app_iap_conn; + rsi_bt_app_iap_disconn_t bt_app_iap_disconn; + rsi_bt_app_iap_acc_auth_strt_t bt_app_iap_acc_auth_strt; + rsi_bt_app_iap_acc_auth_fail_t bt_app_iap_acc_auth_fail; + rsi_bt_app_iap_acc_auth_complete_t bt_app_iap_acc_auth_complete; + rsi_bt_app_iap2_auth_start_t bt_app_iap2_auth_start; + rsi_bt_app_iap2_auth_complete_t bt_app_iap2_auth_complete; + rsi_bt_app_iap2_auth_fail_t bt_app_iap2_auth_fail; + rsi_bt_app_iap2_identification_start_t bt_app_iap2_identification_start; + rsi_bt_app_iap2_identification_complete_t bt_app_iap2_identification_complete; + rsi_bt_app_iap2_identification_reject_t bt_app_iap2_identification_reject; + rsi_bt_app_on_iap2_data_rx_t bt_app_on_iap2_data_rx; + rsi_bt_app_iap2_File_Tx_state_t bt_app_iap2_File_Tx_state; + rsi_bt_app_iap2_File_Transfer_rx_data_t bt_app_iap2_File_Transfer_rx_data; + /* AR STATS Callbacks */ + rsi_bt_on_ar_stats_t bt_on_ar_stats_event; +}; + +/****************************************************** + * * BT Classic internal function declarations + * ******************************************************/ +void rsi_bt_callbacks_handler(rsi_bt_cb_t *bt_cb, uint16_t rsp_type, uint8_t *payload, uint16_t payload_length); + +#endif diff --git a/wiseconnect/sapi/include/rsi_bt_apis.h b/wiseconnect/sapi/include/rsi_bt_apis.h new file mode 100644 index 00000000..357ec80c --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt_apis.h @@ -0,0 +1,3735 @@ +/******************************************************************************* +* @file rsi_bt_apis.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/************************************************************************* + * + */ + +#ifndef RSI_BT_APIS_H +#define RSI_BT_APIS_H + +#include +#include +#include +#ifdef RSI_BT_ENABLE +#include +#else +#include +#endif +#include + +/****************************************************** + * * Macros + * ******************************************************/ +#define RSI_LINK_KEY_LEN 16 + +#define RSI_BUTTON_PUSHED 0x0 +#define RSI_BUTTON_RELEASED 0x1 +/****************************************************** + * * Constants + * ******************************************************/ + +/****************************************************** + * * Enumerations + * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +//BT Classic GAP Command structures + +typedef struct rsi_bt_req_query_services_s { + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_query_services_t; + +//BT Classic GAP Response structures + +typedef struct rsi_bt_resp_query_services_s { + /** Number of Services Supported by Remote Device*/ + uint8_t num_of_services; + + /** Reserved For Future Use*/ + uint8_t reserved[3]; + + /** List Of Services with 32 bit UUID*/ + uint32_t uuid[32]; +} rsi_bt_resp_query_services_t; + +typedef struct rsi_bt_resp_search_service_s { + uint8_t service_status; +} rsi_bt_resp_search_service_t; + +//BT Classic GAP Event structures + +typedef struct rsi_bt_event_role_change_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Currenty role of the local device */ + uint8_t role; +} rsi_bt_event_role_change_t; + +typedef struct rsi_bt_event_unbond_s { + + /** rsi_bt_event_unbond_s */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_unbond_t; + +typedef struct rsi_bt_event_bond_response_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_bond_t; + +typedef struct rsi_bt_event_inquiry_response_s { + + /** Inquiry scan type */ + uint8_t inquiry_type; + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Name length of the remote device */ + uint8_t name_length; + + /** Name of remote device with max length of 50 bytes */ + uint8_t remote_device_name[RSI_DEV_NAME_LEN]; + + /** Class of Device */ + uint8_t cod[3]; + + /** RSSI of the remote device */ + int8_t rssi; +} rsi_bt_event_inquiry_response_t; + +typedef struct rsi_bt_event_remote_device_name_s { + /** Remote Device BD Address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Length Of the Remote Device Name*/ + uint8_t name_length; + + /** Name of the Remote Device*/ + uint8_t remote_device_name[RSI_DEV_NAME_LEN]; +} rsi_bt_event_remote_device_name_t; + +typedef struct rsi_bt_event_remote_name_request_cancel_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_remote_name_request_cancel_t; + +typedef struct rsi_bt_event_connection_initiated_s { + + /** if the value is 1 implies connection initiated by remote device */ + uint8_t conn_initiated; +} rsi_bt_event_connection_initiated_t; + +typedef struct rsi_bt_event_disconnect_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_disconnect_t; + +typedef struct rsi_bt_event_user_confirmation_request_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Reserved field for future use */ + uint8_t reserved[2]; + + /** This is the passkey to be confirmed */ + uint8_t confirmation_value[4]; +} rsi_bt_event_user_confirmation_request_t; + +typedef struct rsi_bt_event_user_passkey_display_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Reserved field for future use */ + uint8_t reserved[2]; + + /** Passkey value */ + uint8_t passkey[4]; +} rsi_bt_event_user_passkey_display_t; + +typedef struct rsi_bt_event_user_passkey_notify_s { + uint8_t dev_addr[6]; + uint8_t reserved[2]; + uint8_t passkey[4]; +} rsi_bt_event_user_passkey_notify_t; + +typedef struct rsi_bt_event_user_pincode_request_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_user_pincode_request_t; + +typedef struct rsi_bt_event_user_passkey_request_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_user_passkey_request_t; + +typedef struct rsi_bt_event_auth_complete_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_auth_complete_t; + +typedef struct rsi_bt_event_user_linkkey_request_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_user_linkkey_request_t; + +typedef struct rsi_bt_event_user_linkkey_save_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Link Key to be saved */ + uint8_t linkKey[RSI_LINK_KEY_LEN]; + + /** local device address */ + uint8_t local_dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_user_linkkey_save_t; + +typedef struct rsi_bt_event_spp_receive_s { + + /** Length of the data received */ + uint16_t data_len; + + /** Buffer holding the received SPP data. It holds the max payload length of 1k bytes */ + uint8_t data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_event_spp_receive_t; + +typedef struct rsi_bt_event_spp_connect_s { + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** MTU size supported by the remote device */ + uint16_t tx_mtu_size; + uint16_t rx_mtu_size; + +} rsi_bt_event_spp_connect_t; + +typedef struct rsi_bt_event_spp_disconnect_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_spp_disconnect_t; + +typedef struct rsi_bt_event_l2cap_data_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t data_len[2]; + uint8_t data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_event_l2cap_data_t; +typedef struct rsi_bt_event_l2cap_connect_s { +#define BT_L2CAP_CONNECTED 1 +#define BT_L2CAP_DISCONNECTED 0 + uint8_t conn_status; + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reason_code[2]; + uint8_t rem_mtu_size[2]; +} rsi_bt_event_l2cap_connect_t; + +typedef struct rsi_bt_event_l2cap_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_l2cap_disconnect_t; + +typedef struct rsi_bt_event_hid_receive_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t hid_channel; + uint8_t data_len[2]; + uint8_t data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_event_hid_receive_t; + +typedef struct rsi_bt_event_hid_connect_s { +#define BT_HID_CONNECTED 1 +#define BT_HID_DISCONNECTED 0 + uint8_t conn_status; + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reason_code[2]; + uint8_t rem_mtu_size[2]; +} rsi_bt_event_hid_connect_t; + +typedef struct rsi_bt_event_hid_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hid_disconnect_t; + +typedef struct rsi_bt_event_mode_change_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Indicates the current state of connection between the local device and the remote device i.e., Active mode / Hold mode/ Sniff mode \n + 0 ? Active Mode \n + 1 ? Hold Mode \n + 2 ? Sniff Mode */ + uint8_t current_mode; + + /** Reserved field for future use */ + uint8_t reserved; + + /** This specifies the time interval to each mode */ + uint16_t mode_interval; +} rsi_bt_event_mode_change_t; + +typedef struct rsi_bt_event_sniff_subrating_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Maximum latency for data being transmitted from the local device to the remote device */ + uint16_t max_tx_latency; + + /** Base sniff subrate timeout in baseband slots that the remote device use */ + uint16_t min_remote_timeout; + + /** Base sniff subrate timeout in baseband slots that the local device use */ + uint16_t min_local_timeout; +} rsi_bt_event_sniff_subrating_t; + +typedef struct rsi_bt_event_gatt_connect_s { + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_gatt_connect_t; + +typedef struct rsi_bt_event_gatt_disconnect_s { + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_gatt_disconnect_t; + +typedef struct rsi_bt_event_ssp_complete_s { + + /** remote device address */ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** This is the SSP mode connection status with remote device */ + uint8_t status; +} rsi_bt_event_ssp_complete_t; + +//PER structure paramters +typedef struct rsi_bt_tx_per_params_s { + /** Command ID parameter is set to BT_TRANSMIT_CMD_ID of value 0x15 */ + uint8_t cmd_id; + /** enables/disables the bt per transmit mode \n + 1 ? PER transmit Enable \n + 0 ? PER transmit Disable */ + uint8_t transmit_enable; + /** Device BD address from which packets to be transmitted */ + uint8_t device_Addr[6]; + /** Length of the packet to be transmitted */ + uint8_t pkt_len[2]; + /** Packet types proposed by BT_SIG. Value takes from 0 to 15 */ + uint8_t pkt_type; + /** Field corresponds to BR/EDR Mode \n + 1 ? BR_MODE \n + 2 ? EDR_MODE */ + uint8_t br_edr_mode; + /** Field corresponds to rx channel number to be used (0 to 78) */ + uint8_t rx_chnl_in; + /** Field corresponds to tx channel number to be used (0 to 78) */ + uint8_t tx_chnl_in; + /** field corresponds to link type to be setup for transmitting per packets \n + 0 ? SCO_LINK \n + 1 ? ACL_LINK \n + 2 ? ESCO_LINK */ + uint8_t link_type; + /** Initial seed to be used for whitening. It should be set to �0� in order to disable whitening. \n + In order to enable, one should give the scrambler seed value which is used on the receive side */ + uint8_t scrambler_seed; + /** Defines the frequency hopping type to be used \n + 0 ? NO_HOPPING \n + 1 ? FIXED_HOPPING \n + 2 ? RANDOM_HOPPING (rx_chnl_in, tx_chnl_in parameters are unused in this mode) */ + uint8_t hopping_type; + /** Field defines the antenna selection (onboard/external) to be used for transmission \n + 2 ? ONBOARD_ANT_SEL \n + 3 ? EXT_ANT_SEL */ + uint8_t ant_sel; + /** Field defines the pll_mode type to be used \n + 0 ? PLL_MODE0 (to be used by Default) \n + 1 ? PLL_MODE1 */ + uint8_t pll_mode; + /** Field defines the selection of RF type (internal/external) \n + 0 ? BT_EXTERNAL_RF \n + 1 ? BT_INTERNAL_RF (to be used by Default) */ + uint8_t rf_type; + /** Field corresponds to the selection of RF chain (HP/LP) to be used \n + 2 ? BT_HP_CHAIN \n + 3 ? BT_LP_CHAIN (Only for BR_MODE) */ + uint8_t rf_chain; + /**Field corresponds to the payload sequence of data to be transmitted. The default payload type is '4'. \n + 0 ? SEQUENCE_0 \n + 1 ? SEQUENCE_1 \n + 2 ? SEQUENCE_2 \n + 3 ? SEQUENCE_F0 \n + 4 ? SEQUENCE_PRBS */ + uint8_t payload_type; + /** Field corresponds to the transmit power. Range is different based on rf_chain \n + BT_LP_CHAIN - 1 - 31 power index - 0 dBm Mode \n + 33 - 63 power index - 8 dBm Mode \n + Following are the equations to be used for deriving power output in dBm \n + (0 - 31) o/p power equation is -2 + 10log10(power_index/31) \n + (32-63) o/p power equation is -2 + 8+10log10((power_index -32)/31) \n \n + BT_HP_CHAIN - 1 to 22 dBm (based on Country Regulations and Chip capability Max dBm varies. Configure 127 to select Max permitted value) */ + uint8_t tx_power; + /** field corresponds to the transmit mode to be used either Burst/Continuous \n + 0 ? BURST_MODE (BT stats are observed only in this mode) \n + 1 ? CONTINUOUS_MODE (no_of_packets variable is unused when this mode is selected) \n + 2 ? CONTINUOUS_WAVE_MODE (For CW_MODE) */ + uint8_t transmit_mode; + /** This field takes the value of inter packet gap. \n + Number of slots to be skipped between two packets. Each slot will be 625usec */ + uint8_t inter_pkt_gap; + /** This field defines the number of packets to be transmitted, default to zero for continuous transmission */ + uint8_t no_of_packets[4]; +} rsi_bt_tx_per_params_t; + +//PER structure paramters +typedef struct rsi_bt_rx_per_params_s { + /** Command ID parameter is set to BT_RECEIVE_CMD_ID of value 0x16 */ + uint8_t cmd_id; + /** enables/disables the bt per receive mode \n + 1 ? PER Receive Enable \n + 0 ? PER Receive Disable */ + uint8_t receive_enable; + /** Device BD address from which packets to be received */ + uint8_t device_Addr[6]; + /** Length of the packet to be received */ + uint8_t pkt_len[2]; + /** Packet types proposed by BT_SIG. Value takes from 0 to 15 */ + uint8_t pkt_type; + /** Field corresponds to BR/EDR Mode \n + 1 ? BR_MODE \n + 2 ? EDR_MODE */ + uint8_t br_edr_mode; + /** Field corresponds to rx channel number to be used for receive (0 to 78) */ + uint8_t rx_chnl_in; + /** Field corresponds to tx channel number to be used (0 to 78) */ + uint8_t tx_chnl_in; + /** field corresponds to link type to be setup for receiving per packets \n + 0 ? SCO_LINK \n + 1 ? ACL_LINK \n + 2 ? ESCO_LINK */ + uint8_t link_type; + /** Initial seed to be used for whitening. It should be set to �0� in order to disable whitening. \n + In order to enable, one should give the scrambler seed value which is used on the transmit side */ + uint8_t scrambler_seed; + /** Defines the frequency hopping type to be used \n + 0 ? NO_HOPPING \n + 1 ? FIXED_HOPPING \n + 2 ? RANDOM_HOPPING (rx_chnl_in, tx_chnl_in parameters are unused in this mode) */ + uint8_t hopping_type; + /** Field defines the antenna selection (onboard/external) to be used for reception \n + 2 ? ONBOARD_ANT_SEL \n + 3 ? EXT_ANT_SEL */ + uint8_t ant_sel; + /** Field defines the pll_mode type to be used \n + 0 ? PLL_MODE0 (to be used by Default) \n + 1 ? PLL_MODE1 */ + uint8_t pll_mode; + /** Field defines the selection of RF type (internal/external) \n + 0 ? BT_EXTERNAL_RF \n + 1 ? BT_INTERNAL_RF (to be used by Default) */ + uint8_t rf_type; + /** Field corresponds to the selection of RF chain (HP/LP) to be used \n + 2 ? BT_HP_CHAIN \n + 3 ? BT_LP_CHAIN (Only for BR_MODE) */ + uint8_t rf_chain; + /** Field defines the loopback to be enable or disable \n + 0 ? LOOP_BACK_MODE_DISABLE \n + 1 ? LOOP_BACK_MODE_ENABLE */ + uint8_t loop_back_mode; +} rsi_bt_rx_per_params_t; + +typedef struct rsi_bt_event_avdtp_stats_s { + + /** LMAC timer BT Clock*/ + uint32_t clock; + /* BDR stats */ + + /** Num of TXed POLLS*/ + uint16_t tx_poll; + + /** Num of TXed NULLS*/ + uint16_t tx_null; + + /** Num of RXed POLLS*/ + uint16_t rx_poll; + + /** Num of RXed NULLS*/ + uint16_t rx_null; + + /** dm1_pkt[0] - Num of TXed dm1 Pkts \n + dm1_pkt[1] - Num of RXed dm1 Pkts*/ + uint16_t dm1_pkt[2]; + + /** dm3_pkt[0] - Num of TXed dm3 Pkts \n + dm3_pkt[1] - Num of RXed dm3 Pkts*/ + uint16_t dm3_pkt[2]; + + /** dm5_pkt[0] - Num of TXed dm5 Pkts \n + dm5_pkt[1] - Num of RXed dm5 Pkts*/ + uint16_t dm5_pkt[2]; + + /** dh1_pkt[0] - Num of TXed dh1 Pkts \n + dh1_pkt[1] - Num of RXed dh1 Pkts*/ + uint16_t dh1_pkt[2]; + + /** dh3_pkt[0] - Num of TXed dh3 Pkts \n + dh3_pkt[1] - Num of RXed dh3 Pkts*/ + uint16_t dh3_pkt[2]; + + /** dh5_pkt[0] - Num of TXed dh5 Pkts \n + dh5_pkt[1] - Num of RXed dh5 Pkts*/ + uint16_t dh5_pkt[2]; + + /* EDR stats */ + /** 2dh1_pkt[0] - Num of TXed 2dh1 Pkts \n + 2dh1_pkt[1] - Num of RXed 2dh1 Pkts*/ + uint16_t edr_2dh1_pkt[2]; + + /** 2dh3_pkt[0] - Num of TXed 2dh3 Pkts \n + 2dh3_pkt[1] - Num of RXed 2dh3 Pkts*/ + uint16_t edr_2dh3_pkt[2]; + + /** 2dh5_pkt[0] - Num of TXed 2dh5 Pkts \n + 2dh5_pkt[1] - Num of RXed 2dh5 Pkts*/ + uint16_t edr_2dh5_pkt[2]; + + /** 3dh1_pkt[0] - Num of TXed 3dh1 Pkts \n + 3dh1_pkt[1] - Num of RXed 3dh1 Pkts*/ + uint16_t edr_3dh1_pkt[2]; + + /** 3dh3_pkt[0] - Num of TXed 3dh3 Pkts \n + 3dh3_pkt[1] - Num of RXed 3dh3 Pkts*/ + uint16_t edr_3dh3_pkt[2]; + + /** 3dh5_pkt[0] - Num of TXed 3dh5 Pkts \n + 3dh5_pkt[1] - Num of RXed 3dh5 Pkts*/ + uint16_t edr_3dh5_pkt[2]; + /* Packet stats overall */ + + /** Num of CRC Failed Packets*/ + uint16_t no_of_crc_fail; + + /** Num of Retransmission Packets*/ + uint16_t no_of_retries; + + /** Num of Header Error Packets*/ + uint16_t no_of_hdr_err; + + /** Num of Duplicate Packets Received \n + (If previous sequence number is received again)*/ + uint16_t no_of_seq_repeat; + + /** Num of ack packets received with delay of 10ms to 100ms and more that 100ms \n + 10 - ack_delay[10] ......... >100 - ack_delay[10]*/ + uint16_t ack_delay[11]; + + /** Num of ACK packets Received*/ + uint16_t ack_received; + + /** Num of NAK packets Received*/ + uint16_t nak_received; + + /** Num of missed response packets in the RX Slot*/ + uint16_t no_of_rx_missed; + + /** Num of RXed error packets in the RX Slot*/ + uint16_t no_of_rx_error; + + /** Num of TX Attempts*/ + uint16_t tx_attempts; + + /** Number of Packets TXed on Air*/ + uint16_t tx_done; +} rsi_bt_event_avdtp_stats_t; + +#define _3M_STATE_CONTINUOUS_FAIL_THRESHOLD_REACHED 1 +#define _3M_STATE_PER_THRESHOLD_REACHED 2 +#define _2M_STATE_PASS_THRESHOLD_REACHED 3 +#define _2M_STATE_CONTINUOUS_PASS_THRESHOLD_REACHED 4 +#define _BT_AR_STATS_PERIODIC 5 + +typedef struct rsi_bt_event_ar_stats_s { + + /** 3m TX Fail Count*/ + uint32_t fail_count_3m; + + /** 2m TX Fail Count*/ + uint32_t fail_count_2m; + + /** 3m TX Pass Count*/ + uint32_t pass_count_3m; + + /** 2m TX Pass Count*/ + uint32_t pass_count_2m; + + /**#define _3M_STATE_CONTINUOUS_FAIL_THRESHOLD_REACHED 1 \n + #define _3M_STATE_PER_THRESHOLD_REACHED 2 \n + #define _2M_STATE_PASS_THRESHOLD_REACHED 3 \n + #define _2M_STATE_CONTINUOUS_PASS_THRESHOLD_REACHED 4 \n + #define _BT_AR_STATS_PERIODIC 5*/ + uint32_t reason_code; + + /** Current data rate state \n + #define STATE_3M_RATE BIT(0) \n + #define STATE_2M_RATE BIT(1)*/ + uint32_t current_state; +} rsi_bt_event_ar_stats_t; + +typedef struct rsi_bt_event_pkt_change_s { + + /** remote device address*/ + uint8_t bd_addr[6]; + + /** packet_type bitmap. \n + 0x0001 Reserved for future use \n + 0x0002 2-DH1 should not be used. \n + 0x0004 3-DH1 should not be used \n + 0x0008 DM1 may be used. \n + 0x0010 DH1 may be used. \n + 0x0020 Reserved for future use. \n + 0x0040 Reserved for future use. \n + 0x0080 Reserved for future use. \n + 0x0100 2-DH3 should not be used. \n + 0x0200 3-DH3 should not be used. \n + 0x0400 DM3 may be used. \n + 0x0800 DH3 may be used. \n + 0x1000 2-DH5 should not be used. \n + 0x2000 3-DH5 should not be used. \n + 0x4000 DM5 may be used. \n + 0x8000 DH5 may be used. */ + uint16_t pkt_type; + +} rsi_bt_event_pkt_change_t; + +typedef struct chip_bt_buffers_stats_s { + uint8_t acl_buffer_utilization; + uint8_t cp_buffer_utilization; +} chip_bt_buffers_stats_t; + +typedef struct rsi_bt_event_iap_s { + uint8_t status; +} rsi_bt_event_iap_t; + +typedef struct rsi_bt_event_iap2_receive_s { + uint16_t data_len; + uint8_t data[1000]; +} rsi_bt_event_iap2_receive_t; + +/****************************************************** + * * BT GAP Response Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-CLASSIC7 +* @{ +*/ +/** + * @typedef void (*rsi_bt_on_role_change_t)(uint16_t resp_status, rsi_bt_event_role_change_t *role_change_status); + * @brief When role change status event is received from the module this callback will be called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes. + * @param[out] role_change_status, contains the role_change_status information , please refer \ref rsi_bt_event_role_change_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_role_change_t)(uint16_t resp_status, rsi_bt_event_role_change_t *role_change_status); + +/** + * @typedef void (*rsi_bt_on_connect_t)(uint16_t resp_status, rsi_bt_event_bond_t *bond_response); + * @brief When Connect event is raised from the module, this callback will be called. \n + * This event will be given by the module when BT PHY Level connection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] bond_response, contains the connect/bond response information , please refer \ref rsi_bt_event_bond_response_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_connect_t)(uint16_t resp_status, rsi_bt_event_bond_t *bond_response); + +/** + * @typedef void (*rsi_bt_on_unbond_t)(uint16_t resp_status, rsi_bt_event_unbond_t *unbond_status); + * @brief When unbond event is raised from the module this callback is called . \n + This event will be given by the module when either slave or master device issues unbond command to the other. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] unbond_status, contains the disconnection information , please refer \ref rsi_bt_event_unbond_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_unbond_t)(uint16_t resp_status, rsi_bt_event_unbond_t *unbond_status); + +/** + * @typedef void (*rsi_bt_on_disconnect_t)(uint16_t resp_status, rsi_bt_event_disconnect_t *bt_disconnect); + * @brief When disconnection event is raised from the module this callback will be called . \n + * This event will be given by the module when either slave or master device issues disconnect command to the other. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] bt_disconnect, contains the disconnection information , please refer \ref rsi_bt_event_disconnect_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_disconnect_t)(uint16_t resp_status, rsi_bt_event_disconnect_t *bt_disconnect); + +/** + * @typedef void (*rsi_bt_on_scan_resp_t)(uint16_t resp_status, rsi_bt_event_inquiry_response_t *single_scan_resp); + * @brief When the single scan response is received from the module in response to inquiry command this callback is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] rsi_ble_resp_profiles, contains the inquiry response information , please refer \ref rsi_bt_event_inquiry_response_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_scan_resp_t)(uint16_t resp_status, rsi_bt_event_inquiry_response_t *single_scan_resp); + +/** + * @typedef void (*rsi_bt_on_remote_name_resp_t)(uint16_t resp_status, rsi_bt_event_remote_device_name_t *name_resp); + * @brief When the remote name request command response is received from the module this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] name_resp, contains the remote device name information, please refer \ref rsi_bt_event_remote_device_name_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_remote_name_resp_t)(uint16_t resp_status, rsi_bt_event_remote_device_name_t *name_resp); + +/** + * @typedef typedef void (*rsi_bt_on_passkey_display_t)(uint16_t resp_status, + rsi_bt_event_user_passkey_display_t *bt_event_user_passkey_display); + * @brief When the passkey display request is received from the module this callback function is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] bt_event_user_passkey_display, contains the passkey information , please refer \ref rsi_bt_event_user_passkey_display_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_passkey_display_t)(uint16_t resp_status, + rsi_bt_event_user_passkey_display_t *bt_event_user_passkey_display); + +/** + * @typedef typedef void (*rsi_bt_on_remote_name_request_cancel_t)(uint16_t resp_status, + rsi_bt_event_remote_name_request_cancel_t *remote_name_request_cancel); + * @brief When the remote name request cancels the command response received from the module this callback function is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] remote_name_request_cancel, contains the response to remote name request cancel cmd , please refer \ref rsi_bt_event_remote_name_request_cancel_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_remote_name_request_cancel_t)( + uint16_t resp_status, + rsi_bt_event_remote_name_request_cancel_t *remote_name_request_cancel); + +/** + * @typedef void (*rsi_bt_on_confirm_request_t)(uint16_t resp_status, + * rsi_bt_event_user_confirmation_request_t *user_confirmation_request); + * @brief When the user confirmation request is received from the module this callback is called. \n + * The user has to give rsi_bt_accept_ssp_confirm or rsi_bt_reject_ssp_confirm command upon reception of this event. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] user_confirmation_request, contains the confirmation request information ,please refer \ref rsi_bt_event_user_confirmation_request_s structure for more information . + + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_confirm_request_t)(uint16_t resp_status, + rsi_bt_event_user_confirmation_request_t *user_confirmation_request); + +/** + * @typedef void (*rsi_bt_on_pincode_request_t)(uint16_t resp_status, + * rsi_bt_event_user_pincode_request_t *user_pincode_request); + * @brief When pincode request is received from the module, this callback is called. \n + * User has to give rsi_bt_accept_pincode_request command upon reception of this event. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] user_pincode_request, contains the pincode request information ,please refer \ref rsi_bt_event_user_pincode_request_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_pincode_request_t)(uint16_t resp_status, + rsi_bt_event_user_pincode_request_t *user_pincode_request); + +/** + * @typedef void (*rsi_bt_on_passkey_request_t)(uint16_t resp_status, + * rsi_bt_event_user_passkey_request_t *user_passkey_request); + * @brief When the passkey request is received from the module this callback is called. \n + * User has to give rsi_bt_passkey command upon reception of this event. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] user_passkey_request, contains the passkey request information ,please refer \ref rsi_bt_event_user_passkey_request_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_passkey_request_t)(uint16_t resp_status, + rsi_bt_event_user_passkey_request_t *user_passkey_request); + +/** + * @typedef void (*rsi_bt_on_inquiry_complete_t)(uint16_t resp_status); + * @brief When inquiry complete status is received from the module this callback is called . \n + * This event will be given by the module when inquiry command is completely executed. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_inquiry_complete_t)(uint16_t resp_status); + +/** + * @typedef void (*rsi_bt_on_auth_complete_t)(uint16_t resp_status, rsi_bt_event_auth_complete_t *auth_complete); + * @brief When authentication complete indication is received from the module this callback is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] auth_complete, contains the authentication complete information , please refer \ref rsi_bt_event_auth_complete_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_auth_complete_t)(uint16_t resp_status, rsi_bt_event_auth_complete_t *auth_complete); + +/** + * @typedef void (*rsi_bt_on_linkkey_request_t)(uint16_t resp_status, + * rsi_bt_event_user_linkkey_request_t *user_linkkey_request); + * @brief When linkkey request is received from the module this callback is called. \n + * User has to give linkkey reply command upon reception of this event. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] user_linkkey_request, contains the linkkey request information , please refer \ref rsi_bt_event_user_linkkey_request_s structure for mre information . + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_linkkey_request_t)(uint16_t resp_status, + rsi_bt_event_user_linkkey_request_t *user_linkkey_request); + +/** + * @typedef void (*rsi_bt_on_ssp_complete_t)(uint16_t resp_status, rsi_bt_event_ssp_complete_t *ssp_complete); + * @brief When SSP complete status is received from the module this callback is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] ssp_complete, contains the ssp complete status, please refer \ref rsi_bt_event_ssp_complete_s structure for more information . + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_ssp_complete_t)(uint16_t resp_status, rsi_bt_event_ssp_complete_t *ssp_complete); + +/** + * @typedef void (*rsi_bt_on_linkkey_save_t)(uint16_t resp_status, rsi_bt_event_user_linkkey_save_t *user_linkkey_save); + * @brief When linkkey save is received from the module this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] user_linkkey_save, contains the linkkey save information , plesae refer \ref rsi_bt_event_user_linkkey_save_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_linkkey_save_t)(uint16_t resp_status, rsi_bt_event_user_linkkey_save_t *user_linkkey_save); + +/** + * @typedef void (*rsi_bt_on_get_services_t)(uint16_t resp_status, rsi_bt_resp_query_services_t *service_list); + * @brief When the get services command response is received from the module this callback is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] service_list, contains the response information to get services cmd ,please refer \ref rsi_bt_resp_query_services_s structure for more information. + * @return void + * @note This callback is Reserved for Future. + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_get_services_t)(uint16_t resp_status, rsi_bt_resp_query_services_t *service_list); + +/** + * @typedef void (*rsi_bt_on_search_service_t)(uint16_t resp_status, uint8_t *status); + * @brief When the search service command response is received from the module this calback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] status, contains the status response to search service cmd. + * @return void + * @note This callback is Reserved for Future. + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_search_service_t)(uint16_t resp_status, uint8_t *status); + +/** + * @typedef void (*rsi_bt_on_mode_chnage_t)(uint16_t resp_status, rsi_bt_event_mode_change_t *mode_change); + * @brief When the local device enters / exits the Sniff mode this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] mode_change, contains the response payload for the mode change response , please refer \ref rsi_bt_event_mode_change_s structure for more information . + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_mode_chnage_t)(uint16_t resp_status, rsi_bt_event_mode_change_t *mode_change); + +/** + * @typedef void (*rsi_bt_on_avdtp_stats_t)(uint16_t resp_status, rsi_bt_event_avdtp_stats_t *avdtp_event); + * @brief When AVDTP stats event is receicved from module this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @param[out] avdtp_event, contains the avdtp stats parameters , please refer \ref rsi_bt_event_avdtp_stats_s structure for more information . + * @return void + * @note This callback has to be registered using rsi_bt_avdtp_events_register_callbacks API + */ +typedef void (*rsi_bt_on_avdtp_stats_t)(uint16_t resp_status, rsi_bt_event_avdtp_stats_t *avdtp_event); + +/** + * @typedef void (*rsi_bt_on_ar_stats_t)(uint16_t resp_status, rsi_bt_event_ar_stats_t *ar_event); + * @brief When AR stats event is received from module this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @param[out] ar_event, contains the ar stats parameters , please refer \ref rsi_bt_event_ar_stats_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_ar_events_register_callbacks API + */ +typedef void (*rsi_bt_on_ar_stats_t)(uint16_t resp_status, rsi_bt_event_ar_stats_t *ar_event); + +/** + * @typedef void (*rsi_bt_pkt_change_stats_t)(uint16_t resp_status, rsi_bt_event_pkt_change_t *bt_pkt_change_stats); + * @brief When HCI packet type change receicved from module this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @param[out] avdtp_event, contains the packet type , please refer \ref rsi_bt_event_pkt_change_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_pkt_change_events_register_callbacks API + */ + +typedef void (*rsi_bt_pkt_change_stats_t)(uint16_t resp_status, rsi_bt_event_pkt_change_t *bt_pkt_change_stats); + +/** + * @typedef void (*rsi_bt_on_sniff_subrating_t)(uint16_t resp_status, rsi_bt_event_sniff_subrating_t *mode_change); + * @brief When Sniff subrating is enabled or the parameters are negotiated with the remote device this callback is called . + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] mode_change, contains parameters related to sniff subrating , please refer \ref rsi_bt_event_sniff_subrating_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_sniff_subrating_t)(uint16_t resp_status, rsi_bt_event_sniff_subrating_t *mode_change); +/** + * @typedef void (*rsi_bt_on_connection_initiated_t)(uint16_t resp_status, + * rsi_bt_event_connection_initiated_t *mode_change); + * @brief When the headset initiates the connection this callback is called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] conn_event, if the value is 1 implies connection initiated by remote device , please refer \ref rsi_bt_event_connection_initiated_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_register_gap_callbacks API + */ +typedef void (*rsi_bt_on_connection_initiated_t)(uint16_t resp_status, + rsi_bt_event_connection_initiated_t *mode_change); + +/** @} */ + +/** + * @typedef void (*rsi_bt_on_chip_memory_stats_handler_t)(uint16_t resp_status, + * struct chip_bt_buffers_stats_s *chip_bt_buffers_stats); + * @brief Callback function to be called when memory stats received from module + * @note This API is not supported in the current release. + * @param[out] resp_status - contains the response status (Success or Error code) + * @param[out] avdtp_event - contains the stats info + * @return void + * @note Currently Not Using this callback + */ +typedef void (*rsi_bt_on_chip_memory_stats_handler_t)(uint16_t resp_status, + struct chip_bt_buffers_stats_s *chip_bt_buffers_stats); +/** + * @typedef void (*rsi_bt_on_gatt_connection_t)(uint16_t resp_status, rsi_bt_event_gatt_connect_t *gatt_conn); + * @brief Callback function to be called if gatt connection response is received + * @note This API is not supported in the current release. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] gatt_conn, contains the remote device address of gatt connected over classic. \n + * Please refer \ref rsi_bt_event_gatt_connect_s structure for more info. + * @return void + */ +typedef void (*rsi_bt_on_gatt_connection_t)(uint16_t resp_status, rsi_bt_event_gatt_connect_t *gatt_conn); +/** + * @typedef void (*rsi_bt_on_gatt_disconnection_t)(uint16_t resp_status, rsi_bt_event_gatt_disconnect_t *gatt_disconn); + * @brief Callback function to be called if gatt disconnection response is received + * @note This API is not supported in the current release. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] gatt_disconn, contains the remote device address of gatt disconnected over classic. \n + * Please refer \ref rsi_bt_event_gatt_disconnect_s structure for more info. + * @return void + */ +typedef void (*rsi_bt_on_gatt_disconnection_t)(uint16_t resp_status, rsi_bt_event_gatt_disconnect_t *gatt_disconn); + +/****************************************************** + * * BT SPP Response Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-CLASSIC7 +* @{ +*/ +/** + * @typedef void (*rsi_bt_on_spp_connect_t)(uint16_t resp_status, rsi_bt_event_spp_connect_t *spp_connect); + * @brief When SPP connected event is raised from the module,this callback will be called .\n + * This event will be given by the module when spp profile level connection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] spp_connect, contains the spp connect information, please refer \ref rsi_bt_event_spp_connect_s for more information. + * @return void + * @note This callback has to be registered using rsi_bt_spp_register_callbacks API + */ +typedef void (*rsi_bt_on_spp_connect_t)(uint16_t resp_status, rsi_bt_event_spp_connect_t *spp_connect); + +/** + * @typedef void (*rsi_bt_on_spp_disconnect_t)(uint16_t resp_status, rsi_bt_event_spp_disconnect_t *spp_disconnect); + * @brief When SPP disconnected event is raised from the module,this callback will be called .\n + * This event will be given by the module when spp profile level disconnection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] spp_disconnect, contains the spp disconnect information, please refer \ref rsi_bt_event_spp_disconnect_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_spp_register_callbacks API. + */ +typedef void (*rsi_bt_on_spp_disconnect_t)(uint16_t resp_status, rsi_bt_event_spp_disconnect_t *spp_disconnect); + +/** + * @typedef void (*rsi_bt_on_spp_rx_data_t)(uint16_t resp_status, rsi_bt_event_spp_receive_t *bt_event_spp_receive); + * @brief When SPP receive event is raised from the module,this callback will be called.\n + * This event will be given by the local device when it receives data from the remote device. + * @param[out] resp_status, contains the response status (Success or Error code) + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes + * @param[out] bt_event_spp_receive, contains the spp rcvd data information, please refer \ref rsi_bt_event_spp_receive_s structure for more information. + * @return void + * @note This callback has to be registered using rsi_bt_spp_register_callbacks API + */ +typedef void (*rsi_bt_on_spp_rx_data_t)(uint16_t resp_status, rsi_bt_event_spp_receive_t *bt_event_spp_receive); +/** @} */ +/****************************************************** + * * BT L2CAP Response Callbacks Declarations + * ******************************************************/ + +/** + * @typedef void (*rsi_bt_on_l2cap_connect_t)(uint16_t resp_status, rsi_bt_event_l2cap_connect_t *l2cap_connect); + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] l2cap_connect, contains the l2cap connect information + * @return void + */ +typedef void (*rsi_bt_on_l2cap_connect_t)(uint16_t resp_status, rsi_bt_event_l2cap_connect_t *l2cap_connect); + +/** + * @typedef void (*rsi_bt_on_l2cap_disconnect_t)(uint16_t resp_status, rsi_bt_event_l2cap_disconnect_t *l2cap_disconnect); + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] l2cap_disconnect, contains the l2cap disconnect information + * @return void + */ +typedef void (*rsi_bt_on_l2cap_disconnect_t)(uint16_t resp_status, rsi_bt_event_l2cap_disconnect_t *l2cap_disconnect); + +/** + * @typedef void (*rsi_bt_on_l2cap_rx_data_t)(uint16_t resp_status, rsi_bt_event_l2cap_data_t *bt_event_l2cap_receive); + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] bt_event_hid_receive, contains the hid rcvd data information. + * @return void + */ +typedef void (*rsi_bt_on_l2cap_rx_data_t)(uint16_t resp_status, rsi_bt_event_l2cap_data_t *bt_event_l2cap_receive); + +/****************************************************** + * * BT HID Response Callbacks Declarations + * ******************************************************/ + +/** + * @typedef void (*rsi_bt_on_hid_connect_t)(uint16_t resp_status, rsi_bt_event_hid_connect_t *hid_connect); + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] hid_connect, contains the hid connect information + * @return void + */ +typedef void (*rsi_bt_on_hid_connect_t)(uint16_t resp_status, rsi_bt_event_hid_connect_t *hid_connect); + +/** + * @typedef void (*rsi_bt_on_hid_disconnect_t)(uint16_t resp_status, rsi_bt_event_hid_disconnect_t *hid_disconnect); + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] hid_disconnect, contains the hid disconnect information + * @return void + */ +typedef void (*rsi_bt_on_hid_disconnect_t)(uint16_t resp_status, rsi_bt_event_hid_disconnect_t *hid_disconnect); + +/** + * @typedef void (*rsi_bt_on_hid_rx_data_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] bt_event_hid_receive, contains the hid rcvd data information. + * @return void + * @section description + */ +typedef void (*rsi_bt_on_hid_rx_data_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); + +typedef void (*rsi_bt_on_hid_handshake_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); +typedef void (*rsi_bt_on_hid_control_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); +typedef void (*rsi_bt_on_hid_get_report_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); +typedef void (*rsi_bt_on_hid_set_report_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); +typedef void (*rsi_bt_on_hid_get_protocol_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); +typedef void (*rsi_bt_on_hid_set_protocol_t)(uint16_t resp_status, rsi_bt_event_hid_receive_t *bt_event_hid_receive); +typedef void (*rsi_bt_app_iap_conn_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap_disconn_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap_acc_auth_strt_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap_acc_auth_fail_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap_acc_auth_complete_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_auth_start_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_auth_complete_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_auth_fail_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_identification_start_t)(uint16_t resp_status, rsi_bt_event_iap_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_identification_complete_t)(uint16_t resp_status, + rsi_bt_event_iap2_receive_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_identification_reject_t)(uint16_t resp_status, rsi_bt_event_iap2_receive_t *iap_disconn); +typedef void (*rsi_bt_app_iap2_File_Tx_state_t)(uint16_t resp_status, rsi_bt_event_iap2_receive_t *iap2_receive); +typedef void (*rsi_bt_app_on_iap2_data_rx_t)(uint16_t resp_status, rsi_bt_event_iap2_receive_t *iap2_receive); +//typedef void (*rsi_bt_app_iap2_File_Tx_state_t)(uint16_t resp_status, rsi_bt_event_iap2_receive_t *iap2_receive); +typedef void (*rsi_bt_app_iap2_File_Transfer_rx_data_t)(uint16_t resp_status, + rsi_bt_event_iap2_receive_t *iap2_receive); + +/****************************************************** + * * BT GAP Callbacks register function Declarations + * ******************************************************/ + +/*==============================================*/ +/** + * @fn rsi_bt_register_gap_callbacks + * @brief This function registers the GAP callbacks + * @param[in] rsi_bt_on_connect_t bt_on_conn_status_event : Connection status callback + * @param[in] rsi_bt_on_unbond_t bt_on_unbond_status : Connection status callback + * @param[in] rsi_bt_on_disconnect_t bt_on_disconnect_event : Disconnection status callback + * @param[in] rsi_bt_on_scan_resp_t bt_on_scan_resp_event : Scan report callback + * @param[in] rsi_bt_on_remote_name_resp_t bt_on_remote_name_resp_event : Remote name report callback + * @param[in] rsi_bt_on_passkey_display_t bt_on_passkey_display_event : Passkey display report callback + * @param[in] rsi_bt_on_remote_name_request_cancel_t bt_on_remote_name_request_cancel_event: Remote name request cancel status callback + * @param[in] rsi_bt_on_confirm_request_t bt_on_confirm_request_event : Authentication status callback + * @param[in] rsi_bt_on_pincode_request_t bt_on_pincode_request_event : Pincode request status callback + * @param[in] rsi_bt_on_passkey_request_t bt_on_passkey_request_event : Passkey request status callback + * @param[in] rsi_bt_on_inquiry_complete_t bt_on_inquiry_complete_event : Inquiry report callback + * @param[in] rsi_bt_on_auth_complete_t bt_on_auth_complete_event : Authentication status callback + * @param[in] rsi_bt_on_linkkey_request_t bt_on_linkkey_request_event : Linkkey request report callback + * @param[in] rsi_bt_on_ssp_complete_t bt_on_ssp_complete_event : SSP status callback + * @param[in] rsi_bt_on_linkkey_save_t bt_on_linkkey_save_event : Linkkey save status callback + * @param[in] rsi_bt_on_get_services_t bt_on_get_services_event : Get services report callback + * @param[in] rsi_bt_on_search_service_t bt_on_search_service_event : Search service status callback + * @return + * Non zero - If fails + * 0 - If success + * + * + */ +void rsi_bt_gap_register_callbacks(rsi_bt_on_role_change_t bt_on_role_change_status_event, + rsi_bt_on_connect_t bt_on_conn_status_event, + rsi_bt_on_unbond_t bt_on_unbond_status, + rsi_bt_on_disconnect_t bt_on_disconnect_event, + rsi_bt_on_scan_resp_t bt_on_scan_resp_event, + rsi_bt_on_remote_name_resp_t bt_on_remote_name_resp_event, + rsi_bt_on_passkey_display_t bt_on_passkey_display_event, + rsi_bt_on_remote_name_request_cancel_t bt_on_remote_name_request_cancel_event, + rsi_bt_on_confirm_request_t bt_on_confirm_request_event, + rsi_bt_on_pincode_request_t bt_on_pincode_request_event, + rsi_bt_on_passkey_request_t bt_on_passkey_request_event, + rsi_bt_on_inquiry_complete_t bt_on_inquiry_complete_event, + rsi_bt_on_auth_complete_t bt_on_auth_complete_event, + rsi_bt_on_linkkey_request_t bt_on_linkkey_request_event, + rsi_bt_on_ssp_complete_t bt_on_ssp_complete_event, + rsi_bt_on_linkkey_save_t bt_on_linkkey_save_event, + rsi_bt_on_get_services_t bt_on_get_services_event, + rsi_bt_on_search_service_t bt_on_search_service_event, + rsi_bt_on_mode_chnage_t bt_on_mode_change_event, + rsi_bt_on_sniff_subrating_t bt_on_sniff_subrating_event, + rsi_bt_on_connection_initiated_t bt_on_connection_initiated); + +void rsi_bt_iap_register_callbacks(rsi_bt_app_iap_conn_t bt_app_iap_conn, + rsi_bt_app_iap_disconn_t bt_app_iap_disconn, + rsi_bt_app_iap_acc_auth_strt_t bt_app_iap_acc_auth_strt, + rsi_bt_app_iap_acc_auth_fail_t bt_app_iap_acc_auth_fail, + rsi_bt_app_iap_acc_auth_complete_t bt_app_iap_acc_auth_complete, + rsi_bt_app_iap2_auth_start_t bt_app_iap2_auth_start, + rsi_bt_app_iap2_auth_complete_t bt_app_iap2_auth_complete, + rsi_bt_app_iap2_auth_fail_t bt_app_iap2_auth_fail, + rsi_bt_app_iap2_identification_start_t bt_app_iap2_identification_start, + rsi_bt_app_iap2_identification_complete_t bt_app_iap2_identification_complete, + rsi_bt_app_iap2_identification_reject_t bt_app_iap2_identification_reject, + rsi_bt_app_on_iap2_data_rx_t bt_app_on_iap2_data_rx, + rsi_bt_app_iap2_File_Tx_state_t bt_app_iap2_File_Transfer_state, + rsi_bt_app_iap2_File_Transfer_rx_data_t bt_app_iap2_File_Transfer_data); + +/** + * @fn rsi_bt_gatt_extended_register_callbacks + * + * + */ + +void rsi_bt_gatt_extended_register_callbacks(rsi_bt_on_gatt_connection_t bt_on_gatt_connection_event, + rsi_bt_on_gatt_disconnection_t bt_on_gatt_disconnection_event); + +/** + * @fn rsi_bt_avdtp_events_register_callbacks + * + */ + +void rsi_bt_avdtp_events_register_callbacks(rsi_bt_on_avdtp_stats_t bt_on_avdtp_stats_event); + +/** + * @fn rsi_bt_ar_events_register_callbacks + * @brief This function registers the AR Event callbacks + * @param[in] rsi_bt_on_avdtp_stats_t bt_on_ar_stats_event + * @return + * Non zero - If fails + * 0 - If success + * + * @section description + * This function registers the ar stats callbacks + * + */ + +void rsi_bt_ar_events_register_callbacks(rsi_bt_on_ar_stats_t bt_on_ar_stats_event); + +/** + * @fn rsi_bt_pkt_change_events_register_callbacks + * + */ +void rsi_bt_pkt_change_events_register_callbacks(rsi_bt_pkt_change_stats_t bt_pkt_change_stats_event); +/** + * @fn rsi_bt_on_chip_memory_status_callbacks_register + * + */ +void rsi_bt_on_chip_memory_status_callbacks_register( + rsi_bt_on_chip_memory_stats_handler_t bt_on_chip_memory_stats_event); +/****************************************************** + * * BT SPP Callbacks register function Declarations + * ******************************************************/ + +/*==============================================*/ + +/** + * @fn rsi_bt_spp_register_callbacks + * + */ +void rsi_bt_spp_register_callbacks(rsi_bt_on_spp_connect_t bt_on_spp_connect_event, + rsi_bt_on_spp_disconnect_t bt_on_spp_disconnect_event, + rsi_bt_on_spp_rx_data_t bt_on_spp_rx_data_event); + +void rsi_bt_l2cap_register_callbacks(rsi_bt_on_l2cap_connect_t bt_on_l2cap_connect_event, + rsi_bt_on_l2cap_rx_data_t bt_on_l2cap_rx_data_event); +/*==============================================*/ +/** + * @fn rsi_bt_set_local_class_of_device + */ +int32_t rsi_bt_set_local_class_of_device(uint32_t class_of_device); + +/*==============================================*/ +/** + * @fn rsi_bt_get_local_class_of_device + */ +int32_t rsi_bt_get_local_class_of_device(uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_start_discoverable + */ +int32_t rsi_bt_start_discoverable(void); + +/*==============================================*/ +/** + * @fn rsi_bt_start_limited_discoverable + */ +int32_t rsi_bt_start_limited_discoverable(int32_t time_out_ms); + +/*==============================================*/ +/** + * @fn rsi_bt_stop_discoverable + */ +int32_t rsi_bt_stop_discoverable(void); + +/*==============================================*/ +/** + * @fn rsi_bt_get_discoverable_status + */ +int32_t rsi_bt_get_discoverable_status(uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_set_connectable + */ +int32_t rsi_bt_set_connectable(void); + +/*==============================================*/ +/** + * @fn rsi_bt_set_non_connectable + */ +int32_t rsi_bt_set_non_connectable(void); + +/*==============================================*/ +/** + * @fn rsi_bt_get_connectable_status + */ +int32_t rsi_bt_get_connectable_status(uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_enable_authentication + */ +int32_t rsi_bt_enable_authentication(void); + +/*==============================================*/ +/** + * @fn rsi_bt_disable_authentication + */ +int32_t rsi_bt_disable_authentication(void); + +/*==============================================*/ +/** + * @fn rsi_bt_get_authentication + */ +int32_t rsi_bt_get_authentication(uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_remote_name_request_async + */ +int32_t rsi_bt_remote_name_request_async(uint8_t *remote_dev_addr, + rsi_bt_event_remote_device_name_t *bt_event_remote_device_name); + +/*==============================================*/ +/** + * @fn rsi_bt_remote_name_request_cancel + */ +int32_t rsi_bt_remote_name_request_cancel(uint8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_bt_spp_connect + * */ +int32_t rsi_bt_spp_connect(uint8_t *remote_dev_addr); + +/*==============================================*/ +/** + + * @fn rsi_ble_set_eir_data + * + */ +int32_t rsi_bt_set_eir_data(uint8_t *data, uint16_t data_len); + +/*==============================================*/ +/** + * @fn rsi_bt_spp_init + */ +int32_t rsi_bt_spp_init(void); + +/*==============================================*/ +/** + * @fn rsi_bt_spp_transfer + * + */ +int32_t rsi_bt_spp_transfer(uint8_t *remote_dev_addr, uint8_t *data, uint16_t length); + +/*==============================================*/ +/** + * @fn rsi_bt_inquiry + */ +int32_t rsi_bt_inquiry(uint8_t inquiry_type, uint32_t inquiry_duration, uint8_t max_devices); + +/*==============================================*/ +/** + * @fn rsi_bt_cancel_inquiry + */ +int32_t rsi_bt_cancel_inquiry(void); + +/*==============================================*/ +/** + * @fn rsi_bt_connect + */ +int32_t rsi_bt_connect(uint8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_bt_cancel_connect + * + */ +int32_t rsi_bt_cancel_connect(uint8_t *remote_dev_address); + +/*==============================================*/ +/** + * @fn rsi_bt_disconnect + * + */ +int32_t rsi_bt_disconnect(uint8_t *remote_dev_address); + +/*==============================================*/ +/** + * @fn rsi_bt_accept_ssp_confirm + * + */ +int32_t rsi_bt_accept_ssp_confirm(uint8_t *remote_dev_address); + +/*==============================================*/ +/** + * @fn rsi_bt_reject_ssp_confirm + * + */ +int32_t rsi_bt_reject_ssp_confirm(uint8_t *remote_dev_address); + +/*==============================================*/ +/** + * @fn rsi_bt_passkey + * + */ +int32_t rsi_bt_passkey(uint8_t *remote_dev_addr, uint32_t passkey, uint8_t reply_type); + +/*==============================================*/ +/** + * @fn rsi_bt_pincode_request_reply + * + */ +int32_t rsi_bt_pincode_request_reply(uint8_t *remote_dev_addr, uint8_t *pin_code, uint8_t reply_type); + +/*==============================================*/ +/** + * @fn rsi_bt_linkkey_request_reply + * + */ +int32_t rsi_bt_linkkey_request_reply(uint8_t *remote_dev_addr, uint8_t *linkkey, uint8_t reply_type); + +/*==============================================*/ +/** + * @fn rsi_bt_get_local_device_role + * + */ +int32_t rsi_bt_get_local_device_role(uint8_t *remote_dev_addr, uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_get_services_async + * + */ +int32_t rsi_bt_get_services_async(uint8_t *remote_dev_addr, rsi_bt_resp_query_services_t *bt_resp_query_services); + +/*==============================================*/ +/** + * @fn rsi_bt_search_service_async + * + */ +int32_t rsi_bt_search_service_async(uint8_t *remote_dev_addr, uint32_t service_uuid); + +/*==============================================*/ +/** + * @fn rsi_bt_sniff_mode + */ +int32_t rsi_bt_sniff_mode(uint8_t *remote_dev_addr, + uint16_t sniff_max_intv, + uint16_t sniff_min_intv, + uint16_t sniff_attempt, + uint16_t sniff_tout); + +/*==============================================*/ +/** + * @fn rsi_bt_sniff_exit_mode + */ +int32_t rsi_bt_sniff_exit_mode(uint8_t *remote_dev_addr); + +/*==============================================*/ +/** + * @fn rsi_bt_sniff_subrating_mode + */ +int32_t rsi_bt_sniff_subrating_mode(uint8_t *remote_dev_addr, + uint16_t max_latency, + uint16_t min_remote_tout, + uint16_t min_local_tout); + +/*==============================================*/ +/** + * @fn rsi_bt_set_ssp_mode + */ +int32_t rsi_bt_set_ssp_mode(uint8_t pair_mode, uint8_t IOcapability); +int32_t rsi_bt_iap_conn(uint8_t *remote_dev_addr, uint8_t version); +int32_t rsi_bt_iap_disconn(uint8_t *remote_dev_addr, uint8_t version); +int32_t rsi_bt_iap_set_accessory_info(uint8_t type, uint8_t length, uint8_t *data); +int32_t rsi_bt_iap_set_voice_over(uint8_t mode, uint8_t restore); +int32_t rsi_bt_iap1_identification(void); +int32_t rsi_bt_iap2_identification(void); +int32_t rsi_bt_iap1_device_authentication(void); +int32_t rsi_bt_iap_init(void); +int32_t rsi_bt_iap_set_protocol_type(uint8_t type); +int32_t rsi_bt_iap_find_protocol_type(uint8_t *resp); + +/* A2DP Profile */ +typedef struct rsi_bt_event_a2dp_connect_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_connect_t; + +typedef struct rsi_bt_event_a2dp_disconnect_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_disconnect_t; + +typedef struct rsi_bt_event_a2dp_configure_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_configure_t; + +typedef struct rsi_bt_event_a2dp_start_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Sampling frequency of the A2DP Stream codec*/ + uint16_t sample_freq; + + /** MTU size supported by the remote device*/ + uint16_t rem_mtu_size; +#if BT_HFP_HF_ROLE + uint16_t rx_mtu_size; +#endif +} rsi_bt_event_a2dp_start_t; + +typedef struct rsi_bt_event_a2dp_open_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_open_t; + +typedef struct rsi_bt_event_a2dp_suspend_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_suspend_t; + +typedef struct rsi_bt_event_a2dp_abort_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_abort_t; + +typedef struct rsi_bt_event_a2dp_close_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_a2dp_close_t; + +typedef struct rsi_bt_event_a2dp_encode_data_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Length of the received encoded data*/ + uint16_t encode_data_len; + + /** Buffer holding the received a2dp encoded data. It holds the max payload length of 1k bytes*/ + uint8_t encode_data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_event_a2dp_encode_data_t; + +typedef struct rsi_bt_event_a2dp_pcm_data_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Length of the received pcm data*/ + uint16_t pcm_data_len; + + /** Buffer holding the received a2dp pcm data. It holds the max payload length of 1k bytes*/ + uint8_t pcm_data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_event_a2dp_pcm_data_t; + +typedef struct rsi_bt_event_a2dp_more_data_req_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Number of Bytes to be send from Host to Stack*/ + uint16_t NbrBytesReqd; +} rsi_bt_event_a2dp_more_data_req_t; + +typedef struct rsi_bt_event_a2dp_reconfig_s { + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** If Reconfig Command given to Remote Device and there is no response till timer exits, \n + then ERR_BT_A2DP_RECONFIG_CMD_TIMEOUT 0x4514 will be send through this status from stack to host.*/ + uint16_t resp_status; +} rsi_bt_event_a2dp_reconfig_t; +/****************************************************** + * * BT A2DP Response Callbacks Declarations + * ******************************************************/ +/** @addtogroup BT-CLASSIC7 +* @{ +*/ +/** + * @typedef void (*rsi_bt_on_a2dp_connect_t)(uint16_t resp_status, rsi_bt_event_a2dp_connect_t *a2dp_connect); + * @brief When A2DP connected event is raised from the module, this callback will be called. \n + * This event will be given by the module when A2DP profile level connection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_connect, contains the a2dp connect information, please refer \ref rsi_bt_event_a2dp_connect_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_connect_t)(uint16_t resp_status, rsi_bt_event_a2dp_connect_t *a2dp_connect); + +/** + * @typedef void (*rsi_bt_on_a2dp_disconnect_t)(uint16_t resp_status, rsi_bt_event_a2dp_disconnect_t *a2dp_disconnect); + * @brief When A2DP disconnected event is raised from the module, this callback will be called. \n + * This event will be given by the module when a2dp profile level disconnection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_disconnect, contains the a2dp disconnect information, please refer \ref rsi_bt_event_a2dp_disconnect_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_disconnect_t)(uint16_t resp_status, rsi_bt_event_a2dp_disconnect_t *a2dp_disconnect); + +/** + * @typedef void (*rsi_bt_on_a2dp_configure_t)(uint16_t resp_status, rsi_bt_event_a2dp_configure_t *a2dp_configure); + * @brief When A2DP configured event is raised from the module, this callback will be called. \n + * This event will be given by the module when a2dp profile onfiguration happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_configure, contains the a2dp configure information, please refer \ref rsi_bt_event_a2dp_configure_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_configure_t)(uint16_t resp_status, rsi_bt_event_a2dp_configure_t *a2dp_configure); + +/** + * @typedef void (*rsi_bt_on_a2dp_open_t)(uint16_t resp_status, rsi_bt_event_a2dp_open_t *a2dp_open); + * @brief When A2DP open event is raised from the module, this callback will be called. \n + * This event will be given by the module when a2dp opens in either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_open, contains the a2dp open information, please refer \ref rsi_bt_event_a2dp_open_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_open_t)(uint16_t resp_status, rsi_bt_event_a2dp_open_t *a2dp_open); + +/** + * @typedef void (*rsi_bt_on_a2dp_start_t)(uint16_t resp_status, rsi_bt_event_a2dp_start_t *a2dp_start); + * @brief When A2DP start event is raised from the module, this callback is called. \n + * This event will be given by the module when a2dp starts from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_start, contains the a2dp start information, please refer \ref rsi_bt_event_a2dp_start_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_start_t)(uint16_t resp_status, rsi_bt_event_a2dp_start_t *a2dp_start); + +/** + * @typedef void (*rsi_bt_on_a2dp_suspend_t)(uint16_t resp_status, rsi_bt_event_a2dp_suspend_t *a2dp_suspend); + * @brief When A2DP suspend event is raised from the module, this callback will be called. \n + * This event will be given by the module when a2dp suspend happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp suspend, contains the a2dp suspend information, please refer \ref rsi_bt_event_a2dp_suspend_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_suspend_t)(uint16_t resp_status, rsi_bt_event_a2dp_suspend_t *a2dp_suspend); + +/** + * @typedef void (*rsi_bt_on_a2dp_abort_t)(uint16_t resp_status, rsi_bt_event_a2dp_abort_t *a2dp_abort); + * @brief When A2DP abort event is raised from the module, this callback will be called. \n + * This event will be given by the module when a2dp abort happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_abort, contains the a2dp abort information, please refer \ref rsi_bt_event_a2dp_abort_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_abort_t)(uint16_t resp_status, rsi_bt_event_a2dp_abort_t *a2dp_abort); + +/** + * @typedef void (*rsi_bt_on_a2dp_close_t)(uint16_t resp_status, rsi_bt_event_a2dp_close_t *a2dp_close); + * @brief When A2DP close event is raised from the module, this callback will be called. \n + * This event will be given by the module when a2dp closed from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_close, contains the a2dp close information, please refer \ref rsi_bt_event_a2dp_close_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_close_t)(uint16_t resp_status, rsi_bt_event_a2dp_close_t *a2dp_close); + +/** + * @typedef void (*rsi_bt_on_a2dp_encode_data_t)(uint16_t resp_status, rsi_bt_event_a2dp_encode_data_t *a2dp_encode_data); + * @brief Callback function to be called if SBC data received from TA + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_encode_data, contains the SBC encoded packet information, please refer \ref rsi_bt_event_a2dp_encode_data_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_encode_data_t)(uint16_t resp_status, rsi_bt_event_a2dp_encode_data_t *a2dp_encode_data); + +/** + * @typedef void (*rsi_bt_on_a2dp_pcm_data_t)(uint16_t resp_status, rsi_bt_event_a2dp_pcm_data_t *a2dp_pcm_data); + * @brief Callback function to be called if PCM data is received from TA + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_pcm_data, contains the PCM audio data information + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_pcm_data_t)(uint16_t resp_status, rsi_bt_event_a2dp_pcm_data_t *a2dp_pcm_data); + +/** + * @typedef void (*rsi_bt_on_a2dp_data_req_t)(uint16_t resp_status, rsi_bt_event_a2dp_more_data_req_t *a2dp_more_data_req); + * @brief Callback function to be called if more data request evenis received + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_more_data_req, contains the a2dp_more_data_req information + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_data_req_t)(uint16_t resp_status, rsi_bt_event_a2dp_more_data_req_t *a2dp_more_data_req); + +/** + * @typedef void (*rsi_bt_on_a2dp_reconfig_t)(uint16_t resp_status, rsi_bt_event_a2dp_reconfig_t *a2dp_reconfig); + * @brief When A2DP Reconfig event is raised from the module, this callback will be called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] a2dp_reconfig, contains the a2dp reconfig information, please refer \ref rsi_bt_event_a2dp_reconfig_s structure for more info + * @return void + * @note This callback has to be registered using rsi_bt_a2dp_register_callbacks API + */ +typedef void (*rsi_bt_on_a2dp_reconfig_t)(uint16_t resp_status, rsi_bt_event_a2dp_reconfig_t *a2dp_reconfig); +/** @} */ +/****************************************************** + * * BT A2DP Callbacks register function Declarations + * ******************************************************/ + +/*==============================================*/ + +/** + * @fn rsi_bt_spp_register_callbacks + * @brief This function registers the SPP callbacks + * @param[in] rsi_bt_on_a2dp_connect_t bt_on_a2dp_connect_event : a2dp connection status callback + * @param[in] rsi_bt_on_a2dp_disconnect_t bt_on_a2dp_disconnect_event : a2dp disconnection status callback + * @param[in] rsi_bt_on_a2dp_configure_t bt_on_a2dp_configure_event : a2dp configure status callback + * @param[in] rsi_bt_on_a2dp_open_t bt_on_a2dp_open_event : a2dp open status callback + * @param[in] rsi_bt_on_a2dp_start_t bt_on_a2dp_start_event : a2dp start status callback + * @param[in] rsi_bt_on_a2dp_suspend_t bt_on_a2dp_suspend_event : a2dp suspend status callback + * @param[in] rsi_bt_on_a2dp_abort_t bt_on_a2dp_abort_event : a2dp abort status callback + * @param[in] rsi_bt_on_a2dp_close_t bt_on_a2dp_close_event : a2dp close status callback + * @param[in] rsi_bt_on_a2dp_encode_data_t bt_on_a2dp_encode_data_event : a2dp SBC packet received callback + * @param[in] rsi_bt_on_a2dp_pcm_data_t bt_on_a2dp_pcm_data_event : a2dp PCM packet received callback + * @param[in] rsi_bt_on_a2dp_data_req_t rsi_bt_on_a2dp_data_req_t : a2dp data request received callback + * @param[in] rsi_bt_on_a2dp_reconfig_t bt_on_a2dp_reconfig_event : a2dp reconfig status callback + * @return + * Non zero - If fails + * 0 - If success + * + * + */ +void rsi_bt_a2dp_register_callbacks(rsi_bt_on_a2dp_connect_t bt_on_a2dp_connect_event, + rsi_bt_on_a2dp_disconnect_t bt_on_a2dp_disconnect_event, + rsi_bt_on_a2dp_configure_t bt_on_a2dp_configure_event, + rsi_bt_on_a2dp_open_t bt_on_a2dp_open_event, + rsi_bt_on_a2dp_start_t bt_on_a2dp_start_event, + rsi_bt_on_a2dp_suspend_t bt_on_a2dp_suspend_event, + rsi_bt_on_a2dp_abort_t bt_on_a2dp_abort_event, + rsi_bt_on_a2dp_close_t bt_on_a2dp_close_event, + rsi_bt_on_a2dp_encode_data_t bt_on_a2dp_encode_data_event, + rsi_bt_on_a2dp_pcm_data_t bt_on_a2dp_pcm_data_event, + rsi_bt_on_a2dp_data_req_t bt_on_a2dp_data_req_t, + rsi_bt_on_a2dp_reconfig_t bt_on_a2dp_reconfig_event); + +/* AVRCP Profile */ +typedef struct rsi_bt_event_avrcp_connect_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_avrcp_connect_t; + +typedef struct rsi_bt_event_avrcp_disconnect_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_avrcp_disconnect_t; + +typedef struct rsi_bt_event_avrcp_play_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_play_t; + +typedef struct rsi_bt_event_avrcp_pause_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_pause_t; + +typedef struct rsi_bt_event_avrcp_stop_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_stop_t; + +typedef struct rsi_bt_event_avrcp_next_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_next_t; + +typedef struct rsi_bt_event_avrcp_previous_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_previous_t; + +typedef struct rsi_bt_event_avrcp_vol_up_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_vol_up_t; + +typedef struct rsi_bt_event_avrcp_vol_down_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Status of the Button Pressed/Released + 0 - BUTTON_PUSHED, 1 - BUTTON_RELEASED*/ + uint8_t status_flag; +} rsi_bt_event_avrcp_vol_down_t; + +typedef struct rsi_bt_event_avrcp_get_elem_attr_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t pkt_type; + uint16_t param_len; + uint8_t param[512]; +} rsi_bt_event_avrcp_get_elem_attr_resp_t; + +typedef struct player_att_value_s { + + /** Attribute ID*/ + uint8_t attid; + + /** Attribute Value*/ + uint8_t attvalue; + + /** Reserved For Future Use*/ + uint8_t reserved[2]; +} player_att_value_t; + +typedef struct player_att_val_list_s { + uint8_t nbr_att; + player_att_value_t att_list[5]; +} player_att_val_list_t; + +typedef struct att_val_s { + /** Player application setting attribute ID for which the value is returned */ + uint8_t att_id; + + /** Currently set Player Application Setting value on the TG for \n + the above PlayerApplicationSettingA ttributeID.*/ + uint8_t att_val; + + /** Reserved for Future Purpose*/ + uint8_t reserved[2]; +} att_val_t; +#define MAX_ATT_VALS 5 +typedef struct att_val_list_s { + /** Please refer \ref att_val_s structure for more info*/ + att_val_t att_vals[MAX_ATT_VALS]; + + /** Number of player application setting attributes */ + uint8_t nbr_atts; +} att_val_list_t; + +typedef union notify_val_s { + /** Play Status \n + 0 - STOPPED\n + 1 - PLAYING\n + 2 - PAUSED\n + 3 - FWD_SEEK\n + 4 - REV_SEEK\n + FF - ERROR*/ + uint8_t player_status; + + /** Current Playing Track Index*/ + uint32_t track_num; + + /** Current playback position in millisecond */ + uint32_t track_pos; + + /** Battery Status \n + 0 - NORMAL \n + 1 - WARNING \n + 2 - CRITICAL \n + 3 - EXTERNAL \n + 4 - FULLCHARGE */ + uint8_t battery_status; + + /** System Status \n + 0 - POWER_ON \n + 1 - POWER_OFF \n + 2 - UNPLUGGED */ + uint8_t system_status; + + /** Absolute Volume Value*/ + uint8_t abs_vol; + + /** Media Player ID*/ + uint16_t playerid; + + /** Unique ID for the MediaPlayer*/ + uint16_t uidcounter; + + /** Please refer \ref att_val_list_s structure for more info*/ + att_val_list_t att_val_list; +} notify_val_t; + +typedef struct avrcp_notify_s { + + /** ID's for events received via Avrcp Registration Notification \n + #define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01 \n + #define AVRCP_EVENT_TRACK_CHANGED 0x02 \n + #define AVRCP_EVENT_TRACK_REACHED_END 0x03 \n + #define AVRCP_EVENT_TRACK_REACHED_START 0x04 \n + #define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05 \n + #define AVRCP_EVENT_BATT_STATUS_CHANGED 0x06 \n + #define AVRCP_EVENT_SYSTEM_STATUS_CHANGED 0x07 \n + #define AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED 0x08 \n + #define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09 \n + #define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0a \n + #define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0b \n + #define AVRCP_EVENT_UIDS_CHANGED 0x0c \n + #define AVRCP_EVENT_VOLUME_CHANGED 0x0d*/ + uint8_t eventid; + + uint8_t rtype; + uint8_t Reserved[2]; + /** The below structure variable has elements corresponding to the above event ID's \n + Please refer \ref notify_val_s structure for more info*/ + notify_val_t notify_val; + /* union notify_val_s { + uint8_t player_status; + uint32_t track_num; + uint32_t track_pos; + uint8_t batter_status; + uint8_t system_status; + player_att_val_list_t att_val_list; + } notify_val;*/ +} avrcp_notify_t; + +typedef struct rsi_bt_event_avrcp_notify_s { + + /** remote device address*/ + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + + /** Please refer \ref avrcp_notify_s structure for more info*/ + avrcp_notify_t notify_val; +} rsi_bt_event_avrcp_notify_t; +/** @addtogroup BT-CLASSIC7 +* @{ +*/ +/** + * @typedef void (*rsi_bt_on_avrcp_connect_t)(uint16_t resp_status, rsi_bt_event_avrcp_connect_t *bt_event_avrcp_connect); + * @brief When Avrcp Connect event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp connection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] avrcp_conn, contains the avrcp connected information, please refer \ref rsi_bt_event_avrcp_connect_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_connect_t)(uint16_t resp_status, rsi_bt_event_avrcp_connect_t *bt_event_avrcp_connect); + +/** + * @typedef void (*rsi_bt_on_avrcp_disconnect_t)(uint16_t resp_status, + * rsi_bt_event_avrcp_disconnect_t *bt_event_avrcp_disconnect); + * @brief When Avrcp Disconnect event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp connection happens from either side. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] avrcp_disconn, contains the avrcp disconnected information, please refer \ref rsi_bt_event_avrcp_disconnect_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_disconnect_t)(uint16_t resp_status, + rsi_bt_event_avrcp_disconnect_t *bt_event_avrcp_disconnect); + +/** + * @typedef void (*rsi_bt_on_avrcp_play_t)(uint16_t resp_status, rsi_bt_event_avrcp_play_t *bt_event_avrcp_play); + * @brief When Avrcp Play event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp play button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] avrcp_play, contains the avrcp play information, please refer \ref rsi_bt_event_avrcp_play_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_play_t)(uint16_t resp_status, rsi_bt_event_avrcp_play_t *bt_event_avrcp_play); + +/** + * @typedef void (*rsi_bt_on_avrcp_pause_t)(uint16_t resp_status, rsi_bt_event_avrcp_pause_t *bt_event_avrcp_pause); + * @brief When Avrcp Pause event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp pause button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note Refer Bluetooth Generic Error Codes section upto 0x4FF8 from \ref error-codes . + * @param[out] avrcp_pause, contains the avrcp pause information, please refer \ref rsi_bt_event_avrcp_pause_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_pause_t)(uint16_t resp_status, rsi_bt_event_avrcp_pause_t *bt_event_avrcp_pause); + +/** + * @typedef void (*rsi_bt_on_avrcp_stop_t)(uint16_t resp_status, rsi_bt_event_avrcp_stop_t *bt_event_avrcp_stop); + * @brief When Avrcp Stop event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp stop button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * non-zero value - errorcodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] avrcp_stop, contains the avrcp pause information, please refer \ref rsi_bt_event_avrcp_stop_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_stop_t)(uint16_t resp_status, rsi_bt_event_avrcp_stop_t *bt_event_avrcp_stop); + +/** + * @typedef void (*rsi_bt_on_avrcp_next_t)(uint16_t resp_status, rsi_bt_event_avrcp_next_t *bt_event_avrcp_next); + * @brief When Avrcp next event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp next button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * Non-Zero Value - ErrorCodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] avrcp_next, contains the avrcp next information, please refer \ref rsi_bt_event_avrcp_next_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_next_t)(uint16_t resp_status, rsi_bt_event_avrcp_next_t *bt_event_avrcp_next); + +/** + * @typedef void (*rsi_bt_on_avrcp_previous_t)(uint16_t resp_status, + * rsi_bt_event_avrcp_previous_t *bt_event_avrcp_previous); + * @brief When Avrcp Previous event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp Previous button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * non-zero value - errorcodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] avrcp_previous, contains the avrcp previous information, please refer \ref rsi_bt_event_avrcp_previous_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_previous_t)(uint16_t resp_status, + rsi_bt_event_avrcp_previous_t *bt_event_avrcp_previous); + +/** + * @typedef void (*rsi_bt_on_avrcp_vol_up_t)(uint16_t resp_status, rsi_bt_event_avrcp_vol_up_t *bt_event_avrcp_vol_up); + * @brief When Avrcp volume up event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp volume up button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * non-zero value - errorcodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] avrcp_vol_up, contains avrcp vol up info, please refer \ref rsi_bt_event_avrcp_vol_up_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_vol_up_t)(uint16_t resp_status, rsi_bt_event_avrcp_vol_up_t *bt_event_avrcp_vol_up); + +/** + * @typedef void (*rsi_bt_on_avrcp_vol_down_t)(uint16_t resp_status, + * rsi_bt_event_avrcp_vol_down_t *bt_event_avrcp_vol_down); + * @brief When Avrcp volume Down event is raised from the module, this callback will be called. \n + * This event will be given by the module when avrcp volume Down button pressed/Released from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * non-zero value - errorcodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] avrcp_vol_down, contains the avrcp vol down info, please refer \ref rsi_bt_event_avrcp_vol_down_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_vol_down_t)(uint16_t resp_status, + rsi_bt_event_avrcp_vol_down_t *bt_event_avrcp_vol_down); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_elem_attr_resp_t)(uint16_t resp_status, + * rsi_bt_event_avrcp_get_elem_attr_resp_t *avrcp_get_elem_attr_resp); + * @brief When Remote Devices Element Attributes is received this callback will be called. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * non-zero value - errorcodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] avrcp_get_elem_attr_resp, contains the avrcp get elem attr resp info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_elem_attr_resp_t)(uint16_t resp_status, + rsi_bt_event_avrcp_get_elem_attr_resp_t *avrcp_get_elem_attr_resp); + +/** + * @typedef void (*rsi_bt_on_avrcp_notify_event_t)(uint16_t resp_status, + * rsi_bt_event_avrcp_notify_t *bt_event_avrcp_notify); + * @brief Callback function is invoke when avrcp notification received from Control Device. + * @param[out] resp_status, contains the response status (Success or Error code) \n + * 0 - SUCCESS \n + * non-zero value - errorcodes + * @note refer bluetooth generic error codes section upto 0x4ff8 from \ref error-codes . + * @param[out] bt_event_avrcp_notify, contains the avrcp registered notifications information, \n + * please refer \ref rsi_bt_event_avrcp_notify_s structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_notify_event_t)(uint16_t resp_status, + rsi_bt_event_avrcp_notify_t *bt_event_avrcp_notify); +/** @} */ +/*==============================================*/ + +/** + * @fn rsi_bt_avrcp_register_callbacks + * @brief This function registers the AVRCP profile callbacks + * @param[in] rsi_bt_on_avrcp_connect_t bt_on_avrcp_connect_event : avrcp connection status callback + * @param[in] rsi_bt_on_avrcp_disconnect_t bt_on_avrcp_disconnect_event : avrcp disconnection status callback + * @param[in] rsi_bt_on_avrcp_play_t bt_on_avrcp_play_event : avrcp play status callback + * @param[in] rsi_bt_on_avrcp_pause_t bt_on_avrcp_pause_event : avrcp pause status callback + * @param[in] rsi_bt_on_avrcp_stop_t bt_on_avrcp_stop_event : avrcp stop status callback + * @param[in] rsi_bt_on_avrcp_next_t bt_on_avrcp_next_event : avrcp next status callback + * @param[in] rsi_bt_on_avrcp_previous_t bt_on_avrcp_previous_event : avrcp previous status callback + * @param[in] rsi_bt_on_avrcp_vol_up_t bt_on_avrcp_vol_up_event : avrcp vol up status callback + * @param[in] rsi_bt_on_avrcp_vol_down_t bt_on_avrcp_vol_down_event : avrcp vol down status callback + * @return + * Non zero - If fails + * 0 - If success + * + * + */ +void rsi_bt_avrcp_register_callbacks(rsi_bt_on_avrcp_connect_t bt_on_avrcp_connect_event, + rsi_bt_on_avrcp_disconnect_t bt_on_avrcp_disconnect_event, + rsi_bt_on_avrcp_play_t bt_on_avrcp_play_event, + rsi_bt_on_avrcp_pause_t bt_on_avrcp_pause_event, + rsi_bt_on_avrcp_stop_t bt_on_avrcp_stop_event, + rsi_bt_on_avrcp_next_t bt_on_avrcp_next_event, + rsi_bt_on_avrcp_previous_t bt_on_avrcp_previous_event, + rsi_bt_on_avrcp_vol_up_t bt_on_avrcp_vol_up_event, + rsi_bt_on_avrcp_vol_down_t bt_on_avrcp_vol_down_event, + rsi_bt_on_avrcp_get_elem_attr_resp_t bt_on_avrcp_get_elem_attr_resp_event, + rsi_bt_on_avrcp_notify_event_t bt_on_avrcp_notify_event); + +#define AVRCP_MAX_APP_SUPP_ATTS 5 +#define AVRCP_MAX_APP_SUPP_ATT_VALS 5 +#define AVRCP_MAX_APP_SUPP_CHAR_SETS 5 +#define AVRCP_MAX_SONG_ATTS 10 + +typedef struct rsi_bt_event_avrcp_get_cur_att_val_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** Number of Attributes*/ + uint8_t nbr_atts; + + /** Attributes List \n + #define AVRCP_MAX_APP_SUPP_ATTS 5*/ + uint8_t atts[AVRCP_MAX_APP_SUPP_ATTS]; +} rsi_bt_event_avrcp_get_cur_att_val_t; + +typedef struct rsi_bt_event_avrcp_set_att_val_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** Number of Attributes*/ + uint8_t nbr_atts; + + /** Reserved for Future Use*/ + uint8_t reserved; + + /** Please refer \ref player_att_value_s structure for mote info \n + #define AVRCP_MAX_APP_SUPP_ATTS 5*/ + player_att_value_t att_list[AVRCP_MAX_APP_SUPP_ATTS]; +} rsi_bt_event_avrcp_set_att_val_t; + +typedef struct rsi_bt_event_avrcp_vals_text_req_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** ID of the Attribute*/ + uint8_t att_id; + + /** Number of Values Present in the given att_id*/ + uint8_t nbr_vals; + + /** Values List \n + #define AVRCP_MAX_APP_SUPP_ATT_VALS 5*/ + uint8_t vals[AVRCP_MAX_APP_SUPP_ATT_VALS]; +} rsi_bt_event_avrcp_vals_text_req_t; + +typedef struct rsi_bt_event_avrcp_char_sets_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** Number of Character Sets*/ + uint8_t nbr_sets; + + /** Reserved for Future Use*/ + uint8_t reserved; + + /** Character Sets List \n + #define AVRCP_MAX_APP_SUPP_CHAR_SETS 5*/ + uint16_t char_sets[AVRCP_MAX_APP_SUPP_CHAR_SETS]; +} rsi_bt_event_avrcp_char_sets_t; + +typedef struct rsi_bt_event_avrcp_ele_att_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** Number of Attributes*/ + uint8_t nbr_atts; + + /** Reserved for Future Use*/ + uint8_t reserved; + + /** Element Attributes List of a Track \n + #define AVRCP_MAX_SONG_ATTS 10*/ + uint32_t ele_atts[AVRCP_MAX_SONG_ATTS]; +} rsi_bt_event_avrcp_ele_att_t; + +typedef struct rsi_bt_event_avrcp_set_abs_vol_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** Absolute Volume*/ + uint8_t abs_vol; + uint8_t remote_req_or_cmd_resp; //0 - remote request event, 1 - host cmd resp +} rsi_bt_event_avrcp_set_abs_vol_t; +typedef struct rsi_bt_event_avrcp_set_addr_player_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** A Unique ID of a Media Player which is SET by Control Device*/ + uint16_t player_id; +} rsi_bt_event_avrcp_set_addr_player_t; + +typedef struct rsi_bt_event_avrcp_get_folder_items_s { + + /** remote device address*/ + uint8_t dev_addr[6]; + + /** Scope refers which List of folder items to be accessed at present \n + 0 - Media_Player_List \n + 1 - Virtual_File_System \n + 2 - Search \n + 3 - NowPlaying */ + uint8_t scope; + + /** The offset within the listing of the item, which should be the first \n + returned item. The first element in the listing is at offset 0.*/ + uint16_t start_item; + + /** The offset within the listing of the item which should be the final returned item. \n + If this is set to a value beyond what is available, the TG shall return items from the \n + provided Start Item index to the index of the final item. \n + If the End Item index is smaller than the Start Item index, the TG shall return an error. \n + If CT requests too many items, TG can respond with a sub-set of the requested items. */ + uint16_t end_item; + + /** Request the Attributes present on the attr_cnt value \n + 0x00 - All attributes are requested. \n + 0x01-0xFE - The following Attribute List contains this number of attributes. \n + 0xFF - No attributes are requested.*/ + uint8_t attr_cnt; +} rsi_bt_event_avrcp_get_folder_items_t; + +typedef struct rsi_bt_event_avrcp_get_tot_num_items_s { + + /** This array holds the device address of length 6 bytes*/ + uint8_t dev_addr[6]; + + /** Scope refers which List of folder items to be accessed at present \n + 0 - Media_Player_List \n + 1 - Virtual_File_System \n + 2 - Search \n + 3 - NowPlaying */ + uint8_t scope; +} rsi_bt_event_avrcp_get_tot_num_items_t; +/** @addtogroup BT-CLASSIC7 +* @{ +*/ +/** + * @typedef void (*rsi_bt_on_avrcp_get_cap_event_t)(uint8_t *bd_addr, uint8_t cap_type); + * @brief Callback function is invoke when we receive get capabilities request from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] cap_type, avrcp capabilities type. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_cap_event_t)(uint8_t *bd_addr, uint8_t cap_type); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_app_supp_atts_event_t)(uint8_t *bd_addr); + * @brief Callback function is invoke when we receive get application support attribute list request from remote device. + * @param[out] bd_addr, Remote bd address. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_app_supp_atts_event_t)(uint8_t *bd_addr); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_app_suup_att_vals_event_t)(uint8_t *bd_addr, uint8_t att_id); + * @brief Callback function is invoke when we receive get application support attribute values request from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] att_id, application attribute id. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_app_suup_att_vals_event_t)(uint8_t *bd_addr, uint8_t att_id); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_app_cur_att_val_event_t)(rsi_bt_event_avrcp_get_cur_att_val_t *p_att_list); + * @brief Callback function is invoke when we receive get application current attributes value request from remote device. + * @param[out] p_att_list, attribute list, please refer \ref rsi_bt_event_avrcp_get_cur_att_val_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_app_cur_att_val_event_t)(rsi_bt_event_avrcp_get_cur_att_val_t *p_att_list); + +/** + * @typedef void (*rsi_bt_on_avrcp_set_app_cur_att_val_event_t)(rsi_bt_event_avrcp_set_att_val_t *p_att_list); + * @brief Callback function is invoke when we receive set application curent attributes value request from remote device. + * @param[out] p_att_list, attribute list, please refer \ref rsi_bt_event_avrcp_set_att_val_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_set_app_cur_att_val_event_t)(rsi_bt_event_avrcp_set_att_val_t *p_att_list); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_app_att_text_event_t)(rsi_bt_event_avrcp_get_cur_att_val_t *p_att_list); + * @brief Callback function is invoke when we receive get application attributes text request from remote device. + * @param[out] p_att_list, attribute list, please refer \ref rsi_bt_event_avrcp_get_cur_att_val_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_app_att_text_event_t)(rsi_bt_event_avrcp_get_cur_att_val_t *p_att_list); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_app_att_vals_text_event_t)(rsi_bt_event_avrcp_vals_text_req_t *p_vals_list); + * @brief Callback function is invoke when we receive get application attribute values text request from remote device. + * @param[out] p_vals_list, attribute values list, please refer \ref rsi_bt_event_avrcp_vals_text_req_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_app_att_vals_text_event_t)(rsi_bt_event_avrcp_vals_text_req_t *p_vals_list); + +/** + * @typedef void (*rsi_bt_on_avrcp_supp_char_sets_event_t)(rsi_bt_event_avrcp_char_sets_t *p_char_sets); + * @brief Callback function is invoke when we receive inform character sets request from remote device. + * @param[out] p_char_sets, support character sets list, please refer \ref rsi_bt_event_avrcp_char_sets_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_supp_char_sets_event_t)(rsi_bt_event_avrcp_char_sets_t *p_char_sets); + +/** + * @typedef void (*rsi_bt_on_avrcp_batt_status_event_t)(uint8_t *bd_addr, uint8_t batt_status); + * @brief Callback function is invoke when we receive battery status from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] batt_status, battery status. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_batt_status_event_t)(uint8_t *bd_addr, uint8_t batt_status); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_song_atts_event_t)(rsi_bt_event_avrcp_ele_att_t *p_song_atts); + * @brief Callback function is invoke when we receive element/song attribute request from remote device. + * @param[out] p_song_atts, requested song attribute list, please refer \ref rsi_bt_event_avrcp_ele_att_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_song_atts_event_t)(rsi_bt_event_avrcp_ele_att_t *p_song_atts); + +/** + * @typedef void (*rsi_bt_on_avrcp_get_play_status_event_t)(uint8_t *bd_addr); + * @brief Callback function is invoke when we receive player status from remote device. + * @param[out] bd_addr, Remote bd address. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_play_status_event_t)(uint8_t *bd_addr); + +/** + * @typedef void (*rsi_bt_on_avrcp_reg_notify_event_t)(uint8_t *bd_addr, uint8_t event_id); + * @brief Callback function is invoke when we receive register notify event from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] event_id, Event for which the Control Device requires notifications + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_reg_notify_event_t)(uint8_t *bd_addr, uint8_t event_id); + +/** + * @typedef void (*rsi_bt_on_avrcp_set_abs_vol_event_t)(rsi_bt_event_avrcp_set_abs_vol_t *p_abs_vol); + * @brief Callback function is invoke when we receive set absolute volume event from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] p_abs_vol, avrcp absolute vol, please refer \ref rsi_bt_event_avrcp_set_abs_vol_s structure \n + * for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_set_abs_vol_event_t)(uint16_t resp_status, rsi_bt_event_avrcp_set_abs_vol_t *p_abs_vol); + +/** + * @typedef void (*rsi_bt_on_avrcp_set_addr_player_event_t)(rsi_bt_event_avrcp_set_addr_player_t *p_set_addr_player); + * @brief Callback function is invoke when we receive set address player event from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] p_set_addr_player, inform the Target Device of which media player the Control Device wishes to control, \n + * please refer \ref rsi_bt_event_avrcp_set_addr_player_s structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_set_addr_player_event_t)(rsi_bt_event_avrcp_set_addr_player_t *p_set_addr_player); + +/** + * @callback rsi_bt_on_avrcp_get_folder_items_event_t + * @brief Callback function is invoke when we receive get folder items event from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] p_get_folder_items, to get the media player items list in a folder, please refer \ref rsi_bt_event_avrcp_get_folder_items_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_folder_items_event_t)(rsi_bt_event_avrcp_get_folder_items_t *p_get_folder_items); + +/** + * @callback rsi_bt_on_avrcp_get_tot_num_items_event_t + * @brief Callback function is invoke when we receive get total number of items event from remote device. + * @param[out] bd_addr, Remote bd address. + * @param[out] p_get_tot_num_items, total number of items present in a folder, please refer \ref rsi_bt_event_avrcp_get_tot_num_items_s \n + * structure for more info. + * @return void + * @note This callback has to be registered using rsi_bt_avrcp_target_register_callbacks API + */ +typedef void (*rsi_bt_on_avrcp_get_tot_num_items_event_t)(rsi_bt_event_avrcp_get_tot_num_items_t *p_get_tot_num_items); +/** @} */ +/*==============================================*/ + +/** + * @fn rsi_bt_avrcp_target_register_callbacks + * @brief This function registers the avrcp target callbacks + * @param[in] rsi_bt_on_avrcp_get_cap_event_t bt_on_avrcp_gat_cap, + * @param[in] rsi_bt_on_avrcp_get_app_supp_atts_event_t bt_on_avrcp_get_app_att_list, + * @param[in] rsi_bt_on_avrcp_get_app_suup_att_vals_event_t bt_on_avrcp_get_app_att_vals_list, + * @param[in] rsi_bt_on_avrcp_get_app_cur_att_val_event_t bt_on_avrcp_get_app_cur_att_val, + * @param[in] rsi_bt_on_avrcp_set_app_cur_att_val_event_t bt_on_avrcp_set_app_cur_att_val, + * @param[in] rsi_bt_on_avrcp_get_app_att_text_event_t bt_on_avrcp_get_app_att_text, + * @param[in] rsi_bt_on_avrcp_get_app_att_vals_text_event_t bt_on_avrcp_get_app_att_vals_text, + * @param[in] rsi_bt_on_avrcp_supp_char_sets_event_t bt_on_avrcp_supp_char_sets, + * @param[in] rsi_bt_on_avrcp_batt_status_event_t bt_on_avrcp_batt_status, + * @param[in] rsi_bt_on_avrcp_get_song_atts_event_t bt_on_avrcp_get_song_atts, + * @param[in] rsi_bt_on_avrcp_get_play_status_event_t bt_on_avrcp_get_player_status, + * @param[in] rsi_bt_on_avrcp_reg_notify_event_t bt_on_avrcp_reg_notifivation); + * @param[in] rsi_bt_on_avrcp_set_abs_vol_event_t bt_on_avrcp_set_abs_vol); + * + * @return + * Non zero - If fails + * 0 - If success + * + * + */ +void rsi_bt_avrcp_target_register_callbacks( + rsi_bt_on_avrcp_get_cap_event_t bt_on_avrcp_gat_cap, + rsi_bt_on_avrcp_get_app_supp_atts_event_t bt_on_avrcp_get_app_att_list, + rsi_bt_on_avrcp_get_app_suup_att_vals_event_t bt_on_avrcp_get_app_att_vals_list, + rsi_bt_on_avrcp_get_app_cur_att_val_event_t bt_on_avrcp_get_app_cur_att_val, + rsi_bt_on_avrcp_set_app_cur_att_val_event_t bt_on_avrcp_set_app_cur_att_val, + rsi_bt_on_avrcp_get_app_att_text_event_t bt_on_avrcp_get_app_att_text, + rsi_bt_on_avrcp_get_app_att_vals_text_event_t bt_on_avrcp_get_app_att_vals_text, + rsi_bt_on_avrcp_supp_char_sets_event_t bt_on_avrcp_supp_char_sets, + rsi_bt_on_avrcp_batt_status_event_t bt_on_avrcp_batt_status, + rsi_bt_on_avrcp_get_song_atts_event_t bt_on_avrcp_get_song_atts, + rsi_bt_on_avrcp_get_play_status_event_t bt_on_avrcp_get_player_status, + rsi_bt_on_avrcp_reg_notify_event_t bt_on_avrcp_reg_notifivation, + rsi_bt_on_avrcp_set_abs_vol_event_t bt_on_avrcp_set_abs_vol, + rsi_bt_on_avrcp_set_addr_player_event_t bt_on_avrcp_set_addr_player, + rsi_bt_on_avrcp_get_folder_items_event_t bt_on_avrcp_get_folder_items, + rsi_bt_on_avrcp_get_tot_num_items_event_t bt_on_avrcp_get_tot_num_items); + +/* HFP Profile */ +typedef struct rsi_bt_event_hfp_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_connect_t; + +typedef struct rsi_bt_event_hfp_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_disconnect_t; + +typedef struct rsi_bt_event_hfp_ring_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_ring_t; +typedef struct rsi_bt_event_hfp_callstatus_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t call_status; +} rsi_bt_event_hfp_callstatus_t; + +typedef struct rsi_bt_event_hfp_callsetup_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t call_setup; +} rsi_bt_event_hfp_callsetup_t; + +typedef struct rsi_bt_event_hfp_audioconn_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_audioconn_t; + +typedef struct rsi_bt_event_hfp_audiodisconn_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_audiodisconn_t; + +typedef struct rsi_bt_event_hfp_signalstrength_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t signal_strength; +} rsi_bt_event_hfp_signalstrength_t; + +typedef struct rsi_bt_event_hfp_batterylevel_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t battery_status; +} rsi_bt_event_hfp_batterylevel_t; + +typedef struct rsi_bt_event_hfp_dialcomp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_dialcomp_t; + +typedef struct rsi_bt_event_hfp_anscomp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_anscomp_t; + +typedef struct rsi_bt_event_hfp_hangupcomp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_hangupcomp_t; + +typedef struct rsi_bt_event_hfp_senddtmfcomp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_senddtmfcomp_t; + +typedef struct rsi_bt_event_hfp_phoneservice_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t service; +} rsi_bt_event_hfp_phoneservice_t; + +typedef struct rsi_bt_event_hfp_roamstatus_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t status; +} rsi_bt_event_hfp_roamstatus_t; + +typedef struct rsi_bt_event_hfp_calheldrelease_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_calheldrelease_t; + +typedef struct rsi_bt_event_hfp_callheld_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t held_status; + +} rsi_bt_event_hfp_callheld_t; + +typedef struct rsi_bt_event_hfp_audio_codecselect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t codec_val; +} rsi_bt_event_hfp_audio_codecselect_t; + +typedef struct rsi_bt_event_hfp_voice_data_s { + uint16_t sco_handle; + uint8_t length; +#ifdef MXRT_595s + uint8_t voice_data[0]; +#endif +} rsi_bt_event_hfp_voice_data_t; + +typedef struct rsi_bt_event_hfp_calwait_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_calwait_t; +typedef struct rsi_bt_event_hfp_servnotfound_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_servnotfound_t; + +typedef struct rsi_bt_event_hfp_voicerecogactivated_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_voicerecogactivated_t; + +typedef struct rsi_bt_event_hfp_voicerecogdeactivated_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_hfp_voicerecogdeactivated_t; + +typedef struct rsi_bt_event_hfp_dialnum_s { + uint8_t dial_num[10]; +} rsi_bt_event_hfp_dialnum_t; + +typedef struct rsi_bt_event_hfp_spkgain_s { + uint8_t spk_gain; +} rsi_bt_event_hfp_spkgain_t; + +typedef struct rsi_bt_event_hfp_micgain_s { + uint8_t mic_gain; +} rsi_bt_event_hfp_micgain_t; + +typedef struct rsi_bt_event_hfp_phonenumber_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t PhoneNbr[21]; + uint8_t PhoneType; + uint8_t PhoneNbrType; +} rsi_bt_event_phonenum_t; + +/****************************************************** + * * BT HFP Response Callbacks Declarations + * ******************************************************/ + +/** + * @callback rsi_bt_on_hfp_connect_t + * @brief Callback function to be called if profiles list response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] hfp_connect, contains the hfp connect information + * @return void + * @section description + * This callback function will be called if hfp connection happens. + * This callback has to be registered using rsi_bt_spp_register_callbacks API + */ +typedef void (*rsi_bt_on_hfp_connect_t)(uint16_t resp_status, rsi_bt_event_hfp_connect_t *hfp_connect); +typedef void (*rsi_bt_on_hfp_disconnect_t)(uint16_t resp_status, rsi_bt_event_hfp_disconnect_t *hfp_disconn); +typedef void (*rsi_bt_on_hfp_ring_t)(uint16_t resp_status, rsi_bt_event_hfp_ring_t *hfp_ring); +typedef void (*rsi_bt_on_hfp_callcallerid_t)(uint16_t resp_status, rsi_bt_event_phonenum_t *phonenum); +typedef void (*rsi_bt_on_hfp_audioconnected_t)(uint16_t resp_status, rsi_bt_event_hfp_audioconn_t *audioconn); +typedef void (*rsi_bt_on_hfp_audiodisconnected_t)(uint16_t resp_status, rsi_bt_event_hfp_audiodisconn_t *audiodisconn); +typedef void (*rsi_bt_on_hfp_dialcomplete_t)(uint16_t resp_status, rsi_bt_event_hfp_dialcomp_t *dialcomp); +typedef void (*rsi_bt_on_hfp_answercomplete_t)(uint16_t resp_status, rsi_bt_event_hfp_anscomp_t *anscomp); +typedef void (*rsi_bt_on_hfp_hangupcomplete_t)(uint16_t resp_status, rsi_bt_event_hfp_hangupcomp_t *hangupcomp); +typedef void (*rsi_bt_on_hfp_senddtmfcomplete_t)(uint16_t resp_status, rsi_bt_event_hfp_senddtmfcomp_t *senddtmfcomp); +typedef void (*rsi_bt_on_hfp_callwait_t)(uint16_t resp_status, rsi_bt_event_hfp_calwait_t *callwait); +typedef void (*rsi_bt_on_hfp_callvoicerecogdeactivated_t)( + uint16_t resp_status, + rsi_bt_event_hfp_voicerecogdeactivated_t *voicerecog_deactivated); +typedef void (*rsi_bt_on_hfp_callvoicerecogactivated_t)(uint16_t resp_status, + rsi_bt_event_hfp_voicerecogactivated_t *voicerecog_activated); +typedef void (*rsi_bt_on_hfp_servicenotfound_t)(uint16_t resp_status, rsi_bt_event_hfp_servnotfound_t *servnotfound); +typedef void (*rsi_bt_app_on_hfp_callstatus_t)(uint16_t resp_status, rsi_bt_event_hfp_callstatus_t *callstatus); +typedef void (*rsi_bt_app_on_hfp_signalstrength_t)(uint16_t resp_status, + rsi_bt_event_hfp_signalstrength_t *signalstrength); +typedef void (*rsi_bt_app_on_hfp_batterylevel_t)(uint16_t resp_status, rsi_bt_event_hfp_batterylevel_t *batterylevel); +typedef void (*rsi_bt_app_on_hfp_phoneservice_t)(uint16_t resp_status, rsi_bt_event_hfp_phoneservice_t *phoneservice); +typedef void (*rsi_bt_app_on_hfp_roamingstatus_t)(uint16_t resp_status, rsi_bt_event_hfp_roamstatus_t *roamstatus); +typedef void (*rsi_bt_app_on_hfp_callsetup_t)(uint16_t resp_status, rsi_bt_event_hfp_callsetup_t *callsetup); +typedef void (*rsi_bt_app_on_hfp_callheld_t)(uint16_t resp_status, rsi_bt_event_hfp_callheld_t *callheld); +typedef void (*rsi_bt_app_on_hfp_voice_data_t)(uint16_t resp_status, rsi_bt_event_hfp_voice_data_t *voice_data); +typedef void (*rsi_bt_app_on_hfp_audio_codecselect_t)(uint16_t resp_status, + rsi_bt_event_hfp_audio_codecselect_t *codecvalue); + +/****************************************************** + * * BT HFP Callbacks register function Declarations + * ******************************************************/ + +/*==============================================*/ +/** + * @fn rsi_bt_hfp_register_callbacks + * @brief This function registers the HFP callbacks + * @param[in] rsi_bt_on_hfp_connect_t bt_on_hfp_connect_event : HFP connection status callback + * @param[in] rsi_bt_on_hfp_disconnect_t bt_on_hfp_disconnect_event : HFP disconnection status callback + * @param[in] rsi_bt_on_hfp_ring_t bt_on_hfp_ring_event : HFP call ring status callback + * @return + * Non zero - If fails + * 0 - If success + * + */ + +void rsi_bt_hfp_register_callbacks(rsi_bt_on_hfp_connect_t bt_on_hfp_connect_event, + rsi_bt_on_hfp_disconnect_t bt_on_hfp_disconnect_event, + rsi_bt_on_hfp_ring_t bt_on_hfp_ring_event, + rsi_bt_on_hfp_callcallerid_t bt_on_hfp_callcallerid_event, + rsi_bt_on_hfp_audioconnected_t bt_on_hfp_audioconnected_event, + rsi_bt_on_hfp_audiodisconnected_t bt_on_hfp_audiodisconnected_event, + rsi_bt_on_hfp_dialcomplete_t bt_on_hfp_dialcomplete_event, + rsi_bt_on_hfp_answercomplete_t bt_on_hfp_answercomplete_event, + rsi_bt_on_hfp_hangupcomplete_t bt_on_hfp_hangupcomplete_event, + rsi_bt_on_hfp_senddtmfcomplete_t bt_on_hfp_senddtmfcomplete_event, + rsi_bt_on_hfp_callwait_t bt_on_hfp_callwait_event, + rsi_bt_on_hfp_callvoicerecogdeactivated_t bt_on_hfp_callvoicerecogdeactivated_event, + rsi_bt_on_hfp_callvoicerecogactivated_t bt_on_hfp_callvoicerecogactivated_event, + rsi_bt_on_hfp_servicenotfound_t bt_on_hfp_servicenotfound_event, + rsi_bt_app_on_hfp_callstatus_t bt_on_hfp_callstatus_event, + rsi_bt_app_on_hfp_signalstrength_t bt_on_hfp_signalstrength_event, + rsi_bt_app_on_hfp_batterylevel_t bt_on_hfp_batterylevel_event, + rsi_bt_app_on_hfp_phoneservice_t bt_on_hfp_phoneservice_event, + rsi_bt_app_on_hfp_roamingstatus_t bt_on_hfp_roamingstatus_event, + rsi_bt_app_on_hfp_callsetup_t bt_on_hfp_callsetup_event, + rsi_bt_app_on_hfp_callheld_t bt_on_hfp_callheld_event, + rsi_bt_app_on_hfp_voice_data_t bt_on_hfp_voice_data_event, + rsi_bt_app_on_hfp_audio_codecselect_t bt_on_hfp_audio_codecselect_event); + +/* PBAP Profile */ +typedef struct rsi_bt_event_pbap_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_pbap_connect_t; + +typedef struct rsi_bt_event_pbap_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_event_pbap_disconnect_t; + +typedef struct rsi_bt_event_pbap_data_s { + uint8_t PhoneNbr[13]; + uint8_t Name[30]; +} rsi_bt_event_pbap_data_t; + +/****************************************************** + * * BT PBAP Response Callbacks Declarations + * ******************************************************/ + +/** + * @typedef void (*rsi_bt_on_pbap_connect_t)(uint16_t resp_status, rsi_bt_event_pbap_connect_t *pbap_connect); + * @brief Callback function to be called if pbap connect response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] pbap_connect, contains the pbap connect information + * @return void + */ +typedef void (*rsi_bt_on_pbap_connect_t)(uint16_t resp_status, rsi_bt_event_pbap_connect_t *pbap_connect); +/** + * @typedef void (*rsi_bt_on_pbap_disconnect_t)(uint16_t resp_status, rsi_bt_event_pbap_disconnect_t *pbap_disconn); + * @brief Callback function to be called if pbap disconnect response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] pbap_disconnect, contains the pbap connect information + * @return void + */ + +typedef void (*rsi_bt_on_pbap_disconnect_t)(uint16_t resp_status, rsi_bt_event_pbap_disconnect_t *pbap_disconn); +/** + * @typedef void (*rsi_bt_on_pbap_data_t)(uint16_t resp_status, rsi_bt_event_pbap_data_t *pbap_data); + * @brief Callback function to be called if pbap data response is received + * @param[in] resp_status, contains the response status (Success or Error code) + * @param[in] pbap_data, contains the pbap data information + * @return void + */ + +typedef void (*rsi_bt_on_pbap_data_t)(uint16_t resp_status, rsi_bt_event_pbap_data_t *pbap_data); + +/****************************************************** + * * BT PBAP Callbacks register function Declarations + * ******************************************************/ + +/*==============================================*/ +/** + * @fn rsi_bt_pbap_register_callbacks + * @brief This function registers the PBAP callbacks + * @param[in] rsi_bt_on_pbap_connect_t bt_on_pbap_connect_event : PBAP connection status callback + * @param[in] rsi_bt_on_pbap_disconnect_t bt_on_pbap_disconnect_event : PBAP disconnection status callback + * @param[in] rsi_bt_on_pbap_data_t bt_on_pbap_data_event : PBAP data status callback + * @return + * Non zero - If fails + * 0 - If success + * + * + */ + +void rsi_bt_pbap_register_callbacks(rsi_bt_on_pbap_connect_t bt_on_pbap_connect_event, + rsi_bt_on_pbap_disconnect_t bt_on_pbap_disconnect_event, + rsi_bt_on_pbap_data_t bt_on_pbap_data_event); +/*==============================================*/ +/* + * @fn rsi_bt_add_device_id + * @brief To add device identification for local device + * @param[in] Specification ID + * Vendor ID + * Product ID + * Version + * Primary record + * Vendor ID source + * @return int32_t + * 0 = success + * !0 = failure + * @section description + * This function is used to add the device id in the SDP. + +-------------------------------------------------------------------------------------------------*/ +int32_t rsi_bt_add_device_id(uint16_t spec_id, + uint16_t vendor_id, + uint16_t product_id, + uint16_t version, + int primary_rec, + uint16_t vendor_id_source); + +/** + * @fn rsi_bt_set_sdp_attr_id + */ +uint32_t rsi_bt_set_sdp_attr_id(rsi_sdp_att_record_t *att_rec, + uint16_t attr_id, + uint16_t pattr_buf_idx, + uint16_t attr_buf_len); + +/** + * @fn rsi_bt_add_sdp_attribute + */ +uint32_t rsi_bt_add_sdp_attribute(rsi_sdp_att_record_t *att_rec, + uint16_t attr_id, + uint8_t att_data_8, + uint16_t att_data_16, + uint8_t is_boolean, + uint8_t param_len); + +/** + * @fn rsi_bt_add_sdp_hid_language_attribute + */ +uint32_t rsi_bt_add_sdp_hid_language_attribute(rsi_sdp_att_record_t *att_record_data, + uint16_t lang_id, + uint16_t lang_attr_base); + +/** + * @fn rsi_bt_add_sdp_hid_descriptor_list + */ +uint32_t rsi_bt_add_sdp_hid_descriptor_list(rsi_sdp_att_record_t *att_record_data, uint8_t *buff_ptr, uint8_t buff_len); + +/** + * @fn rsi_bt_add_sdp_service_attribute + */ +uint32_t rsi_bt_add_sdp_service_attribute(rsi_sdp_att_record_t *att_rec, + char *service_name, + uint8_t name_len, + uint16_t attr_id); + +/** + * @fn rsi_bt_add_sdp_service_classid + */ +uint32_t rsi_bt_add_sdp_service_classid(rsi_sdp_att_record_t *att_rec, uint16_t serv_class_uuid); + +/** + * @fn rsi_bt_add_sdp_service_handle + */ +uint32_t rsi_bt_add_sdp_service_handle(rsi_sdp_att_record_t *att_rec, uint32_t serv_hndl); + +/** + * @fn rsi_bt_add_sdp_protocol_list + */ +uint32_t rsi_bt_add_sdp_protocol_list(rsi_sdp_att_record_t *att_rec, + bt_sdp_proto_desc_list_elem_t *list, + uint8_t list_cnt, + uint16_t attr_id); + +/** + * @fn rsi_bt_add_sdp_language_base_attributeid_list + */ +uint32_t rsi_bt_add_sdp_language_base_attributeid_list(rsi_sdp_att_record_t *att_rec, + bt_sdp_lang_attr_id_elem_t *list, + uint8_t list_cnt); + +/** + * @fn rsi_bt_add_sdp_profile_descriptor_list + */ +uint32_t rsi_bt_add_sdp_profile_descriptor_list(rsi_sdp_att_record_t *att_rec, + uint16_t profile_uuid, + uint16_t profile_version); + +/** + * @fn rsi_bt_add_sdp_service_record_handle + */ +uint32_t rsi_bt_add_sdp_service_record_handle(rsi_sdp_att_record_t *att_rec, uint32_t serv_hndl); + +// A2DP Connect command +typedef struct rsi_bt_req_a2dp_connect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_connect_t; + +// A2DP disconnect command +typedef struct rsi_bt_req_a2dp_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_disconnect_t; + +// A2DP pcm/mp3 data structure +typedef struct rsi_bt_req_a2dp_pcm_mp3_data_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t pcm_mp3_data_len : 12; + uint16_t audio_type : 4; + uint8_t pcm_mp3_data[512 * 7]; //[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_req_a2dp_pcm_mp3_data_t; + +// A2DP sbc data command +typedef struct rsi_bt_req_a2dp_sbc_aac_data_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint16_t sbc_aac_data_len : 12; + uint16_t audio_type : 4; + uint8_t reserved[13]; // RTP_HEADER_LEN + uint8_t sbc_aac_data[RSI_BT_MAX_PAYLOAD_SIZE]; +} rsi_bt_req_a2dp_sbc_aac_data_t; + +// A2DP request start command +typedef struct rsi_bt_req_a2dp_start_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_start_t; + +// A2DP request suspend command +typedef struct rsi_bt_req_a2dp_suspend_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_suspend_t; + +// A2DP request close command +typedef struct rsi_bt_req_a2dp_close_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_close_t; + +// A2DP request abort command +typedef struct rsi_bt_req_a2dp_abort_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_abort_t; + +// AVRCP profile command +// AVRCP profile connect command +typedef struct rsi_bt_req_avrcp_conn_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_conn_t; + +// AVRCP profile disconnect command +typedef struct rsi_bt_req_avrcp_disconnect_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_disconnect_t; + +typedef struct rsi_bt_a2dp_sbc_codec_cap_s { + + /** Channel Mode for SBC \n + #define SBC_CHANNEL_MODE_MONO (1 << 3) \n + #define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) \n + #define SBC_CHANNEL_MODE_STEREO (1 << 1) \n + #define SBC_CHANNEL_MODE_JOINT_STEREO (1 << 0)*/ + uint8_t ChannelMode : 4; + + /** Sampling Frequency for SBC \n + #define SBC_SAMPLING_FREQ_16000 (1 << 3) \n + #define SBC_SAMPLING_FREQ_32000 (1 << 2) \n + #define SBC_SAMPLING_FREQ_44100 (1 << 1) \n + #define SBC_SAMPLING_FREQ_48000 (1 << 0)*/ + uint8_t Freq : 4; + + /** Allocation Method for SBC \n + #define SBC_ALLOCATION_SNR (1 << 1) \n + #define SBC_ALLOCATION_LOUDNESS (1 << 0)*/ + uint8_t AllocMethod : 2; + + /** Number of Subbands for SBC \n + #define SBC_SUBBANDS_4 (1 << 1) \n + #define SBC_SUBBANDS_8 (1 << 0)*/ + uint8_t SubBands : 2; + + /** Block Length for SBC \n + #define SBC_BLOCK_LENGTH_4 (1 << 3) \n + #define SBC_BLOCK_LENGTH_8 (1 << 2) \n + #define SBC_BLOCK_LENGTH_12 (1 << 1) \n + #define SBC_BLOCK_LENGTH_16 (1 << 0)*/ + uint8_t BlockLength : 4; + + /** The frame_length and bitrate will be calculated \n + based on bitpool value and Sampling Frequency \n + #define SBC_MIN_BITPOOL 2*/ + uint8_t MinBitPool; + + /** The frame_length and bitrate will be calculated \n + based on bitpool value and Sampling Frequency \n + #define SBC_MAX_BITPOOL 53 \n + @note In Coex Environment, we are supporting MAX_BITPOOL as 35*/ + uint8_t MaxBitPool; +} rsi_bt_a2dp_sbc_codec_cap_t; + +typedef struct rsi_bt_req_a2dp_get_config_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_a2dp_get_config_t; + +typedef struct rsi_bt_resp_a2dp_get_config_s { + + /**Please refer \ref rsi_bt_a2dp_sbc_codec_cap_s structure for more info */ + rsi_bt_a2dp_sbc_codec_cap_t sbc_cap; + uint32_t status; +} rsi_bt_resp_a2dp_get_config_t; + +typedef struct rsi_bt_req_a2dp_set_config_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + rsi_bt_a2dp_sbc_codec_cap_t sbc_cap; +} rsi_bt_req_a2dp_set_config_t; + +typedef struct rsi_bt_resp_a2dp_set_config_s { + uint32_t err_status; +} rsi_bt_resp_a2dp_set_config_t; + +// AVRCP profile play song command +typedef struct rsi_bt_req_avrcp_play_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_play_t; + +// AVRCP profile pause song command +typedef struct rsi_bt_req_avrcp_pause_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_pause_t; + +// AVRCP profile stop song command +typedef struct rsi_bt_req_avrcp_stop_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_stop_t; + +// AVRCP profile next song command +typedef struct rsi_bt_req_avrcp_next_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_next_t; + +// AVRCP profile previous song command +typedef struct rsi_bt_req_avrcp_previous_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_previous_t; + +// AVRCP profile vol up command +typedef struct rsi_bt_req_avrcp_vol_up_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_vol_up_t; + +// AVRCP profile vol down command +typedef struct rsi_bt_req_avrcp_vol_down_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_vol_down_t; + +// AVRCP profile get capabilities command +typedef struct rsi_bt_req_avrcp_get_capabilities_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t type; +} rsi_bt_req_avrcp_get_capabilities_t; + +typedef struct rsi_bt_rsp_avrcp_get_capabilities_s { + /** Capability Count*/ + uint32_t nbr_ids; + + /** List of Ids Supported to the given capability type*/ + uint32_t ids[RSI_MAX_ATT]; +} rsi_bt_rsp_avrcp_get_capabilities_t; + +// AVRCP profile get attributes list command +typedef struct rsi_bt_req_avrcp_get_att_list_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_get_att_list_t; + +typedef struct rsi_bt_rsp_avrcp_get_atts_list_s { + /** Number of Attributes Provided*/ + uint8_t nbr_ids; + + /** Array of player application Setting attribute ID \n + #define BT_AVRCP_ILLEGAL_ATTRIBUTE 0x00 \n + #define BT_AVRCP_EQUALIZER_ATTRIBUTE 0x01 \n + #define BT_AVRCP_REPEAT_MODE_ATTRIBUTE 0x02 \n + #define BT_AVRCP_SHUFFLE_ATTRIBUTE 0x03 \n + #define BT_AVRCP_SCAN_ATTRIBUTE 0x04 */ + uint8_t att_ids[RSI_MAX_ATT]; +} rsi_bt_rsp_avrcp_get_atts_list_t; + +// AVRCP profile get attribute values list command +typedef struct rsi_bt_req_avrcp_get_att_vals_list_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t att_id; +} rsi_bt_req_avrcp_get_att_vals_list_t; + +typedef struct rsi_bt_rsp_avrcp_get_att_vals_list_s { + /** Number of player application setting values*/ + uint8_t nbr_vals; + + /** Equalizer ON/OFF Status Attr Values \n + #define BT_AVRCP_EQUALIZER_OFF 0x01 \n + #define BT_AVRCP_EQUALIZER_ON 0x02 \n + + Repeat Mode Status Attr Values \n + #define BT_AVRCP_REPEAT_OFF 0x01 \n + #define BT_AVRCP_REPEAT_SINGLE 0x02 \n + #define BT_AVRCP_REPEAT_ALL 0x03 \n + #define BT_AVRCP_REPEAT_GROUP 0x04 \n + + Shuffle ON/OFF Status Attr Values \n + #define BT_AVRCP_SHUFFLE_OFF 0x01 \n + #define BT_AVRCP_SHUFFLE_ALL 0x02 \n + #define BT_AVRCP_SHUFFLE_GROUP 0x03 \n + + Scan ON/OFF Status Attr Values \n + #define BT_AVRCP_SCAN_OFF 0x01 \n + #define BT_AVRCP_SCAN_ALL 0x02*/ + uint8_t att_vals[RSI_MAX_ATT]; +} rsi_bt_rsp_avrcp_get_att_vals_list_t; + +// AVRCP profile get current attribute value command +typedef struct rsi_bt_req_avrcp_get_cur_att_val_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t nbr_atts; + uint8_t att_list[RSI_MAX_ATT]; +} rsi_bt_req_avrcp_get_cur_att_val_t; + +typedef struct rsi_bt_rsp_avrcp_get_cur_att_val_s { + /** Number of player application setting values*/ + uint8_t nbr_vals; + + /** Equalizer ON/OFF Status Attr Values \n + #define BT_AVRCP_EQUALIZER_OFF 0x01 \n + #define BT_AVRCP_EQUALIZER_ON 0x02 \n + + Repeat Mode Status Attr Values \n + #define BT_AVRCP_REPEAT_OFF 0x01 \n + #define BT_AVRCP_REPEAT_SINGLE 0x02 \n + #define BT_AVRCP_REPEAT_ALL 0x03 \n + #define BT_AVRCP_REPEAT_GROUP 0x04 \n + + Shuffle ON/OFF Status Attr Values \n + #define BT_AVRCP_SHUFFLE_OFF 0x01 \n + #define BT_AVRCP_SHUFFLE_ALL 0x02 \n + #define BT_AVRCP_SHUFFLE_GROUP 0x03 \n + + Scan ON/OFF Status Attr Values \n + #define BT_AVRCP_SCAN_OFF 0x01 \n + #define BT_AVRCP_SCAN_ALL 0x02*/ + uint8_t att_vals[RSI_MAX_ATT]; +} rsi_bt_rsp_avrcp_get_cur_att_val_t; + +// AVRCP profile Set current attribute value command + +typedef struct rsi_bt_req_avrcp_set_cur_att_val_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t nbr_atts; + uint8_t reserved; + att_val_t att_val_list[RSI_MAX_ATT]; +} rsi_bt_req_avrcp_set_cur_att_val_t; + +// AVRCP profile get song attribute value command +typedef struct rsi_bt_req_avrcp_get_ele_att_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t nbr_atts; + uint8_t reserved; + uint32_t att_list[RSI_MAX_ATT]; +} rsi_bt_req_avrcp_get_ele_att_t; + +typedef struct normal_time_s { + uint32_t org_time; + uint32_t min; + uint32_t sec; +} normal_time_t; + +typedef struct att_text_s { + /** Specifies the attribute/Value ID to be written*/ + uint32_t id; + + /** Specifies the character set ID to be displayed on CT*/ + uint16_t char_set_id; + + /** Length of the player application setting attribute/Value string*/ + uint16_t attr_text_len; + + /** Specifies the player application setting attribute/Value string in specified character set.*/ + uint8_t att_text[31]; +} att_text_t; +#define MAX_TEXT_LIST 7 +typedef struct player_att_text_s { + /** Please refer \ref att_text_s structure for more info*/ + att_text_t list[MAX_TEXT_LIST]; + + /** Number of Attributes/Values Provided*/ + uint8_t nbr_atts; +} player_att_text_t; + +typedef struct attr_list_s { + /** Specifies the attribute ID to be written*/ + uint32_t id; + + /** Specifies the character set ID to be displayed on CT*/ + uint16_t char_set_id; + + /** Length of the value of the attribute*/ + uint16_t attr_len; + + /** Attribute Name in specified character set*/ + uint8_t attr_val[499]; +} attr_list_t; +#define MAX_ATT_LIST 7 +typedef struct elem_attr_list_s { + /** Number of attributes provided*/ + uint8_t num_attrs; + + /** Please refer \ref attr_list_s structure for more info*/ + attr_list_t attr_list[MAX_ATT_LIST]; +} elem_attr_list_t; + +typedef struct rsi_bt_rsp_avrcp_get_ele_att_s { + player_att_text_t player_attr; +} rsi_bt_rsp_avrcp_get_ele_att_t; + +typedef struct rsi_bt_rsp_avrcp_elem_attr_s { + /** Please refer \ref elem_attr_list_s structure for more info*/ + elem_attr_list_t elem_attr_list; +} rsi_bt_rsp_avrcp_elem_attr_t; + +// AVRCP profile get player status command +typedef struct rsi_bt_req_avrcp_get_player_status_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_get_player_status_t; + +typedef struct rsi_bt_rsp_avrcp_get_player_status_s { + /** The total length of the playing song in milliseconds*/ + uint32_t song_len; + + /** The current position of the playing in milliseconds elapsed */ + uint32_t song_pos; + + /** Current Status of playing \n + STOPPED 0x00\n + PLAYING 0x01\n + PAUSED 0x02\n + FWD_SEEK 0x03\n + REV_SEEK 0x04\n + ERROR 0xFF*/ + uint8_t play_status; +} rsi_bt_rsp_avrcp_get_player_status_t; + +// AVRCP profile register notification event command +typedef struct rsi_bt_req_avrcp_reg_notification_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t event_id; +} rsi_bt_req_avrcp_reg_notification_t; + +// AVRCP profile get player status command +typedef struct rsi_bt_req_avrcp_remote_version_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_req_avrcp_remote_version_t; + +typedef struct rsi_bt_rsp_avrcp_remote_version_s { + + /** AVRCP Profile Version Info of Remote Device*/ + uint16_t version; + + /** Reserved For Future Use*/ + uint16_t reserved; +} rsi_bt_rsp_avrcp_remote_version_t; + +// AVRCP profile get attribute value text command +typedef struct rsi_bt_req_avrcp_get_att_val_text_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t att_id; + uint8_t nbr_vals; + uint8_t vals[RSI_MAX_ATT]; +} rsi_bt_req_avrcp_get_att_val_text_t; + +// AVRCP profile send the battery status command +typedef struct rsi_bt_req_avrcp_batt_status_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t batt_status; +} rsi_bt_req_avrcp_batt_status_t; + +// AVRCP profile send the support character sets command +#define MAX_SUPP_VALS 5 +typedef struct char_sets_s { + uint16_t supp_vals[MAX_SUPP_VALS]; + uint8_t nbr_sets; +} char_sets_t; + +typedef struct rsi_bt_req_avrcp_char_sets_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t Reserved[2]; + char_sets_t char_sets; +} rsi_bt_req_avrcp_char_sets_t; + +typedef struct rsi_bt_avrcp_set_abs_vol_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t rev; + uint8_t abs_vol; +} rsi_bt_avrcp_set_abs_vol_t; + +#define AVRCP_SUPP_CMP_CAP_ID 2 +#define AVRCP_SUPP_NOTIFYS_CAP_ID 3 +#define MAX_CAPS 10 +typedef struct rsi_bt_avrcp_cap_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t cap_type; + uint8_t nbr_caps; + uint32_t caps[MAX_CAPS]; +} rsi_bt_avrcp_cap_resp_t; + +typedef struct rsi_bt_avrcp_att_list_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t nbr_atts; + uint8_t atts[MAX_CAPS]; +} rsi_bt_avrcp_att_list_resp_t; + +typedef struct rsi_bt_avrcp_att_vals_list_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t nbr_vals; + uint8_t vals[MAX_CAPS]; +} rsi_bt_avrcp_att_vals_list_resp_t; + +typedef struct rsi_bt_avrcp_cur_att_vals_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + att_val_list_t att_list; +} rsi_bt_avrcp_cur_att_vals_resp_t; + +typedef struct rsi_bt_avrcp_set_att_vals_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t status; +} rsi_bt_avrcp_set_att_vals_resp_t; + +typedef struct rsi_bt_avrcp_elem_attr_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + elem_attr_list_t elem_attr_list; +} rsi_bt_avrcp_elem_attr_resp_t; + +typedef struct rsi_bt_avrcp_play_status_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t play_status; + uint8_t reserved; + uint32_t song_len; + uint32_t song_pos; +} rsi_bt_avrcp_play_status_resp_t; + +typedef union reg_notify_val_u { + uint8_t play_status; + uint8_t curr_track_idx[8]; + uint8_t curr_playback_pos[4]; + uint8_t batter_status; + uint8_t system_status; + uint8_t player_app_setting[3]; + uint16_t playerid; + uint16_t uidcounter; + uint8_t abs_vol; +} reg_notify_val_t; + +typedef struct rsi_bt_avrcp_reg_notify_interim_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t event_id; + uint8_t reserved; + reg_notify_val_t reg_notify_val; +} rsi_bt_avrcp_reg_notify_interim_resp_t; + +typedef struct rsi_bt_avrcp_reg_notifiy_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t status; +} rsi_bt_avrcp_reg_notify_resp_t; + +typedef struct rsi_bt_avrcp_att_text_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t reserved[2]; + player_att_text_t atts_text; +} rsi_bt_avrcp_att_text_resp_t; + +/* typedef union notify_val_s { + uint8_t player_status; + uint32_t track_num; + uint32_t track_pos; + uint8_t battery_status; + uint8_t system_status; + att_val_list_t att_val_list; +} notify_val_t; */ + +typedef struct rsi_bt_avrcp_notify_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t event_id; + uint8_t reserved; + notify_val_t notify_val; +} rsi_bt_avrcp_notify_t; + +typedef struct rsi_bt_avrcp_cmd_reject_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t pdu_id; + uint8_t status; +} rsi_bt_avrcp_cmd_reject_t; + +typedef struct rsi_bt_avrcp_set_abs_vol_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t abs_vol; +} rsi_bt_avrcp_set_abs_vol_resp_t; + +typedef struct rsi_bt_avrcp_set_addr_player_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t status; +} rsi_bt_avrcp_set_addr_player_resp_t; + +typedef struct folder_items_resp_s { + /** Identified by an UID*/ + uint16_t uidcntr; + + /** Number of items present in that Folder*/ + uint16_t numofitems; + + /** Item_Type \n + 1 - Media Player Item \n + 2 - Folder Item \n + 3 - Media Element Item \n + @note But this structure is declared for Media_Player_Item*/ + uint8_t itemtype; + + /** Lenth of the Items*/ + uint16_t itemlen; + + /** A unique identifier for this media player.*/ + uint16_t playerid; + + /** There are currently four base types of media player \n + BIT(0) - AUDIO_PLAYER (Eg: Mp3 Player) \n + BIT(1) - VIDEO_PLAYER (Eg: Mpeg4 Player) \n + BIT(2) - BROADCASTING_AUDIO (Eg: FM Radio) \n + BIT(3) - BROADCASTING_VIDEO (Eg: DVB-H Tuner) */ + uint8_t majorplayertype; + + /** There are Two defined SubTypes \n + BIT(0) - AUDIO_BOOK \n + BIT(1) - PODCAST*/ + uint32_t playersubtype; + + /** Current Play Status \n + 0 - STOPPED \n + 1 - PLAYING \n + 2 - PAUSED \n + 3 - FWD_SEEK \n + 4 - REV_SEEK \n + FF - ERROR*/ + uint8_t playstatus; + + /** Each Player on a TG announces its features to the CT in the PlayerFeatureBitmask*/ + uint8_t featurebitmask[16]; + + /** Specifies the character set ID to be displayed on CT*/ + uint16_t charsetid; + + /** Length of Displayable Name. The name length shall be limited such that a response \n + to a GetFolderItems containing one media player item fits within the maximum size of \n + AVRCP PDU which can be received by the CT. */ + uint16_t disnamelen; + + /** Displayable name of player */ + uint8_t disname[11]; +} folder_items_resp_t; + +typedef struct rsi_bt_avrcp_get_folder_items_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + folder_items_resp_t fldr_items; + uint8_t status; +} rsi_bt_avrcp_get_folder_items_resp_t; + +typedef struct rsi_bt_avrcp_get_tot_num_items_resp_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; + uint8_t status; + uint16_t uidcntr; + uint32_t numofitems; +} rsi_bt_avrcp_get_tot_num_items_resp_t; +#define RSI_BT_IAP_MAX_DATA_LEN 300 +typedef struct rsi_bt_iap_payload_s { + uint16_t len; + uint8_t data[1000]; +} rsi_bt_iap_payload_t; + +typedef struct rsi_bt_iap_cmds_info_s { + uint16_t len; + uint16_t cmd[20]; +} rsi_bt_iap_cmds_info_t; + +typedef struct rsi_bt_iap_File_transfer_info_s { + uint16_t len; + uint8_t state; + uint8_t FileTransferId; + uint8_t FileTransferSessionId; + uint8_t data[RSI_BT_IAP_MAX_DATA_LEN]; +} rsi_bt_iap_File_transfer_info_t; + +int32_t rsi_bt_a2dp_init(rsi_bt_a2dp_sbc_codec_cap_t *sbc_cap); +int32_t rsi_bt_a2dp_connect(uint8_t *remote_dev_addr); +int32_t rsi_bt_a2dp_disconnect(uint8_t *remote_dev_addr); + +#if (!TA_BASED_ENCODER) +int32_t rsi_bt_a2dp_send_pcm_mp3_data(uint8_t *remote_dev_addr, + uint8_t *pcm_mp3_data, + uint16_t pcm_mp3_data_len, + uint8_t audio_type, + uint16_t *bytes_consumed); +#else +int32_t rsi_bt_a2dp_send_pcm_mp3_data(uint8_t *remote_dev_addr, + uint8_t *pcm_mp3_data, + uint16_t pcm_mp3_data_len, + uint8_t audio_type); +#endif +int32_t rsi_bt_a2dp_send_sbc_aac_data(uint8_t *remote_dev_addr, + uint8_t *sbc_aac_data, + uint16_t sbc_aac_data_len, + uint8_t audio_type); +int32_t rsi_bt_a2dp_start(uint8_t *remote_dev_addr); +int32_t rsi_bt_a2dp_suspend(uint8_t *remote_dev_addr); +int32_t rsi_bt_a2dp_close(uint8_t *remote_dev_addr); +int32_t rsi_bt_a2dp_abort(uint8_t *remote_dev_addr); +int32_t rsi_bt_a2dp_get_config(uint8_t *remote_dev_addr, rsi_bt_resp_a2dp_get_config_t *sbc_resp_cap); +int32_t rsi_bt_a2dp_set_config(uint8_t *remote_dev_addr, rsi_bt_a2dp_sbc_codec_cap_t *set_sbc_cap, int32_t *status); +int32_t rsi_bt_app_sbc_encode(void); +int32_t rsi_sbc_encode(void); +int32_t rsi_bt_set_local_device_role(uint8_t *remote_dev_addr, uint8_t set_role, uint8_t *resp); +int32_t rsi_switch_proto(uint8_t type, void (*callback)(uint16_t mode, uint8_t *bt_disable)); + +int32_t rsi_bt_avrcp_init(uint8_t *avrcp_feature); +int32_t rsi_bt_avrcp_conn(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_disconn(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_play(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_pause(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_stop(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_next(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_previous(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_vol_up(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_vol_down(uint8_t *remote_dev_addr); +int32_t rsi_bt_avrcp_get_capabilities(uint8_t *remote_dev_addr, + uint8_t capability_type, + rsi_bt_rsp_avrcp_get_capabilities_t *cap_list); +int32_t rsi_bt_avrcp_get_att_list(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_get_atts_list_t *att_list); +int32_t rsi_bt_avrcp_get_att_vals_list(uint8_t *remote_dev_addr, + uint8_t att_id, + rsi_bt_rsp_avrcp_get_att_vals_list_t *att_vals_list); +int32_t rsi_bt_avrcp_get_cur_att_val(uint8_t *remote_dev_addr, + uint8_t *att_list, + uint8_t nbr_atts, + rsi_bt_rsp_avrcp_get_cur_att_val_t *att_vals_list); +int32_t rsi_bt_avrcp_set_cur_att_val(uint8_t *remote_dev_addr, att_val_t *val_list, uint8_t nbr_atts); +int32_t rsi_bt_avrcp_get_element_att(uint8_t *remote_dev_addr, + uint8_t *att_ids, + uint8_t nbr_atts, + rsi_bt_rsp_avrcp_elem_attr_t *att_vals); +int32_t rsi_bt_avrcp_get_play_status(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_get_player_status_t *play_status); +int32_t rsi_bt_avrcp_reg_notification(uint8_t *remote_dev_addr, uint8_t event_id, uint8_t *p_resp_val); +int32_t rsi_bt_avrcp_get_remote_version(uint8_t *remote_dev_addr, rsi_bt_rsp_avrcp_remote_version_t *version); +int32_t rsi_bt_avrcp_get_att_text(uint8_t *remote_dev_addr, + uint8_t nbr_atts, + uint8_t *p_atts, + player_att_text_t *p_att_text_resp); +int32_t rsi_bt_avrcp_get_att_val_text(uint8_t *remote_dev_addr, + uint8_t att_id, + uint8_t nbr_vals, + uint8_t *p_vals, + player_att_text_t *p_att_text_resp); +int32_t rsi_bt_avrcp_batt_status(uint8_t *remote_dev_addr, uint8_t batt_level); +int32_t rsi_bt_avrcp_supp_char_sets(uint8_t *remote_dev_addr, uint8_t nbr_sets, uint16_t *p_sets); +int32_t rsi_bt_avrcp_set_abs_vol(uint8_t *remote_dev_addr, uint8_t abs_vol, uint8_t *p_resp_abs_vol); +int32_t rsi_bt_avrcp_cap_resp(uint8_t *remote_dev_addr, uint8_t cap_type, uint8_t nbr_caps, uint32_t *p_caps); +int32_t rsi_bt_avrcp_att_list_resp(uint8_t *remote_dev_addr, uint8_t nbr_atts, uint8_t *p_atts); +int32_t rsi_bt_avrcp_att_val_list_resp(uint8_t *remote_dev_addr, uint8_t nbr_vals, uint8_t *p_vals); +int32_t rsi_bt_avrcp_cur_att_val_resp(uint8_t *remote_dev_addr, uint8_t nbr_atts, att_val_t *p_att_vals); +int32_t rsi_bt_avrcp_set_cur_att_val_resp(uint8_t *remote_dev_addr, uint8_t status); +int32_t rsi_bt_avrcp_ele_att_resp(uint8_t *remote_dev_addr, uint8_t num_attrs, attr_list_t *p_attr_list); +int32_t rsi_bt_avrcp_play_status_resp(uint8_t *remote_dev_addr, + uint8_t play_status, + uint32_t song_len, + uint32_t song_pos); +int32_t rsi_bt_avrcp_reg_notify_resp(uint8_t *remote_dev_addr, + uint8_t event_id, + uint8_t event_data_len, + uint8_t *event_data); +int32_t rsi_bt_avrcp_att_text_resp(uint8_t *remote_dev_addr, uint8_t nbr_atts, att_text_t *p_att_text); +int32_t rsi_bt_avrcp_att_vals_text_resp(uint8_t *remote_dev_addr, uint8_t nbr_vals, att_text_t *p_vals_text); +int32_t rsi_bt_avrcp_batt_status_resp(uint8_t *remote_dev_addr, uint8_t status); +int32_t rsi_bt_avrcp_char_set_status_resp(uint8_t *remote_dev_addr, uint8_t status); +int32_t rsi_bt_avrcp_notify(uint8_t *remote_dev_addr, uint8_t event_id, notify_val_t *p_notify_val); +int32_t rsi_bt_avrcp_cmd_reject(uint8_t *remote_dev_addr, uint8_t pdu_id, uint8_t status); +int32_t rsi_bt_avrcp_set_abs_vol_resp(uint8_t *remote_dev_addr, uint8_t abs_vol); +int32_t rsi_bt_avrcp_set_addr_player_resp(uint8_t *remote_dev_addr, uint8_t status); +int32_t rsi_bt_avrcp_get_folder_items_resp(uint8_t *remote_dev_addr, + uint8_t status, + folder_items_resp_t folder_items_resp); +int32_t rsi_bt_avrcp_get_tot_num_items_resp(uint8_t *remote_dev_addr, + uint8_t status, + uint16_t uidcntr, + uint32_t numofitems); + +int32_t rsi_bt_write_current_iac_lap(uint8_t no_of_iaps, uint8_t *iap_lap_list); +int32_t rsi_bt_set_afh_host_channel_classification(uint8_t enable, uint8_t *channel_map); +int32_t rsi_bt_get_afh_host_channel_classification(uint8_t *status); +int32_t rsi_bt_enable_device_under_testmode(void); +int32_t rsi_bt_gatt_connect(uint8_t *remote_dev_addr); +int32_t rsi_bt_per_rx(uint32_t *bt_perrx); +int32_t rsi_bt_per_tx(uint32_t *bt_pertx); +int32_t rsi_bt_change_pkt_type(uint8_t *remote_dev_addr, uint16_t pkt_type); +int32_t rsi_bt_ptt_req(uint8_t mode); + +int32_t rsi_bt_per_stats(uint8_t cmd_type, struct rsi_bt_per_stats_s *per_stats); +int32_t rsi_bt_vendor_avdtp_stats_enable(uint16_t avdtp_stats_enable, uint32_t avdtp_stats_rate); +int32_t rsi_bt_vendor_ar_enable(uint16_t enable); +int32_t rsi_memory_stats_enable(uint8_t protocol, uint8_t memory_stats_enable, uint32_t memory_stats_interval_ms); +int32_t rsi_bt_vendor_dynamic_pwr(uint16_t enable, + uint8_t *remote_dev, + uint8_t power_index_br, + uint8_t power_index_2m, + uint8_t power_index_3m); +int32_t rsi_bt_vendor_set_afh_classification_intervals(uint16_t afh_min, uint16_t afh_max); + +int32_t rsi_bt_iap_send_control_session_data(rsi_bt_iap_payload_t *payload); +int32_t rsi_bt_iap2_update_send_cmds_info(rsi_bt_iap_cmds_info_t *cmd_list); +int32_t rsi_bt_iap2_update_recv_cmds_info(rsi_bt_iap_cmds_info_t *cmd_list); +int32_t rsi_bt_iap2_Init_File_Transfer(void); +int32_t rsi_bt_iap2_deInit_File_Transfer(void); +int32_t rsi_bt_iap2_Send_File_Transfer_State(rsi_bt_iap_File_transfer_info_t *payload_info); +int32_t rsi_bt_iap2_Send_File_Transfer_data(rsi_bt_iap_File_transfer_info_t *payload_info); +int32_t rsi_bt_spp_disconnect(uint8_t *remote_dev_addr); +int32_t rsi_bt_spp_transfer(uint8_t *remote_dev_addr, uint8_t *data, uint16_t length); +int32_t rsi_bt_hfp_init(void); +int32_t rsi_bt_hfp_connect(uint8_t *remote_dev_addr); +int32_t rsi_bt_hfp_disconnect(uint8_t *remote_dev_addr); +int32_t rsi_bt_hfp_phoneoperator(uint8_t *phone_operator); +int32_t rsi_bt_hfp_callaccept(void); +int32_t rsi_bt_hfp_callreject(void); +int32_t rsi_bt_hfp_dialnum(uint8_t *phone_no); +int32_t rsi_bt_hfp_dialmem(uint8_t *mem_ix); +int32_t rsi_bt_hfp_redial(void); +int32_t rsi_bt_hfp_voicerecognitionactive(void); +int32_t rsi_bt_hfp_voicerecognitiondeactive(void); +int32_t rsi_bt_hfp_spkgain(uint8_t spk_gain); +int32_t rsi_bt_hfp_micgain(uint8_t mic_gain); +int32_t rsi_bt_hfp_getcalls(void); +int32_t rsi_bt_hfp_audiotransfer(uint8_t b_to_hf_transfer); +int32_t rsi_bt_hfp_audio(void *hfp_audio_pkt); +int32_t rsi_bt_pbap_init(void); +int32_t rsi_bt_pbap_connect(uint8_t *remote_dev_addr); +int32_t rsi_bt_pbap_disconnect(uint8_t *remote_dev_addr); +int32_t rsi_bt_pbap_contacts(uint8_t *remote_dev_addr, uint8_t folder_id, uint8_t nbr_contacts, uint8_t start_ix); +#endif diff --git a/wiseconnect/sapi/include/rsi_bt_common.h b/wiseconnect/sapi/include/rsi_bt_common.h new file mode 100644 index 00000000..f82920c5 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt_common.h @@ -0,0 +1,412 @@ +/******************************************************************************* +* @file rsi_bt_common.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE)) + +#ifndef RSI_BT_COMMON_H +#define RSI_BT_COMMON_H + +#include +#include +#include +#include +//#include + +//#define RSI_DEBUG_PRINTS +/****************************************************** + * * Macros + * ******************************************************/ +#define RSI_BT_HCI_CMD_PKT 0x1 +#define RSI_BT_HCI_ACL_PKT 0x2 +#define RSI_BT_HCI_PER_CMD_PKT 0x3 + +#define RSI_BT_DUAL_MODE 0x8 +#define RSI_BT_BLE_MODE_BITS (BIT(2) | BIT(3)) + +#define RSI_BT_STATUS_OFFSET 0x0C +#define RSI_BT_RSP_TYPE_OFFSET 0x02 +#define RSI_BT_RSP_LEN_OFFSET 0x00 +#define RSI_BT_RSP_LEN_MASK 0x0FFF + +#define RSI_PROTO_BT_COMMON 0x01 +#define RSI_PROTO_BT_CLASSIC 0x02 +#define RSI_PROTO_BLE 0x03 +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define RSI_PROTO_PROP_PROTOCOL 0x04 +#endif +#define RSI_PROTO_BT_BLE_STACK 0x05 + +#define RSI_DEV_NAME_LEN 50 +#define RSI_DEV_ADDR_LEN 6 +#define RSI_DEV_ATT_LEN 240 + +#define RSI_BT_CLASSIC_DEVICE 0x00 +#define RSI_BT_LE_DEVICE 0x01 +#define RSI_BT_UNKWON_DEVICE 0xFF + +#define STACK_BT_MODE 0x01 +#define STACK_BTLE_MODE 0x02 + +//RF types +#define RSI_EXTERNAL_RF 0x00 +#define RSI_INTERNAL_RF 0x01 +#define RSI_RF_TYPE RSI_INTERNAL_RF + +#define RSI_MAX_ATT 5 + +#define RSI_OPERMODE_WLAN_BT_DUAL_MODE 9 + +#define RSI_BT_STATE_NONE 0 +#define RSI_BT_STATE_OPERMODE_DONE 1 +#define LOWERNIBBLE 0x0F +/****************************************************** + * * Constants + * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +typedef struct rsi_ble_cb_s rsi_ble_cb_t; +typedef struct rsi_bt_classic_cb_s rsi_bt_classic_cb_t; +typedef struct rsi_bt_common_specific_cb_s rsi_bt_common_specific_cb_t; +typedef int32_t (*rsi_bt_get_ber_pkt_t)(uint8_t *pkt, uint16_t pkt_len); +#ifdef RSI_PROP_PROTOCOL_ENABLE +typedef struct rsi_prop_protocol_cb_s rsi_prop_protocol_cb_t; +#endif + +/****************************************************** + * * Enumerations + * ******************************************************/ + +typedef enum rsi_bt_common_cmd_request_e { + RSI_BT_SET_LOCAL_NAME = 0x0001, + RSI_BT_GET_LOCAL_NAME = 0x0002, + RSI_BT_GET_RSSI = 0x0005, + RSI_BT_GET_LOCAL_DEV_ADDR = 0x0007, + RSI_BT_REQ_INIT = 0x008D, + RSI_BT_REQ_DEINIT = 0x008E, + RSI_BT_SET_ANTENNA_SELECT = 0x008F, + RSI_BT_REQ_PER_CMD = 0x009A, + RSI_BT_SET_FEATURES_BITMAP = 0x00A6, + RSI_BT_VENDOR_SPECIFIC = 0x00BE, + RSI_BT_SET_ANTENNA_TX_POWER_LEVEL = 0x00A7, + RSI_BT_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE = 0x012C, + RSI_BT_SET_BD_ADDR_REQ = 0x012E, + RSI_BT_GET_BT_STACK_VERSION = 0x012F, + + RSI_BLE_ONLY_OPER_MODE = 0x8010, + RSI_BLE_REQ_PWRMODE = 0x8015, + RSI_BLE_REQ_SOFTRESET = 0x801C +} rsi_bt_common_cmd_request_t; + +typedef enum rsi_bt_common_event_e { + RSI_BT_EVENT_CARD_READY = 0x0505, +} rsi_bt_common_event_t; + +typedef enum rsi_bt_common_cmd_resp_e { + RSI_BT_RSP_SET_LOCAL_NAME = 0x0001, + RSI_BT_RSP_QUERY_LOCAL_NAME = 0x0002, + RSI_BT_RSP_QUERY_RSSI = 0x0005, + RSI_BT_RSP_QUERY_LOCAL_BD_ADDRESS = 0x0007, + RSI_BT_RSP_INIT = 0x008D, + RSI_BT_RSP_DEINIT = 0x008E, + RSI_BT_RSP_ANTENNA_SELECT = 0x008F, + RSI_BT_RSP_SET_FEATURES_BITMAP = 0x00A6, + RSI_BT_RSP_ANTENNA_TX_POWER_LEVEL = 0x00A7, + RSI_BT_RSP_SET_GAIN_TABLE_OFFSET_OR_MAX_POWER_UPDATE = 0x012C, + RSI_BT_RSP_SET_BD_ADDR = 0x012E, + + RSI_BLE_RSP_ONLY_OPER_MODE = 0x8010, + RSI_BLE_RSP_PWRMODE = 0x8015, + RSI_BLE_RSP_SOFTRESET = 0x801C +} rsi_bt_common_cmd_resp_t; + +/****************************************************** + * * Structures + * ******************************************************/ +// Driver control block +struct rsi_driver_cb_s; + +// Driver BT Common control block +struct rsi_bt_common_specific_cb_s { + // PER BER Call Backs + rsi_bt_get_ber_pkt_t rsi_bt_get_ber_pkt; +}; + +// Specific BT, BLE blocks +typedef struct rsi_bt_global_cb_s { + // BT Common specific cb + rsi_bt_common_specific_cb_t *bt_common_specific_cb; + // BLE specific cb + rsi_ble_cb_t *ble_specific_cb; + // BT Classic specific cb + rsi_bt_classic_cb_t *bt_specific_cb; +#ifdef RSI_PROP_PROTOCOL_ENABLE + // PROP_PROTOCOL specific cb + rsi_prop_protocol_cb_t *prop_protocol_specific_cb; +#endif +} rsi_bt_global_cb_t; + +// Remote LE Device info structure +typedef struct rsi_remote_ble_info_s { + // BD Address of the remote LE device + uint8_t remote_dev_bd_addr[RSI_DEV_ADDR_LEN]; + + // Address type of the remote LE device + uint8_t remote_dev_addr_type; + + // Available Buffer Count + uint8_t avail_buf_cnt; + + // Max Buffer Count + uint8_t max_buf_cnt; + + // Max Buffer Length + uint16_t max_buf_len; + + // Flag for dev info used or not + uint8_t used; + + // Flag for checking command in use + uint8_t cmd_in_use; + + // Flag for checking expected remote response for each procedure + uint16_t expected_resp; + + // Buffer config mode + uint8_t mode; + + // mutex handle for avail_buf_info update + rsi_mutex_handle_t ble_buff_mutex; +} rsi_remote_ble_info_t; + +// Driver BT/BLE/PROP_PROTOCOL control block +typedef struct rsi_bt_cb_s { + // driver BT control block status + volatile int32_t status; + + // driver BT control block state + uint16_t state; + + // driver BT control block mutex + rsi_mutex_handle_t bt_mutex; + + // driver BT control block expected command response + void *expected_response_buffer; + + // expected command response type + uint16_t expected_response_type; + + // sync command flag to identify that the command is blocking / sync type + uint8_t sync_rsp; + + // BT device type at disconnect. + uint8_t dev_type; + + // driver BT control block semaphore + rsi_semaphore_handle_t bt_cmd_sem; + + // driver BT control block semaphore + rsi_semaphore_handle_t bt_sem; + + // driver BT control block tx packet pool + rsi_pkt_pool_t bt_tx_pool; + + // buffer pointer given by application to driver + uint8_t *app_buffer; + + // buffer length given by application to driver + uint32_t app_buffer_length; + + rsi_bt_global_cb_t *bt_global_cb; + + //uint8, address of the device to which directed advertising has to be done in ll privacy mode + uint8_t directed_addr[RSI_DEV_ADDR_LEN]; + +// Structure Holding Remote LE Dev info (BD address & Controller Buffer availability) +#define MAX_REMOTE_BLE_DEVICES 10 // 2(RSI_BLE_MAX_NBR_MASTERS) + 8 (RSI_BLE_MAX_NBR_SLAVES) + rsi_remote_ble_info_t remote_ble_info[MAX_REMOTE_BLE_DEVICES]; + + // Variable indicating buffer full/empty status --> 0 -> Empty, 1 -> Full + uint8_t buf_status; + + // Variable indicating command in use status --> 0 -> Not In Use, 1 -> In Use + uint8_t cmd_status; + + // Variable to save Remote info index + uint8_t remote_ble_index; + + // driver BT control block asynchronous status + volatile int32_t async_status; + +} rsi_bt_cb_t; + +// Set local name command structure +typedef struct rsi_bt_req_set_local_name_s { + // uint8, length of the required name to be set + uint8_t name_len; + // int8[50], required name + int8_t name[RSI_DEV_NAME_LEN]; +} rsi_bt_req_set_local_name_t; + +// Get RSSI command structure +typedef struct rsi_bt_get_rssi_s { + // uint8, device address of the device whose RSSI has to be known + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_get_rssi_t; + +// Response structures + +// Get local name response structures +typedef struct rsi_bt_resp_get_local_name_s { + /** Name length */ + uint8_t name_len; + /** Array which consists name of the local device. The maximum size of this array is 50 */ + int8_t name[RSI_DEV_NAME_LEN]; +} rsi_bt_resp_get_local_name_t; + +// Get Stack Version +typedef struct rsi_bt_resp_get_bt_stack_version_s { + /** stack version variable */ + int8_t stack_version[10]; +} rsi_bt_resp_get_bt_stack_version_t; + +// Set antenna structure +typedef struct rsi_ble_set_antenna_s { + //uint8, antenna value - internal/external + uint8_t value; +} rsi_ble_set_antenna_t; + +// Set feature bitmap structure +typedef struct rsi_bt_set_feature_bitmap_s { + //uint8[4], features bits (bit map) + uint32_t bit_map; +} rsi_bt_set_feature_bitmap_t; + +typedef struct rsi_ble_oper_mode_s { + //uint8, antenna value - internal/external + uint32_t bt_features; + uint8_t module_type; +} rsi_ble_oper_mode_t; + +typedef struct rsi_ble_power_mode_s { + // power mode to set + uint8_t power_mode; + + // set LP/ULP/ULP-without RAM retention + uint8_t ulp_mode_enable; + +} rsi_ble_power_mode_t; + +// Set antenna tx power level structure +typedef struct rsi_bt_set_antenna_tx_power_level_s { + //uint8, protocol_mode : 1-BT, 2-LE + uint8_t protocol_mode; + //int8_t, transmit power + int8_t tx_power; +} rsi_bt_set_antenna_tx_power_level_t; + +// BT PER Stats +typedef struct rsi_bt_per_stats_s { + /** Packet count of CRC fails (Cyclic Redundancy Check (CRC)) */ + uint16_t crc_fail_cnt; + /** Packet count of CRC fails (Cyclic Redundancy Check (CRC)) */ + uint16_t crc_pass_cnt; + /** Packet count of aborted Tx */ + uint16_t tx_abort_cnt; + /** Packet count of dropped Rx */ + uint16_t rx_drop_cnt; + /** Packet count of CCA Idle (Clear Channel Assessment (CCA)) */ + uint16_t rx_cca_idle_cnt; + /** Packet count of Rx start */ + uint16_t rx_start_idle_cnt; + /** Packet count of aborted Rx */ + uint16_t rx_abrt_cnt; + /** Packet count of successful transmissions */ + uint16_t tx_dones; + /** Received Signal Strength Indicator of the packet */ + int8_t rssi; + /** Packet count of ID packets received */ + uint16_t id_pkts_rcvd; + /** Dummy array of length 5 */ + uint16_t dummy[5]; +} rsi_bt_per_stats_t; + +typedef struct rsi_bt_per_cw_mode_s { + /** Command ID. Should be set to #define HCI_BT_CW_MODE_CMD_ID 0x0D*/ + uint8_t cmd_id; + /** 1-Enable, 0-Disable */ + uint8_t cw_mode_enable; +} rsi_bt_per_cw_mode_t; + +typedef struct rsi_bt_set_local_bd_addr_s { + uint8_t dev_addr[RSI_DEV_ADDR_LEN]; +} rsi_bt_set_local_bd_addr_t; + +// BT BER CMD +typedef struct rsi_bt_ber_cmd_s { + /** BER command ID */ + uint8_t cmd_id; + /** 1-Enable, 0-Disable */ + uint8_t enable; +} rsi_bt_ber_cmd_t; + +typedef struct rsi_bt_cmd_update_gain_table_offset_or_maxpower_s { + /** node id (0 - BLE, 1 - BT) */ + uint8_t node_id; + /** gain table request type (0 - max power update, 1 - offset update) */ + uint8_t update_gain_table_type; + /** gain table payload length */ + uint8_t payload_len; + /** gain table payload data */ + uint8_t payload[128]; +} rsi_bt_cmd_update_gain_table_offset_or_maxpower_t; + +/****************************************************** + * * BT/BLE common function declarations + * ******************************************************/ +void rsi_bt_set_status(rsi_bt_cb_t *bt_cb, int32_t status); +void rsi_bt_common_init(void); +void rsi_bt_common_tx_done(rsi_pkt_t *pkt); +int8_t rsi_bt_cb_init(rsi_bt_cb_t *bt_cb, uint16_t protocol_type); +int32_t rsi_bt_driver_send_cmd(uint16_t cmd, void *cmd_struct, void *resp); +uint16_t rsi_bt_global_cb_init(struct rsi_driver_cb_s *driver_cb, uint8_t *buffer); +uint16_t rsi_driver_process_bt_resp_handler(rsi_pkt_t *pkt); +uint16_t rsi_bt_get_proto_type(uint16_t rsp_type, rsi_bt_cb_t **bt_cb); +uint8_t rsi_bt_get_ACL_type(uint16_t rsp_type); + +int32_t rsi_bt_get_local_name(rsi_bt_resp_get_local_name_t *bt_resp_get_local_name); +int32_t rsi_bt_per_cw_mode(struct rsi_bt_per_cw_mode_s *bt_cw_mode); +#ifndef SAPIS_BT_STACK_ON_HOST +int32_t intialize_bt_stack(uint8_t mode); +#endif +#endif + +#define HCI_BT_PER_STATS_CMD_ID 0x08 +#define HCI_BT_CW_MODE_CMD_ID 0x0D +#define HCI_BLE_TRANSMIT_CMD_ID 0x13 +#define HCI_BLE_RECEIVE_CMD_ID 0x14 +#define HCI_BT_TRANSMIT_CMD_ID 0x15 +#define HCI_BT_RECEIVE_CMD_ID 0x16 + +#endif diff --git a/wiseconnect/sapi/include/rsi_bt_common_apis.h b/wiseconnect/sapi/include/rsi_bt_common_apis.h new file mode 100644 index 00000000..d95c26a8 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt_common_apis.h @@ -0,0 +1,170 @@ +/******************************************************************************* +* @file rsi_bt_common_apis.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_BT_COMMON_APIS_H +#define RSI_BT_COMMON_APIS_H + +#include +#include +#include + +/****************************************************** + * * Macros + * ******************************************************/ +// success return value +#define RSI_SUCCESS 0 + +// failure return value +#define RSI_FAILURE -1 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +/****************************************************** + * * Global Variables + * ******************************************************/ + +/****************************************************** + * * BT Common API's Declarations + * ******************************************************/ +/*==============================================*/ +/** + * @fn int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr) + * + */ +#ifdef __cplusplus +extern "C" { +#endif +int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr); + +/*==============================================*/ +/** + * @fn int32_t rsi_bt_ber_enable(struct rsi_bt_ber_cmd_s *rsi_bt_ber_cmd) + * + */ +int32_t rsi_bt_ber_enable_or_disable(rsi_bt_ber_cmd_t *ber_cmd); + +/*==============================================*/ +/** + * @fn rsi_bt_set_local_name + * + */ +int32_t rsi_bt_set_local_name(uint8_t *local_name); + +/*==============================================*/ +/** + * @fn rsi_bt_get_local_name + * + */ +int32_t rsi_bt_get_local_name(rsi_bt_resp_get_local_name_t *bt_resp_get_local_name); + +/*==============================================*/ +/** + * @fn rsi_bt_cmd_update_gain_table_offset_or_max_pwr + * + * + */ +int32_t rsi_bt_cmd_update_gain_table_offset_or_max_pwr(uint8_t node_id, + uint8_t payload_len, + uint8_t *payload, + uint8_t req_type); + +/*==============================================*/ +/** + * @fn rsi_bt_get_rssi + * + * + */ +int32_t rsi_bt_get_rssi(uint8_t *remote_dev_addr, int8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_get_local_device_address + * + */ +int32_t rsi_bt_get_local_device_address(uint8_t *resp); + +/*==============================================*/ +/** + * @fn rsi_bt_init + * + */ +int32_t rsi_bt_init(void); + +/*==============================================*/ +/** + * @fn rsi_bt_deinit + * + * + * + */ +int32_t rsi_bt_deinit(void); + +/*==============================================*/ +/** + * @fn rsi_bt_set_antenna + * + * + */ +int32_t rsi_bt_set_antenna(uint8_t antenna_value); + +/*==============================================*/ +/** + * @fn rsi_bt_set_feature_bitmap + * + * + */ +int32_t rsi_bt_set_feature_bitmap(uint32_t feature_bit_map); + +/*==============================================*/ +/** + * @fn rsi_bt_set_antenna_tx_power_level + * + * + */ +int32_t rsi_bt_set_antenna_tx_power_level(uint8_t protocol_mode, int8_t tx_power); + +/*==============================================*/ +/** + * @fn rsi_bt_get_stack_version + * + * + */ +int32_t rsi_bt_get_bt_stack_version(rsi_bt_resp_get_bt_stack_version_t *bt_resp_get_bt_stack_version); + +int32_t rsi_bt_power_save_profile(uint8_t psp_mode, uint8_t psp_type); +#ifdef __cplusplus +} +#endif +#endif diff --git a/wiseconnect/sapi/include/rsi_bt_common_config.h b/wiseconnect/sapi/include/rsi_bt_common_config.h new file mode 100644 index 00000000..857d2e45 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt_common_config.h @@ -0,0 +1,206 @@ +/******************************************************************************* +* @file rsi_bt_common_config.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_bt_common_config.h + * @version 0.1 + * @date 15 Aug 2018 + * + * + * + * @brief : This file contains user configurable details to configure the device + * + * @section Description This file contains user configurable details to configure the device + * + * + */ +#ifndef RSI_BT_COMMON_CONFIG_H +#define RSI_BT_COMMON_CONFIG_H + +#ifndef BD_ADDR_ARRAY_LEN +#define BD_ADDR_ARRAY_LEN 18 +#endif + +#ifndef RSI_LINKKEY_REPLY_SIZE +#define RSI_LINKKEY_REPLY_SIZE 16 +#endif + +// WLAN + BT Classic coex mode +#ifndef RSI_OPERMODE_WLAN_BT_CLASSIC +#define RSI_OPERMODE_WLAN_BT_CLASSIC 5 +#endif + +#ifndef RSI_BT_BLE_DUAL_MODE +#define RSI_BT_BLE_DUAL_MODE 9 +#endif + +#ifndef BT_GLOBAL_BUFF_LEN +#define BT_GLOBAL_BUFF_LEN 10000 +#endif +/*=======================================================================*/ +// Discovery command parameters +/*=======================================================================*/ + +// Discovery mode +// Start the discoverable mode +#ifndef START_DISCOVERY +#define START_DISCOVERY 0x01 +#endif + +// Start the limited discoverable mode +#ifndef START_LIMITED_DISCOVERY +#define START_LIMITED_DISCOVERY 0x02 +#endif + +// Stop the discoverable mode +#ifndef STOP_DISCOVERY +#define STOP_DISCOVERY 0x00 +#endif +/*=======================================================================*/ +// Connectability command parameters +/*=======================================================================*/ + +// Connectable mode +// Start the connectable mode +#ifndef CONNECTABLE +#define CONNECTABLE 0x01 +#endif + +// Stop the connectable mode +#ifndef NON_CONNECTABLE +#define NON_CONNECTABLE 0x00 +#endif + +/*=======================================================================*/ +// SSP Confirmation command parameters +/*=======================================================================*/ +// Confimation type +// Accept confirmation +#ifndef ACCEPT +#define ACCEPT 0x01 +#endif + +// Reject confirmation +#ifndef REJECT +#define REJECT 0x00 +#endif +/*=======================================================================*/ +// BT classic profile enable BITS +/*=======================================================================*/ +#ifndef RSI_SPP_PROFILE_BIT +#define RSI_SPP_PROFILE_BIT BIT(0) +#endif + +#ifndef RSI_A2DP_PROFILE_BIT +#define RSI_A2DP_PROFILE_BIT BIT(1) +#endif + +#ifndef RSI_AVRCP_PROFILE_BIT +#define RSI_AVRCP_PROFILE_BIT BIT(2) +#endif + +#ifndef RSI_HFP_PROFILE_BIT +#define RSI_HFP_PROFILE_BIT BIT(3) +#endif + +#ifndef RSI_PBAP_PROFILE_BIT +#define RSI_PBAP_PROFILE_BIT BIT(4) +#endif +/*=======================================================================*/ +// A2DP Profile Related +/*=======================================================================*/ + +#ifndef A2DP_BURST_MODE +#define A2DP_BURST_MODE 1 // 0 - Disable, 1 - Enable +#endif + +#ifndef A2DP_BURST_SIZE +#define A2DP_BURST_SIZE 1 // Number of PCM/MP3 packets buffered +#endif + +#ifndef PCM_AUDIO +#define PCM_AUDIO 1 +#endif +#ifndef SBC_AUDIO +#define SBC_AUDIO 2 +#endif +#ifndef MP3_AUDIO +#define MP3_AUDIO 3 +#endif + +#ifndef RSI_AUDIO_DATA_TYPE +#define RSI_AUDIO_DATA_TYPE SBC_AUDIO +#endif +#ifndef PCM_INPUT_BUFFER_SIZE +#define PCM_INPUT_BUFFER_SIZE 30 * 512 +#endif + +#ifndef MP3_INPUT_BUFFER_SIZE +#define MP3_INPUT_BUFFER_SIZE 10 * 512 +#endif + +#ifndef BIN_FILE +#define BIN_FILE 1 +#endif +#ifndef BT_ARRAY +#define BT_ARRAY 2 +#endif +#ifndef SD_BIN_FILE +#define SD_BIN_FILE 3 +#endif + +#ifndef RSI_AUDIO_DATA_SRC +#define RSI_AUDIO_DATA_SRC BIN_FILE +#endif + +#ifndef PRE_ENC_BUF_LEN +#define PRE_ENC_BUF_LEN 8 +#endif + +//avdtp related defines +#ifndef ACCEPTOR_ROLE +#define ACCEPTOR_ROLE 1 +#endif +#ifndef INITIATOR_ROLE +#define INITIATOR_ROLE 2 +#endif +#ifndef ANY_ROLE +#define ANY_ROLE 3 +#endif + +#ifndef RSI_BT_MAX_PAYLOAD_SIZE +#define RSI_BT_MAX_PAYLOAD_SIZE \ + 1040 // BT MTU size changes //310 /* Max supported is 200, but 190 gives optimum Tx throughput */ +#endif + +#ifndef BT_BDR_MODE +#define BT_BDR_MODE 0 // 1 - HP chain +#endif + +#ifndef USE_REM_MTU_SIZE_ONLY +#define USE_REM_MTU_SIZE_ONLY 1 +#endif + +#ifndef TA_BASED_ENCODER +#define TA_BASED_ENCODER 0 +#endif + +#endif //RSI_BT_COMMON_CONFIG_H diff --git a/wiseconnect/sapi/include/rsi_bt_sbc_codec.h b/wiseconnect/sapi/include/rsi_bt_sbc_codec.h new file mode 100644 index 00000000..8a389c8c --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt_sbc_codec.h @@ -0,0 +1,48 @@ +#ifndef RSI_BT_SBC_APIS_H +#define RSI_BT_SBC_APIS_H + +#define SBC_SAMPLING_FREQ_16000 (1 << 3) +#define SBC_SAMPLING_FREQ_32000 (1 << 2) +#define SBC_SAMPLING_FREQ_44100 (1 << 1) +#define SBC_SAMPLING_FREQ_48000 (1 << 0) + +#define SBC_CHANNEL_MODE_MONO (1 << 3) +#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) +#define SBC_CHANNEL_MODE_STEREO (1 << 1) +#define SBC_CHANNEL_MODE_JOINT_STEREO (1 << 0) + +#define SBC_BLOCK_LENGTH_4 (1 << 3) +#define SBC_BLOCK_LENGTH_8 (1 << 2) +#define SBC_BLOCK_LENGTH_12 (1 << 1) +#define SBC_BLOCK_LENGTH_16 (1 << 0) + +#define SBC_SUBBANDS_4 (1 << 1) +#define SBC_SUBBANDS_8 (1 << 0) + +#define SBC_ALLOCATION_SNR (1 << 1) +#define SBC_ALLOCATION_LOUDNESS (1 << 0) + +#define SBC_MAX_BITPOOL 53 +#define SBC_MIN_BITPOOL 2 + +/***********************************************************************************************************************************************/ +// Error codes +/***********************************************************************************************************************************************/ + +#define RSI_APP_ERR_A2DP_SBC_BUFF_OVERFLOW 0x00A1 +#define RSI_APP_ERR_A2DP_SBC_BUFF_UNDERFLOW 0x00A2 +#define RSI_APP_ERR_INVALID_INPUT 0x00A3 + +void bt_evt_a2dp_more_data(void); +void bt_evt_a2dp_start(uint16_t rem_mtu_size); +void bt_evt_a2dp_config(void); +void bt_evt_a2dp_open(void); +void bt_evt_a2dp_conn(void); +void bt_evt_a2dp_disconn(void); +int16_t rsi_bt_cmd_sbc_init(void); +int16_t rsi_bt_cmd_sbc_reinit(void *sbc_cap); +int16_t rsi_bt_a2dp_sbc_encode_task(uint8_t *pcm_data, uint16_t pcm_data_len, uint16_t *bytes_consumed); +int16_t rsi_bt_cmd_a2dp_pcm_mp3_data(uint8_t *addr, uint8_t *pcm_data, uint16_t pcm_data_len, uint16_t *bytes_consumed); +int16_t rsi_bt_send_sbc_data(void); + +#endif diff --git a/wiseconnect/sapi/include/rsi_bt_sdp.h b/wiseconnect/sapi/include/rsi_bt_sdp.h new file mode 100644 index 00000000..edb80dc5 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_bt_sdp.h @@ -0,0 +1,141 @@ +/******************************************************************************* +* @file rsi_bt_sdp.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_BT_SDP_H +#define RSI_BT_SDP_H + +#include +#include +#include + +#define BT_SERVICE_UUID_PUBLIC_BROWSE_GROUP 0x1002 +#define BT_SERVICE_UUID_HID 0x1124 +#define BT_HID_CONTROL_PSM 0x0011 +#define BT_HID_INTERRUPT_PSM 0x0013 + +#define BT_SDP_LANG_ATTR_NATURAL_LANG_ID 0x656E /* 'en' */ +#define BT_SDP_LANG_ATTR_ENCODING_UTF8 0x006A /* UTF-8 */ +#define BT_SDP_LANG_ATTR_BASE_ATTR_ID 0x0100 + +#define BT_ATTR_ID_SERVICE_RECORD_HANDLE 0x0000 +#define BT_ATTR_ID_SERVICE_CLASS_ID_LIST 0x0001 +#define BT_ATTR_ID_SERVICE_RECORD_STATE 0x0002 +#define BT_ATTR_ID_SERVICE_ID 0x0003 +#define BT_ATTR_ID_PROTOCOL_DESC_LIST 0x0004 +#define BT_ATTR_ID_BROWSE_GROUP_LIST 0x0005 +#define BT_ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST 0x0006 +#define BT_ATTR_ID_SERVICE_INFO_TIME_TO_LIVE 0x0007 +#define BT_ATTR_ID_SERVICE_AVAILABILITY 0x0008 +#define BT_ATTR_ID_BLUETOOTH_PROFILE_DESC_LIST 0x0009 +#define BT_ATTR_ID_DOCUMENTATION_URL 0x000A +#define BT_ATTR_ID_CLIENT_EXECUTABLE_URL 0x000B +#define BT_ATTR_ID_ICON_URL 0x000C +#define BT_ATTR_ID_ADDITIONAL_PROTOCOL_DESC_LIST 0x000D + +#define BT_ATTR_ID_ENGLISH_SERVICE_NAME 0x0100 +#define BT_ATTR_ID_ENGLISH_SERVICE_DESCRIPTION 0x0101 +#define BT_ATTR_ID_ENGLISH_PROVIDER_NAME 0x0102 + +#define BT_ATTR_ID_HID_VERSION_NUM 0x0200 +#define BT_ATTR_ID_HID_PARSER_VERSION 0x0201 +#define BT_ATTR_ID_HID_DEVICE_SUBCLASS 0x0202 +#define BT_ATTR_ID_HID_COUNTRY_CODE 0x0203 +#define BT_ATTR_ID_HID_VIRTUAL_CABLE 0x0204 +#define BT_ATTR_ID_HID_RECONNECT_INITIATE 0x0205 +#define BT_ATTR_ID_HID_DESCRIPTIOR_LIST 0x0206 +#define BT_ATTR_ID_HID_LANG_ID_BASE_LIST 0x0207 +#define BT_ATTR_ID_HID_SDP_DISABLE 0x0208 +#define BT_ATTR_ID_HID_BATTERY_POWER 0x0209 +#define BT_ATTR_ID_HID_REMOTE_WAKE 0x020A +#define BT_ATTR_ID_HID_PROFILE_VERSION 0x020B +#define BT_ATTR_ID_HID_SUPERVISION_TIMEOUT 0x020C +#define BT_ATTR_ID_HID_NORMALLY_CONNECTABLE 0x020D +#define BT_ATTR_ID_HID_BOOT_DEVICE 0x020E +#define BT_ATTR_ID_HID_SSR_HOST_MAX_LATENCY 0x020F +#define BT_ATTR_ID_HID_SSR_HOST_MIN_LATENCY 0x0210 + +typedef struct attr_id_array_s { + uint16_t attr_id; + uint16_t attr_buf_ptr_idx; + uint16_t attr_buf_len; +} attr_id_array_t; + +typedef struct rsi_sdp_att_record_s { +#define MAX_SDP_ATTR 27 + attr_id_array_t attr_array[MAX_SDP_ATTR]; + uint16_t attr_array_cnt; +#define MAX_SDP_BUFF_LEN 500 + uint16_t buf_len; + uint8_t buf_array[MAX_SDP_BUFF_LEN]; +} rsi_sdp_att_record_t; + +#define BT_ATTR_TYPE_NIL 0x00 +#define BT_ATTR_TYPE_UNSIGNED_INTEGER 0x01 +#define BT_ATTR_TYPE_SIGNED_INTEGER 0x02 +#define BT_ATTR_TYPE_UUID 0x03 +#define BT_ATTR_TYPE_TEXT_STRING 0x04 +#define BT_ATTR_TYPE_BOOLEAN 0x05 +#define BT_ATTR_TYPE_SEQUENCE 0x06 +#define BT_ATTR_TYPE_ALT_SEQUENCE 0x07 +#define BT_ATTR_TYPE_URL 0x08 + +#define BT_MEM_WR_BE_08U(addr, val) \ + { \ + (*(((uint8_t *)(addr)) + 0)) = ((uint8_t)((((uint8_t)(val)) & 0xFF) >> (0 * 8))); \ + } + +#define BT_MEM_WR_BE_16U(addr, val) \ + { \ + (*(((uint8_t *)(addr)) + 0)) = ((uint8_t)((((uint16_t)(val)) & 0xFF00) >> (1 * 8))); \ + (*(((uint8_t *)(addr)) + 1)) = ((uint8_t)((((uint16_t)(val)) & 0x00FF) >> (0 * 8))); \ + } + +#define BT_MEM_WR_BE_32U(addr, val) \ + { \ + (*(((uint8_t *)(addr)) + 0)) = ((uint8_t)((((uint32_t)(val)) & 0xFF000000) >> (3 * 8))); \ + (*(((uint8_t *)(addr)) + 1)) = ((uint8_t)((((uint32_t)(val)) & 0x00FF0000) >> (2 * 8))); \ + (*(((uint8_t *)(addr)) + 2)) = ((uint8_t)((((uint32_t)(val)) & 0x0000FF00) >> (1 * 8))); \ + (*(((uint8_t *)(addr)) + 3)) = ((uint8_t)((((uint32_t)(val)) & 0x000000FF) >> (0 * 8))); \ + } + +//protocol uuid's +#define BT_PROTOCOL_UUID_L2CAP 0x0100 +#define BT_PROTOCOL_UUID_RFCOMM 0x0003 +#define BT_PROTOCOL_UUID_ATT 0x0007 +#define BT_PROTOCOL_UUID_HID 0x0011 +#define BT_PROTOCOL_UUID_AVCTP 0x0017 +#define BT_PROTOCOL_UUID_A2DP 0x0019 + +typedef struct bt_sdp_proto_desc_list_elem { + uint16_t proto_uuid; + uint16_t num_params; + uint16_t params[2]; +} bt_sdp_proto_desc_list_elem_t; + +/* sdp language base attribute ID list, data element stucture */ +typedef struct bt_sdp_lang_attr_id_elem { + uint16_t lang_id; + uint16_t lang_encode_id; + uint16_t base_attr_id; +} bt_sdp_lang_attr_id_elem_t; + +#endif diff --git a/wiseconnect/sapi/include/rsi_common.h b/wiseconnect/sapi/include/rsi_common.h new file mode 100644 index 00000000..287e089d --- /dev/null +++ b/wiseconnect/sapi/include/rsi_common.h @@ -0,0 +1,966 @@ +/******************************************************************************* +* @file rsi_common.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_COMMON_H +#define RSI_COMMON_H +#ifndef EFM32_SDIO // This file is not needed for EFM32 board. In order to avoid compilation warnings, we excluded the below code for EFM32 +#include "rsi_board_configuration.h" +#endif +#ifdef RSI_M4_INTERFACE +#include "rsi_ipmu.h" +#endif +#include "rsi_wlan_non_rom.h" +#include "rsi_timer.h" +#include "rsi_pkt_mgmt.h" + +/****************************************************** + * * Macros + * ******************************************************/ + +// Power save SLP and WKP frame type +#define RSI_RSP_SLP 0xDE +#define RSI_RSP_WKP 0xDD + +// Max packet length of WLAN tx packet +#define RSI_WLAN_CMD_LEN (1600 + SIZE_OF_HEADROOM) + +// Max packet length of ZigBee tx packet +#define RSI_ZIGB_CMD_LEN (256 + SIZE_OF_HEADROOM) + +// pool size of WLAN tx packets +#define RSI_WLAN_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_WLAN_CMD_LEN + sizeof(void *)) * RSI_WLAN_TX_POOL_PKT_COUNT)) + +// pool size of WLAN tx packets +#define RSI_ZIGB_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_ZIGB_CMD_LEN + sizeof(void *)) * RSI_ZIGB_TX_POOL_PKT_COUNT)) + +// Max packet length of common command responses +//changed cmd len for crypto and PUF +#if defined(RSI_PUF_ENABLE) || (defined RSI_CRYPTO_ENABLE) +#define RSI_COMMON_CMD_LEN 1600 +#else +#define RSI_COMMON_CMD_LEN 100 +#endif + +// pool size of common command packets +#define RSI_COMMON_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_COMMON_CMD_LEN + sizeof(void *)) * RSI_COMMON_TX_POOL_PKT_COUNT)) + +// Max packet length of ssl rx packet +#define RSI_SSL_RECV_BUFFER_LENGTH 0 + +// Max packet length of rx packet +#if !((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) +#define RSI_DRIVER_RX_PKT_LEN (1600 + RSI_SSL_RECV_BUFFER_LENGTH) +#else +#define RSI_DRIVER_RX_PKT_LEN 0 +#endif +// pool size of driver rx packets +#define RSI_DRIVER_RX_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_DRIVER_RX_PKT_LEN + sizeof(void *)) * RSI_DRIVER_RX_POOL_PKT_COUNT)) + +#define RSI_EVENT_INFO_POOL_SIZE (((((uint32_t)(sizeof(rsi_event_cb_t))) + 3) & ~3) * RSI_MAX_NUM_EVENTS) +// pool size of socket information +#ifdef RSI_WLAN_ENABLE +#define RSI_SOCKET_INFO_POOL_SIZE (((((uint32_t)(sizeof(rsi_socket_info_t))) + 3) & ~3) * RSI_NUMBER_OF_SOCKETS) +#define RSI_SOCKET_INFO_POOL_ROM_SIZE \ + (((((uint32_t)(sizeof(rsi_socket_info_non_rom_t))) + 3) & ~3) * RSI_NUMBER_OF_SOCKETS) +#define RSI_SOCKET_SELECT_INFO_POOL_SIZE \ + (((((uint32_t)(sizeof(rsi_socket_select_info_t))) + 3) & ~3) * RSI_NUMBER_OF_SELECTS) +#else +#define RSI_SOCKET_INFO_POOL_SIZE 0 +#define RSI_SOCKET_INFO_POOL_ROM_SIZE 0 +#define RSI_SOCKET_SELECT_INFO_POOL_SIZE 0 +#endif +// Max packet length of BT COMMON tx packet +#define RSI_BT_COMMON_CMD_LEN (300 + SIZE_OF_HEADROOM) +#if ENCODER_IN_RS9116 +#define RSI_BT_CLASSIC_CMD_LEN 4000 +#else +#define RSI_BT_CLASSIC_CMD_LEN (1040 + SIZE_OF_HEADROOM) +#endif +#define RSI_BLE_CMD_LEN (300 + SIZE_OF_HEADROOM) +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define RSI_PROP_PROTOCOL_CMD_LEN (300 + SIZE_OF_HEADROOM) +#endif + +#ifdef SAPIS_BT_STACK_ON_HOST +#define RSI_OPERMODE_WLAN_BTBLE_DUALMODE_STACK_BYPASS (16 + 8 + 4 + 1) +#define RSI_OPERMODE_WLAN_BTBLE_DUALROLE_STACK_BYPASS (234) +#endif +// pool size of BT COMMON tx packets +#define RSI_BT_COMMON_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_BT_COMMON_CMD_LEN + sizeof(void *)) * RSI_BT_COMMON_TX_POOL_PKT_COUNT)) + +// pool size of BT Classic tx packets +#define RSI_BT_CLASSIC_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_BT_CLASSIC_CMD_LEN + sizeof(void *)) * RSI_BT_CLASSIC_TX_POOL_PKT_COUNT)) + +// pool size of BLE tx packets +#define RSI_BLE_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_BLE_CMD_LEN + sizeof(void *)) * RSI_BLE_TX_POOL_PKT_COUNT)) +#ifdef RSI_PROP_PROTOCOL_ENABLE +// pool size of PROP_PROTOCOL tx packets +#define RSI_PROP_PROTOCOL_POOL_SIZE \ + ((((((uint32_t)(sizeof(rsi_pkt_pool_t))) + 3) & ~3)) \ + + ((RSI_PROP_PROTOCOL_CMD_LEN + sizeof(void *)) * RSI_PROP_PROTOCOL_TX_POOL_PKT_COUNT)) +#endif +#ifdef RSI_M4_INTERFACE +#define RSI_M4_MEMORY_POOL_SIZE ((((uint32_t)(sizeof(efuse_ipmu_t))) + 3) & ~3) +#else +#define RSI_M4_MEMORY_POOL_SIZE 0 +#endif + +#ifdef PROCESS_SCAN_RESULTS_AT_HOST +#define SCAN_RESULTS_MEMORY_POOL_SIZE ((((uint32_t)(sizeof(struct wpa_scan_results_arr))) + 3) & ~3) +#else +#define SCAN_RESULTS_MEMORY_POOL_SIZE 0 +#endif + +#define RSI_WLAN_CB_NON_ROM_POOL_SIZE ((((uint32_t)(sizeof(rsi_wlan_cb_non_rom_t))) + 3) & ~3) + +#ifdef RSI_ZB_ENABLE +#ifdef ZB_MAC_API +#define ZB_GLOBAL_BUF_SIZE ((((uint32_t)(sizeof(rsi_zigb_global_mac_cb_t))) + 3) & ~3) +#else +#define ZB_GLOBAL_BUF_SIZE ((((uint32_t)(sizeof(rsi_zigb_global_cb_t))) + 3) & ~3) +#endif +#endif + +#ifdef RSI_ZB_ENABLE +#define RSI_ZB_MEMORY_POOL_SIZE \ + ((((uint32_t)(sizeof(rsi_zigb_cb_t))) + 3) & ~3) + RSI_ZIGB_POOL_SIZE + ZB_GLOBAL_BUF_SIZE +#else +#define RSI_ZB_MEMORY_POOL_SIZE 0 +#endif + +#if (defined RSI_BT_ENABLE || defined RSI_BLE_ENABLE || defined RSI_PROP_PROTOCOL_ENABLE) +#define RSI_BT_BLE_PROP_PROTOCOL_MEMORY_POOL_SIZE \ + ((((uint32_t)(sizeof(rsi_bt_cb_t))) + 3) & ~3) + RSI_BT_COMMON_POOL_SIZE \ + + ((((uint32_t)(sizeof(rsi_bt_global_cb_t))) + 3) & ~3) +#else +#define RSI_BT_BLE_PROP_PROTOCOL_MEMORY_POOL_SIZE 0 +#endif + +#ifdef RSI_BT_ENABLE +#define RSI_BT_MEMORY_POOL_SIZE \ + ((((uint32_t)(sizeof(rsi_bt_cb_t))) + 3) & ~3) + RSI_BT_CLASSIC_POOL_SIZE \ + + ((((uint32_t)(sizeof(rsi_bt_classic_cb_t))) + 3) & ~3) +#else +#define RSI_BT_MEMORY_POOL_SIZE 0 +#endif + +#ifdef RSI_BLE_ENABLE +#define RSI_BLE_MEMORY_POOL_SIZE \ + ((((uint32_t)(sizeof(rsi_bt_cb_t))) + 3) & ~3) + RSI_BLE_POOL_SIZE + ((((uint32_t)(sizeof(rsi_ble_cb_t))) + 3) & ~3) +#else +#define RSI_BLE_MEMORY_POOL_SIZE 0 +#endif + +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define PROP_PROTOCOL_MEMORY_SIZE \ + ((((uint32_t)(sizeof(rsi_bt_cb_t))) + 3) & ~3) + RSI_PROP_PROTOCOL_POOL_SIZE \ + + ((((uint32_t)(sizeof(rsi_prop_protocol_cb_t))) + 3) & ~3) +#else +#define PROP_PROTOCOL_MEMORY_SIZE 0 +#endif + +#ifdef SAPIS_BT_STACK_ON_HOST +#define BT_STACK_ON_HOST_MEMORY ((((uint32_t)(sizeof(rsi_bt_cb_t))) + 3) & ~3) + RSI_BT_CLASSIC_POOL_SIZE +#else +#define BT_STACK_ON_HOST_MEMORY 0 +#endif + +#define RSI_DRIVER_POOL_SIZE \ + sizeof(uint32_t) + ((((uint32_t)(sizeof(rsi_driver_cb_t))) + 3) & ~3) + RSI_DRIVER_RX_POOL_SIZE \ + + ((((uint32_t)(sizeof(rsi_common_cb_t))) + 3) & ~3) + ((((uint32_t)(sizeof(rsi_driver_cb_non_rom_t))) + 3) & ~3) \ + + RSI_COMMON_POOL_SIZE + ((((uint32_t)(sizeof(rsi_wlan_cb_t))) + 3) & ~3) + RSI_WLAN_POOL_SIZE \ + + RSI_M4_MEMORY_POOL_SIZE + RSI_SOCKET_INFO_POOL_SIZE + RSI_SOCKET_INFO_POOL_ROM_SIZE \ + + RSI_SOCKET_SELECT_INFO_POOL_SIZE + SCAN_RESULTS_MEMORY_POOL_SIZE + RSI_ZB_MEMORY_POOL_SIZE \ + + RSI_BT_BLE_PROP_PROTOCOL_MEMORY_POOL_SIZE + RSI_BT_MEMORY_POOL_SIZE + RSI_BLE_MEMORY_POOL_SIZE \ + + PROP_PROTOCOL_MEMORY_SIZE + BT_STACK_ON_HOST_MEMORY + RSI_EVENT_INFO_POOL_SIZE + RSI_WLAN_CB_NON_ROM_POOL_SIZE \ + + ((((uint32_t)(sizeof(global_cb_t))) + 3) & ~3) + ((((uint32_t)(sizeof(rom_apis_t))) + 3) & ~3) + +#define RSI_WAIT_FOREVER 0 +#define RSI_ZIGB_RESPONSE_WAIT_TIME RSI_WAIT_FOREVER +#define RSI_WAIT_TIME RSI_WAIT_FOREVER + +#define RSI_TX_EVENT_WAIT_TIME (30000 + TX_WAIT_TIME) +#define DEFAULT_TIMEOUT RSI_TX_EVENT_WAIT_TIME +#define WAIT_TIMEOOUT 5000 +// Internal command timeout defines +#define RSI_OPERMODE_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BAND_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_MAC_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DISCONNECT_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_TRANSMIT_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_RX_STATS_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WMM_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_AUTO_CONFIG_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SOCK_CONFIG_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_ANTENNA_SEL_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DEBUG_LOG_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_GET_RAM_DUMP_RESPONSE_WAIT_TIME ((1000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_FEATURE_FRAME_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_UART_FLOW_CTRL_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PWRMODE_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_START_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_SET_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_DIS_SET_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_GET_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_DIS_GET_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_LOAD_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_AES_ENCRYPT_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_AES_DECRYPT_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_AES_MAC_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_INTR_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SEND_DATA_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SWITCH_PROTO_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_RAW_DATA_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_DIS_ENROLL_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PUF_ENROLL_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_GAIN_TABLE_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_GET_PROFILE_RESPONSE_WAIT_TIME ((1000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SET_PROFILE_RESPONSE_WAIT_TIME ((1000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_EAP_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_REGION_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_REGION_AP_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DYNAMIC_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_ROAMING_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_MULTICAST_FIL_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_HT_CAPS_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_MULTICAST_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BCAST_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CARD_READY_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_INIT_RESPONSE_WAIT_TIME ((3000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_CONFIG_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_GET_RANDOM_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_RSSI_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_QUERY_NETWORK_PARAMS_WAIT_TIME ((200 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_REQ_GET_CFG_WAIT_TIME ((200 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_CFG_SAVE_WAIT_TIME ((1000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BOARD_READY_WAIT_TIME ((50000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SET_SLEEP_TIMER_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DEINIT_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CERTIFICATE_RESPONSE_WAIT_TIME ((1000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_REJOIN_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_USER_SC_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_REQ_GET_STATS_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_REQ_EXT_STATS_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_AUTO_JOIN_RESPONSE_WAIT_TIME \ + ((60000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) //! Here timeout should wait for init,scan and join commands +#define RSI_DELETE_PROFILE_RESPONSE_WAIT_TIME ((1000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_IAP_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_IAP_GET_CERT_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_IAP_GEN_SIG_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_TA_M4_COMMAND_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_ADD_MFI_IE_RESPONSE_WAIT_TIME ((500 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_FILTER_BROADCAST_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SET_RTC_TIMER_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#ifdef RSI_ASSERT_API +#define RSI_ASSERT_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#endif +#define RSI_WLAN_RADIO_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_GET_RTC_TIMER_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_TCP_WINDOW_RESPONSE_WAIT_TIME ((5000 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_TIMEOUT_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SET_CONFIG_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#ifdef FW_LOGGING_ENABLE +#define RSI_DEVICE_LOG_RESPONSE_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#endif +// WIFI WAIT timeout defines +#define RSI_SCAN_RESPONSE_WAIT_TIME ((10000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_JOIN_RESPONSE_WAIT_TIME ((10000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_P2P_RESPONSE_WAIT_TIME ((1000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BGSCAN_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PING_RESPONSE_WAIT_TIME ((60000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WEP_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_IPCONFV4_RESPONSE_WAIT_TIME ((20000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_IPCONFV6_RESPONSE_WAIT_TIME ((20000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_MDNSD_RESPONSE_WAIT_TIME \ + ((250000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) //!Firmware max timeout value is 240 seconds +#define RSI_HTTP_RESPONSE_WAIT_TIME \ + ((110000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) //!Firmware max timeout value is 100 seconds +#define RSI_AP_CONFIG_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_FWUP_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_MTYPE_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WP_LOAD_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_JSON_LOAD_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WP_ERASE_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_JSON_ERASE_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WP_CLEAR_ALL_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CONNECT_RESPONSE_WAIT_TIME ((10000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WPS_RESPONSE_WAIT_TIME ((180000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_FREQ_OFFSET_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CALIB_WRITE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CALIB_READ_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SMTP_RESPONSE_WAIT_TIME ((60000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DNS_SERVER_ADD_RESPONSE_WAIT_TIME ((150000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_FTP_RESPONSE_WAIT_TIME ((120000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_OTA_FWUP_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CRYPTO_RESPONSE_WAIT_TIME ((2000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SOCKET_CREATE_RESPONSE_WAIT_TIME ((100000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_CERT_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SCAN_WITH_BITMAP_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DNS_QUERY_RESPONSE_WAIT_TIME ((150000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_DNS_UPDATE_RESPONSE_WAIT_TIME ((150000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_HOST_WP_SEND_RESPONSE_WAIT_TIME ((200000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_POP3_RESPONSE_WAIT_TIME ((60000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_HTTP_ABORT_RESPONSE_WAIT_TIME \ + ((100000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) //!Firmware max timeout value is 100 seconds +#define RSI_HTTP_CLIENT_PUT_RESPONSE_WAIT_TIME \ + ((100000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) //!Firmware max timeout value is 100 seconds +#define RSI_SNTP_RESPONSE_WAIT_TIME ((100000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_EMB_MQTT_RESPONSE_WAIT_TIME ((60000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_PSK_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SOCKET_CLOSE_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_11AX_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_TWT_RESPONSE_WAIT_TIME ((5000 * WIFI_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) + +// WIFI BLOCKED timeout defines +#define RSI_ACCEPT_RESPONSE_WAIT_TIME (RSI_WAIT_FOREVER * WIFI_BLOCKED_TIMEOUT_SF) +#define RSI_SELECT_RESPONSE_WAIT_TIME ((RSI_WAIT_FOREVER * WIFI_BLOCKED_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_SOCKET_RECVFROM_RESPONSE_WAIT_TIME ((RSI_WAIT_FOREVER * WIFI_BLOCKED_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_GPIO_WAIT_TIME 10000 +#define RSI_RX_EVENT_WAIT_TIME DEFAULT_TIMEOUT +#define RSI_COMMON_SEND_CMD_RESPONSE_WAIT_TIME ((250000 * WIFI_BLOCKED_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_WLAN_SEND_CMD_RESPONSE_WAIT_TIME ((250000 * WIFI_BLOCKED_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_NWK_SEND_CMD_RESPONSE_WAIT_TIME ((250000 * WIFI_BLOCKED_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_GPIO_CONFIG_RESP_WAIT_TIME ((100 * WIFI_INTERNAL_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) + +//BT/BLE command timeouts in ms +#define RSI_BT_COMMON_CMD_RESP_WAIT_TIME ((500 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_A2DP_CMD_RESP_WAIT_TIME ((500 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_A2DP_DATA_CMD_RESP_WAIT_TIME ((2000 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_AVRCP_CMD_RESP_WAIT_TIME ((200 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_HFP_CMD_RESP_WAIT_TIME ((500 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_PBAP_CMD_RESP_WAIT_TIME ((500 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_HID_CMD_RESP_WAIT_TIME ((500 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BT_SPP_CMD_RESP_WAIT_TIME ((500 * BT_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) + +#define RSI_BLE_GAP_CMD_RESP_WAIT_TIME ((500 * BLE_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#define RSI_BLE_GATT_CMD_RESP_WAIT_TIME ((200 * BLE_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define RSI_PROP_PROTOCOL_CMD_TX_PKT_SEND_WAIT_TIME ((2000 * PROP_PROTOCOL_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) +#endif + +#define RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME ((2000 * BT_COMMON_WAIT_TIMEOUT_SF) + (DEFAULT_TIMEOUT)) + +//Antenna Output power in dBm +#define RSI_MIN_OUTPUT_POWER_IN_DBM -8 +#define RSI_MAX_OUTPUT_POWER_IN_DBM 15 + +/********TA GPIO defines ******************************/ +//! GPIO address +#define RSI_GPIO_ADDR 0x40200000 +//! PAD enable +#define PAD_REN 0x41380000 + +/******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +// enumeration for states used in common control block in driver +typedef enum rsi_common_state_e { + RSI_COMMON_STATE_NONE = 0, + RSI_COMMON_CARDREADY, + RSI_COMMON_OPERMODE_DONE +} rsi_common_state_t; + +// enumeration for states used in initial control block in driver +typedef enum rsi_device_state_e { + RSI_DEVICE_STATE_NONE = 0, + RSI_DRIVER_INIT_DONE, + RSI_DEVICE_INIT_DONE +} rsi_device_state_t; +// enumeration for command responses used in common control block +typedef enum rsi_common_cmd_response_e { + RSI_COMMON_RSP_CLEAR = 0x00, + RSI_COMMON_RSP_OPERMODE = 0x10, + RSI_COMMON_RSP_ANTENNA_SELECT = 0x1B, + RSI_COMMON_RSP_FEATURE_FRAME = 0xC8, + RSI_COMMON_RSP_SOFT_RESET = 0x1C, + RSI_COMMON_RSP_CARDREADY = 0x89, + RSI_COMMON_RSP_PWRMODE = 0x15, + RSI_COMMON_RSP_ULP_NO_RAM_RETENTION = 0xCD, + RSI_COMMON_RSP_ASYNCHRONOUS = 0xFF, + RSI_RSP_ENCRYPT_CRYPTO = 0x76, + RSI_COMMON_RSP_UART_FLOW_CTRL_ENABLE = 0xA4, + RSI_COMMON_RSP_TA_M4_COMMANDS = 0xB0, + RSI_COMMON_RSP_DEBUG_LOG = 0x26 + +#ifdef RSI_PUF_ENABLE + , + RSI_COMMON_RSP_PUF_ENROLL = 0xD0, + RSI_COMMON_RSP_PUF_DIS_ENROLL = 0xD1, + RSI_COMMON_RSP_PUF_START = 0xD2, + RSI_COMMON_RSP_PUF_SET_KEY = 0xD3, + RSI_COMMON_RSP_PUF_DIS_SET_KEY = 0xD4, + RSI_COMMON_RSP_PUF_GET_KEY = 0xD5, + RSI_COMMON_RSP_PUF_DIS_GET_KEY = 0xD6, + RSI_COMMON_RSP_PUF_LOAD_KEY = 0xD7, + RSI_COMMON_RSP_AES_ENCRYPT = 0xD8, + RSI_COMMON_RSP_AES_DECRYPT = 0xD9, + RSI_COMMON_RSP_AES_MAC = 0xDA, + RSI_COMMON_RSP_PUF_INTR_KEY = 0xCE +#endif + +#ifdef RSI_WAC_MFI_ENABLE + , + RSI_COMMON_RSP_IAP_GET_CERTIFICATE = 0xB6, + RSI_COMMON_RSP_IAP_INIT = 0xB7, + RSI_COMMON_RSP_IAP_GENERATE_SIGATURE = 0xB8 +#endif + // Reusing RSI_WLAN_REQ_FW_VERSION as RSI_COMMON_REQ_FW_VERSION + , + RSI_COMMON_RSP_FW_VERSION = 0x49, + RSI_COMMON_RSP_SWITCH_PROTO = 0x77, + RSI_COMMON_RSP_GET_RAM_DUMP = 0x92 +#ifdef RSI_ASSERT_API + , + RSI_COMMON_RSP_ASSERT = 0xE1 +#endif + , + RSI_COMMON_RSP_SET_RTC_TIMER = 0xE9, + RSI_COMMON_RSP_GET_RTC_TIMER = 0xF2 +#ifdef CONFIGURE_GPIO_FROM_HOST + , + RSI_COMMON_RSP_GPIO_CONFIG = 0x28 +#endif +#ifdef FW_LOGGING_ENABLE + , + RSI_COMMON_RSP_DEVICE_LOGGING_INIT = 0x82 +#endif + , + RSI_COMMON_RSP_MODULE_TYPE = 0xBF + +} rsi_common_cmd_response_t; + +// enumeration for command request used in common control block +typedef enum rsi_common_cmd_request_e { + + RSI_COMMON_REQ_OPERMODE = 0x10, + RSI_COMMON_REQ_ANTENNA_SELECT = 0x1B, + RSI_COMMON_REQ_FEATURE_FRAME = 0xC8, + RSI_COMMON_REQ_SOFT_RESET = 0x1C, + RSI_COMMON_REQ_PWRMODE = 0x15, + RSI_COMMON_REQ_ENCRYPT_CRYPTO = 0x76, + RSI_COMMON_REQ_UART_FLOW_CTRL_ENABLE = 0xA4, + RSI_COMMON_REQ_TA_M4_COMMANDS = 0xB0, + RSI_COMMON_REQ_DEBUG_LOG = 0x26 + +#ifdef RSI_WAC_MFI_ENABLE + , + RSI_COMMON_REQ_IAP_GET_CERTIFICATE = 0xB6, + RSI_COMMON_REQ_IAP_INIT = 0xB7, + RSI_COMMON_REQ_IAP_GENERATE_SIGATURE = 0xB8 +#endif + +#ifdef RSI_PUF_ENABLE + , + RSI_COMMON_REQ_PUF_ENROLL = 0xD0, + RSI_COMMON_REQ_PUF_DIS_ENROLL = 0xD1, + RSI_COMMON_REQ_PUF_START = 0xD2, + RSI_COMMON_REQ_PUF_SET_KEY = 0xD3, + RSI_COMMON_REQ_PUF_DIS_SET_KEY = 0xD4, + RSI_COMMON_REQ_PUF_GET_KEY = 0xD5, + RSI_COMMON_REQ_PUF_DIS_GET_KEY = 0xD6, + RSI_COMMON_REQ_PUF_LOAD_KEY = 0xD7, + RSI_COMMON_REQ_AES_ENCRYPT = 0xD8, + RSI_COMMON_REQ_AES_DECRYPT = 0xD9, + RSI_COMMON_REQ_AES_MAC = 0xDA, + RSI_COMMON_REQ_PUF_INTR_KEY = 0xCE +#endif + // Reusing RSI_WLAN_REQ_FW_VERSION as RSI_COMMON_REQ_FW_VERSION + , + RSI_COMMON_REQ_FW_VERSION = 0x49, + RSI_COMMON_REQ_SWITCH_PROTO = 0x77, + RSI_COMMON_REQ_GET_RAM_DUMP = 0x92 +#ifdef RSI_ASSERT_API + , + RSI_COMMON_REQ_ASSERT = 0xE1 +#endif + , + RSI_COMMON_REQ_SET_RTC_TIMER = 0xE9, + RSI_COMMON_REQ_GET_RTC_TIMER = 0xF2, + RSI_COMMON_REQ_SET_CONFIG = 0xBA +#ifdef CONFIGURE_GPIO_FROM_HOST + , + RSI_COMMON_REQ_GPIO_CONFIG = 0x28 +#endif +#ifdef FW_LOGGING_ENABLE + , + RSI_COMMON_REQ_DEVICE_LOGGING_INIT = 0x82 +#endif + , + RSI_COMMON_REQ_MODULE_TYPE = 0xBF +} rsi_common_cmd_request_t; + +#ifdef RSI_PUF_ENABLE +// enumeration for Common control block for PUF state machine +typedef enum rsi_puf_state_e { + RSI_PUF_STATE_NONE = 0, + RSI_PUF_STATE_ENROLLED, + RSI_PUF_STATE_STARTED, + RSI_PUF_STATE_SET_KEY, + RSI_PUF_STATE_KEY_LOADED, + RSI_PUF_STATE_DISABLED +} rsi_puf_state_t; +#endif + +#ifdef RSI_M4_INTERFACE +typedef enum ta_m4_commands_e { + RSI_TAKE_M4_64K = 1, + RSI_GET_IPMU_PROGRAMMING_VALUES = 2, + RSI_READ_TA_REGISTER = 3, + RSI_WRITE_TA_REGISTER = 4, + // This enum varibale added for M4 has to give indication to TA, for Configure the Clock switching between 1.3V to 3.3 .For more details check Jira Ticket RSC-3802. + RSI_ENABLE_XTAL = 5, +#ifdef CHIP_9117 + RSI_WRITE_TO_COMMON_FLASH = 6, +#endif +} ta_m4_commands_t; +// M4 and TA secure handshake request structure. +typedef struct ta_m4_handshake_param { + // sub_cmd form the enum ta_m4_commands_e(Main command type is RSI_COMMON_REQ_TA_M4_COMMANDS) + ta_m4_commands_t sub_cmd; + // length of input_data + uint8_t input_data_size; + // Input data. In this input data first byte is reserved for enable(1) or Disable(0) sub_cmd of this structure. + uint8_t *input_data; +} ta_m4_handshake_param_t; + +#ifdef CHIP_9117 +#define RSI_MAX_CHUNK_SIZE 1400 + +// TA2M4 handshake request structure. +typedef struct rsi_req_ta2m4_s { + // sub_cmd + uint8_t sub_cmd; + + // TA flash location + uint32_t addr; + + // total length of input data + uint16_t in_buf_len; + + // total length of chunk + uint16_t chunk_len; + + // more chunks or last chunk + uint8_t more_chunks; + + //data + uint8_t input_data[RSI_MAX_CHUNK_SIZE]; +} __attribute__((__packed__)) rsi_req_ta2m4_t; +#endif +#endif + +#define RSI_DMA_VALID 0 +#define RSI_SKIP_DMA_VALID 1 +#ifndef RSI_M4_INTERFACE +#define DEBUGOUT(...) +#endif + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// opermode command request structure +typedef struct rsi_opermode_s { + // operating mode 0-client, 1-p2p, 2-EAP, 6-AP, 8-PER + uint8_t opermode[4]; + + // BIT(0)-Open mode security, BIT(1)-PSK security, BIT(2) JSON objects + uint8_t feature_bit_map[4]; + + // BIT(0)-tcp/ip bypass, BIT(1)-HTTP server,BIT(2)-DHCPV4 client, + uint8_t tcp_ip_feature_bit_map[4]; + + // BIT(3)-DHCPV6 client, BIT(4)-DHCPV4 server, BIT(5)-DHCPV6 server + uint8_t custom_feature_bit_map[4]; + + // Extended custom feature bitmap + uint8_t ext_custom_feature_bit_map[4]; + + // BYTE(0): Reserved + // BYTE(2): (0-3): Reserved, (4-6): BT classic slaves, 7: A2DP profile enable + // BYTE(3): (0): A2DP proifle role 0- sink, 1 - source, (1) - A2DP Accelerated Mode Enable, (2-5): reserved, 6 - RF type, 7-reserved + uint8_t bt_feature_bit_map[4]; + + // Extended tcp/ip feature bit map + uint8_t ext_tcp_ip_feature_bit_map[4]; + + // BYTE(0) - BLE nbr of attributes, + // BYTE(1): (0 - 3): BLE Nbr of GATT services + // BYTE(1): (4 - 7): BLE Nbr of slaves + // BYTE(2): (0 - 7) BLE powersave index, + // BYTE(3): (0 - 2)BLE powersave options, + // BYTE(3): (3: 5) Reserved, + // BYTE(3): bit 6: BLE new features enable + // BYTE(3): bit 7: Reserved, + // BYTE(4): bits (4 - 5):BLE Nbr of masters + uint8_t ble_feature_bit_map[4]; + + // BYTE(0): (0 - 3): BLE number of connection events + // BYTE(1): (4 - 5): BLE number of connection events + uint8_t ble_ext_feature_bit_map[4]; + uint8_t config_feature_bit_map[4]; +} rsi_opermode_t; + +// Antenna select command request structure +typedef struct rsi_antenna_select_s { + // Antenna value to set + uint8_t antenna_value; + // Antenna 2G gain value + uint8_t gain_2g; + // Antenna 5G gain value + uint8_t gain_5g; + +} rsi_antenna_select_t; + +// UART debug prints request structure +typedef struct rsi_debug_uart_print_s { + // assertion_type + uint32_t assertion_type; + // assertion_level + uint32_t assertion_level; +} rsi_debug_uart_print_t; + +// RR feature frame command request structure +typedef struct rsi_feature_frame_s { + // PLL mode val + uint8_t pll_mode; + // rf type + uint8_t rf_type; + // wireless mode + uint8_t wireless_mode; + // enable ppp + uint8_t enable_ppp; + // afe type + uint8_t afe_type; + uint8_t disable_programming; + uint16_t reserved; + // feature enables + uint32_t feature_enables; + +} rsi_feature_frame_t; + +/****************************************************** + * * Structures + * ******************************************************/ + +// driver power save structure +typedef struct rsi_power_save_s { + // wlan driver power save profile mode + uint8_t wlan_psp_mode; + + // bt driver power save profile mode + uint8_t bt_psp_mode; + + uint8_t zb_psp_mode; + // wlan_driver power save profile type + uint8_t wlan_psp_type; + + // bt_driver power save profile type + uint8_t bt_psp_type; + + uint8_t zb_psp_type; + // module power save state + volatile uint32_t module_state; + +// Module power save State Machine +#define RSI_IDLE 0 +#define RSI_SLP_RECEIVED 1 +#define RSI_SLP_ACK_SENT 2 +#define RSI_WKUP_RECEIVED 3 + + // This is used to detect current module power mode is executing + uint8_t current_ps_mode; + + // This is used to detect current power save mode profile type + uint8_t power_save_enable; +} rsi_power_save_t; + +// Set Sleep Timer structure +typedef struct rsi_set_sleep_timer_s { + uint8_t timeval[2]; +} rsi_set_sleep_timer_t; + +// driver common block structure +typedef struct rsi_common_cb_s { + // driver common block state + volatile rsi_common_state_t state; + + // driver common block status + volatile int32_t status; + + // driver common block mutex + rsi_mutex_handle_t common_mutex; + + // driver common block command expected response + rsi_common_cmd_response_t expected_response; + + // driver common block semaphore + rsi_semaphore_handle_t common_sem; + + // driver common block tx pool + rsi_pkt_pool_t common_tx_pool; + + // power save backups + rsi_power_save_t power_save; + + // coex mode variable for power save command + uint16_t ps_coex_mode; + + // buffer pointer given by application to driver + uint8_t *app_buffer; + + // buffer length given by application to driver + uint32_t app_buffer_length; + +#ifdef RSI_PUF_ENABLE + // PUF state variable + volatile rsi_puf_state_t puf_state; +#endif +#ifdef RSI_M4_INTERFACE + efuse_ipmu_t *ipmu_calib_data_cb; +#endif +#ifdef RSI_WITH_OS + rsi_semaphore_handle_t common_card_ready_sem; +#endif +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD + rsi_semaphore_handle_t wakeup_gpio_sem; +#endif + uint8_t sync_mode; +#ifdef FW_LOGGING_ENABLE + void (*sl_fw_log_callback)(uint8_t *log_message, uint16_t log_message_length); +#endif +} rsi_common_cb_t; + +typedef enum { + ALLOW = 0, + IN_USE = 1, +} command_state; +typedef enum { + COMMON_CMD = 0, + WLAN_CMD = 1, + NWK_CMD = 2, + SOCKET_CMD = 3, + TX_EVENT_CMD = 4, + RX_EVENT_CMD = 5, + BT_CMD = 6, +#ifdef RSI_PROP_PROTOCOL_ENABLE + PROP_PROTOCOL_CMD = 7 +#endif +} command_type; + +typedef enum { + RSI_NWK_CMD_IN_FREE_STATE = 0, + RSI_NWK_CMD_IN_PROGRESS = 1, +} nwk_cmd_state; + +typedef enum { + RSI_WLAN_CMD_IN_FREE_STATE = 0, + RSI_WLAN_CMD_IN_PROGRESS = 1, +} wlan_cmd_state; + +typedef enum { + RSI_COMMON_CMD_IN_FREE_STATE = 0, + RSI_COMMON_CMD_IN_PROGRESS = 1, +} common_cmd_state; + +typedef enum { + RSI_SOCKET_CMD_IN_FREE_STATE = 0, + RSI_SOCKET_CMD_IN_PROGRESS = 1, +} socket_state; + +typedef enum { + RSI_MODULE_TYPE_Q7 = 1, + RSI_MODULE_TYPE_SB = 4, + RSI_MODULE_TYPE_M7DB = 5, + RSI_MODULE_TYPE_M4SB = 6, + RSI_MODULE_TYPE_WMS = 10 +} module_type; + +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) +#define SDIO_BUFFER_LENGTH (2048 + RSI_SSL_RECV_BUFFER_LENGTH) +#endif +typedef struct rsi_driver_cb_non_rom { + uint32_t rom_version_info; + uint32_t tx_mask_event; + rsi_mutex_handle_t tx_mutex; +#ifdef SAPI_LOGGING_ENABLE + rsi_mutex_handle_t logging_mutex; +#endif +#if defined(RSI_DEBUG_PRINTS) || defined(FW_LOGGING_ENABLE) + rsi_mutex_handle_t debug_prints_mutex; +#endif + rsi_semaphore_handle_t nwk_sem; + rsi_semaphore_handle_t wlan_cmd_sem; + rsi_semaphore_handle_t common_cmd_sem; + rsi_semaphore_handle_t common_cmd_send_sem; + rsi_semaphore_handle_t wlan_cmd_send_sem; + rsi_semaphore_handle_t nwk_cmd_send_sem; + rsi_semaphore_handle_t send_data_sem; + uint8_t nwk_wait_bitmap; + uint8_t wlan_wait_bitmap; + uint8_t send_wait_bitmap; + uint8_t common_wait_bitmap; + uint8_t zigb_wait_bitmap; + uint8_t bt_wait_bitmap; + uint8_t bt_cmd_wait_bitmap; + volatile uint8_t nwk_cmd_state; + volatile int32_t nwk_status; + volatile uint8_t socket_state; + volatile int32_t socket_status; + volatile uint8_t wlan_cmd_state; + volatile uint8_t common_cmd_state; + volatile uint32_t timer_counter; +#ifndef RSI_TX_EVENT_HANDLE_TIMER_DISABLE + volatile uint32_t driver_timer_start; + rsi_timer_instance_t timer_start; +#endif +#ifndef RSI_RX_EVENT_HANDLE_TIMER_DISABLE + volatile uint32_t driver_rx_timer_start; + rsi_timer_instance_t rx_timer_start; +#endif + +#ifdef RSI_SPI_INTERFACE + uint32_t rsi_spiTimer1; + uint32_t rsi_spiTimer2; + uint32_t rsi_spiTimer3; + uint32_t rsi_spiTimer4; +#endif +#ifdef RSI_SDIO_INTERFACE + uint32_t rsi_sdioTimer; +#endif +#if ((defined RSI_SDIO_INTERFACE) && (!defined LINUX_PLATFORM)) + uint8_t sdio_read_buff[SDIO_BUFFER_LENGTH]; +#endif + //! timer flag + uint32_t rx_driver_flag; + volatile rsi_device_state_t device_state; +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + //error response handler pointer + void (*rsi_wait_timeout_handler_error_cb)(int32_t status, uint32_t cmd_type); +#endif + // buffer pointer given by application to driver + uint8_t *nwk_app_buffer; + + // buffer length given by application to driver + uint32_t nwk_app_buffer_length; + uint8_t module_type_valid; + uint8_t module_type_id; +} rsi_driver_cb_non_rom_t; +typedef struct rsi_set_config_s { +#define XO_CTUNE_FROM_HOST BIT(0) + uint32_t code; + union { + uint8_t xo_ctune; + } values; +} rsi_set_config_t; + +/** + * RTC time from host + */ +typedef struct module_rtc_time_s { + uint8_t tm_sec[4]; //@ seconds [0-59] + uint8_t tm_min[4]; //@ minutes [0-59] + uint8_t tm_hour[4]; //@ hours since midnight [0-23] + uint8_t tm_mday[4]; //@ day of the month [1-31] + uint8_t tm_mon[4]; //@ months since January [0-11] + uint8_t tm_year[4]; //@ year since 1990 + uint8_t tm_wday[4]; //@ Weekday from Sunday to Saturday [1-7] +} module_rtc_time_t; + +extern rsi_driver_cb_non_rom_t *rsi_driver_cb_non_rom; +extern rsi_wlan_cb_non_rom_t *rsi_wlan_cb_non_rom; +#define COMMON_PKT 1 +#define BT_BLE_STACK_PACKET 2 +#define BT_PKT 3 +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define PROP_PROTOCOL_PKT 4 +#endif +#define ZB_PKT 5 +#define WLAN_PKT 6 +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_driver_process_common_recv_cmd(rsi_pkt_t *pkt); +int32_t rsi_driver_common_send_cmd(rsi_common_cmd_request_t cmd, rsi_pkt_t *pkt); +int8_t rsi_common_cb_init(rsi_common_cb_t *common_cb); +void rsi_common_set_status(int32_t status); +void rsi_handle_slp_wkp(uint8_t frame_type); +int8_t rsi_req_wakeup(void); +int8_t rsi_wait4wakeup(void); +void rsi_allow_sleep(void); +void rsi_powersave_gpio_init(void); +void rsi_common_packet_transfer_done(rsi_pkt_t *pkt); +int32_t rsi_sleep_mode_decision(rsi_common_cb_t *rsi_common_cb); +int32_t rsi_cmd_m4_ta_secure_handshake(uint8_t sub_cmd_type, + uint8_t input_len, + uint8_t *input_data, + uint8_t output_len, + uint8_t *output_data); +void rsi_update_common_cmd_state_to_free_state(void); +void rsi_update_common_cmd_state_to_progress_state(void); +rsi_error_t rsi_wait_on_common_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms); +int32_t rsi_check_and_update_cmd_state(uint8_t cmd_type, uint8_t cmd_state); +void rsi_post_waiting_wlan_semaphore(void); +void rsi_post_waiting_common_semaphore(void); +void rsi_post_waiting_bt_semaphore(void); +int32_t rsi_release_waiting_semaphore(void); +void rsi_check_pkt_queue_and_dequeue(void); +void rsi_free_queue_pkt(uint8_t pkt_dequeued, rsi_pkt_t *pkt); +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE +void rsi_wait_timeout_handler_error_cb(int32_t status, uint32_t cmd_type); +void rsi_register_wait_timeout_error_callbacks(void (*callback_handler_ptr)(int32_t status, uint32_t cmd_type)); +#endif +#if (!defined RSI_TX_EVENT_HANDLE_TIMER_DISABLE || !defined RSI_RX_EVENT_HANDLE_TIMER_DISABLE) +void rsi_error_timeout_and_clear_events(int32_t error, uint32_t cmd_type); +#endif +int32_t rsi_check_waiting_cmds(rsi_rsp_waiting_cmds_t *response); +int32_t rsi_set_config(uint32_t code, uint8_t value); +#ifdef WAKEUP_GPIO_INTERRUPT_METHOD +void rsi_give_wakeup_indication(void); +void rsi_hal_gpio_clear(void); +void rsi_hal_gpio_mask(void); +void rsi_hal_gpio_unmask(void); +#endif +#endif diff --git a/wiseconnect/sapi/include/rsi_common_apis.h b/wiseconnect/sapi/include/rsi_common_apis.h new file mode 100644 index 00000000..1ac9c4f8 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_common_apis.h @@ -0,0 +1,191 @@ +/******************************************************************************* +* @file rsi_common_apis.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_COMMON_APIS_H +#define RSI_COMMON_APIS_H +#ifdef RSI_M4_INTERFACE +#include "rsi_ccp_user_config.h" +#endif +#if defined(RSI_DEBUG_PRINTS) || (defined(RSI_ENABLE_DEBUG_PRINT) && defined(LINUX_PLATFORM)) +#include +#endif +#ifdef RSI_WITH_OS +#include "rsi_os.h" +#endif +#include "rsi_common.h" +/****************************************************** + * * Macros + * ******************************************************/ +#if !(defined(FRDM_K28F) || defined(MXRT_595s)) +#if defined(RSI_DEBUG_PRINTS) +#define LOG_PRINT(...) \ + { \ + rsi_mutex_lock(&rsi_driver_cb_non_rom->debug_prints_mutex); \ + printf(__VA_ARGS__); \ + rsi_mutex_unlock(&rsi_driver_cb_non_rom->debug_prints_mutex); \ + } +#elif (defined(RSI_M4_INTERFACE) && defined(DEBUG_UART)) +#define LOG_PRINT(...) DEBUGOUT(__VA_ARGS__) +#elif defined(RSI_ENABLE_DEBUG_PRINT) && defined(LINUX_PLATFORM) +#define LOG_PRINT(...) printf(__VA_ARGS__) +#else +#define LOG_PRINT(...) +#endif +#endif + +// To select antenna type , internal antenna for 301 modules RFOUT2 for 03 modules +#define RSI_INTERNAL_OR_RFOUT2 0 + +// To select antenna type , ufl connector for 301 modules RFOUT1 for 03 modules +#define RSI_UFL_OR_RFOUT1 1 + +// success return value +#define RSI_SUCCESS 0 + +// failure return value +#define RSI_FAILURE -1 + +//Load Image types +#define LOAD_NWP_FW '1' +#define LOAD_DEFAULT_NWP_FW_ACTIVE_LOW 0x71 + +// Upgrade images +#define BURN_NWP_FW 'B' + +// Upgrade images +#define RSI_JUMP_TO_PC 'J' + +#define RSI_ACTIVE_LOW_INTR 0x2 +#define RSI_ACTIVE_HIGH_INTR 0x0 +#define RSI_RX_BUFFER_CHECK 0x15 +// TX buffer full macro +#define RSI_TX_BUFFER_FULL -2 +#define RSI_SOFT_RESET 0 +#define RSI_HARD_RESET 1 + +#ifdef CONFIGURE_GPIO_FROM_HOST +typedef struct rsi_gpio_pin_config_val_s { + + uint8_t drive_strength; + uint8_t input_mode; + uint8_t default_gpio_state; + +} rsi_gpio_pin_config_val_t; + +typedef struct rsi_gpio_pin_config_s { + uint8_t gpio_type; + uint8_t config_mode; + uint8_t pin_num; + uint8_t config_values; + uint8_t output_value; + +} rsi_gpio_pin_config_t; +#endif +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +// enumerations for power save profile modes +typedef enum rsi_power_save_profile_mode_e { + RSI_ACTIVE = 0, + RSI_SLEEP_MODE_1 = 1, + RSI_SLEEP_MODE_2 = 2, + RSI_SLEEP_MODE_8 = 8, + RSI_SLEEP_MODE_10 = 10, +} rsi_power_save_profile_mode_t; + +// enumerations for power save profile types +typedef enum rsi_power_save_profile_type_e { + RSI_MAX_PSP = 0, + RSI_FAST_PSP = 1, + RSI_UAPSD = 2 +} rsi_power_save_profile_type_t; + +// enumerations for differnt power mode exists for SiLabs module +typedef enum rsi_power_save_mode_e { + RSI_POWER_MODE_DISABLE = 0, + RSI_CONNECTED_SLEEP_PS = 1, + RSI_CONNECTED_GPIO_BASED_PS = 2, + RSI_CONNECTED_MSG_BASED_PS = 3, +#ifdef RSI_M4_INTERFACE + RSI_CONNECTED_M4_BASED_PS = 4, +#endif + RSI_GPIO_BASED_DEEP_SLEEP = 8, + RSI_MSG_BASED_DEEP_SLEEP = 9, +#ifdef RSI_M4_INTERFACE + RSI_M4_BASED_DEEP_SLEEP = 10 +#endif +} rsi_power_save_mode_t; + +#ifdef CONFIGURE_GPIO_FROM_HOST +typedef enum rsi_gpio_config_mode_e { RSI_CONFIG_GPIO = 0, RSI_SET_GPIO = 1, RSI_GET_GPIO = 2 } rsi_gpio_config_mode_t; +#endif + +#ifdef RSI_M4_INTERFACE +#define NO_OF_HOURS_IN_A_DAY 24 +#define NO_OF_MINUTES_IN_AN_HOUR 60 +#define NO_OF_SECONDS_IN_A_MINUTE 60 +#define BASE_YEAR 2000 +#define SOC_OPER_FREQUENCY 36000 +#endif + +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +#include +extern int32_t rsi_driver_init(uint8_t *buffer, uint32_t length); +extern int32_t rsi_driver_deinit(void); +extern int32_t rsi_wireless_init(uint16_t opermode, uint16_t coex_mode); +extern int32_t rsi_wireless_antenna(uint8_t type, uint8_t gain_2g, uint8_t gain_5g); +extern int32_t rsi_send_feature_frame(void); +extern int32_t rsi_get_fw_version(uint8_t *response, uint16_t length); +extern int32_t rsi_get_module_type(uint8_t *response); +extern int32_t rsi_common_debug_log(int32_t assertion_type, int32_t assertion_level); +extern int32_t rsi_socket_config(void); +extern int32_t rsi_wireless_deinit(void); +extern int32_t rsi_common_get_status(void); +extern void rsi_wireless_driver_task(void); +extern int16_t rsi_check_assertion(void); +extern int32_t rsi_get_ram_log(uint32_t addr, uint32_t length); +extern int32_t rsi_driver_version(uint8_t *request); +extern int32_t rsi_set_rtc_timer(module_rtc_time_t *timer); + +#define RSI_DRIVER_VERSION "2.8.0.45" +#ifdef RSI_ASSERT_API +int32_t rsi_assert(void); +#endif +#ifdef RSI_WITH_OS +extern int32_t rsi_destroy_driver_task_and_driver_deinit(rsi_task_handle_t *task_handle); +#endif +#endif diff --git a/wiseconnect/sapi/include/rsi_crypto.h b/wiseconnect/sapi/include/rsi_crypto.h new file mode 100644 index 00000000..e3b876b2 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_crypto.h @@ -0,0 +1,409 @@ +/******************************************************************************* +* @file rsi_crypto.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_SHA_H +#define RSI_SHA_H +/****************************************************** + * * Macros + * ******************************************************/ + +#define FIRST_CHUNK BIT(0) +#define MIDDLE_CHUNK BIT(1) +#define LAST_CHUNK BIT(2) + +#define SHA_1 1 +#define SHA_256 2 +#define SHA_384 3 +#define SHA_512 4 +#define SHA_224 5 + +#define SHAKE_128 21 +#define SHAKE_256 17 +#define SHA3_224 18 +#define SHA3_256 17 +#define SHA3_384 13 +#define SHA3_512 9 + +#define AES 2 +#define SHA 4 +#define HMAC_SHA 5 +#define DH 14 +#define ECDH 15 +#define SHA3 16 +#define CHACHAPOLY 17 +#define GCM 18 +#define SHAKE 19 +#define TRNG 21 +#define ATTESTATION 30 + +#define ECDH_PM 1 +#define ECDH_PA 2 +#define ECDH_PS 3 +#define ECDH_PD 4 +#define ECDH_PAF 5 + +#define SHA_1_DIGEST_LEN 20 +#define SHA_256_DIGEST_LEN 32 +#define SHA_384_DIGEST_LEN 48 +#define SHA_512_DIGEST_LEN 64 +#define SHA_224_DIGEST_LEN 28 +#define SHAKE_128_DIGEST_LEN 16 + +#define HMAC_SHA_1 1 +#define HMAC_SHA_256 2 +#define HMAC_SHAA_384 3 +#define HMAC_SHA_512 4 +#define IV_SIZE 16 + +#define ECDH_VECTOR_192_SIZE 24 +#define ECDH_VECTOR_224_SIZE 28 +#define ECDH_VECTOR_256_SIZE 32 + +#define ECDH_MAX_OUTPUT_SIZE 96 +#define ECDH_MAX_VECTOR_SIZE 32 +#define DH_MAX_OUTPUT_SIZE 512 + +#define HMAC_SHA_1_DIGEST_LEN 20 +#define HMAC_SHA_256_DIGEST_LEN 32 +#define HMAC_SHA_384_DIGEST_LEN 48 +#define HMAC_SHA_512_DIGEST_LEN 64 + +#define CBC_MODE 1 +#define ECB_MODE 2 +#define CTR_MODE 3 + +#define AES_ENCRYPTION 1 +#define AES_DECRYPTION 2 + +#define GCM_ENCRYPTION 0 +#define GCM_DECRYPTION 1 + +#define AES_KEY_SIZE_128 16 +#define AES_KEY_SIZE_192 24 +#define AES_KEY_SIZE_256 32 + +#define GCM_KEY_SIZE_128 128 +#define GCM_KEY_SIZE_192 192 +#define GCM_KEY_SIZE_256 256 +#define GCM_IV_SIZE_IN_BYTES 12 +#define ECDH_192 1 +#define ECDH_224 2 +#define ECDH_256 4 + +//! ECDH curve types +#define ECDH_CURVE_P 0 +#define ECDH_CURVE_K 1 +#define ECDH_CURVE_B 2 + +//!DMA Support +#define DMA_ENABLE 1 +#define DMA_DISABLE 0 + +//! PAD Char +#define PAD_CHAR_SHA3 0x06 +#define PAD_CHAR_SHAKE 0x1F +#define CHACHA20POLY1305 0 +#define CHACHA20 1 +#define CHACHAPOLY_MODE_POLY1305_KEYR_KEYS 2 +#define POLY1305_MODE 3 + +#define TAG_SIZE 16 + +#define CHACHAPOLY_ENCRYPTION 0 +#define CHACHAPOLY_DECRYPTION 1 + +#define KEY_CHACHA_SIZE 32 +#define KEYR_SIZE 16 +#define KEYS_SIZE 16 +#define NONCE_SIZE 16 +#define MAX_DATA_SIZE_BYTES 1400 /*Data size*/ +#define MAX_DATA_SIZE_BYTES_FOR_CHACHAPOLY 1200 /*Data size for chachapoly*/ + +#define TRNG_INIT 1 +#define TRNG_ENTROPY 2 +#define TRNG_KEY 3 +#define TRNG_GENERATION 4 + +#define TRNG_INIT_MSG_LENGTH 16 +#define TRNG_KEY_SIZE 4 +#define TRNG_TEST_DATA_SIZE 64 +#define NONCE_DATA_SIZE 32 +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// TRNG Request Frames Structures +typedef struct rsi_trng_req_s { + uint8_t algorithm_type; + uint8_t algorithm_sub_type; + uint16_t total_msg_length; + uint32_t trng_key[TRNG_KEY_SIZE]; + uint32_t msg[TRNG_TEST_DATA_SIZE]; +} rsi_trng_req_t; + +// Attestation token Request Frames Structures +typedef struct rsi_token_req_s { + uint8_t algorithm_type; + uint16_t total_msg_length; + uint32_t msg[NONCE_DATA_SIZE]; +} rsi_token_req_t; + +// SHA Request Frames Structures +typedef struct rsi_sha_req_s { + uint16_t algorithm_type; + uint8_t algorithm_sub_type; + uint8_t sha_flags; + uint16_t total_msg_length; + uint16_t current_chunk_length; + uint8_t msg[1400]; +} rsi_sha_req_t; + +typedef struct rsi_chachapoly_req_s { + uint16_t algorithm_type; + uint8_t algorithm_sub_type; + uint8_t chachapoly_flags; + uint16_t total_msg_length; + uint16_t header_length; + uint16_t current_chunk_length; + uint16_t encrypt_decryption; + uint32_t dma_use; + uint8_t key_chacha[32]; + uint8_t nonce[16]; + uint8_t keyr_in[16]; + uint8_t keys_in[16]; + uint8_t header_input[128]; + uint8_t msg[1200]; +} rsi_chachapoly_req_t; +typedef struct rsi_hmac_sha_req_s { + uint16_t algorithm_type; + uint8_t algorithm_sub_type; + uint8_t hmac_sha_flags; + uint16_t total_msg_length; + uint16_t current_chunk_length; + uint32_t key_length; + uint8_t hmac_data[1400]; +} rsi_hmac_sha_req_t; + +typedef struct rsi_aes_req_s { + uint16_t algorithm_type; + uint8_t algorithm_sub_type; + uint8_t aes_flags; + uint16_t total_msg_length; + uint16_t current_chunk_length; + uint16_t encrypt_decryption; + uint16_t key_length; + uint8_t key[32]; + uint8_t IV[16]; + uint8_t msg[1400]; +} rsi_aes_req_t; + +typedef struct rsi_gcm_req_s { + uint16_t algorithm_type; + uint8_t gcm_flags; + uint8_t encrypt_decryption; + uint16_t total_msg_length; + uint16_t current_chunk_length; + uint16_t key_length; + uint16_t header_length; + uint32_t dma_use; + uint8_t key[32]; + uint8_t IV[12]; + uint8_t header[128]; + uint8_t msg[1400]; +} rsi_gcm_req_t; +typedef struct rsi_exp_req_s { + uint32_t algorithm_type; + uint32_t prime_length; + uint32_t base_length; + uint32_t exponent_length; + uint8_t prime[512]; + uint8_t base[512]; + uint8_t exponent[512]; +} rsi_exp_req_t; + +typedef struct rsi_ecdh_pm_req_s { + uint8_t algorithm_type; + uint8_t ecdh_mode; + uint8_t ecdh_sub_mode; + uint8_t ecdh_curve_type; + uint8_t d[32]; + uint8_t sx[32]; + uint8_t sy[32]; + uint8_t sz[32]; +} rsi_ecdh_pm_req_t; + +typedef struct rsi_ecdh_pa_ps_req_s { + uint8_t algorithm_type; + uint8_t ecdh_mode; + uint8_t ecdh_sub_mode; + uint8_t sx[32]; + uint8_t sy[32]; + uint8_t sz[32]; + uint8_t tx[32]; + uint8_t ty[32]; + uint8_t tz[32]; +} rsi_ecdh_pa_ps_req_t; + +typedef struct rsi_ecdh_pd_req_s { + uint8_t algorithm_type; + uint8_t ecdh_mode; + uint8_t ecdh_sub_mode; + uint8_t sx[32]; + uint8_t sy[32]; + uint8_t sz[32]; +} rsi_ecdh_pd_req_t; + +typedef struct rsi_ecdh_affine_req_s { + uint8_t algorithm_type; + uint8_t ecdh_mode; + uint8_t ecdh_sub_mode; + uint8_t ecdh_curve_type; + uint8_t sx[32]; + uint8_t sy[32]; + uint8_t sz[32]; +} rsi_ecdh_affine_req_t; +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_sha(uint8_t sha_mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest); +int32_t rsi_sha_pen(uint8_t sha_mode, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_len, + uint8_t pending_flag, + uint8_t *digest); +int32_t rsi_hmac_sha(uint8_t hmac_sha_mode, + uint8_t *msg, + uint32_t msg_length, + uint8_t *key, + uint32_t key_length, + uint8_t *digest, + uint8_t *hmac_buffer); +int32_t rsi_hmac_sha_pen(uint8_t hmac_sha_mode, + uint8_t *data, + uint16_t total_length, + uint16_t chunk_length, + uint32_t key_length, + uint8_t pending_flag, + uint8_t *digest); +int32_t rsi_aes_pen(uint16_t aes_mode, + uint16_t enc_dec, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint8_t aes_flags, + uint8_t *output); +int32_t rsi_aes(uint16_t aes_mode, + uint16_t enc_dec, + uint8_t *msg, + uint16_t msg_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint8_t *output); +int32_t rsi_exponentiation(uint8_t *prime, + uint32_t prime_length, + uint8_t *base, + uint32_t base_length, + uint8_t *exponent, + uint32_t exponent_length, + uint8_t *exp_result); +int32_t rsi_sha3(uint8_t mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest); +int32_t rsi_shake(uint8_t mode, uint8_t *msg, uint16_t msg_length, uint8_t *digest); +int32_t rsi_sha3_shake_pen(uint8_t pad_char, + uint8_t mode, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_len, + uint8_t pending_flag, + uint8_t *digest); +int32_t rsi_chachapoly(uint16_t chachapoly_mode, + uint16_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint8_t *key_chacha, + uint8_t *keyr_in, + uint8_t *keys_in, + uint8_t *nonce, + uint8_t *header_input, + uint16_t header_length, + uint8_t *output); +int32_t rsi_chachapoly_pen(uint16_t chachapoly_mode, + uint16_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_len, + uint8_t *key_chacha, + uint8_t *keyr_in, + uint8_t *keys_in, + uint8_t *nonce, + uint8_t *header_input, + uint16_t header_length, + uint8_t chachapoly_flags, + uint8_t *output); +int32_t rsi_gcm_pen(uint8_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint16_t chunk_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint16_t iv_sz, + uint8_t *header, + uint16_t header_length, + uint8_t gcm_flags, + uint8_t *output); +int32_t rsi_gcm(uint8_t enc_dec, + uint16_t dma_use, + uint8_t *msg, + uint16_t msg_length, + uint8_t *key, + uint16_t key_length, + uint8_t *iv, + uint16_t iv_sz, + uint8_t *header, + uint16_t header_length, + uint8_t *output); +int32_t trng_init(uint32_t *trng_key, uint32_t *trng_test_data, uint16_t input_length, uint32_t *output); +int32_t trng_get_random_num(uint32_t *random_number, uint16_t length); +int32_t trng_program_key(uint32_t *trng_key, uint16_t key_length); +int32_t trng_entropy(void); +int32_t sl_attestation_get_token(uint8_t *token, uint16_t length, uint32_t *nonce); +#endif diff --git a/wiseconnect/sapi/include/rsi_data_types.h b/wiseconnect/sapi/include/rsi_data_types.h new file mode 100644 index 00000000..5675c8ec --- /dev/null +++ b/wiseconnect/sapi/include/rsi_data_types.h @@ -0,0 +1,94 @@ +/******************************************************************************* +* @file rsi_data_types.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_DATA_TYPES_H +#define RSI_DATA_TYPES_H +#include +/****************************************************** + * * Macros + * ******************************************************/ +#ifndef NULL +#define NULL 0 +#endif + +//! Enable feature +#define RSI_ENABLE 1 +//! Disable feature +#define RSI_DISABLE 0 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +#if 0 +#ifndef int8_t +typedef signed char int8_t; +#endif + +#ifndef uint8_t +typedef unsigned char uint8_t; +#endif + +#ifndef int16_t +typedef short int int16_t; +#endif + +#ifndef uint16_t +typedef unsigned short int uint16_t; +#endif + +#ifndef int32_t +typedef int int32_t; +#endif + +#ifndef uint32_t +typedef unsigned int uint32_t; +#endif + +#ifndef int64_t +typedef signed long long int int64_t; +#endif + +#ifndef uint64_t +typedef unsigned long long int uint64_t; +#endif +#endif + +#ifndef RSI_M4_INTERFACE +#define STATIC static +#define INLINE inline +#endif +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +#endif diff --git a/wiseconnect/sapi/include/rsi_driver.h b/wiseconnect/sapi/include/rsi_driver.h new file mode 100644 index 00000000..fe9d6ac1 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_driver.h @@ -0,0 +1,283 @@ +/******************************************************************************* +* @file rsi_driver.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_DRIVER_H +#define RSI_DRIVER_H + +#ifndef EFM32_SDIO // This file is not needed for EFM32 board. In order to avoid compilation warnings, we excluded the below code for EFM32 +#include "rsi_board_configuration.h" +#endif +#ifdef RSI_M4_INTERFACE +#include "rsi_ccp_user_config.h" +#endif +#include +#include +#include +//#ifdef WISECONNECT +#if (defined(__CC_ARM) || defined(WISECONNECT) || defined(RSI_M4_INTERFACE)) +#ifdef RSI_WLAN_API_ENABLE +#include +#endif +#elif defined(RSI_WLAN_ENABLE) +#include +#endif +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE)) +#ifdef RSI_BT_ENABLE +#include +#endif +#ifdef RSI_BLE_ENABLE +#include +#else +#include "rsi_ble_common_config.h" +#endif +#endif +#ifndef RSI_ENABLE_DEMOS +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef RSI_SPI_INTERFACE +#include +#include +#endif +#ifdef RSI_SDIO_INTERFACE +#include +#endif +#ifdef RSI_UART_INTERFACE +#include +#endif +#include +#include +#include +#include +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE)) +#include +#include + +#include "rsi_bt.h" +#include "rsi_ble.h" +#include "rsi_bt_common_apis.h" +#endif +#ifdef RSI_ZB_ENABLE +#include +#endif +#include +#ifdef __GNUC__ +#include "strings.h" +#endif +#ifdef RSI_WAC_MFI_ENABLE +#include "rsi_iap.h" +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE +#include "rsi_prop_protocol.h" +#endif +#include "rsi_apis_rom.h" +#include "rsi_wlan_non_rom.h" +#ifdef SAPI_LOGGING_ENABLE +#include "debug_auto_gen.h" +#include "sl_app_logging.h" +#endif +#ifdef FW_LOGGING_ENABLE +#include "sl_fw_logging.h" +#endif + +//#include +/****************************************************** + * * Macros + * ******************************************************/ + +// string functions +#define rsi_strcpy(x, y) strcpy((char *)x, (const char *)y) +#define rsi_strcat(x, y) strcat((char *)x, (const char *)y) +#define rsi_strlen(x) strlen((const char *)x) +#define rsi_strncasecmp(x, y, z) strncasecmp((const char *)x, (const char *)y, (size_t)z) +// Below macros were used to avoid warnings for unused variables present in the API arguments +#define USED_PARAMETER(x) x = x /*To avoid gcc/g++ warnings*/ +#define UNUSED_PARAMETER(x) x = x /*To avoid gcc/g++ warnings*/ +// for unused constant variables, the below assignment is valid than above +#define USED_CONST_PARAMETER(x) (void)x /*To avoid gcc/g++ warnings*/ +#define UNUSED_CONST_PARAMETER(x) (void)x /*To avoid gcc/g++ warnings*/ + +//! common type +#define RSI_COMMON_Q 0 +// ZB protocol type +#define RSI_ZB_Q 1 + +// BT protocol type +#define RSI_BT_Q 2 +#ifdef SAPIS_BT_STACK_ON_HOST +#define RSI_BT_INT_MGMT_Q 6 +#define RSI_BT_HCI_Q 7 +#endif +// WLAN mgmt queue type +#define RSI_WLAN_MGMT_Q 4 + +// WLAN data queue type +#define RSI_WLAN_DATA_Q 5 + +#ifdef FW_LOGGING_ENABLE +#define RSI_SL_LOG_DATA_Q 8 +#define SL_LOG_DATA 0x01 +#endif + +// frame descriptor length +#define RSI_FRAME_DESC_LEN 16 + +// status offset in frame descriptor +#define RSI_STATUS_OFFSET 12 + +// response type offset in frame descriptor +#define RSI_RESP_OFFSET 2 + +#define RSI_TRUE 1 +#define RSI_FALSE 0 + +//SL_PRINTF logging call +#ifndef SL_PRINTF +#define SL_PRINTF(...) +#endif + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// driver control block structure +typedef struct rsi_driver_cb_s { + // rx packet pool + rsi_pkt_pool_t rx_pool; + + // driver common control block structure pointer + rsi_common_cb_t *common_cb; + + // driver common control block TX queue + rsi_queue_cb_t common_tx_q; + + // driver WLAN control block structure pointer + rsi_wlan_cb_t *wlan_cb; + + // driver WLAN control block TX queue + rsi_queue_cb_t wlan_tx_q; + + // driver scheduler control block + rsi_scheduler_cb_t scheduler_cb; + + // driver event list structure +#if (defined(RSI_M4_INTERFACE) && !defined(A11_ROM)) + rsi_event_cb_t event_list[RSI_MAX_NUM_EVENTS]; +#else + rsi_event_cb_t *event_list; +#endif + rsi_queue_cb_t m4_tx_q; + + rsi_queue_cb_t m4_rx_q; + + void (*rsi_tx_done_handler)(struct rsi_pkt_s *); + +#ifdef RSI_ZB_ENABLE + // driver BT/ZB control block structure pointer + rsi_zigb_cb_t *zigb_cb; + + // driver BT/ZB control block TX queue + rsi_queue_cb_t zigb_tx_q; +#endif + +#if (defined(RSI_BT_ENABLE) || defined(RSI_BLE_ENABLE) || defined(RSI_PROP_PROTOCOL_ENABLE)) + rsi_bt_global_cb_t *bt_global_cb; + + rsi_bt_cb_t *bt_common_cb; + rsi_queue_cb_t bt_single_tx_q; + rsi_queue_cb_t bt_common_tx_q; +#endif +#ifdef RSI_BT_ENABLE + rsi_bt_cb_t *bt_classic_cb; + rsi_queue_cb_t bt_classic_tx_q; +#endif +#ifdef RSI_BLE_ENABLE + rsi_bt_cb_t *ble_cb; +#endif +#ifdef RSI_PROP_PROTOCOL_ENABLE + rsi_bt_cb_t *prop_protocol_cb; + rsi_queue_cb_t prop_protocol_tx_q; +#endif +#ifdef SAPIS_BT_STACK_ON_HOST + rsi_bt_cb_t *bt_ble_stack_cb; + // driver BT/BLE stack control block TX queue + rsi_queue_cb_t bt_ble_stack_tx_q; +#endif + +// tx packet state in case of UART interface +#ifdef RSI_UART_INTERFACE + uint8_t tx_pkt_state; +#endif + + void (*unregistered_event_callback)(uint32_t event_num); + +#ifdef FW_LOGGING_ENABLE + sl_fw_log_cb_t *fw_log_cb; +#endif +} rsi_driver_cb_t; + +#define RSI_PKT_ALLOC_RESPONSE_WAIT_TIME 100000 +#define RSI_PKT_FREE_RESPONSE_WAIT_TIME 100000 + +extern rsi_driver_cb_t *rsi_driver_cb; +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_send_ps_mode_to_module(uint8_t selected_ps_mode, uint8_t selected_ps_type); +int32_t rsi_driver_process_bt_zb_recv_cmd(rsi_pkt_t *pkt); +void rsi_clear_sockets(int32_t sockID); +void rsi_interrupt_handler(void); +void rsi_mask_ta_interrupt(void); +void rsi_unmask_ta_interrupt(void); +uint32_t rsi_hal_critical_section_entry(void); +void rsi_hal_critical_section_exit(void); + +int32_t rsi_driver_process_recv_data(rsi_pkt_t *pkt); +//int32_t rsi_driver_send_data(int32_t sock_no, uint8_t* buffer, uint32_t length, struct rsi_sockaddr *destAddr); +int32_t rsi_send_raw_data(uint8_t *buffer, uint32_t length); +int32_t rsi_ftp_mode_set(uint8_t mode); + +#endif diff --git a/wiseconnect/sapi/include/rsi_error.h b/wiseconnect/sapi/include/rsi_error.h new file mode 100644 index 00000000..31c04463 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_error.h @@ -0,0 +1,112 @@ +/******************************************************************************* +* @file rsi_error.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_ERROR_H +#define RSI_ERROR_H +/****************************************************** + * * Macros + * ******************************************************/ +#define RSI_ERROR_REMOTE_TERNIMATE 0xFF62 +#define RSI_ERROR_SOCKET_RCV_TIMEOUT 0xFF6A +#define RSI_ERROR_MQTT_PING_TIMEOUT 0xBBF1 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +// enumeration for error codes used in driver +typedef enum rsi_error_e { + RSI_ERROR_NONE = 0, + RSI_ERROR_TIMEOUT = -1, // Time out error + RSI_ERROR_INVALID_PARAM = -2, // Invalid param error + RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE = -3, + RSI_ERROR_PKT_ALLOCATION_FAILURE = -4, + RSI_ERROR_COMMAND_NOT_SUPPORTED = -5, + RSI_ERROR_INSUFFICIENT_BUFFER = -6, + RSI_ERROR_IN_OS_OPERATION = -7, + RSI_ERROR_INVALID_MEMORY = -8, + RSI_ERROR_BOOTUP_OPTIONS_NOT_SAVED = -9, + RSI_ERROR_BOOTUP_OPTIONS_CHECKSUM_FAIL = -10, + RSI_ERROR_BOOTLOADER_VERSION_NOT_MATCHING = -11, + RSI_ERROR_WAITING_FOR_BOARD_READY = -12, + RSI_ERROR_INVALID_ADDRESS = -13, + RSI_ERROR_VALID_FIRMWARE_NOT_PRESENT = -14, + RSI_ERROR_INVALID_OPTION = -15, + RSI_ERROR_EXCEEDS_MAX_CALLBACKS = -16, + RSI_ERROR_SET_ITIMER = -17, + RSI_ERROR_SIG_ACTION = -18, + RSI_ERROR_NOT_IN_CONNECTED_STATE = -19, + RSI_ERROR_NOT_IN_IPCONFIG_STATE = -20, + RSI_ERROR_SPI_BUSY = -21, + RSI_ERROR_SPI_FAIL = -22, + RSI_ERROR_SPI_TIMEOUT = -23, + RSI_ERROR_CARD_READY_TIMEOUT = -24, + RSI_ERROR_BOARD_READY_TIMEOUT = -25, + RSI_ERROR_INVALID_PACKET = -26, + RSI_ERROR_FW_UPGRADE_TIMEOUT = -27, + RSI_ERROR_FW_LOAD_OR_UPGRADE_TIMEOUT = -28, + RSI_ERROR_GPIO_WAKEUP_TIMEOUT = -29, + RSI_ERROR_RESPONSE_TIMEOUT = -30, + RSI_ERROR_BLE_DEV_BUF_FULL = -31, + RSI_ERROR_NWK_CMD_IN_PROGRESS = -32, + RSI_ERROR_SOCKET_CMD_IN_PROGRESS = -33, + RSI_ERROR_WLAN_CMD_IN_PROGRESS = -34, + RSI_ERROR_COMMON_CMD_IN_PROGRESS = -35, + RSI_ERROR_PROP_PROTOCOL_DEV_BUF_FULL = -36, + RSI_ERROR_BT_BLE_CMD_IN_PROGRESS = -37, + RSI_ERROR_PROP_PROTOCOL_CMD_IN_PROGRESS = -38, + RSI_ERROR_BLE_ATT_CMD_IN_PROGRESS = -39, + RSI_ERROR_MEMORY_NOT_ALIGNED = -40, + RSI_ERROR_SEMAPHORE_CREATE_FAILED = -41, + RSI_ERROR_SEMAPHORE_DESTROY_FAILED = -42, + RSI_ERROR_IN_WLAN_CMD = -43, + RSI_ERROR_RX_BUFFER_CHECK = -44, + RSI_ERROR_PARAMTER_LENGTH_EXCEEDS_MAX_VAL = -45, + RSI_ERROR_IN_COMMON_CMD = -46, + RSI_ERROR_TX_BUFFER_FULL = -47, + RSI_ERROR_SDIO_TIMEOUT = -48, + RSI_ERROR_SDIO_WRITE_FAIL = -49, + RSI_ERROR_INVALID_SET_CONFIG_FLAG = -50, + RSI_ERROR_BLE_DEV_BUF_IS_IN_PROGRESS = -51, + RSI_ERROR_SET_REGION_NOT_ENABLED = -52, + RSI_ERROR_BLE_INVALID_CALLBACK_CNT = -53, + RSI_ERROR_BLE_ADV_EXT_COMMAND_NOT_ALLOWED = -54, + RSI_ERROR_BLE_LEGACY_COMMAND_NOT_ALLOWED = -55, +} rsi_error_t; + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +#endif diff --git a/wiseconnect/sapi/include/rsi_events.h b/wiseconnect/sapi/include/rsi_events.h new file mode 100644 index 00000000..6acd1e80 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_events.h @@ -0,0 +1,129 @@ +/******************************************************************************* +* @file rsi_events.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_EVENTS_H +#define RSI_EVENTS_H +/****************************************************** + * * Macros + * ******************************************************/ +#ifndef RSI_M4_INTERFACE +#ifdef RSI_ENABLE_DEMOS +// Max number events used in the driver +#define RSI_MAX_NUM_EVENTS 5 + +// RX event number used in the driver +#define RSI_RX_EVENT 1 + +// TX event number used in the driver +#define RSI_TX_EVENT 0 + +// Socket event number used in the driver +#define RSI_SOCKET_EVENT 2 + +// Application event1 number used in driver +#define RSI_APP_EVENT1 3 + +// Application event1 number used in driver +#define RSI_APP_EVENT2 4 + +#else + +// Max number events used in the driver +#define RSI_MAX_NUM_EVENTS 3 + +// RX event number used in the driver +#define RSI_RX_EVENT 0 + +// TX event number used in the driver +#define RSI_TX_EVENT 1 + +// Socket event number used in the driver +#define RSI_SOCKET_EVENT 2 + +#endif +#else + +// Max number events used in the driver +#define RSI_MAX_NUM_EVENTS 2 + +// RX event number used in the driver +#define RSI_RX_EVENT 1 + +// TX event number used in the driver +#define RSI_TX_EVENT 0 + +#endif + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// event handler structure +typedef struct rsi_event_cb_s { + // event handler pointer + void (*event_handler)(void); +} rsi_event_cb_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +uint16_t rsi_register_event(uint32_t event_id, void (*event_handler_ptr)(void)); +uint32_t rsi_find_event(uint32_t event_map); +void rsi_set_event(uint32_t event_num); +void rsi_clear_event(uint32_t event_num); +void rsi_mask_event(uint32_t event_num); +void rsi_unmask_event(uint32_t event_num); +void rsi_tx_event_handler(void); +void rsi_rx_event_handler(void); +void rsi_set_event_from_isr(uint32_t event_num); +void rsi_unmask_event_from_isr(uint32_t event_num); +rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore); +#ifndef RSI_M4_INTERFACE + +#ifdef RSI_ENABLE_DEMOS + +#if (BT_A2DP_SOURCE_WIFI_HTTP_S_RX || BLE_DUAL_MODE_BT_A2DP_SOURCE_WIFI_HTTP_S_RX \ + || BT_A2DP_SOURCE_WIFI_HTTP_S_RX_DYN_COEX) +void rsi_app_event1_handler(void); +void rsi_app_event2_handler(void); +#endif + +#endif + +void rsi_socket_event_handler(void); +#endif +void rsi_events_init(void); + +#endif diff --git a/wiseconnect/sapi/include/rsi_hal.h b/wiseconnect/sapi/include/rsi_hal.h new file mode 100644 index 00000000..a18d5692 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_hal.h @@ -0,0 +1,159 @@ +/******************************************************************************* +* @file rsi_hal.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef _RSIHAL_H_ +#define _RSIHAL_H_ + +#ifndef RSI_SAMPLE_HAL +#include "hal/rsi_hal.h" +#else + +#include +/****************************************************** + * * Macros + * ******************************************************/ + +//! User can configure this pin based on platform + +//! GPIO to reset WiSeConnect Module +#define RSI_HAL_RESET_PIN 1 + +// GPIO to receive packet pending interrupt +#define RSI_HAL_MODULE_INTERRUPT_PIN 2 + +// GPIO to receive module wakeup from power save indication +#define RSI_HAL_WAKEUP_INDICATION_PIN 3 + +// ULP GPIO to give sleep confirmation to module to goto sleep in power save +#define RSI_HAL_SLEEP_CONFIRM_PIN 4 + +// LP GPIO to give sleep confirmation to module to goto sleep in power save +#define RSI_HAL_LP_SLEEP_CONFIRM_PIN 6 + +//!ULP GPIO to receive module wakeup from wake on wireless indication +#define RSI_HAL_WOWLAN_INTR_FROM_DEV_PIN 7 + +//! ULP GPIO to give confirmation to module to goto wake on wireless mode +#define RSI_HAL_WOWLAN_CONFIRM_TO_DEV_PIN 8 + +//! GPIO for Power On Control Input to reset WiSeConnect Module +#define RSI_HAL_POC_IN_PIN 9 + +//! GPIO Pins related Macros +//! Macro to configure GPIO in output mode +#define RSI_HAL_GPIO_OUTPUT_MODE 1 + +// Macro to configure GPIO in input mode +#define RSI_HAL_GPIO_INPUT_MODE 0 + +// Macro to drive low value on GPIO +#define RSI_HAL_GPIO_LOW 0 + +// Macro to drive high value on GPIO +#define RSI_HAL_GPIO_HIGH 1 + +//! Timer related macros +//! Macro to configure timer type in single shot +#define RSI_HAL_TIMER_TYPE_SINGLE_SHOT 0 + +// Macro to configure timer type in periodic +#define RSI_HAL_TIMER_TYPE_PERIODIC 1 + +// Macro to configure timer in micro seconds mode +#define RSI_HAL_TIMER_MODE_MICRO 0 + +// Macro to configure timer in milli seconds mode +#define RSI_HAL_TIMER_MODE_MILLI 1 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +void rsi_hal_board_init(void); +void rsi_switch_to_high_clk_freq(void); +void rsi_hal_intr_config(void (*rsi_interrupt_handler)(void)); +void rsi_hal_intr_mask(void); +void rsi_hal_intr_unmask(void); +void rsi_hal_intr_clear(void); +uint8_t rsi_hal_intr_pin_status(void); +void rsi_hal_config_gpio(uint8_t gpio_number, uint8_t mode, uint8_t value); +void rsi_hal_set_gpio(uint8_t gpio_number); +uint8_t rsi_hal_get_gpio(uint8_t gpio_number); +void rsi_hal_clear_gpio(uint8_t gpio_number); +int16_t rsi_spi_transfer(uint8_t *tx_buff, uint8_t *rx_buff, uint16_t transfer_length, uint8_t mode); +int16_t rsi_uart_send(uint8_t *ptrBuf, uint16_t bufLen); +int16_t rsi_uart_recv(uint8_t *ptrBuf, uint16_t bufLen); +int16_t rsi_com_port_send(uint8_t *ptrBuf, uint16_t bufLen); +int16_t rsi_com_port_receive(uint8_t *ptrBuf, uint16_t bufLen); +uint32_t rsi_get_random_number(void); +int32_t rsi_timer_start(uint8_t timer_node, + uint8_t mode, + uint8_t type, + uint32_t duration, + void (*rsi_timer_expiry_handler)(void)); +int32_t rsi_timer_stop(uint8_t timer_node); +uint32_t rsi_timer_read(uint8_t timer_node); +void rsi_delay_us(uint32_t delay_us); +void rsi_delay_ms(uint32_t delay_ms); +uint32_t rsi_hal_gettickcount(void); +void rsi_hal_enable_uart_irq(void); +void SysTick_Handler(void); +void rsi_hal_enable_uart_irq(void); + +void rsi_interrupt_handler(void); +void ABRD(void); + +void Error_Handler(void); + +/* RTC Related API's */ +uint32_t rsi_rtc_get_time(void); +int32_t rsi_rtc_set_time(uint32_t time); +/* End - RTC Related API's */ + +#ifdef LOGGING_STATS +void rsi_hal_log_stats_intr_config(void (*rsi_give_wakeup_indication)()); +#endif +#ifdef RSI_WITH_OS +void rsi_os_delay_ms(uint32_t delay_ms); +void PORTD_IRQHandler(void); + +#endif +#endif +#endif diff --git a/wiseconnect/sapi/include/rsi_hid.h b/wiseconnect/sapi/include/rsi_hid.h new file mode 100644 index 00000000..ac5d678b --- /dev/null +++ b/wiseconnect/sapi/include/rsi_hid.h @@ -0,0 +1,113 @@ +/******************************************************************************* +* @file rsi_hid.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/************************************************************************* + * + */ + +#ifndef RSI_BT_HID_H +#define RSI_BT_HID_H + +#include +#include +#include +#include + +/* HID Profile MACROS*/ +#define HID_MSG_HANDSHAKE_LEN 0x1 +#define HID_MSG_CONTROL_LEN 0x1 +#define HID_MSG_GET_PROTO_LEN 0x1 +#define HID_MSG_SET_PROTO_LEN 0x1 +#define HID_MSG_GET_REPORT_LEN 0x1 +#define HID_MSG_SET_REPORT_LEN 0x1 + +#define HID_MSG_HANDSHAKE 0x0 +#define HID_MSG_CONTROL 0x1 +#define HID_MSG_GET_REPORT 0x4 +#define HID_MSG_SET_REPORT 0x5 +#define HID_MSG_GET_PROTO 0x6 +#define HID_MSG_SET_PROTO 0x7 +#define HID_MSG_DATA 0xA + +#define HID_REPORT_TYPE_RESERVED 0x00 +#define HID_REPORT_TYPE_INPUT 0x01 +#define HID_REPORT_TYPE_OUTPUT 0x02 +#define HID_REPORT_TYPE_FEATURE 0x03 + +#define HID_MSG_HANDSHAKE_SUCCESSFUL 0x00 +#define HID_MSG_HANDSHAKE_NOT_READY 0x01 +#define HID_MSG_HANDSHAKE_ERR_INV_REP_ID 0x02 +#define HID_MSG_HANDSHAKE_ERR_UNSUPP_REQ 0x03 +#define HID_MSG_HANDSHAKE_ERR_INV_PARAM 0x04 +#define HID_MSG_HANDSHAKE_ERR_UNKNOWN 0x0E +#define HID_MSG_HANDSHAKE_ERR_FATAL 0x0F + +#define HID_MSG_CONTROL_SUSPEND 0x03 +#define HID_MSG_CONTROL_EXIT_SUSPEND 0x04 +#define HID_MSG_CONTROL_VIRT_CABLE_UNPLUG 0x05 + +#define HID_MSG_PROTOCOL_BOOT 0x00 +#define HID_MSG_PROTOCOL_REPORT 0x01 + +#define HID_CHANNEL_CONTROL 0x00 +#define HID_CHANNEL_INTERRUPT 0x01 + +#define RSI_HID_DEVICE_VERSION_NUM 0x0100 +#define RSI_PARSER_VERSION 0x0111 +#define RSI_HID_DEV_SUBCLASS 0x0040 +#define RSI_HID_COUNTRY_CODE 0x0000 +#define RSI_VIRTUAL_CABLE 0x0001 +#define RSI_RECONNECT_INITIATE 0x0001 +#define RSI_HID_LANG_BASE 0x0100 +#define RSI_SDP_DISBALE 0x0000 +#define RSI_BATTERY_POWER 0x0001 +#define RSI_REMOTE_WAKE 0x0001 +#define RSI_PROFILE_VER 0x0100 +#define RSI_SUPERVISION_TIMEOUT 0x0C80 +#define RSI_NORMALLY_CONNECTABLE 0x0000 +#define RSI_BOOT_DEVICE 0x0001 +#define RSI_SSR_HOST_MIN_LATENCY 0x0320 +#define RSI_SSR_HOST_MAX_LATENCY 0x0640 +#define RSI_HID_LANG_ID 0x0409 +#endif +//rsi_bt_hid_apis.c function declarations +int32_t rsi_bt_hid_init(void); +int32_t rsi_bt_hid_connect(uint8_t *remote_dev_addr); +int32_t rsi_bt_hid_profile_data(uint8_t *remote_dev_addr, uint8_t *data, uint16_t len, uint8_t cid); +int32_t rsi_bt_hid_send_handshake(uint8_t *remote_dev_addr, uint8_t status); +int32_t rsi_bt_hid_send_control(uint8_t *remote_dev_addr, uint8_t control); +int32_t rsi_bt_hid_get_report(uint8_t *remote_dev_addr, uint8_t report_id, uint8_t report_type); +int32_t rsi_bt_hid_set_report(uint8_t *remote_dev_addr, + uint8_t report_id, + uint8_t report_type, + uint8_t *data, + uint16_t data_len); +int32_t rsi_bt_hid_get_protocol(uint8_t *remote_dev_addr); +int32_t rsi_bt_hid_set_protocol(uint8_t *remote_dev_addr, uint8_t protocol); +int32_t rsi_bt_hid_send_interrupt_data(uint8_t *remote_dev_addr, uint8_t *data, uint16_t data_len); + +int32_t rsi_bt_hid_disconnect(uint8_t *remote_dev_addr); +int32_t rsi_bt_hid_service_initialize(char *service_name, + char *service_description, + char *service_provider, + uint8_t *desc_buf, + uint16_t desc_buf_len); diff --git a/wiseconnect/sapi/include/rsi_mac_api.h b/wiseconnect/sapi/include/rsi_mac_api.h new file mode 100644 index 00000000..4e3ef1ca --- /dev/null +++ b/wiseconnect/sapi/include/rsi_mac_api.h @@ -0,0 +1,87 @@ +/******************************************************************************* +* @file rsi_mac_api.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/** + * Includes + * */ + +#ifndef MAC_API_H +#define MAC_API_H + +#include "rsi_zb_types.h" + +/** @brief Defines the length of the 16 - bit Short Address */ +#define g_SHORT_ADDRESS_LENGTH_c 0x02 + +/** @brief Defines the length of the 16 - bit Short PAN ID */ +#define g_SHORT_PAN_ID_LENGTH_c 0x02 +/********************************** + *** MAC Interface Commands *** + **********************************/ +/* ZigBee Enqueue to MAC MLME Q frame */ +const uint8_t rsi_zigb_frameEnqueueMacMlme[RSI_ZIGB_BYTES_2] = { MANAGEMENT_INTERFACE, ZIGBEEENQUEUEMACMLME }; + +/* ZigBee Enqueue to MAC MCPS Q frame */ +const uint8_t rsi_zigb_frameEnqueueMacMcps[RSI_ZIGB_BYTES_2] = { MANAGEMENT_INTERFACE, ZIGBEEENQUEUEMACMCPS }; + +/* ZigBee Set MAC PIB frame */ +const uint8_t rsi_zigb_frameSetMACPib[RSI_ZIGB_BYTES_2] = { MANAGEMENT_INTERFACE, ZIGBEEMACPIBSET }; + +/* ZigBee Get MAC PIB frame */ +const uint8_t rsi_zigb_frameGetMACPib[RSI_ZIGB_BYTES_2] = { MANAGEMENT_INTERFACE, ZIGBEEMACPIBGET }; + +/* ZigBee Get CCA status */ +const uint8_t rsi_zigb_frameGetCcaStatus[RSI_ZIGB_BYTES_2] = { MANAGEMENT_INTERFACE, ZIGBEEGETCCASTATUS }; + +/* MAC PIB Lookup Table*/ +const uint8_t ga_PIB_Look_Up_Table_c[25][2] = { { g_MAC_ASSOCIATION_PERMIT_c, sizeof(uint8_t) }, + { g_MAC_AUTO_REQUEST_c, sizeof(uint8_t) }, + { g_MAC_BEACON_PAYLOAD_LENGTH_c, sizeof(uint8_t) }, + { g_MAC_BEACON_ORDER_c, sizeof(uint8_t) }, + { g_MAC_BSN_c, sizeof(uint8_t) }, + { g_MAC_COORD_EXTENDED_ADDDRESS_c, g_EXTENDED_ADDRESS_LENGTH_c }, + { g_MAC_COORD_SHORT_ADDRESS_c, g_SHORT_ADDRESS_LENGTH_c }, + { g_MAC_DSN_c, sizeof(uint8_t) }, + { g_MAC_SUPERFRAME_ORDER_c, sizeof(uint8_t) }, + { g_MAC_TRANSACTION_PERSISTENCE_TIME_c, sizeof(uint16_t) }, + { g_MAC_ASSOC_PAN_COORDINATOR_c, sizeof(uint8_t) }, + { g_MAC_MAX_FRAME_TOTAL_WAIT_TIME_c, sizeof(uint16_t) }, + { g_MAC_RESPONSE_WAIT_TIME_c, sizeof(uint8_t) }, + { g_MAC_MAX_CSMA_BACKOFFS_c, sizeof(uint8_t) }, + { g_MAC_MIN_BE_c, sizeof(uint8_t) }, + { g_MAC_SHORT_ADDRESS_c, g_SHORT_ADDRESS_LENGTH_c }, + { g_MAC_PAN_ID_c, g_SHORT_PAN_ID_LENGTH_c }, + { g_MAC_ACK_WAIT_DURATION_c, sizeof(uint8_t) }, + { g_MAC_RX_ON_WHEN_IDLE_c, sizeof(uint8_t) }, + { g_MAC_PAN_COORDINATOR_c, sizeof(uint8_t) }, + { g_MAC_MAX_BE_c, sizeof(uint8_t) }, + { g_MAC_MAX_FRAME_RETRIES_c, sizeof(uint8_t) }, + { g_MAC_LIFS_PERIOD_c, sizeof(uint8_t) }, + { g_MAC_SIFS_PERIOD_c, sizeof(uint8_t) } }; + +/**************************** Function Prototypes *********************/ +int16_t rsi_zigb_send_to_mac_mlme(uint8_t messageIndex); +int16_t rsi_zigb_send_to_mac_mcps(uint8_t messageIndex); +uint8_t rsi_zigb_get_pib_len(uint8_t pib_id); +void memUtils_memCopy(uint8_t *pDestination, uint8_t *pSource, uint8_t length); +int32_t rsi_zigb_send_cmd(uint8_t *cmd, rsi_pkt_t *pkt); +#endif diff --git a/wiseconnect/sapi/include/rsi_mac_interface.h b/wiseconnect/sapi/include/rsi_mac_interface.h new file mode 100644 index 00000000..577bc064 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_mac_interface.h @@ -0,0 +1,1090 @@ +/******************************************************************************* +* @file rsi_mac_interface.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/** + * Includes + * */ + +#ifndef MAC_INTERFACE_H +#define MAC_INTERFACE_H + +#include "rsi_driver.h" + +/**************************** Public Macro Definitions ***********************/ + +/** @brief Defines the max num of PAN descriptors supported */ +#define g_MAX_PAN_DESC_SUPPORTED_c 6 + +/** @brief Defines the max num of ED scan results supported */ +#define g_MAX_ED_SCAN_RESULTS_SUPPORTED_c 16 +/**************************** Public Type Definitions ************************/ + +/** @brief Defines a union for Destination/Source/Coordinator Address */ +typedef union Addr_Tag { + /*! Short address */ + uint8_t a_short_addr[2]; + + /*! Extended address */ + uint8_t a_extend_addr[8]; +} __attribute__((__packed__)) Addr_t; + +/** @brief Defines type for time values */ +typedef uint32_t Time_t; + +/** @brief Defines a type for loop counter variable */ +typedef uint32_t Loop_Ctr_t; + +/**************************** Public Enum Definitions ************************/ + +/*! @brief Boolean values for true and false */ +typedef enum Bool_Tag { + /*! -False is defined as 0x00 */ + g_FALSE_c, + + /*! -True is defined as 0x01 */ + g_TRUE_c +} Bool_t; +/** @brief Defines the structure for MCPS DATA Request which will be used for + MAC data related requests from the application */ +typedef struct MCPS_Data_Request_Tag { + /*! Message type of MCPS Data Request */ + uint8_t msg_type; + + /*! Source addressing mode used */ + uint8_t src_addr_mode; + + /*! Destination addressing mode used */ + uint8_t dst_addr_mode; + + /*! Destination PAN ID */ + uint8_t a_dst_pan_id[2]; + + /*! Destination address */ + Addr_t dst_addr; + + /*! The handle associated with the MSDU to be transmitted */ + uint8_t msdu_handle; + + /*! The transmission options for the MSDU */ + uint8_t tx_options; + + /*! The security level to be used */ + uint8_t security_level; + + /*! The mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! The originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! The index of the key to be used */ + uint8_t key_index; + + /*! The number of octets contained in the MSDU */ + uint8_t msdu_length; + + /*! Reserved for LMAC */ + uint8_t a_reserved[23]; + + /*! The set of octets forming the MSDU */ + uint8_t a_msdu[100]; +} __attribute__((__packed__)) MCPS_Data_Request_t; + +/******************************************************************************/ + +/** @brief Defines the structure for MCPS DATA Confirm which will be used for + reporting the results of MAC data related requests from the + application */ +typedef struct MCPS_Data_Confirm_Tag { + /*! Message type of MCPS Data Confirm */ + uint8_t msg_type; + + /*! The status of the last MSDU transmission */ + uint8_t status; + + /*! The handle associated with the MSDU being confirmed */ + uint8_t msdu_handle; + + /*! The time, in symbols, at which the data were transmitted */ + uint8_t a_time_stamp[4]; +} __attribute__((__packed__)) MCPS_Data_Confirm_t; + +/******************************************************************************/ +/** @brief Defines the structure for MCPS DATA Indication which will be used + for indicating the transfer of a data packet by the MAC */ +typedef struct MCPS_Data_Indication_Tag { + /*! Message type of MCPS Data Indication */ + uint8_t msg_type; + + /*! Source addressing mode used */ + uint8_t src_addr_mode; + + /*! Source PAN ID */ + uint8_t a_src_pan_id[2]; + + /*! Source address */ + Addr_t src_addr; + + /*! Destination addressing mode used */ + uint8_t dst_addr_mode; + + /*! Destination PAN ID */ + uint8_t a_dst_pan_id[2]; + + /*! LQI value measured during reception of the MPDU */ + uint8_t mpdu_link_quality; + + /*! Destination address */ + Addr_t dst_addr; + + /*! The data sequence number of the received data frame */ + uint8_t dsn; + + /*! The time, in symbols, at which the data were received */ + uint8_t a_time_stamp[4]; + + /*! The security level purportedly used by the received data frame */ + uint8_t security_level; + + /*! The mode used to identify the key */ + uint8_t key_id_mode; + + /*! The originator of the key */ + uint8_t a_key_source[8]; + + /*! The index of the key */ + uint8_t key_index; + + /*! The number of octets contained in the MSDU being indicated */ + uint8_t msdu_length; + + /*! Reserved for LMAC */ + uint8_t a_reserved[9]; + + /*! The set of octets forming the MSDU being indicated */ + uint8_t a_msdu[1]; +} __attribute__((__packed__)) MCPS_Data_Indication_t; + +/******************************************************************************/ + +/** @brief Defines the structure for MLME ASSOCIATE Request which will be used + by the application to request an association */ +typedef struct MLME_Associate_Request_Tag { + /*! Message type of MLME Associate Request */ + uint8_t msg_type; + + /*! The logical channel on which to attempt association */ + uint8_t logical_channel; + + /*! The channel page on which to attempt association */ + uint8_t channel_page; + + /*! Coordinator addressing mode used */ + uint8_t coord_addr_mode; + + /*! The identifier of the PAN with which to associate*/ + uint8_t a_coord_pan_id[2]; + + /*! Coordinator address */ + Addr_t coord_addr; + + /*! Operational capabilities of the associating device */ + uint8_t capability_info; + + /*! The security level to be used */ + uint8_t security_level; + + /*! The mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! The originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! The index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Associate_Request_t; + +/******************************************************************************/ + +/** @brief Defines the structure for MLME ASSOCIATE Indication which will be + used by the MAC to indicate the reception of an association request + command */ +typedef struct MLME_Associate_Indication_Tag { + /*! Message type of MLME Associate Indication */ + uint8_t msg_type; + + /*! Extended address of the device requesting association */ + uint8_t a_device_addr[8]; + + /*! Operational capabilities of the device requesting association */ + uint8_t capability_info; + + /*! Security level purportedly used by the received MAC command frame*/ + uint8_t security_level; + + /*! The mode used to identify the key used by the originator of frame */ + uint8_t key_id_mode; + + /*! The originator of the key used by the originator of the received frame */ + uint8_t a_key_source[8]; + + /*! Index of the key used by the originator of the received frame */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Associate_Indication_t; + +/******************************************************************************/ + +/** @brief Defines the structure for MLME ASSOCIATE Response which is used to + initiate a response to an MLME-ASSOCIATE.indication*/ +typedef struct MLME_ASSOCIATE_Response_Tag { + /*! Message type of MLME Associate Response */ + uint8_t msg_type; + + /*! Extended address of the device requesting association */ + uint8_t a_device_addr[8]; + + /*! 16-bit short device address allocated by the coordinator on successful + association */ + uint8_t a_assoc_short_addr[2]; + + /*! Status of the association attempt */ + uint8_t status; + + /*! Security level to be used */ + uint8_t security_level; + + /*! The mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! The originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! The index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Associate_Response_t; + +/******************************************************************************/ + +/** @brief Defines a structure for MLME ASSOCIATE Confirm which is used to + inform the application of the initiating device whether its + request to associate was successful or unsuccessful */ +typedef struct MLME_Associate_Confirm_Tag { + /*! Message type of MLME Associate Confirm */ + uint8_t msg_type; + + /*! Status of the association attempt*/ + uint8_t status; + + /*! Short address allocated by the coordinator on successful association */ + uint8_t a_assoc_short_addr[2]; + + /*! The security level used */ + uint8_t security_level; + + /*! The mode used to identify the key */ + uint8_t key_id_mode; + + /*! The originator of the key */ + uint8_t a_key_source[8]; + + /*! The index of the key */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Associate_Confirm_t; + +/******************************************************************************/ + +/** @brief Defines the structure for MLME DISASSOCIATE Request which will be + used by the application to request an disassociation */ +typedef struct MLME_Disassociate_Request_Tag { + /*! Message type of MLME Associate Request */ + uint8_t msg_type; + + /*! Device addressing mode used */ + uint8_t device_addr_mode; + + /*! The identifier of the PAN of the device */ + uint8_t device_pan_id[2]; + + /*! Device address */ + Addr_t device_addr; + + /*! The reason for the disassociation */ + uint8_t disassociate_reason; + + /*! TRUE if the disassociation notification command is to be sent indirectly + */ + Bool_t tx_indirect; + + /*! The security level to be used */ + uint8_t security_level; + + /*! The mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! The originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! The index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Disassociate_Request_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME DISASSOCIATE indication which will be + used to send disassociation indication to the application. */ +typedef struct MLME_Disassociate_Indication_Tag { + /*! Message type of MLME Associate Request */ + uint8_t msg_type; + + /*! Device address of the device requesting the disassociation*/ + Addr_t device_addr; + + /*! The reason for the disassociation */ + uint8_t disassociate_reason; + + /*! The security level to be used */ + uint8_t security_level; + + /*! The mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! The originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! The index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Disassociate_Indication_t; + +/******************************************************************************/ + +/** @brief Defines the structure for MLME DISASSOCIATE Confirm which will be + used to send disassociation Confirmation to the application. */ +typedef struct MLME_Disassociate_Confirm_Tag { + /*! Message type of MLME Associate Request */ + uint8_t msg_type; + + /*! Status of the disassociation attempt*/ + uint8_t status; + + /*! Device addressing mode used */ + uint8_t device_addr_mode; + + /*! The identifier of the PAN of the device */ + uint8_t device_pan_id[2]; + + /*! Device address */ + Addr_t device_addr; + +} __attribute__((__packed__)) MLME_Disassociate_Confirm_t; + +/******************************************************************************/ +/** @brief Defines a structure for MAC PAN Descriptor which contains the + network details of the device from which the beacon is received */ +typedef struct MAC_PAN_Descriptor_Tag { + /*! Coordinator addressing mode */ + uint8_t coord_addr_mode; + + /*! PAN identifier of the coordinator */ + uint8_t a_coord_pan_id[2]; + + /*! Coordinator address */ + Addr_t coord_addr; + + /*! The current logical channel occupied by the network */ + uint8_t logical_channel; + + /*! The current channel page occupied by the network */ + uint8_t channel_page; + + /*! Superframe specification as specified in the received beacon frame */ + uint8_t a_superframe_spec[2]; + + /*! PAN coordinator is accepting GTS requests or not */ + uint8_t gts_permit; + + /*! The LQI at which the network beacon was received */ + uint8_t link_quality; + + /*! The time at which the beacon frame was received, in symbols */ + uint8_t a_time_stamp[4]; + + /*! Security level purportedly used by the received beacon frame */ + uint8_t security_level; + +} __attribute__((__packed__)) MAC_PAN_Descriptor_t; + +/******************************************************************************/ +/** @brief Defines a structure for MLME BEACON NOTIIFY Indication which is + used to send parameters contained within a beacon frame received + by the MAC to the application */ +typedef struct MLME_Beacon_Notify_Indication_Tag { + /*! Message type of MLME Beacon Notify Indication */ + uint8_t msg_type; + + /*! Beacon Sequence Number */ + uint8_t bsn; + + /*! The PAN Descriptor for the received beacon */ + MAC_PAN_Descriptor_t mac_pan_descriptor; + + /*! The beacon pending address specification */ + uint8_t pending_addr_spec; + + /*! Number of octets contained in the beacon payload of the beacon frame */ + uint8_t sdu_length; + + /*! Set of octets comprising the beacon payload & the list of addresses of + the devices forwhich the beacon source has data */ + uint8_t a_bcn_data[1]; +} __attribute__((__packed__)) MLME_Beacon_Notify_Indication_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME ORPHAN Indication which is used by + the coordinator to notify the application of the presence of + an orphaned device */ +typedef struct MLME_Orphan_Indication_Tag { + /*! Message type of MLME Orphan Indication */ + uint8_t msg_type; + + /*! Extended address of the orphaned device */ + uint8_t a_orphan_addr[8]; + + /*! Security level purportedly used by the received MAC command frame */ + uint8_t security_level; + + /*! Mode used to identify the key used by originator of received frame */ + uint8_t key_id_mode; + + /*! Originator of the key used by the originator of the received frame */ + uint8_t a_key_source[8]; + + /*! Index of the key used by the originator of the received frame */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Orphan_Indication_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME ORPHAN Response which is used by the + application layer of the coordinator to respond to the MLME ORPHAN + Indication */ +typedef struct MLME_Orphan_Response_Tag { + /*! Message type of MLME Orphan Response */ + uint8_t msg_type; + + /*! Extended address of the orphaned device */ + uint8_t a_orphan_addr[8]; + + /*! Short address allocated to the orphaned device */ + uint8_t a_short_addr[2]; + + /*! If the orphaned device is associated with the coordinator or not */ + uint8_t assoc_member; + + /*! Security level to be used */ + uint8_t security_level; + + /*! Mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! Originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! Index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Orphan_Response_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME RX ENABLE Request which allows the + application to request that the receiver is either enabled + for a finite period of time or disabled */ +typedef struct MLME_RX_Enable_Request_Tag { + /*! Message type of MLME RX Enable Request */ + uint8_t msg_type; + + /*! The requested operation can be deferred or not */ + uint8_t defer_permit; + + /*! Number of symbols measured before the receiver is to be enabled or + disabled */ + uint8_t a_rx_on_time[4]; + + /*! Number of symbols for which the receiver is to be enabled */ + uint8_t a_rx_on_duration[4]; +} __attribute__((__packed__)) MLME_RX_Enable_Request_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME RX ENABLE Confirm which is used to + report the results of the attempt to enable or disable the receiver*/ +typedef struct MLME_RX_Enable_Confirm_Tag { + /*! Message type of MLME RX Enable Confirm */ + uint8_t msg_type; + + /*! Result of the request to enable or disable the receiver */ + uint8_t status; +} __attribute__((__packed__)) MLME_RX_Enable_Confirm_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME SCAN Request which is used to + initiate a channel scan over a given list of channels */ +typedef struct MLME_Scan_Request_Tag { + /*! Message type of MLME Scan Request */ + uint8_t msg_type; + + /*! The type of scan to be performed */ + uint8_t scan_type; + + /*! Indicate which channels are to be scanned */ + uint8_t a_scan_channels[4]; + + /*! The time spent on scanning each channel */ + uint8_t scan_duration; + + /*! Channel page on which to perform the scan */ + uint8_t channel_page; + + /*! Security level to be used */ + uint8_t security_level; + + /*! Mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! Originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! Index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Scan_Request_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME SCAN Confirm which is used to report + the result of the channel scan request */ +typedef struct MLME_Scan_Confirm_Tag { + /*! Message type of MLME Scan Confirm */ + uint8_t msg_type; + + /*! Status of the scan request */ + uint8_t status; + + /*! The type of scan performed */ + uint8_t scan_type; + + /*! Channel page on which the scan was performed */ + uint8_t channel_page; + + /*! Channels given in the request which were not scanned */ + uint8_t a_unscanned_channel[4]; + + /*! Number of elements returned in the appropriate result lists */ + uint8_t result_list_size; + + /*! Defines a union of energy measurements list and pan descriptor list */ + union { + /*! List of energy measurements */ + uint8_t energy_detect_list[g_MAX_ED_SCAN_RESULTS_SUPPORTED_c]; + + /*! List of PAN descriptors */ + MAC_PAN_Descriptor_t pan_desc_list[g_MAX_PAN_DESC_SUPPORTED_c]; + + } __attribute__((__packed__)) result_list; + +} __attribute__((__packed__)) MLME_Scan_Confirm_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME COMM STATUS Indication which is used + by the MAC to indicate a communications status */ +typedef struct MLME_Comm_Status_Indication_Tag { + /*! Message type of MLME Comm Status Indication */ + uint8_t msg_type; + + /*! The 16-bit PAN identifier of the device from which the frame was + received or to which the frame was being sent */ + uint8_t a_pan_id[2]; + + /*! Source addressing mode */ + uint8_t src_addr_mode; + + /*! Source address */ + Addr_t src_addr; + + /*! Destination addressing mode */ + uint8_t dst_addr_mode; + + /*! Destination address */ + Addr_t dst_addr; + + /*! The communications status */ + uint8_t status; + + /*! Security level to be used */ + uint8_t security_level; + + /*! Mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! Originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! Index of the key to be used */ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Comm_Status_Indication_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME START Request which is used by the + FFDs to initiate a new PAN or to begin using a new superframe + configuration */ +typedef struct MLME_Start_Request_Tag { + /*! Message type of MLME Start Request */ + uint8_t msg_type; + + /*! PAN identifier to be used by the device */ + uint8_t a_pan_id[2]; + + /*! Logical channel on which to begin */ + uint8_t logical_channel; + + /*! Channel page on which to begin */ + uint8_t channel_page; + + /*! Time at which to begin transmitting beacons */ + uint8_t a_start_time[4]; + + /*! Indicates how often the beacon is to be transmitted */ + uint8_t beacon_order; + + /*! Length of the active portion of the superframe */ + uint8_t superframe_order; + + /*! Indicates whether the device is a PAN coordinator or not */ + uint8_t pan_coord; + + /*! Indicates if the receiver of the beaconing device is disabled or not */ + uint8_t battery_life_ext; + + /*! Indicates if the coordinator realignment command is to be transmitted */ + uint8_t coord_realignmnt; + + /*! Security level to be used for coordinator realignment command frames */ + uint8_t coord_realign_security_level; + + /*! Mode used to identify the key to be used */ + uint8_t coord_realign_key_id_mode; + + /*! Originator of the key to be used*/ + uint8_t a_coord_realign_key_source[8]; + + /*! Index of the key to be used */ + uint8_t coord_realign_key_index; + + /*! Security level to be used for beacon frames */ + uint8_t beacon_security_level; + + /*! Mode used to identify the key to be used */ + uint8_t beacon_key_id_mode; + + /*! Originator of the key to be used */ + uint8_t a_beacon_key_source[8]; + + /*! Index of the key to be used */ + uint8_t beacon_key_index; +} __attribute__((__packed__)) MLME_Start_Request_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME START Confirm which is used to + report the results of the attempt to start using a new superframe + configuration */ +typedef struct MLME_Start_Confirm_Tag { + /*! Message type of MLME Start Confirm */ + uint8_t msg_type; + + /*!Result of the attempt to start using an updated superframe configuration*/ + uint8_t status; +} __attribute__((__packed__)) MLME_Start_Confirm_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME SYNC LOSS Indication which is used + by the MAC to indicate the loss of synchronization with the + coordinator */ +typedef struct MLME_Sync_Loss_Indication_Tag { + /*! Message type of MLME Sync Loss Indication */ + uint8_t msg_type; + + /*! The reason that synchronization was lost */ + uint8_t loss_reason; + + /*! The PAN identifier with which the device lost synchronization or to + which it was realigned */ + uint8_t a_pan_id[2]; + + /*! The logical channel on which the device lost synchronization or to which + it was realigned */ + uint8_t logical_channel; + + /*! The channel page on which the device lost synchronization or to which it + was realigned */ + uint8_t channel_page; + + /*! The security level used by the received MAC frame */ + uint8_t security_level; +} __attribute__((__packed__)) MLME_Sync_Loss_Indication_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME POLL Request which prompts the + device to request data from the coordinator */ +typedef struct MLME_Poll_Request_Tag { + /*! Message type of MLME Poll Request */ + uint8_t msg_type; + + /*! Addressing mode of the coordinator */ + uint8_t coord_addr_mode; + + /*! PAN identifier of the coordinator */ + uint8_t a_coord_pan_id[2]; + + /*! Coordinator address */ + Addr_t coord_addr; + + /*! Security level to be used */ + uint8_t security_level; + + /*! Mode used to identify the key to be used */ + uint8_t key_id_mode; + + /*! Originator of the key to be used */ + uint8_t a_key_source[8]; + + /*! Index of the key to be used*/ + uint8_t key_index; +} __attribute__((__packed__)) MLME_Poll_Request_t; + +/******************************************************************************/ +/** @brief Defines the structure for MLME POLL Confirm which is used to report + the result of a request to poll the coordinator for data */ +typedef struct MLME_Poll_Confirm_Tag { + /*! Message type of MLME Poll Confirm */ + uint8_t msg_type; + + /*! The status of the data request */ + uint8_t status; +} __attribute__((__packed__)) MLME_Poll_Confirm_t; + +/**************************** Public Enum Definitions ************************/ + +/** @brief Message ID of MAC request/response/indication/confirmation */ +typedef enum MAC_Message_ID_Tag { + /*! -MCPS Data Request */ + g_MCPS_DATA_REQUEST_c = (uint8_t)0x40, + + /*! -MCPS Data Confirm */ + g_MCPS_DATA_CONFIRM_c = (uint8_t)0x41, + + /*! -MCPS Data Indication */ + g_MCPS_DATA_INDICATION_c = (uint8_t)0x42, + + /*! -MCPS Purge request */ + g_MCPS_PURGE_REQUEST_c = (uint8_t)0x43, + + /*! -MCPS Purge Confirm */ + g_MCPS_PURGE_CONFIRM_c = (uint8_t)0x44, + + /*! -MLME Associate Request */ + g_MLME_ASSOCIATE_REQUEST_c = (uint8_t)0x45, + + /*! -MLME Associate Confirm */ + g_MLME_ASSOCIATE_CONFIRM_c = (uint8_t)0x46, + + /*! -MLME Associate Indication */ + g_MLME_ASSOCIATE_INDICATION_c = (uint8_t)0x47, + + /*! -MLME Associate Response */ + g_MLME_ASSOCIATE_RESPONSE_c = (uint8_t)0x48, + + /*! -MLME Disassociate Request */ + g_MLME_DISASSOCIATE_REQUEST_c, + + /*! -MLME Disassociate Confirm */ + g_MLME_DISASSOCIATE_CONFIRM_c, + + /*! -MLME Disassociate Indication */ + g_MLME_DISASSOCIATE_INDICATION_c, + + /*! -MLME Beacon Notify Indication */ + g_MLME_BEACON_NOTIFY_INDICATION_c, + + /*! -MLME Get Request */ + g_MLME_GET_REQUEST_c, + + /*! -MLME Get Confirm */ + g_MLME_GET_CONFIRM_c, + + /*! -MLME Orphan Indication */ + g_MLME_ORPHAN_INDICATION_c, + + /*! -MLME Orphan Response */ + g_MLME_ORPHAN_RESPONSE_c, + + /*! -MLME Reset Request */ + g_MLME_RESET_REQUEST_c, + + /*! -MLME Reset Confirm */ + g_MLME_RESET_CONFIRM_c, + + /*! -MLME RX Enable Request */ + g_MLME_RX_ENABLE_REQUEST_c, + + /*! -MLME RX Enable Confirm */ + g_MLME_RX_ENABLE_CONFIRM_c, + + /*! -MLME Scan Request */ + g_MLME_SCAN_REQUEST_c, + + /*! -MLME Scan Confirm */ + g_MLME_SCAN_CONFIRM_c, + + /*! -MLME Comm Status Indication */ + g_MLME_COMM_STATUS_INDICATION_c, + + /*! -MLME Set Request */ + g_MLME_SET_REQUEST_c, + + /*! -MLME Set Confirm */ + g_MLME_SET_CONFIRM_c, + + /*! -MLME Start Request */ + g_MLME_START_REQUEST_c, + + /*! -MLME Start Confirm */ + g_MLME_START_CONFIRM_c, + + /*! -MLME Sync Loss Indication */ + g_MLME_SYNC_LOSS_INDICATION_c, + + /*! -MLME Poll Request */ + g_MLME_POLL_REQUEST_c, + + /*! -MLME Poll Confirm */ + g_MLME_POLL_CONFIRM_c +} MAC_Message_ID_t; + +/******************************************************************************/ + +/** @brief MAC Transmission Options */ +typedef enum MAC_Tx_Options_Tag { + /*! -Acknowledged Transmission */ + g_ACK_TX_c = (uint8_t)0x01, + + /*! -GTS Transmission */ + g_GTS_TX_c = (uint8_t)0x02, + + /*! -Indirect Transmission */ + g_INDIRECT_TX_c = (uint8_t)0x04, + + /*! -Security Enabled Transmission */ + g_SECURED_TX_c = (uint8_t)0x08 +} MAC_Tx_Options_t; + +/******************************************************************************/ +/** @brief MAC Association Status */ +typedef enum MAC_Association_Status_Tag { + /*! -Association successful */ + g_MAC_ASSO_SUCCESS_c = (uint8_t)0x00, + + /*! -PAN at capacity */ + g_MAC_PAN_AT_CAPACITY_c = (uint8_t)0x01, + + /*! -PAN access denied */ + g_MAC_PAN_ACCESS_DENIED_c = (uint8_t)0x02 +} MAC_Association_Status_t; + +/******************************************************************************/ +/** @brief MAC Disassociation reason codes */ +typedef enum MAC_Disassociation_Reason_Tag { + /*! -The coordinator wishes the device to leave the PAN. */ + g_COORD_REQUESTED_c = (uint8_t)0x01, + + /*! -The device wishes to leave the PAN. */ + g_DEVICE_REQUESTED_c = (uint8_t)0x02 + +} MAC_Disassociation_Reason_t; + +/******************************************************************************/ +/** @brief MAC Security Mode */ +typedef enum MAC_Security_Mode_Tag { + /*! - MAC Unsecured Mode Security */ + g_MAC_UNSECURED_MODE_c = (uint8_t)0x00, + + /*! - MAC ACL Mode Security */ + g_MAC_ACL_MODE_c = (uint8_t)0x01, + + /*! - MAC Secured Mode Security */ + g_MAC_SECURED_MODE_c = (uint8_t)0x02 +} MAC_Security_Mode_t; + +/******************************************************************************/ +/** @brief This enum contains all the mac pib Ids */ +typedef enum MAC_Pib_Ids_Tag { + /*! -Id of mac attribute mac_ack_wait_duration */ + g_MAC_ACK_WAIT_DURATION_c = (uint8_t)0x40, + + /*! -Id of mac attribute mac_association_permit */ + g_MAC_ASSOCIATION_PERMIT_c = (uint8_t)0x41, + + /*! -Id of mac attribute mac_auto_request */ + g_MAC_AUTO_REQUEST_c = (uint8_t)0x42, + + /*! -Id of mac attribute mac_beacon_payload */ + g_MAC_BEACON_PAYLOAD_c = (uint8_t)0x45, + + /*! -Id of mac attribute mac_beacon_payload_length */ + g_MAC_BEACON_PAYLOAD_LENGTH_c = (uint8_t)0x46, + + /*! -Id of mac attribute mac_beacon_order */ + g_MAC_BEACON_ORDER_c = (uint8_t)0x47, + + /*! -Id of mac attribute mac_bsn */ + g_MAC_BSN_c = (uint8_t)0x49, + + /*! -Id of mac attribute mac_coord_extended_address */ + g_MAC_COORD_EXTENDED_ADDDRESS_c = (uint8_t)0x4A, + + /*! -Id of mac attribute mac_coord_short_address */ + g_MAC_COORD_SHORT_ADDRESS_c = (uint8_t)0x4B, + + /*! -Id of mac attribute mac_dsn */ + g_MAC_DSN_c = (uint8_t)0x4C, + + /*! -Id of mac attribute mac_max_frame_total_wait_time */ + g_MAC_MAX_FRAME_TOTAL_WAIT_TIME_c = (uint8_t)0x58, + + /*! -Id of mac attribute mac_max_frame_retries */ + g_MAC_MAX_FRAME_RETRIES_c = (uint8_t)0x59, + + /*! -Id of mac attribute mac_pan_id */ + g_MAC_PAN_ID_c = (uint8_t)0x50, + + /*! -Id of mac attribute mac_response_wait_time */ + g_MAC_RESPONSE_WAIT_TIME_c = (uint8_t)0x5A, + + /*! -Id of mac attribute mac_rx_on_when_idle */ + g_MAC_RX_ON_WHEN_IDLE_c = (uint8_t)0x52, + + /*! -Id of mac attribute mac_security_enabled */ + g_MAC_SECURITY_ENABLED_c = (uint8_t)0x5D, + + /*! -Id of mac attribute mac_short_address */ + g_MAC_SHORT_ADDRESS_c = (uint8_t)0x53, + + /*! -Id of mac attribute mac_superframe_order */ + g_MAC_SUPERFRAME_ORDER_c = (uint8_t)0x54, + + /*! -Id of mac attribute mac_time_stamp_supported */ + g_MAC_TIMESTAMP_SUPPORTED_c = (uint8_t)0x5C, + + /*! -Id of mac attribute mac_transaction_persistence_time */ + g_MAC_TRANSACTION_PERSISTENCE_TIME_c = (uint8_t)0x55, + + /*! -Id of mac attribute mac_max_be */ + g_MAC_MAX_BE_c = (uint8_t)0x57, + + /*! -Id of mac attribute mac_lifs */ + g_MAC_LIFS_PERIOD_c = (uint8_t)0x5E, + + /*! -Id of mac attribute mac_sifs */ + g_MAC_SIFS_PERIOD_c = (uint8_t)0x5F, + + /*! -Id of mac attribute mac_max_csma_backoffs */ + g_MAC_MAX_CSMA_BACKOFFS_c = (uint8_t)0x4E, + + /*! -Id of mac attribute mac_min_be */ + g_MAC_MIN_BE_c = (uint8_t)0x4F, + + /*! -Id of pan coordinator */ + g_MAC_PAN_COORDINATOR_c = (uint8_t)0x10, + + /*! -Id of parent is a pan coordinator */ + g_MAC_ASSOC_PAN_COORDINATOR_c = (uint8_t)0x11, + + /*! -Id of mac extended address */ + g_MAC_EXTENDED_ADDRESS_c = (uint8_t)0x6F, + + /*! -Id for MAC ACL Entry */ + g_MAC_ACL_ENTRY_DESCRIPTOR_c = (uint8_t)0x70, + + /*! -Id for No of ACL Security Descriptor Entries */ + g_MAC_ACL_ENTRY_DESCRIPTOR_SIZE_c = (uint8_t)0x71, + + /*! -Id for MAC Default Security Support */ + g_MAC_DEFAULT_SECURITY_c = (uint8_t)0x72, + + /*! -Id for MAC Default Security material length */ + g_MAC_DEFAULT_SECURITY_MATERIAL_LENGTH_c = (uint8_t)0x73, + + /*! -Id for MAC Default Security Material */ + g_MAC_DEFAULT_SECURITY_MATERIAL_c = (uint8_t)0x74, + + /*! -Id for MAC Default Security Suite */ + g_MAC_DEFAULT_SECURITY_SUITE_c = (uint8_t)0x75, + + /*! -Id for MAC Security Mode */ + g_MAC_SECURITY_MODE_c = (uint8_t)0x76, + + /*! - Proprietary Id for Current number of ACL Entries */ + g_MAC_CURRENT_ACL_ENTRIES_c = (uint8_t)0x80, + + /*! - Proprietary Id for Default MAC Security Extended Address */ + g_MAC_DEFAULT_SECURITY_EXTENDED_ADDRESS_c = (uint8_t)0x81 +} MAC_Pib_Ids_t; + +/**************************** Public Function Prototypes *********************/ +int16_t rsi_zigb_mac_data_req(uint8_t dsn_enable, uint8_t dsn, MCPS_Data_Request_t *Data_Request); +int16_t rsi_zigb_mac_assoc_req(MLME_Associate_Request_t *assoc_request); +int16_t rsi_zigb_mac_disassoc_req(MLME_Disassociate_Request_t *pDisassociateRequest); +int16_t rsi_zigb_mac_poll_req(MLME_Poll_Request_t *pPollRequest); +int16_t rsi_zigb_mac_rxenable_req(MLME_RX_Enable_Request_t *pRxenableRequest); +int16_t rsi_zigb_mac_scan_req(MLME_Scan_Request_t *pScanRequest); +int16_t rsi_zigb_mac_start_req(MLME_Start_Request_t *pStartRequest); +int16_t rsi_zigb_mac_orphan_response(MLME_Orphan_Response_t *pOrphan_response); +int16_t rsi_zigb_mac_mlmepib_set(uint8_t pibAttributeId, uint8_t pibAttributeIndex, uint8_t *pPibAttributeValue); +int16_t rsi_zigb_mac_mlmepib_get(uint8_t pibAttributeId, uint8_t pibAttributeIndex, uint8_t *pPibAttributeValue); +int16_t rsi_zigb_mac_assoc_response(MLME_Associate_Response_t *pMLME_Associate_Response); +int16_t rsi_zigb_send_to_mac_mlme(uint8_t messageIndex); +int16_t rsi_zigb_send_to_mac_mcps(uint8_t messageIndex); +int16_t rsi_zigb_bypass_stack(uint8_t bypass); +uint8_t rsi_zigb_get_pib_len(uint8_t pib_id); +int16_t rsi_zigb_mac_assoc_response(MLME_Associate_Response_t *pMLME_Associate_Response); +int16_t rsi_zigb_mac_orphan_response(MLME_Orphan_Response_t *pOrphan_response); +int16_t rsi_zigb_mac_data_confirm(MCPS_Data_Confirm_t *pMCPS_Data_Confirm); +int16_t rsi_zigb_mac_data_indication(MCPS_Data_Indication_t *pMCPS_Data_Indication); +int16_t rsi_zigb_mac_assoc_confirm(MLME_Associate_Confirm_t *pMLME_Associate_Confirm); +int16_t rsi_zigb_mac_assoc_indication(MLME_Associate_Indication_t *pMLME_Associate_Indication); +int16_t rsi_zigb_mac_disassoc_confirm(MLME_Disassociate_Confirm_t *pMLME_Disassociate_Confirm); +int16_t rsi_zigb_mac_disassoc_indication(MLME_Disassociate_Indication_t *pMLME_Disassociate_Indication); +int16_t rsi_zigb_mac_beacon_notify_indication(MLME_Beacon_Notify_Indication_t *pMLME_Beacon_Notify_Indication); +int16_t rsi_zigb_mac_orphan_indication(MLME_Orphan_Indication_t *pMLME_Orphan_Indication); +int16_t rsi_zigb_mac_rx_enable_confirm(MLME_RX_Enable_Confirm_t *pMLME_RX_Enable_Confirm); +int16_t rsi_zigb_mac_scan_confirm(MLME_Scan_Confirm_t *pMLME_Scan_Confirm); +int16_t rsi_zigb_mac_comm_status_confirm(MLME_Comm_Status_Indication_t *pMLME_Comm_Status_Indication); +int16_t rsi_zigb_mac_start_confirm(MLME_Start_Confirm_t *pMLME_Start_Confirm); +int16_t rsi_zigb_mac_sync_loss_indication(MLME_Sync_Loss_Indication_t *pMLME_Sync_Loss_Indication); +int16_t rsi_zigb_mac_poll_confirm(MLME_Poll_Confirm_t *pMLME_Poll_Confirm); +int16_t rsi_zigb_init_mac(void); +int16_t rsi_zigb_reset_mac(void); +int16_t rsi_zigb_get_cca_status(void); +/******************************************************************************/ +#endif /*MAC_INTERFACE_H*/ diff --git a/wiseconnect/sapi/include/rsi_nwk.h b/wiseconnect/sapi/include/rsi_nwk.h new file mode 100644 index 00000000..038131b4 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_nwk.h @@ -0,0 +1,1383 @@ +/******************************************************************************* +* @file rsi_nwk.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_NWK_H +#define RSI_NWK_H +#include "rsi_os.h" +#include "rsi_pkt_mgmt.h" +// common includes + +/****************************************************** + * * Macros + * ******************************************************/ +#ifndef RSI_IPV6 +// flag bit to set IPV6 +#define RSI_IPV6 BIT(0) +#endif +// flags bit to enable SSL +#define RSI_SSL_ENABLE BIT(1) + +// flag bit to enable JSON associated to the webpage +#define RSI_WEB_PAGE_JSON_ENABLE BIT(3) + +// HTTP client post big data support +#define RSI_SUPPORT_HTTP_POST_DATA BIT(5) + +// HTTP version 1.1 support feature bitmap +#define RSI_SUPPORT_HTTP_V_1_1 BIT(6) +#define RSI_HTTP_USER_DEFINED_CONTENT_TYPE BIT(7) + +// To specify index of SSL cert to be used for HTTPS, for index 0 leave them unset +#define HTTPS_CERT_INDEX_1 BIT(9) +#define HTTPS_CERT_INDEX_2 BIT(10) + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +int16_t rsi_nwk_register_callbacks( + uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t command_type, uint32_t status, const uint8_t *buffer, const uint32_t length)); +int16_t rsi_wlan_nwk_register_json_update_cb( + uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t *filename, uint8_t *json_object, uint32_t length, uint32_t status)); +int16_t rsi_wlan_nwk_register_webpage_req_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t type, + uint8_t *url_name, + uint8_t *post_content_buffer, + uint32_t post_content_length, + uint32_t status)); +int16_t rsi_wlan_nwk_register_wireless_fw_upgrade_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint8_t type, uint32_t status)); +int16_t rsi_wlan_nwk_register_json_event_cb(uint32_t callback_id, + void (*callback_handler_ptr)(uint32_t status, + uint8_t *json_object, + uint32_t length)); + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +// HTTP CLIENT application includes + +/****************************************************** + * * Macros + * ******************************************************/ +// HTTP GET +#define RSI_HTTP_GET 0 + +// HTTP POST +#define RSI_HTTP_POST 1 + +// HTTP OTAF +#define RSI_HTTP_OTAF 2 + +// HTTP OFFSET +#define RSI_HTTP_OFFSET 12 + +// HTTP PUT OFFSET +#define RSI_HTTP_PUT_OFFSET 16 + +// Buffer length +#define RSI_HTTP_BUFFER_LEN 1200 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// HTTP Get/Post request structure +typedef struct rsi_req_http_client_s { + + // ip version + uint8_t ip_version[2]; + + // https enable + uint8_t https_enable[2]; + + // port number + uint16_t port; + + // buffer + uint8_t buffer[RSI_HTTP_BUFFER_LEN]; + +} rsi_req_http_client_t; + +/******************************************************************/ + +// HTTP credentials structure +#define MAX_USERNAME_LENGTH 31 +#define MAX_PASSWORD_LENGTH 31 +typedef struct rsi_req_http_credentials_s { + //username + uint8_t username[MAX_USERNAME_LENGTH]; + + //password + uint8_t password[MAX_PASSWORD_LENGTH]; + +} rsi_req_http_credentials_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +#if RSI_HTTP_STATUS_INDICATION_EN +int32_t rsi_http_client_async(uint8_t type, + uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, + void (*callback)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + uint32_t moredata, + uint16_t status_code)); +#else +int32_t rsi_http_client_async( + uint8_t type, + uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, + void (*callback)(uint16_t status, const uint8_t *buffer, const uint16_t length, uint32_t moredata)); +#endif +int32_t rsi_http_otaf_async(uint8_t type, + uint8_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, + void (*callback)(uint16_t status, const uint8_t *buffer)); + +// USER CLASS Application include +/****************************************************** + * * Macros + * ******************************************************/ +#define RSI_DHCP_USER_CLASS_MAX_COUNT 2 +#define RSI_DHCP_USER_CLASS_DATA_MAX_LEN 64 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Structures +*******************************************************/ + +typedef struct user_class_data_s { + uint8_t length; + uint8_t data[RSI_DHCP_USER_CLASS_DATA_MAX_LEN]; +} user_class_data_t; +typedef struct rsi_dhcp_user_class_s { + // DHCP user class mode + uint8_t mode; + + // User class list count + uint8_t count; + + // User class data + user_class_data_t user_class_data[RSI_DHCP_USER_CLASS_MAX_COUNT]; + +} rsi_dhcp_user_class_t; + +// DNS Application includes + +/****************************************************** + * * Macros + * ******************************************************/ + +#define MAX_URL_LEN 90 +#define MAX_DNS_REPLIES 10 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Structures +*******************************************************/ + +// DNS Server add request structure +typedef struct rsi_req_dns_server_add_s { + // Ip version value + uint8_t ip_version[2]; + + // Dns mode to use + uint8_t dns_mode[2]; + + // Primary DNS addresss + union { + uint8_t primary_dns_ipv4[4]; + uint8_t primary_dns_ipv6[16]; + } ip_address1; + + // Seconadary DNS address + union { + uint8_t secondary_dns_ipv4[4]; + uint8_t secondary_dns_ipv6[16]; + } ip_address2; +} rsi_req_dns_server_add_t; + +// DNS Query request structure + +typedef struct rsi_req_dns_query_s { + // Ip version value + uint8_t ip_version[2]; + + // URL name + uint8_t url_name[MAX_URL_LEN]; + + // DNS servers count + uint8_t dns_server_number[2]; + +} rsi_req_dns_query_t; + +#define MAX_ZONE_NAME_LEN 31 +#define MAX_HOSTNAME_LEN 31 + +// DNS Update request structure +typedef struct rsi_req_dns_update_s { + // Ip version value + uint8_t ip_version; + + // Zone name + uint8_t zone_name[MAX_ZONE_NAME_LEN]; + + // Host name + uint8_t host_name[MAX_HOSTNAME_LEN]; + + // DNS servers count + uint8_t dns_server_number[2]; + + // DNS Hostname TTL + uint8_t ttl[2]; + +} rsi_req_dns_update_t; + +// DNS Server add response structure +typedef struct rsi_rsp_dns_server_add_s { + // Primary DNS srever address + union { + uint8_t primary_dns_ipv4_addr[4]; + uint8_t primary_dns_ipv6_addr[16]; + } ip_address1; + + // Secondary DNS srever address + union { + uint8_t secondary_dns_ipv4_addr[4]; + uint8_t secondary_dns_ipv6_addr[16]; + } ip_address2; +} rsi_rsp_dns_server_add_t; + +// DNS Query response structure + +typedef struct rsi_rsp_dns_query_s { + // Ip version of the DNS server + uint8_t ip_version[2]; + + // DNS response count + uint8_t ip_count[2]; + + // DNS address responses + union { + uint8_t ipv4_address[4]; + uint8_t ipv6_address[16]; + } ip_address[MAX_DNS_REPLIES]; +} rsi_rsp_dns_query_t; + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +int32_t rsi_dns_req(uint8_t ip_version, + uint8_t *url_name, + uint8_t *primary_server_address, + uint8_t *secondary_server_address, + rsi_rsp_dns_query_t *dns_query_resp, + uint16_t length); +int32_t rsi_dns_update(uint8_t ip_version, + uint8_t *zone_name, + uint8_t *host_name, + uint8_t *server_address, + uint16_t ttl, + void (*dns_update_rsp_handler)(uint16_t status)); + +// FTP Client feature related prototypes +/****************************************************** + * * Macros + * ******************************************************/ + +// Max length of FTP server login username +#define RSI_FTP_USERNAME_LENGTH 31 +// Max length of FTP server login password +#define RSI_FTP_PASSWORD_LENGTH 31 + +// Max length of FTP file path +#define RSI_FTP_PATH_LENGTH 51 +// Max chunk length in a command +#define RSI_FTP_MAX_CHUNK_LENGTH 1400 + +// FTP client modes +#define FTP_ENABLE_PASSIVE 1 +#define FTP_ENABLE_ACTIVE 0 + +// FTP TRANSFER MODES +#define FTP_BLOCK_TRANSFER_MODE 1 +#define FTP_STREAM_TRANSFER_MODE 0 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +// FTP client commands +typedef enum rsi_ftp_commands_e { + // Creates FTP objects. This should be the first command for accessing FTP + RSI_FTP_CREATE = 1, + + // Command to Connect to FTP server. + RSI_FTP_CONNECT, + + // Command to create directory in a specified path. + RSI_FTP_DIRECTORY_CREATE, + + // Command to delete directory in a specified path + RSI_FTP_DIRECTORY_DELETE, + + // Command to change working directory to a specified path. + RSI_FTP_DIRECTORY_SET, + + // Command to list directory contents in a specified path + RSI_FTP_DIRECTORY_LIST, + + // Command to read the file + RSI_FTP_FILE_READ, + + // Command to write the file + RSI_FTP_FILE_WRITE, + + // Command to write the content in file already opened + RSI_FTP_FILE_WRITE_CONTENT, + + // Command to delete the specified file + RSI_FTP_FILE_DELETE, + + // Command to Rename the specified file + RSI_FTP_FILE_RENAME, + + // Disconnects from FTP server. + RSI_FTP_DISCONNECT, + + // Destroys FTP objects + RSI_FTP_DESTROY, + + // Command to enable FTP client passive mode + RSI_FTP_COMMAND_MODE_SET, + + // Command to enable FTP client active mode + RSI_FTP_COMMAND_FILE_SIZE_SET +} rsi_ftp_commands_t; + +/****************************************************** + * * Structures +*******************************************************/ + +// FTP connect request structure +typedef struct rsi_ftp_connect_s { + // Command type + uint8_t command_type; + + // FTP client IP version + uint8_t ip_version; + + union { + // IPv4 address + uint8_t ipv4_address[4]; + + // IPv6 address + uint8_t ipv6_address[16]; + } server_ip_address; + + // FTP client username + uint8_t username[RSI_FTP_USERNAME_LENGTH]; + + // FTP client password + uint8_t password[RSI_FTP_PASSWORD_LENGTH]; + + // FTP server port number + uint8_t server_port[4]; + +} rsi_ftp_connect_t; + +// FTP file rename request structure +typedef struct rsi_ftp_file_rename_s { + + // Command type + uint8_t command_type; + + // Directory or file path + uint8_t old_file_name[RSI_FTP_PATH_LENGTH]; + + // New file name + uint8_t new_file_name[RSI_FTP_PATH_LENGTH]; + +} rsi_ftp_file_rename_t; + +typedef struct rsi_ftp_mode_params_s { + + // Command type + uint8_t command_type; + uint8_t mode_type; + +} rsi_ftp_mode_params_t; + +typedef struct rsi_ftp_file_size_set_params_s { + + // Command type + uint8_t command_type; + uint8_t file_size[4]; +} rsi_ftp_file_size_set_params_t; +// FTP file operations request structure +typedef struct rsi_ftp_file_ops_s { + + // Command type + uint8_t command_type; + + // Directory or file path + uint8_t file_name[RSI_FTP_PATH_LENGTH]; + +} rsi_ftp_file_ops_t; + +// FTP file write request structure +typedef struct rsi_ftp_file_write_s { + // command type + uint8_t command_type; + + // End of file + uint8_t end_of_file; + + // Path of file to write + uint8_t file_content[RSI_FTP_MAX_CHUNK_LENGTH]; + +} rsi_ftp_file_write_t; + +// FTP file operations response structure +typedef struct rsi_ftp_file_rsp_s { + // command type + uint8_t command_type; + + // Data pending + uint8_t more; + + // data length + uint16_t data_length; + + // Data content + uint8_t data_content[1024]; + +} rsi_ftp_file_rsp_t; + +/****************************************************** + * * Function Declarations + * ******************************************************/ + +int32_t rsi_ftp_connect(uint16_t flags, int8_t *server_ip, int8_t *username, int8_t *password, uint32_t server_port); +int32_t rsi_ftp_disconnect(void); +int32_t rsi_ftp_file_write(int8_t *file_name); +int32_t rsi_ftp_file_size_set(uint32_t file_size); +int32_t rsi_ftp_file_write_content(uint16_t flags, int8_t *file_content, int16_t content_length, uint8_t end_of_file); + +int32_t rsi_ftp_file_read_aysnc( + int8_t *file_name, + void (*call_back_handler_ptr)(uint16_t status, uint8_t *file_content, uint16_t content_length, uint8_t end_of_file)); +int32_t rsi_ftp_file_delete(int8_t *file_name); +int32_t rsi_ftp_file_rename(int8_t *old_file_name, int8_t *new_file_name); +int32_t rsi_ftp_directory_create(int8_t *directory_name); +int32_t rsi_ftp_directory_delete(int8_t *directory_name); +int32_t rsi_ftp_directory_set(int8_t *directory_path); +int32_t rsi_ftp_directory_list_async( + int8_t *directory_path, + void (*call_back_handler_ptr)(uint16_t status, uint8_t *directory_list, uint16_t length, uint8_t end_of_list)); + +// SNTP client Application includes + +/****************************************************** + * * Macros + * ******************************************************/ +//SNTP client feature +#define RSI_SNTP_CREATE 1 +#define RSI_SNTP_GETTIME 2 +#define RSI_SNTP_GETTIME_DATE 3 +#define RSI_SNTP_GETSERVER_ADDRESS 4 +#define RSI_SNTP_DELETE 5 +#define RSI_SNTP_GET_SERVER_INFO 6 +#define RSI_SNTP_SERVER_ASYNC_RSP 7 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// Define for SNTP client initialization + +typedef struct rsi_sntp_client { + //SNTP client command type + uint8_t command_type; + //SNTP server ip version + uint8_t ip_version; + union { + //server ipv4 address + uint8_t ipv4_address[4]; + //server ipv6 address + uint8_t ipv6_address[16]; + } server_ip_address; + // SNTP server method + uint8_t sntp_method; + uint8_t sntp_retry_count[2]; +} rsi_sntp_client_t; + +typedef struct rsi_sntp_server_info_rsp_t { + uint8_t command_type; + uint8_t ip_version; + + union { + uint8_t ipv4_address[4]; + uint8_t ipv6_address[16]; + + } server_ip_address; + + uint8_t sntp_method; + +} rsi_sntp_server_info_rsp_t; + +typedef struct rsi_sntp_server_rsp_t { + uint8_t ip_version; + union { + uint8_t ipv4_address[4]; + uint8_t ipv6_address[16]; + } server_ip_address; + uint8_t sntp_method; +} rsi_sntp_server_rsp_t; + +// SMTP client Application includes + +/****************************************************** + * * Macros + * ******************************************************/ + +// SMTP feature + +#define RSI_SMTP_BUFFER_LENGTH 1024 +#define RSI_SMTP_CLIENT_CREATE 1 +#define RSI_SMTP_CLIENT_INIT 2 +#define RSI_SMTP_CLIENT_MAIL_SEND 3 +#define RSI_SMTP_CLIENT_DEINIT 4 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// Define for SMTP client initialization + +typedef struct rsi_smtp_client_init_s { + // SMTP server ip version + uint8_t ip_version; + + union { + // Server ipv4 address + uint8_t ipv4_address[4]; + + // Server ipv6 address + uint8_t ipv6_address[16]; + + } server_ip_address; + + // SMTP server authentication type + uint8_t auth_type; + + // SMTP server port number + uint8_t server_port[4]; + +} rsi_smtp_client_init_t; + +// Define for SMTP client mail send +typedef struct rsi_smtp_mail_send_s { + // SMTP mail priority level + uint8_t smtp_feature; + + // SMTP mail body length + uint8_t mail_body_length[2]; + +} rsi_smtp_mail_send_t; + +// Define SMTP client structure +typedef struct rsi_req_smtp_client_s { + // SMTP client command type + uint8_t command_type; + + // SMTP client command structure + union { + rsi_smtp_client_init_t smtp_client_init; + rsi_smtp_mail_send_t smtp_mail_send; + + } smtp_struct; + + uint8_t smtp_buffer[RSI_SMTP_BUFFER_LENGTH]; + +} rsi_req_smtp_client_t; + +// SMTP response structure +typedef struct rsi_rsp_smtp_client_s { + // Receive SMTP command type + uint8_t command_type; + +} rsi_rsp_smtp_client_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +// multicast related prototypes +/****************************************************** + * * Macros + * ******************************************************/ + +// Multicast join command +#define RSI_MULTICAST_JOIN 1 + +// Multicast leave command +#define RSI_MULTICAST_LEAVE 0 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// Multicast request structure +typedef struct rsi_req_multicast { + // IP version + uint8_t ip_version[2]; + + // command type + uint8_t type[2]; + + union { + uint8_t ipv4_address[4]; + uint8_t ipv6_address[16]; + } multicast_address; + +} rsi_req_multicast_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +// HTTP server Application includes + +/****************************************************** + * * Macros + * ******************************************************/ + +#define RSI_MAX_URL_LENGTH 40 +#define RSI_MAX_FILE_NAME_LENGTH 24 +#define RSI_MAX_POST_DATA_LENGTH 512 +#define RSI_MAX_WEBPAGE_SEND_SIZE 1024 +#define RSI_MAX_HOST_WEBPAGE_SEND_SIZE 1400 + +#define RSI_JSON_MAX_CHUNK_LENGTH 1024 +#define RSI_WEB_PAGE_CLEAR_ALL_FILES 1 +#define RSI_WEB_PAGE_HAS_JSON 1 + +/****************************************************** + * * Global Variables + * ******************************************************/ + +/****************************************************** + * * Structures +*******************************************************/ + +typedef struct { + uint8_t url_length; + uint8_t url_name[RSI_MAX_URL_LENGTH]; + uint8_t request_type; + uint8_t post_content_length[2]; + uint8_t post_data[RSI_MAX_POST_DATA_LENGTH]; + +} rsi_urlReqFrameRcv; + +// Define Webpage load request structure +typedef struct rsi_webpage_load_s { + // file name of the webpage + uint8_t filename[RSI_MAX_FILE_NAME_LENGTH]; + + // Total length of the webpage + uint8_t total_len[2]; + + // Current length of the webapge + uint8_t current_len[2]; + + // webpage associated json object flag + uint8_t has_json_data; + + // Webpage content + uint8_t webpage[RSI_MAX_WEBPAGE_SEND_SIZE]; + +} rsi_webpage_load_t; + +// Define json object load request structure +typedef struct rsi_json_object_load_s { + // File name of the json object + uint8_t filename[RSI_MAX_FILE_NAME_LENGTH]; + + // Total length of the json object data + uint8_t total_length[2]; + + // Current length of the json object + uint8_t current_length[2]; + + // Json object data + uint8_t json_object[RSI_JSON_MAX_CHUNK_LENGTH]; + +} rsi_json_object_load_t; + +// Define webpage erase all request structure +typedef struct rsi_webpage_erase_all_s { + // Flag to clear the file + uint8_t clear; + +} rsi_webpage_erase_all_t; + +// Define webpage erase request structure +typedef struct rsi_wbpage_erase_s { + // Filename of the webpage or json object data + char filename[RSI_MAX_FILE_NAME_LENGTH]; + +} rsi_wbpage_erase_t; + +// Define json object erase request structure +typedef struct rsi_json_object_erase_s { + // Filename of the webpage or json object data + char filename[RSI_MAX_FILE_NAME_LENGTH]; + +} rsi_json_object_erase_t; + +// Host web page send request structure +typedef struct rsi_webpage_send_s { + // Total length of the webpage + uint8_t total_len[4]; + + // More chunks flag + uint8_t more_chunks; + + // Webpage content + uint8_t webpage[RSI_MAX_HOST_WEBPAGE_SEND_SIZE]; + +} rsi_webpage_send_t; + +/****************************************************** + * * Function Declarations + * ******************************************************/ + +int32_t rsi_webpage_load(uint8_t flags, uint8_t *file_name, uint8_t *webpage, uint32_t length); +int32_t rsi_json_object_create(uint8_t flags, const char *file_name, uint8_t *json_object, uint32_t length); +int32_t rsi_webpage_erase(uint8_t *file_name); +int32_t rsi_json_object_delete(uint8_t *file_name); +int32_t rsi_webpage_send(uint8_t flags, uint8_t *webpage, uint32_t length); +void rsi_update_nwk_cmd_state_to_free_state(void); +void rsi_update_nwk_cmd_state_to_progress_state(void); +void rsi_post_waiting_nwk_semaphore(void); +int32_t rsi_driver_process_recv_data_non_rom(rsi_pkt_t *pkt); +int32_t rsi_driver_send_data_non_rom(uint32_t sockID, uint8_t *buffer, uint32_t length, struct rsi_sockaddr *destAddr); +int32_t rsi_http_credentials(int8_t *username, int8_t *password); +int32_t rsi_req_wireless_fwup(void); +// MDNS-SD structure definations + +/****************************************************** + * * Macros + * ******************************************************/ +// MDNSD buffer size +#define MDNSD_BUFFER_SIZE 1000 + +// MDNSD init +#define RSI_MDNSD_INIT 1 + +// MDNSD register service +#define RSI_MDNSD_REGISTER_SERVICE 3 + +// MDNSD deinit +#define RSI_MDNSD_DEINIT 6 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// mdnsd init structure +typedef struct rsi_mdnsd_init_s { + // ip version + uint8_t ip_version; + + // time to live + uint8_t ttl[2]; + +} rsi_mdnsd_init_t; + +// mdnsd register-service structure +typedef struct rsi_mdnsd_reg_srv_s { + // port number + uint8_t port[2]; + + // time to live + uint8_t ttl[2]; + + // reset if it is last service in the list + uint8_t more; + +} rsi_mdnsd_reg_srv_t; + +// mdnsd structure +typedef struct rsi_req_mdnsd_t { + // command type 1-MDNSD init, 3- Register service, 6- Deinit + uint8_t command_type; + union { + // mdnsd init + rsi_mdnsd_init_t mdnsd_init; + + // mdnsd register + rsi_mdnsd_reg_srv_t mdnsd_register_service; + + } mdnsd_struct; + + // buffer + uint8_t buffer[MDNSD_BUFFER_SIZE]; + +} rsi_req_mdnsd_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +// POP3 Client Application includes + +/****************************************************** + * * Macros + * ******************************************************/ + +#define POP3_CLIENT_MAX_USERNAME_LENGTH 101 +#define POP3_CLIENT_MAX_PASSWORD_LENGTH 101 + +// POP3 client session create command +#define POP3_CLIENT_SESSION_CREATE 1 + +// POP3 client get mail stats command +#define POP3_CLIENT_GET_MAIL_STATS 2 + +// POP3 client get mail list command +#define POP3_CLIENT_GET_MAIL_LIST 3 + +// POP3 client retrive mail command +#define POP3_CLIENT_RETR_MAIL 4 + +// POP3 client mark(deleted) mail stats command +#define POP3_CLIENT_MARK_MAIL 5 + +// POP3 client unmark all mails command +#define POP3_CLIENT_UNMARK_MAIL 6 + +// POP3 client get server status command +#define POP3_CLIENT_GET_SERVER_STATUS 7 + +// POP3 client session delete command +#define POP3_CLIENT_SESSION_DELETE 8 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +// Define POP3 client session create structure +typedef struct rsi_pop3_client_session_create { + // POP3 server ip version + uint8_t ip_version; + + union { + // Server ipv4 address + uint8_t ipv4_address[4]; + + // Server ipv6 address + uint8_t ipv6_address[16]; + + } server_ip_address; + + // POP3 server port number + uint8_t server_port_number[2]; + + // POP3 client authentication type + uint8_t auth_type; + + // POP3 client username + uint8_t username[POP3_CLIENT_MAX_USERNAME_LENGTH]; + + // POP3 client password + uint8_t password[POP3_CLIENT_MAX_PASSWORD_LENGTH]; + +} rsi_pop3_client_session_create_t; + +// Define POP3 client request structure +typedef struct rsi_req_pop3_client_s { + // POP3 client command type + uint8_t command_type; + + // POP3 client command structure + union { + // POP3 client session create structure + rsi_pop3_client_session_create_t pop3_client_session_create; + + // POP3 client mail index + uint8_t pop3_client_mail_index[2]; + + } pop3_struct; + +} rsi_req_pop3_client_t; + +// Define POP3 client response structure +typedef struct rsi_pop3_client_resp_s { + uint8_t command_type; + + // Total number of mails + uint8_t mail_count[2]; + + // Total size of all the mails + uint8_t size[4]; + +} rsi_pop3_client_resp_t; + +// Define POP3 client mail data response structure +typedef struct rsi_pop3_mail_data_resp_s { + // Type of the POP3 client command + uint8_t command_type; + + // More data pending flag + uint8_t more; + + // Length the mail chunk + uint8_t length[2]; + +} rsi_pop3_mail_data_resp_t; + +// HTTP Client PUT Application includes + +/****************************************************** + * * Macros + * ******************************************************/ + +#define HTTP_CLIENT_PUT_MAX_BUFFER_LENGTH 900 + +#define MAX_HTTP_CLIENT_PUT_BUFFER_LENGTH 900 + +// HTTP client maximum post data chunk length +#define HTTP_CLIENT_POST_DATA_MAX_BUFFER_LENGTH 900 +#define MAX_HTTP_CLIENT_POST_DATA_BUFFER_LENGTH 900 + +// HTTP client PUT create command +#define HTTP_CLIENT_PUT_CREATE 1 + +// HTTP client PUT START command +#define HTTP_CLIENT_PUT_START 2 + +// HTTP client PUT PKT command +#define HTTP_CLIENT_PUT_PKT 3 + +// HTTP client PUT DELETE command +#define HTTP_CLIENT_PUT_DELETE 4 + +// HTTP client PUT PKT OFFSET command +#define HTTP_CLIENT_PUT_OFFSET_PKT 5 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +// Define HTTP client PUT START create structure +typedef struct rsi_http_client_put_start_s { + // HTTP server ip version + uint8_t ip_version; + + // HTTPS bit map + uint8_t https_enable[2]; + + // HTTP server port number + uint8_t port_number[4]; + + // HTTP Content Length + uint8_t content_length[4]; + +} rsi_http_client_put_start_t; + +typedef struct rsi_http_client_put_data_req_s { + // Current chunk length + uint8_t current_length[2]; +} rsi_http_client_put_data_req_t; + +typedef struct rsi_http_client_put_req_s { + // Command type + uint8_t command_type; + + union { + // HTTP PUT START command structure + rsi_http_client_put_start_t http_client_put_start; + + // HTTP PUT PACKET command structure + rsi_http_client_put_data_req_t http_client_put_data_req; + + } http_client_put_struct; + + // HTTP PUT buffer + uint8_t http_put_buffer[MAX_HTTP_CLIENT_PUT_BUFFER_LENGTH]; + +} rsi_http_client_put_req_t; + +// HTTP Client PUT pkt server response structure +typedef struct http_Put_Data_s { + uint32_t command_type; + uint32_t more; + uint32_t offset; + uint32_t data_len; +} http_Put_Data_t; + +// HTTP Client PUT response structure +typedef struct rsi_http_client_put_rsp_s { + // Receive HTTP Client PUT command type + uint8_t command_type; + +} rsi_http_client_put_rsp_t; + +// HTTP Client PUT PKT response structure +typedef struct rsi_http_client_put_pkt_rsp_s { + // Receive HTTP client PUT command type + uint8_t command_type; + + // End of resource content file + uint8_t end_of_file; + +} rsi_http_client_put_pkt_rsp_t; + +// HTTP Client POST DATA PKT request structure +typedef struct rsi_http_client_post_data_req_s { + // Current http data chunk length + uint8_t current_length[2]; + + // HTTP POST buffer + uint8_t http_post_data_buffer[MAX_HTTP_CLIENT_POST_DATA_BUFFER_LENGTH]; + +} rsi_http_client_post_data_req_t; + +/****************************************************** + * * Macros + * ******************************************************/ + +#define RSI_EMB_MQTT_TOPIC_MAX_LEN 62 +#define RSI_EMB_MQTT_WILL_MSG_MAX_LEN 100 +#define RSI_EMB_MQTT_CLIENTID_MAX_LEN 62 +#define RSI_EMB_MQTT_USERNAME_MAX_LEN 62 +#define RSI_EMB_MQTT_PASSWORD_MAX_LEN 62 +#define RSI_TCP_MAX_SEND_SIZE 1460 +#define RSI_EMB_MQTT_PUB_MAX_LEN RSI_TCP_MAX_SEND_SIZE +#define RSI_EMB_MQTT_SSL_PUB_MAX_LEN (RSI_TCP_MAX_SEND_SIZE - RSI_SSL_HEADER_SIZE) +#define RSI_EMB_MQTT_FIXED_HDR_LEN 3 +#define RSI_EMB_MQTT_PACKET_ID_LEN 2 + +// Emb MQTT init Flags +#define RSI_EMB_MQTT_CLEAN_SESSION BIT(0) +#define RSI_EMB_MQTT_SSL_ENABLE BIT(1) +#define RSI_EMB_MQTT_IPV6_ENABLE BIT(2) +#ifdef CHIP_9117 +//! Here BIT(4,5,6,7) all four bit related to RSI_EMB_MQTT_TCP_MAX_RETRANSMISSION_CAP +//! for example if BIT(4) set will treat it as 1 sec +//! if BIT(5) set will treat as 2 sec +//! if (BIT(4) | BIT(5)) set will treat as 3sec like so on.... +#define RSI_EMB_MQTT_TCP_MAX_RETRANSMISSION_CAP BIT(4) +#endif +// Emb MQTT Connect flags +#define RSI_EMB_MQTT_USER_FLAG BIT(7) +#define RSI_EMB_MQTT_PWD_FLAG BIT(6) +#define RSI_EMB_MQTT_WILL_RETAIN BIT(5) +#define RSI_EMB_MQTT_WILL_FLAG BIT(2) + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations +` * ******************************************************/ + +typedef enum rsi_emb_mqtt_state_e { + RSI_EMB_MQTT_UNINIT_STATE = 0, + RSI_EMB_MQTT_CLIENT_INIT = 1, + RSI_EMB_MQTT_CONNECT = 2, + RSI_EMB_MQTT_SUBSCRIBE = 3, + RSI_EMB_MQTT_SND_PUB_PKT = 4, + RSI_EMB_MQTT_UNSUBSCRIBE = 5, + RSI_EMB_MQTT_TIMEOUT = 6, + RSI_EMB_MQTT_RCV_PUB_PKT = 7, + RSI_EMB_MQTT_DISCONNECT = 8, + RSI_EMB_MQTT_COMMAND_DESTROY = 9 +} rsi_emb_mqtt_state_t; + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +typedef struct rsi_mqtt_pubmsg_s { + int8_t qos; + + int8_t retained; + + int8_t dup; + + void *payload; + + uint16_t payloadlen; + +} rsi_mqtt_pubmsg_t; + +typedef struct rsi_emb_mqtt_unsub_s { + uint8_t command_type[4]; + // length of TOPIC + uint8_t topic_len; + // topic of unsubscribe message + uint8_t topic[RSI_EMB_MQTT_TOPIC_MAX_LEN]; + +} rsi_emb_mqtt_unsub_t; + +typedef struct rsi_emb_mqtt_snd_pub_s { + uint8_t command_type[4]; + // length of TOPIC + uint8_t topic_len; + // topic of unsubscribe message + uint8_t topic[RSI_EMB_MQTT_TOPIC_MAX_LEN]; + // message Qos, can be 0, 1, or 2 + uint8_t qos; + // retained flag, can be 0 or 1 + uint8_t retained; + // duplicate flag, can be 0 or 1 + uint8_t dup; + // length of publish message(option), if set to 0 or + //omitted, will be parsed in text format, else + //hexidecimai format + uint8_t msg_len[2]; + // publish message + int8_t *msg; + +} rsi_emb_mqtt_snd_pub_t; + +typedef struct rsi_emb_mqtt_sub_s { + uint8_t command_type[4]; + // length of TOPIC + uint8_t topic_len; + // topic of subscribe message + int8_t topic[RSI_EMB_MQTT_TOPIC_MAX_LEN]; + // message Qos, can be 0, 1, or 2 + int8_t qos; + +} rsi_emb_mqtt_sub_t; + +typedef struct rsi_emb_mqtt_connect_s { + uint8_t command_type[4]; + // weather to use username (0-1) + uint8_t usrFlag; + // weather to use pwdFlag (0-1) + uint8_t pwdFlag; + // weather to set willmsg (0-1) + uint8_t willFlag; + // retained flag(0-1) + uint8_t willRetain; + // message Qos(0-2) + uint8_t willQos; + // length of topic + uint8_t willTopic_len; + // topic name of will + uint8_t will_topic[RSI_EMB_MQTT_TOPIC_MAX_LEN]; + // Length of Will message + uint8_t will_message_len; + // message of will + uint8_t will_msg[RSI_EMB_MQTT_WILL_MSG_MAX_LEN]; + +} rsi_emb_mqtt_connect_t; + +typedef struct rsi_emb_mqtt_ip_addr_s { + // IP version + uint8_t ip_version[4]; + union { + uint8_t ipv4_address[4]; + uint8_t ipv6_address[16]; + } server_ip_address; +} rsi_emb_mqtt_ip_addr_t; + +typedef struct rsi_emb_mqtt_client_init_s { + uint8_t command_type[4]; + // MQTT server IP address + rsi_emb_mqtt_ip_addr_t server_ip; + // MQTT server port + uint8_t server_port[4]; + // Client ID Length + uint8_t clientID_len; + // client ID, should be unique + int8_t client_id[RSI_EMB_MQTT_CLIENTID_MAX_LEN]; + // keep alive interval (s) + uint8_t keep_alive_interval[2]; + // username Length + uint8_t username_len; + // user name + uint8_t user_name[RSI_EMB_MQTT_USERNAME_MAX_LEN]; + // password Length + uint8_t password_len; + // password + uint8_t password[RSI_EMB_MQTT_PASSWORD_MAX_LEN]; + // clean session(0-1) + uint8_t clean; + // 0 : TCP , 1 : SSl + uint8_t encrypt; + // MQTT Client port + uint8_t client_port[4]; +#ifdef CHIP_9117 + //! Capping tcp retransmission timeout + uint8_t tcp_max_retransmission_cap_for_emb_mqtt; +#endif +} rsi_emb_mqtt_client_init_t; + +typedef struct rsi_req_emb_mqtt_command_s { + // MQTT command type + uint8_t command_type[4]; + +} rsi_req_emb_mqtt_command_t; + +#endif diff --git a/wiseconnect/sapi/include/rsi_os.h b/wiseconnect/sapi/include/rsi_os.h new file mode 100644 index 00000000..7a08165c --- /dev/null +++ b/wiseconnect/sapi/include/rsi_os.h @@ -0,0 +1,133 @@ +/******************************************************************************* +* @file rsi_os.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_OS_H +#define RSI_OS_H +#include "rsi_error.h" +/****************************************************** + * * Macros + * ******************************************************/ +// Macro to increment a value +#define RSI_ATOMIC_INCREMENT(value) \ + { \ + (value)++; \ + } + +// Macro to decrement a value +#define RSI_ATOMIC_DECREMENT(value) \ + { \ + (value)--; \ + } +// Error none (success) +#define RSI_ERR_NONE (0) + +// Error returned when invalid arguments are given +#define RSI_ERR_INVALID_ARGS (1) + +// Error returned when timeout error occurs +#define RSI_ERR_TIMEOUT (3) + +// Mutex unlock value +#define RSI_NO_OS_MUTEX_UNLOCKED (0) + +// Mutex lock value +#define RSI_NO_OS_MUTEX_LOCKED (1) + +// Macro to set the mutex lock +#define RSI_NO_OS_ATOMIC_MUTEX_SET(mutex, value) (mutex) = value + +// Macro for checking whether mutex is locked or not +#define RSI_NO_OS_ATOMIC_MUTEX_CHECK(mutex, value) (((mutex) == value) ? 1 : 0) +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +typedef uint32_t rsi_reg_flags_t; +// Handle to manage Semaphores. +typedef uint32_t rsi_semaphore_handle_t; +// Handle to manage Mutex. +typedef uint32_t rsi_mutex_handle_t; + +// Task handler +typedef void *rsi_task_handle_t; + +typedef long rsi_base_type_t; +// Task function +typedef void (*rsi_task_function_t)(void *function); +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +/* --------- CRITICAL SECTION FUNCTIONS --------- */ +rsi_reg_flags_t rsi_critical_section_entry(void); +void rsi_critical_section_exit(rsi_reg_flags_t flags); +/* -------------- MUTEX FUNCTIONS -------------- */ +rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *p_mutex); +rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *p_mutex); +void rsi_mutex_lock_from_isr(volatile rsi_mutex_handle_t *mutex); +rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *p_mutex); +void rsi_mutex_unlock_from_isr(volatile rsi_mutex_handle_t *mutex); +rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *p_mutex); + +/* ------------- SEMAPHORE FUNCTIONS ----------- */ +rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *p_sem, uint32_t cnt); +rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *p_sem); +rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *p_sem); +rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *p_sem, uint32_t timeout); +rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *p_sem); +rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore); +rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *p_sem); + +/* ------------- TASK FUNCTIONS ----------- */ +rsi_error_t rsi_task_create(rsi_task_function_t task_function, + uint8_t *task_name, + uint32_t stack_size, + void *parameters, + uint32_t task_priority, + rsi_task_handle_t *task_handle); + +void rsi_task_destroy(rsi_task_handle_t *task_handle); +void rsi_task_delete(rsi_task_handle_t *task_handle); +void rsi_os_task_delay(uint32_t timeout_ms); +void rsi_task_suspend(rsi_task_handle_t *task_handle); +void rsi_start_os_scheduler(void); +void rsi_wireless_driver_task_create(void); +/* ---------- OS MEMORY MAPPING FUNCTIONS -------- */ +void *rsi_virtual_to_physical_address(void *x); +void *rsi_physical_to_virtual_address(void *x); +void *rsi_malloc(uint32_t size); +void rsi_free(void *p); +void rsi_vport_enter_critical(void); +void rsi_vport_exit_critical(void); +int32_t rsi_get_error(int32_t sockID); +void rsi_set_os_errno(int32_t error); +#endif diff --git a/wiseconnect/sapi/include/rsi_pkt_mgmt.h b/wiseconnect/sapi/include/rsi_pkt_mgmt.h new file mode 100644 index 00000000..caa4dca5 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_pkt_mgmt.h @@ -0,0 +1,89 @@ +/******************************************************************************* +* @file rsi_pkt_mgmt.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_PKT_MGMT_H +#define RSI_PKT_MGMT_H + +#include +#include +#if ((defined RSI_SDIO_INTERFACE) && (defined CHIP_9117)) +#define SIZE_OF_HEADROOM 216 +#else +#define SIZE_OF_HEADROOM 0 +#endif +/****************************************************** + * * Macros + * ******************************************************/ +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +// driver TX/RX packet structure +typedef struct rsi_pkt_s { + // next packet pointer + struct rsi_pkt_s *next; + +#if ((defined RSI_SDIO_INTERFACE) && (defined CHIP_9117)) + uint8_t headroom[SIZE_OF_HEADROOM]; +#endif + + // host descriptor + uint8_t desc[16]; + + // payload + uint8_t data[1]; +} rsi_pkt_t; + +// packet pool structure +typedef struct rsi_pkt_pool_s { + // Pool total packets count + uint16_t size; + + // Pool avaialble packets count + uint16_t avail; + + // Pool pointer + void **pool; + + rsi_semaphore_handle_t pkt_sem; + +} rsi_pkt_pool_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_pkt_pool_init(rsi_pkt_pool_t *pool_cb, uint8_t *buffer, uint32_t total_size, uint32_t pkt_size); +rsi_pkt_t *rsi_pkt_alloc(rsi_pkt_pool_t *pool_cb); +int32_t rsi_pkt_free(rsi_pkt_pool_t *pool_cb, rsi_pkt_t *pkt); +uint32_t rsi_is_pkt_available(rsi_pkt_pool_t *pool_cb); +#endif diff --git a/wiseconnect/sapi/include/rsi_prop_protocol.h b/wiseconnect/sapi/include/rsi_prop_protocol.h new file mode 100644 index 00000000..0f931b8a --- /dev/null +++ b/wiseconnect/sapi/include/rsi_prop_protocol.h @@ -0,0 +1,47 @@ +/******************************************************************************* +* @file rsi_prop_protocol.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_PROP_PROTOCOL_H +#define RSI_PROP_PROTOCOL_H + +#include +#include +#include + +typedef void (*rsi_prop_protocol_resp_handler_t)(uint8_t *data); +typedef void (*rsi_prop_protocol_data_request_callback_t)(void); +// Driver PROP_PROTOCOL control block +typedef struct rsi_prop_protocol_cb_s { + //PROP_PROTOCOL CBFC callbacks + rsi_prop_protocol_resp_handler_t prop_protocol_async_resp_handler; + rsi_prop_protocol_data_request_callback_t rsi_prop_protocol_data_request_callback; +} rsi_prop_protocol_cb_t; + +void rsi_prop_protocol_common_tx_done(rsi_pkt_t *pkt); +void rsi_prop_protocol_callbacks_handler(rsi_bt_cb_t *, uint16_t rsp_type, uint8_t *payload, uint16_t payload_length); +int32_t rsi_driver_process_prop_protocol_resp( + rsi_bt_cb_t *, + rsi_pkt_t *pkt, + void (*rsi_bt_async_callback_handler)(rsi_bt_cb_t *cb, uint16_t type, uint8_t *data, uint16_t length)); +#define RSI_OPERMODE_PROP_PROTOCOL 0x109 + +#endif diff --git a/wiseconnect/sapi/include/rsi_qspi_defines.h b/wiseconnect/sapi/include/rsi_qspi_defines.h new file mode 100644 index 00000000..d7846ceb --- /dev/null +++ b/wiseconnect/sapi/include/rsi_qspi_defines.h @@ -0,0 +1,298 @@ +/******************************************************************************* +* @file rsi_qspi_defines.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef QSPI_DEFINES_H +#define QSPI_DEFINES_H + +// This structure members are used to configure qspi +typedef struct spi_config_1_s { + /** + * QSPI operation modes, all modes are single, dual or quad + **/ + uint32_t inst_mode : 2; //< instruction will be sent in this mode + uint32_t addr_mode : 2; //< addr will be sent in this mode + uint32_t data_mode : 2; //< data will be sent/received in this mode + uint32_t dummy_mode : 2; //< dummy bytes will be sent/received in this mode + uint32_t extra_byte_mode : 2; //< extra bytes will be sent in this mode + // SPI mode +#define SINGLE_MODE 0 + // dual mode +#define DUAL_MODE 1 + // quad mode +#define QUAD_MODE 2 +#define OCTA_MODE 3 + + uint32_t prefetch_en : 1; //< prefetch enable + // prefetch will be enabled +#define EN_PREFETCH 1 + // prefetch will be disabled +#define DIS_PREFETCH 0 + + uint32_t dummy_W_or_R : 1; //< dummy writes or read select + // dummy's are read +#define DUMMY_READS 0 + // dummy's are written +#define DUMMY_WRITES 1 + + uint32_t extra_byte_en : 1; //< Enable extra byte + // Extra byte will be enabled +#define EN_EXTRA_BYTE + // Extra byte will be disabled +#define DIS_EXTRA_BYTE + + uint32_t d3d2_data : 2; //< Data on D3 and D2 line in SPI or DUAL mode + + uint32_t continuous : 1; //< continuous mode select + // continuous mode is selected +#define CONTINUOUS 1 + // discontinuous mode is selected +#define DIS_CONTINUOUS 0 + + uint32_t read_cmd : 8; //< read cmd to be used +// fast read dual output +#define FREAD_DUAL_O 0x3B +// fast read quad output +#define FREAD_QUAD_O 0x6B + +#define FREAD_QUAD_O_EB 0xEB + +/**************************************** + * WINBOND + MACRONIX specific cmds + ***************************************/ +// fast read dual IO +#define FREAD_DUAL_IO 0xBB +// fast read quad IO +#define FREAD_QUAD_IO 0xEB + + uint32_t flash_type : 4; //< flash defines + // sst spi flash +#define SST_SPI_FLASH 0 + // sst dual flash +#define SST_DUAL_FLASH 1 + // sst quad flash +#define SST_QUAD_FLASH 2 + // Winbond quad flash +#define WBOND_QUAD_FLASH 3 + // Atmel quad flash +#define AT_QUAD_FLASH 4 + // macronix quad flash +#define MX_QUAD_FLASH 5 + // cFeon quad flash +#define EON_QUAD_FLASH 6 + // Micron quad flash +#define MICRON_QUAD_FLASH 7 + // Giga Device flash +#define GIGA_DEVICE_FLASH 8 + // macronix octa flash +#define MX_OCTA_FLASH 9 + // Adesto octa flash +#define ADESTO_OCTA_FLASH 10 + + uint32_t no_of_dummy_bytes : 4; //< no_of_dummy_bytes to be used for read operations +} spi_config_1_t; + +// This structure members are used to configure qspi +typedef struct spi_config_2_s { + + uint32_t auto_mode : 1; //< mode select + // Auto mode selection +#define EN_AUTO_MODE 1 + // Manual mode selection +#define EN_MANUAL_MODE 0 + + uint32_t cs_no : 2; //< QSPI chip_select + // cs-0 +#define CHIP_ZERO 0 + // cs-1 +#define CHIP_ONE 1 + // cs-2 +#define CHIP_TWO 2 + // cs-3 +#define CHIP_THREE 3 + + uint32_t reserved1 : 1; //< Jump Enable + // Enables jump +#define EN_JUMP 1 + // Disables jump +#define DIS_JUMP 0 + + uint32_t neg_edge_sampling : 1; //< For High speed mode, sample at neg edge + // enables neg edge sampling +#define NEG_EDGE_SAMPLING 1 + // enables pos edge sampling +#define POS_EDGE_SAMPLING 0 + + uint32_t qspi_clk_en : 1; //< qspi clk select + // full time clk will be provided +#define QSPI_FULL_TIME_CLK 1 + // dynamic clk gating will be enabled +#define QSPI_DYNAMIC_CLK 0 + + uint32_t protection : 2; //< flash protection select + // enable write protection +#define EN_WR_PROT 2 + // remove write protection +#define REM_WR_PROT 1 + // no change to wr protection +#define DNT_REM_WR_PROT 0 + + uint32_t dma_mode : 1; //< dma mode enable + // use dma only in manaul mode +#define DMA_MODE 1 + // dma will not be used +#define NO_DMA 0 + + uint32_t swap_en : 1; //< swap enable for w/r + // swap will be enabled +#define SWAP 1 + // swap will be disabled +#define NO_SWAP 0 + + uint32_t full_duplex : 2; //< full duplex mode select + // do nothing for full duplex +#define IGNORE_FULL_DUPLEX 2 + // enable full duplex +#define EN_FULL_DUPLEX 1 + // disable full duplex +#define DIS_FULL_DUPLEX 0 + + uint32_t wrap_len_in_bytes : 3; //< wrap len to be used + // wrap is diabled +#define NO_WRAP 7 + // 8 byte wrap will be used +#define SST_8BYTE_WRAP 0 + // 16 byte wrap will be used +#define SST_16BYTE_WRAP 1 + // 32 byte wrap will be used +#define SST_32BYTE_WRAP 2 + // 64 byte wrap will be used +#define SST_64BYTE_WRAP 3 + + // 16 byte wrap will be used +#define MICRON_16BYTE_WRAP 0 + // 32 byte wrap will be used +#define MICRON_32BYTE_WRAP 1 + // 64 byte wrap will be used +#define MICRON_64BYTE_WRAP 2 + + uint32_t addr_width_valid : 1; + + uint32_t addr_width : 3; //< addr width to used + // 32 bit addr is configured +#define _32BIT_ADDR 4 + // 24 bit addr is configured +#define _24BIT_ADDR 3 + // 16 bit addr is configured +#define _16BIT_ADDR 2 + // 9 bit addr is configured +#define _9BIT_ADDR 1 + // 8 bit addr is configured +#define _8BIT_ADDR 0 + +#define MANUAL_DUMMY_BYTE_OR_BIT_MODE BIT(25) +#define DUMMY_BYTE_OR_BIT_MODE BIT(0) + uint32_t dummy_cycles_for_controller : 2; + + uint32_t reserved2 : 6; + // uint32_t jump_inst : 8; //< Instruction to be used in case of jump + + uint32_t pinset_valid : 1; + + uint32_t flash_pinset : 4; //< width of memory protection reg for sst flashes + +} spi_config_2_t; + +// This structure members are used to configure qspi +typedef struct spi_config_3_s { +#define CONTINUE_FETCH_EN BIT(12) +#define WORD_SWAP_EN 20 + uint32_t en_word_swap : 1; + uint32_t _16bit_cmd_valid : 1; + uint32_t _16bit_rd_cmd_msb : 8; + uint32_t xip_mode : 1; + uint32_t no_of_dummy_bytes_wrap : 4; //< no_of_dummy_bytes to be used for wrap operations + uint32_t ddr_mode_en : 1; + uint32_t wr_cmd : 8; + uint32_t wr_inst_mode : 2; + uint32_t wr_addr_mode : 2; + uint32_t wr_data_mode : 2; + uint32_t dummys_4_jump : 2; //< no_of_dummy_bytes in case of jump instruction +} spi_config_3_t; + +typedef struct spi_config_4_s { + uint32_t _16bit_wr_cmd_msb : 8; + uint32_t qspi_ddr_clk_en : 1; + uint32_t qspi_loop_back_mode_en : 1; + uint32_t qspi_manual_ddr_phasse : 1; + uint32_t ddr_data_mode : 1; + uint32_t ddr_inst_mode : 1; + uint32_t ddr_addr_mode : 1; + uint32_t ddr_dummy_mode : 1; + uint32_t ddr_extra_byte : 1; + uint32_t dual_flash_mode : 1; + uint32_t secondary_csn : 1; + uint32_t polarity_mode : 1; + uint32_t valid_prot_bits : 4; + uint32_t no_of_ms_dummy_bytes : 4; + uint32_t ddr_dll_en : 1; + uint32_t continue_fetch_en : 1; + uint32_t dma_write : 1; + uint32_t prot_top_bottom : 1; + uint32_t auto_csn_based_addr_en : 1; +} spi_config_4_t; +typedef struct spi_config_5_s { + uint32_t block_erase_cmd : 16; + uint32_t busy_bit_pos : 3; + uint32_t d7_d4_data : 4; + uint32_t dummy_bytes_for_rdsr : 4; + uint32_t reset_type : 5; +} spi_config_5_t; + +typedef struct spi_config_6_s { + uint32_t chip_erase_cmd : 16; + // chip erase cmd +#define CHIP_ERASE 0xC7 + uint32_t sector_erase_cmd : 16; +// block erase cmd +#define BLOCK_ERASE 0xD8 + // sector erase cmd +#define SECTOR_ERASE 0x20 + +} spi_config_6_t; + +typedef struct spi_config_7_s { + uint32_t status_reg_write_cmd : 16; + uint32_t status_reg_read_cmd : 16; +} spi_config_7_t; + +// This structure has two daughter structures to configure qspi +typedef struct spi_config_s { + spi_config_1_t spi_config_1; //< daughter structure 1 + spi_config_2_t spi_config_2; //< daughter structure 2 + spi_config_3_t spi_config_3; //< daughter structure 3 + spi_config_4_t spi_config_4; //< daughter structure 4 + spi_config_5_t spi_config_5; //< daughter structure 5 + spi_config_6_t spi_config_6; //< daughter structure 5 + spi_config_7_t spi_config_7; //< daughter structure 5 +} spi_config_t; + +#endif diff --git a/wiseconnect/sapi/include/rsi_queue.h b/wiseconnect/sapi/include/rsi_queue.h new file mode 100644 index 00000000..d4f7706d --- /dev/null +++ b/wiseconnect/sapi/include/rsi_queue.h @@ -0,0 +1,73 @@ +/******************************************************************************* +* @file rsi_queue.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_QUEUE_H +#define RSI_QUEUE_H +/****************************************************** + * * Macros + * ******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ + +// queue structure +typedef struct rsi_queue_cb_s { + // queue head + rsi_pkt_t *head; + + // queue tail + rsi_pkt_t *tail; + + // number of packets pending in queue + volatile uint16_t pending_pkt_count; + + // mask status of the queue + uint16_t queue_mask; + + // Mutex handle to queues + rsi_mutex_handle_t queue_mutex; + +} rsi_queue_cb_t; + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +extern void rsi_queues_init(rsi_queue_cb_t *queue); +extern void rsi_enqueue_pkt(rsi_queue_cb_t *queue, rsi_pkt_t *pkt); +extern rsi_pkt_t *rsi_dequeue_pkt(rsi_queue_cb_t *queue); +extern uint32_t rsi_check_queue_status(rsi_queue_cb_t *queue); +extern void rsi_block_queue(rsi_queue_cb_t *queue); +extern void rsi_unblock_queue(rsi_queue_cb_t *queue); +#endif diff --git a/wiseconnect/sapi/include/rsi_scheduler.h b/wiseconnect/sapi/include/rsi_scheduler.h new file mode 100644 index 00000000..cd51c72e --- /dev/null +++ b/wiseconnect/sapi/include/rsi_scheduler.h @@ -0,0 +1,64 @@ +/******************************************************************************* +* @file rsi_scheduler.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_SCHEDULER_H +#define RSI_SCHEDULER_H +/****************************************************** + * * Macros + * ******************************************************/ +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// scheduler control block structure +typedef struct rsi_scheduler_cb_s { + // This bitmap is used to set and clear events + volatile uint32_t event_map; + + // This bitmap is used to mask and unmask events + volatile uint32_t mask_map; + + // scheduler semaphore + rsi_semaphore_handle_t scheduler_sem; +} rsi_scheduler_cb_t; + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +void rsi_scheduler_init(rsi_scheduler_cb_t *scheduler_cb); +uint32_t rsi_get_event(rsi_scheduler_cb_t *scheduler_cb); +void rsi_scheduler(rsi_scheduler_cb_t *scheduler_cb); +uint32_t rsi_get_event_non_rom(rsi_scheduler_cb_t *scheduler_cb); + +#endif diff --git a/wiseconnect/sapi/include/rsi_sdio.h b/wiseconnect/sapi/include/rsi_sdio.h new file mode 100644 index 00000000..3a441ef0 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_sdio.h @@ -0,0 +1,76 @@ +/******************************************************************************* +* @file rsi_sdio.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_SDIO_H +#define RSI_SDIO_H + +#ifndef LINUX_PLATFORM +#ifdef RSI_SDIO_INTERFACE +#include "rsi_data_types.h" +#include "stdint.h" +// host descriptor structure +typedef struct rsi_frame_desc_s { + // Data frame body length. Bits 14:12=queue, 000 for data, Bits 11:0 are the length + uint8_t frame_len_queue_no[2]; + // Frame type + uint8_t frame_type; + // Unused , set to 0x00 + uint8_t reserved[9]; + // Management frame descriptor response status, 0x00=success, else error + uint8_t status; + uint8_t reserved1[3]; +} rsi_frame_desc_t; + +// SDIO Apis defines +#define SD_MASTER_ACCESS BIT(16) +#define RSI_SDIO_TIMEOUT 50000 +#define RSI_INC_SDIO_TIMER rsi_driver_cb_non_rom->rsi_sdioTimer++ +#define RSI_RESET_SDIO_TIMER rsi_driver_cb_non_rom->rsi_sdioTimer = 0 +int16_t rsi_sdio_iface_init(void); +int16_t rsi_sdio_write_multiple(uint8_t *tx_data, uint32_t Addr, uint16_t no_of_blocks); +int8_t rsi_sdio_read_multiple(uint8_t *read_buff, uint32_t no_of_blocks); +int8_t sdio_reg_writeb(uint32_t Addr, uint8_t *dBuf); +int8_t sdio_reg_readb(uint32_t Addr, uint8_t *dBuf); +int16_t rsi_sdio_readb(uint32_t addr, uint16_t len, uint8_t *dBuf); +int16_t rsi_sdio_writeb(uint32_t addr, uint16_t len, uint8_t *dBuf); +int16_t rsi_mem_wr(uint32_t addr, uint16_t len, uint8_t *dBuf); +int16_t rsi_mem_rd(uint32_t addr, uint16_t len, uint8_t *dBuf); +int16_t rsi_reg_rd(uint8_t regAddr, uint8_t *dBuf); +int16_t rsi_reg_wr(uint8_t regAddr, uint8_t *dBuf); +int32_t rsi_mcu_sdio_init(void); +int16_t rsi_device_interrupt_status(uint8_t *int_status); +int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param); +int16_t rsi_frame_read(uint8_t *pkt_buffer); + +void smih_callback_handler(uint32_t event); +#endif +#endif +#ifndef RSI_BUFFER_FULL +// buffer full indication register value from module +#define RSI_BUFFER_FULL 0x01 +#endif +// RX packet pending register value from module +#define RSI_RX_PKT_PENDING 0x08 + +// Assertion Interrupt indication from module +#define RSI_ASSERT_INTR 0x80 // BIT(7) +#endif diff --git a/wiseconnect/sapi/include/rsi_setregion_countryinfo.h b/wiseconnect/sapi/include/rsi_setregion_countryinfo.h new file mode 100644 index 00000000..ee98b388 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_setregion_countryinfo.h @@ -0,0 +1,36 @@ +/******************************************************************************* +* @file rsi_setregion_countryinfo.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef _SETREGION_COUNTRYINFO_H_ +#define _SETREGION_COUNTRYINFO_H_ + +#include + +#define REGION_US 1 +#define REGION_EU 2 +#define REGION_JP 3 +#define REGION_INDIA 4 +#define REGION_SINGAPORE 5 +#define REGION_KOREA 6 + +void extract_setregionap_country_info(rsi_req_set_region_ap_t *); +#endif diff --git a/wiseconnect/sapi/include/rsi_socket.h b/wiseconnect/sapi/include/rsi_socket.h new file mode 100644 index 00000000..fa76a7f3 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_socket.h @@ -0,0 +1,694 @@ +/******************************************************************************* +* @file rsi_socket.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI__SOCKET_H +#define RSI__SOCKET_H +#include "rsi_os.h" +/****************************************************** + * * Macros + * ******************************************************/ +#ifdef fd_set +#undef fd_set +#endif +#define RSI_FD_ZERO(x) memset(x, 0, sizeof(rsi_fd_set)) +#define RSI_FD_SET(x, y) rsi_set_fd(x, y) +#define RSI_FD_CLR(x, y) rsi_fd_clr(x, y) +#define RSI_FD_ISSET(x, y) rsi_fd_isset(x, y) + +#define RSI_SOCKET_FEAT_SSL BIT(0) +#define RSI_SOCKET_FEAT_WEBS_SUPPORT BIT(1) +#define RSI_HIGH_PERFORMANCE_SOCKET BIT(7) + +#define RSI_SOCKET_FEAT_LTCP_ACCEPT BIT(1) +#define RSI_SOCKET_FEAT_TCP_ACK_INDICATION BIT(2) +#define RSI_SOCKET_FEAT_TCP_RX_WINDOW BIT(4) +#define RSI_SOCKET_FEAT_CERT_INDEX BIT(5) +#define RSI_SOCKET_FEAT_SYNCHRONOUS BIT(7) + +#define RSI_CERT_INDEX_0 0 +#define RSI_CERT_INDEX_1 1 +#define RSI_CERT_INDEX_2 2 + +#define RSI_TCP_LISTEN_MIN_BACKLOG 1 + +#define RSI_DHCP_UNICAST_OFFER BIT(3) + +#define RSI_LTCP_PRIMARY_SOCKET 1 +#define RSI_LTCP_SECONDARY_SOCKET 2 + +#define BSD_MAX_SOCKETS 10 +#define RSI_CLEAR_ALL_SOCKETS 0xEF +#define RSI_LTCP_PORT_BASED_CLOSE 0xEE +#ifdef FD_SETSIZE +#undef FD_SETSIZE /* May be different in other header files e.g 64 in GNU types.h file */ +#define FD_SETSIZE BSD_MAX_SOCKETS /* Number of sockets to select on - same is max sockets! */ +#else +#define FD_SETSIZE BSD_MAX_SOCKETS /* Number of sockets to select on - same is max sockets! */ +#endif + +// Max size of buffer to receive socket data +#define RSI_SOCKET_RECEIVE_BUFFER_SIZE 1500 + +/* Define some BSD protocol constants. */ + +#define SOCK_STREAM 1 /* TCP Socket */ +#define SOCK_DGRAM 2 /* UDP Socket */ +#define SOCK_RAW 3 /* Raw socket */ +#define IPPROTO_TCP 6 /* TCP Socket */ +#define IPPROTO_UDP 17 /* TCP Socket */ +#define IPPROTO_RAW 255 /* Raw Socket */ + +/* Address families. */ + +#define AF_UNSPEC 0 /* Unspecified. */ +#define AF_NS 1 /* Local to host (pipes, portals). */ +#define AF_INET 2 /* IPv4 socket (UDP, TCP, etc) */ +#define AF_INET6 3 /* IPv6 socket (UDP, TCP, etc) */ + +/* Protocol families, same as address families. */ +#define PF_INET AF_INET +#define PF_INET6 AF_INET6 + +#ifndef INADDR_ANY +#define INADDR_ANY 0 +#endif + +#define BSD_LOCAL_IF_INADDR_ANY 0xFFFFFFFF +/* Define API error codes. */ + +#ifndef htons +#define htons(a) a +#endif +#ifndef htonl +#define htonl(a) a +#endif +#ifndef ntohs +#define ntohs(a) a +#endif +#ifndef ntohl +#define ntohl(a) a +#endif + +/* Define error handling macro. */ + +/* Define file descriptor operation flags. */ + +/* Note: FIONREAD is hardware dependant. The default is for i386 processor. */ +#ifndef FIONREAD +#define FIONREAD 0x541B /* Read bytes available for the ioctl() command */ +#endif + +#define F_GETFL 3 /* Get file descriptors */ +#define F_SETFL 4 /* Set a subset of file descriptors (e.g. O_NONBlOCK */ +#define O_NONBLOCK 0x4000 /* Option to enable non blocking on a file (e.g. socket) */ + +#ifndef FIONBIO +#define FIONBIO 0x5421 /* Enables socket non blocking option for the ioctl() command */ +#endif + +/* Define additional BSD socket errors. */ + +/* From errno-base.h in /usr/include/asm-generic; */ +#define RSI_ERROR_EPERM 1 /* Operation not permitted */ +#define RSI_ERROR_E_MIN 1 /* Minimum Socket/IO error */ +#define RSI_ERROR_ENOENT 2 /* No such file or directory */ +#define RSI_ERROR_ESRCH 3 /* No such process */ +#define RSI_ERROR_EINTR 4 /* Interrupted system call */ +#define RSI_ERROR_EIO 5 /* I/O error */ +#define RSI_ERROR_ENXIO 6 /* No such device or address */ +#define RSI_ERROR_E2BIG 7 /* Argument list too long */ +#define RSI_ERROR_ENOEXEC 8 /* Exec format error */ +#define RSI_ERROR_EBADF 9 /* Bad file number */ +#define RSI_ERROR_ECHILD 10 /* No child processes */ +#define RSI_ERROR_EAGAIN 11 /* Try again */ +#define RSI_ERROR_ENOMEM 12 /* Out of memory */ +#define RSI_ERROR_EACCES 13 /* Permission denied */ +#define RSI_ERROR_EFAULT 14 /* Bad address */ +#define RSI_ERROR_ENOTBLK 15 /* Block device required */ +#define RSI_ERROR_EBUSY 16 /* Device or resource busy */ +#define RSI_ERROR_EEXIST 17 /* File exists */ +#define RSI_ERROR_EXDEV 18 /* Cross-device link */ +#define RSI_ERROR_ENODEV 19 /* No such device */ +#define RSI_ERROR_ENOTDIR 20 /* Not a directory */ +#define RSI_ERROR_EISDIR 21 /* Is a directory */ +#define RSI_ERROR_EINVAL 22 /* Invalid argument */ +#define RSI_ERROR_ENFILE 23 /* File table overflow */ +#define RSI_ERROR_EMFILE 24 /* Too many open files */ +#define RSI_ERROR_ENOTTY 25 /* Not a typewriter */ +#define RSI_ERROR_ETXTBSY 26 /* Text file busy */ +#define RSI_ERROR_EFBIG 27 /* File too large */ +#define RSI_ERROR_ENOSPC 28 /* No space left on device */ +#define RSI_ERROR_ESPIPE 29 /* Illegal seek */ +#define RSI_ERROR_EROFS 30 /* Read-only file system */ +#define RSI_ERROR_EMLINK 31 /* Too many links */ +#define RSI_ERROR_EPIPE 32 /* Broken pipe */ +#define RSI_ERROR_EDOM 33 /* Math argument out of domain of func */ +#define RSI_ERROR_ERANGE 34 /* Math result not representable */ + +/* From errno.h in /usr/include/asm-generic; */ + +#define RSI_ERROR_EDEADLK 35 /* Resource deadlock would occur */ +#define RSI_ERROR_ENAMETOOLONG 36 /* File name too long */ +#define RSI_ERROR_ENOLCK 37 /* No record locks available */ +#define RSI_ERROR_ENOSYS 38 /* Function not implemented */ +#define RSI_ERROR_ENOTEMPTY 39 /* Directory not empty */ +#define RSI_ERROR_ELOOP 40 /* Too many symbolic links encountered */ +#define RSI_ERROR_EWOULDBLOCK EAGAIN /* Operation would block */ +#define RSI_ERROR_ENOMSG 42 /* No message of desired type */ +#define RSI_ERROR_EIDRM 43 /* Identifier removed */ +#define RSI_ERROR_ECHRNG 44 /* Channel number out of range */ +#define RSI_ERROR_EL2NSYNC 45 /* Level 2 not synchronized */ +#define RSI_ERROR_EL3HLT 46 /* Level 3 halted */ +#define RSI_ERROR_EL3RST 47 /* Level 3 reset */ +#define RSI_ERROR_ELNRNG 48 /* Link number out of range */ +#define RSI_ERROR_EUNATCH 49 /* Protocol driver not attached */ +#define RSI_ERROR_ENOCSI 50 /* No CSI structure available */ +#define RSI_ERROR_EL2HLT 51 /* Level 2 halted */ +#define RSI_ERROR_EBADE 52 /* Invalid exchange */ +#define RSI_ERROR_EBADR 53 /* Invalid request descriptor */ +#define RSI_ERROR_EXFULL 54 /* Exchange full */ +#define RSI_ERROR_ENOANO 55 /* No anode */ +#define RSI_ERROR_EBADRQC 56 /* Invalid request code */ +#define RSI_ERROR_EBADSLT 57 /* Invalid slot */ +#define RSI_ERROR_EDEADLOCK EDEADLK +#define RSI_ERROR_EBFONT 59 /* Bad font file format */ +#define RSI_ERROR_ENOSTR 60 /* Device not a stream */ +#define RSI_ERROR_ENODATA 61 /* No data available */ +#define RSI_ERROR_ETIME 62 /* Timer expired */ +#define RSI_ERROR_ENOSR 63 /* Out of streams resources */ +#define RSI_ERROR_ENONET 64 /* Machine is not on the network */ +#define RSI_ERROR_ENOPKG 65 /* Package not installed */ +#define RSI_ERROR_EREMOTE 66 /* Object is remote */ +#define RSI_ERROR_ENOLINK 67 /* Link has been severed */ +#define RSI_ERROR_EADV 68 /* Advertise error */ +#define RSI_ERROR_ESRMNT 69 /* Srmount error */ +#define RSI_ERROR_ECOMM 70 /* Communication error on send */ +#define RSI_ERROR_EPROTO 71 /* Protocol error */ +#define RSI_ERROR_EMULTIHOP 72 /* Multihop attempted */ +#define RSI_ERROR_EDOTDOT 73 /* RFS specific error */ +#define RSI_ERROR_EBADMSG 74 /* Not a data message */ +#define RSI_ERROR_EOVERFLOW 75 /* Value too large for defined data type */ +#define RSI_ERROR_ENOTUNIQ 76 /* Name not unique on network */ +#define RSI_ERROR_EBADFD 77 /* File descriptor in bad state */ +#define RSI_ERROR_EREMCHG 78 /* Remote address changed */ +#define RSI_ERROR_ELIBACC 79 /* Can not access a needed shared library */ +#define RSI_ERROR_ELIBBAD 80 /* Accessing a corrupted shared library */ +#define RSI_ERROR_ELIBSCN 81 /* .lib section in a.out corrupted */ +#define RSI_ERROR_ELIBMAX 82 /* Attempting to link in too many shared libraries */ +#define RSI_ERROR_ELIBEXEC 83 /* Cannot exec a shared library directly */ +#define RSI_ERROR_EILSEQ 84 /* Illegal byte sequence */ +#define RSI_ERROR_ERESTART 85 /* Interrupted system call should be restarted */ +#define RSI_ERROR_ESTRPIPE 86 /* Streams pipe error */ +#define RSI_ERROR_EUSERS 87 /* Too many users */ +#define RSI_ERROR_ENOTSOCK 88 /* Socket operation on non-socket */ +#define RSI_ERROR_EDESTADDRREQ 89 /* Destination address required */ +#define RSI_ERROR_EMSGSIZE 90 /* Message too long */ +#define RSI_ERROR_EPROTOTYPE 91 /* Protocol wrong type for socket */ +#define RSI_ERROR_ENOPROTOOPT 92 /* Protocol not available */ +#define RSI_ERROR_EPROTONOSUPPORT 93 /* Protocol not supported */ +#define RSI_ERROR_ESOCKTNOSUPPORT 94 /* Socket type not supported */ +#define RSI_ERROR_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define RSI_ERROR_EPFNOSUPPORT 96 /* Protocol family not supported */ +#define RSI_ERROR_EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define RSI_ERROR_EADDRINUSE 98 /* Address already in use */ +#define RSI_ERROR_EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#define RSI_ERROR_ENETDOWN 100 /* Network is down */ +#define RSI_ERROR_ENETUNREACH 101 /* Network is unreachable */ +#define RSI_ERROR_ENETRESET 102 /* Network dropped connection because of reset */ +#define RSI_ERROR_ECONNABORTED 103 /* Software caused connection abort */ +#define RSI_ERROR_ECONNRESET 104 /* Connection reset by peer */ +#define RSI_ERROR_ENOBUFS 105 /* No buffer space available */ +#define RSI_ERROR_EISCONN 106 /* Transport endpoint is already connected */ +#define RSI_ERROR_ENOTCONN 107 /* Transport endpoint is not connected */ +#define RSI_ERROR_ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ +#define RSI_ERROR_ETOOMANYREFS 109 /* Too many references: cannot splice */ +#define RSI_ERROR_ETIMEDOUT 110 /* Connection timed out */ +#define RSI_ERROR_ECONNREFUSED 111 /* Connection refused */ +#define RSI_ERROR_EHOSTDOWN 112 /* Host is down */ +#define RSI_ERROR_EHOSTUNREACH 113 /* No route to host */ +#define RSI_ERROR_EALREADY 114 /* Operation already in progress */ +#define RSI_ERROR_EINPROGRESS 115 /* Operation now in progress */ +#define RSI_ERROR_ESTALE 116 /* Stale NFS file handle */ +#define RSI_ERROR_EUCLEAN 117 /* Structure needs cleaning */ +#define RSI_ERROR_ENOTNAM 118 /* Not a XENIX named type file */ +#define RSI_ERROR_ENAVAIL 119 /* No XENIX semaphores available */ +#define RSI_ERROR_EISNAM 120 /* Is a named type file */ +#define RSI_ERROR_EREMOTEIO 121 /* Remote I/O error */ +#define RSI_ERROR_EDQUOT 122 /* Quota exceeded */ +#define RSI_ERROR_ENOMEDIUM 123 /* No medium found */ +#define RSI_ERROR_EMEDIUMTYPE 124 /* Wrong medium type */ +#define RSI_ERROR_ECANCELED 125 /* Operation Canceled */ +#define RSI_ERROR_ENOKEY 126 /* Required key not available */ +#define RSI_ERROR_EKEYEXPIRED 127 /* Key has expired */ +#define RSI_ERROR_EKEYREVOKED 128 /* Key has been revoked */ +#define RSI_ERROR_EKEYREJECTED 129 /* Key was rejected by service */ +#define RSI_ERROR_EOWNERDEAD 130 /* Owner died - for robust mutexes*/ +#define RSI_ERROR_ENOTRECOVERABLE 131 /* State not recoverable */ +#define RSI_ERROR_ERFKILL 132 /* Operation not possible due to RF-kill */ + +/* List of BSD sock options from socket.h in /usr/include/asm/socket.h and asm-generic/socket.h. + The first set of socket options take the socket level (category) SOL_SOCKET. */ + +#define SOL_SOCKET 1 /* Define the socket option category. */ +#define IPPROTO_IP 2 /* Define the IP option category. */ +#define SO_MIN 1 /* Minimum Socket option ID */ +#define SO_DEBUG 1 /* Debugging information is being recorded.*/ +#define SO_REUSEADDR 2 /* Enable reuse of local addresses in the time wait state */ +#define SO_TYPE 3 /* Socket type */ +#define SO_ERROR 4 /* Socket error status */ +#define SO_DONTROUTE 5 /* Bypass normal routing */ +#define SO_BROADCAST 6 /* Transmission of broadcast messages is supported.*/ +#define SO_SNDBUF 7 /* Enable setting trasnmit buffer size */ +#define SO_RCVBUF 8 /* Enable setting receive buffer size */ +#define SO_KEEPALIVE 9 /* Connections are kept alive with periodic messages */ +#define SO_OOBINLINE 10 /* Out-of-band data is transmitted in line */ +#define SO_NO_CHECK 11 /* Disable UDP checksum */ +#define SO_PRIORITY 12 /* Set the protocol-defined priority for all packets to be sent on this socket */ +#define SO_LINGER 13 /* Socket lingers on close pending remaining send/receive packets. */ +#define SO_BSDCOMPAT 14 /* Enable BSD bug-to-bug compatibility */ +#define SO_REUSEPORT 15 /* Rebind a port already in use */ + +#ifndef SO_PASSCRED /* Used for passing credentials. Not currently in use. */ +#define SO_PASSCRED 16 /* Enable passing local user credentials */ +#define SO_PEERCRED 17 /* Obtain the process, user and group ids of the other end of the socket connection */ +#define SO_RCVLOWAT 18 /* Enable receive "low water mark" */ +#define SO_SNDLOWAT 19 /* Enable send "low water mark" */ +#define SO_RCVTIMEO 20 /* Enable receive timeout */ +#define SO_SNDTIMEO 21 /* Enable send timeout */ +#endif /* SO_PASSCRED */ +#define SO_SNDBUFFORCE 22 /* Enable setting trasnmit buffer size overriding user limit (admin privelege) */ +#define SO_RCVBUFFORCE 23 /* Enable setting trasnmit buffer size overriding user limit (admin privelege) */ +#define SO_MAX SO_RCVBUFFORCE /* Maximum Socket option ID */ +#define SO_MAXRETRY 24 /* To Enable max tcp retry count */ +#define SO_SOCK_VAP_ID 25 /* To Configure the socket VAP iD */ +#define SO_TCP_KEEP_ALIVE 26 /* To Configure the tcp keep alive */ +#define SO_SSL_ENABLE 37 /* To enable ssl */ +#define SO_HIGH_PERFORMANCE_SOCKET 38 /* To Configure the high performance socket */ +#define SO_CHECK_CONNECTED_STATE 39 /* To check for the connected state */ +#define SO_TCP_MSS 40 /* To Configure the tcp mss */ +#define SO_TCP_RETRY_TRANSMIT_TIMER 41 /* To Configure the tcp retry transmit timer */ +#define SO_SSL_V_1_0_ENABLE 42 /* To enable ssl 1.0 */ +#define SO_SSL_V_1_1_ENABLE 43 /* To enable ssl 1.1*/ +#define SO_SSL_V_1_2_ENABLE 44 /* To enable ssl 1.2*/ +#define SO_TCP_ACK_INDICATION 45 /* To enable tcp ack indication feature*/ +#define SO_CERT_INDEX 46 /* To enable set certificate index*/ +#define SO_TLS_SNI 47 /* To Configure the TLS SNI extension */ +#ifdef CHIP_9117 +#define SO_MAX_RETRANSMISSION_TIMEOUT_VAL 48 /* to configure max retransmission timeout value*/ +#define SO_SSL_V_1_3_ENABLE 49 /* To enable ssl 1.3*/ +#define SO_SSL_RECV_BUFF_SIZE 50 /* To configure SSL Data path enhancement*/ +#endif +#define MAX_RETRANSMISSION_TIME_VALUE 32 + +/* This second set of socket options take the socket level (category) IPPROTO_IP. */ +#ifdef MULTICAST_OPTIONS //! Added these multicast socket options under this define as they are not supported. +#define IP_MULTICAST_IF 27 /* Specify outgoing multicast interface */ +#define IP_MULTICAST_TTL 28 /* Specify the TTL value to use for outgoing multicast packet. */ +#define IP_MULTICAST_LOOP 29 /* Whether or not receive the outgoing multicast packet, loopbacloopbackk mode. */ +#define IP_BLOCK_SOURCE 30 /* Block multicast from certain source. */ +#define IP_UNBLOCK_SOURCE 31 /* Unblock multicast from certain source. */ +#define IP_ADD_MEMBERSHIP 32 /* Join IPv4 multicast membership */ +#define IP_DROP_MEMBERSHIP 33 /* Leave IPv4 multicast membership */ +#endif +#define IP_HDRINCL 34 /* Raw socket IPv4 header included. */ +#define IP_RAW_RX_NO_HEADER \ + 35 /* proprietary socket option that does not include + IPv4/IPv6 header (and extension headers) on received raw sockets.*/ +#define IP_RAW_IPV6_HDRINCL 36 /* Transmitted buffer over IPv6 socket contains IPv6 header. */ +#define IP_TOS 48 /* To configure TOS */ +#define IP_OPTION_MAX IP_TOS + +/* + * User-settable options (used with setsockopt). + */ +#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ +#define TCP_MAXSEG 0x02 /* set maximum segment size */ +#define TCP_NOPUSH 0x04 /* don't push last block of write */ +#define TCP_NOOPT 0x08 /* don't use TCP options */ + +#define RSI_TLS_SNI 1 + +#define RSI_SOCKET_TCP_CLIENT 0x0000 +#define RSI_SOCKET_UDP_CLIENT 0x0001 +#define RSI_SOCKET_TCP_SERVER 0x0002 +#define RSI_SOCKET_LUDP 0x0004 + +#define RSI_NULL NULL +#define RSI_IPV4_ADDRESS_LENGTH 4 +#define RSI_IPV6_ADDRESS_LENGTH 16 + +#define RSI_SOCK_ERROR -1 +// send Defines + +// UDP Frame header is 42 bytes, padding bytes are extra +#define RSI_UDP_FRAME_HEADER_LEN 44 + +// TCP Frame header is 54 bytes, padding bytes are extra +#define RSI_TCP_FRAME_HEADER_LEN 56 + +// Frame header is 42 bytes, padding bytes are extra +#define RSI_UDP_V6_FRAME_HEADER_LEN 64 + +// TCP Frame header is 54 bytes, padding bytes are extra +#define RSI_TCP_V6_FRAME_HEADER_LEN 76 + +/****************************************************** + * * Constants + * ******************************************************/ + +/****************************************************** + * * Enumerations + * ******************************************************/ +typedef enum rsi_ip_version_e { RSI_IP_VERSION_4 = 4, RSI_IP_VERSION_6 = 6 } rsi_ip_version_t; + +typedef enum rsi_ip_config_mode_e { + RSI_STATIC = 0, + RSI_DHCP, + RSI_DHCP_RESERVED, + RSI_DHCP_HOSTNAME, + RSI_DHCP_OPTION81, + RSI_DHCP_OPTION77 +} rsi_ip_config_mode_t; +typedef enum rsi_socket_state_e { + RSI_SOCKET_STATE_INIT = 0, + RSI_SOCKET_STATE_CREATE, + RSI_SOCKET_STATE_BIND, + RSI_SOCKET_STATE_LISTEN, + RSI_SOCKET_STATE_CONNECTED +} rsi_socket_state_t; + +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +typedef unsigned long rsi_time_t; + +typedef unsigned long rsi_suseconds_t; + +typedef uint32_t rsi_socklen_t; + +struct rsi_timeval { + rsi_time_t tv_sec; /* Seconds */ + rsi_suseconds_t tv_usec; /* Microseconds */ +}; + +struct rsi_sockaddr { + uint16_t sa_family; /* Address family (e.g. , AF_INET). */ + uint8_t sa_data[14]; /* Protocol- specific address information. */ +}; + +struct rsi_in6_addr { + union { + uint8_t _S6_u8[16]; + uint32_t _S6_u32[4]; + } _S6_un; +}; + +#ifndef s6_addr +#define s6_addr _S6_un._S6_u8 +#endif + +#ifndef s6_addr32 +#define s6_addr32 _S6_un._S6_u32 +#endif + +struct rsi_sockaddr_in6 { + uint16_t sin6_family; /* AF_INET6 */ + uint16_t sin6_port; /* Transport layer port. */ + uint32_t sin6_flowinfo; /* IPv6 flow information. */ + struct rsi_in6_addr sin6_addr; /* IPv6 address. */ + uint32_t sin6_scope_id; /* set of interafces for a scope. */ +}; + +/* Internet address (a structure for historical reasons). */ + +struct rsi_in_addr { + uint32_t s_addr; /* Internet address (32 bits). */ +}; + +#define in_addr_t uint32_t + +/* Socket address, Internet style. */ + +struct rsi_sockaddr_in { + uint16_t sin_family; /* Internet Protocol (AF_INET). */ + uint16_t sin_port; /* Address port (16 bits). */ + struct rsi_in_addr sin_addr; /* Internet address (32 bits). */ + int8_t sin_zero[8]; /* Not used. */ +}; + +typedef struct + rsi_fd_set_s /* The select socket array manager. */ +{ + uint32_t fd_array[(FD_SETSIZE + 31) + / 32]; /* Bit map of SOCKET Descriptors. */ + int32_t fd_count; /* How many are SET? */ +} rsi_fd_set; + +typedef struct BSD_SOCKET_SUSPEND_STRUCT { + uint32_t bsd_socket_suspend_actual_flags; + rsi_fd_set bsd_socket_suspend_read_fd_set; + rsi_fd_set bsd_socket_suspend_write_fd_set; + rsi_fd_set bsd_socket_suspend_exception_fd_set; + +} RSI_BSD_SOCKET_SUSPEND; + +struct rsi_ip_mreq { + struct rsi_in_addr imr_multiaddr; /* The IPv4 multicast address to join. */ + struct rsi_in_addr imr_interface; /* The interface to use for this group. */ +}; + +/* Define additional BSD data structures for supporting socket options. */ + +struct rsi_sock_errno { + int32_t error; /* default = 0; */ +}; + +struct rsi_linger { + int32_t l_onoff; /* 0 = disabled; 1 = enabled; default = 0;*/ + int32_t l_linger; /* linger time in seconds; default = 0;*/ +}; + +struct rsi_sock_keepalive { + int32_t keepalive_enabled; /* 0 = disabled; 1 = enabled; default = 0;*/ +}; + +struct rsi_sock_reuseaddr { + int32_t reuseaddr_enabled; /* 0 = disabled; 1 = enabled; default = 1; */ +}; + +struct rsi_sock_winsize { + int32_t winsize; /* receive window size for TCP sockets ; */ +}; + +typedef union rsi_ip_addr_u { + uint8_t ipv4[4]; + uint8_t ipv6[16]; +} rsi_ip_addr_t; + +typedef struct rsi_socket_info_s { + // socket ID + uint8_t sock_id; + + // socket state + volatile uint8_t sock_state; + + // socket type + uint8_t sock_type; + + // opcode used in websocket + uint8_t opcode; + + // Local port number + uint16_t source_port; + + // Destination port number + uint16_t destination_port; + + // Destination IP address + rsi_ip_addr_t destination_ip_addr; + + // LTCP master socket + uint8_t ltcp_socket_type; + + // Total backlogs + uint8_t backlogs; + + // Current backlog count + uint8_t backlog_current_count; + + // Socket bitmap + uint8_t sock_bitmap; + + // socket recieve buffer + uint8_t *sock_recv_buffer; + + // Socket receive buffer offset + uint32_t sock_recv_buffer_offset; + + // Socket receive available length + uint32_t sock_recv_available_length; + //#else + // Application receive buffer + uint8_t *recv_buffer; + + // Application receive length + uint32_t recv_buffer_length; + //#endif + + uint8_t max_available_buffer_count; + + uint8_t current_available_buffer_count; + + uint8_t rx_window_buffers; + + uint8_t socket_cert_inx; + + // Socket recieve callback + void (*sock_receive_callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length); + + uint16_t read_time_out; + +} rsi_socket_info_t; + +typedef struct socket_config_s { + // TCP TX + TCP RX + UDP TX + UDP RX + uint8_t total_sockets; + + // TCP TX + TCP RX + uint8_t total_tcp_sockets; + + // UDP TX + UDP RX + uint8_t total_udp_sockets; + + // TCP TX + uint8_t tcp_tx_only_sockets; + + // TCP RX + uint8_t tcp_rx_only_sockets; + + // UDP TX + uint8_t udp_tx_only_sockets; + + // UDP RX + uint8_t udp_rx_only_sockets; + + // TCP RX High Performance + uint8_t tcp_rx_high_performance_sockets; + + // TCP RX WIndows cap + uint8_t tcp_rx_window_size_cap; + + // TCP RX WIndows cap + uint8_t tcp_rx_window_div_factor; +} rsi_socket_config_t; + +extern rsi_socket_info_t *rsi_socket_pool; + +// Socket information pool pointer +extern rsi_socket_info_t *rsi_socket_pool; + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_socket(int32_t protocolFamily, int32_t type, int32_t protocol); +int32_t rsi_bind(int32_t sockID, struct rsi_sockaddr *localAddress, int32_t addressLength); +int32_t rsi_connect(int32_t sockID, struct rsi_sockaddr *remoteAddress, int32_t addressLength); +int32_t rsi_listen(int32_t sockID, int32_t backlog); +int32_t rsi_accept(int32_t sockID, struct rsi_sockaddr *ClientAddress, int32_t *addressLength); +int32_t rsi_recvfrom(int32_t sockID, + int8_t *buffer, + int32_t buffersize, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen); +int32_t rsi_recv(int32_t sockID, void *rcvBuffer, int32_t bufferLength, int32_t flags); +int32_t rsi_sendto(int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen); +int32_t rsi_send(int32_t sockID, const int8_t *msg, int32_t msgLength, int32_t flags); +int32_t rsi_send_large_data_async(int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*rsi_sock_data_tx_done_cb)(int32_t sockID, + int16_t status, + uint16_t total_data_sent)); +int32_t rsi_select(int32_t nfds, + rsi_fd_set *readfds, + rsi_fd_set *writefds, + rsi_fd_set *exceptfds, + struct rsi_timeval *timeout, + void (*callback)(rsi_fd_set *fd_read, rsi_fd_set *fd_write, rsi_fd_set *fd_except, int32_t status)); +int32_t rsi_shutdown(int32_t sockID, int32_t how); +int32_t rsi_socket_async(int32_t protocolFamily, + int32_t type, + int32_t protocol, + void (*)(uint32_t sock_no, uint8_t *buffer, uint32_t length)); +int32_t rsi_config_ipaddress(rsi_ip_version_t version, + uint8_t mode, + uint8_t *ip_addr, + uint8_t *mask, + uint8_t *gw, + uint8_t *ipconfig_rsp, + uint16_t length, + uint8_t vap_id); +int32_t rsi_check_state(int32_t type); +int32_t rsi_socket_create(int32_t sockID, int32_t type, int32_t backlog); +int32_t rsi_get_application_socket_descriptor(int32_t sock_id); +void rsi_clear_sockets(int32_t sockID); +uint8_t calculate_buffers_required(uint8_t type, uint16_t length); +uint16_t calculate_length_to_send(uint8_t type, uint8_t buffers); +int32_t rsi_send_async(int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*data_transfer_complete_handler)(int32_t sockID, const uint16_t length)); +int32_t rsi_sendto_async(int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen, + void (*data_transfer_complete_handler)(int32_t sockID, const uint16_t length)); +int rsi_setsockopt(int32_t sockID, int level, int option_name, const void *option_value, rsi_socklen_t option_len); +int32_t rsi_get_app_socket_descriptor(uint8_t *src_port); +int32_t rsi_get_primary_socket_id(uint8_t *port_number); +int rsi_fd_isset(uint32_t fd, struct rsi_fd_set_s *fds_p); +void rsi_set_fd(uint32_t fd, struct rsi_fd_set_s *fds_p); +void rsi_fd_clr(uint32_t fd, struct rsi_fd_set_s *fds_p); +void rsi_reset_per_socket_info(int32_t sockID); +void rsi_chunk_data_tx_done_cb(int32_t sockID, const uint16_t length); +uint32_t rsi_find_socket_data_pending(uint32_t event_map); +int rsi_fill_tls_extension(int32_t sockID, int extension_type, const void *option_value, rsi_socklen_t extension_len); +int32_t rsi_accept_async(int32_t sockID, + void (*callback)(int32_t sock_id, int16_t dest_port, uint8_t *ip_addr, int16_t ip_version)); +int32_t rsi_certificate_valid(uint16_t valid, uint16_t socket_id); +#endif diff --git a/wiseconnect/sapi/include/rsi_spi_cmd.h b/wiseconnect/sapi/include/rsi_spi_cmd.h new file mode 100644 index 00000000..b128be6c --- /dev/null +++ b/wiseconnect/sapi/include/rsi_spi_cmd.h @@ -0,0 +1,260 @@ +/******************************************************************************* +* @file rsi_spi_cmd.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef _SPICMDAPI_H_ +#define _SPICMDAPI_H_ + +/****************************************************** + * * Macros + * ******************************************************/ +//C1 Register Bit Field Defines +#define RSI_C1_INIT_CMD 0x15 +// sent to spi interface after reset/powerup to init the spi interface + +//STM 32 Init Sequence +#define RSI_RS9116_INIT_CMD 0x005c4a12 + +#define RSI_C1_INIT_RESP 0x55 +// response from spi interface to successful init + +#define RSI_C176_INIT 0b00111111 //@ and +#define RSI_C176_RW 0b01000000 //@ or +#define RSI_C15_RD 0b11011111 //@ and +#define RSI_C15_WR 0b00100000 //@ or +#define RSI_C14_SPISLV 0b11101111 //@ and +#define RSI_C14_AHBBUS 0b00010000 //@ or +#define RSI_C13_AHBMEM 0b11110111 //@ and +#define RSI_C13_AHBFRM 0b00001000 //@ or +#define RSI_C12_02BITXFR 0b11111011 //@ and +#define RSI_C12_16BITXFR 0b00000100 //@ or +#define RSI_C110_4BYTESLEN 0b11111100 +// and number of C bytes transferred, usually 4 +#define RSI_C110_1BYTESLEN 0b00000001 +// or/~and number of C bytes transferred +#define RSI_C110_2BYTESLEN 0b00000010 +// or/~and number of C bytes transferred +#define RSI_C110_3BYTESLEN 0b00000011 +// or number of C bytes transferred + +/*=========================================================*/ +// C2 Register Defines +#define RSI_C276_08BIT 0b00111111 //@ and +#define RSI_C276_32BIT 0b01000000 //@ or +#define RSI_C250_SPIADDR 0b00111111 //@ and +#define RSI_C250_DATAPACKET 0b00000010 //@ or +#define RSI_C250_MGMTPACKET 0b00000100 //@ or + +//#define RSI_C3_XFERLENLSB 0x00 //@ set value +//#define RSI_C4_XFERLENMSB 0x00 //@ set value + +/*==========================================================*/ +// C1 Register Defines +// Internal Read +#define RSI_C1INTREAD2BYTES 0x42 +// (((((0x00 & C176_INT) & C15_RD) & C14_SPISLV) & C13_AHBMEM) & C12_02BITXFR) | C110_2BYTESLEN // 01000010 +#define RSI_C1INTREAD1BYTES 0x41 + +// Memory ReadWrite (AHB Master Read/Write, Internal Legacy Name) +// Memory read/write is normally done using 16-bit transfer length with 4 C bytes transferred +#define RSI_C1MEMWR16BIT1BYTE 0x75 +// (((0x00 | C176_RW | C15_WR | C14_AHBBUS) & C13_AHBMEM) & C12_16BITXFR) | C110_1BYTESLEN // 01110101 +#define RSI_C1MEMRD16BIT1BYTE 0x55 +// (((0x00 | C176_RW & C15_RD | C14_AHBBUS) & C13_AHBMEM) & C12_16BITXFR) | C110_1BYTESLEN // 01010101 + +#define RSI_C1MEMWR16BIT4BYTE 0x74 +// (((0x00 | C176_RW | C15_WR | C14_AHBBUS) & C13_AHBMEM) & C12_16BITXFR) & C110_4BYTESLEN // 01110100 +#define RSI_C1MEMRD16BIT4BYTE 0x54 +// ((((0x00 | C176_RW & C15_RD) | C14_AHBBUS) & C13_AHBMEM) & C12_16BITXFR) & C110_4BYTESLEN // 01010100 + +// Normally, 2-bit transfer length is not used for memory read/write +#define RSI_C1MEMWR02BIT1BYTE 0x71 +// (((0x00 | C176_RW | C15_WR | C14_AHBBUS) & C13_AHBMEM) & C12_02BITXFR) | C110_1BYTESLEN // 01110001 +#define RSI_C1MEMRD02BIT1BYTE 0x51 +// (((0x00 | C176_RW & C15_RD | C14_AHBBUS) & C13_AHBMEM) & C12_02BITXFR) | C110_1BYTESLEN // 01010001 +#define RSI_C1MEMWR02BIT4BYTE 0x70 +// (((0x00 | C176_RW | C15_WR | C14_AHBBUS) & C13_AHBMEM) & C12_02BITXFR) & C110_4BYTESLEN // 01110000 +#define RSI_C1MEMRD02BIT4BYTE 0x50 +// ((((0x00 | C176_RW & C15_RD) | C14_AHBBUS) & C13_AHBMEM) & C12_02BITXFR) & C110_4BYTESLEN // 01010000 + +// Frame ReadWrite +// Frame read/writes normally use 16-bit transfer length +#define RSI_C1FRMWR16BIT1BYTE 0x7d +// ((C176_RW | C15_WR | C14_AHBBUS | C13_AHBFRM) & C12_16BITXFR) | C110_1BYTESLEN // 01111101 +#define RSI_C1FRMRD16BIT1BYTE 0x5d +// ((C176_RW & C15_RD | C14_AHBBUS | C13_AHBFRM) & C12_16BITXFR) | C110_1BYTESLEN // 01011101 + +#define RSI_C1FRMWR16BIT4BYTE 0x7c +// ((C176_RW | C15_WR | C14_AHBBUS | C13_AHBFRM) & C12_16BITXFR) | C110_4BYTESLEN // 01111100 +#define RSI_C1FRMRD16BIT4BYTE 0x5c +// ((C176_RW & C15_RD | C14_AHBBUS | C13_AHBFRM) & C12_16BITXFR) | C110_4BYTESLEN // 01011100 + +// Frame read/writes normally do not use 2-bit transfer length +#define RSI_C1FRMWR02BIT1BYTE 0x79 +// ((C176_RW | C15_WR | C14_AHBBUS | C13_AHBFRM) & C12_02BITXFR) | C110_1BYTESLEN // 01111001 +#define RSI_C1FRMRD02BIT1BYTE 0x59 +// ((C176_RW & C15_RD | C14_AHBBUS | C13_AHBFRM) & C12_02BITXFR) | C110_1BYTESLEN // 01011001 + +#define RSI_C1FRMWR02BIT4BYTE 0x78 +// ((C176_RW | C15_WR | C14_AHBBUS | C13_AHBFRM) & C12_02BITXFR) | C110_4BYTESLEN // 01111000 +#define RSI_C1FRMRD02BIT4BYTE 0x58 +// ((C176_RW & C15_RD | C14_AHBBUS | C13_AHBFRM) & C12_02BITXFR) | C110_4BYTESLEN // 01011000 + +// SPI Register ReadWrite +#define RSI_C1SPIREGWR16BIT4BYTE 0x64 +// ((((C176_RW | C15_WR) & C14_SPISLV) & C13_AHBMEM) & C12_16BITXFR) | C110_4BYTESLEN // 01100100 +#define RSI_C1SPIREGRD16BIT4BYTE 0x44 +// ((((C176_RW & C15_RD) & C14_SPISLV) & C13_AHBMEM) & C12_16BITXFR) | C110_4BYTESLEN // 01000100 + +#define RSI_C1SPIREGWR02BIT4BYTE 0x60 +// ((((C176_RW | C15_WR) & C14_SPISLV) & C13_AHBMEM) & C12_02BITXFR) | C110_4BYTESLEN // 01100000 +#define RSI_C1SPIREGRD02BIT4BYTE 0x40 +// ((((C176_RW & C15_RD) & C14_SPISLV) & C13_AHBMEM) & C12_02BITXFR) | C110_4BYTESLEN // 01000000 + +#define RSI_C1SPIREGWR02BIT1BYTE 0x61 +// ((((C176_RW | C15_WR) & C14_SPISLV) & C13_AHBMEM) & C12_02BITXFR) | C110_1BYTESLEN // 01100001 +#define RSI_C1SPIREGRD02BIT1BYTE 0x41 +// ((((C176_RW & C15_RD) & C14_SPISLV) & C13_AHBMEM) & C12_02BITXFR) | C110_1BYTESLEN // 01000001 + +//C2 Register Defines +#define RSI_C2RDWR4BYTE 0x40 //@ 0x00 | C276_32BIT | C250_DATAPACKET // 01000010 +#define RSI_C2RDWR4BYTE 0x40 //@ 0x00 | C276_32BIT | C250_MGMTPACKET // 01000100 + +#define RSI_C2RDWR1BYTE 0x00 //@ (0x00 & C276_08BIT) | C250_DATAPACKET // 00000010 +#define RSI_C2RDWR1BYTE 0x00 //@ (0x00 & C276_08BIT) | C250_MGMTPACKET +//@ 00000100 +#define RSI_C2MGMT 0x04 +#define RSI_C2DATA 0x02 +#define RSI_C2WPS 0x08 + +#define RSI_C2SPIADDR1BYTE 0x00 //@(0x00 & C276_08BIT) | C250_SPIADDR // 00xxxxxx +#define RSI_C2MEMRDWRNOCARE 0x00 //@0x00 or ANYTHING // 00000000 +#define RSI_C2SPIADDR4BYTE 0x40 //@(0x00 | C276_32BIT) | C250_SPIADDR // 01xxxxxx + +#define RSI_C1INTWRITE1BYTES 0x61 +#define RSI_C1INTWRITE2BYTES 0x62 + +/*====================================================*/ +// Constant Defines +// SPI Status + +// SPI success +#define RSI_SPI_SUCCESS 0x58 + +// SPI busy error +#define RSI_SPI_BUSY 0x54 + +// SPI fail +#define RSI_SPI_FAIL 0x52 + +// SPI return codes +#define RSI_SUCCESS 0 + +// module buffer full error code +#define RSI_ERROR_BUFFER_FULL -3 + +// module in sleep error code +#define RSI_ERROR_IN_SLEEP -4 + +// SPI communication + +// SPI Start Token +#define RSI_SPI_START_TOKEN 0x55 + +// SPI Internal Register Offset + +// register access method +#define RSI_SPI_INT_REG_ADDR 0x00 + +// register access method +#define RSI_SPI_MODE_REG_ADDR 0x08 + +// Interrupt mask register +#define RSI_INT_MASK_REG_ADDR 0x41050000 + +// Interrupt clear register +#define RSI_INT_CLR_REG_ADDR 0x22000010 + +//SPI Mode Register +#define RSI_SPI_MODE_LOW 0x00 +#define RSI_SPI_MODE_HIGH 0x01 + +#ifndef RSI_HWTIMER +//approximate ticks for timeout implementation +#define RSI_INC_TIMER_2 rsi_driver_cb_non_rom->rsi_spiTimer2++ +#define RSI_INC_TIMER_1 rsi_driver_cb_non_rom->rsi_spiTimer1++ +#define RSI_INC_TIMER_3 rsi_driver_cb_non_rom->rsi_spiTimer3++ +#define RSI_INC_TIMER_4 rsi_driver_cb_non_rom->rsi_spiTimer4++ +#define RSI_RESET_TIMER1 rsi_driver_cb_non_rom->rsi_spiTimer1 = 0 +#define RSI_RESET_TIMER2 rsi_driver_cb_non_rom->rsi_spiTimer2 = 0 +#define RSI_RESET_TIMER3 rsi_driver_cb_non_rom->rsi_spiTimer3 = 0 +#define RSI_RESET_TIMER4 rsi_driver_cb_non_rom->rsi_spiTimer4 = 0 +#else +#define RSI_INC_TIMER_3 rsi_driver_cb_non_rom->rsi_spiTimer3 +#define RSI_INC_TIMER_2 rsi_driver_cb_non_rom->rsi_spiTimer2 +#define RSI_INC_TIMER_1 rsi_driver_cb_non_rom->rsi_spiTimer1 +#define RSI_INC_TIMER_4 rsi_driver_cb_non_rom->rsi_spiTimer4 +#define RSI_RESET_TIMER1 rsi_driver_cb_non_rom->rsi_spiTimer1 = 0 +#define RSI_RESET_TIMER2 rsi_driver_cb_non_rom->rsi_spiTimer2 = 0 +#define RSI_RESET_TIMER3 rsi_driver_cb_non_rom->rsi_spiTimer3 = 0 +#define RSI_RESET_TIMER4 rsi_driver_cb_non_rom->rsi_spiTimer4 = 0 +void rsi_timer_interrupt_handler(void); +#endif + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +int16_t rsi_send_c1c2(uint8_t c1, uint8_t c2); +int16_t rsi_send_c3c4(uint8_t c3, uint8_t c4); +int16_t rsi_spi_wait_start_token(uint32_t timeout, uint8_t mode); +int16_t rsi_clear_interrupt(uint8_t interruptClear); +int16_t rsi_mem_wr(uint32_t addr, uint16_t len, uint8_t *dBuf); +int16_t rsi_mem_rd(uint32_t addr, uint16_t len, uint8_t *dBuf); +int16_t rsi_reg_rd(uint8_t regAddr, uint8_t *dBuf); +int16_t rsi_reg_rd2(uint8_t regAddr, uint16_t *dBuf); +int16_t rsi_reg_wr(uint8_t regAddr, uint8_t *dBuf); +int16_t rsi_pre_dsc_rd(uint8_t *dbuf); +int16_t rsi_pkt_rd(uint8_t *pkt, uint16_t dummy_len, uint16_t total_len); +int16_t rsi_set_intr_mask(uint8_t interruptMask); +int16_t rsi_spi_iface_init(void); +void rsi_ulp_wakeup_init(void); +int16_t rsi_device_interrupt_status(uint8_t *int_status); +int16_t rsi_spi_high_speed_enable(void); +int16_t rsi_set_intr_type(uint32_t interruptMaskVal); +int16_t rsi_spi_pkt_len(uint16_t *length); +uint8_t rsi_get_intr_status(void); +#endif diff --git a/wiseconnect/sapi/include/rsi_spi_intf.h b/wiseconnect/sapi/include/rsi_spi_intf.h new file mode 100644 index 00000000..61de1406 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_spi_intf.h @@ -0,0 +1,190 @@ +/******************************************************************************* +* @file rsi_spi_intf.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_INTERFACE_H +#define RSI_INTERFACE_H + +#ifndef EFM32_SDIO // This file is not needed for EFM32 board. In order to avoid compilation warnings, we excluded the below code for EFM32 +#include "rsi_board_configuration.h" +#endif + +/****************************************************** + * * Macros + * ******************************************************/ + +// buffer full indication register value from module +#define RSI_BUFFER_FULL 0x01 + +// buffer empty indication register value from module +#define RSI_BUFFER_EMPTY 0x02 + +// RX packet pending register value from module +#define RSI_RX_PKT_PENDING 0x08 + +// Assertion Interrupt indication from module +#define RSI_ASSERT_INTR 0x80 // BIT(7) + +#define RSI_POWER_SAVE 0x08 + +// offset of status in host descriptor +#define RSI_STATUS_OFFSET 12 + +// offset of status in host descriptor +#define RSI_TWOBYTE_STATUS_OFFSET 12 + +// offset of response type in host descriptor +#define RSI_RSP_TYPE_OFFSET 2 + +#ifndef RSI_HWTIMER +// need to define this macro if h/w timer is available +// and it should increment spiTimer2, spiTimer1 +#define RSI_TICKS_PER_SECOND 50000 +#else +#define RSI_TICKS_PER_SECOND 10 +#endif + +// SPI transfer type (8 BIT/32 BIT) +#define RSI_MODE_8BIT 0 +#define RSI_MODE_32BIT 1 + +/*@ firmware upgradation timeout */ +#define RSI_FWUPTIMEOUT 100 * RSI_TICKS_PER_SECOND +/*@ wireless firmware upgradation timeout */ +#define RSI_WIRELESSFWUPTIMEOUT 500 * RSI_TICKS_PER_SECOND +/*@ bootloading timeout */ +#define RSI_BLTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ band timeout */ +#define RSI_BANDTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Init timeout */ +#define RSI_INITTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Query firmware version timeout */ +#define RSI_QFWVTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Set Mac address timeout */ +#define RSI_SMATIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Scan timeout */ +#define RSI_SCANTIMEOUT 12 * RSI_TICKS_PER_SECOND +/*@ Sleep timer timeout */ +#define RSI_SLEEPTIMERTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Wepkeys timeout */ +#define RSI_WEPKEYSTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Join timeout */ +#define RSI_JOINTIMEOUT 12 * RSI_TICKS_PER_SECOND +/*@ Disconnect timeout */ +#define RSI_DISCONTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Query connection status timeout */ +#define RSI_QCSTIMEOUT 3 * RSI_TICKS_PER_SECOND +/*@ Query dhcp params timeout */ +#define RSI_QDPTIMEOUT 3 * RSI_TICKS_PER_SECOND +/*@ Query network params timeout */ +#define RSI_QNPTIMEOUT 3 * RSI_TICKS_PER_SECOND +/*@ Ip configuration timeout */ +#define RSI_IPPTIMEOUT 6 * RSI_TICKS_PER_SECOND +/*@ Query RSSI Value timeout */ +#define RSI_RSSITIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ recv timeout */ +#define RSI_RECVTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Socket open timeout */ +#define RSI_SOPTIMEOUT 6 * RSI_TICKS_PER_SECOND +/*@ Regread timeout */ +#define RSI_REGREADTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Query DNS timeout */ +#define RSI_QDNSTIMEOUT 6 * RSI_TICKS_PER_SECOND +/*@ Start token timeout */ +#define RSI_START_TOKEN_TIMEOUT 10 * RSI_TICKS_PER_SECOND +/*@ Set Listen interval timeout */ +#define RSI_SLITIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Config Enable timeout */ +#define RSI_CETIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Config store timeout */ +#define RSI_CSTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Config get timeout */ +#define RSI_CGTIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Query BSSID/NW TYPE timeout */ +#define RSI_QBSSIDNWTIMEOUT 6 * RSI_TICKS_PER_SECOND +#define RSI_QMACADDTIMEOUT 6 * RSI_TICKS_PER_SECOND +/*@ Query MAC ADDR timeout */ +/*@ Get HTTP timeout */ +#define RSI_GETHTTPTIMEOUT 40 * RSI_TICKS_PER_SECOND +/*@ Post HTTP timeout */ +#define RSI_POSTHTTPTIMEOUT 6 * RSI_TICKS_PER_SECOND +/*@ Mode select timeout */ +#define RSI_MODESEL_TIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ Feature select timeout */ +#define RSI_FEATSEL_TIMEOUT 1 * RSI_TICKS_PER_SECOND +/*@ WPS RESPONSE timeout */ +#define RSI_WPSRSPTIMEOUT 120 * RSI_TICKS_PER_SECOND +/*@ Power save timeout*/ +#define RSI_PWSAVE_TIMEOUT 5 * RSI_TICKS_PER_SECOND +/*@ Command response timeout */ +#define RSI_RESPONSE_TIMEOUT(A) \ + RSI_RESET_TIMER3; \ + while (rsi_check_pkt_irq() != RSI_TRUE) { \ + if (RSI_INC_TIMER_3 > A) { \ + retval = -1; \ + break; \ + } \ + } + +#define RSI_BYTES_3 3 +#define RSI_BYTES_2 2 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +#ifdef RSI_SPI_INTERFACE +//! host descriptor structure +typedef struct rsi_frame_desc_s { + // Data frame body length. Bits 14:12=queue, 000 for data, Bits 11:0 are the length + uint8_t frame_len_queue_no[2]; + // Frame type + uint8_t frame_type; + // Unused , set to 0x00 + uint8_t reserved[9]; + // Management frame descriptor response status, 0x00=success, else error + uint8_t status; + + uint8_t reserved1[3]; +} rsi_frame_desc_t; +#endif +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +extern uint32_t rsi_spiTimer1, rsi_spiTimer2, rsi_spiTimer3; +/****************************************************** + * * Function Declarations + * ******************************************************/ +extern int16_t rsi_module_power_cycle(void); +extern void rsi_build_frame_descriptor(rsi_frame_desc_t *uFrameDscFrame, uint8_t *cmd); +extern int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param); +extern int16_t rsi_frame_read(uint8_t *pkt_buffer); +extern int16_t rsi_spi_frame_dsc_wr(rsi_frame_desc_t *uFrameDscFrame); +extern int16_t rsi_spi_frame_data_wr(uint16_t bufLen, uint8_t *dBuf, uint16_t tbufLen, uint8_t *tBuf); +#endif diff --git a/wiseconnect/sapi/include/rsi_timer.h b/wiseconnect/sapi/include/rsi_timer.h new file mode 100644 index 00000000..38ce2c35 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_timer.h @@ -0,0 +1,58 @@ +/******************************************************************************* +* @file rsi_timer.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_TIMER_H +#define RSI_TIMER_H +/****************************************************** + * * Macros + * ******************************************************/ +#define RSI_TIMER_NODE_0 0 +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +typedef struct rsi_timer_instance_s { + uint32_t start_time; + uint32_t timeout; +} rsi_timer_instance_t; +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +void rsi_timer_expiry_interrupt_handler(void); +uint32_t rsi_timer_read_counter(void); +uint32_t rsi_hal_gettickcount(void); +void rsi_init_timer(rsi_timer_instance_t *rsi_timer, uint32_t duration); +int32_t rsi_timer_expired(rsi_timer_instance_t *timer); +uint32_t rsi_timer_left(rsi_timer_instance_t *timer); + +#endif diff --git a/wiseconnect/sapi/include/rsi_uart.h b/wiseconnect/sapi/include/rsi_uart.h new file mode 100644 index 00000000..86220636 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_uart.h @@ -0,0 +1,162 @@ +/******************************************************************************* +* @file rsi_uart.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_M4_INTERFACE + +#ifndef _RSI_UART_H +#define _RSI_UART_H +#include +#ifdef WISECONNECT +#ifdef RSI_WLAN_API_ENABLE +#include +#endif +#elif defined(RSI_WLAN_ENABLE) +#include +#endif +#include +#include +#include +#ifdef LINUX_PLATFORM +#include +#include "rsi_linux_app_init.h" +#endif +/****************************************************** + * * Macros + * ******************************************************/ +#if defined(LINUX_PLATFORM) +// UART device port +#define RSI_UART_DEVICE "/dev/ttyUSB0" +#elif defined(WINDOWS) +#define RSI_UART_DEVICE "\\\\.\\COM97" +#else +#ifndef EFM32_SDIO // This file is not needed for EFM32 board. In order to avoid compilation warnings, we excluded the below code for EFM32 +#include "rsi_board_configuration.h" +#endif +#endif + +// UART Baud rate to be set +#define BAUDRATE B115200 +//#define BAUDRATE B921600 + +// Pre descriptor length +#define RSI_PRE_DESC_LEN 4 + +// Enable UART hardware flow control 0 - disable, 1- Enable +#define UART_HW_FLOW_CONTROL 0 + +// Frame decriptor length +#define RSI_FRAME_DESC_LEN 16 + +// Skip card ready if in UART mode +#define RSI_SKIP_CARD_READY 1 + +// UART device or USB-CDC device +#define RSI_USB_CDC_DEVICE 0 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +// RX Progrss States +typedef enum rsi_uart_rx_state_e { + // 0 - IDLE state + RSI_UART_IDLE_STATE = 0, + + // Pre descriptor receive state + RSI_UART_LEN_DESC_RECV_STATE, + + // Host descriptor receive state + RSI_UART_WAIT_FOR_HOST_DESC_STATE, + + // Payload receive state + RSI_UART_PAYLOAD_RECV_STATE +} rsi_uart_rx_state_t; + +extern uint32_t desired_len; +extern uint8_t uart_rev_buf[1600]; + +// host descriptor structure +typedef struct rsi_frame_desc_s { + // Data frame body length. Bits 14:12=queue, 000 for data, Bits 11:0 are the length + uint8_t frame_len_queue_no[2]; + // Frame type + uint8_t frame_type; + // Unused , set to 0x00 + uint8_t reserved[9]; + // Management frame descriptor response status, 0x00=success, else error + uint8_t status; + uint8_t reserved1[3]; +} rsi_frame_desc_t; + +typedef struct rsi_linux_app_cb_s { + + // RX receive state + rsi_uart_rx_state_t rx_is_in_progress; + + // RX packet allocated + rsi_pkt_t *rcvPktPtr; + + // Uart file descriptor + int32_t ttyfd; + + // Pre descriptor read + uint8_t pre_desc_buf[RSI_PRE_DESC_LEN]; + + // byte count of received bytes + uint16_t byte_count; + + // payload size of the packet + uint16_t payload_size; + + // recv queue + rsi_queue_cb_t rcv_queue; +#ifdef LINUX_PLATFORM + // mutex + pthread_mutex_t mutex1; +#endif +} rsi_linux_app_cb_t; + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +extern rsi_linux_app_cb_t rsi_linux_app_cb; +extern int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param); +extern int16_t rsi_frame_read(uint8_t *pkt_buffer); +extern int16_t rsi_uart_send(uint8_t *ptrBuf, uint16_t bufLen); +extern int16_t rsi_uart_recv(uint8_t *ptrBuf, uint16_t bufLen); +extern int16_t rsi_serial_init(void); +extern uint8_t rsi_uart_byte_read(void); +extern uint8_t rsi_serial_fifo_status(void); +extern int32_t rsi_uart_init(void); +extern void rsi_enter_critical_sec(void); +extern void rsi_exit_critical_sec(void); +extern void rsi_platform_based_init(void); +extern int32_t rsi_uart_deinit(void); +#endif + +#endif diff --git a/wiseconnect/sapi/include/rsi_user.h b/wiseconnect/sapi/include/rsi_user.h new file mode 100644 index 00000000..d0da0a94 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_user.h @@ -0,0 +1,135 @@ +/******************************************************************************* +* @file rsi_user.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_USER_H +#define RSI_USER_H +/****************************************************** + * * Macros + * ******************************************************/ + +// Silicon Version 1.3 +#define CHIP_VER_1P3 0 + +// Silicon Version 1.4 and above +#define CHIP_VER_1P4_AND_ABOVE 1 + +// To selcet Silicon version, select either of one from among two macros +#define RS9116_SILICON_CHIP_VER \ + CHIP_VER_1P4_AND_ABOVE // Set 1 for Silicon Chip Version 1p4 and Above, 0 for Silicon Chip Version 1p3 + +// For TASK Notify +#define RSI_TASK_NOTIFY 0 + +#define WIFI_INTERNAL_TIMEOUT_SF 1 +#define WIFI_WAIT_TIMEOUT_SF 1 +#define WIFI_BLOCKED_TIMEOUT_SF 1 +#define TX_WAIT_TIME 0 + +#define BT_WAIT_TIMEOUT_SF 1 +#define BLE_WAIT_TIMEOUT_SF 1 +#ifdef RSI_PROP_PROTOCOL_ENABLE +#define PROP_PROTOCOL_WAIT_TIMEOUT_SF 1 +#endif +#define BT_COMMON_WAIT_TIMEOUT_SF 1 + +//! No of ltcp socktes +//#define RSI_NUMBER_OF_LTCP_SOCKETS 2 +#define RSI_NUMBER_OF_LTCP_SOCKETS 0 + +//! Default number of sockets supported,max 10 sockets are supported +//#define RSI_NUMBER_OF_SOCKETS (2 + RSI_NUMBER_OF_LTCP_SOCKETS) +#define RSI_NUMBER_OF_SOCKETS (6 + RSI_NUMBER_OF_LTCP_SOCKETS) + +//! Default number of sockets supported,max 10 selects are supported +//#define RSI_NUMBER_OF_SELECTS 4 +#define RSI_NUMBER_OF_SELECTS (RSI_NUMBER_OF_SOCKETS) + +// Max packets in wlan control tx pool +#define RSI_WLAN_TX_POOL_PKT_COUNT 1 + +// Max packets in bt common control tx pool +#define RSI_BT_COMMON_TX_POOL_PKT_COUNT 1 + +// Max packets in bt classic control tx pool +#define RSI_BT_CLASSIC_TX_POOL_PKT_COUNT 1 + +// Max packets in ble control tx pool +#define RSI_BLE_TX_POOL_PKT_COUNT 1 + +#ifdef RSI_PROP_PROTOCOL_ENABLE +// User configured MAX number of PROP_PROTOCOL TX PKTS pool COUNT. +#define PROP_PROTOCOL_TX_POOL_CONFIG_VAL 5 + +// Max packets in PROP_PROTOCOL control tx pool +#define RSI_PROP_PROTOCOL_TX_POOL_PKT_COUNT PROP_PROTOCOL_TX_POOL_CONFIG_VAL +#endif + +// Max packets in wlan control tx pool +#define RSI_ZIGB_TX_POOL_PKT_COUNT 1 + +// Max packets in common control tx pool +#define RSI_COMMON_TX_POOL_PKT_COUNT 1 + +// Max packets + +#define RSI_DRIVER_RX_POOL_PKT_COUNT 1 + +// Little Endian is enabled +#define RSI_LITTLE_ENDIAN 1 + +// Maximum scan results to be stored +#define MAX_SCAN_COUNT 48 + +// HAL specific maximum write buffer length in bytes +#define RSI_HAL_MAX_WR_BUFF_LEN 4096 + +#ifdef SAPI_LOGGING_ENABLE +#define CONFIG_DEBUG_LEVEL LOG_ERROR +#define LOG_TSF_GRANULARITY_TICKS 1UL +#endif + +#ifdef ENABLE_POC_IN_TOGGLE +// Configurable delay between clearing the POC_IN and RESET pin. For example, here the delay is set to 10 milliseconds. +#define CONFIG_DELAY_POCIN_RESET_PIN_CLEAR 10 +// Configurable delay between setting the POC_IN and RESET pin. For example, here the delay is set to 30 milliseconds. +#define CONFIG_DELAY_POCIN_RESET_PIN_SET 30 +#endif + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +#endif diff --git a/wiseconnect/sapi/include/rsi_utils.h b/wiseconnect/sapi/include/rsi_utils.h new file mode 100644 index 00000000..fe6ed10b --- /dev/null +++ b/wiseconnect/sapi/include/rsi_utils.h @@ -0,0 +1,86 @@ +/******************************************************************************* +* @file rsi_utils.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_UTILS_H +#define RSI_UTILS_H + +#include +/****************************************************** + * * Macros + * ******************************************************/ +#ifndef BIT +#define BIT(a) ((uint32_t)1U << a) +#endif + +//#define RSI_MIN(x, y) ((x) > (y) ? (y) : (x)) //This statement is modified to avoid compilation warning +#define RSI_MIN(x, y) ((int32_t)(x) > (int32_t)(y) ? (int32_t)(y) : (int32_t)(x)) + +#ifndef NULL +#define NULL 0 +#endif + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +void rsi_uint32_to_4bytes(uint8_t *dBuf, uint32_t val); +void rsi_uint16_to_2bytes(uint8_t *dBuf, uint16_t val); +uint16_t rsi_bytes2R_to_uint16(uint8_t *dBuf); +uint32_t rsi_bytes4R_to_uint32(uint8_t *dBuf); +uint8_t multicast_mac_hash(uint8_t *mac); +uint8_t lmac_crc8_c(uint8_t crc8_din, uint8_t crc8_state, uint8_t end); +uint8_t *rsi_ascii_dev_address_to_6bytes_rev(uint8_t *hex_addr, int8_t *ascii_mac_address); +uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, uint8_t *hex_addr); +uint8_t convert_lower_case_to_upper_case(uint8_t lwrcase); +void string2array(uint8_t *dst, uint8_t *src, uint32_t length); +int32_t rsi_atoi(const int8_t *str); +void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress); +void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress); +uint64_t ip_to_reverse_hex(char *ip); +uint8_t ascii_to_dec(uint8_t *num); +int8_t rsi_ascii_hex2num(int8_t ascii_hex_in); +int8_t rsi_char_hex2dec(int8_t *cBuf); +int8_t hex_to_ascii(uint8_t hex_num); +uint8_t *rsi_itoa(uint32_t val, uint8_t *str); +int8_t asciihex_2_num(int8_t ascii_hex_in); +int8_t rsi_charhex_2_dec(int8_t *cBuf); +uint32_t rsi_ntohl(uint32_t a); +#if defined(FLOAT_PRINT_BYPASS) +void rsi_reverse(char *str, int len); +int rsi_intToStr(int x, char str[], int d); +void rsi_ftoa(char *res, float n, int afterpoint); +#endif +#endif \ No newline at end of file diff --git a/wiseconnect/sapi/include/rsi_wlan.h b/wiseconnect/sapi/include/rsi_wlan.h new file mode 100644 index 00000000..bfebcb87 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_wlan.h @@ -0,0 +1,1829 @@ +/******************************************************************************* +* @file rsi_wlan.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_WLAN_H +#define RSI_WLAN_H + +#include +#include +#include +#include "rsi_socket.h" +#include "rsi_wlan_non_rom.h" +/****************************************************** + * * Macros + * ******************************************************/ +// Maximum length of PSK +#define RSI_PSK_LEN 64 + +// length of the PMK +#define RSI_PMK_LEN 32 + +// Host descriptor length +#define RSI_HOST_DESC_LENGTH 16 + +// Maximum payload size +#define RSI_MAX_PAYLOAD_SIZE 1500 + +// IP address length in bytes +#define RSI_IP_ADDRESS_LEN 4 + +// Maximum certificate length supported in one chunk +#define RSI_MAX_CERT_SEND_SIZE 1400 + +// Maximum certificate length supported in one chunk +#define RSI_MAX_CERT_RECV_SIZE 1400 + +// country code length in set region command +#define RSI_COUNTRY_CODE_LENGTH 3 + +// maximum no of channels to set rules +#define RSI_MAX_POSSIBLE_CHANNEL 24 + +// length of wps pin +#define RSI_WPS_PIN_LEN 8 + +// BIT to identify set mac to give before init +#define RSI_SET_MAC_BIT BIT(0) + +// Websocket max url length +#define RSI_WEBS_MAX_URL_LENGTH 51 + +// Websocket max host length +#define RSI_WEBS_MAX_HOST_LENGTH 51 + +// snmp response buf max length +#define MAX_SNMP_VALUE 200 + +// snmp trap buffer length +#define RSI_SNMP_TRAP_BUFFER_LENGTH 1024 + +// Maximum chunk size of firmware upgradation +#define RSI_MAX_FWUP_CHUNK_SIZE 1024 + +// Maximum chunk size of OTA firmware upgradation +#define RSI_MAX_OTA_FWUP_CHUNK_SIZE 800 + +// RPS header size +#define RSI_RPS_HEADER_SIZE 64 + +#define RSI_WPS_NOT_SUPPORTED 0x86 + +// Auto config going on bitmap +#define RSI_AUTO_CONFIG_FAILED BIT(1) + +// Auto config going on bitmap +#define RSI_AUTO_CONFIG_GOING_ON BIT(2) + +// Auto config done bitmap +#define RSI_AUTO_CONFIG_DONE BIT(3) + +#define RSI_USER_STORE_CFG_STATUS 0x5a5a + +// frame type of raw data packets for host stack +#define DUAL_HOST_RAW_DATA_PACKET 1 + +// AKM suite types +#define RSN_SELECTOR(d, c, b, a) \ + ((((uint32_t)(a)) << 24) | (((uint32_t)(b)) << 16) | (((uint32_t)(c)) << 8) | (uint32_t)(d)) +#define RSN_AKM_OFFSET 12 +#define RSN_SELECTOR_LEN 4 +#define WPA_DRIVER_CAPA_KEY_MGMT_WPA 0x00000001 +#define WPA_DRIVER_CAPA_KEY_MGMT_WPA2 0x00000002 +#define WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK 0x00000004 +#define WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK 0x00000008 +#define WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE 0x00000010 +#define WPA_DRIVER_CAPA_KEY_MGMT_SAE 0x00010000 +#define WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256 0x00020000 +#define WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256 0x00040000 + +#define RSN_AUTH_KEY_MGMT_UNSPEC_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 1) +#define RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 2) +#define RSN_AUTH_KEY_MGMT_FT_802_1X RSN_SELECTOR(0x00, 0x0f, 0xac, 3) +#define RSN_AUTH_KEY_MGMT_FT_PSK RSN_SELECTOR(0x00, 0x0f, 0xac, 4) +#define RSN_AUTH_KEY_MGMT_802_1X_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 5) +#define RSN_AUTH_KEY_MGMT_PSK_SHA256 RSN_SELECTOR(0x00, 0x0f, 0xac, 6) +#define RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE RSN_SELECTOR(0x00, 0x0f, 0xac, 7) +#define RSN_AUTH_KEY_MGMT_SAE RSN_SELECTOR(0x00, 0x0f, 0xac, 8) + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +// enumeration for WLAN control block state machine +typedef enum rsi_wlan_state_e { + RSI_WLAN_STATE_NONE = 0, + RSI_WLAN_STATE_OPERMODE_DONE, + RSI_WLAN_STATE_BAND_DONE, + RSI_WLAN_STATE_INIT_DONE, + RSI_WLAN_STATE_SCAN_DONE, + RSI_WLAN_STATE_CONNECTED, + RSI_WLAN_STATE_IP_CONFIG_DONE, + RSI_WLAN_STATE_IPV6_CONFIG_DONE, + RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON, + RSI_WLAN_STATE_AUTO_CONFIG_DONE, + RSI_WLAN_STATE_AUTO_CONFIG_FAILED +} rsi_wlan_state_t; + +// enumeration for WLAN command response codes +typedef enum rsi_wlan_cmd_response_e { + RSI_WLAN_RSP_CLEAR = 0x00, + RSI_WLAN_RSP_BAND = 0x11, + RSI_WLAN_RSP_INIT = 0x12, + RSI_WLAN_RSP_SCAN = 0x13, + RSI_WLAN_RSP_JOIN = 0x14, + RSI_WLAN_RSP_CONFIG = 0XBE, + RSI_WLAN_RSP_SET_MAC_ADDRESS = 0x17, + RSI_WLAN_RSP_QUERY_NETWORK_PARAMS = 0x18, + RSI_WLAN_RSP_DISCONNECT = 0x19, + RSI_WLAN_RSP_SET_REGION = 0x1D, + RSI_WLAN_RSP_CFG_SAVE = 0x20, + RSI_WLAN_RSP_AUTO_CONFIG_ENABLE = 0x21, + RSI_WLAN_RSP_GET_CFG = 0x22, + RSI_WLAN_RSP_USER_STORE_CONFIG = 0x23, + RSI_WLAN_RSP_AP_CONFIGURATION = 0x24, + RSI_WLAN_RSP_SET_WEP_KEYS = 0x25, + RSI_WLAN_RSP_PING_PACKET = 0x29, + RSI_WLAN_RSP_TWT_PARAMS = 0x2F, + RSI_WLAN_RSP_P2P_CONNECTION_REQUEST = 0x30, + RSI_WLAN_RSP_SET_PROFILE = 0x31, + RSI_WLAN_RSP_GET_PROFILE = 0x32, + RSI_WLAN_RSP_DELETE_PROFILE = 0x33, + RSI_WLAN_RSP_RSSI = 0x3A, + RSI_WLAN_RSP_IPCONFV4 = 0x41, + RSI_WLAN_RSP_SOCKET_CREATE = 0x42, + RSI_WLAN_RSP_SOCKET_CLOSE = 0x43, + RSI_WLAN_RSP_EAP_CONFIG = 0x4C, + RSI_WLAN_RSP_FW_VERSION = 0x49, + RSI_WLAN_RSP_MAC_ADDRESS = 0x4A, + RSI_WLAN_RSP_QUERY_GO_PARAMS = 0x4E, + RSI_WLAN_RSP_CONN_ESTABLISH = 0x61, + RSI_WLAN_RSP_REMOTE_TERMINATE = 0x62, + RSI_WLAN_RSP_SOCKET_READ_DATA = 0x6B, + RSI_WLAN_RSP_SOCKET_ACCEPT = 0x6C, + RSI_WLAN_RSP_IPCONFV6 = 0xA1, + RSI_WLAN_RSP_HOST_PSK = 0xA5, + RSI_WLAN_RSP_SOCKET_CONFIG = 0xA7, + RSI_WLAN_RSP_IPV4_CHANGE = 0xAA, + RSI_WLAN_RSP_TCP_ACK_INDICATION = 0xAB, + RSI_WLAN_RSP_UART_DATA_ACK = 0xAC, + RSI_WLAN_RSP_SET_MULTICAST_FILTER = 0x40, + RSI_WLAN_RSP_GAIN_TABLE = 0x47, + RSI_WLAN_RSP_SET_CERTIFICATE = 0x4D, + RSI_WLAN_RSP_DNS_QUERY = 0x44, + RSI_WLAN_RSP_DNS_UPDATE = 0xED, + RSI_WLAN_RSP_CONNECTION_STATUS = 0x48, + RSI_WLAN_RSP_CONFIGURE_P2P = 0x4B, + RSI_WLAN_RSP_HTTP_CLIENT_GET = 0x51, + RSI_WLAN_RSP_HTTP_CLIENT_POST = 0x52, + RSI_WLAN_RSP_HTTP_CLIENT_POST_DATA = 0xEB, + RSI_WLAN_RSP_HTTP_CLIENT_PUT = 0x53, + RSI_WLAN_RSP_WFD_DEVICE = 0x54, + RSI_WLAN_RSP_DNS_SERVER_ADD = 0x55, + RSI_WLAN_RSP_WIRELESS_FWUP_OK = 0x59, + RSI_WLAN_RSP_WIRELESS_FWUP_DONE = 0x5A, + RSI_WLAN_RSP_BG_SCAN = 0x6A, + RSI_WLAN_RSP_HT_CAPABILITIES = 0x6D, + RSI_WLAN_RSP_REJOIN_PARAMS = 0x6F, + RSI_WLAN_RSP_WPS_METHOD = 0x72, + RSI_WLAN_RSP_ROAM_PARAMS = 0x7B, + RSI_WLAN_RSP_TX_TEST_MODE = 0x7C, + RSI_WLAN_RSP_WMM_PS = 0x97, + RSI_WLAN_RSP_FWUP = 0x99, + RSI_WLAN_RSP_RX_STATS = 0xA2, + RSI_WLAN_RSP_MULTICAST = 0xB1, + RSI_WLAN_RSP_HTTP_ABORT = 0xB3, + RSI_WLAN_RSP_HTTP_CREDENTIALS = 0xB4, +#ifdef RSI_WAC_MFI_ENABLE + RSI_WLAN_RSP_ADD_MFI_IE = 0xB5, +#endif +#ifndef RSI_M4_INTERFACE + RSI_WLAN_RSP_CERT_VALID = 0xBC, +#endif + RSI_WLAN_RSP_SET_REGION_AP = 0xBD, + RSI_WLAN_RSP_CLIENT_CONNECTED = 0xC2, + RSI_WLAN_RSP_CLIENT_DISCONNECTED = 0xC3, + RSI_WLAN_RSP_FREQ_OFFSET = 0xF3, + RSI_WLAN_RSP_CALIB_WRITE = 0xCA, + RSI_WLAN_RSP_CALIB_READ = 0xCF, + RSI_WLAN_RSP_DYNAMIC_POOL = 0xC7, + RSI_WLAN_RSP_FILTER_BCAST_PACKETS = 0xC9, + RSI_WLAN_RSP_EMB_MQTT_CLIENT = 0xCB, + RSI_WLAN_RSP_EMB_MQTT_PUBLISH_PKT = 0xCC, + RSI_WLAN_RSP_MQTT_REMOTE_TERMINATE = 0xF0, + RSI_WLAN_RSP_MDNSD = 0xDB, + RSI_WLAN_RSP_FTP = 0xE2, + RSI_WLAN_RSP_FTP_FILE_WRITE = 0xE3, + RSI_WLAN_RSP_SNTP_CLIENT = 0xE4, + RSI_WLAN_RSP_SNTP_SERVER = 0xE5, + RSI_WLAN_RSP_SMTP_CLIENT = 0xE6, + RSI_WLAN_RSP_OTA_FWUP = 0xEF, + RSI_WLAN_RSP_WEBPAGE_LOAD = 0x50, + RSI_WLAN_RSP_JSON_LOAD = 0x9c, + RSI_WLAN_RSP_WEBPAGE_ERASE = 0x9A, + RSI_WLAN_RSP_JSON_OBJECT_ERASE = 0x9B, + RSI_WLAN_RSP_WEBPAGE_CLEAR_ALL = 0x7F, + RSI_WLAN_RSP_HOST_WEBPAGE_SEND = 0x56, + RSI_WLAN_RSP_JSON_UPDATE = 0x9D, + RSI_WLAN_RSP_GET_RANDOM = 0xF8, + RSI_WLAN_RSP_ASYNCHRONOUS = 0xFF, + RSI_WLAN_RSP_JSON_EVENT = 0xEE, + RSI_WLAN_RSP_POP3_CLIENT = 0xE7, + RSI_WLAN_RSP_POP3_CLIENT_TERMINATE = 0xE8, + RSI_WLAN_RSP_DHCP_USER_CLASS = 0xEC, + RSI_WLAN_RSP_TIMEOUT = 0xEA, + RSI_WLAN_RSP_URL_REQUEST = 0x64, + RSI_WLAN_RSP_MODULE_STATE = 0x70, + RSI_WLAN_RSP_TWT_ASYNC = 0x71, + RSI_WLAN_RSP_SELECT_REQUEST = 0x74, + RSI_WLAN_RSP_SCAN_RESULTS = 0xAF, + RSI_WLAN_RSP_RADIO = 0x81, + RSI_WLAN_RSP_GET_STATS = 0xF1, + RSI_WLAN_RSP_HTTP_OTAF = 0xF4, + RSI_WLAN_RSP_UPDATE_TCP_WINDOW = 0xF5, + RSI_WLAN_RATE_RSP_STATS = 0x88, + RSI_WLAN_RSP_GET_CSI_DATA = 0xC4, + RSI_WLAN_RSP_EXT_STATS = 0x68 + +} rsi_wlan_cmd_response_t; + +// enumeration for WLAN command request codes +typedef enum rsi_wlan_cmd_request_e { + RSI_WLAN_REQ_BAND = 0x11, + RSI_WLAN_REQ_INIT = 0x12, + RSI_WLAN_REQ_SCAN = 0x13, + RSI_WLAN_REQ_JOIN = 0x14, + RSI_WLAN_REQ_CONFIG = 0xBE, + RSI_WLAN_REQ_SET_SLEEP_TIMER = 0x16, + RSI_WLAN_REQ_SET_MAC_ADDRESS = 0x17, + RSI_WLAN_REQ_QUERY_NETWORK_PARAMS = 0x18, + RSI_WLAN_REQ_DISCONNECT = 0x19, + RSI_WLAN_REQ_SET_REGION = 0x1D, + RSI_WLAN_REQ_CFG_SAVE = 0x20, + RSI_WLAN_REQ_AUTO_CONFIG_ENABLE = 0x21, + RSI_WLAN_REQ_GET_CFG = 0x22, + RSI_WLAN_REQ_USER_STORE_CONFIG = 0x23, + RSI_WLAN_REQ_AP_CONFIGURATION = 0x24, + RSI_WLAN_REQ_SET_WEP_KEYS = 0x25, + RSI_WLAN_REQ_PING_PACKET = 0x29, + RSI_WLAN_REQ_TWT_PARAMS = 0x2F, + RSI_WLAN_REQ_SET_PROFILE = 0x31, + RSI_WLAN_REQ_GET_PROFILE = 0x32, + RSI_WLAN_REQ_DELETE_PROFILE = 0x33, + RSI_WLAN_REQ_RSSI = 0x3A, + RSI_WLAN_REQ_IPCONFV4 = 0x41, + RSI_WLAN_REQ_SOCKET_CREATE = 0x42, + RSI_WLAN_REQ_SOCKET_CLOSE = 0x43, + RSI_WLAN_REQ_EAP_CONFIG = 0x4C, + RSI_WLAN_REQ_FW_VERSION = 0x49, + RSI_WLAN_REQ_MAC_ADDRESS = 0x4A, + RSI_WLAN_REQ_QUERY_GO_PARAMS = 0x4E, + RSI_WLAN_REQ_SOCKET_READ_DATA = 0x6B, + RSI_WLAN_REQ_SOCKET_ACCEPT = 0x6C, + RSI_WLAN_REQ_IPCONFV6 = 0x90, + RSI_WLAN_REQ_HOST_PSK = 0xA5, + RSI_WLAN_REQ_SET_MULTICAST_FILTER = 0x40, + RSI_WLAN_REQ_GAIN_TABLE = 0x47, + RSI_WLAN_REQ_SET_CERTIFICATE = 0x4D, + RSI_WLAN_REQ_DNS_QUERY = 0x44, + RSI_WLAN_REQ_DNS_UPDATE = 0xED, + RSI_WLAN_REQ_CONNECTION_STATUS = 0x48, + RSI_WLAN_REQ_CONFIGURE_P2P = 0x4B, + RSI_WLAN_REQ_HTTP_CLIENT_GET = 0x51, + RSI_WLAN_REQ_HTTP_CLIENT_POST = 0x52, + RSI_WLAN_REQ_HTTP_CLIENT_POST_DATA = 0xEB, + RSI_WLAN_REQ_HTTP_CLIENT_PUT = 0x53, + RSI_WLAN_REQ_DNS_SERVER_ADD = 0x55, + RSI_WLAN_REQ_WIRELESS_FWUP = 0x59, + RSI_WLAN_REQ_BG_SCAN = 0x6A, + RSI_WLAN_REQ_HT_CAPABILITIES = 0x6D, + RSI_WLAN_REQ_REJOIN_PARAMS = 0x6F, + RSI_WLAN_REQ_WPS_METHOD = 0x72, + RSI_WLAN_REQ_ROAM_PARAMS = 0x7B, + RSI_WLAN_REQ_TX_TEST_MODE = 0x7C, + RSI_WLAN_REQ_WMM_PS = 0x97, + RSI_WLAN_REQ_FWUP = 0x99, + RSI_WLAN_REQ_RX_STATS = 0xA2, + RSI_WLAN_REQ_SOCKET_CONFIG = 0xA7, + RSI_WLAN_REQ_MULTICAST = 0xB1, + RSI_WLAN_REQ_HTTP_ABORT = 0xB3, + RSI_WLAN_REQ_HTTP_CREDENTIALS = 0xB4, +#ifdef RSI_WAC_MFI_ENABLE + RSI_WLAN_REQ_ADD_MFI_IE = 0xB5, +#endif +#ifndef RSI_M4_INTERFACE + RSI_WLAN_REQ_CERT_VALID = 0xBC, +#endif + RSI_WLAN_REQ_SET_REGION_AP = 0xBD, + RSI_WLAN_REQ_FREQ_OFFSET = 0xF3, + RSI_WLAN_REQ_CALIB_WRITE = 0xCA, + RSI_WLAN_REQ_CALIB_READ = 0xCF, + RSI_WLAN_REQ_DYNAMIC_POOL = 0xC7, + RSI_WLAN_REQ_FILTER_BCAST_PACKETS = 0xC9, + RSI_WLAN_REQ_EMB_MQTT_CLIENT = 0xCB, + RSI_WLAN_REQ_MDNSD = 0xDB, + RSI_WLAN_REQ_FTP = 0xE2, + RSI_WLAN_REQ_FTP_FILE_WRITE = 0xE3, + RSI_WLAN_REQ_SNTP_CLIENT = 0xE4, + RSI_WLAN_REQ_SMTP_CLIENT = 0xE6, + RSI_WLAN_REQ_OTA_FWUP = 0xEF, + RSI_WLAN_REQ_WEBPAGE_LOAD = 0x50, + RSI_WLAN_REQ_JSON_LOAD = 0x9c, + RSI_WLAN_REQ_WEBPAGE_ERASE = 0x9A, + RSI_WLAN_REQ_JSON_OBJECT_ERASE = 0x9B, + RSI_WLAN_REQ_WEBPAGE_CLEAR_ALL = 0x7F, + RSI_WLAN_REQ_HOST_WEBPAGE_SEND = 0x56, + RSI_WLAN_REQ_GET_RANDOM = 0xF8, + RSI_WLAN_REQ_POP3_CLIENT = 0xE7, + RSI_WLAN_REQ_DHCP_USER_CLASS = 0xEC, + RSI_WLAN_REQ_SELECT_REQUEST = 0x74, + RSI_WLAN_REQ_TIMEOUT = 0xEA, + RSI_WLAN_REQ_RADIO = 0x81, + RSI_WLAN_REQ_GET_STATS = 0xF1, + RSI_WLAN_REQ_HTTP_OTAF = 0xF4, + RSI_WLAN_REQ_UPDATE_TCP_WINDOW = 0xF5, + RSI_WLAN_REQ_11AX_PARAMS = 0xFF, + RSI_WLAN_REQ_GET_CSI_DATA = 0xC4, + RSI_WLAN_REQ_EXT_STATS = 0x68 + +} rsi_wlan_cmd_request_t; + +typedef enum rsi_wlan_opermode_e { + RSI_WLAN_CLIENT_MODE = 0, + RSI_WLAN_WIFI_DIRECT_MODE = 1, + RSI_WLAN_ENTERPRISE_CLIENT_MODE = 2, + RSI_WLAN_ACCESS_POINT_MODE = 6, + RSI_WLAN_TRANSMIT_TEST_MODE = 8, + RSI_WLAN_CONCURRENT_MODE = 9 + +} rsi_wlan_opermode_t; + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +// driver WLAN control block +typedef struct rsi_wlan_cb_s { + // driver wlan control block state + volatile rsi_wlan_state_t state; + + // Auto config state + volatile uint8_t auto_config_state; + + // driver wlan control block status + volatile int32_t status; + + // driver wlan control block mutex + rsi_mutex_handle_t wlan_mutex; + + // driver wlan control block expected command response + rsi_wlan_cmd_response_t expected_response; + + // driver wlan control block semaphore + rsi_semaphore_handle_t wlan_sem; + + // driver wlan control block tx packet pool + rsi_pkt_pool_t wlan_tx_pool; + + // socket id of socket which is waiting for socket create response + uint8_t waiting_socket_id; + + // buffer pointer given by application to driver + uint8_t *app_buffer; + + // buffer length given by application to driver + uint32_t app_buffer_length; + + // driver wlan control block requested query command + uint8_t query_cmd; + + // validity + uint16_t field_valid_bit_map; + + // mac address + uint8_t mac_address[6]; + + // opermode + uint16_t opermode; + + // wlan station state + volatile rsi_wlan_state_t sta_state; + + // wlan ap state + volatile rsi_wlan_state_t ap_state; +} rsi_wlan_cb_t; + +// Band command request structure +typedef struct rsi_req_band_s { + // uint8_t, band value to set + uint8_t band_value; +} rsi_req_band_t; + +// Config command request structure +typedef struct rsi_req_config_s { + // config type + uint16_t config_type; + // value to set + uint16_t value; +} rsi_req_config_t; + +// Set Mac address command request structure +typedef struct rsi_req_mac_address_s { + + // byte array, mac address + uint8_t mac_address[6]; +} rsi_req_mac_address_t; + +// Rejoin params command request structure +typedef struct rsi_req_rejoin_params_s { + // maximum number of retries before indicating join failure + uint8_t max_retry[4]; + + // scan interval between each retry + uint8_t scan_interval[4]; + + // beacon miss count to start rejoin + uint8_t beacon_missed_count[4]; + + // retry enable or disable for first time joining + uint8_t first_time_retry_enable[4]; + +} rsi_req_rejoin_params_t; + +// Setregion command request structure +typedef struct rsi_req_set_region_s { + // Enable or disable set region from user: 1-take from user configuration,0-Take from Beacons + uint8_t set_region_code_from_user_cmd; + + // region code(1-US,2-EU,3-JP.4-World Domain)*/ + uint8_t region_code; + + // module type (0- Without on board antenna, 1- With on board antenna) + uint8_t module_type[2]; + +} rsi_req_set_region_t; + +// Set region in AP mode command request structure +typedef struct rsi_req_set_region_ap_s { + // Enable or disable set region from user: 1-take from user configuration, 0-Take US or EU or JP + uint8_t set_region_code_from_user_cmd; + + // region code(1-US,2-EU,3-JP) + uint8_t country_code[RSI_COUNTRY_CODE_LENGTH]; + + uint8_t no_of_rules[4]; + + struct { + uint8_t first_channel; + uint8_t no_of_channels; + uint8_t max_tx_power; + } channel_info[RSI_MAX_POSSIBLE_CHANNEL]; + +} rsi_req_set_region_ap_t; + +// Scan command request structure +typedef struct rsi_req_scan_s { + // RF channel to scan, 0=All, 1-14 for 2.5GHz channels 1-14 + uint8_t channel[4]; + + // uint8[34], ssid to scan + uint8_t ssid[RSI_SSID_LEN]; + + // uint8[6], reserved fields + uint8_t reserved[5]; + + // uint8 , scan_feature_bitmap + uint8_t scan_feature_bitmap; + + // uint8[2], channel bit map for 2.4 Ghz + uint8_t channel_bit_map_2_4[2]; + + // uint8[4], channel bit map for 5 Ghz + uint8_t channel_bit_map_5[4]; + +} rsi_req_scan_t; + +// PSK command request structure +typedef struct rsi_req_psk_s { + // psk type , 1-psk alone, 2-pmk, 3-generate pmk from psk + uint8_t type; + + // psk or pmk + uint8_t psk_or_pmk[RSI_PSK_LEN]; + + // access point ssid: used for generation pmk + uint8_t ap_ssid[RSI_SSID_LEN]; + +} rsi_req_psk_t; + +typedef struct rsi_req_wps_method_s { + // wps method: 0 - push button, 1 - pin method + uint8_t wps_method[2]; + + // If 0 - validate given pin, 1 - generate new pin + uint8_t generate_pin[2]; + + // wps pin for validation + uint8_t wps_pin[RSI_WPS_PIN_LEN]; + +} rsi_req_wps_method_t; + +// Access point configuration parameters +typedef struct rsi_req_ap_config_s { + + // channel number of the access point + uint8_t channel[2]; + + // ssid of the AP to be created + uint8_t ssid[RSI_SSID_LEN]; + + // security type of the Access point + uint8_t security_type; + + // encryption mode + uint8_t encryption_mode; + + // password in case of security mode + uint8_t psk[RSI_PSK_LEN]; + + // beacon interval of the access point + uint8_t beacon_interval[2]; + + // DTIM period of the access point + uint8_t dtim_period[2]; + + // beacon interval of the access point + uint8_t ap_keepalive_type; + + // This is the bitmap to enable AP keep alive functionality and to + // select the keep alive type. + uint8_t ap_keepalive_period; + + // Number of clients supported + uint8_t max_sta_support[2]; + +} rsi_req_ap_config_t; + +// High throughputs enable command +typedef struct rsi_req_ap_ht_caps_s { + // Variable to enable/disable publish high throughputs + // capablities in the beacon in Acess point mode + uint8_t mode_11n_enable[2]; + + // HT capabilities bitmap which is published + // in the beacon + uint8_t ht_caps_bitmap[2]; + +} rsi_req_ap_ht_caps_t; + +typedef struct rsi_req_configure_p2p_s { + + // GO Intent Value 0-15 for P2p GO or client , 16 - Soft AP + uint8_t go_intent[2]; + + // name of the device + uint8_t device_name[64]; + + // In which channel we are operating after becomes Group owner + uint8_t operating_channel[2]; + + // Postfix SSID + uint8_t ssid_post_fix[64]; + + // PSK of the device + uint8_t psk[64]; + +} rsi_req_configure_p2p_t; + +// join command request structure +typedef struct rsi_req_join_s { + // reserved bytes:Can be used for security Type + uint8_t reserved1; + + // 0- Open, 1-WPA, 2-WPA2,6-MIXED_MODE + uint8_t security_type; + + // data rate, 0=auto, 1=1Mbps, 2=2Mbps, 3=5.5Mbps, 4=11Mbps, 12=54Mbps + uint8_t data_rate; + + // transmit power level, 0=low (6-9dBm), 1=medium (10-14dBm, 2=high (15-17dBm) + uint8_t power_level; + + // pre-shared key, 63-byte string , last charecter is NULL + uint8_t psk[RSI_PSK_LEN]; + + // ssid of access point to join to, 34-byte string + uint8_t ssid[RSI_SSID_LEN]; + + // feature bitmap for join + uint8_t join_feature_bitmap; + + // reserved bytes + uint8_t reserved2[2]; + + // length of ssid given + uint8_t ssid_len; + + // listen interval + uint8_t listen_interval[4]; + + // vap id, 0 - station mode, 1 - AP1 mode + uint8_t vap_id; + + // join bssid for mac based join + uint8_t join_bssid[6]; + +} rsi_req_join_t; + +// structure for ping request command +typedef struct rsi_req_ping_s { + // ip version + uint8_t ip_version[2]; + + // ping size + uint8_t ping_size[2]; + + union { + // ipv4 address + uint8_t ipv4_address[4]; + + // ipv6 address + uint8_t ipv6_address[16]; + + } ping_address; + + uint16_t timeout; +} rsi_req_ping_t; + +// Ping Response Frame +typedef struct rsi_rsp_ping_s { + // ip version + uint8_t ip_version[2]; + + // ping size + uint8_t ping_size[2]; + union { + // ipv4 address + uint8_t ipv4_addr[4]; + + // ipv6 address + uint8_t ipv6_addr[16]; + } ping_address; + +} rsi_rsp_ping_t; + +// bg scan command request structure +typedef struct rsi_req_bg_scan_s { + // enable or disable BG scan + uint8_t bgscan_enable[2]; + + // Is it instant bgscan or normal bgscan + uint8_t enable_instant_bgscan[2]; + + // bg scan threshold value + uint8_t bgscan_threshold[2]; + + // tolerance threshold + uint8_t rssi_tolerance_threshold[2]; + + // periodicity + uint8_t bgscan_periodicity[2]; + + // active scan duration + uint8_t active_scan_duration[2]; + + // passive scan duration + uint8_t passive_scan_duration[2]; + + // multi probe + uint8_t multi_probe; + +} rsi_req_bg_scan_t; + +typedef struct rsi_req_roam_params_s { + // Enable or disable roaming + uint8_t roam_enable[4]; + + // roaming threshold + uint8_t roam_threshold[4]; + + // roaming hysteresis + uint8_t roam_hysteresis[4]; + +} rsi_req_roam_params_t; + +// IPV4 ipconfig command request structure +typedef struct rsi_req_ipv4_parmas_s { + // 0=Manual, 1=Use DHCP + uint8_t dhcp_mode; + + // IP address of this module if in manual mode + uint8_t ipaddress[4]; + + // Netmask used if in manual mode + uint8_t netmask[4]; + + // IP address of default gateway if in manual mode + uint8_t gateway[4]; + + // DHCP client host name + uint8_t hostname[31]; + + // vap id, 0 - station and 1 - AP + uint8_t vap_id; + +} rsi_req_ipv4_parmas_t; + +// IPV6 ipconfig command request structure +typedef struct rsi_req_ipv6_parmas_s { + + // 0=Manual, 1=Use DHCP + uint8_t mode[2]; + + // prefix length + uint8_t prefixLength[2]; + + // IPV6 address of the module + uint8_t ipaddr6[16]; + + // address of gateway + uint8_t gateway6[16]; +} rsi_req_ipv6_parmas_t; + +// disassociate command request structure +typedef struct rsi_req_disassoc_s { + + // 0- Module in Client mode, 1- AP mode + uint8_t mode_flag[2]; + + // client MAC address, Ignored/Reserved in case of client mode + uint8_t client_mac_address[6]; + +} rsi_req_disassoc_t; + +// Enterprise configuration command request structure +typedef struct rsi_req_eap_config_s { + // EAP method + uint8_t eap_method[32]; + + // Inner method + uint8_t inner_method[32]; + + // Username + uint8_t user_identity[64]; + + // Password + uint8_t password[128]; + + // Opportunistic key caching enable + int8_t okc_enable[4]; + + // Private key password for encrypted private keys + uint8_t private_key_password[82]; + +} rsi_req_eap_config_t; + +// Set certificate information structure +typedef struct rsi_cert_info_s { + // total length of the certificate + uint8_t total_len[2]; + + // type of certificate + uint8_t certificate_type; + + // more chunks flag + uint8_t more_chunks; + + //length of the current segment + uint8_t certificate_length[2]; + + // index of certificate + uint8_t certificate_inx; + + // reserved + uint8_t key_password[127]; + +} rsi_cert_info_t; +#ifndef RSI_M4_INTERFACE +// Certificate Received structure +typedef struct rsi_cert_recv_s { + // Ip version + uint8_t ip_version[2]; + + // Socket descriptor + uint8_t sock_desc[2]; + + // local port + uint8_t src_port[2]; + + // Destination port + uint8_t dst_port[2]; + + union { + // destination ipv4 address + uint8_t ipv4_address[4]; + + // destination ipv6 address + uint8_t ipv6_address[16]; + } ip_address; + + // sequence number; + uint8_t sequence_no[2]; + + // total length of the certificate + uint8_t total_len[2]; + + //length of the current segment + uint8_t current_len[2]; + + // more chunks flag + uint8_t more_chunks; + + uint8_t reserved[5]; + +} rsi_cert_recv_t; + +typedef struct rsi_req_cert_valid_s { + // Socket ID + uint16_t socket_id; + + // certificate valid status + volatile uint16_t status; + +} rsi_req_cert_valid_t; +#endif +#define RSI_CERT_MAX_DATA_SIZE (RSI_MAX_CERT_SEND_SIZE - (sizeof(struct rsi_cert_info_s))) +// Set certificate command request structure +typedef struct rsi_req_set_certificate_s { + // certificate information structure + struct rsi_cert_info_s cert_info; + + // certificate + uint8_t certificate[RSI_MAX_CERT_SEND_SIZE]; + +} rsi_req_set_certificate_t; + +// tx test mode command request structure +typedef struct rsi_req_tx_test_info_s { + + // uint8_t, enable/disable tx test mode + uint8_t enable[2]; + + // uint8_t, tx test mode power + uint8_t power[2]; + + // uint8_t, tx test mode rate + uint8_t rate[4]; + + // uint8_t, tx test mode length + uint8_t length[2]; + + // uint8_t, tx test mode mode + uint8_t mode[2]; + + // uint8_t, tx test mode channel + uint8_t channel[2]; + + // uint8_t, tx test mode rate_flags + uint8_t rate_flags[2]; + + // uint8_t, tx test mode tx test_ch_bw + uint8_t channel_bw[2]; + + // uint8_t, tx test mode aggr_enable + uint8_t aggr_enable[2]; + + // uint8_t, tx test mode reserved + uint8_t reserved[2]; + + // uint8_t, tx test mode no_of_pkts + uint8_t no_of_pkts[2]; + + // uint8_t, tx test mode delay + uint8_t delay[4]; +#ifdef CHIP_9117 + uint8_t enable_11ax; + uint8_t coding_type; + uint8_t nominal_pe; + uint8_t UL_DL; + uint8_t he_ppdu_type; + uint8_t beam_change; + uint8_t BW; + uint8_t STBC; + uint8_t Tx_BF; + uint8_t GI_LTF; + uint8_t DCM; + uint8_t NSTS_MIDAMBLE; + uint8_t spatial_reuse; + uint8_t BSS_color; + uint8_t HE_SIGA2_RESERVED[2]; + uint8_t RU_ALLOCATION; + uint8_t N_HELTF_TOT; + uint8_t SIGB_DCM; + uint8_t SIGB_MCS; + uint8_t USER_STA_ID[2]; + uint8_t USER_IDX; + uint8_t SIGB_COMPRESSION_FIELD; +#endif +} rsi_req_tx_test_info_t; + +// per stats command request structure +typedef struct rsi_req_rx_stats_s { + // 0 - start , 1 -stop + uint8_t start[2]; + + // channel number + uint8_t channel[2]; + +} rsi_req_rx_stats_t; + +// SNMP command structure +typedef struct rsi_snmp_response_s { + uint8_t type; + uint8_t value[MAX_SNMP_VALUE]; +} rsi_snmp_response_t; + +// snmp object data structure format +typedef struct rsi_snmp_object_data_s { + + // Type of SNMP data contained + uint8_t snmp_object_data_type[4]; + + // Most significant 32 bits + uint8_t snmp_object_data_msw[4]; + + // Least significant 32 bits + uint8_t snmp_object_data_lsw[4]; + + // snmp ip version + uint8_t snmp_ip_version[4]; + union { + + // ipv4 address + uint8_t ipv4_address[4]; + + // ipv6 address + uint8_t ipv6_address[16]; + } snmp_ip_address; + +} rsi_snmp_object_data_t; + +// snmp trap object +typedef struct rsi_snmp_trap_object_s { + // SNMP object string + uint8_t snmp_object_string_ptr[40]; + + // SNMP object data + rsi_snmp_object_data_t snmp_object_data; + +} rsi_snmp_trap_object_t; + +// SNMP trap structure +typedef struct rsi_snmp_trap_s { + // snmp version + uint8_t snmp_version; + + // snmp ip version + uint8_t ip_version[4]; + union { + + // ipv4 address + uint8_t ipv4_address[4]; + + // ipv6 address + uint8_t ipv6_address[16]; + } destIPaddr; + + // communit : Private or public + uint8_t community[32]; + + // trap type + uint8_t trap_type; + + // elapsed time + uint8_t elapsed_time[4]; + + // trap oid + uint8_t trap_oid[51]; + + // object list count + uint8_t obj_list_count; + + // snmp buffer + uint8_t snmp_buf[RSI_SNMP_TRAP_BUFFER_LENGTH]; + +} rsi_snmp_trap_t; + +/* Structure for SNMP Enable */ +typedef struct rsi_snmp_enable_s { + // snmp enable + uint8_t snmp_enable; + +} rsi_snmp_enable_t; + +// Network params command response structure +typedef struct rsi_rsp_nw_params_s { + // uint8, 0=NOT Connected, 1=Connected + uint8_t wlan_state; + + // channel number of connected AP + uint8_t channel_number; + + // PSK + uint8_t psk[64]; + + // Mac address + uint8_t mac_address[6]; + + // uint8[32], SSID of connected access point + uint8_t ssid[RSI_SSID_LEN]; + + // 2 bytes, 0=AdHoc, 1=Infrastructure + uint8_t connType[2]; + + // security type + uint8_t sec_type; + + // uint8, 0=Manual IP Configuration,1=DHCP + uint8_t dhcpMode; + + // uint8[4], Module IP Address + uint8_t ipv4_address[4]; + + // uint8[4], Module Subnet Mask + uint8_t subnetMask[4]; + + // uint8[4], Gateway address for the Module + uint8_t gateway[4]; + + // number of sockets opened + uint8_t num_open_socks[2]; + + // prefix length for ipv6 address + uint8_t prefix_length[2]; + + // modules ipv6 address + uint8_t ipv6_address[16]; + + // router ipv6 address + uint8_t defaultgw6[16]; + + // BIT(0) =1 - ipv4, BIT(1)=2 - ipv6, BIT(0) & BIT(1)=3 - BOTH + uint8_t tcp_stack_used; + + //sockets information array + rsi_sock_info_query_t socket_info[RSI_MN_NUM_SOCKETS]; + +} rsi_rsp_nw_params_t; + +// go paramas response structure +typedef struct rsi_rsp_go_params_s { + // SSID of the P2p GO + uint8_t ssid[RSI_SSID_LEN]; + + // BSSID of the P2p GO + uint8_t mac_address[6]; + + // Operating channel of the GO + uint8_t channel_number[2]; + + // PSK of the GO + uint8_t psk[64]; + + // IPv4 Address of the GO + uint8_t ipv4_address[4]; + + // IPv6 Address of the GO + uint8_t ipv6_address[16]; + + // Number of stations Connected to GO + uint8_t sta_count[2]; + + rsi_go_sta_info_t sta_info[RSI_MAX_STATIONS]; + +} rsi_rsp_go_params_t; + +// socket create command request structure +typedef struct rsi_req_socket_s { + // ip version4 or 6 + uint8_t ip_version[2]; + + // 0=TCP Client, 1=UDP Client, 2=TCP Server (Listening TCP) + uint8_t socket_type[2]; + + // Our local module port number + uint8_t module_socket[2]; + + // Port number of what we are connecting to + uint8_t dest_socket[2]; + + union { + + // remote IPv4 Address + uint8_t ipv4_address[4]; + + // remote IPv6 Address + uint8_t ipv6_address[16]; + } __attribute__((__packed__)) dest_ip_addr; + + // maximum no of LTCP sockets on same port + uint8_t max_count[2]; + + // type of service +#ifdef CHIP_9117 + uint8_t tos[2]; +#else + uint8_t tos[4]; +#endif + + // ssl version select bit map +#ifdef CHIP_9117 + uint32_t ssl_bitmap; +#else + uint8_t ssl_bitmap; + + // ssl ciphers bitmap + uint8_t ssl_ciphers; +#endif + + // web socket resource name + uint8_t webs_resource_name[RSI_WEBS_MAX_URL_LENGTH]; + + // web socket host name + uint8_t webs_host_name[RSI_WEBS_MAX_HOST_LENGTH]; + + // TCP retries + uint8_t max_tcp_retries_count; + + // Socket bitmap + uint8_t socket_bitmap; + + // RX window size + uint8_t rx_window_size; + + // TCP keepalive initial timeout + uint8_t tcp_keepalive_initial_time[2]; + + // VAPID + uint8_t vap_id; + + //socket cert inx + uint8_t socket_cert_inx; + + //ssl ciphers bitmap + uint32_t ssl_ciphers_bitmap; + + //ssl extended ciphers bitmap +#ifdef CHIP_9117 + uint32_t ssl_ext_ciphers_bitmap; + + //! max retransmission timeout value + uint8_t max_retransmission_timeout_value; +#endif + // tcp retry transmission timer + uint8_t tcp_retry_transmit_timer; + + // TCP MSS + uint16_t tcp_mss; + + uint16_t no_of_tls_extensions; + uint16_t total_extension_length; + uint8_t tls_extension_data[MAX_SIZE_OF_EXTENSION_DATA]; +#ifdef CHIP_9117 + uint16_t recv_buff_len; +#endif + +} __attribute__((__packed__)) rsi_req_socket_t; + +// Socket close command request structure +typedef struct rsi_req_socket_close_s { + + // 2 bytes, socket that was closed + uint8_t socket_id[2]; + + // 4 bytes, port number + uint8_t port_number[2]; + +} rsi_req_socket_close_t; + +// socket close command response structure +typedef struct rsi_rsp_socket_close_s { + // 2 bytes, socket that was closed + uint8_t socket_id[2]; + + // 4 bytes, sent bytes count + uint8_t sent_bytes_count[4]; + + // 4 bytes, port number + uint8_t port_number[2]; + +} rsi_rsp_socket_close_t; + +// LTCP socket establish request structure +typedef struct rsi_rsp_ltcp_est_s { + uint8_t ip_version[2]; + + // 2 bytes, socket handle + uint8_t socket_id[2]; + + // 2 bytes, remote port number + uint8_t dest_port[2]; + + union { + + // remote IPv4 Address + uint8_t ipv4_address[4]; + + // remote IPv6 Address + uint8_t ipv6_address[16]; + } dest_ip_addr; + + // 2 bytes, remote peer MSS size + uint8_t mss[2]; + + // 4 bytes, remote peer Window size + uint8_t window_size[4]; + + // source port number + uint8_t src_port_num[2]; + +} rsi_rsp_ltcp_est_t; + +// socket accept request structure +typedef struct rsi_req_socket_accept_s { + // Socket ID + uint8_t socket_id; + + // Local port number + uint8_t source_port[2]; + +} rsi_req_socket_accept_t; +// socket accept request structure +typedef struct rsi_req_socket_select_s { + // Socket ID + uint8_t num_fd; + uint8_t select_id; + + rsi_fd_set rsi_read_fds; + + rsi_fd_set rsi_write_fds; + + struct rsi_timeval rsi_select_timeval; + + uint8_t no_timeout; +} rsi_req_socket_select_t; + +// read bytes coming on socket request structure +typedef struct rsi_req_socket_read_s { + // socket id + uint8_t socket_id; + + // requested bytes + uint8_t requested_bytes[4]; + + // Timeout for read + uint8_t read_timeout[2]; + +} rsi_req_socket_read_t; + +// send data on socket request structure +typedef struct rsi_req_socket_send_s { + + // ip version 4 or 6 + uint8_t ip_version[2]; + + // socket descriptor of the already opened socket connection + uint8_t socket_id[2]; + + // length of the data to be sent + uint8_t length[4]; + + // Data Offset, TCP=44, UDP=32 + uint8_t data_offset[2]; + + // destination port + uint8_t dest_port[2]; + + union { + // 4 bytes, IPv4 Address of the remote device + uint8_t ipv4_address[RSI_IP_ADDRESS_LEN]; + + // 4 bytes, IPv6 Address of the remote device + uint8_t ipv6_address[RSI_IP_ADDRESS_LEN * 4]; + + } dest_ip_addr; + + // data buffer to send + uint8_t send_buffer[RSI_MAX_PAYLOAD_SIZE]; + +} rsi_req_socket_send_t; + +typedef struct rsi_rsp_socket_recv_s { + // 2 bytes, the ip version of the ip address , 4 or 6 + uint8_t ip_version[2]; + + // 2 bytes, the socket number associated with this read event + uint8_t socket_id[2]; + + // 4 bytes, length of data received + uint8_t length[4]; + + // 2 bytes, offset of data from start of buffer + uint8_t offset[2]; + + // 2 bytes, port number of the device sending the data to us + uint8_t dest_port[2]; + + union { + + // 4 bytes, IPv4 Address of the device sending the data to us + uint8_t ipv4_address[4]; + + // 4 bytes, IPv6 Address of the device sending the data to us + uint8_t ipv6_address[16]; + } dest_ip_addr; +#ifdef RSI_PROCESS_MAX_RX_DATA + uint8_t end_of_the_data; + uint8_t more_data_pending; +#endif +} rsi_rsp_socket_recv_t; + +// socket create command response structure +typedef struct rsi_rsp_socket_create_s { + // ip version 4 or 6 + uint8_t ip_version[2]; + + // 2 bytes, type of socket created + uint8_t socket_type[2]; + + // 2 bytes socket descriptor, like a file handle, usually 0x00 + uint8_t socket_id[2]; + + // 2 bytes, Port number of our local socket + uint8_t module_port[2]; + uint8_t dst_port[2]; + union { + + // 4 bytes, Our (module) IPv4 Address + uint8_t ipv4_addr[4]; + + // 4 bytes, Our (module) IPv6 Address + uint8_t ipv6_addr[16]; + + } module_ip_addr; + union { + // 4 bytes, Our (module) IPv4 Address + uint8_t ipv4_addr[4]; + // 4 bytes, Our (module) IPv6 Address + uint8_t ipv6_addr[16]; + } dest_ip_addr; + + // 2 bytes, Remote peer MSS size + uint8_t mss[2]; + + // 4 bytes, Remote peer Window size + uint8_t window_size[4]; + +} rsi_rsp_socket_create_t; + +typedef struct rsi_rsp_socket_select_s { + // select id + uint8_t select_id; + + // readfd struct to store select info + rsi_fd_set rsi_read_fds; + + // readfd struct to store select info + rsi_fd_set rsi_write_fds; + + // readfd struct to store select info + uint32_t socket_terminate_bitmap; +} rsi_rsp_socket_select_t; + +//structure for power save request +typedef struct rsi_power_save_req_s { + // power mode to set + uint8_t power_mode; + + // set LP/ULP/ULP-without RAM retention + uint8_t ulp_mode_enable; + + // set DTIM aligment required + // 0 - module wakes up at beacon which is just before or equal to listen_interval + // 1 - module wakes up at DTIM beacon which is just before or equal to listen_interval + uint8_t dtim_aligned_type; + + //Set PSP type, 0-Max PSP, 1- FAST PSP, 2-APSD + uint8_t psp_type; + + // Monitor interval for the FAST PSP mode + // default is 50 ms, and this parameter is valid for FAST PSP only + uint16_t monitor_interval; + uint8_t num_of_dtim_skip; + uint16_t listen_interval; + +} rsi_power_save_req_t; + +//structure for wmm params +typedef struct rsi_wmm_ps_parms_s { + // wmm ps enable or disable + uint8_t wmm_ps_enable[2]; + + // wmm ps type + uint8_t wmm_ps_type[2]; + + // wmm ps wakeup interval + uint8_t wmm_ps_wakeup_interval[4]; + + // wmm ps UAPSD bitmap + uint8_t wmm_ps_uapsd_bitmap; +} rsi_wmm_ps_parms_t; + +// Structure for TCP ACK indication +typedef struct rsi_rsp_tcp_ack_s { + // Socket ID + uint8_t socket_id; + + // Length + uint8_t length[2]; + +} rsi_rsp_tcp_ack_t; + +// Structure for firmware upgradation +typedef struct rsi_req_fwup_s { + // Type of the packet + uint8_t type[2]; + + // Length of the packet + uint8_t length[2]; + + // RPS content + uint8_t content[RSI_MAX_FWUP_CHUNK_SIZE]; + +} rsi_req_fwup_t; + +// Structure for OTA firmware upgradation +typedef struct rsi_req_ota_fwup_s { + // Type of the packet + uint8_t ip_version; + + union { + // 4 bytes, IPv4 Address of the server + uint8_t ipv4_address[RSI_IP_ADDRESS_LEN]; + + // 4 bytes, IPv6 Address of the server + uint8_t ipv6_address[RSI_IP_ADDRESS_LEN * 4]; + + } server_ip_address; + + // server port + uint8_t server_port[4]; + + // Chunk number + uint8_t chunk_number[2]; + + // Timeout + uint8_t timeout[2]; + + // TCP retry count + uint8_t retry_count[2]; + +} rsi_req_ota_fwup_t; + +//Structure for Timeout +typedef struct rsi_req_timeout_s { + // Timeout bitmap + uint8_t timeout_bitmap[4]; + // Timeout value + uint8_t timeout_value[2]; +} rsi_req_timeout_t; + +//Structure for WLAN filter broadcast packets +typedef struct rsi_req_wlan_filter_bcast_s { + uint8_t beacon_drop_threshold[2]; + + uint8_t filter_bcast_in_tim; + + uint8_t filter_bcast_tim_till_next_cmd; + +} rsi_req_wlan_filter_bcast_t; + +// buffer allocation command parameters +typedef struct { + // tx ratio + uint8_t dynamic_tx_pool; + // rx ratio + uint8_t dynamic_rx_pool; + // global ratio + uint8_t dynamic_global_pool; +} rsi_udynamic; + +#ifdef RSI_WAC_MFI_ENABLE +// Add MFI IE in Beacon command request structure +typedef struct rsi_req_add_mfi_ie_s { + // IE length + uint8_t mfi_ie_len; + + // Actual IE + uint8_t mfi_ie[200]; + +} rsi_req_add_mfi_ie_t; +#endif + +/*===================================================*/ +/** + * HT CAPS Parameters set structure + */ +typedef union { + struct { + uint8_t mode_11n_enable[2]; + uint8_t ht_caps_bitmap[2]; + } htCapsFrameSnd; + uint8_t uHtCapsBuf[4]; +} rsi_uHtCaps; + +/*===================================================*/ +/** + *Structure for rejoin_params + */ +typedef struct rsi_rejoin_params_s { + uint8_t rsi_max_try[4]; + uint8_t rsi_scan_interval[4]; + uint8_t rsi_beacon_missed_count[4]; + uint8_t rsi_first_time_retry_enable[4]; +} rsi_rejoin_params_t; + +/*===================================================*/ +/** + * Roaming Parameters set structure + */ +typedef union { + struct { + uint8_t roam_enable[4]; + uint8_t roam_threshold[4]; + uint8_t roam_hysteresis[4]; + } roamParamsFrameSnd; + uint8_t uRoamParamsBuf[12]; +} rsi_uRoamParams; + +/*==================================================*/ +/*This will keep the wepkey params*/ + +typedef struct { + uint8_t index[2]; + uint8_t key[4][32]; +} rsi_wepkey; + +/*====================================================*/ +/*This will keep the AP configuration parameter*/ + +typedef struct { + uint8_t channel_no[2]; + uint8_t ssid[RSI_SSID_LEN]; + uint8_t security_type; + uint8_t encryp_mode; + uint8_t psk[RSI_PSK_LEN]; + uint8_t beacon_interval[2]; + uint8_t dtim_period[2]; + uint8_t ap_keepalive_type; + uint8_t ap_keepalive_period; + uint8_t max_sta_support[2]; // it can be configured from 1 to 4 +} rsi_apconfig; +// below defines and structure for CFG_GET: Getting user store configuration. +#define IP_ADDRESS_SZ 4 +#define RSI_SSID_LEN 34 +#define WISE_PMK_LEN 32 +#define MAX_HTTP_SERVER_USERNAME 31 +#define MAX_HTTP_SERVER_PASSWORD 31 +#define RSI_PSK_LEN 64 +// structure for cfg_get +typedef struct rsi_cfgGetFrameRcv { + uint8_t cfg_enable; + uint8_t opermode[4]; + uint8_t feature_bit_map[4]; + uint8_t tcp_ip_feature_bit_map[4]; + uint8_t custom_feature_bit_map[4]; + uint8_t band; + uint8_t scan_feature_bitmap; + uint8_t join_ssid[RSI_SSID_LEN]; + uint8_t uRate; + uint8_t uTxPower; + uint8_t reserved_1; + uint8_t reserved_2; + uint8_t scan_ssid_len; + uint8_t reserved_3; + uint8_t csec_mode; + uint8_t psk[RSI_PSK_LEN]; + uint8_t scan_ssid[RSI_SSID_LEN]; + uint8_t scan_cnum; + uint8_t dhcp_enable; + uint8_t ip[IP_ADDRESS_SZ]; + uint8_t sn_mask[IP_ADDRESS_SZ]; + uint8_t dgw[IP_ADDRESS_SZ]; + uint8_t eap_method[32]; + uint8_t inner_method[32]; + uint8_t user_identity[64]; + uint8_t passwd[128]; + uint8_t go_intent[2]; + uint8_t device_name[64]; + uint8_t operating_channel[2]; + uint8_t ssid_postfix[64]; + uint8_t psk_key[64]; + uint8_t pmk[WISE_PMK_LEN]; + rsi_apconfig apconfig; + uint8_t module_mac[6]; + uint8_t antenna_select[2]; + uint8_t reserved_4[2]; + rsi_wepkey wep_key; + uint8_t dhcp6_enable[2]; + uint8_t prefix_length[2]; + uint8_t ip6[16]; + uint8_t dgw6[16]; + uint8_t tcp_stack_used; + uint8_t bgscan_magic_code[2]; + uint8_t bgscan_enable[2]; + uint8_t bgscan_threshold[2]; + uint8_t rssi_tolerance_threshold[2]; + uint8_t bgscan_periodicity[2]; + uint8_t active_scan_duration[2]; + uint8_t passive_scan_duration[2]; + uint8_t multi_probe; + uint8_t chan_bitmap_magic_code[2]; + uint8_t scan_chan_bitmap_stored_2_4_GHz[4]; + uint8_t scan_chan_bitmap_stored_5_GHz[4]; + uint8_t roam_magic_code[2]; + rsi_uRoamParams roam_params_stored; + uint8_t rejoin_magic_code[2]; + rsi_rejoin_params_t rejoin_param_stored; + uint8_t region_request_from_host; + uint8_t rsi_region_code_from_host; + uint8_t region_code; + uint8_t reserved_5[43]; + uint8_t multicast_magic_code[2]; + uint8_t multicast_bitmap[2]; + uint8_t powermode_magic_code[2]; + uint8_t powermode; + uint8_t ulp_mode; + uint8_t wmm_ps_magic_code[2]; + uint8_t wmm_ps_enable; + uint8_t wmm_ps_type; + uint8_t wmm_ps_wakeup_interval[4]; + uint8_t wmm_ps_uapsd_bitmap; + uint8_t listen_interval[4]; + uint8_t listen_interval_dtim; + uint8_t ext_custom_feature_bit_map[4]; + uint8_t private_key_password[82]; + uint8_t join_bssid[6]; + uint8_t join_feature_bitmap; + rsi_uHtCaps ht_caps; + uint8_t ht_caps_magic_word[2]; + uint8_t fast_psp_enable; + uint8_t monitor_interval[2]; + uint8_t request_timeout_magic_word[2]; + uint8_t timeout_value[2]; + uint8_t timeout_bitmap[4]; + // AP IP parameters in Concurrent mode + uint8_t dhcp_ap_enable; + uint8_t ap_ip[4]; + uint8_t ap_sn_mask[4]; + uint8_t ap_dgw[4]; + uint8_t dhcp6_ap_enable[2]; + uint8_t ap_prefix_length[2]; + uint8_t ap_ip6[16]; + uint8_t ap_dgw6[16]; + uint8_t ext_tcp_ip_feature_bit_map[4]; + uint8_t http_credentials_avail; + uint8_t http_username[MAX_HTTP_SERVER_USERNAME]; + uint8_t http_password[MAX_HTTP_SERVER_PASSWORD]; +} rsi_cfgGetFrameRcv_t, rsi_user_store_config_t; + +// user configurable gain table structure +typedef struct rsi_gain_table_info_s { + // band value + uint8_t band; + // bandwidth value + uint8_t bandwidth; + // payload size + uint16_t size; + uint32_t reserved; + // payload + uint8_t gain_table[1]; + +} rsi_gain_table_info_t; + +// ram_dump structure +typedef struct rsi_ram_dump_s { + uint32_t addr; + uint32_t length; +} rsi_ram_dump_t; +// switch protocol structure +typedef struct rsi_switch_proto_s { + uint8_t mode_value; +} rsi_switch_proto_t; + +typedef struct rsi_freq_offset_s { + int32_t freq_offset_in_khz; +} rsi_freq_offset_t; +typedef struct rsi_calib_write_s { +#define BURN_INTO_EFUSE 0 +#define BURN_INTO_FLASH 1 + uint8_t target; + uint8_t reserved0[3]; +#define BURN_GAIN_OFFSET BIT(0) +#define BURN_FREQ_OFFSET BIT(1) +#define SW_XO_CTUNE_VALID BIT(2) +#define BURN_XO_FAST_DISABLE BIT(3) + uint32_t flags; + int8_t gain_offset[3]; + int8_t xo_ctune; +} rsi_calib_write_t; + +// csi config structure +typedef struct rsi_csi_config_s { + // enable/disable CSI data retrieval + uint32_t csi_enable; + // periodicity of CSI data retrieval + uint32_t periodicity; + // number of MAC addresses + uint32_t num_of_mac_addr; + // MAC addresses + uint8_t mac_addresses[1][6]; +} rsi_csi_config_t; + +/****************************************************** + * * Structures + * ******************************************************/ + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +uint8_t *rsi_extract_filename(uint8_t *json, uint8_t *buffer); +void rsi_check_wlan_buffer_full(rsi_pkt_t *pkt); +void rsi_check_common_buffer_full(rsi_pkt_t *pkt); + +void rsi_wlan_packet_transfer_done(rsi_pkt_t *pkt); +int8_t rsi_wlan_cb_init(rsi_wlan_cb_t *wlan_cb); +uint32_t rsi_check_wlan_state(void); +int32_t rsi_wlan_radio_init(void); +void rsi_wlan_set_status(int32_t status); +int32_t rsi_driver_process_wlan_recv_cmd(rsi_pkt_t *pkt); +int32_t rsi_driver_wlan_send_cmd(rsi_wlan_cmd_request_t cmd, rsi_pkt_t *pkt); +int32_t rsi_wlan_check_waiting_socket_cmd(void); +int32_t rsi_wlan_check_waiting_wlan_cmd(void); +void rsi_wlan_process_raw_data(rsi_pkt_t *pkt); +int32_t rsi_wlan_filter_broadcast(uint16_t beacon_drop_threshold, + uint8_t filter_bcast_in_tim, + uint8_t filter_bcast_tim_till_next_cmd); +rsi_error_t rsi_wait_on_wlan_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms); +void rsi_update_wlan_cmd_state_to_progress_state(void); +void rsi_update_wlan_cmd_state_to_free_state(void); +rsi_error_t rsi_wait_on_nwk_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms); +int32_t rsi_wlan_get_nwk_status(void); +void rsi_wlan_set_nwk_status(int32_t status); +int32_t rsi_post_waiting_semaphore(void); +void rsi_call_asynchronous_callback(void); +void rsi_assertion_cb(uint16_t assert_val, uint8_t *buffer, const uint32_t length); +void rsi_max_available_rx_window(uint16_t status, uint8_t *buffer, const uint32_t length); +int32_t send_timeout(uint32_t timeout_bitmap, uint16_t timeout_value); +int32_t rsi_config_timeout(uint32_t timeout_type, uint16_t timeout_value); +#ifdef RSI_ENABLE_DEMOS +void rsi_wlan_app_callbacks_init(void); +void rsi_join_fail_handler(uint16_t status, uint8_t *buffer, const uint32_t length); +void rsi_ip_renewal_fail_handler(uint16_t status, uint8_t *buffer, const uint32_t length); +void rsi_remote_socket_terminate_handler(uint16_t status, uint8_t *buffer, const uint32_t length); +void rsi_ip_change_notify_handler(uint16_t status, uint8_t *buffer, const uint32_t length); +void rsi_stations_connect_notify_handler(uint16_t status, uint8_t *buffer, const uint32_t length); +void rsi_stations_disconnect_notify_handler(uint16_t status, uint8_t *buffer, const uint32_t length); +int32_t rsi_wlan_ping_async(uint8_t flags, + uint8_t *ip_address, + uint16_t size, + void (*wlan_ping_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)); +#endif +#endif diff --git a/wiseconnect/sapi/include/rsi_wlan_apis.h b/wiseconnect/sapi/include/rsi_wlan_apis.h new file mode 100644 index 00000000..4b38c559 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_wlan_apis.h @@ -0,0 +1,1860 @@ +/******************************************************************************* +* @file rsi_wlan_apis.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_WLAN_APIS_H +#define RSI_WLAN_APIS_H + +#include +#include "rsi_user.h" +#ifdef RSI_M4_INTERFACE +#include "base_types.h" +#endif +/****************************************************** + * * Macros + * ******************************************************/ +// To enable A2DP profile +#define A2DP_SOURCE_PROFILE_ENABLE BIT(24) // Added to avoid compilation errors + +// Enable feature +#define RSI_ENABLE 1 +// Disable feature +#define RSI_DISABLE 0 + +// Enable profile config +#define RSI_ENABLE_CFG_PROFILE 2 + +// eap username length +#define RSI_EAP_USER_NAME_LENGTH 64 + +// eap password length +#define RSI_EAP_PASSWORD_LENGTH 128 + +// Macro to mandate CA_CERT requirement in PEAP connection +#define CA_CERT_REQUIRED BIT(1) + +//EAP cipher suites list +#define DHE_RSA_AES256_SHA256 BIT(2) +#define DHE_RSA_AES128_SHA256 BIT(3) +#define DHE_RSA_AES256_SHA BIT(4) +#define DHE_RSA_AES128_SHA BIT(5) +#define AES256_SHA256 BIT(6) +#define AES128_SHA256 BIT(7) +#define AES256_SHA BIT(8) +#define AES128_SHA BIT(9) +#define RC4_SHA BIT(10) +#define DES_CBC3_SHA BIT(11) +#define RC4_MD5 BIT(12) + +// total no of sockets +#define RSI_MN_NUM_SOCKETS 10 + +// max no of stations +#define RSI_MAX_STATIONS 8 + +// Maximum length of SSID +#define RSI_SSID_LEN 34 + +#define RSI_PSK_LEN 64 +#define RSI_PMK_LEN 32 + +// Maximum Acccess points that can be scanned +#define RSI_AP_SCANNED_MAX 11 + +// MAC address length +#define RSI_MAC_ADDR_LEN 6 + +// Maximum wifi direct device count +#define RSI_MAX_WFD_DEVICE_COUNT 10 + +#define RSI_INSTANT_BGSCAN 1 + +#define RSI_BGSCAN_STOP 0 + +// To provide additional scan results to host +#define RSI_SCAN_RESULTS_TO_HOST BIT(1) +// feature bit map +/*=========================================================================*/ +// Securtity type open +#define FEAT_SECURITY_OPEN BIT(0) + +// Securtity type WPA/WPA2 +#define FEAT_SECURITY_PSK BIT(1) + +// Aggregation support +#define FEAT_AGGREGATION BIT(2) + +// LP mode GPIO handshake +#define FEAT_LP_GPIO_BASED_HANDSHAKE BIT(3) + +// ULP mode GPIO based handshake +#define FEAT_ULP_GPIO_BASED_HANDSHAKE BIT(4) + +// To select ULP GPIO 1 for wake up indication +#define FEAT_DEV_TO_HOST_ULP_GPIO_1 BIT(5) + +// To supply 3.3 volt supply +#define FEAT_RF_SUPPY_VOL_3_3_VOLT BIT(6) + +// To Disable WPS in AP mode +#define FEAT_WPS_DISABLE BIT(7) + +// To enable EAP-LEAP mode +#define FEAT_EAP_LEAP_IN_COEX BIT(8) + +// To hide sensitive information (PSK, PMK, EAP credentials) +#define FEAT_HIDE_PSK_CREDENTIALS BIT(9) + +//To enable high SSL streaming throughput +#define SSL_HIGH_STREAMING_BIT BIT(10) +/*=========================================================================*/ + +// BT feature bit map +/*=========================================================================*/ +#define BT_BDR_MODE_ENABLE BIT(0) +#define BT_BDR_MODE_LP_CHAIN_ENABLE BIT(1) +//!TA based encoder +#define TA_BASED_ENCODER_ENABLE BIT(14) +//! To enable HFP profile +#define HFP_PROFILE_ENABLE BIT(15) +//! To enable A2DP profile +#define A2DP_PROFILE_ENABLE BIT(23) +//! To enable A2DP Profile role as source/sink +#define A2DP_SOURCE_ROLE_ENABLE BIT(24) +//! To enable A2DP Accelerator mode +#define A2DP_ACCELERATOR_MODE_ENABLE BIT(25) +//! To enable Buffer Alignment for Test Mode +#define BT_BLE_CP_BUFF_SIZE BIT(27) +//! To bt rf type +#define BT_RF_TYPE BIT(30) +//! To enable ble protocol +#define ENABLE_BLE_PROTOCOL BIT(31) +/*=========================================================================*/ + +// TCP/IP feature bit map parameters description !// +/*=========================================================================*/ +// TCP/IP bypass feature +#define TCP_IP_FEAT_BYPASS BIT(0) + +// Enable HTTP server feature +#define TCP_IP_FEAT_HTTP_SERVER BIT(1) + +// Enable DHCPv4 client feature +#define TCP_IP_FEAT_DHCPV4_CLIENT BIT(2) + +// Enable DHCPv6 client feature +#define TCP_IP_FEAT_DHCPV6_CLIENT BIT(3) + +// Enable DHCPv4 server feature +#define TCP_IP_FEAT_DHCPV4_SERVER BIT(4) + +// Enable DHCPv6 server feature +#define TCP_IP_FEAT_DHCPV6_SERVER BIT(5) + +// Enable JSON objects +#define TCP_IP_FEAT_JSON_OBJECTS BIT(6) + +// Enable HTTP client +#define TCP_IP_FEAT_HTTP_CLIENT BIT(7) + +// Enable DNS client +#define TCP_IP_FEAT_DNS_CLIENT BIT(8) + +// Enable SNMP client +#define TCP_IP_FEAT_SNMP_AGENT BIT(9) + +// Enable SSL feature +#define TCP_IP_FEAT_SSL BIT(10) + +// Enable ICMP feature(ping) +#define TCP_IP_FEAT_ICMP BIT(11) + +// Enable HTTP client +#define TCP_IP_FEAT_HTTPS_SERVER BIT(12) + +// Enable sending web page configuration to host from wireless config page +#define TCP_IP_FEAT_SEND_CONFIGS_TO_HOST BIT(14) + +// Enable FTP client +#define TCP_IP_FEAT_FTP_CLIENT BIT(15) + +// Enable SNTP client +#define TCP_IP_FEAT_SNTP_CLIENT BIT(16) + +// Enable IPV6 support +#define TCP_IP_FEAT_IPV6 BIT(17) + +// Enable Raw data support +#define TCP_IP_FEAT_RAW_DATA BIT(18) + +// Enable MDNSD +#define TCP_IP_FEAT_MDNSD BIT(19) + +// Enable SMTP client +#define TCP_IP_FEAT_SMTP_CLIENT BIT(20) + +// Enable Single SSL socket +#define TCP_IP_FEAT_SINGLE_SSL_SOCKET BIT(25) + +// Enable to Load public and private keys for TLS and SSL handshake +#define TCP_IP_FEAT_LOAD_PUBLIC_PRIVATE_CERTS BIT(26) + +// Enable to Load SSL certificates in to RAM +#define TCP_IP_FEAT_LOAD_CERTS_INTO_RAM BIT(27) + +// Enable POP3 client +#define TCP_IP_FEAT_POP3_CLIENT BIT(29) + +// Enable OTAF client +#define TCP_IP_FEAT_OTAF BIT(30) + +#define TCP_IP_FEAT_EXTENSION_VALID BIT(31) + +// Extended TCP/IP feature bit map parameters description !// +/*=========================================================================*/ +#define EXT_TCP_FEAT_DHCP_OPT77 BIT(1) + +// Enable HTTP server root path (Default configuration page) bypass +#define EXT_TCP_IP_HTTP_SERVER_BYPASS BIT(2) + +// TCP bi-dir ack update +#define EXT_TCP_IP_BI_DIR_ACK_UPDATE BIT(3) + +// TCP RX window division +#define EXT_TCP_IP_WINDOW_DIV BIT(4) + +// SSL server certificate bypass, validation from the host +#define EXT_TCP_IP_CERT_BYPASS BIT(5) + +// SSL 16K record size support +#define EXT_TCP_IP_SSL_16K_RECORD BIT(6) + +// Enable DNS client byass +#define EXT_TCP_IP_DNS_CLIENT_BYPASS BIT(7) + +// Enable TCP window scaling feature +#define EXT_TCP_IP_WINDOW_SCALING BIT(8) + +// Enables both TCP/IP bypass mode & embedded modes +#define EXT_TCP_IP_DUAL_MODE_ENABLE BIT(9) + +// Enables Ethernet to WIFI bridge +#define EXT_TCP_IP_ETH_WIFI_BRIDGE BIT(10) + +// Enables the Dynamic coex memory +#define EXT_DYNAMIC_COEX_MEMORY BIT(11) +#define EXT_TCP_IP_WAIT_FOR_SOCKET_CLOSE BIT(16) +// Enable Embedded/internal MQTT +#define EXT_EMB_MQTT_ENABLE BIT(17) +#define EXT_TCP_IP_TOTAL_SELECTS_1 (1 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_2 (2 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_3 (3 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_4 (4 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_5 (5 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_6 (6 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_7 (7 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_8 (8 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_9 (9 << 12) +#define EXT_TCP_IP_TOTAL_SELECTS_10 (10 << 12) + +// Enables the SSL_HIGH_PERFORMANCE +#define EXT_TCP_IP_FEAT_SSL_HIGH_PERFORMANCE BIT(18) + +// Enabled to update TCP window from host +#define EXT_TCP_DYNAMIC_WINDOW_UPDATE_FROM_HOST BIT(19) +#define EXT_TCP_MAX_RECV_LENGTH BIT(20) + +#define EXT_TCP_IP_FEAT_SSL_THREE_SOCKETS BIT(29) +#define EXT_TCP_IP_FEAT_SSL_MEMORY_CLOUD BIT(30) +#define CONFIG_FEAT_EXTENTION_VALID BIT(31) + +// Select No of sockets +#define TCP_IP_TOTAL_SOCKETS_1 (1 << 21) +#define TCP_IP_TOTAL_SOCKETS_2 (2 << 21) +#define TCP_IP_TOTAL_SOCKETS_3 (3 << 21) +#define TCP_IP_TOTAL_SOCKETS_4 (4 << 21) +#define TCP_IP_TOTAL_SOCKETS_5 (5 << 21) +#define TCP_IP_TOTAL_SOCKETS_6 (6 << 21) +#define TCP_IP_TOTAL_SOCKETS_7 (7 << 21) +#define TCP_IP_TOTAL_SOCKETS_8 (8 << 21) +#define TCP_IP_TOTAL_SOCKETS_9 (9 << 21) +#define TCP_IP_TOTAL_SOCKETS_10 (10 << 21) +/*=========================================================================*/ + +// Custom feature bit map paramters description !// +/*=========================================================================*/ + +// Disables gateway config sent to STA from RSI AP +#define CUSTOM_FEAT_DISABLE_GATEWAY_IN_RSI_AP BIT(2) + +// To configure the clock for NWP SOC 160Mhz +// If higher performance is needed(like High throughput) +// then this configuration is needed +#define CUSTOM_FEAT_SOC_CLK_CONFIG_160MHZ BIT(4) +// If this bit is set, AP is created in hidden mode +// This bit is valid only in case of AP mode +#define CUSTOM_FEAT_AP_IN_HIDDEN_MODE BIT(5) + +// DNS server IP address in DHCP offer response in AP mode +#define CUSTOM_FEAT_DNS_SERVER_IN_DHCP_OFFER BIT(6) + +// Support for scanning in DFS channels() in 5GHZ band +// This bit is valid in WiFi client mode +#define CUSTOM_FEAT_DFS_CHANNEL_SUPPORT BIT(8) + +// If this bit is set it enables the LED blinking feature +// after module initialisation.LED (GPIO_16) is used for +// this feature and blinks when any TX Packet on air happens +// and when we get a unicast packets addressing to our MAC +#define CUSTOM_FEAT_LED_FEATURE BIT(9) + +// If this bit is enabled,module indicates the host +// the wlan connection status asynchronously +// This bit is valid in case of Wifi client mode +#define CUSTOM_FEAT_ASYNC_CONNECTION_STATUS BIT(10) + +// Wake on wireless indication in UART mode +#define CUSTOM_FEAT_WAKE_ON_WIRELESS BIT(11) + +// Enables AP blacklisting in STA mode +#define CUSTOM_FEAT_ENABLE_AP_BLACKLIST BIT(12) + +// Number of clients to support in AP/WFD mode +#define MAX_NUM_OF_CLIENTS 1 +#define CUSTOM_FEAT_MAX_NUM_OF_CLIENTS ((MAX_NUM_OF_CLIENTS & 0xF) << 13) + +// select between de-authentication or null data (with power management bit set) based roaming. +#define CUSTOM_FEAT_ROAM_WITH_DEAUTH_OR_NULLDATA BIT(17) + +// Trigger Auto Configuration +#define CUSTOM_FEAT_TRIGGER_AUTO_CONFIG BIT(20) + +// In AP mode, If set only two packets per STA will be buffered when STA is in PS +#define CUSTOM_FEAT_LIMIT_PACKETS_PER_STA BIT(22) + +#define CUSTOM_FEAT_HTTP_HTTPS_AUTH BIT(23) + +// To configure the clock for NWP SOC 120Mhz +// If higher performance is needed(like High throughput) +// then this configuration is needed +#define CUSTOM_FEAT_SOC_CLK_CONFIG_120MHZ BIT(24) + +// HTTP server credentials to host in get configuration command +#define CUSTOM_FEAT_HTTP_SERVER_CRED_TO_HOST BIT(25) + +// For a LTCP socket when maximum clients are connected if a new connection request is received, then this connection request will be rejected immediately +#define CUSTOM_FEAT_REJECT_CONNECT_REQ_IMMEDIATELY BIT(26) + +// Enables Dual band roaming and vcsafd feature +#define CUSTOM_FEAT_DUAL_BAND_ROAM_VCSAFD BIT(27) + +// Real time clock from host +#define CUSTOM_FEAT_RTC_FROM_HOST BIT(28) + +#define CUSTOM_FEAT_BT_IAP BIT(29) + +// Extention valid to use Extended custom feature bitmap +#define FEAT_CUSTOM_FEAT_EXTENTION_VALID BIT(31) + +/*=========================================================================*/ + +// Extended custom feature bitmap !// +/*=========================================================================*/ +// To support 4096 size RSA KEY certificate +#define EXT_FEAT_RSA_KEY_WITH_4096_SUPPORT BIT(1) + +// Extended custom bitmap to support TELEC +#define EXT_FEAT_TELEC_SUPPORT BIT(2) + +// To support 4096 size KEY SSL certificate +#define EXT_FEAT_SSL_CERT_WITH_4096_KEY_SUPPORT BIT(3) + +// Extended custom bitmap for AP Broadcast customization +#define EXT_FEAT_AP_BROADCAST_PKT_SND_B4_DTIM BIT(4) + +// Extended custom bitmap to support FCC +#define EXT_FEAT_FCC_LOW_PWR BIT(5) + +// To enable PUF +#define EXT_FEAT_PUF BIT(7) + +// Nokia Spectral mask extended custom bitmap +#define EXT_FEAT_SPECTRAL_MASK_NOKIA BIT(8) + +// Extended feature bit map to skip default leading character '\' in HTTP header +#define EXT_HTTP_SKIP_DEFAULT_LEADING_CHARACTER BIT(9) + +// To enable PUF private key +#define EXT_FEAT_PUF_PRIVATE_KEY BIT(10) + +// To enable 802.11R Over The Air Roaming +#define EXT_FEAT_ENABLE_11R_OTA BIT(11) + +// To enable 802.11J protocol +#define EXT_FEAT_IEEE_80211J BIT(12) + +// To enable 802.11W protocol +#define EXT_FEAT_IEEE_80211W BIT(13) + +// To enable the Multiverion TCP over SSL support +#define EXT_FEAT_SSL_VERSIONS_SUPPORT BIT(14) + +// To Enable 16 client support +#define EXT_FEAT_16th_STATION_IN_AP_MODE BIT(15) + +// To enable 802.11R Over the Distribution System Roaming +#define EXT_FEAT_ENABLE_11R_ODS BIT(16) + +// To enable low power mode in Wlan +#define EXT_FEAT_LOW_POWER_MODE BIT(19) + +// To enable http otaf support +#define EXT_FEAT_HTTP_OTAF_SUPPORT BIT(18) + +#ifdef CHIP_9117B0 + +#define EXT_FEAT_352K_M4SS_320K 0 +#define RAM_LEVEL_NWP_BASIC_MCU_ADV EXT_FEAT_352K_M4SS_320K + +// To enable 416K memory for TA +#define EXT_FEAT_416K_M4SS_256K BIT(21) +#define RAM_LEVEL_NWP_MEDIUM_MCU_MEDIUM EXT_FEAT_416K_M4SS_256K + +// To enable 480K memory for TA +#define EXT_FEAT_480K_M4SS_192K BIT(20) +#define RAM_LEVEL_NWP_ADV_MCU_BASIC EXT_FEAT_480K_M4SS_192K + +#ifndef RSI_M4_INTERFACE +// To enable 672K memory for TA; only supported in WiSeConnect +#define EXT_FEAT_672K_M4SS_0K (BIT(20) | BIT(21)) +#define RAM_LEVEL_NWP_ALL_MCU_ZERO EXT_FEAT_672K_M4SS_0K +#endif + +#elif (defined CHIP_9117) + +#define EXT_FEAT_256K_MODE 0 +#define RAM_LEVEL_NWP_BASIC_MCU_ADV EXT_FEAT_256K_MODE + +// To enable 448K memory for TA +#define EXT_FEAT_448K_M4SS_256K BIT(21) +#define RAM_LEVEL_NWP_MEDIUM_MCU_MEDIUM EXT_FEAT_448K_M4SS_256K + +// To enable 512K memory for TA +#define EXT_FEAT_512K_M4SS_192K BIT(20) +#define RAM_LEVEL_NWP_ADV_MCU_BASIC EXT_FEAT_512K_M4SS_192K + +#ifndef RSI_M4_INTERFACE +// To enable 704K memory for TA; only supported in WiSeConnect +#define EXT_FEAT_704K_M4SS_0K (BIT(20) | BIT(21)) +#define RAM_LEVEL_NWP_ALL_MCU_ZERO EXT_FEAT_704K_M4SS_0K +#endif + +#else //defaults + +// To enable 256K memory for TA +#define EXT_FEAT_256K_MODE BIT(21) +#define RAM_LEVEL_NWP_MEDIUM_MCU_MEDIUM EXT_FEAT_256K_MODE + +// To enable 320K memory for TA +#define EXT_FEAT_320K_MODE BIT(20) +#define RAM_LEVEL_NWP_ADV_MCU_BASIC EXT_FEAT_320K_MODE + +// To enable 384K memory for TA +#define EXT_FEAT_384K_MODE (BIT(20) | BIT(21)) +#define RAM_LEVEL_NWP_ALL_MCU_ZERO EXT_FEAT_384K_MODE + +#endif + +// To enable CRYSTAL for TA +// For 9117 EVK set EXT_FEAT_XTAL_CLK_ENABLE to BIT(22) +#ifdef CHIP_9117 +#if ((defined BRD4325A) || (defined EXP_BOARD)) +#define EXT_FEAT_XTAL_CLK_ENABLE BIT(23) +#else +#define EXT_FEAT_XTAL_CLK_ENABLE BIT(22) +#endif +#else +#if (RS9116_SILICON_CHIP_VER == CHIP_VER_1P4_AND_ABOVE) +#define EXT_FEAT_XTAL_CLK_ENABLE BIT(23) +#else +#define EXT_FEAT_XTAL_CLK_ENABLE BIT(22) +#endif +#endif + +// To intimate FW not to modify MDNS text record +#define EXT_FEAT_HOMEKIT_WAC_ENABLED BIT(24) + +// To enable 1.8v support for TA +#define EXT_FEAT_1P8V_SUPPORT BIT(25) + +// To select UART debug prints pin selection +// If BIT(27) is enabled,Debug prints are supported on UART1 +// If BIT(27) is disabled,Debug prints are supported on UART2 +#define EXT_FEAT_UART_SEL_FOR_DEBUG_PRINTS BIT(27) + +// If this bit is enabled,NWP disables Debug prints support +#define EXT_FEAT_DISABLE_DEBUG_PRINTS BIT(28) + +// config feature bitmap +/*=========================================================================*/ +#define RSI_FEAT_SLEEP_GPIO_SEL_BITMAP BIT(0) +// DVS Dynamic Voltage Selection +#define RSI_FEAT_DVS_SEL_CONFIG_1 BIT(2) +#define RSI_FEAT_DVS_SEL_CONFIG_2 BIT(3) +#define RSI_FEAT_DVS_SEL_CONFIG_3 BIT(4) +#define RSI_FEAT_DVS_SEL_CONFIG_4 BIT(5) +// External PMU Selection +#define RSI_EXTERNAL_PMU_GOOD_TIME_100us BIT(6) +#define RSI_EXTERNAL_PMU_GOOD_TIME_200us BIT(7) +#define RSI_EXTERNAL_PMU_GOOD_TIME_300us (BIT(6) | BIT(7)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_400us BIT(8) +#define RSI_EXTERNAL_PMU_GOOD_TIME_500us (BIT(6) | BIT(8)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_600us (BIT(7) | BIT(8)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_700us (BIT(6) | BIT(7) | BIT(8)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_800us BIT(9) +#define RSI_EXTERNAL_PMU_GOOD_TIME_900us (BIT(6) | BIT(9)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_1000us (BIT(7) | BIT(9)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_1100us (BIT(6) | BIT(7) | BIT(9)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_1200us (BIT(8) | BIT(9)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_1300us (BIT(6) | BIT(8) | BIT(9)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_1400us (BIT(7) | BIT(8) | BIT(9)) +#define RSI_EXTERNAL_PMU_GOOD_TIME_1500us (BIT(6) | BIT(7) | BIT(8) | BIT(9)) +// Extrenal LDO voltage selection +#define RSI_FEAT_EXTERNAL_LDO_SEL BIT(10) +// This field valid only if RSI_FEAT_EXTERNAL_LDO_SEL is enabled i.e BIT(10) is set +// if this bit set means 1.0V selected else 1.1V selected +#define RSI_FEAT_EXTERNAL_LDO_VOL BIT(11) +// TLS version selection +#define RSI_FEAT_EAP_TLS_V1P0 BIT(14) +#define RSI_FEAT_EAP_TLS_V1P2 BIT(15) +#define FEAT_CONC_STA_AP_DYN_SWITCH_SEL BIT(17) +#define ULP_GPIO9_FOR_UART2_TX BIT(18) +#define RSI_FEAT_DISABLE_MCS_5_6_7_DATARATES BIT(19) +#define RSI_FEAT_DISABLE_SHORT_GI BIT(20) +//! XTAL goodtime configurations +#define RSI_XTAL_GOODTIME_1000us 0 +#define RSI_XTAL_GOODTIME_2000us BIT(24) +#define RSI_XTAL_GOODTIME_3000us BIT(25) +#define RSI_XTAL_GOODTIME_600us (BIT(24) | BIT(25)) + +#define ENABLE_ENHANCED_MAX_PSP BIT(26) +#define ENABLE_DEBUG_BBP_TEST_PINS BIT(27) +/*=========================================================================*/ + +/*=========================================================================*/ +// Feature enable paramters +#define RSI_FEAT_FRAME_PREAMBLE_DUTY_CYCLE BIT(0) +#define RSI_FEAT_FRAME_PERMIT_UNDESTINED_PACKETS BIT(1) +#define RSI_FEAT_FRAME_DISABLE_DPD BIT(3) +#define RSI_FEAT_FRAME_LP_CHAIN BIT(4) +#define RSI_FEAT_FRAME_IN_PACKET_DUTY_CYCLE BIT(5) +/*=========================================================================*/ + +// BAND COMMAND PARAMETERS OPTIONS +/*=========================================================================*/ + +// module operates in 2.4GHz band +#define RSI_BAND_2P4GHZ 0 + +// Module operates in 5GHz band +#define RSI_BAND_5GHZ 1 + +// Module operates in 4.9GHz band +#define RSI_BAND_4_9GHZ 1 + +// Module opertes in both 2.4GHz and 5GHz band +// This option is valid only in case of Wifi-Direct +// and WiFi client mode +#define RSI_DUAL_BAND 2 + +/*=========================================================================*/ + +// SCAN COMMAND PARAMETERS OPTIONS +/*=========================================================================*/ + +// Scan feature bitmap parameters !// + +// If this bit is set,module scans for the AP given in scan API +// and posts the scan results immediately to the host after finding +// one Accesspoint.This bit is valid only if specific channel and +// ssid to scan is given. +#define RSI_ENABLE_QUICK_SCAN BIT(0) + +// Timeout bitmap parameters !// + +//Set timeout for association and authentication request in msec +#define RSI_ASSOCIATION_AND_AUTHENTICATION_TIMEOUT_MSEC BIT(0) + +//Set each channel active scan time in msec +#define RSI_CHANNEL_SCAN_TIME_MSEC BIT(1) + +//Used for WLAN keep alive timeout in sec +#define RSI_WLAN_KEEP_ALIBE_TIMEOUT_SEC BIT(2) + +/*=========================================================================*/ + +// ACCESS POINT CONFIGURATION PARAMETERS DESCRIPTIONS +/*=========================================================================*/ + +// AP keep alive type bit !// + +// If this bit is enabled, AP performs keep alive functionality +// by sending NULL DATA packet to the station. If no ACK is received +// from the station after specific no of retries, AP discards the station +#define RSI_NULL_BASED_KEEP_ALIVE (BIT(0) | BIT(1)) + +// If this bit is enabled, AP performs keep alive functionality +// based on the rx packets received from its stations. If no packet is +// received from the station with in time out, AP discards it +#define RSI_DEAUTH_BASED_KEEP_ALIVE BIT(0) + +// HT capabilities bitmap paramters !// +// Bit map corresponding to high throughput capabilities +// HT capabilities bitmap is valid only if HT capabilites RSI_ENABLE_HT_CAPABILITIES +// macro is enabled. + +// If this bit is set,Short GI support for 20Mhz band width +#define RSI_ENABLE_SHORT_GI BIT(5) + +// If these bit is set, RX STBC support is enabled in AP mode +#define RSI_ENABLE_RX_STBC_SUPPORT (BIT(8) | ~BIT(9)) + +// If these bit is set, Green field support is enabled in AP mode +#define RSI_ENABLE_GREEN_FIELD_SUPPORT BIT(4) + +/*=========================================================================*/ + +#define AUTH_ASSOC_TIMEOUT 1 +#define CHANNEL_ACTIVE_SCAN_TIMEOUT 2 +#define KEEP_ALIVE_TIMEOUT 3 + +// JOIN COMMAND PARAMETERS OPTIONS +/*=========================================================================*/ + +// Tx Power level !// +// Low Tx power level +// (7+/-1)dBm in 2.4GHz band +// (5+/-1)dBm in 5GHz band +#define RSI_POWER_LEVEL_LOW 0 + +// Medium Tx power level !// +// (5+/-1)dBm in 2.4GHz band +// (7+/-1)dBm in 5GHz band +#define RSI_POWER_LEVEL_MEDIUM 1 + +// High Tx power level !// +// Highest power that can be +// used in that channel +#define RSI_POWER_LEVEL_HIGH 2 + +// To enable b/g only mode in station mode +#define RSI_JOIN_FEAT_STA_BG_ONLY_MODE_ENABLE BIT(0) + +// To take listen interval from join command. +#define RSI_JOIN_FEAT_LISTEN_INTERVAL_VALID BIT(1) + +// To enable quick join feature +#define RSI_JOIN_FEAT_QUICK_JOIN BIT(2) + +//To enable CCXV2 feature +#define RSI_JOIN_FEAT_CCXV2_FEATURE BIT(3) + +//To connect to AP based on BSSID together with configured SSID +#define RSI_JOIN_FEAT_BSSID_BASED BIT(4) + +// MFP Type +#define RSI_JOIN_FEAT_MFP_CAPABLE_ONLY BIT(5) +#define RSI_JOIN_FEAT_MFP_CAPABLE_REQUIRED (BIT(5) | BIT(6)) + +// listen interval from power save command +#define RSI_JOIN_FEAT_PS_CMD_LISTEN_INTERVAL_VALID BIT(7) + +/* ER_SU configuration parameters */ +#define NO_ER_SU_SUPPORT 0 +#define ER_SU_WITH_NON_ER_SU 1 +#define ER_SU_ONLY 2 + +// DATA Rates used // +#define RSI_DATA_RATE_AUTO 0 +#define RSI_DATA_RATE_1 1 +#define RSI_DATA_RATE_2 2 +#define RSI_DATA_RATE_5P5 3 +#define RSI_DATA_RATE_11 4 +#define RSI_DATA_RATE_6 5 +#define RSI_DATA_RATE_9 6 +#define RSI_DATA_RATE_12 7 +#define RSI_DATA_RATE_18 8 +#define RSI_DATA_RATE_24 9 +#define RSI_DATA_RATE_36 10 +#define RSI_DATA_RATE_48 11 +#define RSI_DATA_RATE_54 12 +#define RSI_DATA_RATE_MCS0 13 +#define RSI_DATA_RATE_MCS1 14 +#define RSI_DATA_RATE_MCS2 15 +#define RSI_DATA_RATE_MCS3 16 +#define RSI_DATA_RATE_MCS4 17 +#define RSI_DATA_RATE_MCS5 18 +#define RSI_DATA_RATE_MCS6 19 +#define RSI_DATA_RATE_MCS7 20 +#define RSI_DATA_RATE_HE_MCS0 21 +#define RSI_DATA_RATE_HE_MCS1 22 +#define RSI_DATA_RATE_HE_MCS2 23 +#define RSI_DATA_RATE_HE_MCS3 24 +#define RSI_DATA_RATE_HE_MCS4 25 +#define RSI_DATA_RATE_HE_MCS5 26 +#define RSI_DATA_RATE_HE_MCS6 27 +#define RSI_DATA_RATE_HE_MCS7 28 +/*=========================================================================*/ + +// Multicast filter cmds +/*=========================================================================*/ +#define RSI_MULTICAST_MAC_CLEAR_ALL 2 +#define RSI_MULTICAST_MAC_SET_ALL 3 + +/*=========================================================================*/ + +// SSL features +/*=========================================================================*/ + +//Release 2.0 default ciphers +#define SSL_DEFAULT_CIPHERS \ + (BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 | BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 \ + | BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 | BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 \ + | BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 | BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 \ + | BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA | BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA \ + | BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA | BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA \ + | BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA | BIT_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA \ + | BIT_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA | BIT_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA) +//Release 2.0 all configurable ciphers +#define SSL_RELEASE_2_0_ALL_CIPHERS \ + (SSL_DEFAULT_CIPHERS | BIT_TLS_RSA_WITH_AES_256_CBC_SHA256 | BIT_TLS_RSA_WITH_AES_128_CBC_SHA256 \ + | BIT_TLS_RSA_WITH_AES_256_CBC_SHA | BIT_TLS_RSA_WITH_AES_128_CBC_SHA | BIT_TLS_RSA_WITH_AES_128_CCM_8 \ + | BIT_TLS_RSA_WITH_AES_256_CCM_8) + +#ifdef CHIP_9117 +#define RSI_SSL_EXT_CIPHERS SSL_TLSV1_3_ALL_CIPHERS +#endif + +#define SSL_ALL_CIPHERS SSL_RELEASE_2_0_ALL_CIPHERS + +//TLSv1.3 configurable ciphers +#ifdef CHIP_9117 +#define SSL_TLSV1_3_ALL_CIPHERS \ + (BIT_TLS13_AES_128_GCM_SHA256 | BIT_TLS13_AES_256_GCM_SHA384 | BIT_TLS13_CHACHA20_POLY1305_SHA256 \ + | BIT_TLS13_AES_128_CCM_SHA256 | BIT_TLS13_AES_128_CCM_8_SHA256) +#endif + +//DHE_RSA in combination with CBC secure ciphers +#define BIT_DHE_RSA_CBC (BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 | BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256) +//ECDHE_RSA in combination with CBC secure ciphers +#define BIT_ECDHE_RSA_CBC (BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 | BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) +//ECDHE_ECDSA in combination with CBC secure ciphers +#define BIT_ECDHE_ECDSA_CBC (BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 | BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256) +//DHE_RSA in combination with GCM secure ciphers +#define BIT_DHE_RSA_GCM (BIT_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 | BIT_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384) +//ECDHE_RSA in combination with GCM secure ciphers +#define BIT_ECDHE_RSA_GCM (BIT_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 | BIT_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) + +#define BIT_TLS_RSA_WITH_AES_256_CBC_SHA256 BIT(0) +#define BIT_TLS_RSA_WITH_AES_128_CBC_SHA256 BIT(1) +#define BIT_TLS_RSA_WITH_AES_256_CBC_SHA BIT(2) +#define BIT_TLS_RSA_WITH_AES_128_CBC_SHA BIT(3) +#define BIT_TLS_RSA_WITH_AES_128_CCM_8 BIT(4) +#define BIT_TLS_RSA_WITH_AES_256_CCM_8 BIT(5) +#define BIT_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 BIT(8) +#define BIT_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 BIT(9) +#define BIT_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 BIT(10) +#define BIT_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 BIT(11) +#define BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 BIT(14) +#define BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 BIT(15) +#define BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA BIT(16) +#define BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA BIT(17) +#define BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 BIT(18) +#define BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 BIT(19) +#define BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA BIT(20) +#define BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA BIT(21) +#define BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 BIT(22) +#define BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 BIT(23) +#define BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA BIT(24) +#define BIT_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA BIT(25) +#define BIT_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA BIT(26) +#define BIT_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA BIT(27) +#define SSL_NEW_CIPHERS BIT(31) + +// TLSv1.3 supported ciphers +#ifdef CHIP_9117 +#define BIT_TLS13_AES_128_GCM_SHA256 BIT(0) +#define BIT_TLS13_AES_256_GCM_SHA384 BIT(1) +#define BIT_TLS13_CHACHA20_POLY1305_SHA256 BIT(2) +#define BIT_TLS13_AES_128_CCM_SHA256 BIT(3) +#define BIT_TLS13_AES_128_CCM_8_SHA256 BIT(4) +#endif + +/*=========================================================================*/ + +// ssl version +#define RSI_SSL_V_1_0 BIT(2) +#define RSI_SSL_V_1_2 BIT(3) +#define RSI_SSL_V_1_1 BIT(4) +#ifdef CHIP_9117 +#define RSI_SSL_V_1_3 BIT(8) +#endif + +// socket feature +/*=======================================================================*/ + +// Type of service. possible values are 0 to 7 +#define RSI_TOS 0 + +// power save handshake types +/*=======================================================================*/ +// Type of service. possible values are 0 to 7 +#define MSG_BASED 1 +#define GPIO_BASED 2 +#define M4_BASED 3 + +/*=======================================================================*/ + +// PER mode values +/*=======================================================================*/ +// Possible data rates +#define RSI_RATE_1 0x0 +#define RSI_RATE_2 0x2 +#define RSI_RATE_5_5 0x4 +#define RSI_RATE_11 0x6 +#define RSI_RATE_6 0x8b +#define RSI_RATE_9 0x8f +#define RSI_RATE_12 0x8a +#define RSI_RATE_18 0x8e +#define RSI_RATE_24 0x89 +#define RSI_RATE_36 0x8d +#define RSI_RATE_48 0x88 +#define RSI_RATE_54 0x8c +#define RSI_RATE_MCS0 0x100 +#define RSI_RATE_MCS1 0x101 +#define RSI_RATE_MCS2 0x102 +#define RSI_RATE_MCS3 0x103 +#define RSI_RATE_MCS4 0x104 +#define RSI_RATE_MCS5 0x105 +#define RSI_RATE_MCS6 0x106 +#define RSI_RATE_MCS7 0x107 +#define RSI_RATE_MCS7_SG 0x307 + +/*=========================================================================*/ + +/*=========================================================================*/ + +// Transmit test supported modes +#define RSI_BURST_MODE 0 +#define RSI_CONTINUOUS_MODE 1 +#define RSI_CONTINUOUS_WAVE_MODE_2 2 +#define RSI_CONTINUOUS_WAVE_MODE_3 3 +#define RSI_CONTINUOUS_WAVE_MODE_4 4 + +/*=======================================================================*/ + +// Power save LP/ULP sleep type +/*=======================================================================*/ +#define RSI_LP_MODE 0 +#define RSI_ULP_WITH_RAM_RET 1 +#define RSI_ULP_WITHOUT_RAM_RET 2 + +/*=======================================================================*/ + +/*=======================================================================*/ + +// HT caps supported +#define RSI_HT_CAPS_NUM_RX_STBC (1 << 8) +#define RSI_HT_CAPS_SHORT_GI_20MHZ BIT(5) +#define RSI_HT_CAPS_GREENFIELD_EN BIT(4) +#define RSI_HT_CAPS_SUPPORT_CH_WIDTH BIT(1) + +/*=======================================================================*/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ + +// enumerations for security type of access point to join +typedef enum rsi_security_mode_e { + // open mode + RSI_OPEN = 0, + // WPA security with PSK + RSI_WPA, + // WPA2 security with PSK + RSI_WPA2, + // WEP security + RSI_WEP, + // Enterprise WPA security + RSI_WPA_EAP, + // Enterprise WPA2 security + RSI_WPA2_EAP, + // WPA/WPA2 security with PSK + RSI_WPA_WPA2_MIXED, + // WPA security with PMK + RSI_WPA_PMK, + // WPA2 security with PMK + RSI_WPA2_PMK, + // WPS pin method + RSI_WPS_PIN, + // WPS generated pin method + RSI_USE_GENERATED_WPSPIN, + // WPS push button method + RSI_WPS_PUSH_BUTTON, + // WPA/WPA2 security with PMK + RSI_WPA_WPA2_MIXED_PMK, + // WPA3 security with PSK + RSI_WPA3, + // WPA3 TRANSITION + RSI_WPA3_TRANSITION, + +} rsi_security_mode_t; + +// enumerations for encryption types +typedef enum rsi_encryption_mode_e { RSI_NONE, RSI_TKIP, RSI_CCMP } rsi_encryption_mode_t; + +// enumerations for certificates types +typedef enum rsi_certificate_type_e { + RSI_EAP_CLIENT = 1, + RSI_FAST_PAC_FILE = 2, + RSI_SSL_CLIENT = 3, + RSI_SSL_CLIENT_PRIVATE_KEY = 4, + RSI_SSL_CA_CERTIFICATE = 5, + RSI_SSL_SERVER_CERTIFICATE = 6, + RSI_SSL_SERVER_PRIVATE_KEY = 7, + RSI_EAP_PRIVATE_KEY = 17, + RSI_EAP_PUBLIC_KEY = 33, + RSI_EAP_CA_CERTIFICATE = 49 + +} rsi_certificate_type_t; + +// enumerations for set commands +typedef enum rsi_wlan_set_cmd_e { + RSI_SET_MAC_ADDRESS = 1, + RSI_MULTICAST_FILTER = 2, + RSI_JOIN_BSSID = 3, + RSI_CFG_SAVE = 4, + RSI_CFG_STORE = 5 +} rsi_wlan_set_cmd_t; + +// enumerations for query commands +typedef enum rsi_wlan_query_cmd_e { + RSI_FW_VERSION = 1, + RSI_MAC_ADDRESS = 2, + RSI_RSSI = 3, + RSI_WLAN_INFO = 4, + RSI_CONNECTION_STATUS = 5, + RSI_STATIONS_INFO = 6, + RSI_SOCKETS_INFO = 7, + RSI_CFG_GET = 8, + RSI_GET_WLAN_STATS = 9, + RSI_WLAN_EXT_STATS = 10 +} rsi_wlan_query_cmd_t; + +/****************************************************** + * * Type Definitions + * ******************************************************/ +// wifi direct device info structure +typedef struct rsi_wfd_device_info_s { + // If New device 1; Device left 0 + uint8_t device_state; + + // Name the device found or left 32 bytes + uint8_t device_name[32]; + + // Mac address of the device + uint8_t mac_address[6]; + + // Type of the device 1st byte inidcates primary device type; + // 2nd byte indicates sub catagory + uint8_t device_type[2]; + +} rsi_wfd_device_info_t; + +// wifi direct device info response structure +typedef struct rsi_rsp_wfd_device_info_s { + // device count + uint8_t device_count; + + // 32 maximum responses from scan command + rsi_wfd_device_info_t wfd_dev_info[RSI_MAX_WFD_DEVICE_COUNT]; + +} rsi_rsp_wfd_device_info_t; + +/*P2P connection request from wi-fi device*/ +typedef struct rsi_rsp_p2p_connection_request_s { + // device name + uint8_t device_name[32]; + +} rsi_rsp_p2p_connection_request_t; + +// Scan information response structure +typedef struct rsi_scan_info_s { + // channel number of the scanned AP + uint8_t rf_channel; + + // security mode of the scanned AP + uint8_t security_mode; + + // rssi value of the scanned AP + uint8_t rssi_val; + + // network type of the scanned AP + uint8_t network_type; + + // SSID of the scanned AP + uint8_t ssid[RSI_SSID_LEN]; + + // BSSID of the scanned AP + uint8_t bssid[RSI_MAC_ADDR_LEN]; + + // reserved + uint8_t reserved[2]; +} rsi_scan_info_t; + +// multicast command request structure +typedef struct rsi_req_multicast_filter_info_s { + // cmd_type + uint8_t cmd_type; + + // MAC address to apply filter + uint8_t mac_address[6]; + +} rsi_req_multicast_filter_info_t; + +// wireless information +typedef struct rsi_rsp_wireless_info_s { + // wlan state: connected or disconnected in station mode + // wlan state: no of stations connected in AP mode + uint16_t wlan_state; + + // channel number of connected AP + uint16_t channel_number; + + // uint8[32], SSID of connected access point + uint8_t ssid[RSI_SSID_LEN]; + + // Mac address + uint8_t mac_address[6]; + + // security type + uint8_t sec_type; + + // PSK + uint8_t psk[64]; + + // uint8[4], Module IP Address + uint8_t ipv4_address[4]; + + // uint8[16], Module IPv6 Address + uint8_t ipv6_address[16]; + + // reserved1 + uint8_t reserved1[2]; + + // reserved2 + uint8_t reserved2[2]; + +} rsi_rsp_wireless_info_t; + +typedef struct rsi_go_sta_info_s { + // IP version if the connected client + uint8_t ip_version[2]; + + // Mac Address of the connected client + uint8_t mac[6]; + union { + // IPv4 Address of the Connected client + uint8_t ipv4_address[4]; + + // IPv6 Address of the Connected client + uint8_t ipv6_address[16]; + } ip_address; + +} rsi_go_sta_info_t; + +// stations information +typedef struct rsi_rsp_stations_info_s { + // Number of stations Connected to GO + uint8_t sta_count[2]; + + rsi_go_sta_info_t sta_info[RSI_MAX_STATIONS]; + +} rsi_rsp_stations_info_t; + +typedef struct wep_key_ds_s { + uint8_t index[2]; + uint8_t key[4][32]; +} wep_key_ds_t; + +// Store config profile structure + +typedef struct network_profile { + uint8_t tcp_stack_used; + + uint8_t dhcp_enable; + uint8_t ip_address[4]; + uint8_t sn_mask[4]; + uint8_t default_gw[4]; + + uint8_t dhcp6_enable; + uint8_t prefix_length[2]; + uint8_t ip6_address[16]; + uint8_t deafault_gw[16]; + +} network_profile_t; + +typedef struct feature_frame_params_s { + uint8_t pll_mode; + uint8_t rf_type; + uint8_t wireless_mode; + uint8_t enable_ppp; + uint8_t afe_type; + uint8_t disable_programming; + uint16_t reserved; + uint8_t feature_enables[4]; +} feature_frame_params_t; + +typedef struct ap_profile { + uint8_t ap_profile_magic_word[4]; + uint8_t wlan_feature_bit_map[4]; + uint8_t tcp_ip_feature_bit_map[4]; + uint8_t custom_feature_bit_map[4]; + uint8_t data_rate; + uint8_t tx_power; + uint8_t band; + uint8_t channel[2]; + uint8_t ssid[RSI_SSID_LEN]; + uint8_t security_type; + uint8_t encryption_type; + uint8_t psk[RSI_PSK_LEN]; + uint8_t beacon_interval[2]; + uint8_t dtim_period[2]; + uint8_t keep_alive_type; + uint8_t keep_alive_counter; + uint8_t max_no_sta[2]; + + // Network config profie + network_profile_t network_profile; + + feature_frame_params_t feature_frame_params_s; +} ap_profile_t; + +typedef struct client_profile { + uint8_t client_profile_magic_word[4]; + uint8_t wlan_feature_bit_map[4]; + uint8_t tcp_ip_feature_bit_map[4]; + uint8_t custom_feature_bit_map[4]; + uint8_t listen_interval[4]; + uint8_t data_rate; + uint8_t tx_power; + uint8_t band; + uint8_t ssid[RSI_SSID_LEN]; + uint8_t ssid_len; + uint8_t channel[2]; + uint8_t scan_feature_bitmap; + uint8_t scan_chan_bitmap_magic_code[2]; + uint8_t scan_chan_bitmap_2_4_ghz[4]; + uint8_t scan_chan_bitmap_5_0_ghz[4]; + uint8_t security_type; + uint8_t encryption_type; + uint8_t psk[RSI_PSK_LEN]; + uint8_t pmk[RSI_PMK_LEN]; + wep_key_ds_t wep_key; + + // Network config profie + network_profile_t network_profile; + feature_frame_params_t feature_frame_params_s; + +} client_profile_t; + +typedef struct eap_client_profile { + uint8_t eap_profile_magic_word[4]; + uint8_t wlan_feature_bit_map[4]; + uint8_t tcp_ip_feature_bit_map[4]; + uint8_t custom_feature_bit_map[4]; + uint8_t listen_interval; + uint8_t data_rate; + uint8_t tx_power; + uint8_t band; + uint8_t ssid[RSI_SSID_LEN]; + uint8_t ssid_len; + uint8_t channel[2]; + uint8_t scan_feature_bitmap; + uint8_t scan_chan_bitmap_magic_code[2]; + uint8_t scan_chan_bitmap_2_4_ghz[4]; + uint8_t scan_chan_bitmap_5_0_ghz[4]; + uint8_t security_type; + uint8_t eap_method[32]; + uint8_t inner_method[32]; + uint8_t user_identity[64]; + uint8_t passwd[128]; + + // Network config profie + network_profile_t network_profile; + feature_frame_params_t feature_frame_params_s; +} eap_client_profile_t; + +typedef struct p2p_profile { + + uint8_t p2p_profile_magic_word[4]; + uint8_t wlan_feature_bit_map[4]; + uint8_t tcp_ip_feature_bit_map[4]; + uint8_t custom_feature_bit_map[4]; + uint8_t data_rate; + uint8_t tx_power; + uint8_t band; + uint8_t join_ssid[RSI_SSID_LEN]; + uint8_t go_intent[2]; + uint8_t device_name[64]; + uint8_t operating_channel[2]; + uint8_t ssid_postfix[64]; + uint8_t psk_key[64]; + + // Network config profie + network_profile_t network_profile; + feature_frame_params_t feature_frame_params_s; + +} p2p_profile_t; + +typedef struct rsi_config_profile_s { + uint8_t profile_type[4]; + + union { + // AP config profile + ap_profile_t ap_profile; + + // Client config profile + client_profile_t client_profile; + + // EAP client config profile + eap_client_profile_t eap_client_profile; + + // P2P config profile + p2p_profile_t p2p_profile; + + } wlan_profile_struct; + +} rsi_config_profile_t; + +typedef struct rsi_profile_req_s { + uint8_t profile_type[4]; + +} rsi_profile_req_t; + +typedef struct rsi_auto_config_enable_s { + uint8_t config_enable; + uint8_t profile_type[4]; + +} rsi_auto_config_enable_t; + +// socket information structure +typedef struct rsi_sock_info_query_s { + // 2 bytes, socket id + uint8_t sock_id[2]; + + // 2 bytes, socket type + uint8_t sock_type[2]; + + // 2 bytes, source port number + uint8_t source_port[2]; + + // 2 bytes, remote port number + uint8_t dest_port[2]; + + union { + // remote IPv4 Address + uint8_t ipv4_address[4]; + + // remote IPv6 Address + uint8_t ipv6_address[16]; + + } dest_ip_address; + +} rsi_sock_info_query_t; + +// sockets information +typedef struct rsi_rsp_sockets_info_s { + // number of sockets opened + uint8_t num_open_socks[2]; + + //sockets information array + rsi_sock_info_query_t socket_info[RSI_MN_NUM_SOCKETS]; + +} rsi_rsp_sockets_info_t; + +// Scan command response structure +typedef struct rsi_rsp_scan_s { + // number of access points scanned + uint8_t scan_count[4]; + + // reserved + uint8_t reserved[4]; + + // scanned access points information + rsi_scan_info_t scan_info[RSI_AP_SCANNED_MAX]; + +} rsi_rsp_scan_t; + +// Response structure for Query firmware version command +typedef struct rsi_rsp_fw_version_s { + + // Firmware version + uint8_t firmwre_version[20]; + +} rsi_rsp_fw_version_t; + +// Response structure for Query RSSI command +typedef struct rsi_rsp_rssi_s { + + // RSSI value of the accesspoint to which station is connected + uint8_t rssi_value[2]; + +} rsi_rsp_rssi_t; + +// Response structure for Query MAC address command +typedef struct rsi_rsp_mac_s { + + // MAC address of the module + uint8_t mac_address[6]; + +} rsi_rsp_mac_t; + +// Response structure rx stats command +typedef struct rsi_rsp_rx_stats_s { + // no. of tx pkts + uint8_t tx_pkts[2]; + + // no. of rx pkts + uint8_t reserved_1[2]; + + // no. of tx retries + uint8_t tx_retries[2]; + + // no. of pkts that pass crc + uint8_t crc_pass[2]; + + // no. of pkts failing crc chk + uint8_t crc_fail[2]; + + // no. of times cca got stuck + uint8_t cca_stk[2]; + + // no of times cca didn't get stuck + uint8_t cca_not_stk[2]; + + // no. of pkt aborts + uint8_t pkt_abort[2]; + + // no. of false rx starts + uint8_t fls_rx_start[2]; + + // cca idle time + uint8_t cca_idle[2]; + + // Reserved fields + uint8_t reserved_2[26]; + + // no. of rx retries + uint8_t rx_retries[2]; + + // rssi value + uint8_t reserved_3[2]; + + // cal_rssi + uint8_t cal_rssi[2]; + + // lna_gain bb_gain + uint8_t reserved_4[4]; + + // number of tx packets dropped after maximum retries + uint8_t xretries[2]; + + // consecutive pkts dropped + uint8_t max_cons_pkts_dropped[2]; + + // Reserved fields + uint8_t reserved_5[2]; + + // BSSID matched broadcast packets count + uint8_t bss_broadcast_pkts[2]; + + // BSSID matched multicast packets count + uint8_t bss_multicast_pkts[2]; + + // BSSID & multicast filter matched packets count + uint8_t bss_filter_matched_multicast_pkts[2]; + +} rsi_rsp_rx_stats_t; + +// IPV4 ipconfig command response structure +typedef struct rsi_rsp_ipv4_parmas_s { + // MAC address of this module + uint8_t macAddr[6]; + + // Configured IP address + uint8_t ipaddr[4]; + + // Configured netmask + uint8_t netmask[4]; + + // Configured default gateway + uint8_t gateway[4]; + +} rsi_rsp_ipv4_parmas_t; + +// IPV6 ipconfig command response structure +typedef struct rsi_rsp_ipv6_parmas_s { + // prefix length + uint8_t prefixLength[2]; + + // Configured IPv address + uint8_t ipaddr6[16]; + + // Router IPv6 address + uint8_t defaultgw6[16]; + +} rsi_rsp_ipv6_parmas_t; + +// Set wep keys command request structure +typedef struct rsi_wep_keys_s { + // select the wep key to use + uint8_t index[2]; + + // 4 wep keys + uint8_t key[4][32]; + +} rsi_wep_keys_t; + +typedef struct rsi_eap_credentials_s { + // Username + uint8_t username[RSI_EAP_USER_NAME_LENGTH]; + + // Password + uint8_t password[RSI_EAP_PASSWORD_LENGTH]; + +} rsi_eap_credentials_t; + +/*Structure for module stats notification*/ +typedef struct rsi_rsp_wlan_stats_s { + uint8_t operating_mode; + uint8_t dtim_period; + uint8_t ideal_beacon_info[2]; + uint8_t busy_beacon_info[2]; + uint8_t beacon_interval[2]; +} rsi_rsp_wlan_stats_t; +/*Structure for module stats notification*/ +typedef struct rsi_wlan_ext_stats_s { + uint32_t beacon_lost_count; + uint32_t beacon_rx_count; + uint32_t mcast_rx_count; + uint32_t mcast_tx_count; + uint32_t ucast_rx_count; + uint32_t ucast_tx_count; + uint32_t overrun_count; +} rsi_wlan_ext_stats_t; + +#define RSI_PARSE_1_BYTES 1 +#define RSI_PARSE_2_BYTES 2 +#define RSI_PARSE_4_BYTES 4 + +#define IEEE80211_FC0_SUBTYPE_MASK 0xf0 +#define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50 +#define IEEE80211_FC0_SUBTYPE_BEACON 0x80 + +/* Information Element IDs */ +#define WLAN_EID_SSID 0 +#define WLAN_EID_RSN 48 +#define WLAN_EID_VENDOR_SPECIFIC 221 +#define PAIR_WISE_CIPHER_COUNT 12 +#define WIFI_OUI_RSN 4 +#define IE_TYPE 0 +#define IE_LEN 1 +#define IE_POS 2 + +#define SME_OPEN 0 +#define SME_WPA 1 +#define SME_WPA2 2 +#define SME_WEP 3 +#define SME_WPA_ENTERPRISE 4 +#define SME_WPA2_ENTERPRISE 5 +#define SME_WPA3 7 +#define SME_WPA3_TRANSITION 8 + +#define BSSID_OFFSET 16 +#define SSID_OFFSET 38 +#define CAPABILITIES_OFFSET 34 +#define IES_OFFSET 36 +#define MINIMUM_FRAME_LENGTH 36 + +#define MAX_SCAN_COUNT 48 + +#define ETH_ALEN 6 + +struct wpa_scan_res { + int freq; + int level; + uint8_t channel_no; + uint8_t security_mode; + uint8_t rssiVal; + uint8_t uNetworkType; + uint8_t ssid[RSI_SSID_LEN]; + uint8_t ssid_len; + uint8_t bssid[ETH_ALEN]; +}; + +struct wpa_scan_results_arr { + + uint16_t num; + uint16_t sort_index[MAX_SCAN_COUNT]; + struct wpa_scan_res res[MAX_SCAN_COUNT]; +}; + +//wlan per stats structure +typedef struct rsi_per_stats_rsp_s { + uint16_t tx_pkts; + uint8_t reserved_1[2]; + uint16_t tx_retries; + uint16_t crc_pass; + uint16_t crc_fail; + uint16_t cca_stk; + uint16_t cca_not_stk; + uint16_t pkt_abort; + uint16_t fls_rx_start; + uint16_t cca_idle; + uint8_t reserved_2[26]; + uint16_t rx_retries; + uint8_t reserved_3[2]; + uint16_t cal_rssi; + uint8_t reserved_4[4]; + uint16_t xretries; + uint16_t max_cons_pkts_dropped; + uint8_t reserved_5[2]; + uint16_t bss_broadcast_pkts; + uint16_t bss_multicast_pkts; + uint16_t bss_filter_matched_multicast_pkts; + uint8_t eof_pkt_drop_count[4]; + uint8_t mask_pkt_drop_count[4]; + uint8_t ack_sent[4]; + //!No.of pkts rcvd with 48M + uint16_t pkt_rcvd_with_48M; + //!No.of pkts rcvd with 24M + uint16_t pkt_rcvd_with_24M; + //!No.of pkts rcvd with 12M + uint16_t pkt_rcvd_with_12M; + //!No.of pkts rcvd with 6M + uint16_t pkt_rcvd_with_6M; + //!No.of pkts rcvd with 54M + uint16_t pkt_rcvd_with_54M; + //!No.of pkts rcvd with 36M + uint16_t pkt_rcvd_with_36M; + //!No.of pkts rcvd with 18M + uint16_t pkt_rcvd_with_18M; + //!No.of pkts rcvd with 9M + uint16_t pkt_rcvd_with_9M; + //!No.of pkts rcvd with 11M + uint16_t pkt_rcvd_with_11M; + //!No.of pkts rcvd with 5.5M + uint16_t pkt_rcvd_with_5M; + //!No.of pkts rcvd with 2M + uint16_t pkt_rcvd_with_2M; + //!No.of pkts rcvd with 1M + uint16_t pkt_rcvd_with_1M; + //!No.of pkts rcvd with mcs0 + uint16_t pkt_rcvd_with_mcs0; + //!No.of pkts rcvd with mcs1 + uint16_t pkt_rcvd_with_mcs1; + //!No.of pkts rcvd with mcs2 + uint16_t pkt_rcvd_with_mcs2; + //!No.of pkts rcvd with mcs3 + uint16_t pkt_rcvd_with_mcs3; + //!No.of pkts rcvd with mcs4 + uint16_t pkt_rcvd_with_mcs4; + //!No.of pkts rcvd with mcs5 + uint16_t pkt_rcvd_with_mcs5; + //!No.of pkts rcvd with mcs6 + uint16_t pkt_rcvd_with_mcs6; + //!No.of pkts rcvd with mcs7 + uint16_t pkt_rcvd_with_mcs7; +#ifdef CHIP_9117 + //!No.of pkts rcvd with 11ax SU PPDU Type + uint16_t pkt_count_HE_SU_PPDU; + uint16_t pkt_count_HE_ER_SU_PPDU; + uint16_t pkt_count_HE_TRIG_PPDU; + uint16_t pkt_count_HE_MU_PPDU; + uint16_t pkt_count_11AC; + uint16_t tx_done; +#endif + uint32_t reserved_8[9]; + uint16_t noise_rssi; + int32_t stop_per; +} rsi_per_stats_rsp_t; + +// TWT User configurable parameters. +typedef struct twt_user_params_s { + // Nominal minimum wake duration. Range : 0 - 255 + uint8_t wake_duration; + // Wake duration tolerance. Range : 0 - 255 + uint8_t wake_duration_tol; + // Wake interval Exponent. Range : 0 - 31 + uint8_t wake_int_exp; + // Wake interval exponent tolerance. Range : 0 - 31 + uint8_t wake_int_exp_tol; + // Wake interval mantissa. Range : 0 - 65535 + uint16_t wake_int_mantissa; + // Wake interval mantissa tolerance. Range : 0 - 65535 + uint16_t wake_int_mantissa_tol; + // Implicit TWT : 0 or 1 + uint8_t implicit_twt; + // Un-announced TWT : 0 or 1 + uint8_t un_announced_twt; + // Triggered TWT : 0 or 1 + uint8_t triggered_twt; + // Wake duration unit. 0 : 1TU = 256uSec; 1 : 1TU 1024uSec + uint8_t wake_duration_unit; + // TWT Channel. Range : 0 - 7 valid channels. Ignored by firmware. + uint8_t twt_channel; + // TWT protection : 0 or 1. Ignored by firmware. + uint8_t twt_protection; + // Restrict TX outside TSP : 0 or 1 + uint8_t restrict_tx_outside_tsp; + // TWT Retry limit. Range : 0 - 15 + uint8_t twt_retry_limit; + // TWT retry interval in seconds. Range : 5 - 255. + uint8_t twt_retry_interval; + // TWT Request type. 0 - Request TWT; 1 - Suggest TWT; 2 - Demand TWT + uint8_t req_type; +} twt_user_params_t; +// TWT request structure to configure a session +typedef struct rsi_twt_req_s { + // Nominal minimum wake duration. Range : 0 - 255 + uint8_t wake_duration; + // Wake duration tolerance. Range : 0 - 255 + uint8_t wake_duration_tol; + // Wake interval exponent tolerance. Range : 0 - 31 + uint8_t wake_int_exp; + // Wake interval exponent tolerance. Range : 0 - 31 + uint8_t wake_int_exp_tol; + // Wake interval mantissa. Range : 0 - 65535 + uint8_t wake_int_mantissa[2]; + // Wake interval mantissa tolerance. Range : 0 - 65535 + uint8_t wake_int_mantissa_tol[2]; + // Implicit TWT : 0 or 1 + uint8_t implicit_twt; + // Un-announced TWT : 0 or 1 + uint8_t un_announced_twt; + // Triggered TWT : 0 or 1 + uint8_t triggered_twt; + // Negotiation Type : 0 - Individual TWT; 1 - Broadcast TWT + uint8_t negotiation_type; + // TWT Channel. Range : 0 - 7 + uint8_t twt_channel; + // TWT protection : 0 or 1 + uint8_t twt_protection; + // TWT Session Flow ID. 0 - 7 valid. 0xFF to disable all active TWT sessions. + uint8_t twt_flow_id; + // Restrict TX outside TSP : 0 or 1 + uint8_t restrict_tx_outside_tsp; + // TWT Retry limit. Range : 0 - 15 + uint8_t twt_retry_limit; + // TWT retry interval. Range : 5 - 255 + uint8_t twt_retry_interval; + // TWT Request type. 0 - Request TWT; 1 - Suggest TWT; 2 - Demand TWT + uint8_t req_type; + //TWT Enable. 0 - TWT session teardown; 1 - TWT session setup + uint8_t twt_enable; + // Wake duration unit. 0 - 256 TU; 1 - 1024 TU + uint8_t wake_duration_unit; +} rsi_twt_req_t; +// TWT Response structure. This structure contains response parameters from AP. +typedef struct rsi_twt_rsp_s { + uint8_t wake_duration; + uint8_t wake_duration_unit; + uint8_t wake_int_exp; + uint8_t negotiation_type; + uint16_t wake_int_mantissa; + uint8_t implicit_twt; + uint8_t un_announced_twt; + uint8_t triggered_twt; + uint8_t twt_channel; + uint8_t twt_protection; + uint8_t twt_flow_id; +} rsi_twt_rsp_t; + +// Structure for incoming CSI record +typedef struct rsi_rsp_csi_record_s { + /** Channel estimation information i value*/ + uint16_t csi_matrix_p; + /** Channel estimation information q value*/ + uint16_t csi_matrix_i; +} rsi_rsp_csi_record_t; + +// Structure for incoming CSI data payload +typedef struct rsi_rsp_csi_data_s { + /** Incoming MAC address in payload*/ + uint8_t mac_address[6]; + uint8_t reserved[2]; + /** Incoming TSF of frame in payload*/ + uint32_t tsf; +#define CSI_MAX_NUM_RECORDS 56 + /** Incoming CSI data in payload. Refer to \ref rsi_rsp_csi_record_s*/ + rsi_rsp_csi_record_t rsi_rsp_csi_record[CSI_MAX_NUM_RECORDS]; +} rsi_rsp_csi_data_t; + +typedef struct rsi_calib_read_s { +#define READ_FROM_EFUSE 0 +#define READ_FROM_FLASH 1 + uint8_t target; + uint8_t reserved0[3]; + int8_t gain_offset[3]; + int8_t xo_ctune; +} rsi_calib_read_t; + +/****************************************************** + * * Structures + * ******************************************************/ + +/****************************************************** + * * Global Variables + * ******************************************************/ + +/****************************************************** + * * Function Declarations + * ******************************************************/ +extern int32_t rsi_wlan_scan(int8_t *ssid, uint8_t chno, rsi_rsp_scan_t *result, uint32_t length); +extern int32_t rsi_wlan_scan_async(int8_t *ssid, + uint8_t chno, + void (*callback)(uint16_t status, const uint8_t *buffer, const uint16_t length)); +extern int32_t rsi_wlan_connect(int8_t *ssid, rsi_security_mode_t sec_type, void *secret_key); +extern int32_t rsi_wlan_connect_async(int8_t *ssid, + rsi_security_mode_t sec_type, + void *secret_key, + void (*scan_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)); +extern int32_t rsi_wlan_ap_start(int8_t *ssid, + uint8_t channel, + rsi_security_mode_t security_type, + rsi_encryption_mode_t encryption_mode, + uint8_t *password, + uint16_t beacon_interval, + uint8_t dtim_period); +extern int32_t rsi_wlan_execute_post_connect_cmds(void); +extern int32_t rsi_wlan_disconnect(void); +extern int32_t rsi_wlan_disconnect_stations(uint8_t *mac_address); +extern int32_t rsi_wlan_set_certificate_index(uint8_t certificate_type, + uint8_t cert_inx, + uint8_t *buffer, + uint32_t certificate_length); +extern int32_t rsi_wlan_set_certificate(uint8_t certificate_type, uint8_t *buffer, uint32_t certificate_length); +extern int32_t rsi_wlan_get_status(void); +extern int32_t rsi_wlan_wps_generate_pin(uint8_t *response, uint16_t length); +extern int32_t rsi_wlan_wps_enter_pin(int8_t *wps_pin); +extern int32_t rsi_wlan_wps_push_button_event(int8_t *ssid); +extern int32_t rsi_transmit_test_start(uint16_t power, uint32_t rate, uint16_t length, uint16_t mode, uint16_t channel); +extern int32_t rsi_transmit_test_stop(void); +extern int32_t rsi_wlan_receive_stats_start(uint16_t channel); +extern int32_t rsi_wlan_receive_stats_stop(void); +extern int32_t rsi_wlan_get(rsi_wlan_query_cmd_t cmd_type, uint8_t *response, uint16_t length); +extern int32_t rsi_wlan_set(rsi_wlan_set_cmd_t cmd_type, uint8_t *request, uint16_t length); +extern uint16_t rsi_wlan_register_callbacks(uint32_t callback_id, + void (*callback_handler_ptr)(uint16_t status, + uint8_t *buffer, + const uint32_t length)); +extern int32_t rsi_wlan_send_data(uint8_t *buffer, uint32_t length); +extern int32_t rsi_wlan_wfd_start_discovery( + uint16_t go_intent, + int8_t *device_name, + uint16_t channel, + int8_t *ssid_post_fix, + uint8_t *psk, + void (*wlan_wfd_discovery_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length), + void (*wlan_wfd_connection_request_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length)); +extern int32_t rsi_wlan_wfd_connect(int8_t *device_name, + void (*join_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)); +extern int32_t rsi_power_save_profile(uint8_t psp_mode, uint8_t psp_type); +extern int32_t rsi_send_raw_data(uint8_t *buffer, uint32_t length); +extern uint8_t *rsi_fill_config_profile(uint32_t type, uint8_t *profile_buffer); +extern int32_t rsi_wlan_add_profile(uint32_t type, uint8_t *profile); +extern int32_t rsi_wlan_get_profile(uint32_t type, rsi_config_profile_t *profile_rsp, uint16_t length); +extern int32_t rsi_wlan_delete_profile(uint32_t type); +extern int32_t rsi_wlan_enable_auto_config(uint8_t enable, uint32_t type); +extern int32_t rsi_wlan_bgscan_profile(uint8_t cmd, rsi_rsp_scan_t *result, uint32_t length); + +extern int32_t rsi_wlan_twt_config(uint8_t twt_enable, uint8_t twt_flow_id, twt_user_params_t *twt_req_params); + +extern int32_t rsi_wlan_update_gain_table(uint8_t band, uint8_t bandwidth, uint8_t *payload, uint16_t payload_len); +extern int32_t rsi_wlan_power_save_profile(uint8_t psp_mode, uint8_t psp_type); +extern int32_t rsi_wlan_power_save_with_listen_interval(uint8_t psp_mode, uint8_t psp_type, uint16_t listen_interval); +extern int32_t rsi_wlan_power_save_disable_and_enable(uint8_t psp_mode, uint8_t psp_type); +extern int32_t rsi_wlan_scan_with_bitmap_options(int8_t *ssid, + uint8_t chno, + rsi_rsp_scan_t *result, + uint32_t length, + uint32_t scan_bitmap); +extern void rsi_sort_scan_results_array_based_on_rssi(struct wpa_scan_results_arr *scan_results_array); +extern int32_t rsi_wlan_scan_async_with_bitmap_options(int8_t *ssid, + uint8_t chno, + uint32_t bitmap, + void (*scan_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)); +int32_t rsi_wlan_ping_async(uint8_t flags, + uint8_t *ip_address, + uint16_t size, + void (*wlan_ping_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)); +int32_t rsi_send_freq_offset(int32_t freq_offset_in_khz); +int32_t rsi_calib_read(uint8_t target, rsi_calib_read_t *calib_data); +int32_t rsi_calib_write(uint8_t target, + uint32_t flags, + int8_t gain_offset_low, + int8_t gain_offset_mid, + int8_t gain_offset_high, + int8_t xo_ctune); +int16_t rsi_parse(void *address, uint16_t length, uint8_t *value); +int32_t rsi_wlan_11ax_config(uint8_t gi_ltf); +int32_t rsi_wlan_csi_config_async(uint8_t enable, + uint32_t periodicity, + uint8_t num_of_mac_addr, + uint8_t (*mac_addr)[6], + void (*wlan_csi_data_response_handler)(uint16_t status, + uint8_t *buffer, + const uint32_t length)); + +void rsi_register_auto_config_rsp_handler(void (*rsi_auto_config_rsp_handler)(uint16_t status, uint8_t state)); +STATIC INLINE void set_option(uint32_t *parameter, uint32_t flag) +{ + *parameter |= flag; +} + +STATIC INLINE void clear_option(uint32_t *parameter, uint32_t flag) +{ + *parameter &= ~flag; +} + +#endif diff --git a/wiseconnect/sapi/include/rsi_wlan_common_config.h b/wiseconnect/sapi/include/rsi_wlan_common_config.h new file mode 100644 index 00000000..1629ebd2 --- /dev/null +++ b/wiseconnect/sapi/include/rsi_wlan_common_config.h @@ -0,0 +1,1304 @@ +/******************************************************************************* +* @file rsi_wlan_common_config.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/** + * @file rsi_wlan_common_config.h + * @version 0.1 + * @date 15 Aug 2018 + * + * + * + * @brief : This file contains user configurable details to configure the device + * + * @section Description This file contains user configurable details to configure the device + * + * + */ +#ifndef RSI_WLAN_COMMON_CONFIG_H +#define RSI_WLAN_COMMON_CONFIG_H + +#include "rsi_wlan_defines.h" +#include "rsi_user.h" +#include + +#ifdef CHIP_9117B0 +#define CHIP_9117 1 +#endif + +/****************************************************** + * * WLAN + * ******************************************************/ +// Enable feature +#ifndef RSI_ENABLE +#define RSI_ENABLE 1 +#endif + +// Disable feature +#ifndef RSI_DISABLE +#define RSI_DISABLE 0 +#endif + +// To enable concurrent mode +#ifndef CONCURRENT_MODE +#define CONCURRENT_MODE RSI_DISABLE +#endif + +#ifndef RSI_FAST_FW_UP +#define RSI_FAST_FW_UP RSI_DISABLE +#endif +// opermode command paramaters +/*=======================================================================*/ +// To set wlan feature select bit map +#ifndef RSI_FEATURE_BIT_MAP +#define RSI_FEATURE_BIT_MAP (FEAT_SECURITY_OPEN) +#endif + +// TCP IP BYPASS feature check +#ifndef RSI_TCP_IP_BYPASS +#define RSI_TCP_IP_BYPASS RSI_DISABLE +#endif + +// TCP/IP feature select bitmap for selecting TCP/IP features +#ifndef RSI_TCP_IP_FEATURE_BIT_MAP +#define RSI_TCP_IP_FEATURE_BIT_MAP (TCP_IP_FEAT_DHCPV4_CLIENT) +#endif + +// To set custom feature select bit map +#ifndef RSI_CUSTOM_FEATURE_BIT_MAP +#define RSI_CUSTOM_FEATURE_BIT_MAP 0 +#endif + +// To set Extended custom feature select bit map +#ifndef RSI_EXT_CUSTOM_FEATURE_BIT_MAP +#define RSI_EXT_CUSTOM_FEATURE_BIT_MAP 0 +#endif + +#ifndef RSI_EXT_TCPIP_FEATURE_BITMAP +#define RSI_EXT_TCPIP_FEATURE_BITMAP 0 +#endif + +#ifndef RSI_BT_FEATURE_BITMAP +#define RSI_BT_FEATURE_BITMAP BT_RF_TYPE +#endif + +#ifndef RSI_SLEEP_IND_FROM_DEV_PIN_SELECT +#define RSI_SLEEP_IND_FROM_DEV_PIN_SELECT 0 +#endif + +/*************************************************** + * PowerSave Bitmap Configuration + *************************************************** + */ +#if (RS9116_SILICON_CHIP_VER == CHIP_VER_1P4_AND_ABOVE) +#define PROTOCOL_DEBUG_GPIO_PINS BIT(1) +#define RSI_APP_TCP_IP_FEATURE_BITMAP TCP_IP_FEAT_EXTENSION_VALID +#define RSI_APP_EXT_TCP_IP_FEATURE_BITMAP CONFIG_FEAT_EXTENTION_VALID +#define RSI_APP_CONFIG_FEATURE_BITMAP RSI_FEAT_SLEEP_GPIO_SEL_BITMAP + +#else + +#define RSI_APP_TCP_IP_FEATURE_BITMAP 0 +#define RSI_APP_EXT_TCP_IP_FEATURE_BITMAP 0 +#define RSI_APP_CONFIG_FEATURE_BITMAP 0 + +#endif + +#ifndef RSI_CONFIG_FEATURE_BITMAP +#define RSI_CONFIG_FEATURE_BITMAP 0 +#endif + +/*=======================================================================*/ + +// Feature frame parameters +/*=======================================================================*/ +#ifndef PLL_MODE +#define PLL_MODE 0 +#endif + +#ifndef RF_TYPE +#define RF_TYPE 1 // 0 - External RF 1- Internal RF +#endif + +#ifndef WIRELESS_MODE +#define WIRELESS_MODE 0 +#endif + +#ifndef ENABLE_PPP +#define ENABLE_PPP 0 +#endif + +#ifndef AFE_TYPE +#define AFE_TYPE 1 +#endif + +#ifndef FEATURE_ENABLES +#define FEATURE_ENABLES 0 +#endif + +/*=======================================================================*/ + +// Band command paramters +/*=======================================================================*/ + +// RSI_BAND_2P4GHZ(2.4GHz) or RSI_BAND_5GHZ(5GHz) or RSI_DUAL_BAND +#ifndef RSI_BAND +#define RSI_BAND RSI_BAND_2P4GHZ +#endif + +/*=======================================================================*/ + +// set region command paramters +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE Set region support +#ifndef RSI_SET_REGION_SUPPORT +#define RSI_SET_REGION_SUPPORT RSI_DISABLE //@ RSI_ENABLE or RSI_DISABLE set region +#endif + +// If 1:region configurations taken from user ;0:region configurations taken from beacon +#ifndef RSI_SET_REGION_FROM_USER_OR_BEACON +#define RSI_SET_REGION_FROM_USER_OR_BEACON 1 +#endif + +// 0-Default Region domain ,1-US, 2-EUROPE, 3-JAPAN, 4-WORLD, 5-KOREA +#ifndef RSI_REGION_CODE +#define RSI_REGION_CODE 1 +#endif + +// 0- Without On Board Antenna , 1- With On Board Antenna +#ifndef RSI_MODULE_TYPE +#define RSI_MODULE_TYPE 1 +#endif + +/*=======================================================================*/ + +// set region AP command paramters +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE Set region AP support +#ifndef RSI_SET_REGION_AP_SUPPORT +#define RSI_SET_REGION_AP_SUPPORT RSI_DISABLE +#endif + +// If 1:region configurations taken from user ;0:region configurations taken from firmware +#ifndef RSI_SET_REGION_AP_FROM_USER +#define RSI_SET_REGION_AP_FROM_USER RSI_DISABLE +#endif + +// "US" or "EU" or "JP" or other region codes +#ifndef RSI_COUNTRY_CODE +#define RSI_COUNTRY_CODE "US" //TODO: review +#endif + +/*=======================================================================*/ + +// Rejoin parameters +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE rejoin params +#ifndef RSI_REJOIN_PARAMS_SUPPORT +#define RSI_REJOIN_PARAMS_SUPPORT RSI_DISABLE +#endif + +// Rejoin retry count. If 0 retries infinity times +#ifndef RSI_REJOIN_MAX_RETRY +#define RSI_REJOIN_MAX_RETRY 0 +#endif + +// Periodicity of rejoin attempt +#ifndef RSI_REJOIN_SCAN_INTERVAL +#define RSI_REJOIN_SCAN_INTERVAL 4 +#endif + +// Beacon missed count +#ifndef RSI_REJOIN_BEACON_MISSED_COUNT +#define RSI_REJOIN_BEACON_MISSED_COUNT 40 +#endif + +// RSI_ENABLE or RSI_DISABLE retry for first time join failure +#ifndef RSI_REJOIN_FIRST_TIME_RETRY +#define RSI_REJOIN_FIRST_TIME_RETRY RSI_DISABLE +#endif + +/*=======================================================================*/ + +//BG scan command parameters +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE BG Scan support +#ifndef RSI_BG_SCAN_SUPPORT +#define RSI_BG_SCAN_SUPPORT RSI_DISABLE +#endif + +// RSI_ENABLE or RSI_DISABLE BG scan +#ifndef RSI_BG_SCAN_ENABLE +#define RSI_BG_SCAN_ENABLE RSI_ENABLE +#endif + +// RSI_ENABLE or RSI_DISABLE instant BG scan +#ifndef RSI_INSTANT_BG +#define RSI_INSTANT_BG RSI_DISABLE +#endif + +// BG scan threshold value +#ifndef RSI_BG_SCAN_THRESHOLD +#define RSI_BG_SCAN_THRESHOLD 10 +#endif + +// RSSI tolerance Threshold +#ifndef RSI_RSSI_TOLERANCE_THRESHOLD +#define RSI_RSSI_TOLERANCE_THRESHOLD 4 +#endif + +// BG scan periodicity +#ifndef RSI_BG_SCAN_PERIODICITY +#define RSI_BG_SCAN_PERIODICITY 10 +#endif + +// Active scan duration +#ifndef RSI_ACTIVE_SCAN_DURATION +#define RSI_ACTIVE_SCAN_DURATION 15 +#endif + +// Passive scan duration +#ifndef RSI_PASSIVE_SCAN_DURATION +#define RSI_PASSIVE_SCAN_DURATION 20 +#endif + +// Multi probe +#ifndef RSI_MULTIPROBE +#define RSI_MULTIPROBE RSI_DISABLE +#endif +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE for RSI_WLAN_CONFIG_ENABLE +#ifndef RSI_WLAN_CONFIG_ENABLE +#define RSI_WLAN_CONFIG_ENABLE RSI_ENABLE +#endif + +#ifndef CONFIG_RTSTHRESHOLD +#define CONFIG_RTSTHRESHOLD 1 +#endif + +#ifndef RSI_RTS_THRESHOLD +#define RSI_RTS_THRESHOLD 2346 +#endif + +/*=======================================================================*/ +//Roaming parameters +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE Roaming support +#ifndef RSI_ROAMING_SUPPORT +#define RSI_ROAMING_SUPPORT RSI_DISABLE +#endif + +// roaming threshold value +#ifndef RSI_ROAMING_THRESHOLD +#define RSI_ROAMING_THRESHOLD 10 +#endif + +// roaming hysterisis value +#ifndef RSI_ROAMING_HYSTERISIS +#define RSI_ROAMING_HYSTERISIS 4 +#endif + +/*=======================================================================*/ + +// High Throughput Capabilies related information +/*=======================================================================*/ + +// RSI_ENABLE or RSI_DISABLE 11n mode in AP mode +#ifndef RSI_MODE_11N_ENABLE +#define RSI_MODE_11N_ENABLE RSI_DISABLE +#endif + +// HT caps bit map. +#ifndef RSI_HT_CAPS_BIT_MAP +#define RSI_HT_CAPS_BIT_MAP 2 +#endif + +/*=======================================================================*/ + +// Scan command parameters +/*=======================================================================*/ + +// scan channel bit map in 2.4GHz band,valid if given channel to scan is 0 +#ifndef RSI_SCAN_CHANNEL_BIT_MAP_2_4 +#define RSI_SCAN_CHANNEL_BIT_MAP_2_4 0 +#endif + +// scan channle bit map in 5GHz band ,valid if given channel to scan is 0 +#ifndef RSI_SCAN_CHANNEL_BIT_MAP_5 +#define RSI_SCAN_CHANNEL_BIT_MAP_5 0 +#endif + +// scan_feature_bitmap ,valid only if specific channel to scan and ssid are given +#ifndef RSI_SCAN_FEAT_BITMAP +#define RSI_SCAN_FEAT_BITMAP RSI_ENABLE_QUICK_SCAN +#endif + +/*=======================================================================*/ + +// Enterprise configuration command parameters +/*=======================================================================*/ + +// Enterprise method ,should be one of among TLS, TTLS, FAST or PEAP +#ifndef RSI_EAP_METHOD +#define RSI_EAP_METHOD "TTLS" +#endif +// This parameter is used to configure the module in Enterprise security mode +#ifndef RSI_EAP_INNER_METHOD +#define RSI_EAP_INNER_METHOD "\"auth=MSCHAPV2\"" +#endif + +// Private Key Password is required for encrypted private key, format is like "\"12345678\"" +#ifndef RSI_PRIVATE_KEY_PASSWORD +#define RSI_PRIVATE_KEY_PASSWORD "" +#endif + +/* OKC value of EAP command +BIT[0] - OKC (Opportunistic Key Caching) +BIT[1] - CA certificate for PEAP connection. +BIT[2-12] - EAP Ciphers list +BIT[13-31] - Reserved +*/ +#ifndef OKC_VALUE +#define OKC_VALUE 0 +#endif + +/*=======================================================================*/ + +// AP configuration command parameters +/*=======================================================================*/ + +// This Macro is used to enable AP keep alive functionality +#ifndef RSI_AP_KEEP_ALIVE_ENABLE +#define RSI_AP_KEEP_ALIVE_ENABLE RSI_ENABLE +#endif + +// This parameter is used to configure keep alive type +#ifndef RSI_AP_KEEP_ALIVE_TYPE +#define RSI_AP_KEEP_ALIVE_TYPE RSI_NULL_BASED_KEEP_ALIVE +#endif + +// This parameter is used to configure keep alive period +#ifndef RSI_AP_KEEP_ALIVE_PERIOD +#define RSI_AP_KEEP_ALIVE_PERIOD 100 +#endif + +// This parameter is used to configure maximum stations supported +#ifndef RSI_MAX_STATIONS_SUPPORT +#define RSI_MAX_STATIONS_SUPPORT 4 +#endif + +/*=======================================================================*/ + +// Join command parameters +/*=======================================================================*/ + +// Tx power level +#ifndef RSI_POWER_LEVEL +#define RSI_POWER_LEVEL RSI_POWER_LEVEL_HIGH +#endif + +// RSI_JOIN_FEAT_STA_BG_ONLY_MODE_ENABLE or RSI_JOIN_FEAT_LISTEN_INTERVAL_VALID +#ifndef RSI_JOIN_FEAT_BIT_MAP +#define RSI_JOIN_FEAT_BIT_MAP 0 +#endif + +// +#ifndef RSI_LISTEN_INTERVAL +#define RSI_LISTEN_INTERVAL 0 +#endif + +// Transmission data rate. Physical rate at which data has to be transmitted. +#ifndef RSI_DATA_RATE +#define RSI_DATA_RATE RSI_DATA_RATE_AUTO +#endif + +/*=======================================================================*/ + +// Ipconf command parameters +/*=======================================================================*/ + +// DHCP client host name +#ifndef RSI_DHCP_HOST_NAME +#define RSI_DHCP_HOST_NAME "dhcp_client" +#endif + +// Transmit test command parameters +/*=======================================================================*/ +// TX TEST rate flags +#ifndef RSI_TX_TEST_RATE_FLAGS +#define RSI_TX_TEST_RATE_FLAGS 0 +#endif + +// BIT description of PER rate flags +#define RSI_TX_IMMEDIATE_TRANSFER BIT(6) + +// TX TEST per channel bandwidth +#ifndef RSI_TX_TEST_PER_CH_BW +#define RSI_TX_TEST_PER_CH_BW 0 +#endif + +// TX TEST aggregation enable or disable +//If defined in 'rsi_config.h' file, then this won't be used +#ifndef RSI_TX_TEST_AGGR_ENABLE +#define RSI_TX_TEST_AGGR_ENABLE RSI_DISABLE +#endif + +// TX TEST delay +#ifndef RSI_TX_TEST_DELAY +#define RSI_TX_TEST_DELAY 0 +#endif + +// TX TEST Number of packets +#ifndef RSI_TX_TEST_NUM_PKTS +#define RSI_TX_TEST_NUM_PKTS 0 +#endif + +#ifdef CHIP_9117 +#ifndef RSI_11AX_ENABLE +//11AX_ENABLE 0-disable, 1-enable +#define RSI_11AX_ENABLE 0 +#endif + +#ifndef RSI_CODING_TYPE +// coding_type 0-BCC 1-LDPC +#define RSI_CODING_TYPE 0 +#endif + +#ifndef RSI_NOMINAL_PE +// nominal_pe 0-0Us 1-8Us 2-16Us +#define RSI_NOMINAL_PE 0 +#endif + +// he_ppdu_type 0-HE SU PPDU, 1-HE ER SU PPDU, 2-HE TB PPDU, 3-HE MU PPDU +#ifndef RSI_HE_PPDU_TYPE +#define RSI_HE_PPDU_TYPE 0 +#endif + +//beam_change 0-sameway, 1-differently +#ifndef RSI_BEAM_CHANGE +#define RSI_BEAM_CHANGE 0 +#endif + +//BW 0-242 tone RU, 1-Upper 106 tone RU +#ifndef RSI_BW +#define RSI_BW 0 +#endif + +//UL_DL 0-PPDU sent by AP, 1-PPDU sent by STA to AP +#ifndef RSI_UL_DL +#define RSI_UL_DL 0 +#endif + +//STBC 0-no STBC, 1-STBC if only DCM is set to 0 +#ifndef RSI_STBC +#define RSI_STBC 0 +#endif + +//TX_BF 0-no beamforming matrix, 1- beamforming matrix +#ifndef RSI_TX_BF +#define RSI_TX_BF 0 +#endif + +//GT_LTF shall be in the range 0-3 +#ifndef RSI_GI_LTF +#define RSI_GI_LTF 0 +#endif + +//DCM 0-No DCM, 1-DCM +#ifndef RSI_DCM +#define RSI_DCM 0 +#endif + +//NSTS_MIDAMBLE shall be in the range 0-7 +#ifndef RSI_NSTS_MIDAMBLE +#define RSI_NSTS_MIDAMBLE 0 +#endif + +//spatial_reuse shall be in the range 0-15 +#ifndef RSI_SPATIAL_REUSE +#define RSI_SPATIAL_REUSE 0 +#endif + +//BSS_COLOR shall be in the range 0-63 +#ifndef RSI_BSS_COLOR +#define RSI_BSS_COLOR 0 +#endif + +//HE_SIGA2_RESERVED shall be in the range 0-511 +#ifndef RSI_HE_SIGA2_RESERVED +#define RSI_HE_SIGA2_RESERVED 0 +#endif + +//RU_ALLOCATION shall be in the range 0-255 +#ifndef RSI_RU_ALLOCATION +#define RSI_RU_ALLOCATION 0 +#endif + +//N_HELTF_TOT shall be in the range 0-7 +#ifndef RSI_N_HELTF_TOT +#define RSI_N_HELTF_TOT 0 +#endif + +//SIGB_DCM 0-disable, 1-enable +#ifndef RSI_SIGB_DCM +#define RSI_SIGB_DCM 0 +#endif + +//SIGB_MCS shall be in the range 0-5 +#ifndef RSI_SIGB_MCS +#define RSI_SIGB_MCS 0 +#endif + +//USER_STA_ID shall be in the range 0-2047 +#ifndef RSI_USER_STA_ID +#define RSI_USER_STA_ID 0 +#endif + +//USER_IDX shall be in the range 0-8 +#ifndef RSI_USER_IDX +#define RSI_USER_IDX 0 +#endif + +//SIGB_COMPRESSION_FIELD shall be 0/1 +#ifndef RSI_SIGB_COMPRESSION_FIELD +#define RSI_SIGB_COMPRESSION_FIELD 0 +#endif +#endif +/*=======================================================================*/ + +// ssl parameters +/*=======================================================================*/ +// ssl version +#ifndef RSI_SSL_VERSION +#define RSI_SSL_VERSION 0 +#endif + +#define RSI_SSL_RELEASE_2_0 RSI_ENABLE + +#ifdef CHIP_9117 +#ifndef RSI_SSL_EXT_CIPHERS +#define RSI_SSL_EXT_CIPHERS SSL_TLSV1_3_ALL_CIPHERS +#endif +#endif + +// ssl ciphers +#ifndef RSI_SSL_CIPHERS +#if RSI_SSL_RELEASE_2_0 +#define RSI_SSL_CIPHERS SSL_RELEASE_2_0_ALL_CIPHERS +#else +#define RSI_SSL_CIPHERS \ + (BIT_DHE_RSA_GCM | BIT_ECDHE_RSA_GCM | BIT_DHE_RSA_CBC | BIT_ECDHE_RSA_CBC | BIT_ECDHE_ECDSA_CBC | SSL_NEW_CIPHERS) +#endif +#endif + +// Enable TCP over SSL with TLS version depends on remote side +#ifndef PROTOCOL_DFLT_VERSION +#define PROTOCOL_DFLT_VERSION BIT(0) +#endif + +// Enable TCP over SSL with TLS version 1.0 +#ifndef PROTOCOL_TLS_1_0 +#define PROTOCOL_TLS_1_0 (BIT(0) | BIT(13)) +#endif + +// Enable TCP over SSL with TLS version 1.1 +#ifndef PROTOCOL_TLS_1_1 +#define PROTOCOL_TLS_1_1 (BIT(0) | BIT(14)) +#endif + +// Enable TCP over SSL with TLS version 1.2 +#ifndef PROTOCOL_TLS_1_2 +#define PROTOCOL_TLS_1_2 (BIT(0) | BIT(15)) +#endif +/*=======================================================================*/ + +// Power save command parameters +/*=======================================================================*/ +// set handshake type of power mode +#ifndef RSI_HAND_SHAKE_TYPE +#define RSI_HAND_SHAKE_TYPE MSG_BASED +#endif + +// 0 - LP, 1- ULP mode with RAM retention and 2 - ULP with Non RAM retention +#ifndef RSI_SELECT_LP_OR_ULP_MODE +#define RSI_SELECT_LP_OR_ULP_MODE RSI_ULP_WITH_RAM_RET +#endif + +// set DTIM aligment required +// 0 - module wakes up at beacon which is just before or equal to listen_interval +// 1 - module wakes up at DTIM beacon which is just before or equal to listen_interval +#ifndef RSI_DTIM_ALIGNED_TYPE +#define RSI_DTIM_ALIGNED_TYPE 0 +#endif + +// Monitor interval for the FAST PSP mode +// default is 50 ms, and this parameter is valid for FAST PSP only +#ifndef RSI_MONITOR_INTERVAL +#define RSI_MONITOR_INTERVAL 50 +#endif + +// Number of DTIMs to skip during powersave +#ifndef RSI_NUM_OF_DTIM_SKIP +#define RSI_NUM_OF_DTIM_SKIP 0 +#endif + +//WMM PS parameters +// set wmm enable or disable +#ifndef RSI_WMM_PS_ENABLE +#define RSI_WMM_PS_ENABLE RSI_DISABLE +#endif + +// set wmm enable or disable +// 0- TX BASED 1 - PERIODIC +#ifndef RSI_WMM_PS_TYPE +#define RSI_WMM_PS_TYPE 0 +#endif + +// set wmm wake up interval +#ifndef RSI_WMM_PS_WAKE_INTERVAL +#define RSI_WMM_PS_WAKE_INTERVAL 20 +#endif + +// set wmm UAPSD bitmap +#ifndef RSI_WMM_PS_UAPSD_BITMAP +#define RSI_WMM_PS_UAPSD_BITMAP 15 +#endif + +/*=======================================================================*/ + +// Socket configuration +/*=======================================================================*/ +// RSI_ENABLE or RSI_DISABLE High performance socket +#ifndef HIGH_PERFORMANCE_ENABLE +#define HIGH_PERFORMANCE_ENABLE RSI_ENABLE //@ RSI_ENABLE or RSI_DISABLE High performance socket +#endif + +#ifndef TOTAL_SOCKETS +#define TOTAL_SOCKETS 1 //@ Total number of sockets. TCP TX + TCP RX + UDP TX + UDP RX +#endif + +#ifndef TOTAL_TCP_SOCKETS +#define TOTAL_TCP_SOCKETS 1 //@ Total TCP sockets. TCP TX + TCP RX +#endif + +#ifndef TOTAL_UDP_SOCKETS +#define TOTAL_UDP_SOCKETS 0 //@ Total UDP sockets. UDP TX + UDP RX +#endif + +#ifndef TCP_TX_ONLY_SOCKETS +#define TCP_TX_ONLY_SOCKETS 0 //@ Total TCP TX only sockets. TCP TX +#endif + +#ifndef TCP_RX_ONLY_SOCKETS +#define TCP_RX_ONLY_SOCKETS 1 //@ Total TCP RX only sockets. TCP RX +#endif + +#ifndef UDP_TX_ONLY_SOCKETS +#define UDP_TX_ONLY_SOCKETS 0 //@ Total UDP TX only sockets. UDP TX +#endif + +#ifndef UDP_RX_ONLY_SOCKETS +#define UDP_RX_ONLY_SOCKETS 0 //@ Total UDP RX only sockets. UDP RX +#endif + +#ifndef TCP_RX_HIGH_PERFORMANCE_SOCKETS +#define TCP_RX_HIGH_PERFORMANCE_SOCKETS 1 //@ Total TCP RX High Performance sockets +#endif + +#ifndef TCP_RX_WINDOW_SIZE_CAP +#define TCP_RX_WINDOW_SIZE_CAP \ + 10 //@ TCP RX Window size - To scale the window size linearly according to the value (TCP MSS * TCP_RX_WINDOW_SIZE_CAP) +#endif + +#ifndef TCP_RX_WINDOW_DIV_FACTOR +#define TCP_RX_WINDOW_DIV_FACTOR \ + 10 //@ TCP RX Window division factor - To increase the ACK frequency for asynchronous sockets +#endif + +/*=======================================================================*/ + +// Socket Create parameters +/*=======================================================================*/ + +// Initial timeout for Socket +#ifndef RSI_SOCKET_KEEPALIVE_TIMEOUT +#define RSI_SOCKET_KEEPALIVE_TIMEOUT 1200 +#endif + +// VAP ID for Concurrent mode +#ifndef RSI_VAP_ID +#define RSI_VAP_ID 0 +#endif + +// Timeout for join or scan +/*=======================================================================*/ + +//RSI_ENABLE or RSI_DISABLE Timeout support +#ifndef RSI_TIMEOUT_SUPPORT +#define RSI_TIMEOUT_SUPPORT RSI_ENABLE +#endif + +// roaming threshold value +#ifndef RSI_TIMEOUT_BIT_MAP +#define RSI_TIMEOUT_BIT_MAP 1 +#endif + +// roaming hysterisis value +#ifndef RSI_TIMEOUT_VALUE +#define RSI_TIMEOUT_VALUE 3000 +#endif + +// Timeout for ping request +/*=======================================================================*/ + +//Timeout for PING_REQUEST +#ifndef RSI_PING_REQ_TIMEOUT_MS +#define RSI_PING_REQ_TIMEOUT_MS 10000 +#endif + +#ifndef RSI_PING_REQ_TIMEOUT +#define RSI_PING_REQ_TIMEOUT (RSI_PING_REQ_TIMEOUT_MS / 100) +#endif + +// Store Config Profile parameters +/*=======================================================================*/ + +// Client profile +#ifndef RSI_WLAN_PROFILE_CLIENT +#define RSI_WLAN_PROFILE_CLIENT 0 +#endif + +// P2P profile +#ifndef RSI_WLAN_PROFILE_P2P +#define RSI_WLAN_PROFILE_P2P 1 +#endif + +// EAP profile +#ifndef RSI_WLAN_PROFILE_EAP +#define RSI_WLAN_PROFILE_EAP 2 +#endif + +// AP profile +#ifndef RSI_WLAN_PROFILE_AP +#define RSI_WLAN_PROFILE_AP 6 +#endif + +// All profiles +#ifndef RSI_WLAN_PROFILE_ALL +#define RSI_WLAN_PROFILE_ALL 0xFF +#endif + +// AP Config Profile Parameters +/*==============================================================================*/ + +// Transmission data rate. Physical rate at which data has to be transmitted. +#ifndef RSI_CONFIG_AP_DATA_RATE +#define RSI_CONFIG_AP_DATA_RATE RSI_DATA_RATE_AUTO +#endif + +// To set wlan feature select bit map +#ifndef RSI_CONFIG_AP_WLAN_FEAT_BIT_MAP +#define RSI_CONFIG_AP_WLAN_FEAT_BIT_MAP (FEAT_SECURITY_PSK) +#endif + +// TCP/IP feature select bitmap for selecting TCP/IP features +#ifndef RSI_CONFIG_AP_TCP_IP_FEAT_BIT_MAP +#define RSI_CONFIG_AP_TCP_IP_FEAT_BIT_MAP (TCP_IP_FEAT_DHCPV4_SERVER) +#endif + +// To set custom feature select bit map +#ifndef RSI_CONFIG_AP_CUSTOM_FEAT_BIT_MAP +#define RSI_CONFIG_AP_CUSTOM_FEAT_BIT_MAP 0 +#endif + +// Tx power level +#ifndef RSI_CONFIG_AP_TX_POWER +#define RSI_CONFIG_AP_TX_POWER RSI_POWER_LEVEL_HIGH +#endif + +// AP SSID +#ifndef RSI_CONFIG_AP_SSID +#define RSI_CONFIG_AP_SSID "SILABS_AP" +#endif + +// RSI_BAND_2P4GHZ(2.4GHz) or RSI_BAND_5GHZ(5GHz) or RSI_DUAL_BAND +#ifndef RSI_CONFIG_AP_BAND +#define RSI_CONFIG_AP_BAND RSI_BAND_2P4GHZ +#endif + +// To configure AP channle number +#ifndef RSI_CONFIG_AP_CHANNEL +#define RSI_CONFIG_AP_CHANNEL 6 +#endif + +// To configure security type +#ifndef RSI_CONFIG_AP_SECURITY_TYPE +#define RSI_CONFIG_AP_SECURITY_TYPE RSI_WPA +#endif + +// To configure encryption type +#ifndef RSI_CONFIG_AP_ENCRYPTION_TYPE +#define RSI_CONFIG_AP_ENCRYPTION_TYPE 1 +#endif + +// To configure PSK +#ifndef RSI_CONFIG_AP_PSK +#define RSI_CONFIG_AP_PSK "1234567890" +#endif + +// To configure beacon interval +#ifndef RSI_CONFIG_AP_BEACON_INTERVAL +#define RSI_CONFIG_AP_BEACON_INTERVAL 100 +#endif + +// To configure DTIM period +#ifndef RSI_CONFIG_AP_DTIM +#define RSI_CONFIG_AP_DTIM 2 +#endif + +// This parameter is used to configure keep alive type +#ifndef RSI_CONFIG_AP_KEEP_ALIVE_TYPE +#define RSI_CONFIG_AP_KEEP_ALIVE_TYPE 0 // RSI_NULL_BASED_KEEP_ALIVE +#endif + +#ifndef RSI_CONFIG_AP_KEEP_ALIVE_COUNTER +#define RSI_CONFIG_AP_KEEP_ALIVE_COUNTER 0 // 100 +#endif + +// This parameter is used to configure keep alive period +#ifndef RSI_CONFIG_AP_KEEP_ALIVE_PERIOD +#define RSI_CONFIG_AP_KEEP_ALIVE_PERIOD 100 +#endif + +// This parameter is used to configure maximum stations supported +#ifndef RSI_CONFIG_AP_MAX_STATIONS_COUNT +#define RSI_CONFIG_AP_MAX_STATIONS_COUNT 4 +#endif + +// P2P Network parameters +// TCP_STACK_USED BIT(0) - IPv4, BIT(1) -IPv6, (BIT(0) | BIT(1)) - Both IPv4 and IPv6 +#ifndef RSI_CONFIG_AP_TCP_STACK_USED +#define RSI_CONFIG_AP_TCP_STACK_USED BIT(0) +#endif + +// IP address of the module +// E.g: 0x0A0AA8C0 == 192.168.10.10 +#ifndef RSI_CONFIG_AP_IP_ADDRESS +#define RSI_CONFIG_AP_IP_ADDRESS 0x0A0AA8C0 +#endif + +// IP address of netmask +// E.g: 0x00FFFFFF == 255.255.255.0 +#ifndef RSI_CONFIG_AP_SN_MASK_ADDRESS +#define RSI_CONFIG_AP_SN_MASK_ADDRESS 0x00FFFFFF +#endif + +// IP address of Gateway +// E.g: 0x0A0AA8C0 == 192.168.10.10 +#ifndef RSI_CONFIG_AP_GATEWAY_ADDRESS +#define RSI_CONFIG_AP_GATEWAY_ADDRESS 0x0A0AA8C0 +#endif + +// Client Profile Parameters +/* ===================================================================================== */ + +// To configure data rate +#ifndef RSI_CONFIG_CLIENT_DATA_RATE +#define RSI_CONFIG_CLIENT_DATA_RATE RSI_DATA_RATE_AUTO +#endif + +// To configure wlan feature bitmap +#ifndef RSI_CONFIG_CLIENT_WLAN_FEAT_BIT_MAP +#define RSI_CONFIG_CLIENT_WLAN_FEAT_BIT_MAP 0 +#endif + +// To configure tcp/ip feature bitmap +#ifndef RSI_CONFIG_CLIENT_TCP_IP_FEAT_BIT_MAP +#define RSI_CONFIG_CLIENT_TCP_IP_FEAT_BIT_MAP BIT(2) +#endif + +// To configure custom feature bit map +#ifndef RSI_CONFIG_CLIENT_CUSTOM_FEAT_BIT_MAP +#define RSI_CONFIG_CLIENT_CUSTOM_FEAT_BIT_MAP 0 +#endif + +// To configure TX power +#ifndef RSI_CONFIG_CLIENT_TX_POWER +#define RSI_CONFIG_CLIENT_TX_POWER RSI_POWER_LEVEL_HIGH +#endif + +// To configure listen interval +#ifndef RSI_CONFIG_CLIENT_LISTEN_INTERVAL +#define RSI_CONFIG_CLIENT_LISTEN_INTERVAL 0 +#endif + +// To configure SSID +#ifndef RSI_CONFIG_CLIENT_SSID +#define RSI_CONFIG_CLIENT_SSID "SILABS_AP" +#endif + +// RSI_BAND_2P4GHZ(2.4GHz) or RSI_BAND_5GHZ(5GHz) or RSI_DUAL_BAND +#ifndef RSI_CONFIG_CLIENT_BAND +#define RSI_CONFIG_CLIENT_BAND RSI_BAND_2P4GHZ +#endif + +// To configure channel number +#ifndef RSI_CONFIG_CLIENT_CHANNEL +#define RSI_CONFIG_CLIENT_CHANNEL 0 +#endif + +// To configure security type +#ifndef RSI_CONFIG_CLIENT_SECURITY_TYPE +#define RSI_CONFIG_CLIENT_SECURITY_TYPE RSI_WPA +#endif + +// To configure encryption type +#ifndef RSI_CONFIG_CLIENT_ENCRYPTION_TYPE +#define RSI_CONFIG_CLIENT_ENCRYPTION_TYPE 0 +#endif + +// To configure PSK +#ifndef RSI_CONFIG_CLIENT_PSK +#define RSI_CONFIG_CLIENT_PSK "1234567890" +#endif + +// To configure PMK +#ifndef RSI_CONFIG_CLIENT_PMK +#define RSI_CONFIG_CLIENT_PMK "" +#endif + +// Client Network parameters +// TCP_STACK_USED BIT(0) - IPv4, BIT(1) -IPv6, (BIT(0) | BIT(1)) - Both IPv4 and IPv6 +#ifndef RSI_CONFIG_CLIENT_TCP_STACK_USED +#define RSI_CONFIG_CLIENT_TCP_STACK_USED BIT(0) +#endif + +// DHCP mode 1- Enable 0- Disable +// If DHCP mode is disabled given IP statically +#ifndef RSI_CONFIG_CLIENT_DHCP_MODE +#define RSI_CONFIG_CLIENT_DHCP_MODE RSI_DHCP +#endif + +// IP address of the module +// E.g: 0x0A0AA8C0 == 192.168.10.10 +#ifndef RSI_CONFIG_CLIENT_IP_ADDRESS +#define RSI_CONFIG_CLIENT_IP_ADDRESS 0x0A0AA8C0 +#endif + +// IP address of netmask +// E.g: 0x00FFFFFF == 255.255.255.0 +#ifndef RSI_CONFIG_CLIENT_SN_MASK_ADDRESS +#define RSI_CONFIG_CLIENT_SN_MASK_ADDRESS 0x00FFFFFF +#endif + +// IP address of Gateway +// E.g: 0x010AA8C0 == 192.168.10.1 +#ifndef RSI_CONFIG_CLIENT_GATEWAY_ADDRESS +#define RSI_CONFIG_CLIENT_GATEWAY_ADDRESS 0x010AA8C0 +#endif + +// scan channel bit map in 2.4GHz band,valid if given channel to scan is 0 +#ifndef RSI_CONFIG_CLIENT_SCAN_FEAT_BITMAP +#define RSI_CONFIG_CLIENT_SCAN_FEAT_BITMAP 0 +#endif + +// Scan channel magic code +#ifndef RSI_CONFIG_CLIENT_MAGIC_CODE +#define RSI_CONFIG_CLIENT_MAGIC_CODE 0x4321 +#endif + +// scan channel bit map in 2.4GHz band,valid if given channel to scan is 0 +#ifndef RSI_CONFIG_CLIENT_SCAN_CHAN_BITMAP_2_4_GHZ +#define RSI_CONFIG_CLIENT_SCAN_CHAN_BITMAP_2_4_GHZ 0 +#endif + +// scan channle bit map in 5GHz band ,valid if given channel to scan is 0 +#ifndef RSI_CONFIG_CLIENT_SCAN_CHAN_BITMAP_5_0_GHZ +#define RSI_CONFIG_CLIENT_SCAN_CHAN_BITMAP_5_0_GHZ 0 +#endif + +// EAP Client Profile Parameters +/* =========================================================================== */ + +// To configure data rate +#ifndef RSI_CONFIG_EAP_DATA_RATE +#define RSI_CONFIG_EAP_DATA_RATE RSI_DATA_RATE_AUTO +#endif + +// To configure wlan feature bitmap +#ifndef RSI_CONFIG_EAP_WLAN_FEAT_BIT_MAP +#define RSI_CONFIG_EAP_WLAN_FEAT_BIT_MAP 0 +#endif + +// To configure tcp/ip feature bitmap +#ifndef RSI_CONFIG_EAP_TCP_IP_FEAT_BIT_MAP +#define RSI_CONFIG_EAP_TCP_IP_FEAT_BIT_MAP BIT(2) +#endif + +// To configure custom feature bit map +#ifndef RSI_CONFIG_EAP_CUSTOM_FEAT_BIT_MAP +#define RSI_CONFIG_EAP_CUSTOM_FEAT_BIT_MAP 0 +#endif + +// To configure EAP TX power +#ifndef RSI_CONFIG_EAP_TX_POWER +#define RSI_CONFIG_EAP_TX_POWER RSI_POWER_LEVEL_HIGH +#endif + +// To Configure scan channel feature bitmap +#ifndef RSI_CONFIG_EAP_SCAN_FEAT_BITMAP +#define RSI_CONFIG_EAP_SCAN_FEAT_BITMAP 0 +#endif + +// scan channel bit map in 2.4GHz band,valid if given channel to scan is 0 +#ifndef RSI_CONFIG_EAP_CHAN_MAGIC_CODE +#define RSI_CONFIG_EAP_CHAN_MAGIC_CODE 0 //0x4321 +#endif + +// scan channel bit map in 2.4GHz band,valid if given channel to scan is 0 +#ifndef RSI_CONFIG_EAP_SCAN_CHAN_BITMAP_2_4_GHZ +#define RSI_CONFIG_EAP_SCAN_CHAN_BITMAP_2_4_GHZ 0 +#endif + +// scan channle bit map in 5GHz band ,valid if given channel to scan is 0 +#ifndef RSI_CONFIG_EAP_SCAN_CHAN_BITMAP_5_0_GHZ +#define RSI_CONFIG_EAP_SCAN_CHAN_BITMAP_5_0_GHZ 0 +#endif + +// To configure SSID +#ifndef RSI_CONFIG_EAP_SSID +#define RSI_CONFIG_EAP_SSID "SILABS_AP" +#endif + +// RSI_BAND_2P4GHZ(2.4GHz) or RSI_BAND_5GHZ(5GHz) or RSI_DUAL_BAND +#ifndef RSI_CONFIG_EAP_BAND +#define RSI_CONFIG_EAP_BAND RSI_BAND_2P4GHZ +#endif + +// To set security type +#ifndef RSI_CONFIG_EAP_SECURITY_TYPE +#define RSI_CONFIG_EAP_SECURITY_TYPE RSI_WPA2_EAP +#endif + +// To set encryption type +#ifndef RSI_CONFIG_EAP_ENCRYPTION_TYPE +#define RSI_CONFIG_EAP_ENCRYPTION_TYPE 0 +#endif + +// To set channel number +#ifndef RSI_CONFIG_EAP_CHANNEL +#define RSI_CONFIG_EAP_CHANNEL 0 +#endif + +// Enterprise method ,should be one of among TLS, TTLS, FAST or PEAP +#ifndef RSI_CONFIG_EAP_METHOD +#define RSI_CONFIG_EAP_METHOD "TLS" +#endif + +// This parameter is used to configure the module in Enterprise security mode +#ifndef RSI_CONFIG_EAP_INNER_METHOD +#define RSI_CONFIG_EAP_INNER_METHOD "\"auth=MSCHAPV2\"" +#endif + +// To configure EAP user identity +#ifndef RSI_CONFIG_EAP_USER_IDENTITY +#define RSI_CONFIG_EAP_USER_IDENTITY "\"user1\"" +#endif + +// TO configure EAP password +#ifndef RSI_CONFIG_EAP_PASSWORD +#define RSI_CONFIG_EAP_PASSWORD "\"test123\"" +#endif + +// EAP Network parameters +// TCP_STACK_USED BIT(0) - IPv4, BIT(1) -IPv6, (BIT(0) | BIT(1)) - Both IPv4 and IPv6 +#ifndef RSI_CONFIG_EAP_TCP_STACK_USED +#define RSI_CONFIG_EAP_TCP_STACK_USED BIT(0) +#endif + +// DHCP mode 1- Enable 0- Disable +// If DHCP mode is disabled given IP statically +#ifndef RSI_CONFIG_EAP_DHCP_MODE +#define RSI_CONFIG_EAP_DHCP_MODE RSI_DHCP +#endif + +// IP address of the module +// E.g: 0x0A0AA8C0 == 192.168.10.10 +#ifndef RSI_CONFIG_EAP_IP_ADDRESS +#define RSI_CONFIG_EAP_IP_ADDRESS 0x0A0AA8C0 +#endif + +// IP address of netmask +// E.g: 0x00FFFFFF == 255.255.255.0 +#ifndef RSI_CONFIG_EAP_SN_MASK_ADDRESS +#define RSI_CONFIG_EAP_SN_MASK_ADDRESS 0x00FFFFFF +#endif + +// IP address of Gateway +// E.g: 0x010AA8C0 == 192.168.10.1 +#ifndef RSI_CONFIG_EAP_GATEWAY_ADDRESS +#define RSI_CONFIG_EAP_GATEWAY_ADDRESS 0x010AA8C0 +#endif + +// P2P Profile parameters +/* ================================================================================= */ + +// To configure data rate +#ifndef RSI_CONFIG_P2P_DATA_RATE +#define RSI_CONFIG_P2P_DATA_RATE RSI_DATA_RATE_AUTO +#endif +// To configure wlan feature bitmap +#ifndef RSI_CONFIG_P2P_WLAN_FEAT_BIT_MAP +#define RSI_CONFIG_P2P_WLAN_FEAT_BIT_MAP 0 +#endif + +// To configure P2P tcp/ip feature bitmap +#ifndef RSI_CONFIG_P2P_TCP_IP_FEAT_BIT_MAP +#define RSI_CONFIG_P2P_TCP_IP_FEAT_BIT_MAP BIT(2) +#endif + +// To configure P2P custom feature bitmap +#ifndef RSI_CONFIG_P2P_CUSTOM_FEAT_BIT_MAP +#define RSI_CONFIG_P2P_CUSTOM_FEAT_BIT_MAP 0 +#endif + +// TO configure P2P tx power level +#ifndef RSI_CONFIG_P2P_TX_POWER +#define RSI_CONFIG_P2P_TX_POWER RSI_POWER_LEVEL_HIGH +#endif + +// Set P2P go intent +#ifndef RSI_CONFIG_P2P_GO_INTNET +#define RSI_CONFIG_P2P_GO_INTNET 16 // Support only Autonomous GO mode +#endif + +// Set device name +#ifndef RSI_CONFIG_P2P_DEVICE_NAME +#define RSI_CONFIG_P2P_DEVICE_NAME "WSC1.1" +#endif + +// Set device operating channel +#ifndef RSI_CONFIG_P2P_OPERATING_CHANNEL +#define RSI_CONFIG_P2P_OPERATING_CHANNEL 11 +#endif + +// Set SSID postfix +#ifndef RSI_CONFIG_P2P_SSID_POSTFIX +#define RSI_CONFIG_P2P_SSID_POSTFIX "WSC_1_0_0" +#endif + +// Set P2P join SSID +#ifndef RSI_CONFIG_P2P_JOIN_SSID +#define RSI_CONFIG_P2P_JOIN_SSID "SILABS_AP" +#endif + +// Set psk key +#ifndef RSI_CONFIG_P2P_PSK_KEY +#define RSI_CONFIG_P2P_PSK_KEY "12345678" +#endif + +// P2P Network parameters +// TCP_STACK_USED BIT(0) - IPv4, BIT(1) -IPv6, (BIT(0) | BIT(1)) - Both IPv4 and IPv6 +#ifndef RSI_CONFIG_P2P_TCP_STACK_USED +#define RSI_CONFIG_P2P_TCP_STACK_USED BIT(0) +#endif + +// DHCP mode 1- Enable 0- Disable +// If DHCP mode is disabled given IP statically +#ifndef RSI_CONFIG_P2P_DHCP_MODE +#define RSI_CONFIG_P2P_DHCP_MODE 1 +#endif + +// IP address of the module +// E.g: 0x0A0AA8C0 == 192.168.10.10 +#ifndef RSI_CONFIG_P2P_IP_ADDRESS +#define RSI_CONFIG_P2P_IP_ADDRESS 0x0A0AA8C0 +#endif + +// IP address of netmask +// E.g: 0x00FFFFFF == 255.255.255.0 +#ifndef RSI_CONFIG_P2P_SN_MASK_ADDRESS +#define RSI_CONFIG_P2P_SN_MASK_ADDRESS 0x00FFFFFF +#endif + +// IP address of Gateway +// E.g: 0x010AA8C0 == 192.168.10.1 +#ifndef RSI_CONFIG_P2P_GATEWAY_ADDRESS +#define RSI_CONFIG_P2P_GATEWAY_ADDRESS 0x010AA8C0 +#endif + +/*=======================================================================*/ +// buffer allocation parameters +/*=======================================================================*/ + +#ifndef TX_RX_RATIO_ENABLE +#define TX_RX_RATIO_ENABLE RSI_DISABLE +#endif + +#ifndef TX_POOL_RATIO +#define TX_POOL_RATIO 1 +#endif + +#ifndef RX_POOL_RATIO +#define RX_POOL_RATIO 1 +#endif + +#ifndef GLOBAL_POOL_RATIO +#define GLOBAL_POOL_RATIO 1 +#endif +/*=======================================================================*/ + +// Unblock call +/*=======================================================================*/ +#ifndef BUFFER_FULL_HANDLING +#define BUFFER_FULL_HANDLING RSI_DISABLE +#endif +/*=======================================================================*/ + +// To enable ASSERT indication from module +/*========================================================================*/ +#ifndef RSI_ASSERT_ENABLE +#define RSI_ASSERT_ENABLE 1 +#endif +/*========================================================================*/ +// 11ax params +/*========================================================================*/ +#define HE_PARAMS_SUPPORT RSI_DISABLE +#define GUARD_INTERVAL 3 +#define NOMINAL_PE 2 +#define DCM_ENABLE 0 +#define LDPC_ENABLE 0 +#define NG_CB_ENABLE 0 +#define NG_CB_VALUES 0 +#define UORA_ENABLE 0 +#define TRIGGER_RESP_IND 0xF +#define IPPS_VALID_VALUE 0 +#define TX_ONLY_ON_AP_TRIG 0 +#define TWT_SUPPORT RSI_DISABLE +/* 0 - NO ER_SU support, 1 - Use ER_SU rates along with Non_ER_SU rates, 2 - Use ER_SU rates only */ +#define CONFIG_ER_SU NO_ER_SU_SUPPORT +/*========================================================================*/ +#endif diff --git a/wiseconnect/sapi/include/rsi_wlan_defines.h b/wiseconnect/sapi/include/rsi_wlan_defines.h new file mode 100644 index 00000000..1de1507d --- /dev/null +++ b/wiseconnect/sapi/include/rsi_wlan_defines.h @@ -0,0 +1,30 @@ +/******************************************************************************* +* @file rsi_wlan_defines.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_WLAN_DEFINES_H +#define RSI_WLAN_DEFINES_H + +#ifndef BIT +#define BIT(a) ((uint32_t)1U << (a)) +#endif + +#endif diff --git a/wiseconnect/sapi/include/rsi_wlan_non_rom.h b/wiseconnect/sapi/include/rsi_wlan_non_rom.h new file mode 100644 index 00000000..dccae46f --- /dev/null +++ b/wiseconnect/sapi/include/rsi_wlan_non_rom.h @@ -0,0 +1,638 @@ +/******************************************************************************* +* @file rsi_wlan_non_rom.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_WLAN_NON_ROM_H +#define RSI_WLAN_NON_ROM_H +#include "rsi_socket.h" +#include "rsi_os.h" + +#include "rsi_scheduler.h" + +// Max chunk size +#define CHUNK_SIZE 1472 + +#define MAX_RX_DATA_LENGTH (1460 * 3) +#define RX_DATA_LENGTH 16384 +// Assertion value register address +#define RSI_ASSERT_VAL_RD_REG 0x41050034 +#define RSI_ASSERT_INTR_CLR_REG 0x41050008 + +#ifndef MIN +#define MIN(x, y) ((x) < (y) ? (x) : (y)) +#endif + +typedef enum { + RSI_WLAN_RADIO_DEREGISTER = 1, + RSI_WLAN_RADIO_REGISTER, +} wlan_radio; + +#define RSI_SSL_HEADER_SIZE 90 + +#define RSI_MAX_NUM_CALLBACKS 20 + +#ifdef CHIP_9117 +#define MAX_SIZE_OF_EXTENSION_DATA 256 +#else +#define MAX_SIZE_OF_EXTENSION_DATA 64 +#endif + +typedef struct rsi_socket_info_non_rom_s { + uint8_t max_tcp_retries; + + uint8_t vap_id; + + // TCP keepalive initial timeout + uint8_t tcp_keepalive_initial_time[2]; + + // Asynchronous accpet respone handler + void (*accept_call_back_handler)(int32_t sock_id, int16_t dest_port, uint8_t *ip_addr, int16_t ip_version); + // Asynchronous data tx done call back handler + void (*rsi_sock_data_tx_done_cb)(int32_t sockID, int16_t status, uint16_t total_data_sent); + + // total data to be send + int8_t *buffer; + // total data sent + int32_t offset; + // remaining data to be send + int32_t rem_len; + // flag which indicates more data is present + uint32_t more_data; + // user flags + int32_t flags; + + // ssl version select bit map +#ifdef CHIP_9117 + uint32_t ssl_bitmap; +#else + uint8_t ssl_bitmap; +#endif + + // High performance socket + uint8_t high_performance_socket; + + uint8_t socket_wait_bitmap; + uint8_t recv_pending_bit; + // tcp retry transmission timer + uint8_t tcp_retry_transmit_timer; + // TCP MSS + uint16_t tcp_mss; + + rsi_semaphore_handle_t socket_sem; + rsi_semaphore_handle_t sock_recv_sem; + + rsi_semaphore_handle_t sock_send_sem; + uint8_t socket_terminate_indication; + + int32_t socket_status; + // 2 bytes, Remote peer MSS size + uint16_t mss; + uint8_t wait_to_connect; + uint8_t sock_non_block; + uint16_t no_of_tls_extensions; + uint16_t extension_offset; + uint8_t tls_extension_data[MAX_SIZE_OF_EXTENSION_DATA]; + uint32_t window_size; +#ifdef SOCKET_CLOSE_WAIT + uint8_t close_pending; +#endif +#ifdef RSI_PROCESS_MAX_RX_DATA + uint8_t more_rx_data_pending; +#endif + +#ifdef CHIP_9117 + uint16_t tos; +#else + uint32_t tos; +#endif +#ifdef CHIP_9117 + //! max retransmission timeout value. + uint8_t max_retransmission_timeout_value; + uint16_t ssl_buff_len; +#endif +} rsi_socket_info_non_rom_t; + +typedef struct rsi_tls_tlv_s { + uint16_t type; + uint16_t length; +} rsi_tls_tlv_t; +typedef struct rsi_req_tcp_window_update_s { + // Socket ID + uint32_t socket_id; + + // window size + uint32_t window_size; + +} rsi_req_tcp_window_update_t; +typedef struct rsi_rsp_tcp_window_update_s { + // Socket ID + uint32_t socket_id; + + // window size + uint32_t window_size; + +} rsi_rsp_tcp_window_update_t; + +typedef struct rsi_max_available_rx_window_s { + // Maximum TCP Rx window available + uint32_t max_window_size; + + //window reset + uint32_t window_reset; +} rsi_max_available_rx_window_t; + +// call backs structure +typedef struct rsi_callback_cb_s { + // events to be registered explicitly: and has an event id + + // join fail handler pointer + void (*join_fail_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // ip renewal fail handler pointer + void (*ip_renewal_fail_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // remote socket terminate handler pointer + void (*remote_socket_terminate_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // ip change notify handler pointer + void (*ip_change_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // stations connect notify handler pointer + void (*stations_connect_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // stations disconnect notify handler pointer + void (*stations_disconnect_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // Raw data receive handler pointer + void (*wlan_data_receive_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // events which are registered in APIS + + // Receive stats response handler pointer + void (*wlan_receive_stats_response_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // Wifi direct device discovery noitfy handler pointer + void (*wlan_wfd_discovery_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // wifi direct connection request notify handler pointer + void (*wlan_wfd_connection_request_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // async scan response handler pointer + void (*wlan_scan_response_handler)(uint16_t status, const uint8_t *buffer, const uint16_t length); + + // async join response handler pointer + void (*wlan_join_response_handler)(uint16_t status, const uint8_t *buffer, const uint16_t length); + + // async ping response handler pointer + void (*wlan_ping_response_handler)(uint16_t status, const uint8_t *buffer, const uint16_t length); + + //raw data response handler pointer + void (*raw_data_receive_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + void (*auto_config_rsp_handler)(uint16_t status, uint8_t state); + + void (*socket_connect_response_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + void (*certificate_response_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + void (*wlan_async_module_state)(uint16_t status, uint8_t *buffer, const uint32_t length); + + void (*flash_write_response_handler)(uint16_t status); + + //Assertion response handler pointer + void (*rsi_assertion_cb)(uint16_t assert_val, uint8_t *buffer, const uint32_t length); + + // Wlan tcp window update handler + void (*rsi_max_available_rx_window)(uint16_t status, uint8_t *buffer, const uint32_t length); + + //TWT status response handler + void (*twt_response_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + //CSI data receive response handler + void (*wlan_receive_csi_data_response_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); +} rsi_callback_cb_t; + +// enumerations for call back types +typedef enum rsi_callback_id_e { + RSI_JOIN_FAIL_CB = 0, + RSI_IP_FAIL_CB = 1, + RSI_REMOTE_SOCKET_TERMINATE_CB = 2, + RSI_IP_CHANGE_NOTIFY_CB = 3, + RSI_STATIONS_DISCONNECT_NOTIFY_CB = 4, + RSI_STATIONS_CONNECT_NOTIFY_CB = 5, + RSI_WLAN_DATA_RECEIVE_NOTIFY_CB = 6, + RSI_WLAN_WFD_DISCOVERY_NOTIFY_CB = 7, + RSI_WLAN_RECEIVE_STATS_RESPONSE_CB = 8, + RSI_WLAN_WFD_CONNECTION_REQUEST_NOTIFY_CB = 9, + RSI_WLAN_SCAN_RESPONSE_HANDLER = 10, + RSI_WLAN_JOIN_RESPONSE_HANDLER = 11, + RSI_WLAN_RAW_DATA_RECEIVE_HANDLER = 12, + RSI_WLAN_SOCKET_CONNECT_NOTIFY_CB = 13, + RSI_WLAN_SERVER_CERT_RECEIVE_NOTIFY_CB = 14, + RSI_WLAN_ASYNC_STATS = 15, + RSI_FLASH_WRITE_RESPONSE = 16, + RSI_WLAN_ASSERT_NOTIFY_CB = 17, + RSI_WLAN_MAX_TCP_WINDOW_NOTIFY_CB = 18, + RSI_WLAN_TWT_RESPONSE_CB = 19, + RSI_WLAN_RECEIVE_CSI_DATA = 20 +} rsi_callback_id_t; +typedef struct rsi_nwk_callback_s { + + void (*nwk_error_call_back_handler)(uint8_t command_type, + uint32_t status, + const uint8_t *buffer, + const uint32_t length); + + // http response notify handler pointer +#if RSI_HTTP_STATUS_INDICATION_EN + void (*http_client_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t more_data, + uint16_t status_code); +#else + void (*http_client_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t more_data); +#endif + // HTTP OTAF response notify handler pointer + void (*http_otaf_response_handler)(uint16_t status, const uint8_t *buffer); + + // sntp create response notify handler pointer + void (*rsi_sntp_client_create_response_handler)(uint16_t status, const uint8_t cmd_type, const uint8_t *buffer); + + // smtp mail sent response notify handler pointer + void (*smtp_client_mail_response_handler)(uint16_t status, const uint8_t cmd_type); + + // smtp client delete response notify handler pointer + void (*smtp_client_delete_response_handler)(uint16_t status, const uint8_t cmd_type); + + // FTP client directory list + void (*ftp_directory_list_call_back_handler)(uint16_t status, + uint8_t *directory_list, + uint16_t length, + uint8_t end_of_list); + + // FTP client file read callback handler + void (*ftp_file_read_call_back_handler)(uint16_t status, + uint8_t *file_content, + uint16_t content_length, + uint8_t end_of_file); + // Callback for data transfer complete notification + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length); + + // webpage request handler + void (*rsi_webpage_request_handler)(uint8_t type, + uint8_t *url_name, + uint8_t *post_content_buffer, + uint32_t post_content_length, + uint32_t status); + + // Json object upadte response handler + void (*rsi_json_object_update_handler)(uint8_t *file_name, uint8_t *json_object, uint32_t length, uint32_t status); + + // wireless firmware upgrade handler + void (*rsi_wireless_fw_upgrade_handler)(uint8_t type, uint32_t status); + + // Json object event response handler + void (*rsi_json_object_event_handler)(uint32_t status, uint8_t *json_object_str, uint32_t length); + + // POP3 client response notify handler pointer + void (*rsi_pop3_client_mail_response_handler)(uint16_t status, uint8_t cmd_type, const uint8_t *buffer); + + // HTTP CLIENT PUT response notify handler pointer + void (*rsi_http_client_put_response_handler)(uint16_t status, + uint8_t cmd_type, + const uint8_t *buffer, + uint16_t length, + const uint8_t end_of_put_pkt); + + // HTTP CLIENT POST data response notify handler pointer +#if RSI_HTTP_STATUS_INDICATION_EN + void (*rsi_http_client_post_data_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t more_data, + uint16_t status_code); +#else + void (*rsi_http_client_post_data_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t more_data); +#endif + + // HTTP CLIENT POST data response notify handler pointer + void (*rsi_ota_fw_up_response_handler)(uint16_t status, uint16_t chunk_number); + + // DNS client hostname update response notify handler pointer + void (*rsi_dns_update_rsp_handler)(uint16_t status); + + // DHCP USER CLASS response notify handler pointer + void (*rsi_dhcp_usr_cls_rsp_handler)(uint16_t status); + + // Remote terminate of Embedded mqtt socket call back handler + void (*rsi_emb_mqtt_remote_terminate_handler)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // MQTT Call back for publish message + void (*rsi_emb_mqtt_publish_message_callback)(uint16_t status, uint8_t *buffer, const uint32_t length); + + // MQTT keep alive timeout callback handler + void (*rsi_emb_mqtt_keep_alive_timeout_callback)(uint16_t status, uint8_t *buffer, const uint32_t length); + +} rsi_nwk_callback_t; + +// enumerations for nwk call back types +typedef enum rsi_nwk_callback_id_e { + RSI_NWK_ERROR_CB = 0, + RSI_WLAN_NWK_URL_REQ_CB = 1, + RSI_WLAN_NWK_JSON_UPDATE_CB = 2, + RSI_WLAN_NWK_FW_UPGRADE_CB = 3, + RSI_WLAN_NWK_JSON_EVENT_CB = 4, + RSI_WLAN_NWK_EMB_MQTT_REMOTE_TERMINATE_CB = 5, + RSI_WLAN_NWK_EMB_MQTT_PUB_MSG_CB = 6, + RSI_WLAN_NWK_EMB_MQTT_KEEPALIVE_TIMEOUT_CB = 7 +} rsi_nwk_callback_id_t; + +// wlan radio req structure +typedef struct rsi_wlan_req_radio_s { + uint8_t radio_req; +} rsi_wlan_req_radio_t; + +/*==================================================*/ +// Asynchronous message for connection state notification +typedef struct rsi_state_notification_s { + uint8_t TimeStamp[4]; + uint8_t StateCode; + uint8_t reason_code; + uint8_t rsi_channel; + uint8_t rsi_rssi; + uint8_t rsi_bssid[6]; +} rsi_state_notification_t; + +/*==================================================*/ +#define WLAN_MODULE_STATES 11 +#define WLAN_REASON_CODES 50 +struct rsi_bit_2_string { + uint8_t bit; + char *string; +}; +static const struct rsi_bit_2_string STATE[WLAN_MODULE_STATES] = { + { 0x10, (char *)"Beacon Loss (Failover Roam)" }, + { 0x20, (char *)"De-authentication (AP induced Roam / Disconnect from supplicant" }, + { 0x50, (char *)"Current AP is best" }, + { 0x60, (char *)"Better AP found" }, + { 0x70, (char *)"No AP found" }, + { 0x80, (char *)"Associated" }, + { 0x90, (char *)"Unassociated" }, + { 0x01, (char *)"Authentication denial" }, + { 0x02, (char *)"Association denial" }, + { 0x03, (char *)"AP not present" }, + { 0x05, (char *)"WPA2 key exchange failed" } + +}; + +static const struct rsi_bit_2_string REASONCODE[WLAN_REASON_CODES] = { + { 0x01, (char *)"Authentication denial" }, + { 0x02, (char *)"Association denial" }, + { 0x10, (char *)"Beacon Loss (Failover Roam)" }, + { 0x20, (char *)"De-authentication (AP induced Roam/Deauth from supplicant)" }, + { 0x07, (char *)"PSK not configured" }, + { 0x05, (char *)"Roaming not enabled" }, + { 0x28, (char *)"TLS CA Cert not present" }, + { 0x29, (char *)"TLS PRIVATE key not present " }, + { 0x2A, (char *)"TLS Client Cert not present" }, + { 0x2B, (char *)"TLS no Cert present" }, + { 0x2C, (char *)"PEAP CA Cert not present" }, + { 0x2D, (char *)"Server Cert Invalid Key Type" }, + { 0x2E, (char *)"Server Intermediate CA Invalid Key Type" }, + { 0x2F, (char *)"Server Root CA Invalid Key Type" }, + { 0x30, (char *)"Client Cert Invalid Key Type" }, + { 0x31, (char *)"Client Root CA Invalid Key Type" }, + { 0x32, (char *)"FIPS Server Cert Invalid Length" }, + { 0x33, (char *)"FIPS Server Intermediate CA Invalid Length" }, + { 0x34, (char *)"FIPS Server Root CA Invalid Length" }, + { 0x35, (char *)"FIPS Client Cert Invlaid Length" }, + { 0x36, (char *)"FIPS Client Root CA Invalid Length" }, + { 0x37, (char *)"Server Cert Invalid Length" }, + { 0x38, (char *)"Server Intermediate CA Invalid Length" }, + { 0x39, (char *)"Server Root CA Invalid Length" }, + { 0x3A, (char *)"Client Cert Invalid Lenght" }, + { 0x3B, (char *)"Client Root CA Invalid Length" }, + { 0x3C, (char *)"Server Cert Invalid Sign Alg" }, + { 0x3D, (char *)"Server Intermediate CA Invalid Sign Alg" }, + { 0x3E, (char *)"Server Root CA Invalid Sign Length" }, + { 0x3F, (char *)"Client Cert Invalid Sign Alg" }, + { 0x40, (char *)"Client Root CA Invalid Sign Length" }, + { 0x41, (char *)"Server Intermediate CA not Present" }, + { 0x42, (char *)"Server Root CA Parse Error" }, + { 0x43, (char *)"Server Intermediate Root CA Parse Error" }, + { 0x44, (char *)"Sever Cert Parse Error" }, + { 0x45, (char *)"Client Cert Parse Error" }, + { 0x46, (char *)"Incorrect Private Key Password" }, + { 0x47, (char *)"EAP Failure Received" }, + { 0x48, (char *)"Client Cert Bad Date Error" }, + { 0x49, (char *)"Server Cert Bad Date Error" }, + { 0x4A, (char *)"Server Root CA Bad Date Error" }, + { 0x4B, (char *)"Client Root CA Bad Date Error" }, + { 0x4C, (char *)"Server Intermediate Root CA Bad Date Error" }, + { 0x4D, (char *)"Pem Header Error" }, + { 0x4E, (char *)"Pem Footer Error" }, + { 0x4F, (char *)"Client Intermediate CA Invalid Sign Length" }, + { 0x50, (char *)"Client Intermediate CA Invalid Length" }, + { 0x51, (char *)"FIPS Client Intermediate CA Invalid Length" }, + { 0x52, (char *)"Client Intermediate CA invalid Key Type" }, + { 0x53, (char *)"Pem Error" } +}; + +int32_t rsi_socket_create_async(int32_t sockID, int32_t type, int32_t backlog); +int32_t rsi_get_socket_descriptor(uint8_t *src_port, + uint8_t *dst_port, + uint8_t *ip_addr, + uint16_t ip_version, + uint16_t sockid); +int32_t rsi_socket_connect(int32_t sockID, struct rsi_sockaddr *remoteAddress, int32_t addressLength); +int32_t rsi_socket_recvfrom(int32_t sockID, + int8_t *buffer, + int32_t buffersize, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen); +rsi_error_t rsi_wait_on_socket_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms); +int32_t rsi_accept_non_rom(int32_t sockID, struct rsi_sockaddr *ClientAddress, int32_t *addressLength); +int32_t rsi_socket_async_non_rom(int32_t protocolFamily, + int32_t type, + int32_t protocol, + void (*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length)); +int32_t rsi_socket_listen(int32_t sockID, int32_t backlog); +int32_t rsi_socket_shutdown(int32_t sockID, int32_t how); +int32_t rsi_select_get_status(int32_t selectid); +void rsi_select_set_status(int32_t status, int32_t selectid); +int32_t rsi_socket_bind(int32_t sockID, struct rsi_sockaddr *localAddress, int32_t addressLength); +void rsi_clear_sockets_non_rom(int32_t sockID); +int32_t rsi_sendto_async_non_rom(int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen, + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length)); +int32_t rsi_send_async_non_rom(int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length)); +void rsi_wlan_socket_set_status(int32_t status, int32_t sockID); +int32_t rsi_wlan_socket_get_status(int32_t sockID); +int32_t rsi_get_socket_id(uint32_t src_port, uint32_t dst_port); +int32_t rsi_application_socket_descriptor(int32_t sock_id); +void rsi_post_waiting_socket_semaphore(int32_t sockID); +int32_t rsi_wlan_req_radio(uint8_t enable); +int32_t rsi_wlan_radio_deinit(void); +int32_t rsi_send_large_data_sync(int32_t sockID, const int8_t *msg, int32_t msgLength, int32_t flags); +uint32_t rsi_get_event(rsi_scheduler_cb_t *scheduler_cb); +#ifdef RSI_PROCESS_MAX_RX_DATA +int32_t rsi_recv_large_data_sync(int32_t sockID, + int8_t *buffer, + int32_t buffersize, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen); +#endif +#if (defined(RSI_WITH_OS) && defined(MXRT_595s)) +void rsi_scheduler_non_rom(rsi_scheduler_cb_t *scheduler_cb); +void rsi_set_event_non_rom(uint32_t event_num); +void rsi_set_event_from_isr_non_rom(uint32_t event_num); +void rsi_unmask_event_from_isr_non_rom(uint32_t event_num); +void rsi_unmask_event_non_rom(uint32_t event_num); +#endif +int rsi_getsockopt(int32_t sockID, int level, int option_name, const void *option_value, rsi_socklen_t option_len); +int32_t rsi_tcp_window_update(uint32_t sockID, uint32_t new_size_bytes); +typedef enum { + RSI_SOCKET_SELECT_STATE_INIT = 0, + RSI_SOCKET_SELECT_STATE_CREATE, +} select_state; + +// driver WLAN control block +typedef struct rsi_wlan_cb_non_rom_s { + uint32_t tls_version; + uint8_t join_bssid_non_rom[6]; + // to identify on which socket data is present + uint32_t socket_bitmap; +#ifdef RSI_UART_INTERFACE + uint8_t rsi_uart_data_ack_check; +#endif + void (*switch_proto_callback)(uint16_t mode, uint8_t *bt_disabled_status); + + uint16_t read_data; + + // network callbacks + rsi_nwk_callback_t nwk_callbacks; + + // application call back list structure + rsi_callback_cb_t callback_list; + + uint8_t wlan_radio; + uint16_t ps_listen_interval; + + uint8_t emb_mqtt_ssl_enable; + + //! scan results to host + uint8_t scan_results_to_host; + + //! socket connection request pending + uint32_t socket_cmd_rsp_pending; + //! network command request pending + uint32_t nwk_cmd_rsp_pending; +} rsi_wlan_cb_non_rom_t; + +#define RSI_AP_NOT_FOUND 0x3 + +// Network command Request pending bitmaps +#define PING_RESPONSE_PENDING BIT(0) +#define DNS_RESPONSE_PENDING BIT(1) +#define SNTP_RESPONSE_PENDING BIT(2) +/*===================================================*/ +typedef struct rsi_rsp_waiting_cmds_s { + uint16_t waiting_cmds; + uint8_t rx_driver_flag; +} rsi_rsp_waiting_cmds_t; + +// socket select request structure +typedef struct rsi_socket_select_info_s { + // read fds + rsi_fd_set *rsi_sel_read_fds; + + // writes fds + rsi_fd_set *rsi_sel_write_fds; + + //expection fds + rsi_fd_set *rsi_sel_exception_fds; + + // read fds + rsi_fd_set rsi_sel_read_fds_var; + + // writes fds + rsi_fd_set rsi_sel_write_fds_var; + + //expection fds + rsi_fd_set rsi_sel_exception_fds_var; + + // driver select control block semaphore + rsi_semaphore_handle_t select_sem; + + int32_t select_status; + + uint8_t select_state; + + uint8_t select_id; + + void (*sock_select_callback)(rsi_fd_set *fd_read, rsi_fd_set *fd_write, rsi_fd_set *fd_except, int32_t status); + +} rsi_socket_select_info_t; +// 11ax params + +//TWT STATUS CODES +#define TWT_SESSION_SUCC 0 +#define TWT_UNSOL_SESSION_SUCC 1 +#define TWT_SETUP_AP_REJECTED 4 +#define TWT_SETUP_RSP_OUTOF_TOL 5 +#define TWT_SETUP_RSP_NOT_MATCHED 6 +#define TWT_SETUP_UNSUPPORTED_RSP 10 +#define TWT_TEARDOWN_SUCC 11 +#define TWT_AP_TEARDOWN_SUCC 12 +#define TWT_SETUP_FAIL_MAX_RETRIES_REACHED 15 +#define TWT_INACTIVE_DUETO_ROAMING 16 +#define TWT_INACTIVE_DUETO_DISCONNECT 17 +#define TWT_INACTIVE_NO_AP_SUPPORT 18 + +typedef struct wlan_11ax_config_params_s { + uint8_t guard_interval; + uint8_t nominal_pe; + uint8_t dcm_enable; + uint8_t ldpc_enable; + uint8_t ng_cb_enable; + uint8_t ng_cb_values; + uint8_t uora_enable; + uint8_t trigger_rsp_ind; + uint8_t ipps_valid_value; + uint8_t tx_only_on_ap_trig; + uint8_t twt_support; + uint8_t config_er_su; +} wlan_11ax_config_params_t; +#endif diff --git a/wiseconnect/sapi/include/sl_app_logging.h b/wiseconnect/sapi/include/sl_app_logging.h new file mode 100644 index 00000000..7ceefb3f --- /dev/null +++ b/wiseconnect/sapi/include/sl_app_logging.h @@ -0,0 +1,78 @@ +/******************************************************************************* +* @file sl_logging.h +* @brief +******************************************************************************* +* # License +* Copyright 2021 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#ifndef __SL_APP_LOGGING_H__ +#define __SL_APP_LOGGING_H__ +#ifdef SAPI_LOGGING_ENABLE +//Includes +#include "rsi_common.h" +#include "rsi_driver.h" + +extern rsi_driver_cb_non_rom_t *rsi_driver_cb_non_rom; + +typedef enum { LOG_OFF, LOG_ERROR, LOG_WARNING, LOG_INFO } log_levels_t; +typedef enum { BYTE_LEN, WORD_LEN, VARIABLE_LEN, DWORD_LEN } log_data_len_t; +typedef enum { BLE, BLUETOOTH, COMMON, CRYPTO, DRIVER, FW_UPDATE, NETWORK, WLAN } log_component_t; + +typedef struct log_flags_s { + uint32_t signal_lost : 1; + uint32_t tsf_present : 1; + uint32_t hdid_present : 1; + uint32_t did : 12; +} __attribute__((packed)) log_flags_t; + +typedef struct log_tsf_s { + uint16_t tsf_format : 1; + uint16_t tsf : 15; +} __attribute__((packed)) log_tsf_t; + +typedef struct debug_info_s { + uint32_t did : 12; + uint32_t arg1_len : 2; + uint32_t arg2_len : 2; + uint32_t arg3_len : 2; + uint32_t component : 3; + uint32_t level : 3; + uint32_t reserved : 8; +} debug_info_t; + +extern uint8_t *logging_buffer; +#define LOG_BUFFER_SIZE 128 +// LDID is 5 bits wide +#define MAX_LDID 0x1F +// LTSF is 7 bits wide +#define MAX_LTSF 0x3F +// Maximum number of arguments +#define MAX_NUM_ARGS 3 + +// Function prototypes +uint32_t sl_log_init(uint8_t *buffer); +uint32_t sl_log_deinit(); +void sl_log_no_args(uint32_t diagnostic_info); +void sl_log_1_args(uint32_t diagnostic_info, uint32_t arg1); +void sl_log_2_args(uint32_t diagnostic_info, uint32_t arg1, uint32_t arg2); +void sl_log_3_args(uint32_t diagnostic_info, uint32_t arg1, uint32_t arg2, uint32_t arg3); + +// HAL function to send the logging buffer +int32_t sl_hal_send_log(uint8_t *buffer, uint32_t buffer_length); +#endif + +#endif diff --git a/wiseconnect/sapi/include/sl_fw_logging.h b/wiseconnect/sapi/include/sl_fw_logging.h new file mode 100644 index 00000000..90d9b8d7 --- /dev/null +++ b/wiseconnect/sapi/include/sl_fw_logging.h @@ -0,0 +1,128 @@ +/******************************************************************************* +* @file sl_logging.h +* @brief +******************************************************************************* +* # License +* Copyright 2021 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#ifndef __SL_FW_LOGGING_H__ +#define __SL_FW_LOGGING_H__ +#ifdef FW_LOGGING_ENABLE +#include "rsi_common.h" +extern rsi_driver_cb_non_rom_t *rsi_driver_cb_non_rom; + +// Max firmware log message length +#define MAX_FW_LOG_MSG_LEN \ + ((((FW_LOG_BUFFER_SIZE + 1023) & ~1023) / 2) > 1600) ? 1600 : (((FW_LOG_BUFFER_SIZE + 1023) & ~1023) / 2) + +// Firmware component log level values +typedef enum { FW_LOG_OFF, FW_LOG_ERROR, FW_LOG_WARN, FW_LOG_TRACE, FW_LOG_INFO } fw_log_levels_t; + +// Firmware logging memory pool structure +typedef struct sl_fw_log_pool_s { + //! Firmware log mutex + rsi_mutex_handle_t fw_log_pool_mutex; + //! Pool total node count + uint16_t size; + //! Pool available node count + uint16_t avail; + //! Pool pointer + void **pool; +} sl_fw_log_pool_t; + +// Firmware logging message node structure +typedef struct sl_fw_log_node_s { + //! Message lost flag + uint16_t prev_message_lost; + //! Log message length + uint16_t fw_log_message_length; + //! Log message + uint8_t fw_log_message[MAX_FW_LOG_MSG_LEN]; + //! Pointer to next log node + struct sl_fw_log_node_t *next; +} sl_fw_log_node_t; + +//Firmware logging queue structure +typedef struct sl_fw_log_queue_s { + //! Head of queue + sl_fw_log_node_t *head; + //! Tail of queue + sl_fw_log_node_t *tail; + //! Nodes pending in the queue + volatile uint16_t pending_node_count; + //! Mutex for firmware logging + rsi_mutex_handle_t fw_log_mutex; +} sl_fw_log_queue_t; + +//Firmware logging control block structure +typedef struct sl_fw_log_cb_s { + //! Firmware log queue + sl_fw_log_queue_t fw_log_queue; + //! Firmware log pool + sl_fw_log_pool_t fw_log_node_pool; +} sl_fw_log_cb_t; + +// Firmware component log level structure +typedef struct sl_fw_log_level_s { + uint8_t common_log_level; + uint8_t cm_pm_log_level; + uint8_t wlan_lmac_log_level; + uint8_t wlan_umac_log_level; + uint8_t wlan_netstack_log_level; + uint8_t bt_ble_ctrl_log_level; + uint8_t bt_ble_stack_log_level; + uint8_t reserved; +} sl_fw_log_level_t; + +// Firmware logging configuration frame structure +typedef struct sl_fw_logging_s { + uint8_t logging_enable; + uint8_t tsf_granularity; + uint16_t reserved_1; + sl_fw_log_level_t component_log_level; // log levels for the 7 firmware components and 1 byte reserved + uint32_t reserved_2; + uint32_t log_buffer_size; +} sl_fw_logging_t; + +// Function prototypes to set firmware logging configuration +// Firmware logging configuration functions +void sl_set_fw_component_log_levels(sl_fw_log_level_t *component_log_level); +int32_t sl_fw_log_configure(uint8_t logging_enable, + uint8_t tsf_granularity, + sl_fw_log_level_t *component_log_level, + uint32_t log_buffer_size, + void (*sl_fw_log_callback)(uint8_t *log_message, uint16_t log_message_length)); + +// Firmware log init/deinit functions +uint32_t sl_fw_log_init(uint8_t *buffer); +void sl_fw_log_deinit(void); + +// Firmware log queue functions +void sl_fw_queue_init(sl_fw_log_queue_t *queue); +void sl_fw_log_enqueue(sl_fw_log_queue_t *fw_log_queue, sl_fw_log_node_t *fw_log_node); +sl_fw_log_node_t *sl_fw_log_dequeue(sl_fw_log_queue_t *fw_log_queue, uint16_t *remaining_node_count); + +// Firmware log pool functions +int32_t sl_fw_log_pool_init(sl_fw_log_pool_t *pool_cb, uint8_t *buffer, uint32_t node_count); +sl_fw_log_node_t *sl_fw_log_node_alloc(sl_fw_log_pool_t *pool_cb); +void sl_fw_log_node_free(sl_fw_log_pool_t *pool_cb, sl_fw_log_node_t *fw_log_node); + +// Firmware log message print function +void sl_fw_log_print(uint8_t *buffer, uint32_t len, uint16_t msg_lost_flag); + +#endif +#endif diff --git a/wiseconnect/sapi/include/sleep_wakeup_logging.h b/wiseconnect/sapi/include/sleep_wakeup_logging.h new file mode 100644 index 00000000..b031409a --- /dev/null +++ b/wiseconnect/sapi/include/sleep_wakeup_logging.h @@ -0,0 +1,17 @@ +#ifndef __SLEEP_WAKEUP_LOGGING_H__ +#define __SLEEP_WAKEUP_LOGGING_H__ +//Includes + +#include "rsi_driver.h" + +/** + * @fn sl_sleepwakeup_log_task + * @param[in] none. + * @return none. + * @section description + * This API is used to log sleep/wakeup statistics based on the + * global variables g_gpio_sleep_log & g_gpio_wakeup_log which are set + * as part of GPIO Interrupt event handler. + */ +void sl_sleepwakeup_log_task(); +#endif \ No newline at end of file diff --git a/wiseconnect/sapi/logging/sl_app_logging.c b/wiseconnect/sapi/logging/sl_app_logging.c new file mode 100644 index 00000000..e048dbad --- /dev/null +++ b/wiseconnect/sapi/logging/sl_app_logging.c @@ -0,0 +1,283 @@ +/******************************************************************************* + * @file sl_app_logging.c + * @brief + ******************************************************************************* + * # License + * Copyright 2021 Silicon Laboratories Inc. http://www.silabs.com/ + ******************************************************************************* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifdef SAPI_LOGGING_ENABLE +/** + * Includes + */ +#include "rsi_driver.h" +#include "sl_app_logging.h" + +uint8_t *logging_buffer; +uint8_t signal_lost; +uint32_t last_msg_sent_tsf; +const char debug_version[] = SL_LOG_VERSION; + +/*==================================================================*/ +/** + * @fn uint8_t *sl_log_init() + * @param[in] uint8_t * buffer, address of the buffer + * @return uint32_t length of the buffer consumed + * @section description + * This API initializes logging feature + */ +uint32_t sl_log_init(uint8_t *buffer) +{ + // Creates logging mutex + rsi_mutex_create(&rsi_driver_cb_non_rom->logging_mutex); + // assign the buffer + logging_buffer = buffer; + + return LOG_BUFFER_SIZE; +} + +/*==================================================================*/ +/** + * @fn uint8_t *sl_log_deinit() + * @param[in] none + * @return 0 = success + * <0 = failure + * @section description + * This API deinitializes logging feature + */ +uint32_t sl_log_deinit() +{ + // Destroys logging mutex + return rsi_mutex_destroy(&rsi_driver_cb_non_rom->logging_mutex); +} + +/*==================================================================*/ +/** + * @fn uint8_t *sl_get_log_buffer() + * @param[in] None + * @return uint8_t *pointer to the buffer + * @section description + * This API provides logging buffer + */ +uint8_t *sl_get_log_buffer() +{ + return logging_buffer; +} + +/*==================================================================*/ +/** + * @fn uint32_t sl_log_data_into_buf(uint8_t *buf, uint32_t arg_len, uint32_t arg) + * @param[in] uint8_t *buf, pointer to the buffer to add data + * @param[in] uint32_t arg_len, length of the data argument + * @param[in] uint32_t arg, data argument + * @return uint32_t len, number of bytes added to the buf + * @section description + * This API is used to populate the log data into buffer + */ +uint32_t sl_log_data_into_buf(uint8_t *buf, uint32_t arg_len, uint32_t arg) +{ + uint32_t len; + + if (arg_len == VARIABLE_LEN) { + // Decoder needs NULL terminator + len = strlen((char *)arg) + 1; + strncpy((char *)buf, (char *)arg, LOG_BUFFER_SIZE); + } else { + len = (arg_len + 1); + if (arg_len == DWORD_LEN) { + *(uint32_t *)buf = (uint32_t)arg; + } else if (arg_len == WORD_LEN) { + *(uint16_t *)buf = (uint16_t)arg; + } else { + *(uint8_t *)buf = (uint8_t)arg; + } + } + return len; +} + +/*==================================================================*/ +/** + * @fn uint32_t sl_log_debug_header(uint8_t *buf, uint32_t debug_info) + * @param[in] uint8_t *buf, pointer to the buffer to add data + * @param[in] debug_info_t *debug_info, debug information passed by reference + * @param[in] uint32_t arg, data argument + * @return uint32_t len, number of bytes added to the buf + * @section description + * This API is populates the debug logging header info into the buffer + */ +uint32_t sl_log_debug_header(uint8_t *buf, debug_info_t *debug_info) +{ + log_flags_t *msg_header = NULL; + log_tsf_t *msg_tsf = NULL; + uint32_t current_tsf; + uint32_t tsf_diff; + + msg_header = (log_flags_t *)buf; + + // signal_lost will be 1, if the previous logging attempt had failed + msg_header->signal_lost = signal_lost; + // reset signal_lost as buffer is now available + signal_lost = 0; + + // check if HDID is required + if (debug_info->did > MAX_LDID) { + msg_header->hdid_present = 1; + buf += sizeof(log_flags_t); + } else { + msg_header->hdid_present = 0; + // HDID is not required, tsf can start a byte earlier + buf += sizeof(log_flags_t) - 1; + } + msg_header->did = debug_info->did; + + // check for TSF + current_tsf = rsi_hal_gettickcount(); + tsf_diff = current_tsf - last_msg_sent_tsf; + + // add a new TSF only if the tsf_diff is equal/more than granularity configured + if (tsf_diff < LOG_TSF_GRANULARITY_TICKS) { + msg_header->tsf_present = 0; + } else { + msg_header->tsf_present = 1; + msg_tsf = (log_tsf_t *)buf; + if ((tsf_diff > MAX_LTSF) || (last_msg_sent_tsf == 0)) { + msg_tsf->tsf_format = 1; + msg_tsf->tsf = current_tsf; + buf += sizeof(log_tsf_t); + } else { + msg_tsf->tsf_format = 0; + msg_tsf->tsf = tsf_diff; + buf += sizeof(log_tsf_t) - 1; + } + last_msg_sent_tsf = current_tsf; + } + + return ((uint32_t)buf - (uint32_t)msg_header); +} + +/*==================================================================*/ +/** + * @fn void sl_log_send_message(uint32_t diagnostic_info, uint8_t num_args, uint32 *args) + * @param[in] uint32_t diagnostic info, debug information passed as value + * @param[in] uint8_t num_args, number of valid arguments sent by caller + * @param[in] uint8_t *args, pointer to array of data + * @param[out] None + * @return None + * @section description + * This API is used to log diagnostic information without any arguments + */ +void sl_log_send_message(uint32_t diagnostic_info, uint8_t num_args, uint32_t *args) +{ + uint8_t *buf = NULL; + uint8_t *buf_start = NULL; + uint8_t arg_len[MAX_NUM_ARGS]; + debug_info_t *debug_info = (debug_info_t *)&diagnostic_info; + + // log msg_headers with debug level within user configured level + if (debug_info->level <= CONFIG_DEBUG_LEVEL) { + rsi_mutex_lock(&rsi_driver_cb_non_rom->logging_mutex); + + buf_start = buf = sl_get_log_buffer(); + if (buf == NULL) { + signal_lost = 1; + rsi_mutex_unlock(&rsi_driver_cb_non_rom->logging_mutex); + return; + } + arg_len[0] = debug_info->arg1_len; + arg_len[1] = debug_info->arg2_len; + arg_len[2] = debug_info->arg3_len; + + buf += sl_log_debug_header(buf, debug_info); + + for (uint32_t i = 0; (i < num_args) && (i < MAX_NUM_ARGS); i++) { + buf += sl_log_data_into_buf(buf, arg_len[i], args[i]); + } + + sl_hal_send_log(buf_start, (uint32_t)buf - (uint32_t)buf_start); + rsi_mutex_unlock(&rsi_driver_cb_non_rom->logging_mutex); + } +} +/*==================================================================*/ +/** + * @fn void sl_log_no_args(uint32_t debug_info) + * @param[in] uint32_t debug_info, debug information passed as value + * @param[out] None + * @return None + * @section description + * This API is used to log diagnostic information without any arguments + */ +void sl_log_no_args(uint32_t diagnostic_info) +{ + sl_log_send_message(diagnostic_info, 0, NULL); +} +/*==================================================================*/ +/** + * @fn void sl_log_1_args(uint32_t debug_info, uint32_t arg1) + * @param[in] uint32_t debug_info, debug information passed as value + * @param[in] uint32_t arg1, argument passed - could be integer or address + * @param[out] None + * @return None + * @section description + * This API is used to log diagnostic information containing 1 argument + */ +void sl_log_1_args(uint32_t diagnostic_info, uint32_t arg1) +{ + sl_log_send_message(diagnostic_info, 1, &arg1); +} +/*==================================================================*/ +/** + * @fn void sl_log_2_args(uint32_t debug_info, uint32_t arg1, uint32_t arg2) + * @param[in] uint32_t debug_info, debug information passed as value + * @param[in] uint32_t arg1, argument passed - could be integer or address + * @param[in] uint32_t arg2, argument passed - could be integer or address + * @param[out] None + * @return None + * @section description + * This API is used to log diagnostic information containing 2 arguments + */ +void sl_log_2_args(uint32_t diagnostic_info, uint32_t arg1, uint32_t arg2) +{ + uint32_t args[2]; + + args[0] = arg1; + args[1] = arg2; + + sl_log_send_message(diagnostic_info, 2, args); +} +/*==================================================================*/ +/** + * @fn void sl_log_3_args(uint32_t debug_info, uint32_t arg1, uint32_t arg2, uint32_t arg3) + * @param[in] uint32_t debug_info, debug information passed as value + * @param[in] uint32_t arg1, argument passed - could be integer or address + * @param[in] uint32_t arg2, argument passed - could be integer or address + * @param[in] uint32_t arg3, argument passed - could be integer or address + * @param[out] None + * @return None + * @section description + * This API is used to log diagnostic information containing 3 arguments + */ +void sl_log_3_args(uint32_t diagnostic_info, uint32_t arg1, uint32_t arg2, uint32_t arg3) +{ + uint32_t args[3]; + + args[0] = arg1; + args[1] = arg2; + args[2] = arg3; + + sl_log_send_message(diagnostic_info, 3, args); +} +#endif diff --git a/wiseconnect/sapi/logging/sl_fw_logging.c b/wiseconnect/sapi/logging/sl_fw_logging.c new file mode 100644 index 00000000..6037e681 --- /dev/null +++ b/wiseconnect/sapi/logging/sl_fw_logging.c @@ -0,0 +1,398 @@ +/******************************************************************************* + * @file sl_fw_logging.c + * @brief + ******************************************************************************* + * # License + * Copyright 2021 Silicon Laboratories Inc. http://www.silabs.com/ + ******************************************************************************* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifdef FW_LOGGING_ENABLE +/** + * Includes + */ +#include "rsi_driver.h" +#include "sl_fw_logging.h" + +/*==================================================================*/ +/** + * @fn sl_fw_log_configure + * @param[in] logging_enable - enable or disable logging + * @param[in] tsf_granularity - configure granularity for TSF in micro seconds + * @param[in] fw_component_log_level - configure logging level for firmware components + * @param[in] log_buffer_size - configure logging buffer size (Multiples of 512 bytes; Min buffer size = 2048 bytes; Max buffer size = 4096 bytes) + * @param[in] sl_fw_log_callback - logging callback + * @param[out] status - logging initialisation success or failure + * @return 0 - Success \n + * Non-zero value - Failure + * @section description + * This API is used to send the configurable parameters for firmware logging framework + */ +int32_t sl_fw_log_configure(uint8_t logging_enable, + uint8_t tsf_granularity, + sl_fw_log_level_t *fw_component_log_level, + uint32_t log_buffer_size, + void (*sl_fw_log_callback)(uint8_t *log_message, uint16_t log_message_length)) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt; + sl_fw_logging_t *fw_logging; + // Get common cb structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + if ((common_cb->state < RSI_COMMON_OPERMODE_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(COMMON_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from common pool + pkt = rsi_pkt_alloc(&common_cb->common_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Callback for logging + common_cb->sl_fw_log_callback = sl_fw_log_callback; + // Take the user provided data and fill it in debug uart print select structure + fw_logging = (sl_fw_logging_t *)pkt->data; + // Logging enable + fw_logging->logging_enable = logging_enable; + + // TSF Granularity + fw_logging->tsf_granularity = tsf_granularity; + + // Log level for each component + fw_logging->component_log_level.common_log_level = fw_component_log_level->common_log_level; + fw_logging->component_log_level.cm_pm_log_level = fw_component_log_level->cm_pm_log_level; + fw_logging->component_log_level.wlan_lmac_log_level = fw_component_log_level->wlan_lmac_log_level; + fw_logging->component_log_level.wlan_umac_log_level = fw_component_log_level->wlan_umac_log_level; + fw_logging->component_log_level.wlan_netstack_log_level = fw_component_log_level->wlan_netstack_log_level; + fw_logging->component_log_level.bt_ble_ctrl_log_level = fw_component_log_level->bt_ble_ctrl_log_level; + fw_logging->component_log_level.bt_ble_stack_log_level = fw_component_log_level->bt_ble_stack_log_level; + + // Log buffer size + fw_logging->log_buffer_size = log_buffer_size; + +#ifndef RSI_COMMON_SEM_BITMAP + rsi_driver_cb_non_rom->common_wait_bitmap |= BIT(0); +#endif + // Send firmware version query request + status = rsi_driver_common_send_cmd(RSI_COMMON_REQ_DEVICE_LOGGING_INIT, pkt); + + // Wait on common semaphore + rsi_wait_on_common_semaphore(&rsi_driver_cb_non_rom->common_cmd_sem, RSI_DEVICE_LOG_RESPONSE_WAIT_TIME); + + // Change common state to allow state + rsi_check_and_update_cmd_state(COMMON_CMD, ALLOW); + + } + + else { + // Return common command error + return status; + } + + // Get common command response status + status = rsi_common_get_status(); + + // Return status + return status; +} + +/*==============================================*/ +/** + * @fn sl_set_fw_component_log_levels + * @brief this function sets debug log levels for firmware components + * @param[in] component_log_level - log levels for firmware components + * @return none. + */ +void sl_set_fw_component_log_levels(sl_fw_log_level_t *component_log_level) +{ + component_log_level->common_log_level = COMMON_LOG_LEVEL; + component_log_level->cm_pm_log_level = CM_PM_LOG_LEVEL; + component_log_level->wlan_lmac_log_level = WLAN_LMAC_LOG_LEVEL; + component_log_level->wlan_umac_log_level = WLAN_UMAC_LOG_LEVEL; + component_log_level->wlan_netstack_log_level = WLAN_NETSTACK_LOG_LEVEL; + component_log_level->bt_ble_ctrl_log_level = BT_BLE_CTRL_LOG_LEVEL; + component_log_level->bt_ble_stack_log_level = BT_BLE_STACK_LOG_LEVEL; +} + +/*==============================================*/ +/** + * @fn sl_fw_log_init + * @brief this function initializes the firmware logging feature + * @param[in] buffer - address of buffer + * @param[out] size - allocated size + */ +uint32_t sl_fw_log_init(uint8_t *buffer) +{ + uint32_t size; + uint8_t *logging_buffer = buffer; + //! Designate memory for fw_log_cb + rsi_driver_cb->fw_log_cb = (sl_fw_log_cb_t *)logging_buffer; + logging_buffer += sizeof(sl_fw_log_cb_t); + //! Designate memory for log node pool + logging_buffer += sl_fw_log_pool_init(&rsi_driver_cb->fw_log_cb->fw_log_node_pool, logging_buffer, FW_LOG_QUEUE_SIZE); + sl_fw_queue_init(&rsi_driver_cb->fw_log_cb->fw_log_queue); + size = logging_buffer - buffer; + return size; +} + +/*==============================================*/ +/** + * @fn sl_fw_queue_init + * @brief this function initializes creates a queue for firmware log messages + * @param[in] queue - logging queue + * @return none + */ +void sl_fw_queue_init(sl_fw_log_queue_t *queue) +{ + //! Initialize firmware logging queue + queue->head = queue->tail = NULL; + queue->pending_node_count = 0; + rsi_mutex_create(&queue->fw_log_mutex); +} + +/*==============================================*/ +/** + * @fn sl_fw_log_deinit + * @brief this function de-initializes the firmware logging feature + * @param[in] none + * @param[out] none + */ +void sl_fw_log_deinit(void) +{ + //! Destroy log pool mutex + rsi_mutex_destroy(&rsi_driver_cb->fw_log_cb->fw_log_node_pool.fw_log_pool_mutex); + //! Destroy log queue mutex + rsi_mutex_destroy(&rsi_driver_cb->fw_log_cb->fw_log_queue.fw_log_mutex); +} + +/*==============================================*/ +/** + * @fn sl_fw_log_enqueue + * @brief this function enqueues a log message node to the firmware log message queue + * @param[in] fw_log_queue - firmware log queue + * @param[in] fw_log_node - log message node from firmware + * @return none. + */ +void sl_fw_log_enqueue(sl_fw_log_queue_t *fw_log_queue, sl_fw_log_node_t *fw_log_node) +{ + if (fw_log_node == NULL) { + return; + } + if (fw_log_queue->pending_node_count == 0) { + // First node in queue + fw_log_queue->head = fw_log_queue->tail = fw_log_node; + } else { + // Every subsequent node in the queue + fw_log_queue->tail->next = (struct sl_fw_log_node_t *)fw_log_node; + fw_log_queue->tail = fw_log_node; + } + fw_log_queue->pending_node_count++; +} + +/*==============================================*/ +/** + * @fn sl_fw_log_dequeue + * @brief this function dequeues a log message node from the firmware log message queue + * @param[in] fw_log_queue - firmware log queue + * @param[in] remaining_node_count - count of remaining log message nodes in the queue after the current message is dequeued + * @param[out] temp_log_node - log node to be deleted + * @return NULL - queue empty \n + * !NULL - node deleted + */ +sl_fw_log_node_t *sl_fw_log_dequeue(sl_fw_log_queue_t *fw_log_queue, uint16_t *remaining_node_count) +{ + sl_fw_log_node_t *temp_log_node; + + if (fw_log_queue->pending_node_count == 0) { + // Empty log queue + *remaining_node_count = fw_log_queue->pending_node_count; + return NULL; + } else { + //! Dequeue log message node + temp_log_node = fw_log_queue->head; + fw_log_queue->head = (sl_fw_log_node_t *)fw_log_queue->head->next; + //! Decrease node count in queue + fw_log_queue->pending_node_count--; + if (fw_log_queue->pending_node_count == 0) { + //! Queue is empty + fw_log_queue->head = NULL; + fw_log_queue->tail = NULL; + } + } + *remaining_node_count = fw_log_queue->pending_node_count; + + return temp_log_node; +} + +/*==============================================*/ +/** + * @fn sl_fw_log_pool_init + * @brief Initialize/create log pool from the provided buffer + * @param[in] pool_cb - log pool pointer which needs to be initialized + * @param[in] buffer - buffer pointer to create pool + * @param[in] node_count - number of nodes to preset. + * @return 0 - Success \n + * Negative value - Failure + */ +int32_t sl_fw_log_pool_init(sl_fw_log_pool_t *pool_cb, uint8_t *buffer, uint32_t node_count) +{ + uint32_t number_of_nodes; + uint32_t pool_size; + uint32_t buffer_index = 0; + uint8_t *logging_buffer = buffer; + uint32_t size; + // Memset pool structure + memset(pool_cb, 0, sizeof(sl_fw_log_pool_t)); + + // Calculate number of packets can be created with given buffer + number_of_nodes = node_count; + + // Save pool pointer + pool_cb->pool = (void *)logging_buffer; + + // Calculate pool array size + pool_size = (number_of_nodes * 4); + + // Increase buffer pointer by pool size + // Buffer contains pool array then actual buffer + logging_buffer += pool_size; + // While total size is available fill pool array + while (number_of_nodes > 0) { + // Fill buffer pointer to current index + pool_cb->pool[buffer_index++] = logging_buffer; + + // Increase available count + pool_cb->avail++; + + // Increase pool size + pool_cb->size++; + + // Move buffer pointer to point next buffer + logging_buffer += sizeof(sl_fw_log_node_t); + + number_of_nodes--; + } + // create mutex for fimrware log pool + rsi_mutex_create(&pool_cb->fw_log_pool_mutex); + + // calculate size to be incremented in buffer + size = logging_buffer - buffer; + return size; +} + +/*==============================================*/ +/** + * @fn sl_fw_log_node_alloc + * @brief this function allocates a log node from given log pool + * @param[in] pool_cb - pointer to firmware log pool + * @param[out] fw_log_node - pointer to firmware log node + * @return NULL - If allocation fails \n + * !NULL - Allocated packet pointer if Success + */ +sl_fw_log_node_t *sl_fw_log_node_alloc(sl_fw_log_pool_t *pool_cb) +{ + sl_fw_log_node_t *fw_log_node = NULL; + + rsi_mutex_lock(&pool_cb->fw_log_pool_mutex); + + if (pool_cb->avail == 0) { + // If available count is zero return NULL + // release mutex lock + rsi_mutex_unlock(&pool_cb->fw_log_pool_mutex); + return NULL; + } + + // If packets are available then return packet pointer from pool + fw_log_node = (sl_fw_log_node_t *)(pool_cb->pool[pool_cb->avail - 1]); + + // Decrease available count + pool_cb->avail--; + + // initialize next with NULL + fw_log_node->next = NULL; + + // release mutex lock + rsi_mutex_unlock(&pool_cb->fw_log_pool_mutex); + + // Return node pointer + return fw_log_node; +} + +/*==============================================*/ +/** + * @fn sl_fw_log_node_free + * @brief Free the log node + * @param[in] pool_cb - log pool to which log node needs to be freed + * @param[in] fw_log_node - log node pointer which needs to be freed + * @return 0 - Success \n + * Negative Value - Failure + */ +void sl_fw_log_node_free(sl_fw_log_pool_t *pool_cb, sl_fw_log_node_t *fw_log_node) +{ + + rsi_mutex_lock(&pool_cb->fw_log_pool_mutex); + + if (pool_cb->avail == pool_cb->size) { + // If available and size are equal then return an error + // Release mutex lock + rsi_mutex_unlock(&pool_cb->fw_log_pool_mutex); + return; + } + + // Increase pool available count + pool_cb->avail++; + + // Fill packet pointer into pool array + pool_cb->pool[pool_cb->avail - 1] = fw_log_node; + + // Release mutex lock + rsi_mutex_unlock(&pool_cb->fw_log_pool_mutex); +} + +/*==============================================*/ +/** + * @fn sl_fw_log_print + * @brief Print the log message from firmware + * @param[in] buffer - log message to be printed + * @param[in] len - length of log message + * @param[in] msg_lost_flag - flag indicating if previous message was lost + * @return none + */ +void sl_fw_log_print(uint8_t *buffer, uint32_t len, uint16_t msg_lost_flag) +{ + rsi_mutex_lock(&rsi_driver_cb_non_rom->debug_prints_mutex); + int i = 0; + + if (msg_lost_flag) { + printf("\r\nPrev Msg Lost"); + } + printf("\r\n&^$ "); + for (i = 0; i < len; i++) { + printf("%02x ", buffer[i]); + } + printf("\r\n"); + rsi_mutex_unlock(&rsi_driver_cb_non_rom->debug_prints_mutex); +} +#endif diff --git a/wiseconnect/sapi/logging/sleep_wakeup_logging.c b/wiseconnect/sapi/logging/sleep_wakeup_logging.c new file mode 100644 index 00000000..26e9b115 --- /dev/null +++ b/wiseconnect/sapi/logging/sleep_wakeup_logging.c @@ -0,0 +1,53 @@ +/******************************************************************************* + * @file sleep_wakeup_logging.c + * @brief + ******************************************************************************* + * # License + * Copyright 2021 Silicon Laboratories Inc. www.silabs.com + ******************************************************************************* + * + * The licensor of this software is Silicon Laboratories Inc. Your use of this + * software is governed by the terms of Silicon Labs Master Software License + * Agreement (MSLA) available at + * www.silabs.com/about-us/legal/master-software-license-agreement. This + * software is distributed to you in Source Code format and is governed by the + * sections of the MSLA applicable to Source Code. + * + ******************************************************************************/ +#ifdef SLEEP_WAKEUP_LOGGING +/** + * Includes + */ +#include "sleep_wakeup_logging.h" + +/* GPIO Interrupt Sleep flag for logging */ +uint32_t g_gpio_sleep_log; +/* GPIO Interrupt Wakeup flag for logging */ +uint32_t g_gpio_wakeup_log; +/* Variables used for Sleep and Wake up aspects */ +uint32_t gpio_rise_timestamp, gpio_fall_timestamp, initial_time; + +/*============================*/ +/** + * @fn sl_sleepwakeup_log_task + * @param[in] none. + * @return none. + * @section description + * This API is used to log sleep/wakeup statistics based on the + * global variables g_gpio_sleep_log & g_gpio_wakeup_log which are set + * as part of GPIO Interrupt event handler. + */ +void sl_sleepwakeup_log_task() +{ + if (g_gpio_sleep_log) { + LOG_PRINT("S %ld\n", (gpio_rise_timestamp - gpio_fall_timestamp)); + g_gpio_sleep_log = RSI_FALSE; + } else if (g_gpio_wakeup_log) { + LOG_PRINT("W %ld\n", (gpio_fall_timestamp - gpio_rise_timestamp)); + g_gpio_wakeup_log = RSI_FALSE; + } else { + /* no logging */ + return; + } +} +#endif \ No newline at end of file diff --git a/wiseconnect/sapi/network/protocols/http_server/rsi_http_server.c b/wiseconnect/sapi/network/protocols/http_server/rsi_http_server.c new file mode 100644 index 00000000..dce88a11 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/http_server/rsi_http_server.c @@ -0,0 +1,734 @@ +/******************************************************************************* +* @file rsi_http_server.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_json_handlers.h" + +/** @addtogroup NETWORK14 +* @{ +*/ +/*==============================================*/ +/** + * @brief Load the webpage to the HTTP Server's file system that is present in the module. + * This is a blocking API. + * @param[in] flags - BIT [2] is used to set the webpage that is associated with JSON object + * @param[in] file_name - Filename of the HTML webpage + * @param[in] webpage - Pointer to the HTML webpage that contains the HTML webpage content + * @param[in] length - Webpage length + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_webpage_load(uint8_t flags, uint8_t *file_name, uint8_t *webpage, uint32_t length) +{ + rsi_webpage_load_t *webpage_load; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint16_t current_len = RSI_MAX_WEBPAGE_SEND_SIZE; + uint16_t offset = 0; + uint32_t file_length = length; + SL_PRINTF(SL_HTTP_WEBPAGE_LOAD_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + while (file_length) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_WEBPAGE_LOAD_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + webpage_load = (rsi_webpage_load_t *)pkt->data; + + // Fill total length of the webpage + rsi_uint16_to_2bytes(webpage_load->total_len, length); + + // Fill filename of the webpage + rsi_strcpy(&webpage_load->filename, file_name); + + if (flags & RSI_WEB_PAGE_JSON_ENABLE) { + // Webpage associated JSON object flag + webpage_load->has_json_data = RSI_WEB_PAGE_HAS_JSON; + } else { + webpage_load->has_json_data = 0; + } + + // Get the current length to send + current_len = ((length - offset) > RSI_MAX_WEBPAGE_SEND_SIZE) ? RSI_MAX_WEBPAGE_SEND_SIZE : (length - offset); + + // Update the current length to send + rsi_uint16_to_2bytes(webpage_load->current_len, current_len); + + // Copy the webpage file contents into the buffer + memcpy((uint8_t *)(webpage_load->webpage), (uint8_t *)(webpage + offset), current_len); + + // Calculate send size + send_size = sizeof(rsi_webpage_load_t) - RSI_MAX_WEBPAGE_SEND_SIZE + current_len; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send webpage load request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WEBPAGE_LOAD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_WP_LOAD_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // If fails, do not send other chunks + if (status != RSI_SUCCESS) { + break; + } + + // Increase webpage content offset + offset += current_len; + + // Decrease webpage remaining size + if (file_length >= current_len) { + file_length -= current_len; + } else { + file_length = 0; + } + } + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_WEBPAGE_LOAD_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_WEBPAGE_LOAD_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK14 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create the JSON object to the webpage that is already present in the module's HTTP server file system. + * This is a blocking API. + * @param[in] flags - Reserved + * @param[in] file_name - Filename of the JSON object data + * @param[in] json_object - Pointer to the JSON object data + * @param[in] length - Length of the JSON object data + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_json_object_create(uint8_t flags, const char *file_name, uint8_t *json_object, uint32_t length) +{ + // Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(flags); + rsi_json_object_load_t *json_object_create; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint16_t current_len = RSI_MAX_WEBPAGE_SEND_SIZE; + uint16_t offset = 0; + uint32_t file_length = 0; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + file_length = length; + + while (file_length) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + json_object_create = (rsi_json_object_load_t *)pkt->data; + + // Fill total length of the JSON object + rsi_uint16_to_2bytes(json_object_create->total_length, length); + + // Fill filename of the JSON object + rsi_strcpy(&json_object_create->filename, file_name); + + // Get the current length to send + current_len = ((length - offset) > RSI_JSON_MAX_CHUNK_LENGTH) ? RSI_JSON_MAX_CHUNK_LENGTH : (length - offset); + + // Update the current length to be sent + rsi_uint16_to_2bytes(json_object_create->current_length, current_len); + + // Copy the json object file contents into the buffer + memcpy((uint8_t *)(json_object_create->json_object), (uint8_t *)(json_object + offset), current_len); + + // Calculate send size + send_size = sizeof(rsi_json_object_load_t) - RSI_JSON_MAX_CHUNK_LENGTH + current_len; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send JSON object create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_JSON_LOAD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_JSON_LOAD_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // If fails, do not send other chunks + if (status != RSI_SUCCESS) { + break; + } + + // Increase JSON object content offset + offset += current_len; + + // Decrease JSON object remaining size + if (file_length >= current_len) { + file_length -= current_len; + } else { + file_length = 0; + } + } + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/** @} */ + +/** @addtogroup NETWORK14 +* @{ +*/ +/*==============================================*/ +/** + * @brief Erase the webpage from HTTP server's file system that is present in the module. + * This is a blocking API. + * @param[in] file_name - Erase particular/all loaded webpage files from the HTTP server's file system. \n + * file_name - Erase a particular webpage file. \n + * NULL - Erase all loaded webpage files + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_webpage_erase(uint8_t *file_name) +{ + + rsi_wbpage_erase_t *web_page_erase; + rsi_webpage_erase_all_t *web_page_erase_all; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t cmd_type = 0x00; + int32_t rsi_response_wait_time = 0; + SL_PRINTF(SL_HTTP_WEBPAGE_ERASE_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_WEBPAGE_ERASE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + web_page_erase = (rsi_wbpage_erase_t *)pkt->data; + web_page_erase_all = (rsi_webpage_erase_all_t *)pkt->data; + + if (file_name) { + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_wbpage_erase_t)); + + // Fill filename of the JSON object + rsi_strcpy(&web_page_erase->filename, file_name); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_wbpage_erase_t); + + // Set command type + cmd_type = RSI_WLAN_REQ_WEBPAGE_ERASE; + + rsi_response_wait_time = RSI_WP_ERASE_RESPONSE_WAIT_TIME; + } else { + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_webpage_erase_all_t)); + + // Clear all webpage files + web_page_erase_all->clear = RSI_WEB_PAGE_CLEAR_ALL_FILES; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_webpage_erase_all_t); + + // Set command type + cmd_type = RSI_WLAN_REQ_WEBPAGE_CLEAR_ALL; + + rsi_response_wait_time = RSI_WP_CLEAR_ALL_RESPONSE_WAIT_TIME; + } + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send webpage erase request command + status = rsi_driver_wlan_send_cmd((rsi_wlan_cmd_request_t)cmd_type, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, rsi_response_wait_time); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_WEBPAGE_ERASE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_WEBPAGE_ERASE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK14 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete the JSON object of the HTTP server's file system that is already present in the module. + * This is a blocking API. + * @param[in] file_name - Delete a particular JSON object that is already created in the HTTP server's file system + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_json_object_delete(uint8_t *file_name) +{ + + rsi_json_object_erase_t *json_object_delete; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_HTTP_JSON_OBJECT_DELETE_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_JSON_OBJECT_DELETE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + json_object_delete = (rsi_json_object_erase_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_json_object_erase_t)); + + // Fill filename of the JSON object + rsi_strcpy(&json_object_delete->filename, file_name); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_json_object_erase_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send JSON object delete request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_JSON_OBJECT_ERASE, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_JSON_ERASE_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_JSON_OBJECT_DELETE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_JSON_OBJECT_DELETE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK14 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send the webpage to HTTP server's file system. This is a blocking API. + * @param[in] flags - Reserved + * @param[in] webpage - Pointer to the HTML webpage that contains the HTML webpage content + * @param[in] length - Webpage length + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wlan_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_webpage_send(uint8_t flags, uint8_t *webpage, uint32_t length) +{ + + // Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(flags); + rsi_webpage_send_t *webpage_send; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + uint16_t current_len = RSI_MAX_WEBPAGE_SEND_SIZE; + uint32_t offset = 0; + uint32_t file_size = length; + SL_PRINTF(SL_HTTP_WEBPAGE_SEND_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // If state is not in card ready received state + if (wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + SL_PRINTF(SL_HTTP_WEBPAGE_SEND_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + while (file_size) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_WEBPAGE_SEND_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + webpage_send = (rsi_webpage_send_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_webpage_send_t)); + + // Fill total host webpage size + rsi_uint32_to_4bytes(webpage_send->total_len, length); + + // Fill more chunks + if ((length - offset) <= RSI_MAX_HOST_WEBPAGE_SEND_SIZE) { + webpage_send->more_chunks = 0; + } else { + webpage_send->more_chunks = 1; + } + + // Get the current length to send + current_len = ((length - offset) > RSI_MAX_HOST_WEBPAGE_SEND_SIZE) ? RSI_MAX_HOST_WEBPAGE_SEND_SIZE + : (length - offset); + + // Fill webpage content + memcpy((uint8_t *)(webpage_send->webpage), (uint8_t *)(webpage + offset), current_len); + + // Calculate length of frame to send + send_size = current_len + (sizeof(rsi_webpage_send_t) - sizeof(webpage_send->webpage)); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send webpage load request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HOST_WEBPAGE_SEND, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_HOST_WP_SEND_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // If fails, do not send other chunks + if (status != RSI_SUCCESS) { + break; + } + + // Increase webpage content offset + offset += current_len; + + // Decrease webpage remaining size + if (file_size >= current_len) { + file_size -= current_len; + } else { + file_size = 0; + } + } + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_WEBPAGE_SEND_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_WEBPAGE_SEND_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup FIRMWARE +* @{ +*/ +/*==============================================*/ +/** + * @brief Request wireless firmware upgrade. This is a blocking API + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffc)\n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note For wireless firmware upgrade, it will take approximately 85 seconds for upgrading the firmware file of 1.5 MB + * @note Need to call rsi_bl_module_power_cycle() API, for the module to reboot after successful firmware upgradation and wait for 50 seconds for the upgraded firmware to be reflected. \n + * @note Refer to Error Codes section for the description of the above error codes \ref error-codes. + */ +///@private +int32_t rsi_req_wireless_fwup(void) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_REQ_WIRELESS_FWUP_ENTER, FW_UPDATE, LOG_INFO); + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_REQ_WIRELESS_FWUP_EERROR_PKT_ALLOCATION_FAILURE, FW_UPDATE, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler == NULL) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + } + // Send wireless firmware upgrade request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WIRELESS_FWUP, pkt); + + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler == NULL) { + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FWUP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + // Return NWK command error + SL_PRINTF(SL_REQ_WIRELESS_FWUP_NWK_COMMAND_ERROR, FW_UPDATE, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_REQ_WIRELESS_FWUP_EXIT, FW_UPDATE, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*============================================================================== */ +/** + * @brief Create HTTP server credentials request. Set username and password for HTTP server. This is a blocking API. + * @param[in] username - User-given username + * @param[in] password - User-given password + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * + **/ + +int32_t rsi_http_credentials(int8_t *username, int8_t *password) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_HTTP_CREDENTIALS_ENTRY, NETWORK, LOG_INFO); + rsi_req_http_credentials_t *http_ptr; + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + if (wlan_cb->state > RSI_WLAN_STATE_BAND_DONE) { + // Command given in wrong state + SL_PRINTF(SL_HTTP_CREDENTIALS_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CREDENTIALS_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + memset(&pkt->data, 0, sizeof(rsi_req_http_credentials_t)); + + http_ptr = (rsi_req_http_credentials_t *)pkt->data; + + rsi_strcpy(http_ptr->username, username); + rsi_strcpy(http_ptr->password, password); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send http_credentials + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CREDENTIALS, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_HTTP_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CREDENTIALS_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CREDENTIALS_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.c b/wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.c new file mode 100644 index 00000000..35b06507 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.c @@ -0,0 +1,481 @@ +/******************************************************************************* +* @file rsi_json_handlers.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_json_handlers.h" + +#include "rsi_utils.h" +#include +#include "stdlib.h" + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Prepare the JSON object data string + * @param[in] json_object_string - Prepared JSON object data string + * @param[in] json_object - JSON object data + * @return JSON object data string + * + * + */ + +/* IMPORTANT: Keys are always enclosed in double quotes. + Use the same keys used in the webpage. + */ + +uint8_t *rsi_json_object_stringify(uint8_t *json_object_string, rsi_json_object_t *json_object) +{ + + sprintf((char *)json_object_string, + "{\"ssid\":\"%s\",\"opmode\":%d,\"conec\":%d,\"channel\":%d,\"secenable\":%s,\"sectype\":%d,\"psk\":\"%s\"," + "\"ssid1\":\"%s\",\"ch1\":%d,\"sec1\":%d,\"ssid2\":\"%s\",\"ch2\":%d,\"sec2\":%d,\"ssid3\":\"%s\",\"ch3\":%d," + "\"sec3\":%d,\"ssid4\":\"%s\",\"ch4\":%d,\"sec4\":%d,\"ssid5\":\"%s\",\"ch5\":%d,\"sec5\":%d,\"ssid6\":\"%" + "s\",\"ch6\":%d,\"sec6\":%d,\"ssid7\":\"%s\",\"ch7\":%d,\"sec7\":%d,\"ssid8\":\"%s\",\"ch8\":%d,\"sec8\":%d," + "\"ssid9\":\"%s\",\"ch9\":%d,\"sec9\":%d,\"ssid10\":\"%s\",\"ch10\":%d,\"sec10\":%d,\"ssid11\":\"%s\"," + "\"ch11\":%d,\"sec11\":%d}", + + json_object->ssid, + json_object->opmode, + json_object->conec, + json_object->channel, + (json_object->sec_enable == 1 ? "true" : "false"), + json_object->sec_type, + json_object->psk, + + json_object->json_scan_res_object[0].ssid, + json_object->json_scan_res_object[0].channel, + json_object->json_scan_res_object[0].sec_type, + json_object->json_scan_res_object[1].ssid, + json_object->json_scan_res_object[1].channel, + json_object->json_scan_res_object[1].sec_type, + json_object->json_scan_res_object[2].ssid, + json_object->json_scan_res_object[2].channel, + json_object->json_scan_res_object[2].sec_type, + json_object->json_scan_res_object[3].ssid, + json_object->json_scan_res_object[3].channel, + json_object->json_scan_res_object[3].sec_type, + json_object->json_scan_res_object[4].ssid, + json_object->json_scan_res_object[4].channel, + json_object->json_scan_res_object[4].sec_type, + json_object->json_scan_res_object[5].ssid, + json_object->json_scan_res_object[5].channel, + json_object->json_scan_res_object[5].sec_type, + json_object->json_scan_res_object[6].ssid, + json_object->json_scan_res_object[6].channel, + json_object->json_scan_res_object[6].sec_type, + json_object->json_scan_res_object[7].ssid, + json_object->json_scan_res_object[7].channel, + json_object->json_scan_res_object[7].sec_type, + json_object->json_scan_res_object[8].ssid, + json_object->json_scan_res_object[8].channel, + json_object->json_scan_res_object[8].sec_type, + json_object->json_scan_res_object[9].ssid, + json_object->json_scan_res_object[9].channel, + json_object->json_scan_res_object[9].sec_type, + json_object->json_scan_res_object[10].ssid, + json_object->json_scan_res_object[10].channel, + json_object->json_scan_res_object[10].sec_type); + + return json_object_string; +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Initialize the JSON object structure with default values + * @param[in] json_object - JSON object data + * @return Void + * + */ + +void rsi_json_object_scan_list_update(rsi_json_object_t *json_object, rsi_rsp_scan_t *scan_rsp) +{ + uint8_t i = 0; + uint8_t scan_count = rsi_bytes4R_to_uint32((uint8_t *)scan_rsp->scan_count); + + for (i = 0; i < scan_count; i++) { + rsi_strcpy(json_object->json_scan_res_object[i].ssid, scan_rsp->scan_info[i].ssid); + json_object->json_scan_res_object[i].channel = scan_rsp->scan_info[i].rf_channel; + json_object->json_scan_res_object[i].sec_type = scan_rsp->scan_info[i].security_mode; + } +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Initialize the JSON object structure with default values + * @param[in] json_object - JSON object data + * @return Void + * + */ + +void rsi_json_object_init(rsi_json_object_t *json_object) +{ + memset(json_object, 0, sizeof(rsi_json_object_t)); + rsi_strcpy(json_object->ssid, ""); + json_object->channel = 0; + json_object->opmode = 0; + json_object->conec = 0; + json_object->sec_enable = 0; + json_object->sec_type = 0; + rsi_strcpy(json_object->psk, ""); +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Update the sensor data structure with the updates received from the browser. + * @param[in] json_object - JSON object data + * @param[in] uint8 - JSON string + * @param[in] uint8 - JSON object filename + * @return 0 - send_update Success + * 1 - Failure + */ + +uint8_t rsi_json_object_update(rsi_json_object_t *json_object, uint8_t *json, uint8_t *json_file_name) +{ + uint8_t filename[24] = ""; + uint8_t send_update = 0; + + /* Extract the filename from the structure */ + json = rsi_json_extract_filename(json, filename); + + /* Check if it is our object */ + if (strcmp((const char *)filename, (const char *)json_file_name) == 0) { + + rsi_json_object_data_update_helper(json_object, json); + + /* If both check boxes are enabled, reset the data structure */ + if (json_object->sec_enable && json_object->checkbox_2) { + rsi_json_object_init(json_object); + send_update = 1; + } + } + + /* This boolean indicates whether or not the host needs to push some updated JSON + data to the module. */ + return send_update; +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Helper function that performs the JSON object update received from the browser. + * @param[in] json_object - JSON object data + * @param[in] json - JSON object data string + * @return Void + */ +void rsi_json_object_data_update_helper(rsi_json_object_t *json_object, uint8_t *json) +{ + /* Extract SSID value and update the struct */ + rsi_json_extract_string(json, (uint8_t *)"ssid", (uint8_t *)&json_object->ssid[0]); + + /* Extract CHANNEL NUMBER value */ + rsi_json_extract_int(json, (uint8_t *)"channel", (uint8_t *)&(json_object->channel)); + + /* Extract SECURITY ENABLE value */ + rsi_json_extract_boolean(json, (uint8_t *)"secenable", (int *)&(json_object->sec_enable)); + + /* Extract SECURITY TYPE value */ + rsi_json_extract_int(json, (uint8_t *)"sectype", &(json_object->sec_type)); + + /* Extract PSK value */ + rsi_json_extract_string(json, (uint8_t *)"psk", (uint8_t *)&json_object->psk[0]); + + /* Extract checkbox_2 value */ + rsi_json_extract_boolean(json, (uint8_t *)"cbox2", (int *)&(json_object->checkbox_2)); + + /* Extract accelerometer int_vals */ + rsi_json_extract_int(json, (uint8_t *)"accy", (uint8_t *)&(json_object->accelerometer_y)); +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Extract the filename from the JSON object string + * @param[in] json - JSON object data string + * @param[in] buffer - Contains filename + * @return Filename + * + * + * + */ + +/* Extract filename out of the received JSON update data. */ +uint8_t *rsi_json_extract_filename(uint8_t *json, uint8_t *buffer) +{ + uint8_t c; + uint8_t i = 0; + + while (i < 24) { + + /* Get character */ + c = json[i]; + + if (c != ',') + buffer[i] = c; + else + break; + + ++i; + } + + buffer[i] = '\0'; + + return &json[i + 1]; +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Extract the string from the JSON object string + * @param[in] json - JSON object data string + * @param[in] key - String key name + * @param[in] string - Extracted JSON string name + * @return Void + * + * + * + */ + +void rsi_json_extract_string(uint8_t *json, uint8_t *key, uint8_t *string) +{ + + uint8_t *key_pos = NULL; + uint16_t key_len = 0; + char buffer[66] = ""; + uint8_t c = 0; + uint8_t i = 0; + + /* Get position of key */ + key_pos = (uint8_t *)strstr((const char *)json, (const char *)key); + + /* If key matches */ + if (key_pos != NULL) { + + key_len = strlen((const char *)key); + key_pos += (key_len + 1); + + /* Extract the value */ + if (*key_pos == ':') { + + key_pos++; + if (*key_pos == '"') { + key_pos++; + c = *key_pos; + + while (c != '"') { + buffer[i] = c; + i++; + key_pos++; + c = *key_pos; + } + + buffer[i] = '\0'; + + rsi_strcpy(string, buffer); + return; + } + } + } + return; +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Extract the int values from the JSON object string + * @param[in] json - JSON object data string + * @param[in] key - Integer value key name + * @param[out] val - Contains extracted int value + * @return Void + * + * + */ + +void rsi_json_extract_int(uint8_t *json, uint8_t *key, uint8_t *val) +{ + uint8_t *key_pos = NULL; + uint16_t key_len = 0; + int target = 0; + char buffer[20] = ""; + uint8_t c = 0; + uint8_t i = 0; + + /* Get position of key */ + key_pos = (uint8_t *)strstr((const char *)json, (const char *)key); + + /* If key matches */ + if (key_pos != NULL) { + + key_len = strlen((const char *)key); + key_pos += (key_len + 1); + + /* Extract the value */ + if (*key_pos == ':') { + + key_pos++; + c = *key_pos; + + while (rsi_is_int(c)) { + buffer[i] = c; + i++; + key_pos++; + c = *key_pos; + } + + buffer[i] = '\0'; + + target = rsi_atoi((const int8_t *)buffer); + *val = target; + } + } +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Extract the float values from the JSON object string + * @param[in] json - JSON object data string + * @param[in] key - Float key name + * @param[out] val - Extracted float value + * @return Void + * + * + */ + +void rsi_json_extract_float(uint8_t *json, uint8_t *key, float *val) +{ + uint8_t *key_pos = NULL; + uint16_t key_len = 0; + float target = 0; + char buffer[20] = ""; + uint8_t c = 0; + uint8_t i = 0; + + /* Get position of key */ + key_pos = (uint8_t *)strstr((const char *)json, (const char *)key); + + /* If key matches */ + if (key_pos != NULL) { + + key_len = strlen((const char *)key); + key_pos += (key_len + 1); + + /* Extract the value */ + if (*key_pos == ':') { + + key_pos++; + c = *key_pos; + + while (rsi_is_float(c)) { + buffer[i] = c; + i++; + key_pos++; + c = *key_pos; + } + + buffer[i] = '\0'; + + target = atof(buffer); + *val = target; + } + } +} + +/*==============================================*/ +/** + * @note This API is not supported in current release + * @brief Extract the boolean from the JSON object string + * @param[in] json - JSON object data string + * @param[in] key - Boolean key name + * @param[out] val - Extracted float value + * @return Void + * + * + */ + +void rsi_json_extract_boolean(uint8_t *json, uint8_t *key, int *val) +{ + uint8_t *key_pos = NULL; + uint16_t key_len = 0; + uint8_t target = 0; + uint8_t c = 0; + uint8_t i = 0; + + /* Get position of key */ + key_pos = (uint8_t *)strstr((const char *)json, (const char *)key); + + /* If key matches */ + if (key_pos != NULL) { + + key_len = strlen((const char *)key); + key_pos += (key_len + 1); + + /* Extract the value */ + if (*key_pos == ':') { + + key_pos++; + c = *key_pos; + + while (c != 't' && c != 'f') { + i++; + key_pos++; + c = *key_pos; + } + + target = (c == 't'); + *val = target; + } + } +} + +/*==============================================*/ +/** + * @brief Check if given input is integer or not + * @param[in] c - Input value + * @return 0 - Success \n + * 1 - Failure + * + */ +int rsi_is_int(uint8_t c) +{ + return (c == '0') || (c == '1') || (c == '2') || (c == '3') || (c == '4') || (c == '5') || (c == '6') || (c == '7') + || (c == '8') || (c == '9') || (c == '-'); +} + +/*==============================================*/ +/** + * @brief Check if given input is float or not + * @param[in] c - Input value + * @return 0 - Success \n + * 1 - Failure + * + * + * + */ + +int rsi_is_float(uint8_t c) +{ + return (c == '0') || (c == '1') || (c == '2') || (c == '3') || (c == '4') || (c == '5') || (c == '6') || (c == '7') + || (c == '8') || (c == '9') || (c == '.') || (c == '-'); +} diff --git a/wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.h b/wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.h new file mode 100644 index 00000000..44d4368e --- /dev/null +++ b/wiseconnect/sapi/network/protocols/http_server/rsi_json_handlers.h @@ -0,0 +1,91 @@ +/******************************************************************************* +* @file rsi_json_handlers.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/** + * Includes + */ +#ifndef RSI_JSON_HANDLERS_H +#define RSI_JSON_HANDLERS_H + +/* Scan response JSON object structure */ +typedef struct rsi_json_object_scan_res_s { + + uint8_t ssid[33]; + uint8_t channel; + uint8_t sec_type; + +} rsi_json_object_scan_res_t; + +/* User Data Structure */ +typedef struct rsi_json_object_s { + uint8_t ssid[33]; + uint8_t channel; + uint8_t opmode; + uint8_t conec; + uint32_t accelerometer_y; + uint8_t psk[65]; + uint32_t sec_enable; + uint32_t checkbox_2; + uint8_t sec_type; + rsi_json_object_scan_res_t json_scan_res_object[11]; +} rsi_json_object_t; + +/** + * Global Variables + */ +extern rsi_json_object_t json_object_data; + +/** + * Function declarations + */ + +/* Convert the structure to JSON string form */ +uint8_t *rsi_json_object_stringify(uint8_t *json_object_string, rsi_json_object_t *json_object); + +/* Initialize the structure with default values + These values can be retrieved from webpage or something similar + */ +void rsi_json_object_init(rsi_json_object_t *json_object); + +/* Update the JSON object data structure with the updates + received from the browser. + */ +uint8_t rsi_json_object_update(rsi_json_object_t *json_object, uint8_t *json, uint8_t *json_file_name); + +/* Helper function declarations */ + +/* Extract filename out of the received JSON update data. */ +uint8_t *rsi_json_extract_filename(uint8_t *json, uint8_t *buffer); + +/* Helper function that actually performs the update */ +void rsi_json_object_data_update_helper(rsi_json_object_t *json_object, uint8_t *json); + +int rsi_is_int(uint8_t c); +int rsi_is_float(uint8_t c); + +void rsi_json_extract_float(uint8_t *json, uint8_t *key, float *val); +void rsi_json_extract_int(uint8_t *json, uint8_t *key, uint8_t *val); +void rsi_json_extract_string(uint8_t *json, uint8_t *key, uint8_t *string); +void rsi_json_extract_boolean(uint8_t *json, uint8_t *key, int *val); +void rsi_json_object_scan_list_update(rsi_json_object_t *json_object, rsi_rsp_scan_t *scan_rsp); + +#endif diff --git a/wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.c b/wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.c new file mode 100644 index 00000000..df1e06cf --- /dev/null +++ b/wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.c @@ -0,0 +1,167 @@ +/******************************************************************************* +* @file rsi_mdnsd_records.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include +#include +#include "rsi_mdnsd_records.h" +#include "string.h" + +/*==============================================*/ +/** + * @brief Create MDNS text record. + * @param[in] txtRecord - Pointer to text record + * @param[in] bufferLen - Length of buffer that is given by the buffer + * @param[in] buffer - Pointer to buffer that will be used for text record + * @return void + */ +/// @private +void rsi_mdns_txt_rec_create(rsi_mdns_txt_rec_t *txtRecord, uint16_t bufferLen, void *buffer) +{ + rsi_mdns_txt_rec_t *txtRec = txtRecord; + + txtRec->buffer = buffer; + txtRec->buflen = buffer ? bufferLen : (uint16_t)0; + txtRec->datalen = 0; + txtRec->malloced = 0; +} + +/*==============================================*/ +/** + * @brief Set value in MDNS text record. + * @param[in] txtRecord - Pointer to text record + * @param[in] key - Pointer to Key + * @param[in] valueSize - Size of value + * @param[in] value - Pointer to value + * @return Zero - Success \n + * Non-Zero Value - Failure + * + */ +/// @private +int8_t rsi_mdns_txt_rec_setvalue(rsi_mdns_txt_rec_t *txtRecord, const char *key, uint8_t valueSize, const void *value) +{ + uint8_t *start, *p; + const char *k; + uint32_t keysize, keyvalsize; + rsi_mdns_txt_rec_t *txtRec = txtRecord; + + for (k = key; *k; k++) + if (*k < 0x20 || *k > 0x7E || *k == '=') + return (RSI_FAILURE); + + keysize = (uint32_t)(k - key); + + keyvalsize = 1 + keysize + (value ? (1 + valueSize) : 0); + + if (keysize < 1 || keyvalsize > 255) + return (RSI_FAILURE); + rsi_mdns_txt_rec_removevalue(txtRecord, key); + + start = txtRec->buffer + txtRec->datalen; + p = start + 1; + memcpy(p, key, keysize); + p += keysize; + + if (value) { + *p++ = '='; + memcpy(p, value, valueSize); + p += valueSize; + } + + *start = (uint8_t)(p - start - 1); + txtRec->datalen += p - start; + + return (0); +} + +/*==============================================*/ +/** + * @brief Search in current MDNS text record. + * @param[in] txtLen - Text length + * @param[in] txtRecord - Pointer to Text Record + * @param[in] key - pointer to Key + * @param[in] keylen - pointer to Key Length + * @return 0 - Success \n + * Negative Value - Failure + */ +/// @private +uint8_t *rsi_mdns_txt_rec_search(uint16_t txtLen, const void *txtRecord, const char *key, uint32_t *keylen) +{ + uint8_t *p = (uint8_t *)txtRecord; + uint8_t *e = p + txtLen; + *keylen = (uint32_t)strlen(key); + + while (p < e) { + uint8_t *x = p; + p += 1 + p[0]; + if (p <= e && *keylen <= x[0] && !strncasecmp(key, (char *)x + 1, *keylen)) + if (*keylen == x[0] || x[1 + *keylen] == '=') + return (x); + } + + return (NULL); +} + +/*==============================================*/ +/** + * @brief Remove a value from MDNS text record. + * @param[in] txtRecord - Pointer to Text Record + * @param[in] key - Pointer to Key + * @return 0 - Success \n + * Negative Value - Failure + */ +/// @private +int8_t rsi_mdns_txt_rec_removevalue(rsi_mdns_txt_rec_t *txtRecord, const char *key) +{ + uint32_t keylen, itemlen, remainder; + rsi_mdns_txt_rec_t *txtRec = txtRecord; + + uint8_t *item = rsi_mdns_txt_rec_search(txtRec->datalen, txtRec->buffer, key, &keylen); + + if (!item) + return (RSI_FAILURE); + + itemlen = (uint32_t)(1 + item[0]); + remainder = (uint32_t)((txtRec->buffer + txtRec->datalen) - (item + itemlen)); + + // Use memmove because memcpy behavior is undefined for overlapping regions + memmove(item, item + itemlen, remainder); + txtRec->datalen -= itemlen; + + return RSI_SUCCESS; +} + +// Function to return MDNS text record buffer pointer +/*==============================================*/ +/** + * @brief Return MDNS text record buffer pointer. + * @param[in] txtRecord - Pointer to text record + * @return Pointer to text record buffer + */ +/// @private +const void *rsi_mdns_get_txt_rec_buffer(rsi_mdns_txt_rec_t *txtRecord) +{ + rsi_mdns_txt_rec_t *txtRec = txtRecord; + + txtRec->buffer[txtRec->buflen] = '\0'; + + return (txtRec->buffer); +} diff --git a/wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.h b/wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.h new file mode 100644 index 00000000..1a1f5195 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.h @@ -0,0 +1,42 @@ +/******************************************************************************* +* @file rsi_mdnsd_records.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/** + * Includes + */ +#ifndef RSI_MDNSD_RECORDS_H +#define RSI_MDNSD_RECORDS_H + +typedef struct rsi_mdns_txt_rec_g { + uint8_t *buffer; // Pointer to data + uint16_t buflen; // Length of buffer + uint16_t datalen; // Length currently in use + uint16_t malloced; // Non-zero if buffer was allocated via malloc() +} rsi_mdns_txt_rec_t; + +void rsi_mdns_txt_rec_create(rsi_mdns_txt_rec_t *txtRecord, uint16_t bufferLen, void *buffer); +int8_t rsi_mdns_txt_rec_setvalue(rsi_mdns_txt_rec_t *txtRecord, const char *key, uint8_t valueSize, const void *value); +uint8_t *rsi_mdns_txt_rec_search(uint16_t txtLen, const void *txtRecord, const char *key, uint32_t *keylen); +int8_t rsi_mdns_txt_rec_removevalue(rsi_mdns_txt_rec_t *txtRecord, const char *key); +const void *rsi_mdns_txt_get_bytes_ptr(rsi_mdns_txt_rec_t *txtRecord); +const void *rsi_mdns_get_txt_rec_buffer(rsi_mdns_txt_rec_t *txtRecord); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.c b/wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.c new file mode 100644 index 00000000..3ffeffd0 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.c @@ -0,0 +1,125 @@ +/******************************************************************************* +* @file rsi_dhcp_user_class.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_dhcp_user_class.h" + +/** @addtogroup NETWORK1 +* @{ +*/ +/*==============================================*/ +/** + * @brief Enable DHCP user class. This is a non-blocking API. + * @param[in] mode - DHCP User Class mode \n + * 1- RFC Compatible mode \n + * 2- Windows Compatible mode + * @param[in] count - DHCP User Class count + * @param[in] user_class_data - The first byte of this buffer is user class data length and then user class data follows + * @param[in] dhcp_usr_cls_rsp_handler - DHCP User Class response handler + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_dhcp_user_class(uint8_t mode, + uint8_t count, + user_class_data_t *user_class_data, + void (*dhcp_usr_cls_rsp_handler)(uint16_t status)) +{ + rsi_dhcp_user_class_t *user_class; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_DHCP_USER_CLASS_ENTRY, NETWORK, LOG_INFO); + uint8_t i = 0; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // If state is not in card ready received state + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_DHCP_USER_CLASS_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + if (dhcp_usr_cls_rsp_handler != NULL) { + // Register DHCP client user class response notify callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dhcp_usr_cls_rsp_handler = dhcp_usr_cls_rsp_handler; + } else { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_DHCP_USER_CLASS_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_DHCP_USER_CLASS_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + user_class = (rsi_dhcp_user_class_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_dhcp_user_class_t)); + + if (count > RSI_DHCP_USER_CLASS_MAX_COUNT) { + count = RSI_DHCP_USER_CLASS_MAX_COUNT; + } + // Fill user class mode + user_class->mode = mode; + + // Fill user class count + user_class->count = count; + + // Fill user class data + for (i = 0; i < count; i++) { + // Check for maximum user class data count + + // Copy user class data + user_class->user_class_data[i].length = user_class_data[i].length; + memcpy(&user_class->user_class_data[i].data[0], user_class_data[i].data, user_class_data[i].length); + } + + // Send DHCP user class command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DHCP_USER_CLASS, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_DHCP_USER_CLASS_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_DHCP_USER_CLASS_EXIT, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.h b/wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.h new file mode 100644 index 00000000..c28873c6 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_dhcp_user_class.h @@ -0,0 +1,52 @@ +/******************************************************************************* +* @file rsi_dhcp_user_class.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_OPTION_77_H +#define RSI_OPTION_77_H + +/****************************************************** + * * Macros + * ******************************************************/ +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_dhcp_user_class(uint8_t mode, + uint8_t count, + user_class_data_t *user_class_data, + void (*dhcp_usr_cls_rsp_handler)(uint16_t status)); + +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_dns.c b/wiseconnect/sapi/network/protocols/rsi_dns.c new file mode 100644 index 00000000..17430914 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_dns.c @@ -0,0 +1,407 @@ +/******************************************************************************* +* @file rsi_dns.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +/** @addtogroup NETWORK6 +* @{ +*/ +/*==============================================*/ +/** + * @brief Query the IP address of a given domain name. This is a blocking API. + * @pre \ref rsi_config_ipaddress() API needs to be called before this API. + * @param[in] ip_version - IP version. 4: IPv4, \n 6: IPv6 + * @param[in] url_name - Pointer to the domain name to resolve IP address + * @param[in] primary_server_address - IP address of the DNS server. This parameter is optional, if module gets the DNS server address using DHCP. If DNS server address is obtained using DHCP, in that case this parameter should be NULL. + * @param[in] secondary_server_address - IP address of the secondary DNS server. In case of no secondary DNS server, IP is NULL. + * @param[out] dns_query_resp - Pointer to hold DNS query results. + * @param[in] length - Length of the resultant buffer. + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note DNS mode is determined by the value of primary_server_address. If NULL, then DNS mode is set to DHCP (1), else it is set to Static IP Address (0). + */ + +int32_t rsi_dns_req(uint8_t ip_version, + uint8_t *url_name, + uint8_t *primary_server_address, + uint8_t *secondary_server_address, + rsi_rsp_dns_query_t *dns_query_resp, + uint16_t length) +{ + rsi_req_dns_server_add_t *dns_srever_add; + rsi_req_dns_query_t *dns_query; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_DNS_REQ_ENTRY, NETWORK, LOG_INFO); + uint8_t dns_mode = 0; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_DNS_REQ_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + // Check for invalid parameters + if (((ip_version != RSI_IP_VERSION_4) && (ip_version != RSI_IP_VERSION_6))) { + // Throw error in case of invalid parameters + SL_PRINTF(SL_DNS_REQ_INVALID_PARAM_1, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Check for invalid parameters + if ((dns_query_resp == NULL) || (length == 0)) { + // Throw error in case of invalid parameters + SL_PRINTF(SL_DNS_REQ_INVALID_PARAM_2, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_DNS_REQ_PKT_ALLOCATION_FAILURE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + dns_srever_add = (rsi_req_dns_server_add_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_dns_server_add_t)); + + // Set IP version + rsi_uint16_to_2bytes(dns_srever_add->ip_version, ip_version); + + // Set DNS mode + dns_mode = (primary_server_address != NULL) ? RSI_STATIC : RSI_DHCP; + + // Set user selected DNS mode + rsi_uint16_to_2bytes(dns_srever_add->dns_mode, dns_mode); + + if (ip_version == RSI_IP_VERSION_4) { + + if (primary_server_address) { + // Fill Primary IP address + memcpy(dns_srever_add->ip_address1.primary_dns_ipv4, primary_server_address, RSI_IPV4_ADDRESS_LENGTH); + } + if (secondary_server_address) { + memcpy(dns_srever_add->ip_address2.secondary_dns_ipv4, secondary_server_address, RSI_IPV4_ADDRESS_LENGTH); + } + } else { + if (primary_server_address) { + // Fill Primary IP address + memcpy(dns_srever_add->ip_address1.primary_dns_ipv6, primary_server_address, RSI_IPV6_ADDRESS_LENGTH); + } + if (secondary_server_address) { + memcpy(dns_srever_add->ip_address2.secondary_dns_ipv6, secondary_server_address, RSI_IPV6_ADDRESS_LENGTH); + } + } + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send DNS server add command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DNS_SERVER_ADD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_DNS_SERVER_ADD_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + if (status != RSI_SUCCESS) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return status + SL_PRINTF(SL_DNS_REQ_EXIT_1, NETWORK, LOG_INFO, "status: %4x", status); + return status; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_DNS_REQ_PKT_ALLOCATION_FAILURE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + dns_query = (rsi_req_dns_query_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_dns_query_t)); + // Attach the buffer given by user + rsi_driver_cb_non_rom->nwk_app_buffer = (uint8_t *)dns_query_resp; + + // Length of the buffer provided by user + rsi_driver_cb_non_rom->nwk_app_buffer_length = length; + // Set IP version + rsi_uint16_to_2bytes(dns_query->ip_version, ip_version); + + // Set URL name + rsi_strcpy(dns_query->url_name, url_name); + + // Set DNS server number + rsi_uint16_to_2bytes(dns_query->dns_server_number, 1); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send DNS query command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DNS_QUERY, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_DNS_QUERY_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_DNS_REQ_EXIT_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_DNS_REQ_EXIT_2, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK6 +* @{ +*/ +/*==============================================*/ +/** + * @brief Update the host name for a given host and zone name. This is non-blocking API. + * @param[in] ip_version - IP version. 4: IPv4, 6: IPv6 + * @param[in] zone_name - Pointer to a zone name and to update host name + * @param[in] host_name - HOST name of the domain + * @param[in] server_address - IP address of the DNS server. This parameter is optional, if module gets DNS server address using DHCP. + * @param[in] ttl - Time to live value of the host name. + * @param[in] dns_update_rsp_handler - Callback function called by driver on reception of DNS update response. + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * + */ + +int32_t rsi_dns_update(uint8_t ip_version, + uint8_t *zone_name, + uint8_t *host_name, + uint8_t *server_address, + uint16_t ttl, + void (*dns_update_rsp_handler)(uint16_t status)) +{ + rsi_req_dns_server_add_t *dns_srever_add; + rsi_req_dns_update_t *dns_update; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_DNS_UPDATE_ENTRY, NETWORK, LOG_INFO); + uint8_t dns_mode = 0; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_DNS_UPDATE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + // Check for invalid parameters + if (((ip_version != RSI_IP_VERSION_4) && (ip_version != RSI_IP_VERSION_6))) { + // Throw error in case of invalid parameters + SL_PRINTF(SL_DNS_UPDATE_INVALID_PARAM_1, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (dns_update_rsp_handler != NULL) { + // Register SMTP client response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_dns_update_rsp_handler = dns_update_rsp_handler; + } else { + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_DNS_UPDATE_INVALID_PARAM_2, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + dns_srever_add = (rsi_req_dns_server_add_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_dns_server_add_t)); + + // Set ip version + rsi_uint16_to_2bytes(dns_srever_add->ip_version, ip_version); + + // Set DNS mode + dns_mode = (server_address != NULL) ? RSI_STATIC : RSI_DHCP; + + // Set user selected DNS mode + rsi_uint16_to_2bytes(dns_srever_add->dns_mode, dns_mode); + + if (ip_version == RSI_IP_VERSION_4) { + + if (server_address) { + // Fill Primary IP address + memcpy(dns_srever_add->ip_address1.primary_dns_ipv4, server_address, RSI_IPV4_ADDRESS_LENGTH); + } + } else { + if (server_address) { + // Fill Primary IP address + memcpy(dns_srever_add->ip_address1.primary_dns_ipv6, server_address, RSI_IPV6_ADDRESS_LENGTH); + } + } + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send DNS server add command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DNS_SERVER_ADD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_DNS_SERVER_ADD_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + if (status != RSI_SUCCESS) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return status + SL_PRINTF(SL_DNS_UPDATE_EXIT_1, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_DNS_UPDATE_PKT_ALLOCATION_FAILURE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + dns_update = (rsi_req_dns_update_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_dns_update_t)); + + // Set ip version + dns_update->ip_version = ip_version; + + // Set ZONE name + rsi_strcpy(dns_update->zone_name, zone_name); + + // Set HOST name + rsi_strcpy(dns_update->host_name, host_name); + + // Fill DNS server number + rsi_uint16_to_2bytes(dns_update->dns_server_number, 1); + + // Fill DNS TTL value + rsi_uint16_to_2bytes(dns_update->ttl, ttl); + + if (dns_update_rsp_handler == NULL) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + } else { + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending |= DNS_RESPONSE_PENDING; + } + // Send DNS update command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DNS_UPDATE, pkt); + + if (dns_update_rsp_handler == NULL) { + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_DNS_UPDATE_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + // Return NWK command error + SL_PRINTF(SL_DNS_UPDATE_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_DNS_UPDATE_EXIT_2, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.c b/wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.c new file mode 100644 index 00000000..261ebfed --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.c @@ -0,0 +1,891 @@ +/******************************************************************************* +* @file rsi_emb_mqtt_client.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_emb_mqtt_client.h" + +#define RSI_LENGTH_ADJ 2 +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create MQTT objects. TCP level connection happens in this API. This is a blocking API. + * @pre \ref rsi_config_ipaddress() API needs to be called before this API. + * @param[in] server_ip - MQTT broker IP address to connect \n + * @param[in] server_port - Port number of MQTT broker \n + * @param[in] client_port - Port number of MQTT client (local port) \n + * @param[in] flags - Network flags. Each bit in the flag has its own significance + * + * Flags | Description + * :-------------------------------|:---------------------------------------------------------------------- + * BIT(0) - Clean Session | 1 - Enable clean session for clearing the historic data \n + * ^ | 0 - Disable clean session + * BIT(1) - SSL flag | 1 - SSL Enable \n + * ^ | 0 - SSL Disable + * BIT(2) - Server IP version | 1 - IPV6 \n + * ^ | 0 - IPV4 + + * @param[in] keep_alive_interval - MQTT client keep alive interval + * @param[in] clientid - Client ID of MQTT client which should be unique for different clients. + * @param[in] username - User name of the MQTT client which is a credential for logging to MQTT server as an authentication + * @param[in] password - Password of the MQTT client which is also credential for MQTT server as an authentication + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_emb_mqtt_client_init(int8_t *server_ip, + uint32_t server_port, + uint32_t client_port, + uint16_t flags, + uint16_t keep_alive_interval, + int8_t *clientid, + int8_t *username, + int8_t *password) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_emb_mqtt_client_init_t *mqtt_ops = NULL; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if ((clientid == NULL) || (server_ip == NULL) || (!client_port) || (!server_port)) { + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // If any of the parameter is valid and exceeds max allowed length, then return error + if ((rsi_strlen(clientid) > (RSI_EMB_MQTT_CLIENTID_MAX_LEN - RSI_LENGTH_ADJ)) + || ((username != NULL) && (rsi_strlen(username) > (RSI_EMB_MQTT_USERNAME_MAX_LEN - RSI_LENGTH_ADJ))) + || ((password != NULL) && (rsi_strlen(password) > (RSI_EMB_MQTT_PASSWORD_MAX_LEN - RSI_LENGTH_ADJ)))) { + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_PARAMTER_LENGTH_EXCEEDS_MAX_VAL, NETWORK, LOG_ERROR); + return RSI_ERROR_PARAMTER_LENGTH_EXCEEDS_MAX_VAL; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_emb_mqtt_client_init_t *)pkt->data; + + // Memset + memset(mqtt_ops, 0, sizeof(rsi_emb_mqtt_client_init_t)); + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_CLIENT_INIT); + + // Copy MQTT Server port + rsi_uint32_to_4bytes(mqtt_ops->server_port, server_port); + + // Copy MQTT Client port + rsi_uint32_to_4bytes(mqtt_ops->client_port, client_port); + + // Copy MQTT Keep Alive period + rsi_uint16_to_2bytes(mqtt_ops->keep_alive_interval, keep_alive_interval); + + if (!(flags & RSI_EMB_MQTT_IPV6_ENABLE)) { + // Fill IP version + rsi_uint32_to_4bytes(mqtt_ops->server_ip.ip_version, RSI_IP_VERSION_4); + // Fill IP address + memcpy(mqtt_ops->server_ip.server_ip_address.ipv4_address, server_ip, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Fill IP version + rsi_uint32_to_4bytes(mqtt_ops->server_ip.ip_version, RSI_IP_VERSION_6); + // Fill IPv6 address + memcpy(mqtt_ops->server_ip.server_ip_address.ipv6_address, server_ip, RSI_IPV6_ADDRESS_LENGTH); + } + + // Copy Client id length + mqtt_ops->clientID_len = rsi_strlen(clientid); + + // Copy Client ID + rsi_strcpy(&mqtt_ops->client_id, clientid); + + // Copy username length + mqtt_ops->username_len = rsi_strlen(username); + + if (username) { + // Copy username if username is not NULL + rsi_strcpy(&mqtt_ops->user_name, username); + } + // Copy password length + mqtt_ops->password_len = rsi_strlen(password); + if (password) { + // Copy password if password is not NULL + rsi_strcpy(&mqtt_ops->password, password); + } + + if (flags & RSI_EMB_MQTT_CLEAN_SESSION) { + mqtt_ops->clean = 1; + } + if (flags & RSI_EMB_MQTT_SSL_ENABLE) { + rsi_wlan_cb_non_rom->emb_mqtt_ssl_enable = 1; + + mqtt_ops->encrypt = 1; + } +#ifdef CHIP_9117 + if (flags & RSI_EMB_MQTT_TCP_MAX_RETRANSMISSION_CAP) { + mqtt_ops->tcp_max_retransmission_cap_for_emb_mqtt = RSI_EMB_MQTT_TCP_MAX_RETRANSMISSION_CAP >> 4; + } +#endif /* CHIP_9117 */ + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_CLIENT_INIT_EXIT, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Connect to MQTT Server/Broker. MQTT level connection happens in this API. This is a blocking API. + * @param[in] mqtt_flags - Network flags. Each bit in the flag has its own significance \n + * + * Flags | Description + * :-------------------------------|:-------------------------------------- + * BIT(6) - pwdFlag | 1 - Enable pwdFlag \n + * ^ | 0 - Disable pwdFlag + * BIT(7) - usrFlag | 1 - Enable usrFlag \n + * ^ | 0 - Disable usrFlag + * + * @param[in] will_topic - Will topic that the MQTT client wants the MQTT Server to publish when disconnected unexpectedly. + * @param[in] will_message_len - Length of will message + * @param[in] will_message - Will message issued by the MQTT Server for a broken client. + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_emb_mqtt_client_init() API needs to be called before this API. + * @note will_topic and will_message are not supported and should be NULL. + * @note For connecting Embedded MQTT over SSL : \n Enable TCP_IP_FEAT_SSL in Opermode parameters as here \n + * #define RSI_TCP_IP_FEATURE_BIT_MAP (TCP_IP_FEAT_DHCPV4_CLIENT | TCP_IP_FEAT_SSL | TCP_IP_FEAT_DNS_CLIENT). \n + * Load the related SSL Certificates in the module using rsi_wlan_set_certificate() API. + * @note Refer to \ref error-codes for the description of above error codes. \n + * + */ + +int32_t rsi_emb_mqtt_connect(uint8_t mqtt_flags, int8_t *will_topic, uint16_t will_message_len, int8_t *will_message) +{ + // Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(will_message_len); + UNUSED_PARAMETER(will_topic); + UNUSED_PARAMETER(will_message); + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_CONNECT_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_emb_mqtt_connect_t *mqtt_ops = NULL; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_CONNECT_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_CONNECT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_emb_mqtt_connect_t *)pkt->data; + + // Memset + memset(mqtt_ops, 0, sizeof(rsi_emb_mqtt_connect_t)); + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_CONNECT); + + if (mqtt_flags & RSI_EMB_MQTT_USER_FLAG) { + mqtt_ops->usrFlag = 1; + } + if (mqtt_flags & RSI_EMB_MQTT_PWD_FLAG) { + mqtt_ops->pwdFlag = 1; + } + // Will messages are not supported + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set MQTT connect command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_CONNECT_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_CONNECT_EXIT, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Publish the given message on the topic specified. This is a blocking API. + * @param[in] topic - Topic string on which MQTT client wants to publish data + * @param[in] publish_msg - Publish message + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_emb_mqtt_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_emb_mqtt_publish(int8_t *topic, rsi_mqtt_pubmsg_t *publish_msg) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_PUBLISH_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_emb_mqtt_snd_pub_t *mqtt_ops = NULL; + + uint16_t max_payload_size; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_PUBLISH_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_PUBLISH_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if ((topic == NULL) || (publish_msg == NULL) || (publish_msg->qos > 2)) { + SL_PRINTF(SL_EMB_MQTT_PUBLISH_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_PUBLISH_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_emb_mqtt_snd_pub_t *)pkt->data; + + // Memset + memset(mqtt_ops, 0, sizeof(rsi_emb_mqtt_snd_pub_t)); + + // Length of TOPIC + mqtt_ops->topic_len = rsi_strlen(topic); + + // Strlen + if (mqtt_ops->topic_len > (RSI_EMB_MQTT_TOPIC_MAX_LEN - RSI_LENGTH_ADJ)) { + SL_PRINTF(SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_1, NETWORK, LOG_ERROR); + return RSI_ERROR_PARAMTER_LENGTH_EXCEEDS_MAX_VAL; + } + + if (rsi_wlan_cb_non_rom->emb_mqtt_ssl_enable) { + max_payload_size = RSI_EMB_MQTT_SSL_PUB_MAX_LEN; + } else { + max_payload_size = RSI_EMB_MQTT_PUB_MAX_LEN; + } + + if (max_payload_size < rsi_cal_mqtt_packet_len((2 + mqtt_ops->topic_len + publish_msg->payloadlen))) { + SL_PRINTF(SL_EMB_MQTT_PUBLISH_PARAMTER_LENGTH_EXCEEDS_MAX_VAL_2, NETWORK, LOG_ERROR); + return RSI_ERROR_PARAMTER_LENGTH_EXCEEDS_MAX_VAL; + } + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_SND_PUB_PKT); + + // Copying TOPIC + rsi_strcpy(&mqtt_ops->topic, topic); + + mqtt_ops->qos = publish_msg->qos; + + mqtt_ops->retained = publish_msg->retained; + + mqtt_ops->dup = publish_msg->dup; + + rsi_uint16_to_2bytes(mqtt_ops->msg_len, publish_msg->payloadlen); + + mqtt_ops->msg = (int8_t *)(pkt->data + sizeof(rsi_emb_mqtt_snd_pub_t)); + if (publish_msg->payloadlen) { + + memcpy(mqtt_ops->msg, publish_msg->payload, publish_msg->payloadlen); + } +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_PUBLISH_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_PUBLISH_COMMAND_SEND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Subscribe to the topic specified. Thus, MQTT client will receive any data that is published on this topic. This is a blocking API. + * @param[in] qos - Quality of service of message at MQTT protocol level. Valid values are 0, 1, 2. + * @param[in] topic - Topic string on which MQTT client wants to subscribe. + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_emb_mqtt_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_emb_mqtt_subscribe(uint8_t qos, int8_t *topic) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_emb_mqtt_sub_t *mqtt_ops = NULL; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if (topic == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + // Strlen + if (rsi_strlen(topic) > (RSI_EMB_MQTT_TOPIC_MAX_LEN - RSI_LENGTH_ADJ)) { + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL, NETWORK, LOG_ERROR); + return RSI_ERROR_PARAMTER_LENGTH_EXCEEDS_MAX_VAL; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_emb_mqtt_sub_t *)pkt->data; + + // Memset + memset(mqtt_ops, 0, sizeof(rsi_emb_mqtt_sub_t)); + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_SUBSCRIBE); + + // Length of topic + mqtt_ops->topic_len = rsi_strlen(topic); + + rsi_strcpy(&mqtt_ops->topic, topic); + + mqtt_ops->qos = qos; + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set subscribe command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_SUBSCRIBE_COMMAND_SEND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Unsubscribe to the topic specified.Thus, MQTT client will not receive any data published on this topic. This is a blocking API. + * @param[in] topic - Topic string to which MQTT client wants to unsubscribe. + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_emb_mqtt_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_emb_mqtt_unsubscribe(int8_t *topic) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_emb_mqtt_unsub_t *mqtt_ops = NULL; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if (topic == NULL) { + return RSI_ERROR_INVALID_PARAM; + } + + // Strlen + if (rsi_strlen(topic) > (RSI_EMB_MQTT_TOPIC_MAX_LEN - RSI_LENGTH_ADJ)) { + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_PARAMTER_LENGTH_EXCEEDS_MAX_VAL, NETWORK, LOG_ERROR); + return RSI_ERROR_PARAMTER_LENGTH_EXCEEDS_MAX_VAL; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_emb_mqtt_unsub_t *)pkt->data; + + // Memset + memset(mqtt_ops, 0, sizeof(rsi_emb_mqtt_unsub_t)); + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_UNSUBSCRIBE); + + // Length of TOPIC + mqtt_ops->topic_len = rsi_strlen(topic); + + // Copy topic + rsi_strcpy(&mqtt_ops->topic, topic); +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send MQTT cmd + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_UNSUBSCRIBE_COMMAND_SEND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Disconnect the client from MQTT Server/Broker. TCP and MQTT level disconnection take place here. This is a blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_emb_mqtt_connect() API needs to be called before this API. + * @note Refer to Error Codes section for the description of the above error codes \ref error-codes. + */ + +int32_t rsi_emb_mqtt_disconnect() +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_DISCONNECT_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_req_emb_mqtt_command_t *mqtt_ops = NULL; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_DISCONNECT_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_DISCONNECT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_req_emb_mqtt_command_t *)pkt->data; + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_DISCONNECT); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_DISCONNECT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_DISCONNECT_COMMAND_SEND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK2 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete MQTT clients profile configuration. TCP level disconnection happens here, if required. This is a blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0) \n + * @note **Precondition** - \ref rsi_emb_mqtt_client_init() API needs to be called before this API, based on requirement.This API can also be issued after \ref rsi_emb_mqtt_disconnect() API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_emb_mqtt_destroy() +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_EMB_MQTT_DESTROY_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_req_emb_mqtt_command_t *mqtt_ops = NULL; + + if ((wlan_cb->opermode != RSI_WLAN_CLIENT_MODE) && (wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE)) { + // Command not supported + SL_PRINTF(SL_EMB_MQTT_DESTROY_COMMAND_NOT_SUPPORTED, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_NOT_SUPPORTED; + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_EMB_MQTT_DESTROY_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_EMB_MQTT_DESTROY_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mqtt_ops = (rsi_req_emb_mqtt_command_t *)pkt->data; + + rsi_uint32_to_4bytes(mqtt_ops->command_type, RSI_EMB_MQTT_COMMAND_DESTROY); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EMB_MQTT_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_EMB_MQTT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_EMB_MQTT_DESTROY_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_EMB_MQTT_DESTROY_COMMAND_SEN_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Register callbacks for MQTT Asynchronous messages. This is a non-blocking API. + * @param[in] callback_id - Callback ID for MQTT responses + * @param[in] call_back_handler_ptr - Callback function pointer + * @param[out] status - Success - RSI_SUCCESS. \n + * Failure - Possible error codes are : 0x0030, 0x0036, 0x0065, 0xBBF1, 0xBBF2, 0xBBF3, 0xFFF6 + * @param[out] buffer - Pointer to buffer which holds data \n + * @param[out] length - Length of the buffer \n + * @return Status of the call_back_handler_ptr + */ + +int32_t rsi_emb_mqtt_register_call_back(uint32_t callback_id, + void (*call_back_handler_ptr)(uint16_t status, + uint8_t *buffer, + const uint32_t length)) +{ + + SL_PRINTF(SL_EMB_MQTT_REGISTER_CALL_BACK_ENTRY, NETWORK, LOG_INFO); + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return, if the callback number exceeds the RSI_MAX_NUM_CALLBACKS, or + * the callback is already registered + */ + SL_PRINTF(SL_EMB_MQTT_REGISTER_CALL_BACK_EXCEEDS_MAX_CALLBACKS, NETWORK, LOG_ERROR); + return RSI_ERROR_EXCEEDS_MAX_CALLBACKS; + } + + if (callback_id == RSI_WLAN_NWK_EMB_MQTT_REMOTE_TERMINATE_CB) { + // Remote terminate of Embedded MQTT socket callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_remote_terminate_handler = call_back_handler_ptr; + } else if (callback_id == RSI_WLAN_NWK_EMB_MQTT_PUB_MSG_CB) { + // MQTT callback for publish message + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_publish_message_callback = call_back_handler_ptr; + } else if (callback_id == RSI_WLAN_NWK_EMB_MQTT_KEEPALIVE_TIMEOUT_CB) { + // MQTT keep alive timeout callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_emb_mqtt_keep_alive_timeout_callback = call_back_handler_ptr; + } else { + SL_PRINTF(SL_EMB_MQTT_REGISTER_CALL_BACK_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + SL_PRINTF(SL_EMB_MQTT_REGISTER_CALL_BACK_EXIT, NETWORK, LOG_ERROR); + return RSI_SUCCESS; +} +/*==============================================*/ +/** + * @brief Calculate length of MQTT packet. This is a non-blocking API. + * @param[in] rem_len - Length + * @return Length of MQTT packet (adjusted rem_len) + */ +/// @private +int32_t rsi_cal_mqtt_packet_len(int32_t rem_len) +{ + SL_PRINTF(SL_CAL_MQTT_PACKET_LEN_ENTRY, NETWORK, LOG_INFO); + rem_len += 1; /* Header byte */ + + /* Now remaining_length field */ + if (rem_len < 128) + rem_len += 1; + else if (rem_len < 16384) + rem_len += 2; + else if (rem_len < 2097151) + rem_len += 3; + else + rem_len += 4; + SL_PRINTF(SL_CAL_MQTT_PACKET_LEN_EXIT, NETWORK, LOG_INFO, "remlen: %4x", rem_len); + return rem_len; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.h b/wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.h new file mode 100644 index 00000000..e203dcbb --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_emb_mqtt_client.h @@ -0,0 +1,71 @@ +/******************************************************************************* +* @file rsi_emb_mqtt_client.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_EMB_MQTT_CLIENT_H +#define RSI_EMB_MQTT_CLIENT_H + +/****************************************************** + * * Macros + * ******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations +` * ******************************************************/ + +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ + +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +int32_t rsi_emb_mqtt_client_init(int8_t *server_ip, + uint32_t server_port, + uint32_t client_port, + uint16_t flags, + uint16_t keep_alive_interval, + int8_t *clientid, + int8_t *username, + int8_t *password); +int32_t rsi_emb_mqtt_connect(uint8_t mqtt_flags, int8_t *will_topic, uint16_t will_message_len, int8_t *will_message); +int32_t rsi_emb_mqtt_publish(int8_t *topic, rsi_mqtt_pubmsg_t *publish_msg); +int32_t rsi_emb_mqtt_subscribe(uint8_t qos, int8_t *topic); +int32_t rsi_emb_mqtt_unsubscribe(int8_t *topic); +int32_t rsi_emb_mqtt_disconnect(void); +int32_t rsi_emb_mqtt_destroy(void); +int32_t rsi_emb_mqtt_register_call_back(uint32_t callback_id, + void (*call_back_handler_ptr)(uint16_t status, + uint8_t *buffer, + const uint32_t length)); +int32_t rsi_cal_mqtt_packet_len(int32_t rem_len); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.c b/wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.c new file mode 100644 index 00000000..42abe2aa --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.c @@ -0,0 +1,162 @@ +/******************************************************************************* +* @file rsi_firmware_upgradation.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_firmware_upgradation.h" + +/** @addtogroup FIRMWARE +* @{ +*/ +/*==============================================*/ +/** + * @brief Helper function for actual APIs + * @param[in] type - Firmware upgrade chunk type + * @param[in] content - Firmware content + * @param[in] length - Length of the content + * @return 0 - Success \n + * @return 3 - Firmware upgrade completed successfully \n + * @return Negative Value - Failure + */ +/// @private +static int32_t rsi_fwup(uint8_t type, uint8_t *content, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FWUP_ENTRY, FW_UPDATE, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_req_fwup_t *fwup = NULL; + + // Check if length exceeds + if (length > RSI_MAX_FWUP_CHUNK_SIZE) { + SL_PRINTF(SL_FWUP_INVALID_PARAM, FW_UPDATE, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FWUP_PKT_ALLOCATION_FAILURE, FW_UPDATE, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + fwup = (rsi_req_fwup_t *)pkt->data; + + // Fill packet type + rsi_uint16_to_2bytes(fwup->type, type); + + // Fill packet length + rsi_uint16_to_2bytes(fwup->length, length); + + // Fill packet content + memcpy(fwup->content, content, length); + + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler == NULL) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + } + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FWUP, pkt); + + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_wireless_fw_upgrade_handler == NULL) { + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FWUP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + // Return NWK command error + SL_PRINTF(SL_FWUP_COMMAND_ERROR, FW_UPDATE, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FWUP_EXIT, FW_UPDATE, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup FIRMWARE +* @{ +*/ +/*==============================================*/ +/** + * @brief Send the RPS header content of firmware file. This is a blocking API. + * @param[in] rps_header - Pointer to the RPS header content + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wlan_radio_init() API needs to be called before this API + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_fwup_start(uint8_t *rps_header) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FWUP_START_ENTRY, FW_UPDATE, LOG_INFO); + + status = rsi_fwup(RSI_FWUP_RPS_HEADER, rps_header, RSI_RPS_HEADER_SIZE); + SL_PRINTF(SL_FWUP_START_EXIT, FW_UPDATE, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup FIRMWARE +* @{ +*/ +/*==============================================*/ +/** + * @brief Send the firmware file content. This is a blocking API. + * @pre \ref rsi_wlan_radio_init() API needs to be called before this API + * @param[in] content - Pointer to the firmware file content + * @param[in] length - Length of the content + * @return 0 - Success \n + * @return 3 - Firmware upgradate is completed successfully \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wlan_radio_init() API needs to be called before this API + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_fwup_load(uint8_t *content, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FWUP_LOAD_ENTRY, FW_UPDATE, LOG_INFO); + + status = rsi_fwup(RSI_FWUP_RPS_CONTENT, content, length); + SL_PRINTF(SL_FWUP_LOAD_EXIT, FW_UPDATE, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.h b/wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.h new file mode 100644 index 00000000..f4262da1 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_firmware_upgradation.h @@ -0,0 +1,60 @@ +/******************************************************************************* +* @file rsi_firmware_upgradation.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_FWUP_H +#define RSI_FWUP_H +/****************************************************** + * * Macros + * ******************************************************/ +// Firmware upgrade packet types +#define RSI_FWUP_RPS_HEADER 1 +#define RSI_FWUP_RPS_CONTENT 0 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_fwup_start(uint8_t *rps_header); +int32_t rsi_fwup_load(uint8_t *content, uint16_t length); +int32_t rsi_ota_firmware_upgradation(uint8_t flags, + uint8_t *server_ip, + uint32_t server_port, + uint16_t chunk_number, + uint16_t timeout, + uint16_t tcp_retry_count, + void (*ota_fw_up_response_handler)(uint16_t status, uint16_t chunk_number)); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_ftp.c b/wiseconnect/sapi/network/protocols/rsi_ftp.c new file mode 100644 index 00000000..96bbd4cf --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_ftp.c @@ -0,0 +1,1399 @@ +/******************************************************************************* +* @file rsi_ftp.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create FTP objects and connect to the FTP server on the given server port. This should be the first command for accessing FTP server. \n + * This is a blocking API. + * @param[in] flags - Network flags. Each bit in the flag has its own significance \n + * + * Flags | Description + * :----------------------|:----------------------------------------------------------------------- + * BIT(0) - RSI_IPV6 | Set this bit to enable IPv6. By default, it is configured to IPv4 + * BIT(1) to BIT(15) | Reserved for future use + * + * @param[in] server_ip - FTP server IP address to connect + * @param[in] username - Username for server authentication + * @param[in] password - Password for server authentication + * @param[in] server_port - Port number of FTP server \n + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note FTP server port is also configurable on a non-standard port + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_ftp_connect(uint16_t flags, int8_t *server_ip, int8_t *username, int8_t *password, uint32_t server_port) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_CONNECT_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *file_ops = NULL; + + rsi_ftp_connect_t *ftp_connect = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_1, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + file_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as FTP Create + file_ops->command_type = RSI_FTP_CREATE; + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + if (status != RSI_SUCCESS) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_1, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_CONNECT_PKT_ALLOCATION_FAILURE_2, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_connect = (rsi_ftp_connect_t *)pkt->data; + + // Memset the packet + memset(pkt, 0, sizeof(rsi_ftp_connect_t)); + + // Set command type as FTP connect + ftp_connect->command_type = RSI_FTP_CONNECT; + + if (!(flags & RSI_IPV6)) { + // Fill IP version + ftp_connect->ip_version = RSI_IP_VERSION_4; + + // Fill IP address + memcpy(ftp_connect->server_ip_address.ipv4_address, server_ip, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Fill IP version + ftp_connect->ip_version = RSI_IP_VERSION_6; + + // Fill IPv6 address + memcpy(ftp_connect->server_ip_address.ipv6_address, server_ip, RSI_IPV6_ADDRESS_LENGTH); + } + if (username) { + // Copy login username + rsi_strcpy(ftp_connect->username, username); + } + + if (password) { + // Copy login password + rsi_strcpy(ftp_connect->password, password); + } + + // Copy FTP Server port + rsi_uint32_to_4bytes(ftp_connect->server_port, server_port); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Connect command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_CONNECT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_CONNECT_ERROR_IN_SENDING_COMMAND_2, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Disconnect from the FTP server and destroy the FTP objects. Once the FTP objects are destroyed, FTP server cannot be accessed. \n + * For further accessing, FTP objects should be created again. This is a blocking API. + * @param void + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_disconnect(void) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_DISCONNECT_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as FTP Create + ftp_ops->command_type = RSI_FTP_DISCONNECT; + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + if (status != RSI_SUCCESS) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_1, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_DISCONNECT_PKT_ALLOCATION_FAILURE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Memset the packet + memset(pkt, 0, sizeof(rsi_ftp_file_ops_t)); + + // Get command type as FTP Create + ftp_ops->command_type = RSI_FTP_DESTROY; + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_DISCONNECT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_DISCONNECT_ERROR_IN_SENDING_COMMAND_2, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Open a file in the specified path on the FTP server. This is a blocking API. + * @param[in] file_name - Filename or filename with the path + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_file_write(int8_t *file_name) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_FILE_WRITE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_WRITE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_FILE_WRITE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as FTP file write + ftp_ops->command_type = RSI_FTP_FILE_WRITE; + + // Copy the filename/path + rsi_strcpy(ftp_ops->file_name, file_name); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send FTP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_FILE_WRITE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_FILE_WRITE_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Write the content into the file that was opened using \ref rsi_ftp_file_write() API. This is a blocking API. + * @param[in] flags - Network flags. \n + * + * Flags | Description + * :----------------------|:----------------------------------------------------------------------- + * BIT(0) - RSI_IPV6 | Set this bit to enable IPv6. By default, it is configured to IPv4 + * BIT(1) to BIT(15) | Reserved for future use + * + * @param[in] file_content - Data stream to be written into the file + * @param[in] content_length - File content length + * @param[in] end_of_file - Flag that indicates the end of file. \n + * 1 – Represent the end of content to be written into the file, \n + * 0 – Extra data that is pending to write into the file \n + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note This API can be called multiple times to append data into the same file. \n + * @note File content length should not exceed 1344 bytes in case of IPV4 and 1324 bytes in case of IPV6. \n + * If exceeded, this API will break the file content and send it in multiple packets. \n + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_file_write_content(uint16_t flags, int8_t *file_content, int16_t content_length, uint8_t end_of_file) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_FILE_WRITE_CONTENT_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_write_t *ftp_file_write = NULL; + + rsi_pkt_t *pkt; + + uint32_t file_offset = 0; + + uint32_t chunk_size = 0; + + uint32_t send_size = 0; + + uint8_t head_room = 0; + + uint8_t *host_desc = NULL; + + if (!(flags & RSI_IPV6)) { + // Headroom for IPv4 + head_room = RSI_TCP_FRAME_HEADER_LEN; + } else { + // Headroom for IPv6 + head_room = RSI_TCP_V6_FRAME_HEADER_LEN; + } + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_WRITE_CONTENT_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + while (content_length) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_FILE_WRITE_CONTENT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_file_write = (rsi_ftp_file_write_t *)pkt->data; + + // Memset the packet + memset(pkt, 0, (sizeof(pkt) + sizeof(rsi_ftp_file_write_t))); + + // Get command type as file delete + ftp_file_write->command_type = RSI_FTP_FILE_WRITE_CONTENT; + + if (content_length > RSI_FTP_MAX_CHUNK_LENGTH) { + chunk_size = RSI_FTP_MAX_CHUNK_LENGTH; +#ifndef RSI_UART_INTERFACE + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_ASYNCHRONOUS; +#endif + + // Copy end of file + ftp_file_write->end_of_file = 0; + + } else { + chunk_size = content_length; + + // Copy end of file + ftp_file_write->end_of_file = end_of_file; + +#ifndef RSI_UART_INTERFACE + if (!end_of_file) { + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_ASYNCHRONOUS; + } +#endif + } + // Copy file content + memcpy((((uint8_t *)ftp_file_write) + head_room), (file_content + file_offset), chunk_size); + + // Add headroom to send size + send_size = chunk_size + head_room; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + if (rsi_driver_cb->wlan_cb->expected_response != RSI_WLAN_RSP_ASYNCHRONOUS) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + } + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + if (rsi_driver_cb->wlan_cb->expected_response != RSI_WLAN_RSP_ASYNCHRONOUS) { + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // If failed, do not send other chunks + if (status != RSI_SUCCESS) { + break; + } + } + // Increase file offset + file_offset += chunk_size; + + // Decrease file remaining size + content_length -= chunk_size; + } + + // Change NWK state to allow + // When end_of_file is 0, we will need to change the state to allow, as there is no response expected from the firmware + // When end_of_file is 1, wait_on_nwk_semaphore is already done, so we can allow other nwk commands. + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_FILE_WRITE_CONTENT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_FILE_WRITE_CONTENT_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Read the content from the specified file on the FTP server. This is a non-blocking API. + * @param[in] file_name - Filename or filename with path + * @param[in] call_back_handler_ptr - Called when asynchronous response is received from module for file read request + * @param[out] status - Status code \n + * @param[out] file_content - File content + * @param[out] content_length - Length of file content + * @param[out] end_of_file - Indicate the end of file. \n + * 1 – No more data, \n + * 0 – More data present + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_file_read_aysnc( + int8_t *file_name, + void (*call_back_handler_ptr)(uint16_t status, uint8_t *file_content, uint16_t content_length, uint8_t end_of_file)) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + if (call_back_handler_ptr != NULL) { + // Register FTP file read response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.ftp_file_read_call_back_handler = call_back_handler_ptr; + } else { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as FTP file Read + ftp_ops->command_type = RSI_FTP_FILE_READ; + + // Copy the filename/path + rsi_strcpy(ftp_ops->file_name, file_name); + + // Send FTP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_FILE_READ_ASYNC_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete the file that is present in the specified path on the FTP server. This is a blocking API. + * @pre \ref rsi_config_ipaddress() API needs to be called before this API. + * @param[in] file_name - Filename or filename with path to delete + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_file_delete(int8_t *file_name) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_FILE_DELETE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_FILE_DELETE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as file delete + ftp_ops->command_type = RSI_FTP_FILE_DELETE; + + // Copy the filename/path to delete + rsi_strcpy(ftp_ops->file_name, file_name); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_FILE_DELETE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_FILE_DELETE_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Rename the file with a new name on the FTP server. This is a blocking API. + * @param[in] old_file_name - Filename or filename with path to rename + * @param[in] new_file_name - New filename + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_file_rename(int8_t *old_file_name, int8_t *new_file_name) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_FILE_RENAME_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_rename_t *file_rename = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_RENAME_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_FILE_RENAME_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + file_rename = (rsi_ftp_file_rename_t *)pkt->data; + + // Get command type as file rename + file_rename->command_type = RSI_FTP_FILE_RENAME; + + // Copy the filename/path of old filename + rsi_strcpy(file_rename->old_file_name, old_file_name); + + // Copy the filename/path of new filename + rsi_strcpy(file_rename->new_file_name, new_file_name); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_FILE_RENAME_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_FILE_RENAME_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create a directory on the FTP server. This is a blocking API. + * @param[in] directory_name - Directory name (with path if required) to create + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_directory_create(int8_t *directory_name) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_DIRECTORY_CREATE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_DIRECTORY_CREATE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as directory create + ftp_ops->command_type = RSI_FTP_DIRECTORY_CREATE; + + // Copy the directory name to create + rsi_strcpy(ftp_ops->file_name, directory_name); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_DIRECTORY_CREATE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_DIRECTORY_CREATE_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete the directory on the FTP server. This is a blocking API. + * @param[in] directory_name - Directory name (with path if required) to delete + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_directory_delete(int8_t *directory_name) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_DIRECTORY_DELETE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_DELETE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_DIRECTORY_DELETE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as directory delete + ftp_ops->command_type = RSI_FTP_DIRECTORY_DELETE; + + // Copy the filename/path to delete + rsi_strcpy(ftp_ops->file_name, directory_name); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // send set FTP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_DIRECTORY_DELETE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_DIRECTORY_DELETE_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Change the current working directory to the specified directory path on the FTP server. This is a blocking API. + * @param[in] directory_path - Directory name (with path if required) to create + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_directory_set(int8_t *directory_path) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_DIRECTORY_SET_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_SET_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_DIRECTORY_SET_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as directory delete + ftp_ops->command_type = RSI_FTP_DIRECTORY_SET; + + // Copy the filename/path to delete + rsi_strcpy(ftp_ops->file_name, directory_path); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_DIRECTORY_SET_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_DIRECTORY_SET_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the list of directories present in the specified directory on the FTP server. This is a non-blocking API. + * @param[in] directory_path - Directory path(with path if required) to list + * @param[in] call_back_handler_ptr - Called when asynchronous response is received from module for directory list request + * @param[out] status - Status code + * @param[out] directory_list - Stream of data with directory list as content + * @param[out] length - Length of content + * @param[out] end_of_list - Indicate end of list. \n + * 1 – No more data, \n + * 0 – More data present + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_ftp_directory_list_async( + int8_t *directory_path, + void (*call_back_handler_ptr)(uint16_t status, uint8_t *directory_list, uint16_t length, uint8_t end_of_list)) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_ops_t *ftp_ops = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + if (call_back_handler_ptr != NULL) { + // Register FTP directory list response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.ftp_directory_list_call_back_handler = call_back_handler_ptr; + } else { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_INVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_ops = (rsi_ftp_file_ops_t *)pkt->data; + + // Get command type as directory list + ftp_ops->command_type = RSI_FTP_DIRECTORY_LIST; + + // copy the directory path to list + rsi_strcpy(ftp_ops->file_name, directory_path); + + // Send set FTP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_DIRECTORY_LIST_ASYNC_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the FTP client mode - either in Passive mode or Active Mode. \n + * In active mode, FTP client establishes the command channel, and the server establishes the data channel. \n + * In passive mode, both the command channel and the data channel are established by the client. \n + * This is a blocking API. + * @param[in] mode - Used to select the mode of FTP client if FTP is enabled. \n + * BIT(0) refers FTP client mode and BIT(1) refers FTP transfer mode. \n + * BIT(0) - 0 then active mode is enabled, \n + * BIT(0) - 1 then passive mode is enabled, \n + * BIT(1) - 0 then stream transfer mode is enabled, \n + * BIT(1) - 1 then block transfer mode is enabled + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_ftp_mode_set(uint8_t mode) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_MODE_SET_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_mode_params_t *ftp_mode = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_MODE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_MODE_SET_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_mode = (rsi_ftp_mode_params_t *)pkt->data; + + ftp_mode->command_type = RSI_FTP_COMMAND_MODE_SET; + ftp_mode->mode_type = mode; + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_MODE_SET_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_MODE_SET_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup NETWORK8 +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the file size + * @param[in] file_size - represents the size of the file in bytes that is to be transferred. \n + * @return 0 - Success \n + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021, 0x002C, 0x0015) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note This API is supported only in 9117 + * @note This API should called before every \ref rsi_ftp_file_write_content() when the Block transfer mode is in use + * @note Refer to \ref error-codes for the description of above error codes. + */ +#ifdef CHIP_9117 +int32_t rsi_ftp_file_size_set(uint32_t file_size) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_FTP_FILE_SIZE_SET_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_ftp_file_size_set_params_t *ftp_size_set = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_FTP_FILE_SIZE_SET_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_FTP_FILE_SIZE_SET_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + ftp_size_set = (rsi_ftp_file_size_set_params_t *)pkt->data; + + ftp_size_set->command_type = RSI_FTP_COMMAND_FILE_SIZE_SET; + + rsi_uint32_to_4bytes(ftp_size_set->file_size, file_size); +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FTP, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_FTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_FTP_FILE_SIZE_SET_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_FTP_FILE_SIZE_SET_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_http_client.c b/wiseconnect/sapi/network/protocols/rsi_http_client.c new file mode 100644 index 00000000..73b21a7b --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_http_client.c @@ -0,0 +1,1064 @@ +/******************************************************************************* +* @file rsi_http_client.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +// Include Driver header file +#include "rsi_driver.h" +#include "rsi_http_client.h" +/* + * Global Variables + * */ +extern rsi_driver_cb_t *rsi_driver_cb; +uint8_t *rsi_itoa(uint32_t val, uint8_t *str); +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send HTTP get request to remote HTTP server. This is a non-blocking API. + * @param[in] flags - Select version and security \n + * + * Flags | Macro | Description + * :------|:----------------|:----------------------------------------------------------------------- + * BIT(0) | RSI_IPV6 | Set this bit to enable IPv6, by default it is configured to IPv4 + * BIT(1) | RSI_SSL_ENABLE | Set this bit to enable SSL featuree + * BIT(2) | RSI_SSL_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled + * BIT(3) | RSI_SSL_V_1_2 | Set this bit to support SSL_TLS Version 1.2 if HTTPS is enabled + * BIT(4) | RSI_SSL_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled + * BIT(5) | HTTP_POST_DATA | Set this bit to enable Http_post large data feature + * BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 + * + * @param[in] ip_address - Server IP address + * @param[in] port - Port number of HTTP server + * @param[in] resource - URL string for requested resource + * @param[in] host_name - Host name + * @param[in] extended_header - User-defined extended header, each member header should end by \r\c \n + * @param[in] username - Username for server authentication + * @param[in] password - Password for server authentication + * @param[in] http_client_get_response_handler - Callback when asynchronous response comes for the request + * @param[out] status - Status of response from module. This will return failure upon an internal error only. + * @param[out] buffer - Buffer pointer + * @param[out] length - Length of data + * @param[out] more_data - 1 No more data, \n 0 More data present + * @param[out] status_code - HTTP response code as returned by server in HTTP header. e.g., 200, 201, 404, etc. \n + * This field is valid only when status field (first argument) is successful, indicating a response is received from HTTP server. \n + * A status_code equal to 0 indicates that there was no HTTP header in the received packet, probably a continuation of the frame \n + * body received in the previous chunk. \n + * This field is available, if the feature RSI_HTTP_STATUS_INDICATION_EN is enabled in rsi_wlan_config.h + * @return 0 - Success \n + * @return Negative value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note HTTP server port is configurable on non-standard port. \n + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_http_client_get_async(uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, +#if RSI_HTTP_STATUS_INDICATION_EN + void (*http_client_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code) +#else + void (*http_client_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata) +#endif +) +{ + return rsi_http_client_async(RSI_HTTP_GET, + flags, + ip_address, + port, + resource, + host_name, + extended_header, + user_name, + password, + NULL, + 0, + http_client_response_handler); +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send HTTP post request to remote HTTP server. This is a non-blocking API. + * @param[in] flags - Select version and security \n + * + * Flags | Macro | Description + * :------|:----------------|:----------------------------------------------------------------------- + * BIT(0) | RSI_IPV6 | Set this bit to enable IPv6, by default, it is configured to IPv4 + * BIT(1) | RSI_SSL_ENABLE | Set this bit to enable SSL feature + * BIT(2) | RSI_SSL_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled + * BIT(3) | RSI_SSL_V_1_2 | Set this bit to support SSL_TLS Version 1.2 if HTTPS is enabled + * BIT(4) | RSI_SSL_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled + * BIT(5) | HTTP_POST_DATA | Set this bit to enable Http_post large data feature + * BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 + * + * @param[in] ip_address - Server IP address + * @param[in] port - Port number of HTTP server + * @param[in] resource - URL string for requested resource + * @param[in] host_name - Host name + * @param[in] extended_header - User-defined extended header, each member header should end by \r\c \n + * @param[in] username - Username for server authentication + * @param[in] password - Password for server authentication + * @param[in] post_data - HTTP data to be posted to server + * @param[in] post_data_length - Post data length + * @param[in] http_client_post_response_handler - Callback when asynchronous response comes for the request + * @param[in] status - Status of response from module. This will return failure upon an internal error only. + * @param[in] buffer - Buffer pointer + * @param[in] length - Length of data + * @param[in] moredata - 1 No more data, 0 More data present, 2 HTTP post success response + * @param[in] status_code HTTP response code as returned by server in HTTP header. e.g., 200, 201, 404, etc. \n + * This field is valid only when status field (first argument) is successful, indicating \n + * a response is received from HTTP server. A status_code equal to 0 indicates that \n + * there was no HTTP header in the received packet, probably a continuation of the frame body received in the previous chunk. \n + * This field is available, if the feature RSI_HTTP_STATUS_INDICATION_EN is enabled in rsi_wlan_config.h \n + * @return 0 - Success \n + * @return Negative value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_http_client_post_async(uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, +#if RSI_HTTP_STATUS_INDICATION_EN + void (*http_client_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code) +#else + void (*http_client_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata) +#endif +) +{ + return rsi_http_client_async(RSI_HTTP_POST, + flags, + ip_address, + port, + resource, + host_name, + extended_header, + user_name, + password, + post_data, + post_data_length, + http_client_response_handler); +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send HTTP get request/HTTP post request to remote HTTP server based on the type selected. This is a non-blocking API. + * @param[in] type - 0 RSI_HTTP_GET, 1 RSI_HTTP_POST + * @param[in] flags - Select version and security \n + * + * Flags | Macro | Description + * :------|:-------------------|:----------------------------------------------------------------------- + * BIT(0) | RSI_IPV6 | Set this bit to enable IPv6, by default, it is configured to IPv4 + * BIT(1) | RSI_SSL_ENABLE | Set this bit to enable SSL feature + * BIT(2) | RSI_SSL_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled + * BIT(3) | RSI_SSL_V_1_2 | Set this bit to support SSL_TLS Version 1.2 if HTTPS is enabled + * BIT(4) | RSI_SSL_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled + * BIT(5) | HTTP_POST_DATA | Set this bit to enable Http_post large data feature + * BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 + * BIT(9) | HTTPS_CERT_INDEX_1 | Set this bit to indicate cert at index 1 to be used for HTTPS + * BIT(10)| HTTPS_CERT_INDEX_2 | Set this bit to indicate cert at index 2 to be used for HTTPS, Leave both unset for cert index 0 + * + * + * @param[in] ip_address - Server IP address + * @param[in] port - Port number of HTTP server + * @param[in] resource - URL string for requested resource. \n + * Note: HTTP server port is also configurable on a non-standard port + * @param[in] host_name - Host name + * @param[in] extended_header - User-defined extended header, each member header should end by \r\c \n + * @param[in] username - Username for server authentication + * @param[in] password - Password for server authentication + * @param[in] post_data - HTTP data to be posted to server + * @param[in] post_data_length - This is the post data length + * @param[in] callback - Callback when asyncronous response comes for the request + * @param[out] status - Status of response from module. This will return failure upon an internal error only. + * @param[out] buffer - Buffer pointer + * @param[out] length - Length of data + * @param[out] moredata - 1 - No more data, 0 - More data present + * @param[in] status_code HTTP response code as returned by server in HTTP header. e.g., 200, 201, 404, etc. \n + * This field is valid only when status field (first argument) is successful, indicating \n + * a response is received from HTTP server. A status_code equal to 0 indicates that \n + * there was no HTTP header in the received packet, probably a continuation of the frame body received in the previous chunk. \n + * This field is available, if the feature RSI_HTTP_STATUS_INDICATION_EN is enabled in rsi_wlan_config.h. + * @return 0 - Success \n + * @return Negative value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_http_client_async(uint8_t type, + uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, +#if RSI_HTTP_STATUS_INDICATION_EN + void (*callback)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code) +#else + void (*callback)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata) +#endif +) +{ + rsi_req_http_client_t *http_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t https_enable = 0; + uint16_t http_length = 0; + uint32_t send_size = 0; + uint8_t *host_desc = NULL; + uint8_t tmp_str[7] = { 0 }; + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Register HTTP client response notify call back handler to NULL + rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode and AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // command given in wrong state + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (callback != NULL) { + // Register HTTP client response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.http_client_response_handler = callback; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_NVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_client = (rsi_req_http_client_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_req_http_client_t)); + + // Fill ipversion + if (flags & RSI_IPV6) { + // Set IPv6 version + rsi_uint16_to_2bytes(http_client->ip_version, RSI_IP_VERSION_6); + } else { + // Set IPv4 version + rsi_uint16_to_2bytes(http_client->ip_version, RSI_IP_VERSION_4); + } + + if (flags & RSI_SSL_ENABLE) { + // Set HTTPS feature + https_enable = 1; + https_enable |= flags & (HTTPS_CERT_INDEX_1 | HTTPS_CERT_INDEX_2); + } + + // Set default by NULL delimiter + https_enable |= BIT(1); + + // SSL versions + + if (flags & RSI_SSL_V_1_0) { + https_enable |= RSI_SSL_V_1_0; + } + if (flags & RSI_SSL_V_1_1) { + https_enable |= RSI_SSL_V_1_1; + } + + if (flags & RSI_SUPPORT_HTTP_POST_DATA) { + // Set HTTP post big data feature bit + https_enable |= RSI_SUPPORT_HTTP_POST_DATA; + } + + if (flags & RSI_SUPPORT_HTTP_V_1_1) { + // Set HTTP version 1.1 feature bit + https_enable |= RSI_SUPPORT_HTTP_V_1_1; + } + + // Fill HTTPS features parameters + rsi_uint16_to_2bytes(http_client->https_enable, https_enable); + + // Fill port number + http_client->port = port; + + // Copy username + rsi_strcpy(http_client->buffer, user_name); + http_length = rsi_strlen(user_name) + 1; + + // Copy password + rsi_strcpy((http_client->buffer) + http_length, password); + http_length += rsi_strlen(password) + 1; + + // Check for HTTP_V_1.1 and Empty host name + if ((flags & RSI_SUPPORT_HTTP_V_1_1) && (rsi_strlen(host_name) == 0)) { + host_name = ip_address; + } + + // Copy host name + rsi_strcpy((http_client->buffer) + http_length, host_name); + http_length += rsi_strlen(host_name) + 1; + + // Copy IP address + rsi_strcpy((http_client->buffer) + http_length, ip_address); + http_length += rsi_strlen(ip_address) + 1; + + // Copy URL resource + rsi_strcpy((http_client->buffer) + http_length, resource); + http_length += rsi_strlen(resource) + 1; + + if (extended_header != NULL) { + + // Copy Extended header + rsi_strcpy((http_client->buffer) + http_length, extended_header); + http_length += rsi_strlen(extended_header); + } + + if (type) { + // Check for HTTP post data feature + if (flags & RSI_SUPPORT_HTTP_POST_DATA) { + post_data = rsi_itoa(post_data_length, tmp_str); + + post_data_length = rsi_strlen(post_data); + } + + // Copy HTTP post data + memcpy((http_client->buffer) + http_length + 1, post_data, post_data_length); + + http_length += (post_data_length + 1); + } + + // Use host descriptor to set payload length + send_size = sizeof(rsi_req_http_client_t) - RSI_HTTP_BUFFER_LEN + http_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint32_to_4bytes(host_desc, (send_size & 0xFFF)); + + if (type) { + // Send HTTP post request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_POST, pkt); + } else { + // Send HTTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_GET, pkt); + } + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CLIENT_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Abort ongoing HTTP request from the client. This is a blocking API + * @param[in] Void + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_http_client_abort(void) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_HTTP_CLIENT_ABORT_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_ABORT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send join command to start WPS + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_ABORT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_HTTP_ABORT_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_ABORT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_HTTP_CLIENT_ABORT_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create the HTTP PUT client. This is a blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_http_client_put_create(void) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_HTTP_CLIENT_PUT_CREATE_ENTRY, NETWORK, LOG_INFO); + rsi_http_client_put_req_t *http_put_req; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Register HTTP client response notify call back handler to NULL + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_put_response_handler = NULL; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_PUT_CREATE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_put_req = (rsi_http_client_put_req_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_http_client_put_req_t)); + + // Fill command type + http_put_req->command_type = HTTP_CLIENT_PUT_CREATE; + + // Use host descriptor to set payload length + send_size = sizeof(rsi_http_client_put_req_t) - HTTP_CLIENT_PUT_MAX_BUFFER_LENGTH; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send HTTP put command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_PUT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_HTTP_CLIENT_PUT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_PUT_CREATE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CLIENT_PUT_CREATE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete the created HTTP PUT client. This is a non-blocking API + * @param[in] Void + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_http_client_put_delete(void) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_HTTP_CLIENT_PUT_DELETE_ENTRY, NETWORK, LOG_INFO); + rsi_http_client_put_req_t *http_put_req; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_PUT_DELETE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_put_req = (rsi_http_client_put_req_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_http_client_put_req_t)); + + // Fill command type + http_put_req->command_type = HTTP_CLIENT_PUT_DELETE; + + // Use host descriptor to set payload length + send_size = sizeof(rsi_http_client_put_req_t) - HTTP_CLIENT_PUT_MAX_BUFFER_LENGTH; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + // Send HTTP put command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_PUT, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_PUT_DELETE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CLIENT_PUT_DELETE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Start the HTTP client PUT process. This is a non-blocking API. + * @param[in] flags - Select version and security \n + * + * Flags | Macro | Description + * :------|:-------------------------------|:----------------------------------------------------------------------- + * BIT(0) | RSI_IPV6 | Set this bit to enable IPv6, by default, it is configured to IPv4 + * BIT(1) | RSI_SSL_ENABLE | Set this bit to enable SSL feature + * BIT(2) | RSI_SSL_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled + * BIT(3) | RSI_SSL_V_1_2 | Set this bit to support SSL_TLS Version 1.2 if HTTPS is enabled + * BIT(4) | RSI_SSL_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled + * BIT(5) | HTTP_POST_DATA | Set this bit to enable Http_post large data feature + * BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 + * BIT(7) | HTTP_USER_DEFINED_CONTENT_TYPE | Set this bit to enable user defined http_content type + * + * @param[in] ip_address - Server IP address + * @param[in] port_number - Port number of HTTP server + * @param[in] resource - URL string for requested resource + * @param[in] host_name - Host name + * @param[in] extended_header - User-defined extended header, each member header should end by \r\c \n + * @param[in] user_name - Username for server authentication + * @param[in] password - Password for server authentication + * @param[in] content_length - Total length of HTTP data + * @param[in] post_data_length - HTTP data length to be posted to server + * @param[in] callback - Callback when asyncronous response comes for the request + * @param[in] status - Status code + * @param[in] type - HTTP Client PUT command type. \n + * 2 - Put start response, \n + * 3 - Put packet response, \n + * 4 - Put delete response, \n + * 5 - Data from HTTP server + * @param[in] buffer - Buffer pointer + * @param[in] length - Length of data + * @param[in] end_of_put_pkt - End of file or HTTP resource content. \n + * 0 - More data is pending from host, \n + * 1 - End of HTTP file/resource content, \n + * 8 - More data pending from server, \n + * 9 - End of HTTP file from server + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API and \ref rsi_http_client_put_create API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_http_client_put_start( + uint16_t flags, + uint8_t *ip_address, + uint32_t port_number, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint32_t content_length, + void (*callback)(uint16_t status, uint8_t type, const uint8_t *buffer, uint16_t length, const uint8_t end_of_put_pkt)) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t https_enable = 0; + uint16_t http_length = 0; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_http_client_put_req_t *http_put_req; + rsi_http_client_put_start_t *http_put_start; + SL_PRINTF(SL_HTTP_CLIENT_PUT_START_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (callback != NULL) { + // Register HTTP client response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_put_response_handler = callback; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_HTTP_CLIENT_PUT_START_INVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_PUT_START_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_put_req = (rsi_http_client_put_req_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_http_client_put_req_t)); + + http_put_start = &http_put_req->http_client_put_struct.http_client_put_start; + + // Fill command type + http_put_req->command_type = HTTP_CLIENT_PUT_START; + + // Fill ipversion + if (flags & RSI_IPV6) { + // Set IPv6 version + http_put_start->ip_version = RSI_IP_VERSION_6; + } else { + // Set IPv4 version + http_put_start->ip_version = RSI_IP_VERSION_4; + } + + if (flags & RSI_SSL_ENABLE) { + // Set HTTPS feature + https_enable = 1; + https_enable |= flags & (HTTPS_CERT_INDEX_1 | HTTPS_CERT_INDEX_2); + + // Set default by NULL delimiter + https_enable |= BIT(1); + } + if (flags & RSI_HTTP_USER_DEFINED_CONTENT_TYPE) { + // Enable user given content type in extended header + https_enable |= RSI_HTTP_USER_DEFINED_CONTENT_TYPE; + } + // Fill HTTPS features parameters + rsi_uint16_to_2bytes(http_put_start->https_enable, https_enable); + // Fill HTTP server port number + rsi_uint32_to_4bytes(http_put_start->port_number, port_number); + + // Fill Total resource content length + rsi_uint32_to_4bytes(http_put_start->content_length, content_length); + + // Copy username + rsi_strcpy(http_put_req->http_put_buffer, user_name); + http_length = rsi_strlen(user_name) + 1; + + // Copy password + rsi_strcpy((http_put_req->http_put_buffer) + http_length, password); + http_length += rsi_strlen(password) + 1; + + // Copy host name + rsi_strcpy((http_put_req->http_put_buffer) + http_length, host_name); + http_length += rsi_strlen(host_name) + 1; + + // Copy IP address + rsi_strcpy((http_put_req->http_put_buffer) + http_length, ip_address); + http_length += rsi_strlen(ip_address) + 1; + + // Copy URL resource + rsi_strcpy((http_put_req->http_put_buffer) + http_length, resource); + http_length += rsi_strlen(resource) + 1; + + if (extended_header != NULL) { + // Copy Extended header + rsi_strcpy((http_put_req->http_put_buffer) + http_length, extended_header); + http_length += rsi_strlen(extended_header); + } + + // Use host descriptor to set payload length + send_size = sizeof(rsi_http_client_put_req_t) - HTTP_CLIENT_PUT_MAX_BUFFER_LENGTH + http_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + // Send HTTP put command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_PUT, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_PUT_START_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CLIENT_PUT_START_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send HTTP data to HTTP server for the created URL resource. This is a blocking API. + * @param[in] file_content - HTTP data content + * @param[in] current_chunk_length - HTTP data current chunk length + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress(), \ref rsi_http_client_put_create() and \ref rsi_http_client_put_start() needs to be called before this API + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_http_client_put_pkt(uint8_t *file_content, uint16_t current_chunk_length) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + rsi_http_client_put_req_t *http_put_req; + rsi_http_client_put_data_req_t *http_put_data; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_HTTP_CLIENT_PUT_PKT_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_PUT_PKT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_put_req = (rsi_http_client_put_req_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_http_client_put_req_t)); + + http_put_data = &http_put_req->http_client_put_struct.http_client_put_data_req; + + // Fill command type + http_put_req->command_type = HTTP_CLIENT_PUT_PKT; + + // Fill HTTP put current_chunk_length + rsi_uint16_to_2bytes(http_put_data->current_length, current_chunk_length); + + // Fill resource content + memcpy((uint8_t *)http_put_req->http_put_buffer, file_content, current_chunk_length); + + // Use host descriptor to set payload length + send_size = sizeof(rsi_http_client_put_req_t) - HTTP_CLIENT_PUT_MAX_BUFFER_LENGTH + current_chunk_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + // Send HTTP put command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_PUT, pkt); + + if (rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_put_response_handler == NULL) { +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_HTTP_CLIENT_PUT_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_PUT_PKT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CLIENT_PUT_PKT_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send the HTTP POST data packet to remote HTTP server. This is a non-blocking API. + * @param[in] file_content - User given http file content + * @param[in] current_chunk_length - Length of the current HTTP data + * @param[in] callback - Callback when asynchronous response comes for the request. + * @param[in] status - Status of response from module. This will return failure upon an internal error only. + * @param[in] buffer - Buffer pointer + * @param[in] length - Length of data + * @param[in] more_data - 4 - More data is pending from host. \n + * 5 - End of HTTP data from host(Host sent total data content length). \n + * 8 – More data is pending from module to host. Further interrupts may be \n + * raised by the module till all the data is transferred to the Host. \n + * 9 – End of HTTP data from module to host. + * @param[in] status_code - HTTP response code as returned by server in HTTP header. e.g., 200, 201, 404, etc. \n + * This field is valid only when status field (first argument) is successful, indicating \n + * a response is received from HTTP server. A status_code equal to 0 indicates that \n + * there was no HTTP header in the received packet, probably a continuation of the frame \n + * body received in the previous chunk. \n + * This field is available, if the feature RSI_HTTP_STATUS_INDICATION_EN is enabled in rsi_wlan_config.h \n + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_http_client_post_data(uint8_t *file_content, + uint16_t current_chunk_length, +#if RSI_HTTP_STATUS_INDICATION_EN + void (*rsi_http_post_data_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code) +#else + void (*rsi_http_post_data_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata) +#endif +) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + rsi_http_client_post_data_req_t *http_post_data; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_HTTP_CLIENT_POST_DATA_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (rsi_http_post_data_response_handler != NULL) { + // Register HTTP client response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_http_client_post_data_response_handler = + rsi_http_post_data_response_handler; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_HTTP_CLIENT_POST_DATA_INVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_CLIENT_POST_DATA_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_post_data = (rsi_http_client_post_data_req_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_http_client_post_data_req_t)); + + // Fill HTTP post data current_chunk_length + rsi_uint16_to_2bytes(http_post_data->current_length, current_chunk_length); + + // Fill resource content + memcpy((uint8_t *)http_post_data->http_post_data_buffer, file_content, current_chunk_length); + + // Use host descriptor to set payload length + send_size = + sizeof(rsi_http_client_post_data_req_t) - HTTP_CLIENT_POST_DATA_MAX_BUFFER_LENGTH + current_chunk_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + // Send HTTP put command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_CLIENT_POST_DATA, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_CLIENT_POST_DATA_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_HTTP_CLIENT_POST_DATA_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_http_client.h b/wiseconnect/sapi/network/protocols/rsi_http_client.h new file mode 100644 index 00000000..9873929e --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_http_client.h @@ -0,0 +1,139 @@ +/******************************************************************************* +* @file rsi_http_client.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_HTTP_CLIENT_H +#define RSI_HTTP_CLIENT_H +#include "rsi_driver.h" +/****************************************************** + * * Macros + * ******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +#if RSI_HTTP_STATUS_INDICATION_EN +int32_t rsi_http_client_get_async(uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + void (*http_client_get_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code)); +int32_t rsi_http_client_post_async(uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, + void (*http_client_post_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code)); + +int32_t rsi_http_client_post_data(uint8_t *file_content, + uint16_t current_chunk_length, + void (*http_client_post_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata, + uint16_t status_code)); +#else +int32_t rsi_http_client_get_async(uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + void (*http_client_get_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata)); +int32_t rsi_http_client_post_async(uint16_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, + void (*http_client_post_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata)); + +int32_t rsi_http_client_post_data(uint8_t *file_content, + uint16_t current_chunk_length, + void (*http_client_post_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length, + const uint32_t moredata)); +#endif +int32_t rsi_http_client_abort(void); + +int32_t rsi_http_client_put_start( + uint16_t flags, + uint8_t *ip_address, + uint32_t port_number, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint32_t content_length, + void (*callback)(uint16_t status, uint8_t type, const uint8_t *buffer, uint16_t length, const uint8_t moredata)); + +int32_t rsi_http_client_put_delete(void); + +int32_t rsi_http_client_put_pkt(uint8_t *file_content, uint16_t current_chunk_length); +int32_t rsi_http_client_put_create(void); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_http_ota_fw_up.c b/wiseconnect/sapi/network/protocols/rsi_http_ota_fw_up.c new file mode 100644 index 00000000..45b37968 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_http_ota_fw_up.c @@ -0,0 +1,286 @@ +/******************************************************************************* +* @file rsi_http_ota_fw_up.c +* @brief This file contains API's to get HTTP data and post HTTP data for requested URL +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +/** @addtogroup FIRMWARE +* @{ +*/ +/*==============================================*/ +/** + * @brief Initiate firmware update from an HTTP server. This is non-blocking API. + * @param[in] flags - Select version and security \n + * + * Flags | Macro | Description + * :------|:----------------|:----------------------------------------------------------------------- + * BIT(0) | RSI_IPV6 | Set this bit to enable IPv6 , by default it is configured to IPv4 + * BIT(1) | RSI_SSL_ENABLE | Set this bit to enable SSL feature + * BIT(2) | RSI_SSL_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled + * BIT(3) | RSI_SSL_V_1_2 | Set this bit to support SSL_TLS Version 1.2 if HTTPS is enabled + * BIT(4) | RSI_SSL_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled + * BIT(5) | HTTP_POST_DATA | Set this bit to enable Http_post large data feature + * BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 + * + * @param[in] ip_address - Server IP address + * @param[in] port - Port number, default : 80 - HTTP, 443 - HTTPS + * @param[in] resource - URL string for requested resource + * @param[in] host_name - Host name + * @param[in] extended_header - Extender header if present + * @param[in] username - Username for server Authentication + * @param[in] password - Password for server Authentication + * @param[in] http_otaf_response_handler - Callback is called when asynchronous response is received from module for HTTP firmware update request \n + * @param[out] status - Status code + * @param[out] buffer - NULL + * @return 0 - Success \n + * @return Non-Zero value - Failure (**Possible Error Codes** - BBED,BB40,BB38,BBD2,FF74,FFF4) \n + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_http_fw_update(uint8_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + void (*http_otaf_response_handler)(uint16_t status, const uint8_t *buffer)) +{ + return rsi_http_otaf_async(RSI_HTTP_OTAF, + flags, + ip_address, + port, + resource, + host_name, + extended_header, + user_name, + password, + NULL, + 0, + http_otaf_response_handler); +} +/** @} */ + +/** @addtogroup NETWORK9 +* @{ +*/ +/*==============================================*/ +/** + * @brief Post the HTTP data for the requested URL to HTTP server. This is a non-blocking API. + * @param[in] type - 0 - HTTPGET \n + * - 1 - HTTPPOST \n + * @param[in] flags - Select version and security:\n + * + * Flags | Macro | Description + * :------|:----------------|:----------------------------------------------------------------------- + * BIT(0) | RSI_IPV6 | Set this bit to enable IPv6 , by default it is configured to IPv4 + * BIT(1) | RSI_SSL_ENABLE | Set this bit to enable SSL feature + * BIT(2) | RSI_SSL_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled + * BIT(3) | RSI_SSL_V_1_2 | Set this bit to support SSL_TLS Version 1.2 if HTTPS is enabled + * BIT(4) | RSI_SSL_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled + * BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 + * + * @param[in] ip_address - Server IP address + * @param[in] port - Port number, default : 80 - HTTP, 443 - HTTPS + * @param[in] resource - URL string for requested resource + * @param[in] host_name - Post name + * @param[in] extended_header - Extender header if present, after each header member append \r\c \n + * @param[in] username - Username for server Authentication + * @param[in] password - Password for server Authentication + * @param[in] post_data - HTTP data to be posted to server + * @param[in] post_data_length - HTTP data length to be posted to server + * @param[in] callback - Callback is called when asynchronous response is received from module for HTTP firmware update request + * @param[out] buffer - NULL + * @param[out] status - This is the status response from module. This returns failure upon an internal error only. + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_http_otaf_async(uint8_t type, + uint8_t flags, + uint8_t *ip_address, + uint16_t port, + uint8_t *resource, + uint8_t *host_name, + uint8_t *extended_header, + uint8_t *user_name, + uint8_t *password, + uint8_t *post_data, + uint32_t post_data_length, + void (*callback)(uint16_t status, const uint8_t *buffer)) +{ + rsi_req_http_client_t *http_client = NULL; + rsi_pkt_t *pkt = NULL; + int32_t status = RSI_SUCCESS; + uint8_t https_enable = 0; + uint16_t http_length = 0; + uint32_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_HTTP_OTAF_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Register HTTP client response, notify callback handler to NULL + rsi_wlan_cb_non_rom->nwk_callbacks.http_otaf_response_handler = NULL; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode and AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_HTTP_OTAF_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if (rsi_check_and_update_cmd_state(NWK_CMD, IN_USE) == RSI_SUCCESS) { + // register callback + if (callback != NULL) { + // Register HTTP client response, notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.http_otaf_response_handler = callback; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_HTTP_OTAF_ASYNC_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_HTTP_OTAF_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + http_client = (rsi_req_http_client_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_req_http_client_t)); + + // Fill IP version + if (flags & RSI_IPV6) { + // Set ipv6 version + rsi_uint16_to_2bytes(http_client->ip_version, RSI_IP_VERSION_6); + } else { + // Set ipv4 version + rsi_uint16_to_2bytes(http_client->ip_version, RSI_IP_VERSION_4); + } + + if (flags & RSI_SSL_ENABLE) { + // Set https feature + https_enable = 1; + } + + // Set default by NULL delimiter + https_enable |= BIT(1); + + //ssl versions + + if (flags & RSI_SSL_V_1_0) { + https_enable |= RSI_SSL_V_1_0; + } + if (flags & RSI_SSL_V_1_1) { + https_enable |= RSI_SSL_V_1_1; + } + + if (flags & RSI_SUPPORT_HTTP_V_1_1) { + // Set HTTP version 1.1 feature bit + https_enable |= RSI_SUPPORT_HTTP_V_1_1; + } + + // Fill https features parameters + rsi_uint16_to_2bytes(http_client->https_enable, https_enable); + + // Fill port no + http_client->port = port; + + // Copy username + rsi_strcpy(http_client->buffer, user_name); + http_length = rsi_strlen(user_name) + 1; + + // Copy password + rsi_strcpy((http_client->buffer) + http_length, password); + http_length += rsi_strlen(password) + 1; + + // Check for HTTP_V_1.1 and Empty host name + if ((flags & RSI_SUPPORT_HTTP_V_1_1) && (rsi_strlen(host_name) == 0)) { + host_name = ip_address; + } + + // Copy Host name + rsi_strcpy((http_client->buffer) + http_length, host_name); + http_length += rsi_strlen(host_name) + 1; + + // Copy IP address + rsi_strcpy((http_client->buffer) + http_length, ip_address); + http_length += rsi_strlen(ip_address) + 1; + + // Copy URL resource + rsi_strcpy((http_client->buffer) + http_length, resource); + http_length += rsi_strlen(resource) + 1; + + if (extended_header != NULL) { + + // Copy Extended header + rsi_strcpy((http_client->buffer) + http_length, extended_header); + http_length += rsi_strlen(extended_header); + } + + if (type) { + // Copy Httppost data + memcpy((http_client->buffer) + http_length + 1, post_data, post_data_length); + + http_length += (post_data_length + 1); + } + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_http_client_t) - RSI_HTTP_BUFFER_LEN + http_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint32_to_4bytes(host_desc, (send_size & 0xFFF)); + + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HTTP_OTAF, pkt); + } else { + // Return NWK command error + SL_PRINTF(SL_HTTP_OTAF_ASYNC_NWK_CMD_IN_PROGRESS, NETWORK, LOG_ERROR); + return RSI_ERROR_NWK_CMD_IN_PROGRESS; + } + + // Return status + SL_PRINTF(SL_HTTP_OTAF_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_http_otaf_app.h b/wiseconnect/sapi/network/protocols/rsi_http_otaf_app.h new file mode 100644 index 00000000..41b1e6aa --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_http_otaf_app.h @@ -0,0 +1,30 @@ +/******************************************************************************* +* @file rsi_http_otaf_app.h +* @brief - HTTP OTAF Specific Header File +*******************************************************************************/ + +#ifndef RSI_HTTP_OTAF_APP +#define RSI_HTTP_OTAF_APP + +/****************************************************** + * * Includes + * ******************************************************/ +#include "rsi_driver.h" + +/****************************************************** + * * Declarations + * ******************************************************/ +int32_t rsi_http_fw_update(uint8_t flags, + uint8_t *, + uint16_t, + uint8_t *, + uint8_t *, + uint8_t *, + uint8_t *, + uint8_t *, + void (*http_otaf_response_handler)(uint16_t, const uint8_t *)); + +void http_otaf_response_handler(uint16_t, const uint8_t *); +int32_t rsi_http_response_status(int32_t *); + +#endif //RSI_HTTP_OTAF_APP diff --git a/wiseconnect/sapi/network/protocols/rsi_mdnsd.c b/wiseconnect/sapi/network/protocols/rsi_mdnsd.c new file mode 100644 index 00000000..97dc5f71 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_mdnsd.c @@ -0,0 +1,447 @@ +/******************************************************************************* +* @file rsi_mdnsd.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +// Include Driver header file +#include "rsi_driver.h" +#include "rsi_mdnsd.h" +/** @addtogroup NETWORK15 +* @{ +*/ +/*==============================================*/ +/** + * @brief Initialize the MDNSD service in device. It creates MDNS daemon. This is a blocking API. + * @param[in] ip_version - Select the IP version. 4 – to select IPv4, \n 6 – to select IPv6 + * @param[in] ttl - Time to live in seconds for which service should be active + * @param[in] host_name - Host name that is used as host name in Type A record. + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + */ +int32_t rsi_mdnsd_init(uint8_t ip_version, uint16_t ttl, uint8_t *host_name) +{ + rsi_req_mdnsd_t *mdnsd; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_MSNSD_INIT_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((rsi_strlen(host_name) + 1) > MDNSD_BUFFER_SIZE) { + SL_PRINTF(SL_MSNSD_INIT_INSUFFICIENT_BUFFER, NETWORK, LOG_ERROR); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_MSNSD_INIT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mdnsd = (rsi_req_mdnsd_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_req_mdnsd_t)); + + // Fill command type + mdnsd->command_type = RSI_MDNSD_INIT; + + // Fill IP version + mdnsd->mdnsd_struct.mdnsd_init.ip_version = ip_version; + + // Fill time to live + rsi_uint16_to_2bytes(mdnsd->mdnsd_struct.mdnsd_init.ttl, ttl); + + // Copy host name + rsi_strcpy(mdnsd->buffer, host_name); + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_mdnsd_t) - MDNSD_BUFFER_SIZE + rsi_strlen(mdnsd->buffer) + 1; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send MDNSD request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_MDNSD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_MDNSD_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_MSNSD_INIT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_MSNSD_INIT_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK15 +* @{ +*/ +#ifndef CHIP_9117 +/*==============================================*/ +/** + * @brief Add a MDNSD service/start service discovery. This is a blocking API. + * @param[in] port - Port number on which service should be added. + * @param[in] ttl - Time to live. This is time in seconds for which service should be active + * @param[in] more - This byte should be set to '1' when there are more services to add. \n + * 0 - This is last service, starts MDNS service. \n + * 1 - Still more services will be added. + * @param[in] service_ptr_name - Name to be added in Type-PTR record + * @param[in] service_name - Name to be added in Type-SRV record (service name) + * @param[in] service_text - Text field to be added in Type-TXT record + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Currently, only one service registration is supported + */ + +int32_t rsi_mdnsd_register_service(uint16_t port, + uint16_t ttl, + uint8_t more, + uint8_t *service_ptr_name, + uint8_t *service_name, + uint8_t *service_text) +{ + rsi_req_mdnsd_t *mdnsd; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((rsi_strlen(service_ptr_name) + rsi_strlen(service_name) + rsi_strlen(service_text) + 3) > MDNSD_BUFFER_SIZE) { + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER, NETWORK, LOG_ERROR); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mdnsd = (rsi_req_mdnsd_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_req_mdnsd_t)); + + // Fill command type + mdnsd->command_type = RSI_MDNSD_REGISTER_SERVICE; + + // Fill port number + rsi_uint16_to_2bytes(mdnsd->mdnsd_struct.mdnsd_register_service.port, port); + + // Fill time to live + rsi_uint16_to_2bytes(mdnsd->mdnsd_struct.mdnsd_register_service.ttl, ttl); + + // More + mdnsd->mdnsd_struct.mdnsd_register_service.more = more; + + // Copy service pointer name + rsi_strcpy(mdnsd->buffer, service_ptr_name); + send_size = rsi_strlen(service_ptr_name) + 1; + + // Copy service name + rsi_strcpy((mdnsd->buffer) + send_size, service_name); + send_size += rsi_strlen(service_name) + 1; + + // Copy service text + rsi_strcpy((mdnsd->buffer) + send_size, service_text); + send_size += rsi_strlen(service_text) + 1; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_mdnsd_t) - MDNSD_BUFFER_SIZE + send_size; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send MDNSD request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_MDNSD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_MDNSD_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +#else + +/*==============================================*/ +/** + * @brief Add a MDNSD service/start service discovery. This is a blocking API. + * @param[in] port - Port number on which service should be added. + * @param[in] ttl - Time to live. This is time in seconds for which service should be active + * @param[in] type - Name to be added in Type field + * @param[in] sub_type - Name to be added in SubType field + * @param[in] service_name - Name to be added in Type-SRV record (service name) + * @param[in] service_text - Text field to be added in Type-TXT record + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Currently, only one service registration is supported + */ + +int32_t rsi_mdnsd_register_service(uint16_t port, + uint16_t ttl, + uint8_t *type, + uint8_t *sub_type, + uint8_t *service_name, + uint8_t *service_text) +{ + rsi_req_mdnsd_t *mdnsd; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((rsi_strlen(type) + rsi_strlen(sub_type) + rsi_strlen(service_name) + rsi_strlen(service_text) + 3) + > MDNSD_BUFFER_SIZE) { + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_INSUFFICIENT_BUFFER, NETWORK, LOG_ERROR); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mdnsd = (rsi_req_mdnsd_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_req_mdnsd_t)); + + // Fill command type + mdnsd->command_type = RSI_MDNSD_REGISTER_SERVICE; + + // Fill port number + rsi_uint16_to_2bytes(mdnsd->mdnsd_struct.mdnsd_register_service.port, port); + + // Fill time to live + rsi_uint16_to_2bytes(mdnsd->mdnsd_struct.mdnsd_register_service.ttl, ttl); + + //Copy Type + rsi_strcpy(mdnsd->buffer, type); + send_size = rsi_strlen(type) + 1; + + //Copy subtype + // Copy service pointer name + rsi_strcpy(mdnsd->buffer, sub_type); + send_size += rsi_strlen(sub_type) + 1; + + // Copy service name + rsi_strcpy((mdnsd->buffer) + send_size, service_name); + send_size += rsi_strlen(service_name) + 1; + + // Copy service text + rsi_strcpy((mdnsd->buffer) + send_size, service_text); + send_size += rsi_strlen(service_text) + 1; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_mdnsd_t) - MDNSD_BUFFER_SIZE + send_size; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send MDNSD request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_MDNSD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_MDNSD_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_MSNSD_REGISTER_SERVICE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +#endif +/** @} */ + +/** @addtogroup NETWORK15 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete the MDNSD service. This is a blocking API. + * @param[in] void + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + */ + +int32_t rsi_mdnsd_deinit(void) +{ + rsi_req_mdnsd_t *mdnsd; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_MSNSD_DEINIT_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_MSNSD_DEINIT_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mdnsd = (rsi_req_mdnsd_t *)pkt->data; + + // Memset the packet data to insert NULL between fields + memset(&pkt->data, 0, sizeof(rsi_req_mdnsd_t)); + + // Fill command type + mdnsd->command_type = RSI_MDNSD_DEINIT; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_mdnsd_t) - MDNSD_BUFFER_SIZE; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send MDNSD request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_MDNSD, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_MDNSD_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_MSNSD_INIT_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_MSNSD_INIT_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_mdnsd.h b/wiseconnect/sapi/network/protocols/rsi_mdnsd.h new file mode 100644 index 00000000..3d4c2c63 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_mdnsd.h @@ -0,0 +1,64 @@ +/******************************************************************************* +* @file rsi_mdnsd.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_MDNSD_H +#define RSI_MDNSD_H + +/****************************************************** + * * Macros + * ******************************************************/ +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_mdnsd_init(uint8_t ip_version, uint16_t ttl, uint8_t *host_name); +#ifndef CHIP_9117 +int32_t rsi_mdnsd_register_service(uint16_t port, + uint16_t ttl, + uint8_t more, + uint8_t *service_ptr_name, + uint8_t *service_name, + uint8_t *service_text); +#else +int32_t rsi_mdnsd_register_service(uint16_t port, + uint16_t ttl, + uint8_t *type, + uint8_t *sub_type, + uint8_t *service_name, + uint8_t *service_text); +#endif +int32_t rsi_mdnsd_deinit(void); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_mqtt_client.c b/wiseconnect/sapi/network/protocols/rsi_mqtt_client.c new file mode 100644 index 00000000..8630a3e3 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_mqtt_client.c @@ -0,0 +1,387 @@ +/******************************************************************************* +* @file rsi_mqtt_client.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" + +#include "rsi_mqtt_client.h" + +#include "MQTT_wrappers.h" + +#include "MQTTClient.h" + +#include "rsi_nwk.h" + +/** @addtogroup NETWORK13 +* @{ +*/ +/*==============================================*/ +/** + * @brief Allocate memory for the MQTT for a single client. Returns MQTT Client instance pointer, which is used for further MQTT client operations. This is non-blocking API. + * @param[in] buffer - Buffer pointer to allocate memory for MQTT Client information + * @param[in] length - Buffer length + * @param[in] server_ip - IPv4 address of the MQTT broker + * @param[in] server_port - MQTT broker port number + * @param[in] client_port - MQTT client port number + * @param[in] flags - Each bit has its own significance \n + * + * Flags | Description + * :-----------------------------|:-------------------------------------- + * Bit(0) - Server IP version | 1 - IPv6 \n + * ^ 0 - IPv4 + * + * @param[in] keep_alive_interval - MQTT client keep alive interval \n + * If there are no transactions between MQTT client and broker within \n + * this time period, MQTT Broker disconnects the MQTT client \n + * If 0, Server does not disconnect \n + * @return Positive Value - Success: Returns MQTT client information structure pointer \n + * @return NULL - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API + * + */ + +rsi_mqtt_client_info_t *rsi_mqtt_client_init(int8_t *buffer, + uint32_t length, + int8_t *server_ip, + uint32_t server_port, + uint32_t client_port, + uint16_t flags, + uint16_t keep_alive_interval) +{ + rsi_mqtt_client_info_t *rsi_mqtt_client = NULL; + SL_PRINTF(SL_MQTT_CLIENT_INIT_ENTRY, NETWORK, LOG_INFO); + // If any invalid parameter is given, return NULL + if (!(buffer && length && server_port && client_port && server_port)) { + // Return invalid command error + SL_PRINTF(SL_MQTT_CLIENT_INIT_COMMAND_ERROR, NETWORK, LOG_ERROR); + return NULL; + } + // Given buffer length for MQTT client information is not sufficient + if (length < MQTT_CLIENT_INFO_SIZE) { + SL_PRINTF(SL_MQTT_CLIENT_INIT_INSUFFICIENT_BUFFER_LENGTH, NETWORK, LOG_ERROR); + return NULL; + } + + rsi_mqtt_client = (rsi_mqtt_client_info_t *)buffer; + + buffer += sizeof(rsi_mqtt_client_info_t); + + rsi_mqtt_client->mqtt_client.ipstack = (Network *)buffer; + + buffer += sizeof(Network); + + rsi_mqtt_client->server_port = server_port; + + rsi_mqtt_client->client_port = client_port; + + rsi_mqtt_client->keep_alive_interval = keep_alive_interval; + + if (flags & RSI_IPV6) { + memcpy(&rsi_mqtt_client->server_ip.ipv6[0], server_ip, RSI_IPV6_ADDRESS_LENGTH); + } else { + // Fill IP address + memcpy(&rsi_mqtt_client->server_ip.ipv4[0], server_ip, RSI_IPV4_ADDRESS_LENGTH); + } + + rsi_mqtt_client->mqtt_tx_buffer = buffer; + + buffer += MQTT_CLIENT_TX_BUFFER_SIZE; + + rsi_mqtt_client->mqtt_rx_buffer = buffer; + + buffer += MQTT_CLIENT_RX_BUFFER_SIZE; + + // Initialize creating new network (initialize network callbacks) + NewNetwork(rsi_mqtt_client->mqtt_client.ipstack); + + // Initialize buffer to the MQTT client + MQTTClient((Client *)rsi_mqtt_client, + rsi_mqtt_client->mqtt_client.ipstack, + MQTT_CONNECT_TIME_OUT, + (uint8_t *)rsi_mqtt_client->mqtt_tx_buffer, + MQTT_CLIENT_TX_BUFFER_SIZE, + (uint8_t *)rsi_mqtt_client->mqtt_rx_buffer, + MQTT_CLIENT_RX_BUFFER_SIZE); + SL_PRINTF(SL_MQTT_CLIENT_INIT_EXIT, NETWORK, LOG_ERROR); + return (rsi_mqtt_client); +} +/** @} */ + +/** @addtogroup NETWORK13 +* @{ +*/ +/*==============================================*/ +/** + * @brief Establish TCP connection with the given MQTT client port and establish MQTT protocol level connection. If Callback is provided it is non-blocking API otherwise it is blocking API. + * @param[in] rsi_mqtt_client - MQTT client information pointer which was returned in rsi_mqtt_client_init() API + * @param[in] flags - Network flags,Each bit has its own significance \n + * + * Flags | Description + * :-------------------------------|:----------------------------------- + * BIT(0) - IP version | 1 - IPv6 \n + * ^ | 0 - IPv4 + * BIT(1) - SSL flag | 1 - SSL Enable \n + * ^ | 0 - SSL Disable + * BIT(2) | 1 - SSL cert index 1 + * BIT(3) | 1 - SSL cert index 2 + * + * @param[in] client_id - clientID of the MQTT Client and should be unique for each device + * @param[in] username - Username for the login credentials of MQTT server + * @param[in] password - password for the login credentials of MQTT server + * @note Need to register callback if ASYNC_MQTT is enable + * For Asynchronous \n + * @param[in] callback - Callback handler for asynchronous response. \n + * @param[out] sock_no - Socket descriptor number \n + * @param[out] buffer - Buffer \n + * @param[out] length - length of buffer \n + * + * @return Zero - Success \n + * Negative value - Failure + * @note Procedure for connecting MQTT over SSL : \n Enable TCP_IP_FEAT_SSL in Opermode parameters as below \n + * #define RSI_TCP_IP_FEATURE_BIT_MAP (TCP_IP_FEAT_DHCPV4_CLIENT | TCP_IP_FEAT_SSL | TCP_IP_FEAT_DNS_CLIENT) \n + * Load the related SSL Certificates in the module using rsi_wlan_set_certificate() API. + * + */ +#ifdef ASYNC_MQTT +int32_t rsi_mqtt_connect(rsi_mqtt_client_info_t *rsi_mqtt_client, + uint16_t flags, + int8_t *client_id, + int8_t *username, + int8_t *password, + void (*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length)) +#else +/** @cond */ + +int32_t rsi_mqtt_connect(rsi_mqtt_client_info_t *rsi_mqtt_client, + uint16_t flags, + int8_t *client_id, + int8_t *username, + int8_t *password) +/** @endcond */ + +#endif +{ + SL_PRINTF(SL_MQTT_CLIENT_CONNECT_ENTRY, NETWORK, LOG_INFO); + int32_t status = 0; + + MQTTPacket_connectData data = MQTTPacket_connectData_initializer; + + if ((rsi_mqtt_client == NULL) || (client_id == NULL)) { + // Return invalid parmater error + SL_PRINTF(SL_MQTT_CLIENT_CONNECT_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // Connect to the new network +#ifdef ASYNC_MQTT + status = ConnectNetwork((Network *)&rsi_mqtt_client->mqtt_client, + flags, + (char *)&(rsi_mqtt_client->server_ip), + rsi_mqtt_client->server_port, + rsi_mqtt_client->client_port, + callback); +#else + status = ConnectNetwork((Network *)&rsi_mqtt_client->mqtt_client, + flags, + (char *)&(rsi_mqtt_client->server_ip), + rsi_mqtt_client->server_port, + rsi_mqtt_client->client_port); +#endif + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_MQTT_CLIENT_CONNECT_EXIT_1, NETWORK, LOG_INFO, "status: %4x", status); + return status; + } + + data.willFlag = 0; + // MQTT Version + data.MQTTVersion = MQTT_VERSION; + // Assign client ID + data.clientID.cstring = (char *)client_id; + + // Fill username and password + if (username != NULL) + data.username.cstring = (char *)username; + + if (password != NULL) + data.password.cstring = (char *)password; + // Keep Alive interval + data.keepAliveInterval = rsi_mqtt_client->keep_alive_interval; + // New connection + data.cleansession = 1; + + // Connect to the MQTT broker + status = MQTTConnect(&rsi_mqtt_client->mqtt_client, &data); + + // Shut Down the port + if (status) + mqtt_disconnect(rsi_mqtt_client->mqtt_client.ipstack); + SL_PRINTF(SL_MQTT_CLIENT_CONNECT_EXIT_2, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup NETWORK13 +* @{ +*/ +/*==============================================*/ +/** + * @brief Disconnect the client from MQTT broker. This is a blocking API. + * @param[in] rsi_mqtt_client - MQTT client information structure pointer that was returned in rsi_mqtt_client_init() API + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_mqtt_connect() API needs to be called before this API + * + * + * + */ +int32_t rsi_mqtt_disconnect(rsi_mqtt_client_info_t *rsi_mqtt_client) +{ + SL_PRINTF(SL_MQTT_CLIENT_DISCONNECT_ENTRY, NETWORK, LOG_INFO); + int32_t status = 0; + // If MQTT info structure is NULL ,throw error + if (rsi_mqtt_client == NULL) { + // Return invalid command error + SL_PRINTF(SL_MQTT_CLIENT_DISCONNECT_INVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + // Call MQTT disconnect + status = MQTTDisconnect(&rsi_mqtt_client->mqtt_client); + // Shut Down the port + mqtt_disconnect(rsi_mqtt_client->mqtt_client.ipstack); + SL_PRINTF(SL_MQTT_CLIENT_DISCONNECT_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Publish the given message on the given topic. This is a blocking API. + * @param[in] rsi_mqtt_client - MQTT client info structure that was returned in rsi_mqtt_client_init() API + * @param[in] topic - String of topic + * @param[in] publish_msg - Message to publish + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_mqtt_connect() API needs to be called before this API + * + */ +int32_t rsi_mqtt_publish(rsi_mqtt_client_info_t *rsi_mqtt_client, int8_t *topic, MQTTMessage *publish_msg) +{ + int32_t status = 0; + SL_PRINTF(SL_MQTT_PUBLISH_ENTRY, NETWORK, LOG_INFO); + // If any invalid parameter is received + if ((rsi_mqtt_client == NULL) || (topic == NULL) || (publish_msg == NULL)) { + // Return invalid command parameter error + SL_PRINTF(SL_MQTT_PUBLISH_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Publish the message + status = MQTTPublish(&rsi_mqtt_client->mqtt_client, (const char *)topic, (MQTTMessage *)publish_msg); + + // Return status + SL_PRINTF(SL_MQTT_PUBLISH_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Subscribe on the specified topic given. If any other client posts any message on the same topic, that message is received, if MQTT client is subscribed to that topic. + * This is a non-blocking API. + * @param[in] rsi_mqtt_client - MQTT client structure info pointer that was returned in \ref rsi_mqtt_client_init() API + * @param[in] qos - Quality of service of the message + * @param[in] topic - Topic string + * @param[in] call_back_handler_ptr - Callback pointer to call when a message is received from MQTT broker + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_mqtt_connect() API needs to be called before this API + */ +int32_t rsi_mqtt_subscribe(rsi_mqtt_client_info_t *rsi_mqtt_client, + uint8_t qos, + int8_t *topic, + void (*call_back_handler_ptr)(MessageData *md)) +{ + int32_t status = 0; + SL_PRINTF(SL_MQTT_SUBSCRIBE_ENTRY, NETWORK, LOG_INFO); + // If any invalid parameter is received +#ifdef ASYNC_MQTT + if ((rsi_mqtt_client == NULL) || (topic == NULL)) +#else + if ((rsi_mqtt_client == NULL) || (topic == NULL) || (call_back_handler_ptr == NULL)) +#endif + { + // Return invalid parameter error + SL_PRINTF(SL_MQTT_SUBSCRIBE_INVALID_PARAM_1, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + if (qos > 2) { + // Return invalid parameter error + SL_PRINTF(SL_MQTT_SUBSCRIBE_INVALID_PARAM_2, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + status = MQTTSubscribe(&rsi_mqtt_client->mqtt_client, (const char *)topic, (enum QoS)qos, call_back_handler_ptr); + SL_PRINTF(SL_MQTT_SUBSCRIBE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Unsubscribe on the specified topic given. If unsubscribed, any messages on the topic is not received further + * This is a non-blocking API. + * @param[in] rsi_mqtt_client - MQTT client instance that was returned in \ref rsi_mqtt_client_init() API + * @param[in] topic - Topic string + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_mqtt_connect() API needs to be called before this API + */ +int32_t rsi_mqtt_unsubscribe(rsi_mqtt_client_info_t *rsi_mqtt_client, int8_t *topic) +{ + SL_PRINTF(SL_MQTT_UNSUBSCRIBE_ENTRY, NETWORK, LOG_INFO); + int32_t status; + if ((rsi_mqtt_client == NULL) || (topic == NULL)) { + // Return invalid command error + SL_PRINTF(SL_MQTT_SUBSCRIBE_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + // Unsubscribe to the topic + status = MQTTUnsubscribe(&rsi_mqtt_client->mqtt_client, (const char *)topic); + SL_PRINTF(SL_MQTT_UNSUBSCRIBE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Wait for the MQTT messages to receive on the specific MQTT client. This is a non-blocking API. + * @param[in] rsi_mqtt_client - MQTT client instance that was returned in \ref rsi_mqtt_client_init() API + * @param[in] time_out - Time out in milliseconds. + * @return 0 - Success \n + * @return Negative value - Failure + * @note **Precondition** - \ref rsi_mqtt_connect() API needs to be called before this API + */ +int32_t rsi_mqtt_poll_for_recv_data(rsi_mqtt_client_info_t *rsi_mqtt_client, int time_out) +{ + if (rsi_mqtt_client == NULL) { + // Return invalid command error + SL_PRINTF(SL_MQTT_POLL_FOR_RECV_DATA_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + SL_PRINTF(SL_MQTT_POLL_FOR_RECV_DATA_EXIT, NETWORK, LOG_INFO); + return MQTTYield(&rsi_mqtt_client->mqtt_client, time_out); +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_mqtt_client.h b/wiseconnect/sapi/network/protocols/rsi_mqtt_client.h new file mode 100644 index 00000000..21156e23 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_mqtt_client.h @@ -0,0 +1,119 @@ +/******************************************************************************* +* @file rsi_mqtt_client.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_MQTT_CLIENT_H +#define RSI_MQTT_CLIENT_H + +#include "MQTTClient.h" +/****************************************************** + * * Macros + * ******************************************************/ + +// MQTT version +#define MQTT_VERSION 3 + +// MQTT Connect timeout +#define MQTT_CONNECT_TIME_OUT 20000 + +// Rx buffer size +#define MQTT_CLIENT_RX_BUFFER_SIZE 1500 + +// Tx buffer size +#define MQTT_CLIENT_TX_BUFFER_SIZE 1500 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +typedef struct rsi_mqtt_client_info_s { + // MQTT Client structure + Client mqtt_client; + // MQTT broker port + uint32_t server_port; + // MQTT client port + uint32_t client_port; + + // Server IP address + rsi_ip_addr_t server_ip; + + // Keep alive interval + uint16_t keep_alive_interval; + + // MQTT client TX buffer + int8_t *mqtt_tx_buffer; + + // MQTT client RX buffer + int8_t *mqtt_rx_buffer; + +} rsi_mqtt_client_info_t; + +// Total MQTT initialization buffer required for MQTT client info storage +#define MQTT_CLIENT_INFO_SIZE \ + (sizeof(rsi_mqtt_client_info_t) + sizeof(Network) + MQTT_CLIENT_TX_BUFFER_SIZE + MQTT_CLIENT_RX_BUFFER_SIZE) + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +rsi_mqtt_client_info_t *rsi_mqtt_client_init(int8_t *buffer, + uint32_t length, + int8_t *server_ip, + uint32_t server_port, + uint32_t client_port, + uint16_t flags, + uint16_t keep_alive_interval); +#ifdef ASYNC_MQTT +int32_t rsi_mqtt_connect(rsi_mqtt_client_info_t *rsi_mqtt_client, + uint16_t flags, + int8_t *client_id, + int8_t *username, + int8_t *password, + void (*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length)); +#else +int32_t rsi_mqtt_connect(rsi_mqtt_client_info_t *rsi_mqtt_client, + uint16_t flags, + int8_t *client_id, + int8_t *username, + int8_t *password); +#endif +int32_t rsi_mqtt_disconnect(rsi_mqtt_client_info_t *rsi_mqtt_client); +int32_t rsi_mqtt_publish(rsi_mqtt_client_info_t *rsi_mqtt_client, int8_t *topic, MQTTMessage *publish_msg); +int32_t rsi_mqtt_subscribe(rsi_mqtt_client_info_t *rsi_mqtt_client, + uint8_t qos, + int8_t *topic, + void (*call_back_handler_ptr)(MessageData *md)); +int32_t rsi_mqtt_unsubscribe(rsi_mqtt_client_info_t *rsi_mqtt_client, int8_t *topic); +int32_t rsi_mqtt_poll_for_recv_data(rsi_mqtt_client_info_t *rsi_mqtt_client, int time_out); +void mqtt_disconnect(Network *n); + +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_multicast.c b/wiseconnect/sapi/network/protocols/rsi_multicast.c new file mode 100644 index 00000000..373bdb4f --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_multicast.c @@ -0,0 +1,166 @@ +/******************************************************************************* +* @file rsi_multicast.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_multicast.h" +/** @addtogroup NETWORK3 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send multicast group join or leave. This is a blocking API. + * @param[in] flags - Select IP version. \n BIT(0) : 0 - IPv4 , 1 - IPv6 + * @param[in] ip_address - Multicast IP address + * @param[in] command_type - Type of commands: JOIN/LEAVE + * @return 0 - Success \n + * @return Negative value - Failure + * + */ +/// @private +static int32_t rsi_multicast(uint8_t flags, int8_t *ip_address, uint8_t command_type) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_MULTICAST_ENTRY, NETWORK, LOG_INFO); + + rsi_pkt_t *pkt; + rsi_req_multicast_t *multicast; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return packet allocation failure error + SL_PRINTF(SL_MULTICAST_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + multicast = (rsi_req_multicast_t *)pkt->data; + + // Fill IP version and IP address + if (flags & RSI_IPV6) { + // Fill IPv6 version + rsi_uint16_to_2bytes(multicast->ip_version, RSI_IP_VERSION_6); + + // Fill IPv6 address + memcpy(multicast->multicast_address.ipv6_address, ip_address, RSI_IPV6_ADDRESS_LENGTH); + } else { + // Fill IPv4 version + rsi_uint16_to_2bytes(multicast->ip_version, RSI_IP_VERSION_4); + + // Fill IPv4 address + memcpy(multicast->multicast_address.ipv4_address, ip_address, RSI_IPV4_ADDRESS_LENGTH); + } + + // Fill command type + rsi_uint16_to_2bytes(multicast->type, command_type); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send set FTP Create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_MULTICAST, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_MULTICAST_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_MULTICAST_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_MULTICAST_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK3 +* @{ +*/ +/*==============================================*/ +/** + * @brief Join to a multicast group. This is a blocking API. + * @param[in] flags - Select the IP version. \n + * BIT(0): 0 - IPv4 , 1 - IPv6 + * @param[in] ip_address - IPv4/IPv6 address of multicast group. + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Device supports only one multicast group. It must leave the previous group, to join a new multicast group. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_multicast_join(uint8_t flags, int8_t *ip_address) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_MULTICAST_JOIN_ENTRY, NETWORK, LOG_INFO); + + status = rsi_multicast(flags, ip_address, RSI_MULTICAST_JOIN); + SL_PRINTF(SL_MULTICAST_JOIN_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK3 +* @{ +*/ +/*==============================================*/ +/** + * @brief Leave the multicast group. This is a blocking API. + * @pre \ref rsi_config_ipaddress() API needs to be called before this API. + * @param[in] flags - Select the IP version. \n + * BIT(0) – RSI_IPV6. Set this bit to enable IPv6. By default it is configured to IPv4. + * @param[in] ip_address - IPv4/IPv6 address of multicast group. + * @return 0 - Success \n + * Negative Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc, 0x0021,0x002C,0x0015,0xBB16,0xBB17) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Device supports only one multicast group. It must leave the previous group, to join a new multicast group. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_multicast_leave(uint8_t flags, int8_t *ip_address) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_MULTICAST_LEAVE_ENTRY, NETWORK, LOG_INFO); + + status = rsi_multicast(flags, ip_address, RSI_MULTICAST_LEAVE); + + SL_PRINTF(SL_MULTICAST_LEAVE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_multicast.h b/wiseconnect/sapi/network/protocols/rsi_multicast.h new file mode 100644 index 00000000..cca32f7c --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_multicast.h @@ -0,0 +1,52 @@ +/******************************************************************************* +* @file rsi_multicast.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_MULTICAST_H +#define RSI_MULTICAST_H +#include "rsi_driver.h" +/****************************************************** + * * Macros + * ******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_multicast_join(uint8_t flags, int8_t *ip_address); +int32_t rsi_multicast_leave(uint8_t flags, int8_t *ip_address); + +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_ota_fw_up.c b/wiseconnect/sapi/network/protocols/rsi_ota_fw_up.c new file mode 100644 index 00000000..05e22a2a --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_ota_fw_up.c @@ -0,0 +1,131 @@ +/******************************************************************************* +* @file rsi_ota_fw_up.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_firmware_upgradation.h" + +/** @addtogroup NETWORK20 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create an OTAF client. Initialize the client with a given configuration. This is a non-blocking API. + * @param[in] flags - Select the IP version. \n + * BIT(0) – RSI_IPV6: Set this bit to enable IPv6 , by default it is configured to IPv4 + * @param[in] server_ip - OTAF server IP address + * @param[in] server_port - OTAF server port number + * @param[in] chunk_number - Firmware content request chunk number + * @param[in] timeout - TCP receive packet timeout + * @param[in] tcp_retry_count - TCP retransmissions count + * @param[in] ota_fw_up_response_handler - Callback when asynchronous response is received from module for firmware update request. + * Callback parameters: status and chunk_number + * @param[out] status - Status code + * @param[out] chunk_number - Chunk number of the firmware content + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note For safe firmware upgrade via TCP server, \n + * it will take approx. 65 sec duration for upgrading the firmware of 1.5 MB file. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_ota_firmware_upgradation(uint8_t flags, + uint8_t *server_ip, + uint32_t server_port, + uint16_t chunk_number, + uint16_t timeout, + uint16_t tcp_retry_count, + void (*ota_fw_up_response_handler)(uint16_t status, uint16_t chunk_number)) +{ + int32_t status = RSI_SUCCESS; + + rsi_pkt_t *pkt; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_req_ota_fwup_t *otaf_fwup = NULL; + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (ota_fw_up_response_handler != NULL) { + // Register SMTP client response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_ota_fw_up_response_handler = ota_fw_up_response_handler; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + otaf_fwup = (rsi_req_ota_fwup_t *)pkt->data; + + // Check IP version + if (!(flags & RSI_IPV6)) { + // Fill the IP version + otaf_fwup->ip_version = RSI_IP_VERSION_4; + + // Set IP address to localhost + memcpy(otaf_fwup->server_ip_address.ipv4_address, server_ip, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Fill the IP version + otaf_fwup->ip_version = RSI_IP_VERSION_6; + + // Set IP address to localhost + memcpy(otaf_fwup->server_ip_address.ipv6_address, server_ip, RSI_IPV6_ADDRESS_LENGTH); + } + + // Fill server port number + rsi_uint32_to_4bytes(otaf_fwup->server_port, server_port); + + // Fill chunk number + rsi_uint16_to_2bytes(otaf_fwup->chunk_number, chunk_number); + + // Fill timeout + rsi_uint16_to_2bytes(otaf_fwup->timeout, timeout); + + // Fill TCP retry count + rsi_uint16_to_2bytes(otaf_fwup->retry_count, tcp_retry_count); + + // Send OTAF command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_OTA_FWUP, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status if error in sending command occurs + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_pop3_client.c b/wiseconnect/sapi/network/protocols/rsi_pop3_client.c new file mode 100644 index 00000000..3b3e243a --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_pop3_client.c @@ -0,0 +1,716 @@ +/******************************************************************************* +* @file rsi_pop3_client.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +#ifdef POP3_ENABLE +#include "rsi_driver.h" + +#include "rsi_pop3_client.h" + +/** @addtogroup NETWORK20 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create POP3 client session. This is a non-blocking API. + * @param[in] flags - Select the IP version. \n + * BIT(0) – RSI_IPV6: Set this bit to enable IPv6, by default it is configured to IPv4 + * @param[in] server_ip_address - POP3 server IP address + * @param[in] server_port_number - POP3 server TCP port + * @param[in] auth_type - Client authentication type + * @param[in] username - Username for authentication. It must be a NULL terminated string + * @param[in] password - Password for authentication. It must be a NULL terminated string + * @param[in] rsi_pop3_client_mail_response_handler - Callback when asynchronous response comes for the session create. \n + * The callback parameters are: status,type, and buffer \n + * @param[out] status - Status code + * @param[out] type - Sub-command type + * @param[out] buffer - Buffer pointer + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0x0015,0xBB87,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_pop3_session_create_async(uint8_t flags, + uint8_t *server_ip_address, + uint16_t server_port_number, + uint8_t auth_type, + uint8_t *username, + uint8_t *password, + void (*rsi_pop3_client_mail_response_handler)(uint16_t status, + uint8_t type, + const uint8_t *buffer)) +{ + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (rsi_pop3_client_mail_response_handler != NULL) { + // Register POP3 client response, notify callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_pop3_client_mail_response_handler = rsi_pop3_client_mail_response_handler; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_SESSION_CREATE; + + if (!(flags & RSI_IPV6)) { + // Fill the IP version + pop3_client->pop3_struct.pop3_client_session_create.ip_version = RSI_IP_VERSION_4; + + // Set IP address to localhost + memcpy(pop3_client->pop3_struct.pop3_client_session_create.server_ip_address.ipv4_address, + server_ip_address, + RSI_IPV4_ADDRESS_LENGTH); + } else { + pop3_client->pop3_struct.pop3_client_session_create.ip_version = RSI_IP_VERSION_6; + + // Set IP address to localhost + memcpy(pop3_client->pop3_struct.pop3_client_session_create.server_ip_address.ipv6_address, + server_ip_address, + RSI_IPV6_ADDRESS_LENGTH); + } + + // Fill POP3 server port number + rsi_uint16_to_2bytes(pop3_client->pop3_struct.pop3_client_session_create.server_port_number, server_port_number); + + // Fill authentication type + pop3_client->pop3_struct.pop3_client_session_create.auth_type = auth_type; + + // Fill username + rsi_strcpy(pop3_client->pop3_struct.pop3_client_session_create.username, username); + + // Fill password + rsi_strcpy(pop3_client->pop3_struct.pop3_client_session_create.password, password); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Delete POP3 client session. This is a non-blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_pop3_session_delete(void) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_SESSION_DELETE; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Get POP3 client mail stats. This is a non-blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_pop3_get_mail_stats(void) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_GET_MAIL_STATS; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Get the size of the mail for the passed mail index of the POP2 client. This is a blocking API. + * @param[in] mail_index - Mail index to get the size of the mail + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xBBFF,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_pop3_get_mail_list(uint16_t mail_index) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_GET_MAIL_LIST; + + // Fill POP3 mail index number + rsi_uint16_to_2bytes(pop3_client->pop3_struct.pop3_client_mail_index, mail_index); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_POP3_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Retrieve mail content for the passed mail index of POP3 client. This is a non-blocking API. + * @param[in] mail_index - Mail index to get the mail content for the passed index + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xBBFF,0xBBC5,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_pop3_retrive_mail(uint16_t mail_index) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_RETR_MAIL; + + // Fill POP3 mail index number + rsi_uint16_to_2bytes(pop3_client->pop3_struct.pop3_client_mail_index, mail_index); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Mark a mail as deleted for the passed mail index of POP3 client.This is a non-blocking API. + * @param[in] mail_index - Mail index to mark the mail as deleted + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xBBFF,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_pop3_mark_mail(uint16_t mail_index) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_MARK_MAIL; + + // Fill POP3 mail index number + rsi_uint16_to_2bytes(pop3_client->pop3_struct.pop3_client_mail_index, mail_index); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Unmark all the marked (deleted) mails of POP3 client in the current session. This is a non-blocking API. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_pop3_unmark_mail(void) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_UNMARK_MAIL; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} + +/*==============================================*/ +/** + * @brief Get the POP3 server status. This is a non-blocking API. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x0021,0xBB87,0xFF74) \n + * @note **This API is not supported currently** + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_pop3_get_server_status(void) +{ + + rsi_req_pop3_client_t *pop3_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint8_t *host_desc = NULL; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + pop3_client = (rsi_req_pop3_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_pop3_client_t)); + + // Fill command type + pop3_client->command_type = POP3_CLIENT_GET_SERVER_STATUS; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (sizeof(rsi_req_pop3_client_t) & 0xFFF)); + + // Send POP3 client session create request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_POP3_CLIENT, pkt); + + } else { + // Return NWK command error + return status; + } + + // Return status + return status; +} +/** @} */ +#endif \ No newline at end of file diff --git a/wiseconnect/sapi/network/protocols/rsi_pop3_client.h b/wiseconnect/sapi/network/protocols/rsi_pop3_client.h new file mode 100644 index 00000000..c3cdc1cc --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_pop3_client.h @@ -0,0 +1,90 @@ +/******************************************************************************* +* @file rsi_pop3_client.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_POP3_CLIENT_H +#define RSI_POP3_CLIENT_H + +#include +/****************************************************** + * * Macros + * ******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ + +// To create the POP3 session +int32_t rsi_pop3_session_create(uint8_t flags, + uint8_t *server_ip_address, + uint16_t server_port_number, + uint8_t auth_type, + uint8_t *username, + uint8_t *password, + void (*rsi_pop3_response_handler)(uint16_t status, uint8_t type, uint8_t *buffer)); +int32_t rsi_pop3_session_create_async(uint8_t flags, + uint8_t *server_ip_address, + uint16_t server_port_number, + uint8_t auth_type, + uint8_t *username, + uint8_t *password, + void (*rsi_pop3_client_mail_response_handler)(uint16_t status, + uint8_t type, + const uint8_t *buffer)); + +// Delete the POP3 session +int32_t rsi_pop3_session_delete(void); + +// Get the number of mails count and total size of the mails +int32_t rsi_pop3_get_mail_stats(void); + +// Get the mail size of the passed mail index +int32_t rsi_pop3_get_mail_list(uint16_t mail_index); + +// Get the mail header and mail body of the passed mail index +int32_t rsi_pop3_retrive_mail(uint16_t mail_index); + +// Mail will be marked as deleted on the POP3 server for the passed mail index +int32_t rsi_pop3_mark_mail(uint16_t mail_index); + +// Any messages/mails marked as deleted in the current session will be unmarked +int32_t rsi_pop3_unmark_mail(void); /* or rsi_pop3_reset(void);*/ + +// Get the connection status of the POP3 server +int32_t rsi_pop3_get_server_status(void); + +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_raw_data.c b/wiseconnect/sapi/network/protocols/rsi_raw_data.c new file mode 100644 index 00000000..7adbfb77 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_raw_data.c @@ -0,0 +1,104 @@ +/******************************************************************************* +* @file rsi_raw_data.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/** @addtogroup NETWORK3 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send raw data to the module. This is a blocking API. + * @param[in] buffer - Pointer to the buffer to send + * @param[in] length - Length of the buffer to send + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +#include "rsi_driver.h" +int32_t rsi_send_raw_data(uint8_t *buffer, uint32_t length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SEND_RAW_DATA_ENTRY, NETWORK, LOG_INFO); + uint8_t *host_desc; + rsi_pkt_t *pkt; + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // If buffer is invalid + if ((buffer == NULL) || (length == 0)) { + // Return packet allocation failure error + SL_PRINTF(SL_SEND_RAW_DATA_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate packet to send data + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SEND_RAW_DATA_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Get host descriptor pointer + host_desc = pkt->desc; + + // Memset host descriptor + memset(host_desc, 0, RSI_HOST_DESC_LENGTH); + + // Fill host descriptor + rsi_uint16_to_2bytes(host_desc, (length & 0xFFF)); + + // Fill packet type + host_desc[1] |= (RSI_WLAN_DATA_Q << 4); + + // Fill frame type + host_desc[2] = 0x1; + + // Copy data to be sent + memcpy(pkt->data, buffer, length); + + // Enqueue packet to WLAN TX queue + rsi_enqueue_pkt(&rsi_driver_cb->wlan_tx_q, pkt); + +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap |= BIT(0); +#endif + // Set TX packet pending event + rsi_set_event(RSI_TX_EVENT); + + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->send_data_sem, RSI_RAW_DATA_RESPONSE_WAIT_TIME); + status = rsi_wlan_get_status(); + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + // Return status + SL_PRINTF(SL_SEND_RAW_DATA_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_smtp_client.c b/wiseconnect/sapi/network/protocols/rsi_smtp_client.c new file mode 100644 index 00000000..cf1b22b8 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_smtp_client.c @@ -0,0 +1,488 @@ +/******************************************************************************* +* @file rsi_smtp_client.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" + +#include "rsi_smtp_client.h" +/** @addtogroup NETWORK11 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create an SMTP client. nitialize the client with a given configuration. + * This is a blocking API. + * @param[in] flags - Select IPV4/IPv6 version \n + * + * Flags | Description + * :----------------------|:----------------------------------------------------------------------- + * BIT(0) - RSI_IPV6 | Set this bit to enable IPv6. Configured to IPv4 by default + * BIT(1) to BIT(7) | Reserved for future use + * + * @param[in] username - Username for authentication, must be a NULL terminated string + * @param[in] password - Password for authentication, must be a NULL terminated string + * @param[in] from_address - Sender's address, must be a NULL terminated string + * @param[in] client_domain - Domain name of the client, must be a NULL terminated string + * @param[in] auth_type - Client authentication type. \n + * 1 - SMTP_CLIENT_AUTH_LOGIN, \n + * 3 - SMTP_CLIENT_AUTH_PLAIN + * @param[in] server_ip - SMTP server IP address. \n + * IPv4 address - 4 Bytes hexa-decimal, \n + * IPv6 address - 16 Bytes hexa-decimal + * @param[in] port - SMTP server TCP port + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note **This API is not supported in current release.** + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_smtp_client_create(uint8_t flags, + uint8_t *username, + uint8_t *password, + uint8_t *from_address, + uint8_t *client_domain, + uint8_t auth_type, + uint8_t *server_ip, + uint32_t port) +{ + rsi_req_smtp_client_t *smtp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t smtp_length = 0; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SMTP_CLIENT_CREATE_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SMTP_CLIENT_CREATE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if ((auth_type != RSI_SMTP_CLIENT_AUTH_LOGIN) && (auth_type != RSI_SMTP_CLIENT_AUTH_PLAIN)) { + // Return invalid command error + SL_PRINTF(SL_SMTP_CLIENT_CREATE_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_1, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + smtp_client = (rsi_req_smtp_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_smtp_client_t)); + + // Fill command type + smtp_client->command_type = RSI_SMTP_CLIENT_CREATE; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_smtp_client_t) - RSI_SMTP_BUFFER_LENGTH; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + // Send HTTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SMTP_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_SMTP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + if (status != RSI_SUCCESS) { + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return status + SL_PRINTF(SL_SMTP_CLIENT_CREATE_EXIT_1, NETWORK, LOG_INFO, "status: %4x", status); + return status; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SMTP_CLIENT_CREATE_PKT_ALLOCATION_FAILURE_2, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_smtp_client_t)); + + // Fill command type + smtp_client->command_type = RSI_SMTP_CLIENT_INIT; + + // Fill the authentication type + smtp_client->smtp_struct.smtp_client_init.auth_type = auth_type; + + if (!(flags & RSI_IPV6)) { + // Fill the IP version + smtp_client->smtp_struct.smtp_client_init.ip_version = RSI_IP_VERSION_4; + + // Set IP address to localhost + memcpy(smtp_client->smtp_struct.smtp_client_init.server_ip_address.ipv4_address, + server_ip, + RSI_IPV4_ADDRESS_LENGTH); + } else { + smtp_client->smtp_struct.smtp_client_init.ip_version = RSI_IP_VERSION_6; + + // Set IP address to localhost + memcpy(smtp_client->smtp_struct.smtp_client_init.server_ip_address.ipv6_address, + server_ip, + RSI_IPV6_ADDRESS_LENGTH); + } + + // Fill the server port + rsi_uint32_to_4bytes(smtp_client->smtp_struct.smtp_client_init.server_port, port); + + // Copy username + rsi_strcpy(smtp_client->smtp_buffer, username); + smtp_length = rsi_strlen(username) + 1; + + // Copy password + rsi_strcpy((smtp_client->smtp_buffer) + smtp_length, password); + smtp_length += rsi_strlen(password) + 1; + + // Copy from address + rsi_strcpy((smtp_client->smtp_buffer) + smtp_length, from_address); + smtp_length += rsi_strlen(from_address) + 1; + + // Copy client domain + rsi_strcpy((smtp_client->smtp_buffer) + smtp_length, client_domain); + smtp_length += rsi_strlen(client_domain) + 1; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_smtp_client_t) - RSI_SMTP_BUFFER_LENGTH + smtp_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send HTTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SMTP_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_SMTP_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_SMTP_CLIENT_CREATE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SMTP_CLIENT_CREATE_EXIT_2, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK11 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send mail to the recipient from the SMTP client. + * This is non-blocking API. + * @param[in] mail_recipient_address - Mail recipient address + * @param[in] priority - Priority level at which mail is delivered. \n + * 1 - RSI_SMTP_MAIL_PRIORITY_LOW, \n + * 2 - RSI_SMTP_MAIL_PRIORITY_NORMAL, \n + * 4 - RSI_SMTP_MAIL_PRIORITY_HIGH + * @param[in] mail_subject - Subject line text, a null terminated string. + * @param[in] mail_body - Mail message + * @param[in] mail_body_length - Length of the mail body + * @param[in] smtp_client_mail_response_handler - Callback when asynchronous response comes from the sent mail. \n + * status: Status code, \n + * cmd: Sub-command type + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note **This API is not supported in current release.** + * @note The total maximum length of mail_recipient_address, mail_subject & mail_body is 1024 bytes \n + * @note If status in callback is non-zero, then sub command type will be in 6th byte of the descriptor + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_smtp_client_mail_send_async(uint8_t *mail_recipient_address, + uint8_t priority, + uint8_t *mail_subject, + uint8_t *mail_body, + uint16_t mail_body_length, + void (*smtp_client_mail_response_handler)(uint16_t status, + const uint8_t cmd_type)) +{ + rsi_req_smtp_client_t *smtp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t smtp_length = 0; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if ((priority != RSI_SMTP_MAIL_PRIORITY_LOW) && (priority != RSI_SMTP_MAIL_PRIORITY_NORMAL) + && (priority != RSI_SMTP_MAIL_PRIORITY_HIGH)) { + // Return invalid command error + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_1, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (smtp_client_mail_response_handler != NULL) { + // Register SMTP client response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.smtp_client_mail_response_handler = smtp_client_mail_response_handler; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_INVALID_PARAM_2, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + smtp_client = (rsi_req_smtp_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_smtp_client_t)); + + // Fill command type + smtp_client->command_type = RSI_SMTP_CLIENT_MAIL_SEND; + + smtp_client->smtp_struct.smtp_mail_send.smtp_feature = priority; + + // Copy SMTP mail body length + rsi_uint16_to_2bytes(smtp_client->smtp_struct.smtp_mail_send.mail_body_length, mail_body_length); + + // Copy mail recipient address + rsi_strcpy(smtp_client->smtp_buffer, mail_recipient_address); + smtp_length = rsi_strlen(mail_recipient_address) + 1; + + // Copy mail subject + rsi_strcpy((smtp_client->smtp_buffer) + smtp_length, mail_subject); + smtp_length += rsi_strlen(mail_subject) + 1; + + // Copy mail message + memcpy((smtp_client->smtp_buffer) + smtp_length, mail_body, mail_body_length); + smtp_length += mail_body_length; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_smtp_client_t) - RSI_SMTP_BUFFER_LENGTH + smtp_length; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + // Send SMTP mail send request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SMTP_CLIENT, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SMTP_CLIENT_MAIL_SEND_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK11 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete SMTP client. + * This is a non-blocking API. + * @param[in] smtp_client_delete_response_handler - Callback when asynchronous response comes for the delete request \n + * status: Status code \n + * cmd : Sub-command type + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note **This API is not supported in current release.** + * @note If status in callback is non-zero, then sub-command type will be in 6th byte of the descriptor. + */ + +int32_t rsi_smtp_client_delete_async(void (*smtp_client_delete_response_handler)(uint16_t status, + const uint8_t cmd_type)) +{ + + rsi_req_smtp_client_t *smtp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (smtp_client_delete_response_handler != NULL) { + // Register SMTP client delete response notify call back handler + rsi_wlan_cb_non_rom->nwk_callbacks.smtp_client_delete_response_handler = smtp_client_delete_response_handler; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_INVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + smtp_client = (rsi_req_smtp_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_smtp_client_t)); + + // Fill command type + smtp_client->command_type = RSI_SMTP_CLIENT_DEINIT; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_req_smtp_client_t) - RSI_SMTP_BUFFER_LENGTH; + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + // send SMTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SMTP_CLIENT, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SMTP_CLIENT_DELETE_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_smtp_client.h b/wiseconnect/sapi/network/protocols/rsi_smtp_client.h new file mode 100644 index 00000000..70f69ee7 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_smtp_client.h @@ -0,0 +1,89 @@ +/******************************************************************************* +* @file rsi_smtp_client.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_SMTP_CLIENT_H +#define RSI_SMTP_CLIENT_H +/****************************************************** + * * Macros + * ******************************************************/ +#ifndef RSI_IPV6 +#define RSI_IPV6 1 +#endif + +// Low Priority +#define RSI_SMTP_MAIL_PRIORITY_LOW 1 + +// Normal Priority +#define RSI_SMTP_MAIL_PRIORITY_NORMAL 2 + +// High Priority +#define RSI_SMTP_MAIL_PRIORITY_HIGH 4 + +// Auth type +#define RSI_SMTP_CLIENT_AUTH_LOGIN 1 + +// Auth type +#define RSI_SMTP_CLIENT_AUTH_PLAIN 3 + +//SMTP OVER SSL +#define SMTP_SSL_ENABLED BIT(2) +#define SMTP_SSL_TLSv_1 BIT(3) +#define SMTP_SSL_TLSv_1_2 BIT(4) +#define SMTP_SSL_TLSv_1_1 BIT(5) + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_smtp_client_mail_send_async(uint8_t *mail_recipient_address, + uint8_t priority, + uint8_t *mail_subject, + uint8_t *mail_body, + uint16_t mail_body_length, + void (*smtp_client_mail_response_handler)(uint16_t status, + const uint8_t cmd_type)); +int32_t rsi_smtp_client_create(uint8_t flags, + uint8_t *username, + uint8_t *password, + uint8_t *from_address, + uint8_t *client_domain, + uint8_t auth_type, + uint8_t *server_ip, + uint32_t port); +int32_t rsi_smtp_client_delete_async(void (*smtp_client_delete_response_handler)(uint16_t status, + const uint8_t cmd_type)); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_sntp_client.c b/wiseconnect/sapi/network/protocols/rsi_sntp_client.c new file mode 100644 index 00000000..479ead11 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_sntp_client.c @@ -0,0 +1,590 @@ +/******************************************************************************* +* @file rsi_sntp_client.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" + +#include "rsi_sntp_client.h" + +#include "rsi_nwk.h" + +/** @addtogroup NETWORK12 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create SNTP client. + * This is a non-blocking API. + * @param[in] flags - Select IP version and security \n + * + * Flags | Description + * :----------------------|:----------------------------------------------------------------------- + * BIT(0) - RSI_IPV6 | Set this bit to enable IPv6. Configured to IPv4 by default. + * BIT(1) - RSI_SSL_ENABLE| Set this bit to enable SSL feature + * BIT(2) to BIT(7) | Reserved for future use + * + * @param[in] server_ip - Server IP address + * @param[in] sntp_method - SNTP methods to use \n + * 1-For Broadcast method, 2-For Unicast method + * @param[in] sntp_retry_count - Configures SNTP max retry count \n + * The number of times the client request is retried when the server response is failed to receive. \n + * For each retry, the client waits for 5 secs to receive server response before initiating next attempt. \n + * Need to set the value based on the network quality. \n + * For ex: The value should be <= 5 for good network quality and > 10 for bad network quality. + * @param[in] sntp_client_create_response_handler - Callback function when asynchronous response comes for the request. \n + * status: Status code. Expected error codes are : 0xBB0A, 0xFF5F, 0xBB0B, 0xBB15, 0xBB10 \n + * cmd_type: Command type \n + * buffer: Buffer pointer + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note SNTP broadcast method is currently not supported. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_sntp_client_create_async(uint8_t flags, + uint8_t *server_ip, + uint8_t sntp_method, + uint16_t sntp_retry_count, + void (*rsi_sntp_client_create_response_handler)(uint16_t status, + const uint8_t cmd_type, + const uint8_t *buffer)) + +{ + rsi_sntp_client_t *sntp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Register callback + if (rsi_sntp_client_create_response_handler != NULL) { + // Register POP3 client response notify callback handler + rsi_wlan_cb_non_rom->nwk_callbacks.rsi_sntp_client_create_response_handler = + rsi_sntp_client_create_response_handler; + } else { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return invalid command error + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_INVALID_PARAM, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + sntp_client = (rsi_sntp_client_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_sntp_client_t)); + + // Fill command type + sntp_client->command_type = RSI_SNTP_CREATE; + + if ((sntp_method != RSI_SNTP_BROADCAST_MODE) && (sntp_method != RSI_SNTP_UNICAST_MODE)) { + // Default SNTP is in UNICAST mode + sntp_method = RSI_SNTP_UNICAST_MODE; + } + + // Fill SNTP method + sntp_client->sntp_method = sntp_method; + + // SNTP retry count + rsi_uint16_to_2bytes(sntp_client->sntp_retry_count, sntp_retry_count); + + // Check for IP version + if (!(flags & RSI_IPV6)) { + sntp_client->ip_version = RSI_IP_VERSION_4; + memcpy(sntp_client->server_ip_address.ipv4_address, server_ip, RSI_IPV4_ADDRESS_LENGTH); + } else { + sntp_client->ip_version = RSI_IP_VERSION_6; + memcpy(sntp_client->server_ip_address.ipv4_address, server_ip, RSI_IPV6_ADDRESS_LENGTH); + } + + // Using host descriptor to set payload length + send_size = sizeof(rsi_sntp_client_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending |= SNTP_RESPONSE_PENDING; + // send SNTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SNTP_CLIENT, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SNTP_CLIENT_CREATE_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK12 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the current time parameters (NTP epoch time). + * This is a blocking API. + * @param[in] length - Length of the buffer + * @param[in] sntp_time_rsp - Current time response + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_sntp_client_create_async() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_sntp_client_gettime(uint16_t length, uint8_t *sntp_time_rsp) +{ + + rsi_sntp_client_t *sntp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Attach the buffer given by user + rsi_driver_cb_non_rom->nwk_app_buffer = (uint8_t *)sntp_time_rsp; + + // Length of the buffer provided by user + rsi_driver_cb_non_rom->nwk_app_buffer_length = length; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_sntp_client_t)); + + sntp_client = (rsi_sntp_client_t *)pkt->data; + + // Fill command type + sntp_client->command_type = RSI_SNTP_GETTIME; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_sntp_client_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send SNTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SNTP_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_SNTP_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK12 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get current time in time date format parameters. + * This is a blocking API. + * @param[in] length - Length of the buffer + * @param[in] sntp_time_date_rsp - Current time and date response + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_sntp_client_create_async() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_sntp_client_gettime_date(uint16_t length, uint8_t *sntp_time_date_rsp) +{ + rsi_sntp_client_t *sntp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_DATE_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_DATE_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_DATE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Attach the buffer given by user + rsi_driver_cb_non_rom->nwk_app_buffer = (uint8_t *)sntp_time_date_rsp; + + // Length of the buffer provided by user + rsi_driver_cb_non_rom->nwk_app_buffer_length = length; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_sntp_client_t)); + + sntp_client = (rsi_sntp_client_t *)pkt->data; + + // Fill command type + sntp_client->command_type = RSI_SNTP_GETTIME_DATE; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_sntp_client_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send SNTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SNTP_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_SNTP_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_DATE_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SNTP_CLIENT_GETTIME_DATE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK12 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get SNTP server info. + * This is a blocking API. + * @param[in] length - Reponse buffer length + * @param[in] sntp_server_response - Pointer to the SNTP Reponse buffer + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_sntp_client_create_async() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_sntp_client_server_info(uint16_t length, uint8_t *sntp_server_response) +{ + + rsi_sntp_client_t *sntp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SNTP_CLIENT_SERVER_INFO_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // if state is not in card ready received state + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_SERVER_INFO_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SNTP_CLIENT_SERVER_INFO_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Attach the buffer given by user + rsi_driver_cb_non_rom->nwk_app_buffer = (uint8_t *)sntp_server_response; + + // Length of the buffer provided by user + rsi_driver_cb_non_rom->nwk_app_buffer_length = length; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_sntp_client_t)); + + sntp_client = (rsi_sntp_client_t *)pkt->data; + + // Fill command type + sntp_client->command_type = RSI_SNTP_GET_SERVER_INFO; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_sntp_client_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_NWK_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + + // Send SNTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SNTP_CLIENT, pkt); + + // Wait on NWK semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_SNTP_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + + // Change NWK state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_SNTP_CLIENT_SERVER_INFO_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SNTP_CLIENT_SERVER_INFO_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/** @} */ + +/** @addtogroup NETWORK12 +* @{ +*/ +/*==============================================*/ +/** + * @brief Delete SNTP client. + * This is a non-blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_sntp_client_create_async() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_sntp_client_delete_async(void) +{ + rsi_sntp_client_t *sntp_client; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + SL_PRINTF(SL_SNTP_CLIENT_DELETE_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE || wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // In concurrent mode or AP mode, state should be in RSI_WLAN_STATE_CONNECTED to accept this command + if ((wlan_cb->state < RSI_WLAN_STATE_CONNECTED)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } else { + // If state is not in ipconfig done state + if ((wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_SNTP_CLIENT_DELETE_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_2, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change common state to allow state + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_SNTP_CLIENT_DELETE_ASYNC_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_sntp_client_t)); + + sntp_client = (rsi_sntp_client_t *)pkt->data; + + // Fill command type + sntp_client->command_type = RSI_SNTP_DELETE; + + // Using host descriptor to set payload length + send_size = sizeof(rsi_sntp_client_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending |= SNTP_RESPONSE_PENDING; + // send SNTP Get request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SNTP_CLIENT, pkt); + + } else { + // Return NWK command error + SL_PRINTF(SL_SNTP_CLIENT_DELETE_ASYNC_NWK_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_SNTP_CLIENT_DELETE_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_sntp_client.h b/wiseconnect/sapi/network/protocols/rsi_sntp_client.h new file mode 100644 index 00000000..434ba532 --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_sntp_client.h @@ -0,0 +1,68 @@ +/******************************************************************************* +* @file rsi_sntp_client.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_SNTP_CLIENT_H +#define RSI_SNTP_CLIENT_H +/****************************************************** + * * Macros + * ******************************************************/ +#ifndef RSI_IPV6 +#define RSI_IPV6 1 +#endif + +//SNTP Method to USe +#define RSI_SNTP_BROADCAST_MODE 1 + +//SNTP Method to USe +#define RSI_SNTP_UNICAST_MODE 2 + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ + +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_sntp_client_create_async(uint8_t flags, + uint8_t *server_ip, + uint8_t sntp_method, + uint16_t sntp_timeout, + void (*rsi_sntp_client_create_response_handler)(uint16_t status, + const uint8_t cmd_type, + const uint8_t *buffer)); +int32_t rsi_sntp_client_gettime(uint16_t length, uint8_t *sntp_time_rsp); +int32_t rsi_sntp_client_gettime_date(uint16_t length, uint8_t *sntp_time_date_rsp); +int32_t rsi_sntp_client_server_info(uint16_t length, uint8_t *sntp_server_response); +int32_t rsi_sntp_client_delete_async(void); +#endif diff --git a/wiseconnect/sapi/network/protocols/rsi_web_socket.c b/wiseconnect/sapi/network/protocols/rsi_web_socket.c new file mode 100644 index 00000000..919a12ed --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_web_socket.c @@ -0,0 +1,382 @@ +/******************************************************************************* +* @file rsi_web_socket.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" + +#include "rsi_wlan_non_rom.h" +#include "rsi_web_socket.h" +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create a web socket client. This is a blocking API. + * @param[in] flags - Select IP version and security \n + * BIT(0): RSI_IPV6 - Set this bit to enable IPv6, by default it is configured to IPv4 \n + * BIT(1): RSI_SSL_ENABLE - Set this bit to enable SSL feature \n + * @param[in] server_ip_addr - Web server IP address + * @param[in] server_port - Web server socket port + * @param[in] device_port - Local port + * @param[in] webs_resource_name - Web resource name + * @param[in] webs_host_name - Web host name + * @param[in] sockect_id - Socket ID + * @param[in] web_socket_data_receive_notify_callback - Callback when data packet is received on the created socket + * @param[out] sock_no - Application socket ID + * @param[out] buffer - Buffer pointer + * @param[out] length - Length of data + * @return 0 - Success \n + * @return Negative Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_web_socket_create(int8_t flags, + uint8_t *server_ip_addr, + uint16_t server_port, + uint16_t device_port, + uint8_t *webs_resource_name, + uint8_t *webs_host_name, + int32_t *socket_id, + void (*web_socket_data_receive_notify_callback)(uint32_t sock_no, + uint8_t *buffer, + uint32_t length)) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WEB_SOCKET_CREATE_ENTRY, NETWORK, LOG_INFO); + int32_t sockID, protocolFamily = 0, protocol = 0; + rsi_pkt_t *pkt = NULL; + rsi_req_socket_t *socket_create; + struct rsi_sockaddr_in server_addr, client_addr; + struct rsi_sockaddr_in6 server_addr_v6, client_addr_v6; + + // Check for invalid parameters + if ((web_socket_data_receive_notify_callback == NULL) || (server_ip_addr == NULL)) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check for IPv6 bit enable + if (flags & RSI_IPV6) { + protocolFamily = AF_INET6; + } else { + protocolFamily = AF_INET; + } + + // Check if SSL is enabled + if (flags & RSI_SSL_ENABLE) { + protocol |= RSI_SOCKET_FEAT_SSL; + } + + // Create socket + sockID = rsi_socket_async(protocolFamily, SOCK_STREAM, protocol, web_socket_data_receive_notify_callback); + if (sockID < 0) { + SL_PRINTF(SL_WEB_SOCKET_CREATE_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + *(int32_t *)socket_id = sockID; + + if (protocolFamily == AF_INET) { + // Memset client structure + memset(&client_addr, 0, sizeof(client_addr)); + + // Set family type + client_addr.sin_family = protocolFamily; + + // Set local port number + client_addr.sin_port = htons(device_port); + + // Bind socket + status = rsi_bind(sockID, (struct rsi_sockaddr *)&client_addr, sizeof(client_addr)); + } else if (protocolFamily == AF_INET6) { + + // Memset client structure + memset(&client_addr_v6, 0, sizeof(client_addr_v6)); + + // Set family type + client_addr_v6.sin6_family = protocolFamily; + + // Set local port number + client_addr_v6.sin6_port = htons(device_port); + + // Bind socket + status = rsi_bind(sockID, (struct rsi_sockaddr *)&client_addr_v6, sizeof(client_addr_v6)); + } + + if (status != RSI_SUCCESS) { + rsi_shutdown(sockID, 0); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_EXIT_1, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + if (protocolFamily == AF_INET) { + // Set server structure + memset(&server_addr, 0, sizeof(server_addr)); + + // Set server address family + server_addr.sin_family = protocolFamily; + + // Set server port number, using htons function to use proper byte order + server_addr.sin_port = htons(server_port); + + // Set IP address to localhost + memcpy((uint8_t *)&server_addr.sin_addr.s_addr, server_ip_addr, RSI_IPV4_ADDRESS_LENGTH); + } else if (protocolFamily == AF_INET6) { + // Set server structure + memset(&server_addr_v6, 0, sizeof(server_addr_v6)); + + // Set server address family + server_addr_v6.sin6_family = protocolFamily; + + // Set server port number, using htons function to use proper byte order + server_addr_v6.sin6_port = htons(server_port); + + // Set IP address to localhost + memcpy(server_addr_v6.sin6_addr.s6_addr, server_ip_addr, RSI_IPV6_ADDRESS_LENGTH); + } + if (webs_resource_name != NULL) { + // Check valid lengths + if (rsi_strlen(webs_resource_name) > RSI_WEBS_MAX_URL_LENGTH) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + if (webs_host_name != NULL) { + // Check valid lengths + if (rsi_strlen(webs_host_name) > RSI_WEBS_MAX_HOST_LENGTH) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + if (protocolFamily == AF_INET) { + // Save server IPv4 address + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv4, + (uint8_t *)&server_addr.sin_addr.s_addr, + RSI_IPV4_ADDRESS_LENGTH); + } else { + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv6, server_addr_v6.sin6_addr.s6_addr, RSI_IPV6_ADDRESS_LENGTH); + } + + rsi_socket_pool[sockID].destination_port = htons(server_port); + + // Get data pointer + socket_create = (rsi_req_socket_t *)pkt->data; + + // Memset before filling + memset(socket_create, 0, sizeof(rsi_req_socket_t)); + + // Fill IP verison and destination IP address + if ((rsi_socket_pool[sockID].sock_type >> 4) == AF_INET) { + rsi_uint16_to_2bytes(socket_create->ip_version, 4); + memcpy(socket_create->dest_ip_addr.ipv4_address, + rsi_socket_pool[sockID].destination_ip_addr.ipv4, + RSI_IPV4_ADDRESS_LENGTH); + } else { + rsi_uint16_to_2bytes(socket_create->ip_version, 6); + memcpy(socket_create->dest_ip_addr.ipv6_address, + rsi_socket_pool[sockID].destination_ip_addr.ipv6, + RSI_IPV6_ADDRESS_LENGTH); + } + + // Fill local port + rsi_uint16_to_2bytes(socket_create->module_socket, rsi_socket_pool[sockID].source_port); + + // Fill destination port + rsi_uint16_to_2bytes(socket_create->dest_socket, rsi_socket_pool[sockID].destination_port); + + // Fill socket type + rsi_uint16_to_2bytes(socket_create->socket_type, RSI_SOCKET_TCP_CLIENT); + + // Set max count to 0 + rsi_uint16_to_2bytes(socket_create->max_count, 0); + + // Set websocket support in socket information pool + rsi_socket_pool[sockID].sock_bitmap |= RSI_SOCKET_FEAT_WEBS_SUPPORT; + + // Set websocket support for the socket + socket_create->ssl_bitmap |= RSI_SOCKET_FEAT_WEBS_SUPPORT; + + if (webs_resource_name != NULL) { + // Copy webs resource name + rsi_strcpy(socket_create->webs_resource_name, webs_resource_name); + } + if (webs_host_name != NULL) { + // Copy webhost name + rsi_strcpy(socket_create->webs_host_name, webs_host_name); + } + // Check for SSL feature and fill it in SSL bitmap + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SSL) { + socket_create->ssl_bitmap |= RSI_SOCKET_FEAT_SSL; + } + + // Check for SYNCHRONOUS feature and fill it in socket bitmap + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SYNCHRONOUS) { + socket_create->socket_bitmap |= BIT(0); + } + + // Set waiting socket ID + rsi_driver_cb->wlan_cb->waiting_socket_id = sockID; + socket_create->vap_id = rsi_socket_pool_non_rom[sockID].vap_id; + +#ifdef CHIP_9117 + rsi_uint16_to_2bytes(socket_create->tos, RSI_TOS); + + // Configure SSL extended ciphers bitmap + socket_create->ssl_ext_ciphers_bitmap = RSI_SSL_EXT_CIPHERS; +#else + rsi_uint32_to_4bytes(socket_create->tos, RSI_TOS); +#endif + + // Configure SSL ciphers bitmap + socket_create->ssl_ciphers_bitmap = RSI_SSL_CIPHERS; + + if (rsi_socket_pool_non_rom[sockID].max_tcp_retries) { + socket_create->max_tcp_retries_count = rsi_socket_pool_non_rom[sockID].max_tcp_retries; + } else { + socket_create->max_tcp_retries_count = 10; + } + if (rsi_socket_pool_non_rom[sockID].tcp_keepalive_initial_time) { + memcpy(socket_create->tcp_keepalive_initial_time, rsi_socket_pool_non_rom[sockID].tcp_keepalive_initial_time, 2); + } else { + rsi_uint16_to_2bytes(socket_create->tcp_keepalive_initial_time, RSI_SOCKET_KEEPALIVE_TIMEOUT); + } + if (rsi_socket_pool_non_rom[sockID].ssl_bitmap) { + socket_create->ssl_bitmap = rsi_socket_pool_non_rom[sockID].ssl_bitmap; + } +#ifndef BSD_COMPATIBILITY + else if (socket_create->socket_bitmap & RSI_SOCKET_FEAT_SSL) { + socket_create->ssl_bitmap = rsi_wlan_cb_non_rom->tls_version; + } +#endif + if (rsi_socket_pool_non_rom[sockID].high_performance_socket) { + socket_create->ssl_bitmap |= RSI_HIGH_PERFORMANCE_SOCKET; + } + +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap |= BIT(0); +#endif + // Send socket create command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SOCKET_CREATE, pkt); + + // Wait on socket semaphore + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[sockID].socket_sem, RSI_SOCKET_CREATE_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + // Get WLAN/network command response status + rsi_wlan_socket_set_status(status, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Get WLAN/network command response status + status = rsi_wlan_socket_get_status(sockID); + if (status == RSI_SUCCESS) { + // Change state to connected + rsi_socket_pool[sockID].sock_state = RSI_SOCKET_STATE_CONNECTED; + SL_PRINTF(SL_WEB_SOCKET_CREATE_EXIT_2, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } else { + rsi_shutdown(sockID, 0); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_WEB_SOCKET_CREATE_EXIT9, NETWORK, LOG_INFO, "status: %4x", status); + return status; + } +} + +/*==============================================*/ +/** + * @brief Send data from the web socket client. This is a non-blocking API. + * @param[in] sockID - Application socket ID + * @param[in] opcode - Type of the packet to be included in web socket header + * @param[in] msg - Data + * @param[in] msg_length - Data length + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + */ + +int32_t rsi_web_socket_send_async(int32_t sockID, uint8_t opcode, int8_t *msg, int32_t msg_length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WEB_SOCKET_SEND_ASYNC_ENTRY, NETWORK, LOG_INFO); + // Set as final packet + rsi_socket_pool[sockID].opcode = opcode; + + // Call send API to send web socket data + status = rsi_send(sockID, msg, msg_length, 0); + SL_PRINTF(SL_WEB_SOCKET_SEND_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Close the web socket client. This is a non-blocking API. + * @param[in] sockID - Socket ID of particular socket + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API + */ +int32_t rsi_web_socket_close(int32_t sockID) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WEB_SOCKET_CLOSE_ENTRY, NETWORK, LOG_INFO); + // Web socket client socket close only sock id-based + status = rsi_shutdown(sockID, 0); + SL_PRINTF(SL_WEB_SOCKET_CLOSE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/sapi/network/protocols/rsi_web_socket.h b/wiseconnect/sapi/network/protocols/rsi_web_socket.h new file mode 100644 index 00000000..d582bfcf --- /dev/null +++ b/wiseconnect/sapi/network/protocols/rsi_web_socket.h @@ -0,0 +1,60 @@ +/******************************************************************************* +* @file rsi_web_socket.h +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_WEB_SOCKET_H +#define RSI_WEB_SOCKET_H + +/****************************************************** + * * Macros + * ******************************************************/ + +/****************************************************** + * * Constants + * ******************************************************/ +/****************************************************** + * * Enumerations + * ******************************************************/ +/****************************************************** + * * Type Definitions + * ******************************************************/ +/****************************************************** + * * Structures + * ******************************************************/ +/****************************************************** + * * Global Variables + * ******************************************************/ +/****************************************************** + * * Function Declarations + * ******************************************************/ +int32_t rsi_web_socket_create(int8_t flags, + uint8_t *server_ip_addr, + uint16_t server_port, + uint16_t device_port, + uint8_t *webs_resource_name, + uint8_t *webs_host_name, + int32_t *socket_id, + void (*web_socket_data_receive_notify_callback)(uint32_t sock_no, + uint8_t *buffer, + uint32_t length)); +int32_t rsi_web_socket_send_async(int32_t sockID, uint8_t opcode, int8_t *msg, int32_t msg_length); +int32_t rsi_web_socket_close(int32_t sockID); +#endif diff --git a/wiseconnect/sapi/network/socket/rsi_socket.c b/wiseconnect/sapi/network/socket/rsi_socket.c new file mode 100644 index 00000000..3aa9fa4d --- /dev/null +++ b/wiseconnect/sapi/network/socket/rsi_socket.c @@ -0,0 +1,4307 @@ +/******************************************************************************* +* @file rsi_socket.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_wlan_non_rom.h" +#ifdef RSI_M4_INTERFACE +#include "rsi_board.h" +#endif +#ifdef RSI_WLAN_ENABLE + +// Socket information pool pointer +rsi_socket_info_t *rsi_socket_pool; +rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; +extern rsi_socket_select_info_t *rsi_socket_select_info; + +/*==============================================*/ +/** + * @brief Checking input parameter is power of two or not. This is a non-blocking API. + * @param[in] x - value + * @return 1 - Success \n + * Zero,-1 - Failure + * + */ +int8_t is_power_of_two(int8_t x) +{ + if (x < 0) + return -1; + return x && (!(x & (x - 1))); +} + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Check for the bit for the file descriptor FD in the file descriptor set rsi_fd_set. This is a non-blocking API. + * @param[in] fd - Socket ID + * @param[in] fds_p - Pointer to the rsi_fd_set_s structure + * @return Positive Value - Success \n + * @return 0 - Failure + * + */ + +int rsi_fd_isset(uint32_t fd, struct rsi_fd_set_s *fds_p) +{ + uint32_t mask = 1 << (fd % 32); + SL_PRINTF(SL_FD_ISSET_ENTRY, NETWORK, LOG_INFO); + return fds_p->fd_array[fd / 32] & mask; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the bit for the file descriptor FD in the file descriptor set \ref rsi_fd_set. This is a non-blocking API. + * @param[in] fd - Socket id + * @param[in] fds_p - Pointer to the rsi_fd_set_structure + * @return Void + */ + +void rsi_set_fd(uint32_t fd, struct rsi_fd_set_s *fds_p) +{ + uint32_t mask = 1 << (fd % 32); + SL_PRINTF(SL_SET_FD_ENTRY, NETWORK, LOG_INFO); + fds_p->fd_array[fd / 32] |= mask; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Clear the bit for the file descriptor FD in the file descriptor set rsi_fd_set. This is a non-blocking API. + * @param[in] fd - Socket ID + * @param[in] fds_p - Pointer to the rsi_fd_set_s structure + * @return Void + */ + +void rsi_fd_clr(uint32_t fd, struct rsi_fd_set_s *fds_p) +{ + uint32_t mask = 1 << (fd % 32); + SL_PRINTF(SL_FD_CLR_ENTRY, NETWORK, LOG_INFO); + fds_p->fd_array[fd / 32] &= ~mask; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create a socket and register a callback that will be used by the driver to forward + * the received packets asynchronously to the application (on packet reception) without waiting for \ref rsi_recv() API call. + * This is a non-blocking API. + * @param[in] protocolFamily - Protocol family to select IPv4 or IPv6. \n + * AF_INET (2) : Select IPv4 \n + * AF_INET6 (3) : Select IPv6 + * @param[in] type - Select socket type UDP or TCP. \n + * SOCK_STREAM (1) : Select TCP \n + * SOCK_DGRM (2) : Select UDP + * @param[in] protocol - 0: Non SSL sockets \n + * 1: SSL sockets \n + * BIT(5) - Must be enabled to select the certificate index \n + * 0<<12 for index 0, \n + * 1<<12 for index 1 \n + * Note: Certificates must be loaded in to RAM to select the certificate index feature. + * @param[in] callback - Callback function to read data asynchronously from socket \n + * @param[out] sock_no - Application socket number \n + * @param[out] buffer - Pointer to buffer that holds data \n + * @param[out] length - Length of the buffer + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xFFF8, 0xFF80, 0xFF6D, 0xFF85, 0xBB33, 0xBB22) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_socket_async(int32_t protocolFamily, + int32_t type, + int32_t protocol, + void (*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length)) +{ + SL_PRINTF(SL_SOCKET_ASYNC_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_async_non_rom(protocolFamily, type, protocol, callback); +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create and return a socket instance. This is a non-blocking API. + * @param[in] protocolFamily - Protocol family to select IPv4 or IPv6. \n + * AF_INET (2): Select IPv4 \n + * AF_INET6 (3): Select IPv6 + * @param[in] type - Select socket type UDP or TCP. \n + * SOCK_STREAM (1): Select TCP\n + * TCP SOCK_DGRM (2): Select UDP + * @param[in] protocol - 0: Non SSL sockets \n + * 1: SSL sockets \n + * BIT(5) - Must be enabled to select the certificate index \n + * 0<<12 for index 0, \n + * 1<<12 for index 1 \n + * Note: Certificates must be loaded in to RAM to select the certificate index feature. + * @return SOCK_ID - Socket ID of the created socket \n + * @return Negative value - Failure (**Possible Error Codes** - 0xfffffffd) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * + */ + +int32_t rsi_socket(int32_t protocolFamily, int32_t type, int32_t protocol) +{ + SL_PRINTF(SL_SOCKET_ENTRY, NETWORK, LOG_INFO); +#ifndef BSD_COMPATIBILITY + if (protocol & BIT(0)) { + if (protocol & BIT(13)) { + rsi_wlan_cb_non_rom->tls_version = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_0); + } else if (protocol & BIT(14)) { + rsi_wlan_cb_non_rom->tls_version = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_1); + } else if (protocol & BIT(15)) { + rsi_wlan_cb_non_rom->tls_version = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_2); + } else { + rsi_wlan_cb_non_rom->tls_version = RSI_SOCKET_FEAT_SSL; + } + } +#endif + SL_PRINTF(SL_SOCKET_EXIT, NETWORK, LOG_INFO); + return rsi_socket_async_non_rom(protocolFamily, type, protocol, NULL); +} + +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Assign an address to a socket. This is a non-blocking API for TCP and a blocking API for UDP. + * @param[in] sockID - Socket descriptor ID + * @param[in] localAddress - Address assigned to the socket. The format is compatible with BSD socket + * @param[in] addressLength - Length of the address measured in bytes + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_socket() API needs to be called before this API. + * + * + * + * + */ +int32_t rsi_bind(int32_t sockID, struct rsi_sockaddr *localAddress, int32_t addressLength) +{ + SL_PRINTF(SL_BIND_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_bind(sockID, localAddress, addressLength); +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Connect the socket to the specified remote address. This is a non-blocking API, if socket_connect_response handler() is registered through rsi_wlan_register_callbacks(), otherwise it is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] remoteAddress - Remote peer address. The format is compatible with BSD socket. + * @param[in] addressLength - Length of the address in bytes + * @return 0 - Success \n + * Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_bind() API needs to be called before this API. + * @note For asynchronous behaviour, user need to register RSI_WLAN_SOCKET_CONNECT_NOTIFY_CB callback ID. + * + */ + +int32_t rsi_connect(int32_t sockID, struct rsi_sockaddr *remoteAddress, int32_t addressLength) +{ + SL_PRINTF(SL_CONNECT_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_connect(sockID, remoteAddress, addressLength); +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Enable socket to listen for a remote connection request in passive mode. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] backlog - Maximum length to which the queue of pending connections can be held. This argument is used when multiple client connections over the same server socket are required. \n + * If backlog parameter is issued, then rsi_accept or rsi_accept_async can accept those many client connections over the same server socket \n + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_bind() API needs to be called before this API. + * @note When using multiple client/server sockets, the following macros have to be updated in the wlan_config.h file, in TCP_IP_FEATURE_BIT_MAP - If TCP_IP_TOTAL_SOCKETS_x flag is used, then firmware allocates memory for x sockets. If TCP_IP_TOTAL_SOCKETS_x flag is not passed, then a default value of 10 sockets is used. + * @note When using multiple client/server sockets, the following macros have to be updated in the rsi_user.h file, RSI_NUMBER_OF_LTCP_SOCKETS -> Number of server sockets and RSI_NUMBER_OF_SOCKETS -> Number of client sockets + Number of server sockets. + * @note If multiple server sockets are created then the memory allocated for client sockets is to be shared across the multiple server sockets. If RSI_NUMBER_OF_LTCP_SOCKETS is 0 and RSI_NUMBER_OF_SOCKETS is x, y is server sockets and x-y client sockets can be created + */ + +int32_t rsi_listen(int32_t sockID, int32_t backlog) +{ + SL_PRINTF(SL_LISTEN_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_listen(sockID, backlog); +} +/*==============================================*/ +/** + * @brief Accept the connection request from the remote peer. This API extracts the connection request from the queue of pending connections on listening socket and accepts it. + * @param[in] sockID - Socket descriptor ID + * @param[in] ClientAddress - Remote peer address + * @param[in] addressLength - Length of the address measured in bytes + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + * + */ + +/// @private +int32_t rsi_accept_non_rom(int32_t sockID, struct rsi_sockaddr *ClientAddress, int32_t *addressLength) +{ + struct rsi_sockaddr_in peer4_address; + struct rsi_sockaddr_in6 peer6_address; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ACCEPT_NON_ROM_ENTRY, NETWORK, LOG_INFO); + rsi_req_socket_accept_t *accept; + rsi_pkt_t *pkt = NULL; + rsi_socket_info_t *sock_info; + int8_t accept_sock_id = -1; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check if socket is TCP or not + if ((rsi_socket_pool[sockID].sock_type & 0xF) != SOCK_STREAM) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EPROTOTYPE, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EPROTOTYPE); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is not binded + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_LISTEN) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_EXIT5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (rsi_socket_pool[sockID].ltcp_socket_type != RSI_LTCP_PRIMARY_SOCKET) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EINVAL, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + sock_info = &rsi_socket_pool[sockID]; + + // Check maximum backlogs count + if (sock_info->backlogs == sock_info->backlog_current_count) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ENOBUFS, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOBUFS); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_LISTEN) { + // Create a new instance for socket + accept_sock_id = rsi_socket_async((sock_info->sock_type >> 4), + (sock_info->sock_type & 0xF), + (sock_info->sock_bitmap), + sock_info->sock_receive_callback); + + if ((accept_sock_id >= 0) && (accept_sock_id < NUMBER_OF_SOCKETS)) { + + // Set socket as secondary socket + rsi_socket_pool[accept_sock_id].ltcp_socket_type = RSI_LTCP_SECONDARY_SOCKET; + + // Save local port number + rsi_socket_pool[accept_sock_id].source_port = rsi_socket_pool[sockID].source_port; + } else { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_8, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + + // Allocate packet + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_9, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Send socket accept command + accept = (rsi_req_socket_accept_t *)pkt->data; + + // Fill socket descriptor + accept->socket_id = rsi_socket_pool[sockID].sock_id; + + // Fill local port number + rsi_uint16_to_2bytes(accept->source_port, rsi_socket_pool[sockID].source_port); + +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[accept_sock_id].socket_wait_bitmap |= BIT(0); +#endif + + // Send socket accept command + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_SOCKET_ACCEPT, pkt); + + // Wait on socket semaphore + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[accept_sock_id].socket_sem, RSI_ACCEPT_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + // Get WLAN/network command response status + rsi_wlan_socket_set_status(status, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_10, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Get WLAN/network command response status + status = rsi_wlan_socket_get_status(accept_sock_id); + if (status != RSI_SUCCESS) { +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_ACCEPT_NON_ROM_SOCK_ERROR_11, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Check status, fill out params with remote peer address details if successful and return status + if (status == RSI_SUCCESS) { + // Copy remote peer IP address + if (ClientAddress && *addressLength != 0) { + // Handle the IPv4 socket type + if ((rsi_socket_pool[accept_sock_id].sock_type >> 4) == AF_INET) { + + // Update the client address with socket family, remote host IPv4 address, and port + peer4_address.sin_family = AF_INET; + memcpy(&peer4_address.sin_addr.s_addr, + (ntohl(rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv4)), + RSI_IPV4_ADDRESS_LENGTH); + peer4_address.sin_port = ntohs((uint16_t)rsi_socket_pool[accept_sock_id].destination_port); + + // Copy the peer address/port info to the ClientAddress. + // Truncate if addressLength is smaller than the size of struct rsi_sockaddr_in + if (*addressLength > (int32_t)sizeof(struct rsi_sockaddr_in)) + *addressLength = sizeof(struct rsi_sockaddr_in); + } + memcpy(ClientAddress, &peer4_address, *addressLength); + } else if ((rsi_socket_pool[accept_sock_id].sock_type >> 4) == AF_INET6) { + peer6_address.sin6_family = AF_INET6; + peer6_address.sin6_port = ntohs((uint16_t)rsi_socket_pool[accept_sock_id].destination_port); + //! To avoid compiler warning replace uint32_t with uintptr_t + /*peer6_address.sin6_addr._S6_un._S6_u32[0] = + (uint32_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[0]); + peer6_address.sin6_addr._S6_un._S6_u32[1] = + (uint32_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[4]); + peer6_address.sin6_addr._S6_un._S6_u32[2] = + (uint32_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[8]); + peer6_address.sin6_addr._S6_un._S6_u32[3] = + (uint32_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[12]);*/ + //! To avoid compiler warning replace uint32_t with uintptr_t + peer6_address.sin6_addr._S6_un._S6_u32[0] = + (uintptr_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[0]); + peer6_address.sin6_addr._S6_un._S6_u32[1] = + (uintptr_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[4]); + peer6_address.sin6_addr._S6_un._S6_u32[2] = + (uintptr_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[8]); + peer6_address.sin6_addr._S6_un._S6_u32[3] = + (uintptr_t)ntohl(&rsi_socket_pool[accept_sock_id].destination_ip_addr.ipv6[12]); + + if ((*addressLength) > (int32_t)sizeof(struct rsi_sockaddr_in6)) { + *addressLength = sizeof(struct rsi_sockaddr_in6); + } + + memcpy(ClientAddress, &peer6_address, *addressLength); + } + } + + // Increase backlog current count + rsi_socket_pool[sockID].backlog_current_count++; + + // Return status + SL_PRINTF(SL_ACCEPT_NON_ROM_EXIT, NETWORK, LOG_INFO); + return accept_sock_id; +} + +/** @} */ +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Accept the connection request from the remote peer. This API extracts the connection request from the queue of pending connections on listening socket and accepts it. This is a blocking API. + * @param[in] sockID - Socket descriptor + * @param[in] ClientAddress - Remote peer address + * @param[in] addressLength - Length of the address measured in bytes + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_listen() API needs to be called before this API. + * + * + */ +int32_t rsi_accept(int32_t sockID, struct rsi_sockaddr *ClientAddress, int32_t *addressLength) +{ + SL_PRINTF(SL_ACCEPT_ENTRY, NETWORK, LOG_INFO); + return rsi_accept_non_rom(sockID, ClientAddress, addressLength); +} + +/*==============================================*/ +/** + * @brief Receive large data on a given socket synchronously + * @param[in] sockID - Socket descriptor + * @param[in] buffer - Pointer to buffer to hold receive data + * @param[in] requested_length - Requested buffer length + * @param[in] flags - Reserved + * @param[in] fromAddr - Address of remote peer, from where current packet was received + * @param[in] fromAddrLen - Pointer that contains remote peer address (fromAddr) length + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + */ +/// @private +#ifdef RSI_PROCESS_MAX_RX_DATA +int32_t rsi_recv_large_data_sync(int32_t sockID, + int8_t *buffer, + int32_t requested_length, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen) +{ + SL_PRINTF(SL_RECV_LARGE_DATA_SYNC_ENTRY, NETWORK, LOG_INFO); + int32_t status = 0; + int32_t chunk_size = 0; + int32_t rem_len = 0; + int32_t offset = 0; + int32_t maximum_length = 0; + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED) { + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_RECV_LARGE_DATA_SYNC_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (requested_length > RX_DATA_LENGTH) { + rem_len = RX_DATA_LENGTH; + } else { + rem_len = requested_length; + } + if ((requested_length > MAX_RX_DATA_LENGTH) +#ifdef CHIP_9117B0 + && (!(rsi_socket_pool_non_rom[sockID].ssl_bitmap)) +#endif + ) { + maximum_length = MAX_RX_DATA_LENGTH; + } else { + maximum_length = requested_length; + } + do { + rsi_socket_pool_non_rom[sockID].more_rx_data_pending = 0; + chunk_size = MIN(maximum_length, rem_len); + status = rsi_socket_recvfrom(sockID, buffer + offset, chunk_size, flags, fromAddr, fromAddrLen); + if (status < 0) { + status = rsi_wlan_socket_get_status(sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + break; + } else { + rem_len -= status; + offset += status; + } + } while (rem_len && rsi_socket_pool_non_rom[sockID].more_rx_data_pending); + SL_PRINTF(SL_RECV_LARGE_DATA_SYNC_EXIT, NETWORK, LOG_INFO, "offset: %4x", offset); + return offset; +} +#endif +/** @} */ +/** @addtogroup NETWORK5 +* @{ +*/ + +/*==============================================*/ +/** + * @brief Retrieve the received data from the remote peer on a given socket descriptor. This is a blocking API. + * @param[in] sockID - Socket descriptor + * @param[in] buffer - Pointer to buffer to hold receive data + * @param[in] buffersize - Size of the buffer supplied + * @param[in] flags - Reserved + * @param[in] fromAddr - Address of remote peer, from where current packet was received + * @param[in] fromAddrLen - Pointer that contains remote peer address (fromAddr) length + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + * + */ + +int32_t rsi_recvfrom(int32_t sockID, + int8_t *buffer, + int32_t buffersize, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen) +{ + SL_PRINTF(SL_RECV_FROM_ENTRY, NETWORK, LOG_INFO); + + if ((buffersize == 0) || (buffer == NULL)) { + rsi_wlan_socket_set_status(RSI_ERROR_EINVAL, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + return RSI_SOCK_ERROR; + } +#ifdef RSI_PROCESS_MAX_RX_DATA + if (rsi_socket_pool[sockID].sock_type & SOCK_STREAM) { + SL_PRINTF(SL_RECV_FROM_EXIT_1, NETWORK, LOG_INFO); + return rsi_recv_large_data_sync(sockID, buffer, buffersize, flags, fromAddr, fromAddrLen); + } else { + SL_PRINTF(SL_RECV_FROM_EXIT_2, NETWORK, LOG_INFO); + return rsi_socket_recvfrom(sockID, buffer, buffersize, flags, fromAddr, fromAddrLen); + } +#else + SL_PRINTF(SL_RECV_FROM_EXIT_3, NETWORK, LOG_INFO); + return rsi_socket_recvfrom(sockID, buffer, buffersize, flags, fromAddr, fromAddrLen); +#endif +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Retrieve the data from the remote peer on a specified socket. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] rcvBuffer - Pointer to the buffer to hold the data received from the remote peer + * @param[in] bufferLength - Length of the buffer + * @param[in] flags - Reserved + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + * @note **Precondition (TCP client)** - \ref rsi_connect() API needs to be called before this API. + * @note **Precondition (TCP server)** - \ref rsi_listen() and \ref rsi_accept() API needs to be called before this API. + * @note **Precondition (UDP server)** - \ref rsi_bind() API needs to be called before this API. + * @note **Precondition (UDP client)** - \ref rsi_socket() or \ref rsi_bind() API needs to be called before this API + * + * + */ +int32_t rsi_recv(int32_t sockID, void *rcvBuffer, int32_t bufferLength, int32_t flags) +{ + SL_PRINTF(SL_RECV_ENTRY, NETWORK, LOG_INFO); + int32_t fromAddrLen = 0; + if ((bufferLength == 0) || (rcvBuffer == NULL)) { + rsi_wlan_socket_set_status(RSI_ERROR_EINVAL, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + return RSI_SOCK_ERROR; + } +#ifdef RSI_PROCESS_MAX_RX_DATA + if (rsi_socket_pool[sockID].sock_type & SOCK_STREAM) { + SL_PRINTF(SL_RECV_EXIT_1, NETWORK, LOG_INFO); + return rsi_recv_large_data_sync(sockID, rcvBuffer, bufferLength, flags, NULL, &fromAddrLen); + } else { + SL_PRINTF(SL_RECV_EXIT_2, NETWORK, LOG_INFO); + return rsi_socket_recvfrom(sockID, rcvBuffer, bufferLength, flags, NULL, &fromAddrLen); + } +#else + SL_PRINTF(SL_RECV_EXIT_3, NETWORK, LOG_INFO); + return rsi_socket_recvfrom(sockID, rcvBuffer, bufferLength, flags, NULL, &fromAddrLen); +#endif +} + +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send data to the specified remote IP Address on the given socket. This is non-blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to data buffer containing data to send to remote peer + * @param[in] msgLength - Length of the buffer + * @param[in] flags - Reserved + * @param[in] destAddr - Address of the remote peer to send data + * @param[in] destAddrLen - Length of the address in bytes + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + * @note **Precondition (TCP client)** - \ref rsi_connect() API needs to be called before this API. + * @note **Precondition (TCP server)** - \ref rsi_listen() and \ref rsi_accept() API needs to be called before this API. + * @note **Precondition (UDP server)** - \ref rsi_bind() API needs to be called before this API. + * @note **Precondition (UDP client)** - \ref rsi_socket() or \ref rsi_bind() API needs to be called before this API + * @note The following table lists the maximum individual chunk of data that can be sent over each supported protocol. + + | Protocol | Maximum data chunk (bytes) | + |---------------------|----------------------------| + | TCP/LTCP socket | 1460 | + | LUDP socket | 1472 | + | Web socket | 1450 | + | TCP-SSL/LTCP-SSL | 1370 | + | Web socket over SSL | 1362 | + * + * + */ + +int32_t rsi_sendto(int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen) +{ + SL_PRINTF(SL_SENDTO_ENTRY, NETWORK, LOG_INFO); + return rsi_sendto_async_non_rom(sockID, msg, msgLength, flags, destAddr, destAddrLen, NULL); +} + +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send the data to the specified remote IP Address on the given socket and receive the acknowledgement through the registered call back. This is non-blocking API + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to data buffer containing data to send to remote peer + * @param[in] msgLength - Length of data to send + * @param[in] flags - Reserved + * @param[in] destAddr - Address of the remote peer to send data + * @param[in] destAddrLen - Length of the address in bytes + * @param[in] data_transfer_complete_handler - Pointer to callback function called after complete data transfer + * @param[out] length - Number of bytes transfered + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + * @note The following table lists the maximum individual chunk of data that can be sent over each supported protocol. + + | Protocol | Maximum data chunk (bytes) | + |---------------------|----------------------------| + | TCP/LTCP socket | 1460 | + | LUDP socket | 1472 | + | Web socket | 1450 | + | TCP-SSL/LTCP-SSL | 1370 | + | Web socket over SSL | 1362 | + * + * @note The data_transfer_complete_handler callback handler is supported only for TCP data transfer. This handler is supported only when RSI_WLAN_RSP_TCP_ACK_INDICATION feature is enabled in socket_feature_bitmap. + */ +/// @private +int32_t rsi_sendto_async(int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen, + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length)) +{ + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_ENTRY, NETWORK, LOG_INFO); + return rsi_sendto_async_non_rom(sockID, msg, msgLength, flags, destAddr, destAddrLen, data_transfer_complete_handler); +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Sends the data to the remote peer on the given socket. This is a non-blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to the buffer containing data to send to the remote peer + * @param[in] msgLength - Length of the buffer + * @param[in] flags - Reserved + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + * @note **Precondition** - \ref rsi_connect()/ \ref rsi_accept() API needs to be called before this API. + * @note The following table lists the maximum individual chunk of data that can be sent over each supported protocol. + + | Protocol | Maximum data chunk (bytes) | + |---------------------|----------------------------| + | TCP/LTCP socket | 1460 | + | LUDP socket | 1472 | + | Web socket | 1450 | + | TCP-SSL/LTCP-SSL | 1370 | + | Web socket over SSL | 1362 | + * + * + */ + +int32_t rsi_send(int32_t sockID, const int8_t *msg, int32_t msgLength, int32_t flags) +{ + SL_PRINTF(SL_SEND_ENTRY, NETWORK, LOG_INFO); +#ifdef RSI_UART_INTERFACE + rsi_wlan_cb_non_rom->rsi_uart_data_ack_check = sockID; +#endif +#ifdef LARGE_DATA_SYNC + SL_PRINTF(SL_SEND_EXIT_1, NETWORK, LOG_INFO); + return rsi_send_large_data_sync(sockID, msg, msgLength, flags); +#else + SL_PRINTF(SL_SEND_EXIT_2, NETWORK, LOG_INFO); + return rsi_send_async_non_rom(sockID, msg, msgLength, flags, NULL); +#endif +} + +#ifndef RSI_M4_INTERFACE + +/*==============================================*/ +/** + * @brief Reset all the socket related information + * @param[in] sockID - Socket descriptor ID + * @return Void + * + */ + +/// @private +void rsi_reset_per_socket_info(int32_t sockID) +{ + SL_PRINTF(SL_RESET_PER_SOCKET_INFO_ENTRY, NETWORK, LOG_INFO); + rsi_socket_info_non_rom_t *rsi_sock_info_non_rom_p = &rsi_socket_pool_non_rom[sockID]; + rsi_sock_info_non_rom_p->more_data = 0; + rsi_sock_info_non_rom_p->offset = 0; + rsi_sock_info_non_rom_p->buffer = 0; + rsi_sock_info_non_rom_p->rem_len = 0; + // Reset socket_bitmap + rsi_wlan_cb_non_rom->socket_bitmap &= ~BIT(sockID); + rsi_sock_info_non_rom_p->rsi_sock_data_tx_done_cb = NULL; +} + +/*==============================================*/ +/** + * @brief Send large data on a given socket synchronously. + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to data that needs to be sent to remote peer + * @param[in] msgLength - Length of data to send + * @param[in] flags - Reserved + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ + +/// @private +int32_t rsi_send_large_data_sync(int32_t sockID, const int8_t *msg, int32_t msgLength, int32_t flags) +{ + SL_PRINTF(SL_SEND_LARGE_DATA_SYNC_ENTRY, NETWORK, LOG_INFO); + int32_t status = 0; + int32_t chunk_size = 0; + int32_t rem_len = msgLength; + int32_t offset = 0; + int8_t *buffer = (int8_t *)msg; + int32_t maximum_length = 0; + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SEND_LARGE_DATA_SYNC_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Find maximum limit based on the protocol + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) { + // If it is a UDP socket + maximum_length = 1472; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && ((rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SSL) + || (rsi_socket_pool_non_rom[sockID].ssl_bitmap))) { + // If it is an SSL socket/SSL websocket + maximum_length = rsi_socket_pool_non_rom[sockID].mss - RSI_SSL_HEADER_SIZE; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_WEBS_SUPPORT)) { + // If it is a websocket + maximum_length = 1450; + } else { + maximum_length = rsi_socket_pool_non_rom[sockID].mss; + } + + while (rem_len) { + chunk_size = MIN(maximum_length, rem_len); + // Send next chunk of data and return the total data sent in successful case + status = rsi_send_async(sockID, buffer + offset, chunk_size, flags, NULL); + if (status < 0) { + status = rsi_wlan_socket_get_status(sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + break; + } else { + rem_len -= status; + offset += status; + } + } + SL_PRINTF(SL_SEND_LARGE_DATA_SYNC_EXIT, NETWORK, LOG_INFO, "offset: %4x", offset); + return offset; +} + +/*==============================================*/ +/** + * @brief Send one chunk of data at a time + * @param[in] sockID - Socket descriptor ID + * @param[in] length - Length of data to send + * @return Void + * + */ + +/// @private +void rsi_chunk_data_tx_done_cb(int32_t sockID, const uint16_t length) +{ + SL_PRINTF(SL_CHUNK_DATA_TX_DONE_CB_ENTRY, NETWORK, LOG_INFO); + UNUSED_CONST_PARAMETER(length); // Added to resolve compilation warning, value is unchanged + int16_t status = 0; + uint16_t total_data_sent, chunk_size = 0; + rsi_socket_info_non_rom_t *rsi_sock_info_non_rom_p = &rsi_socket_pool_non_rom[sockID]; + int32_t maximum_length = 0; + + // Find maximum limit based on the protocol + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) { + // If it is a UDP socket + maximum_length = 1472; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && ((rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SSL) + || (rsi_socket_pool_non_rom[sockID].ssl_bitmap))) { + // If it is an SSL socket/SSL websocket + maximum_length = rsi_socket_pool_non_rom[sockID].mss - RSI_SSL_HEADER_SIZE; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_WEBS_SUPPORT)) { + // If it is a websocket + maximum_length = 1450; + } else { + maximum_length = rsi_socket_pool_non_rom[sockID].mss; + } + + if (rsi_sock_info_non_rom_p->rem_len) { +#ifndef WISEMCU + // Mask the socket event + rsi_mask_event(RSI_SOCKET_EVENT); +#endif + rsi_sock_info_non_rom_p->more_data = 1; + chunk_size = MIN(maximum_length, rsi_sock_info_non_rom_p->rem_len); + // Send next chunk of data and return the total data sent in successful case + status = rsi_send_async(sockID, + rsi_sock_info_non_rom_p->buffer + rsi_sock_info_non_rom_p->offset, + chunk_size, + rsi_sock_info_non_rom_p->flags, + rsi_chunk_data_tx_done_cb); + if (status < 0) { + status = rsi_wlan_socket_get_status(sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + total_data_sent = rsi_sock_info_non_rom_p->offset; + if (status != RSI_TX_BUFFER_FULL) { + if (rsi_sock_info_non_rom_p->rsi_sock_data_tx_done_cb != NULL) { + rsi_sock_info_non_rom_p->rsi_sock_data_tx_done_cb(sockID, status, total_data_sent); + } + rsi_reset_per_socket_info(sockID); + } + } else { + rsi_sock_info_non_rom_p->rem_len -= status; + rsi_sock_info_non_rom_p->offset += status; + } +#ifndef WISEMCU + // Unmask the socket event + rsi_unmask_event(RSI_SOCKET_EVENT); +#endif + } else // In case total data is sent + { + total_data_sent = rsi_sock_info_non_rom_p->offset; + if (rsi_sock_info_non_rom_p->rsi_sock_data_tx_done_cb != NULL) { + rsi_sock_info_non_rom_p->rsi_sock_data_tx_done_cb(sockID, RSI_SUCCESS, total_data_sent); + } + rsi_reset_per_socket_info(sockID); + if (rsi_wlan_cb_non_rom->socket_bitmap == 0) { +#ifndef WISEMCU + // Clear the socket event + rsi_clear_event(RSI_SOCKET_EVENT); +#endif + } + } +} + +/*==============================================*/ +/** + * @brief Send large data on a given socket. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to data that needs to be sent to remote peer + * @param[in] msgLength - Length of data to send + * @param[in] flags - Reserved + * @param[in] rsi_sock_data_tx_done_cb - Pointer to the callback function that will be called after one chunk of data transfer completion + * @param[out] sockID - Application socket ID + * @param[out] status - Status of the data transfer + * @param[out] total_data_sent - Total length of data sent + * + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ + +int32_t rsi_send_large_data_async(int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*rsi_sock_data_tx_done_cb)(int32_t sockID, + int16_t status, + uint16_t total_data_sent)) +{ + SL_PRINTF(SL_SEND_LARGE_DATA_ASYNC_ENTRY, NETWORK, LOG_INFO); + int32_t status = 0; + uint16_t chunk_size = 0; + rsi_socket_info_non_rom_t *rsi_sock_info_non_rom_p = &rsi_socket_pool_non_rom[sockID]; + int32_t maximum_length = 0; + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Check if the socket is already doing data transfer, if so, return busy + if ((rsi_wlan_cb_non_rom->socket_bitmap & BIT(sockID))) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EEXIST); +#endif + SL_PRINTF(SL_SEND_LARGE_DATA_ASYNC_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Find maximum limit based on the protocol + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) { + // If it is a UDP socket + maximum_length = 1472; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && ((rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SSL) + || (rsi_socket_pool_non_rom[sockID].ssl_bitmap))) { + // If it is an SSL socket/SSL websocket + maximum_length = rsi_socket_pool_non_rom[sockID].mss - RSI_SSL_HEADER_SIZE; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_WEBS_SUPPORT)) { + // If it is a websocket + maximum_length = 1450; + } else { + maximum_length = rsi_socket_pool_non_rom[sockID].mss; + } + + chunk_size = MIN(maximum_length, msgLength); + rsi_sock_info_non_rom_p->rsi_sock_data_tx_done_cb = rsi_sock_data_tx_done_cb; + rsi_sock_info_non_rom_p->buffer = (int8_t *)msg; + rsi_sock_info_non_rom_p->flags = flags; + rsi_wlan_cb_non_rom->socket_bitmap |= BIT(sockID); + // Return total num of bytes sent in successful case + status = rsi_send_async(sockID, rsi_sock_info_non_rom_p->buffer, chunk_size, flags, rsi_chunk_data_tx_done_cb); + // If chunk of data is not sent, no need to update the values + if (status < 0) { + status = rsi_wlan_socket_get_status(sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + rsi_reset_per_socket_info(sockID); + SL_PRINTF(SL_SEND_LARGE_DATA_ASYNC_EXIT_1, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } else // In case of BUFFER FULL condition, no need to update the values + { + rsi_sock_info_non_rom_p->rem_len = msgLength - status; + rsi_sock_info_non_rom_p->offset = status; + // Set the socket event + rsi_set_event(RSI_SOCKET_EVENT); + } + SL_PRINTF(SL_SEND_LARGE_DATA_ASYNC_EXIT_2, NETWORK, LOG_INFO); + return RSI_SUCCESS; +} + +/*==============================================*/ +/** + * @brief Find on which socket the data is pending, according to the event that is set from the event map + * @param[in] event_map - Event map + * @return Socket ID from the event map + * + */ + +/// @private +uint32_t rsi_find_socket_data_pending(uint32_t event_map) +{ + SL_PRINTF(SL_FIND_SOCKET_DATA_PENDING_ENTRY, NETWORK, LOG_INFO); + uint8_t i; + for (i = 0; i < RSI_NUMBER_OF_SOCKETS; i++) { + if (event_map & BIT(i)) { + break; + } + } + SL_PRINTF(SL_FIND_SOCKET_DATA_PENDING_EXIT, NETWORK, LOG_INFO); + return i; +} + +/*==============================================*/ +/** + * @brief Retrieve the packet from TX data pending queue and forward to the module + * @param[in] Void + * @return Void + * + * + */ + +/// @private +void rsi_socket_event_handler(void) +{ + SL_PRINTF(SL_SOCKET_EVENT_HANDLER_ENTRY, NETWORK, LOG_INFO); + int32_t sockID = 0; + + if (rsi_wlan_cb_non_rom->socket_bitmap) { + sockID = rsi_find_socket_data_pending(rsi_wlan_cb_non_rom->socket_bitmap); + + rsi_chunk_data_tx_done_cb(sockID, 0); + } else { + rsi_clear_event(RSI_SOCKET_EVENT); + } +} +/** @} */ + +#endif +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Send data on a given socket asynchronously. + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to the buffer containing data to send to the remote peer + * @param[in] msgLength - Length of the buffer + * @param[in] flags - Reserved + * @param[in] data_transfer_complete_handler - Pointer to callback function called after complete data transfer + * @param[out] sockID - Socket Descriptor ID + * @param[out] length - Number of bytes transfered + * @return Number of bytes received successfully – Success + * @return Negative value – Failure + * @return 0 – Socket close error + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + * @note The following table lists the maximum individual chunk of data that can be sent over each supported protocol. + + | Protocol | Maximum data chunk (bytes) | + |---------------------|----------------------------| + | TCP/LTCP socket | 1460 | + | LUDP socket | 1472 | + | Web socket | 1450 | + | TCP-SSL/LTCP-SSL | 1370 | + | Web socket over SSL | 1362 | + * @note The data_transfer_complete_handler callback handler is supported only for TCP data transfer. This handler is supported only when RSI_WLAN_RSP_TCP_ACK_INDICATION feature is enabled in socket_feature_bitmap. + */ +/// @private +int32_t rsi_send_async(int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length)) +{ + SL_PRINTF(SL_SEND_ASYNC_ENTRY, NETWORK, LOG_INFO); + return rsi_send_async_non_rom(sockID, msg, msgLength, flags, data_transfer_complete_handler); +} + +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Closes the socket specified in the socket descriptor. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] how - 0: Close the specified socket \n + * 1: Close all the sockets open on a specified socket's source port number + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + * + */ +int32_t rsi_shutdown(int32_t sockID, int32_t how) +{ + SL_PRINTF(SL_SEND_ASYNC_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_shutdown(sockID, how); +} +/** @} */ + +/** @addtogroup WLAN +* @{ +*/ +/*==============================================*/ +/** + * @brief Check if the WLAN is in IP Config state + * @param[in] type - Socket family type + * @return 0 - Success: IP config state \n + * @return Negative value - Failure: -20 (0xffffffec) - Not in IP config state + * + */ +/// @private +int32_t rsi_check_state(int32_t type) +{ + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + + if (rsi_driver_cb->wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + if (RSI_CHECK_WLAN_STATE() != RSI_WLAN_STATE_CONNECTED) { + return RSI_ERROR_NOT_IN_IPCONFIG_STATE; + } + } else { + if (type == AF_INET) { + if (RSI_CHECK_WLAN_STATE() != RSI_WLAN_STATE_IP_CONFIG_DONE) { + return RSI_ERROR_NOT_IN_IPCONFIG_STATE; + } + } else { + if (RSI_CHECK_WLAN_STATE() != RSI_WLAN_STATE_IPV6_CONFIG_DONE) { + return RSI_ERROR_NOT_IN_IPCONFIG_STATE; + } + } + } + return RSI_SUCCESS; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the application socket descriptor from module socket descriptor. + * @param[in] sock_id - Module's socket descriptor ID + * @return Positive Value - Success (Application socket descriptor) \n + * @return Negative Value - Failure (If module’s socket descriptor is not found) + * + */ +/// @private +int32_t rsi_get_application_socket_descriptor(int32_t sock_id) +{ + SL_PRINTF(SL_GET_APPLICATON_SOCKET_DESCRIPTOR_ENTRY, NETWORK, LOG_INFO); + return rsi_application_socket_descriptor(sock_id); +} + +/*==============================================*/ +/** + * @brief Clear socket information + * @param[in] sockID - Socket descriptor ID + * @return Void + * + */ +/// @private +void rsi_clear_sockets(int32_t sockID) +{ + SL_PRINTF(SL_CLEAR_SOCKETS_ENTRY, NETWORK, LOG_INFO); + rsi_clear_sockets_non_rom(sockID); +} + +/*==============================================*/ +/** + * @brief Configure TLS extensions + * @param[in] sockID - Socket descriptor ID + * @param[in] extension_type - Type of TLS extension + * @param[in] option_value - TLS extension data + * @param[in] extension_len - TLS extension data length + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * + **/ +/// @private +int rsi_fill_tls_extension(int32_t sockID, int extension_type, const void *option_value, rsi_socklen_t extension_len) +{ + SL_PRINTF(SL_FILL_TLS_EXTENSION_ENTRY, NETWORK, LOG_INFO); + rsi_tls_tlv_t *tls_extension = NULL; + + if ((rsi_socket_pool_non_rom[sockID].extension_offset + extension_len + sizeof(rsi_tls_tlv_t)) + > MAX_SIZE_OF_EXTENSION_DATA) { + SL_PRINTF(SL_FILL_TLS_EXTENSION_INSUFFICIENT_BUFFER, NETWORK, LOG_ERROR); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + if (extension_type == SO_TLS_SNI) { + extension_type = RSI_TLS_SNI; + } + + tls_extension = (rsi_tls_tlv_t *)&rsi_socket_pool_non_rom[sockID] + .tls_extension_data[rsi_socket_pool_non_rom[sockID].extension_offset]; + tls_extension->type = extension_type; + tls_extension->length = extension_len; + rsi_socket_pool_non_rom[sockID].extension_offset += sizeof(rsi_tls_tlv_t); + memcpy(&rsi_socket_pool_non_rom[sockID].tls_extension_data[rsi_socket_pool_non_rom[sockID].extension_offset], + option_value, + extension_len); + rsi_socket_pool_non_rom[sockID].extension_offset += extension_len; + rsi_socket_pool_non_rom[sockID].no_of_tls_extensions++; + SL_PRINTF(SL_FILL_TLS_EXTENSION_EXIT, NETWORK, LOG_INFO); + return RSI_SUCCESS; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the socket options. This is a non-blocking API. + * @pre \ref rsi_setsockopt() API needs to be called after rsi_socket command only. + * @param[in] sockID - Socket descriptor ID + * @param[in] level - Set the socket option, take the socket level + * @param[in] option_name - Provide the name of the ID. \n + * 1.SO_MAX_RETRY - Select TCP max retry count \n + * 2.SO_SOCK_VAP_ID - Select the VAP id \n + * 3.SO_TCP_KEEP_ALIVE - Configure the TCP keep alive initial time \n + * 4.SO_RCVBUF - Configure the application buffer for receiving server certificate \n + * 5.SO_SSL_ENABLE-Configure SSL socket \n + * 6.SO_HIGH_PERFORMANCE_SOCKET-Configure high performance socket \n + * 7.IP_TOS - Configure the type of service value [0-7] + * | TOS | Value Description | + * |-----|---------------------------------------------------------------------------| + * | 0 | Best Effort | + * | 1 | Priority | + * | 2 | Immediate | + * | 3 | Flash-mainly used for voice signaling | + * | 4 | Flash Override | + * | 5 | Critical - mainly used for voice RTP (Real-time Tranlocal_port Protocol) | + * | 6 | Internet | + * | 7 | Network | + * + * @param[in] option_value - Value of the parameter + * @param[in] option_len - Length of the parameter + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe, 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_socket() API needs to be called before this API. + * @note Default window size is 2920 bytes. To modify window size, user need to configure HIGH_PERFORMANCE socket as option_name in rsi_setsockopt() API + * + */ + +int rsi_setsockopt(int32_t sockID, int level, int option_name, const void *option_value, rsi_socklen_t option_len) +{ + SL_PRINTF(SL_SETSOCKOPT_ENTRY, NETWORK, LOG_INFO); + struct rsi_timeval *timeout = NULL; + int32_t status = RSI_SUCCESS; + uint16_t timeout_val; + uint32_t protocol; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If sockID is not in available range + if (sockID < 0 || sockID >= RSI_NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Configure per socket maximum TCP retries count + if ((option_name == SO_MAXRETRY)) { + rsi_socket_pool_non_rom[sockID].max_tcp_retries = *(uint8_t *)option_value; + SL_PRINTF(SL_SETSOCKOPT_EXIT_1, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure TCP keep alive time + if ((option_name == SO_TCP_KEEP_ALIVE)) { + rsi_uint16_to_2bytes(rsi_socket_pool_non_rom[sockID].tcp_keepalive_initial_time, *(uint16_t *)option_value); + SL_PRINTF(SL_SETSOCKOPT_EXIT_2, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure SSL socket bit map + if ((option_name == SO_SSL_ENABLE)) { + rsi_socket_pool_non_rom[sockID].ssl_bitmap = RSI_SOCKET_FEAT_SSL; + SL_PRINTF(SL_SETSOCKOPT_EXIT_3, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure SSL socket bit map with 1.0 version + if ((option_name == SO_SSL_V_1_0_ENABLE)) { + rsi_socket_pool_non_rom[sockID].ssl_bitmap = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_0); + SL_PRINTF(SL_SETSOCKOPT_EXIT_4, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure SSL socket bit map with 1.1 version + if ((option_name == SO_SSL_V_1_1_ENABLE)) { + rsi_socket_pool_non_rom[sockID].ssl_bitmap = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_1); + SL_PRINTF(SL_SETSOCKOPT_EXIT_5, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure SSL socket bit map with 1.2 version + if ((option_name == SO_SSL_V_1_2_ENABLE)) { + rsi_socket_pool_non_rom[sockID].ssl_bitmap = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_2); + SL_PRINTF(SL_SETSOCKOPT_EXIT_6, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure ssl socket bit map with 1.3 version +#ifdef CHIP_9117 + if ((option_name == SO_SSL_V_1_3_ENABLE)) { + rsi_socket_pool_non_rom[sockID].ssl_bitmap = (RSI_SOCKET_FEAT_SSL | RSI_SSL_V_1_3); + SL_PRINTF(SL_SETSOCKOPT_EXIT_7, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } +#endif + + // Configure tcp ack indication + if ((option_name == SO_TCP_ACK_INDICATION)) { + if (*(uint32_t *)option_value) { + protocol = *(uint32_t *)option_value; + } else { + protocol = RSI_SOCKET_FEAT_TCP_ACK_INDICATION; + } + rsi_socket_pool[sockID].sock_bitmap |= RSI_SOCKET_FEAT_TCP_ACK_INDICATION; + if (((protocol >> 3) & 0XF) == 0) { + rsi_socket_pool[sockID].max_available_buffer_count = rsi_socket_pool[sockID].current_available_buffer_count = 4; + } else { + rsi_socket_pool[sockID].max_available_buffer_count = rsi_socket_pool[sockID].current_available_buffer_count = + ((protocol >> 3) & 0xF); + } + SL_PRINTF(SL_SETSOCKOPT_EXIT_8, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure certificate index bit map + if ((option_name == SO_CERT_INDEX)) { + if (*(uint32_t *)option_value) { + protocol = *(uint32_t *)option_value; + } else { + protocol = 0; + } + // Set certificate index bit + rsi_socket_pool[sockID].sock_bitmap |= RSI_SOCKET_FEAT_CERT_INDEX; + + rsi_socket_pool[sockID].socket_cert_inx = protocol; + SL_PRINTF(SL_SETSOCKOPT_EXIT_9, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure high performance socket + if ((option_name == SO_HIGH_PERFORMANCE_SOCKET)) { + rsi_socket_pool_non_rom[sockID].high_performance_socket = 1; + SL_PRINTF(SL_SETSOCKOPT_EXIT_10, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + if ((option_name == SO_SOCK_VAP_ID)) { + rsi_socket_pool_non_rom[sockID].vap_id = *(uint8_t *)option_value; + SL_PRINTF(SL_SETSOCKOPT_EXIT_11, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + // Configure the TCP MSS size + if (option_name == SO_TCP_MSS) { + rsi_socket_pool_non_rom[sockID].tcp_mss = *(uint16_t *)option_value; + SL_PRINTF(SL_SETSOCKOPT_EXIT_12, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // Configure the TCP MSS size + if (option_name == SO_TCP_RETRY_TRANSMIT_TIMER) { + rsi_socket_pool_non_rom[sockID].tcp_retry_transmit_timer = *(uint8_t *)option_value; + SL_PRINTF(SL_SETSOCKOPT_EXIT_13, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } +#ifdef CHIP_9117 + //! Configure max_retransmission_timeout_value + if (option_name == SO_MAX_RETRANSMISSION_TIMEOUT_VAL) { + status = is_power_of_two(*(int8_t *)option_value); + if ((status == 1) && !((*(int8_t *)option_value) > MAX_RETRANSMISSION_TIME_VALUE)) { + rsi_socket_pool_non_rom[sockID].max_retransmission_timeout_value = *(int8_t *)option_value; + SL_PRINTF(SL_SETSOCKOPT_EXIT_14, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } else { + LOG_PRINT( + "\n Max retransmission timeout value in between 1 - 32 and should be power of two. ex:1,2,4,8,16,32 \n"); + SL_PRINTF(SL_SETSOCKOPT_EXIT_15, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + } +#endif +#ifndef RSI_M4_INTERFACE + if ((option_name == SO_RCVBUF)) { + rsi_socket_pool[sockID].recv_buffer = (uint8_t *)option_value; + rsi_socket_pool[sockID].recv_buffer_length = option_len; + SL_PRINTF(SL_SETSOCKOPT_EXIT_16, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } +#endif + if (option_name == SO_TLS_SNI) { + status = rsi_fill_tls_extension(sockID, option_name, option_value, option_len); + if (status != RSI_SUCCESS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); + +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SETSOCKOPT_EXIT_17, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_SETSOCKOPT_EXIT_18, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + + // For TOS + if (option_name == IP_TOS) { +#ifdef CHIP_9117 + rsi_socket_pool_non_rom[sockID].tos = *(uint16_t *)option_value; +#else + rsi_socket_pool_non_rom[sockID].tos = *(uint32_t *)option_value; +#endif + SL_PRINTF(SL_SETSOCKOPT_EXIT_19, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } +#ifdef CHIP_9117B0 + if (option_name == SO_SSL_RECV_BUFF_SIZE) { + if ((*(uint16_t *)option_value) > RSI_SSL_RECV_BUFFER_LENGTH) { + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + rsi_socket_pool_non_rom[sockID].ssl_buff_len = *(uint16_t *)option_value; + SL_PRINTF(SL_SETSOCKOPT_EXIT_20, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } +#endif + if ((option_name != SO_RCVTIMEO) || (level != SOL_SOCKET)) { + rsi_wlan_socket_set_status(RSI_ERROR_EINVAL, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // If socket is in not created state + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); + +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + if (option_name == SO_RCVTIMEO) { + timeout = (struct rsi_timeval *)option_value; + if ((timeout->tv_sec == 0) && (timeout->tv_usec != 0) && (timeout->tv_usec < 1000)) { + timeout->tv_usec = 1000; + } + timeout_val = (timeout->tv_usec / 1000) + (timeout->tv_sec * 1000); + + // This feature is available only if Synchrounous bit map is set + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SYNCHRONOUS) { + rsi_socket_pool[sockID].read_time_out = timeout_val; + } else { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ENOPROTOOPT, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOPROTOOPT); +#endif + SL_PRINTF(SL_SETSOCKOPT_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + + SL_PRINTF(SL_SETSOCKOPT_EXIT21, NETWORK, LOG_INFO); + return RSI_SUCCESS; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the socket options. This is a non-blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] level - Set the socket option, take the socket level + * @param[in] option_name - Provide the name of the ID + * @param[in] option_value - Value of the parameter + * @param[in] option_len - Length of the parameter + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_socket() API needs to be called before this API. + */ + +int rsi_getsockopt(int32_t sockID, int level, int option_name, const void *option_value, rsi_socklen_t option_len) +{ + SL_PRINTF(SL_GETSOCKOPT_EXIT1, NETWORK, LOG_INFO); + UNUSED_PARAMETER(level); //Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(option_value); //Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(option_len); //Added to resolve compilation warning, value is unchanged +#ifdef RSI_WITH_OS + int32_t status = 0; +#endif + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_GETSOCKOPT_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_GETSOCKOPT_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // If sockID is not in available range + if (sockID < 0 || sockID >= RSI_NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_GETSOCKOPT_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if ((option_name == SO_CHECK_CONNECTED_STATE)) { + // If socket is in not created state + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED) { + // Set error + rsi_wlan_socket_get_status(sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_GETSOCKOPT_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + SL_PRINTF(SL_GETSOCKOPT_EXIT, NETWORK, LOG_ERROR); + return RSI_SUCCESS; +} + +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Monitor multiple socket (file descriptors), waiting until one or more of the sockets become ready to perform receive or send operation. + * If callback is NULL or not provided, it is a blocking API. \n + * Otherwise, it is a non-blocking API + * @param[in] nfds - The highest-numbered file descriptor in any of the three sets, plus 1 + * @param[in] readfds - Socket descriptors to watch to see if data become available for receive + * @param[in] writefds - Socket descriptors to watch to see if space is available in socket to send data. + * @param[in] exceptfds - Socket descriptors to watch for exception + * @param[in] Timeout - Timeout value to break the wait for select. + * If both fields of the timeval structure are zero, then select() returns immediately. + * (This is useful for polling). If timeout is NULL (no timeout), rsi_select() can block indefinitely. + * @param[in] callback - Callback called when asynchronous response reach the select request. + * @param[out] fd_read - Pointer that holds bitmap for the select on read operation + * @param[out] fd_write - Pointer that holds bitmap for the select on write operation + * @param[out] fd_except - Pointer that holds bitmap for the select on exceptional operation + * @param[out] status - Status code + * @return Positive Value - Indicate total number of bits ready across all the descriptor sets \n + * @return 0 - Time out \n \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_accept()/ \ref rsi_connect() API's needs to be called before this API. + * @note **Precondition** - This API needs to be called before \ref rsi_recv()/ \ref rsi_recvfrom()/ \ref rsi_send() API's. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_select(int32_t nfds, + rsi_fd_set *readfds, + rsi_fd_set *writefds, + rsi_fd_set *exceptfds, + struct rsi_timeval *timeout, + void (*callback)(rsi_fd_set *fd_read, rsi_fd_set *fd_write, rsi_fd_set *fd_except, int32_t status)) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SELECT_ENTRY, NETWORK, LOG_INFO); + rsi_req_socket_select_t *select; + rsi_pkt_t *pkt = NULL; + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + uint32_t read_select_bitmap = 0, write_select_bitmap = 0; + int8_t socket_desc = 0; + int8_t index = 0; + int i, read_count = 0, write_count = 0; + int32_t rsi_select_response_wait_time = 0; +#ifdef SOCKET_CLOSE_WAIT + rsi_fd_set rfds, wfds; + RSI_FD_ZERO(&rfds); + RSI_FD_ZERO(&wfds); +#endif + // If NFDS is not in available range + if (nfds < 0 || nfds > NUMBER_OF_SOCKETS) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (nfds > 0) { + if ((readfds != NULL) && (readfds->fd_array[0] == 0)) { + SL_PRINTF(SL_SELECT_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if ((writefds != NULL) && (writefds->fd_array[0] == 0)) { + SL_PRINTF(SL_SELECT_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + RSI_MUTEX_LOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + for (i = 0; i < RSI_NUMBER_OF_SELECTS; i++) { + if (rsi_socket_select_info[i].select_state == RSI_SOCKET_SELECT_STATE_INIT) { + for (index = 0; index < nfds; index++) { + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool_non_rom[index].close_pending) { + if ((readfds != NULL) && (readfds->fd_array[0]) & BIT(index)) { + read_count += 1; + RSI_FD_SET(index, &rfds); + } + if ((writefds != NULL) && (writefds->fd_array[0]) & BIT(index)) { + write_count += 1; + RSI_FD_SET(index, &wfds); + } + } +#endif + + if (readfds != NULL) { + if (((readfds->fd_array[0]) & BIT(index)) + && (rsi_socket_pool[index].sock_state < RSI_SOCKET_STATE_CONNECTED)) { + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + if (writefds != NULL) { + if (((writefds->fd_array[0]) & BIT(index)) + && ((rsi_socket_pool[index].sock_state < RSI_SOCKET_STATE_CONNECTED) + && (!rsi_socket_pool_non_rom[index].sock_non_block))) { + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + } +#ifdef SOCKET_CLOSE_WAIT + if (read_count + write_count) { + if (readfds != NULL) { + readfds->fd_array[0] = rfds.fd_array[0]; + } + if (writefds != NULL) { + writefds->fd_array[0] = wfds.fd_array[0]; + } + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + SL_PRINTF(SL_SELECT_SOCK_ERROR_6, NETWORK, LOG_INFO, "Total count %d", read_count + write_count); + return read_count + write_count; + } +#endif + memset(&rsi_socket_select_info[i], 0, sizeof(rsi_socket_select_info_t)); + if (!callback) { + status = rsi_semaphore_create(&rsi_socket_select_info[i].select_sem, 0); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOMEM); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + // Allocate packet + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOMEM); +#endif + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + SL_PRINTF(SL_SELECT_SOCK_ERROR_8, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + rsi_socket_select_info[i].select_state = RSI_SOCKET_SELECT_STATE_CREATE; + // Memset before filling + select = (rsi_req_socket_select_t *)pkt->data; + memset(select, 0, sizeof(rsi_req_socket_select_t)); + + // Update bitmap with the sock ids + for (index = 0; index < nfds; index++) { + if (readfds != NULL) { + if ((readfds->fd_array[0]) & BIT(index)) { + socket_desc = rsi_socket_pool[index].sock_id; + read_select_bitmap |= BIT(socket_desc); + } + } + if (writefds != NULL) { + if ((writefds->fd_array[0]) & BIT(index)) { + socket_desc = rsi_socket_pool[index].sock_id; + write_select_bitmap |= BIT(socket_desc); + } + } + } + // Save address to a pointer variable to access + if (callback == NULL) { + if (readfds != NULL) { + rsi_socket_select_info[i].rsi_sel_read_fds = (rsi_fd_set *)readfds; + } + if (writefds != NULL) { + rsi_socket_select_info[i].rsi_sel_write_fds = (rsi_fd_set *)writefds; + } + } + // Fill the select req struct + select->num_fd = nfds; + if (readfds != NULL) { + select->rsi_read_fds.fd_array[0] = read_select_bitmap; + } + if (writefds != NULL) { + select->rsi_write_fds.fd_array[0] = write_select_bitmap; + } + select->select_id = i; + + if (timeout != NULL) { + select->rsi_select_timeval.tv_sec = timeout->tv_sec; + select->rsi_select_timeval.tv_usec = timeout->tv_usec; + rsi_select_response_wait_time = + ((select->rsi_select_timeval.tv_sec * 1000) + (select->rsi_select_timeval.tv_usec / 1000) + WAIT_TIMEOOUT + + RSI_SELECT_RESPONSE_WAIT_TIME); + } else { + select->no_timeout = 1; + rsi_select_response_wait_time = 0; + } + if (callback) { + // Set socket asynchronous receive callback + rsi_socket_select_info[i].sock_select_callback = callback; + } + break; + } + } + // If NFDS is not in available range + if (i >= RSI_NUMBER_OF_SELECTS) { + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_9, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_SELECT_REQUEST, pkt); + if (!callback) { + if (rsi_wait_on_socket_semaphore(&rsi_socket_select_info[i].select_sem, (rsi_select_response_wait_time)) + != RSI_ERROR_NONE) { + rsi_select_set_status(RSI_ERROR_RESPONSE_TIMEOUT, i); + rsi_semaphore_destroy(&rsi_socket_select_info[i].select_sem); + return RSI_SOCK_ERROR; + } + // Free packet + status = rsi_semaphore_destroy(&rsi_socket_select_info[i].select_sem); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_10, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Clear the except FD set + if (exceptfds != NULL) { + RSI_FD_ZERO(exceptfds); + } + rsi_socket_select_info[i].select_state = RSI_SOCKET_SELECT_STATE_INIT; + } + status = rsi_select_get_status(i); + if (status == RSI_SUCCESS) { + if (readfds != NULL) { + // Return value of count + read_count = readfds->fd_count; + } + if (writefds != NULL) { + write_count = writefds->fd_count; + } + return read_count + write_count; + } else { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_SELECT_SOCK_ERROR_11, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +} + +/*==============================================*/ +/** + * @brief Calculate the buffers required. + * @param[in] type - Type + * @param[in] length - Length + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + * + */ +/// @private +uint8_t calculate_buffers_required(uint8_t type, uint16_t length) +{ +#ifdef ROM_WIRELESS + return ROMAPI_WL->calculate_buffers_required(global_cb_p, type, length); +#else + return api_wl->calculate_buffers_required(global_cb_p, type, length); +#endif +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Accept the connection request from the remote peer and register a callback that will be used by + * the driver to forward the received connection request asynchronously to the application. This is a non-blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] callback - Callback function to indicate the socket parameters connected + * @param[out] sock_id - Socket descriptor ID + * @param[out] dest_port - Port number of remote peer + * @param[out] ip_addr - Remote peer address + * @param[out] ip_version - 4 - IPV4. \n 6 - IPV6 + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note When attempting to connect multiple clients to the server socket opened on module, i.e., when the backlog parameter is used in rsi_listen() API. rsi_accept_async() has to be called again for each of the client connections. \n + * The API calling has to be repeated for the next client connection, only after the connection process of the previous client is complete. + * @note When using multiple client/server sockets, the following macros have to be updated in the wlan_config.h file, in TCP_IP_FEATURE_BIT_MAP - If TCP_IP_TOTAL_SOCKETS_x flag is used, then firmware allocates memory for x sockets. If TCP_IP_TOTAL_SOCKETS_x flag is not passed, then a default value of 10 sockets is used. + * @note When using multiple client/server sockets, the following macros have to be updated in the rsi_user.h file, RSI_NUMBER_OF_LTCP_SOCKETS -> Number of server sockets and RSI_NUMBER_OF_SOCKETS -> Number of client sockets + Number of server sockets. + * @note If multiple server sockets are created then the memory allocated for client sockets is to be shared across the multiple server sockets. If RSI_NUMBER_OF_LTCP_SOCKETS is 0 and RSI_NUMBER_OF_SOCKETS is x, y is server sockets and x-y client sockets can be created + */ + +int32_t rsi_accept_async(int32_t sockID, + void (*callback)(int32_t sock_id, int16_t dest_port, uint8_t *ip_addr, int16_t ip_version)) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_ACCEPT_ASYNC_ENTRY, NETWORK, LOG_INFO); + rsi_req_socket_accept_t *accept; + rsi_pkt_t *pkt = NULL; + rsi_socket_info_t *sock_info; + int8_t accept_sock_id = -1; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check if socket is TCP or not + if ((rsi_socket_pool[sockID].sock_type & 0xF) != SOCK_STREAM) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EPROTOTYPE, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EPROTOTYPE); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is not in listen state and connected state + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_LISTEN) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (rsi_socket_pool[sockID].ltcp_socket_type != RSI_LTCP_PRIMARY_SOCKET) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EINVAL, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EINVAL); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + sock_info = &rsi_socket_pool[sockID]; + + // Check maximum backlogs count + if (sock_info->backlogs == sock_info->backlog_current_count) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ENOBUFS, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOBUFS); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_LISTEN) { + // Create a new instance for socket + accept_sock_id = rsi_socket_async((sock_info->sock_type >> 4), + (sock_info->sock_type & 0xF), + (sock_info->sock_bitmap & RSI_SOCKET_FEAT_SSL), + sock_info->sock_receive_callback); + + if ((accept_sock_id >= 0) && (accept_sock_id < NUMBER_OF_SOCKETS)) { + + // Set socket as secondary socket + rsi_socket_pool[accept_sock_id].ltcp_socket_type = RSI_LTCP_SECONDARY_SOCKET; + + // Save local port number + rsi_socket_pool[accept_sock_id].source_port = rsi_socket_pool[sockID].source_port; + } else { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_8, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + + // Allocate packet + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_9, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Set socket connection indication callback + rsi_socket_pool_non_rom[accept_sock_id].accept_call_back_handler = callback; + + // Send socket accept command + accept = (rsi_req_socket_accept_t *)pkt->data; + + // Fill socket descriptor + accept->socket_id = rsi_socket_pool[sockID].sock_id; + + // Fill local port number + rsi_uint16_to_2bytes(accept->source_port, rsi_socket_pool[sockID].source_port); + + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending |= BIT(accept_sock_id); + // Send socket accept command + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_SOCKET_ACCEPT, pkt); + + if (status != RSI_SUCCESS) { +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_ACCEPT_ASYNC_SOCK_ERROR_10, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Return status + SL_PRINTF(SL_ACCEPT_ASYNC_EXIT, NETWORK, LOG_INFO); + return accept_sock_id; +} + +/*==============================================*/ +/** + * @brief Get the application socket descriptor from source port + * @param[in] src_port - Pointer to the socket source port + * @return Positive Value - Application socket descriptor \n + * @return Negative Value - If socket is not found + * + */ +/// @private +int32_t rsi_get_app_socket_descriptor(uint8_t *src_port) +{ + SL_PRINTF(SL_GET_APP_SOCKET_DESCRIPTOR_ENTRY, NETWORK, LOG_INFO); + int i; + uint16_t source_port; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + source_port = rsi_bytes2R_to_uint16(src_port); + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if ((rsi_socket_pool[i].source_port == source_port) && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_CONNECTED) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_LISTEN)) { + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + SL_PRINTF(SL_GET_APP_SOCKET_DESCRIPTOR_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_GET_APP_SOCKET_DESCRIPTOR_EXIT, NETWORK, LOG_INFO, "i:%d ", i); + return i; +} +/*==============================================*/ +/** + * @brief Get the socket ID from port number + * @param[in] src_port - Socket source port number + * @param[in] dst_port - Socket destination port number + * @return Positive Value - Socket descriptor \n + * @return Negative Value - If socket is not found + */ +/// @private +int32_t rsi_get_socket_id(uint32_t src_port, uint32_t dst_port) +{ + UNUSED_PARAMETER(dst_port); //This statement is added only to resolve compilation warning, value is unchanged + SL_PRINTF(SL_GET_SOCKET_ID_ENTRY, NETWORK, LOG_INFO); + int i; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool[i].source_port == src_port) { + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + SL_PRINTF(SL_GET_SOCKET_ID_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_GET_SOCKET_ID_EXIT, NETWORK, LOG_INFO, "i:%d ", i); + return i; +} +/*==============================================*/ +/** + * @brief Get the primary socket ID from port number + * @param[in] port_num - Pointer to port number + * @return Positive Value - Socket descriptor \n + * @return Negative Value - If socket is not found + * + */ +/// @private +int32_t rsi_get_primary_socket_id(uint8_t *port_num) +{ + SL_PRINTF(SL_GET_PRIMARY_SOCKET_ID_ENTRY, NETWORK, LOG_INFO); + int i; + uint16_t port_number; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + port_number = rsi_bytes2R_to_uint16(port_num); + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if ((rsi_socket_pool[i].source_port == port_number) + && (rsi_socket_pool[i].ltcp_socket_type == RSI_LTCP_PRIMARY_SOCKET)) { + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + SL_PRINTF(SL_GET_PRIMARY_SOCKET_ID_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_GET_PRIMARY_SOCKET_ID_EXIT, NETWORK, LOG_INFO, "i:%d ", i); + return i; +} +/** @} */ + +#ifndef RSI_M4_INTERFACE +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Validate the server certificate received from the module. This is a non-blocking API. + * @param[in] valid - Indicate whether the server certificate is valid or not. \n + * 1 - Indicate that the server certificate is valid. \n + * 0 - Indicate that the server certificate is not valid + * @param[in] socket_id - Socket identifier + * @return 0 - Success \n + * @return Negative Value - Failure + */ + +int32_t rsi_certificate_valid(uint16_t valid, uint16_t socket_id) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_CERTIFICATE_VALID_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt = NULL; + rsi_req_cert_valid_t *cert_valid; + int32_t sockID = 0; + sockID = rsi_get_application_socket_descriptor(socket_id); +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_CERTIFICATE_VALID_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_CERTIFICATE_VALID_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Allocate packet + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, socket_id); + SL_PRINTF(SL_CERTIFICATE_VALID_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + rsi_driver_cb_non_rom->socket_state = RSI_SOCKET_CMD_IN_PROGRESS; + + cert_valid = (rsi_req_cert_valid_t *)pkt->data; + + cert_valid->socket_id = socket_id; + cert_valid->status = valid; + + // Send cert valid command + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_CERT_VALID, pkt); + SL_PRINTF(SL_CERTIFICATE_VALID_EXIT, NETWORK, LOG_INFO, "status : %4x", status); + return status; +} +#endif + +/*==============================================*/ +/** + * @brief Send socket create request to the module and receive the response asynchronously. This is a non-blocking API if socket_connect_response_handler is registered. \n + * Otherwise it is a blocking API. + * @param[in] global_cb_p - Pointer to the global control block + * @param[in] sockID - Socket descriptor ID + * @param[in] type - Type of socket to create + * @param[in] backlog - Number of backlogs for LTCP socket + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_connect() API needs to be called before this API. + * + */ + +int32_t rsi_socket_create_async(int32_t sockID, int32_t type, int32_t backlog) +{ + SL_PRINTF(SL_SOCKET_CREATE_ASYNC_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt = NULL; + rsi_req_socket_t *socket_create; + int32_t status = 0; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_1, NETWORK, LOG_INFO); + return RSI_SOCK_ERROR; + } +#endif + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); + SL_PRINTF(SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Socket Parameters + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); + SL_PRINTF(SL_SOCKET_CREATE_ASYNC_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Get data pointer + socket_create = (rsi_req_socket_t *)pkt->data; + + // Memset before filling + memset(socket_create, 0, sizeof(rsi_req_socket_t)); + + // Fill IP verison and destination IP address + if ((rsi_socket_pool[sockID].sock_type >> 4) == AF_INET) { + rsi_uint16_to_2bytes(socket_create->ip_version, 4); + memcpy(socket_create->dest_ip_addr.ipv4_address, + rsi_socket_pool[sockID].destination_ip_addr.ipv4, + RSI_IPV4_ADDRESS_LENGTH); + } else { + rsi_uint16_to_2bytes(socket_create->ip_version, 6); + memcpy(socket_create->dest_ip_addr.ipv6_address, + rsi_socket_pool[sockID].destination_ip_addr.ipv6, + RSI_IPV6_ADDRESS_LENGTH); + } + + // Fill local port + rsi_uint16_to_2bytes(socket_create->module_socket, rsi_socket_pool[sockID].source_port); + + // Fill destination port + rsi_uint16_to_2bytes(socket_create->dest_socket, rsi_socket_pool[sockID].destination_port); + + // Fill socket type + rsi_uint16_to_2bytes(socket_create->socket_type, type); + + // Set backlogs + if (type == RSI_SOCKET_TCP_SERVER) { + rsi_uint16_to_2bytes(socket_create->max_count, backlog); + socket_create->socket_bitmap |= RSI_SOCKET_FEAT_LTCP_ACCEPT; + } else { + rsi_uint16_to_2bytes(socket_create->max_count, 0); + } + + if (rsi_socket_pool_non_rom[sockID].sock_non_block) { + type = (type | O_NONBLOCK); + rsi_uint16_to_2bytes(socket_create->socket_type, type); + } + // Check for SSL feature and fill it in SSL bitmap + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SSL) { + socket_create->ssl_bitmap |= RSI_SOCKET_FEAT_SSL; + } + + // Check for SYNCHRONOUS feature and fill it in socket bitmap + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SYNCHRONOUS) { + socket_create->socket_bitmap |= BIT(0); + } + + // Check TCP ACK indication bit + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_TCP_ACK_INDICATION) { + socket_create->socket_bitmap |= RSI_SOCKET_FEAT_TCP_ACK_INDICATION; + } + // Check TCP socket certificate index bit + if (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_CERT_INDEX) { + socket_create->socket_bitmap |= RSI_SOCKET_FEAT_CERT_INDEX; + } + + socket_create->socket_bitmap |= RSI_SOCKET_FEAT_TCP_RX_WINDOW; + + // Set the RX window size + socket_create->rx_window_size = rsi_socket_pool[sockID].rx_window_buffers; + + // Get certificate index + socket_create->socket_cert_inx = rsi_socket_pool[sockID].socket_cert_inx; + + // Fill VAP_ID + socket_create->vap_id = RSI_VAP_ID; + + socket_create->vap_id = rsi_socket_pool_non_rom[sockID].vap_id; + if (rsi_socket_pool_non_rom[sockID].tos) { +#ifdef CHIP_9117 + rsi_uint16_to_2bytes(socket_create->tos, rsi_socket_pool_non_rom[sockID].tos); +#else + rsi_uint32_to_4bytes(socket_create->tos, rsi_socket_pool_non_rom[sockID].tos); +#endif + } else { +#ifdef CHIP_9117 + rsi_uint16_to_2bytes(socket_create->tos, RSI_TOS); +#else + rsi_uint32_to_4bytes(socket_create->tos, RSI_TOS); +#endif + } + if (rsi_socket_pool_non_rom[sockID].max_tcp_retries) { + socket_create->max_tcp_retries_count = rsi_socket_pool_non_rom[sockID].max_tcp_retries; + } else { + socket_create->max_tcp_retries_count = 10; + } + if (*(uint16_t *)rsi_socket_pool_non_rom[sockID].tcp_keepalive_initial_time) { + memcpy(socket_create->tcp_keepalive_initial_time, rsi_socket_pool_non_rom[sockID].tcp_keepalive_initial_time, 2); + } else { + rsi_uint16_to_2bytes(socket_create->tcp_keepalive_initial_time, RSI_SOCKET_KEEPALIVE_TIMEOUT); + } + if (rsi_socket_pool_non_rom[sockID].ssl_bitmap) { + socket_create->ssl_bitmap = rsi_socket_pool_non_rom[sockID].ssl_bitmap; + } +#ifndef BSD_COMPATIBILITY + if (rsi_wlan_cb_non_rom->tls_version & RSI_SOCKET_FEAT_SSL) { + socket_create->ssl_bitmap |= rsi_wlan_cb_non_rom->tls_version; + rsi_wlan_cb_non_rom->tls_version = 0; + } +#endif + if (rsi_socket_pool_non_rom[sockID].high_performance_socket) { + socket_create->ssl_bitmap |= RSI_HIGH_PERFORMANCE_SOCKET; + } + + // Configure SSL extended ciphers bitmap +#ifdef CHIP_9117 + socket_create->ssl_ext_ciphers_bitmap = RSI_SSL_EXT_CIPHERS; +#endif + + // Configure SSL ciphers bitmap + socket_create->ssl_ciphers_bitmap = RSI_SSL_CIPHERS; +#ifdef CHIP_9117 + if (rsi_socket_pool_non_rom[sockID].ssl_bitmap) { + socket_create->recv_buff_len = rsi_socket_pool_non_rom[sockID].ssl_buff_len; + } +#endif + + if (rsi_socket_pool_non_rom[sockID].tcp_mss) { + socket_create->tcp_mss = rsi_socket_pool_non_rom[sockID].tcp_mss; + } + if (rsi_socket_pool_non_rom[sockID].tcp_retry_transmit_timer) { + socket_create->tcp_retry_transmit_timer = rsi_socket_pool_non_rom[sockID].tcp_retry_transmit_timer; + } + +#ifdef CHIP_9117 + //! Copy max_retransmission_timeout_value + if (rsi_socket_pool_non_rom[sockID].max_retransmission_timeout_value) { + socket_create->max_retransmission_timeout_value = rsi_socket_pool_non_rom[sockID].max_retransmission_timeout_value; + } +#endif + + if (!(rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler != NULL)) { +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap |= BIT(0); +#endif + } else { + rsi_wlan_cb_non_rom->socket_cmd_rsp_pending |= BIT(sockID); + } + + if (rsi_socket_pool_non_rom[sockID].extension_offset) { + socket_create->no_of_tls_extensions = rsi_socket_pool_non_rom[sockID].no_of_tls_extensions; + socket_create->total_extension_length = rsi_socket_pool_non_rom[sockID].extension_offset; + memcpy(socket_create->tls_extension_data, + rsi_socket_pool_non_rom[sockID].tls_extension_data, + MAX_SIZE_OF_EXTENSION_DATA); + } + // Send socket create command + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_SOCKET_CREATE, pkt); + if (rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler != NULL) { + // In case of ssl certificate bypass connect behaves as asynchronous cmd for ssl sockets + rsi_wlan_socket_set_status(RSI_SUCCESS, sockID); + } else { + // Wait on socket semaphore + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[sockID].socket_sem, RSI_SOCKET_CREATE_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + // Get WLAN/network command response status + rsi_wlan_socket_set_status(status, sockID); + return RSI_SOCK_ERROR; + } + // Get WLAN/network command response status + status = rsi_wlan_socket_get_status(sockID); + } + SL_PRINTF(SL_SOCKET_CREATE_ASYNC_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup NETWORK16 +* @{ +*/ +/*==============================================*/ +/** + * @brief Update TCP window size from host. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] new_size_bytes - Window size to update in bytes + * @return Positive Value - Window size updated \n + * Negative Value - Failure + * @note **Precondition** - \ref rsi_connect() API needs to be called before this API. + * + */ + +int32_t rsi_tcp_window_update(uint32_t sockID, uint32_t new_size_bytes) +{ + SL_PRINTF(SL_TCP_WINDOW_UPDATE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt = NULL; + rsi_req_tcp_window_update_t *tcp_window_update; + int32_t status = 0; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + if (rsi_socket_pool_non_rom[sockID].socket_terminate_indication) { + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Get data pointer + tcp_window_update = (rsi_req_tcp_window_update_t *)pkt->data; + + // Memset before filling + memset(tcp_window_update, 0, sizeof(rsi_req_tcp_window_update_t)); + tcp_window_update->socket_id = rsi_socket_pool[sockID].sock_id; + tcp_window_update->window_size = new_size_bytes; + +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap |= BIT(0); +#endif + + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_UPDATE_TCP_WINDOW, pkt); + + // Wait on socket semaphore + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[sockID].socket_sem, RSI_WLAN_TCP_WINDOW_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + // Get WLAN/network command response status + rsi_wlan_socket_set_status(status, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_5, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_SOCK_ERROR; + } + // Get WLAN/network command response status + status = rsi_wlan_socket_get_status(sockID); + if (status != RSI_SUCCESS) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ERANGE); +#endif + SL_PRINTF(SL_TCP_WINDOW_UPDATE_SOCK_ERROR_6, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_TCP_WINDOW_UPDATE_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return rsi_socket_pool_non_rom[sockID].window_size; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the socket descriptor based on source port number, destination port number, destination IP address, and the IP version. This is a non-blocking API. + * @param[in] src_port - Pointer to source port number + * @param[in] dst_port - Pointer to destination port number + * @param[in] ip_addr - Pointer to destinaion IP address + * @param[in] ip_version - IP version either IPv4/IPv6 + * @param[in] sockid - Socket descriptor ID from firmware + * @return 0 - Socket descriptor \n + * @return Negative Value - If socket is not found + * + */ +/// @private + +int32_t rsi_get_socket_descriptor(uint8_t *src_port, + uint8_t *dst_port, + uint8_t *ip_addr, + uint16_t ip_version, + uint16_t sockid) +{ + SL_PRINTF(SL_GET_SOCKET_DESCRIPTOR_ENTRY, NETWORK, LOG_INFO); + int i; + uint16_t source_port; + uint16_t destination_port; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + source_port = rsi_bytes2R_to_uint16(src_port); + destination_port = rsi_bytes2R_to_uint16(dst_port); + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool_non_rom[i].sock_non_block) { + if ((rsi_socket_pool[i].sock_id == sockid) && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_CONNECTED)) { + return i; // Go to here + } + if (rsi_socket_pool[i].source_port != 0) { + if ((rsi_socket_pool[i].source_port == source_port) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_CONNECTED) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_LISTEN) + && rsi_socket_pool_non_rom[i].wait_to_connect) { + break; + } + } + // Compare source port and destination port + else if ((rsi_socket_pool[i].destination_port == destination_port) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_CONNECTED) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_LISTEN) + && rsi_socket_pool_non_rom[i].wait_to_connect) { + + // Compare destination IP addess + if (ip_version == 4) { + if (!(memcmp(rsi_socket_pool[i].destination_ip_addr.ipv4, ip_addr, RSI_IPV4_ADDRESS_LENGTH))) { + break; + } + } else { + if (!(memcmp(rsi_socket_pool[i].destination_ip_addr.ipv6, ip_addr, RSI_IPV6_ADDRESS_LENGTH))) { + break; + } + } + } + } else { + if (rsi_socket_pool[i].source_port != 0) { + if ((rsi_socket_pool[i].source_port == source_port) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_CONNECTED) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_LISTEN)) { + break; + } + } + // Compare source port and destination port + else if ((rsi_socket_pool[i].destination_port == destination_port) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_CONNECTED) + && (rsi_socket_pool[i].sock_state != RSI_SOCKET_STATE_LISTEN)) { + + // Compare destination IP addess + if (ip_version == 4) { + if (!(memcmp(rsi_socket_pool[i].destination_ip_addr.ipv4, ip_addr, RSI_IPV4_ADDRESS_LENGTH))) { + break; + } + } else { + if (!(memcmp(rsi_socket_pool[i].destination_ip_addr.ipv6, ip_addr, RSI_IPV6_ADDRESS_LENGTH))) { + break; + } + } + } + } + } + if (i >= NUMBER_OF_SOCKETS) { + SL_PRINTF(SL_GET_SOCKET_DESCRIPTOR_SOCK_ERROR, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_GET_SOCKET_DESCRIPTOR_EXIT, NETWORK, LOG_ERROR); + return i; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Create a socket and register a callback that will be used by the driver to forward the received packets asynchronously to the application (on packet reception) \n + * without waiting for recv API (Add proper API here). This is a non-blocking API. + * @param[in] protocolFamily - Protocol family to select IPv4 or IPv6. \n + * AF_INET (2) : Select IPv4, \n + * AF_INET6 (3) : Select IPv6 + * @param[in] type - Select socket type UDP or TCP. \n + * SOCK_STREAM (1) : Select TCP, \n + * SOCK_DGRM (2) : Select UDP + * @param[in] protocol - 0: Non-SSL sockets, 1: SSL sockets. \n + * BIT(5) must be enabled to select the certificate index, \n + * 0<<12 for index 0, \n + * 1<<12 for index 1 + * @param[in] callback - Callback function to read data asynchronously from socket \n + * @param[out] sock_no - Application socket number + * @param[out] buffer - Pointer to buffer holding the data + * @param[out] length - Length of the response buffer + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + */ +/// @private + +int32_t rsi_socket_async_non_rom(int32_t protocolFamily, + int32_t type, + int32_t protocol, + void (*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length)) +{ + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_ENTRY, NETWORK, LOG_INFO); + int i; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + int32_t status = RSI_SUCCESS; + + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if ((wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE) && (wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE)) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // Check supported protocol family + if ((protocolFamily != AF_INET) && (protocolFamily != AF_INET6)) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EAFNOSUPPORT); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check supported socket type + if ((type != SOCK_STREAM) && (type != SOCK_DGRAM) && (type != (SOCK_STREAM | O_NONBLOCK)) /*&& (type != SOCK_RAW)*/) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EPROTOTYPE); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Acquire mutex lock + RSI_MUTEX_LOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + // search for free entry in socket pool + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool[i].sock_state == RSI_SOCKET_STATE_INIT) { + // Memset socket info + memset(&rsi_socket_pool[i], 0, sizeof(rsi_socket_info_t)); +#ifdef RSI_WITH_OS + status = rsi_semaphore_check_and_destroy(&rsi_socket_pool_non_rom[i].socket_sem); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + status = rsi_semaphore_check_and_destroy(&rsi_socket_pool_non_rom[i].sock_send_sem); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_EXIT4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + status = rsi_semaphore_check_and_destroy(&rsi_socket_pool_non_rom[i].sock_recv_sem); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBUSY); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + memset(&rsi_socket_pool_non_rom[i], 0, sizeof(rsi_socket_info_non_rom_t)); + + status = rsi_semaphore_create(&rsi_socket_pool_non_rom[i].socket_sem, 0); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOMEM); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + status = rsi_semaphore_create(&rsi_socket_pool_non_rom[i].sock_send_sem, 0); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOMEM); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + status = rsi_semaphore_create(&rsi_socket_pool_non_rom[i].sock_recv_sem, 0); + if (status != RSI_ERROR_NONE) { +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOMEM); +#endif + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_8, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Change the socket state to create + rsi_socket_pool[i].sock_state = RSI_SOCKET_STATE_CREATE; + + // Set socket type + rsi_socket_pool[i].sock_type = type; + + // Set protocol type + rsi_socket_pool[i].sock_type |= (protocolFamily << 4); + + if (callback) { + // Set socket asynchronous receive callback + rsi_socket_pool[i].sock_receive_callback = callback; + } else { + // If callback is registered set socket as asynchronous + rsi_socket_pool[i].sock_bitmap |= RSI_SOCKET_FEAT_SYNCHRONOUS; + } + + if (type & O_NONBLOCK) { + type = SOCK_STREAM; + rsi_socket_pool_non_rom[i].wait_to_connect = 1; + rsi_socket_pool_non_rom[i].sock_non_block = 1; + } +#ifndef BSD_COMPATIBILITY + if (protocol & RSI_SOCKET_FEAT_SSL) { + // Check SSL enabled or not + rsi_socket_pool[i].sock_bitmap |= RSI_SOCKET_FEAT_SSL; + } + + if (protocol & RSI_SOCKET_FEAT_TCP_ACK_INDICATION) { + // Set TCP ACK indication bit + rsi_socket_pool[i].sock_bitmap |= RSI_SOCKET_FEAT_TCP_ACK_INDICATION; + + if (((protocol >> 3) & 0XF) == 0) { + rsi_socket_pool[i].max_available_buffer_count = rsi_socket_pool[i].current_available_buffer_count = 4; + } else { + rsi_socket_pool[i].max_available_buffer_count = rsi_socket_pool[i].current_available_buffer_count = + ((protocol >> 3) & 0xF); + } + } + + if (protocol & RSI_SOCKET_FEAT_CERT_INDEX) { + // Set certificate index bit + rsi_socket_pool[i].sock_bitmap |= RSI_SOCKET_FEAT_CERT_INDEX; + + rsi_socket_pool[i].socket_cert_inx = (protocol >> 12); + + } else { + rsi_socket_pool[i].socket_cert_inx = 0; + } + + // Get RX window buffers + rsi_socket_pool[i].rx_window_buffers = ((protocol >> 7) & 0xF); +#endif + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENFILE); +#endif + rsi_wlan_socket_set_status(RSI_ERROR_ENFILE, i); + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_SOCK_ERROR_9, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + // Return available index + SL_PRINTF(SL_SOCKET_ASYNC_NONO_ROM_EXIT, NETWORK, LOG_INFO); + return i; +} +/*==============================================*/ +/** + * @brief Connect the socket to specific remote address. This is a non-blocking API, if socket_connect_response_handler() is registered through rsi_wlan_register_callbacks(). Otherwise it is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] remoteAddress - Remote peer address structure + * @param[in] addressLength - Remote peer address structrue length + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +/// @private + +int32_t rsi_socket_connect(int32_t sockID, struct rsi_sockaddr *remoteAddress, int32_t addressLength) +{ + SL_PRINTF(SL_SOCKET_CONNECT_ENTRY, NETWORK, LOG_INFO); + int32_t status = RSI_SUCCESS; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is in init state + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check whether supplied address structure + if (remoteAddress == RSI_NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EFAULT, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EFAULT); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check address length + if (((remoteAddress->sa_family == AF_INET) && (addressLength != sizeof(struct rsi_sockaddr_in))) + || ((remoteAddress->sa_family == AF_INET6) && (addressLength != sizeof(struct rsi_sockaddr_in6)))) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EAFNOSUPPORT, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EAFNOSUPPORT); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check if the remote address family matches the local BSD socket address family + if (remoteAddress->sa_family != (rsi_socket_pool[sockID].sock_type >> 4)) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EAFNOSUPPORT, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EAFNOSUPPORT); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Acquire mutex lock + RSI_MUTEX_LOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + // Save destination port number, IP address, and port number to use in UDP send() + if (remoteAddress->sa_family == AF_INET) { + // Save destination IPv4 address + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv4, + &(((struct rsi_sockaddr_in *)remoteAddress)->sin_addr.s_addr), + RSI_IPV4_ADDRESS_LENGTH); + rsi_socket_pool[sockID].destination_port = htons(((struct rsi_sockaddr_in *)remoteAddress)->sin_port); + } else { + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv6, + ((struct rsi_sockaddr_in6 *)remoteAddress)->sin6_addr._S6_un._S6_u32, + RSI_IPV6_ADDRESS_LENGTH); + rsi_socket_pool[sockID].destination_port = htons(((struct rsi_sockaddr_in6 *)remoteAddress)->sin6_port); + } + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) { + // Send socket create command + status = rsi_socket_create_async(sockID, RSI_SOCKET_TCP_CLIENT, 0); + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) + && (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_CREATE)) { + // Send socket create command + status = rsi_socket_create_async(sockID, RSI_SOCKET_LUDP, 0); + } + + if (status != RSI_SUCCESS) { + // Set error + rsi_wlan_socket_set_status(status, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_CONNECT_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_SOCKET_CONNECT_EXIT, NETWORK, LOG_INFO); + return RSI_SUCCESS; +} +/*==============================================*/ +/** + * @brief Retrieve the received data from the remote peer on a given socket descriptor. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[out] buffer - Pointer to buffer to hold receive data + * @param[in] buffersize - Size of the buffer supplied + * @param[in] flags - Reserved + * @param[out] fromAddr - Sddress of remote peer, from where current packet was received + * @param[in] fromAddrLen - Pointer that contains remote peer address (fromAddr) length + * @return Positive Value - Number of bytes received successfully + * @return 0 - Socket close error + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + * + */ +/// @private + +int32_t rsi_socket_recvfrom(int32_t sockID, + int8_t *buffer, + int32_t buffersize, + int32_t flags, + struct rsi_sockaddr *fromAddr, + int32_t *fromAddrLen) +{ + SL_PRINTF(SL_SOCKET_RECVFROM_ENTRY, NETWORK, LOG_INFO); + UNUSED_PARAMETER(flags); // Added to resolve compilation warning, value is unchanged + + struct rsi_sockaddr_in peer4_address; + struct rsi_sockaddr_in6 peer6_address; + int32_t status = RSI_SUCCESS; + int32_t rsi_read_response_wait_time = 0; + + int32_t copy_length = 0; + rsi_req_socket_read_t *data_recv; + rsi_pkt_t *pkt = NULL; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *sock_info = &global_cb_p->rsi_socket_pool[sockID]; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SOCKET_RECVFROM_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + // If socket is in init state + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_RECVFROM_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_RECVFROM_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is not in connected state + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_RECVFROM_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + if (rsi_socket_pool_non_rom[sockID].socket_terminate_indication) { + rsi_socket_pool_non_rom[sockID].socket_terminate_indication = 0; + SL_PRINTF(SL_SOCKET_RECVFROM_EXIT_1, NETWORK, LOG_INFO, "copy length: %4x", copy_length); + return copy_length; + } + // Acquire mutex lock + RSI_MUTEX_LOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + if (global_cb_p->rx_buffer_mem_copy != 1) { + sock_info->recv_buffer = (uint8_t *)buffer; +#ifdef RSI_PROCESS_MAX_RX_DATA + if (rsi_socket_pool[sockID].sock_type & SOCK_STREAM) { + sock_info->recv_buffer_length = 0; + } else { + sock_info->recv_buffer_length = buffersize; + } +#else + sock_info->recv_buffer_length = buffersize; +#endif + } + // If nothing is left + if (sock_info->sock_recv_available_length == 0 || global_cb_p->rx_buffer_mem_copy != 1) { + // Allocate packet + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_RECVFROM_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Send data recieve command + data_recv = (rsi_req_socket_read_t *)pkt->data; + + // Memset the recv packet + memset(data_recv, 0, sizeof(rsi_req_socket_read_t)); + + // Fill socket ID + data_recv->socket_id = sock_info->sock_id; +#ifdef RSI_PROCESS_MAX_RX_DATA + if (rsi_socket_pool[sockID].sock_type & SOCK_STREAM) { + if (buffersize > MAX_RX_DATA_LENGTH) { + buffersize = MAX_RX_DATA_LENGTH; + } + } else { + if (buffersize > 1472) { + buffersize = 1472; + } + } +#else + if (rsi_socket_pool[sockID].sock_type & SOCK_STREAM) { +#ifdef CHIP_9117B0 + if (buffersize > RX_DATA_LENGTH) { + buffersize = RX_DATA_LENGTH; + } +#else + if (buffersize > 1460) { + buffersize = 1460; + } +#endif + } else { + if (buffersize > 1472) { + buffersize = 1472; + } + } +#endif + // Fill number of requesting bytes for receive + rsi_uint32_to_4bytes(data_recv->requested_bytes, buffersize); + + // Fill number of requesting bytes for receive + rsi_uint16_to_2bytes(data_recv->read_timeout, rsi_socket_pool[sockID].read_time_out); + + if (rsi_socket_pool[sockID].read_time_out) { + rsi_read_response_wait_time = + (rsi_socket_pool[sockID].read_time_out + WAIT_TIMEOOUT + RSI_SOCKET_RECVFROM_RESPONSE_WAIT_TIME); + } else { + rsi_read_response_wait_time = 0; + } + + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap |= BIT(1); +#endif + + // Send socket receive request command + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_SOCKET_READ_DATA, pkt); + + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[sockID].sock_recv_sem, (rsi_read_response_wait_time)); + + /* Check if we need to invalidate the recv buffer pointer */ + if (global_cb_p->rx_buffer_mem_copy != 1) { + sock_info->recv_buffer = NULL; + } + + if (status != RSI_ERROR_NONE) { + // Get WLAN/network command response status + rsi_wlan_socket_set_status(status, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_RECVFROM_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Get WLAN/network command response status + status = rsi_wlan_socket_get_status(sockID); + + if (status != RSI_SUCCESS) { + rsi_socket_pool_non_rom[sockID].socket_terminate_indication = 0; +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + return RSI_SOCK_ERROR; + } else { + if (rsi_socket_pool_non_rom[sockID].recv_pending_bit & BIT(0)) { + rsi_socket_pool_non_rom[sockID].recv_pending_bit = 0; + } else if (rsi_socket_pool_non_rom[sockID].recv_pending_bit & BIT(1)) { + rsi_socket_pool_non_rom[sockID].recv_pending_bit = 0; + return 0; + } + } + } + + if (global_cb_p->rx_buffer_mem_copy == 1) { + // Get minimum of requested length and available length + if (buffersize > (int32_t)sock_info->sock_recv_available_length) { + copy_length = sock_info->sock_recv_available_length; + } else { + copy_length = buffersize; + } + + // Copy available buffer + buffer = (int8_t *)sock_info->sock_recv_buffer; + + // Increase buffer offset + sock_info->sock_recv_buffer_offset += copy_length; + + if ((int32_t)(sock_info->sock_recv_available_length) >= copy_length) { + // Decrease available length + sock_info->sock_recv_available_length -= copy_length; + } else { + sock_info->sock_recv_available_length = 0; + } + + if (sock_info->sock_recv_available_length == 0) { + // Reset offset value after reading total packet + sock_info->sock_recv_buffer_offset = 0; + } + } else { + copy_length = sock_info->recv_buffer_length; + } + + // If fromAddr is not NULL then copy the IP address + if (fromAddr && (*fromAddrLen != 0)) { + if ((sock_info->sock_type >> 4) == AF_INET) { + // Update the client address with socket family, remote host IPv4 address, and port + peer4_address.sin_family = AF_INET; + memcpy(&peer4_address.sin_addr.s_addr, + (ntohl(rsi_socket_pool[sockID].destination_ip_addr.ipv4)), + RSI_IPV4_ADDRESS_LENGTH); + peer4_address.sin_port = ntohs((uint16_t)rsi_socket_pool[sockID].destination_port); + + // Copy the peer address/port info to the ClientAddress + // Truncate if addressLength is smaller than the size of struct rsi_sockaddr_in + if (*fromAddrLen > (int32_t)sizeof(struct rsi_sockaddr_in)) { + *fromAddrLen = sizeof(struct rsi_sockaddr_in); + } + memcpy(fromAddr, &peer4_address, *fromAddrLen); + } else { + peer6_address.sin6_family = AF_INET6; + peer6_address.sin6_port = ntohs((uint16_t)rsi_socket_pool[sockID].destination_port); + + peer6_address.sin6_addr._S6_un._S6_u32[0] = + (uintptr_t)ntohl(&rsi_socket_pool[sockID].destination_ip_addr.ipv6[0]); + peer6_address.sin6_addr._S6_un._S6_u32[1] = + (uintptr_t)ntohl(&rsi_socket_pool[sockID].destination_ip_addr.ipv6[4]); + peer6_address.sin6_addr._S6_un._S6_u32[2] = + (uintptr_t)ntohl(&rsi_socket_pool[sockID].destination_ip_addr.ipv6[8]); + peer6_address.sin6_addr._S6_un._S6_u32[3] = + (uintptr_t)ntohl(&rsi_socket_pool[sockID].destination_ip_addr.ipv6[12]); + + // Copy the peer address/port info to the ClientAddress + // Truncate if addressLength is smaller than the size of struct rsi_sockaddr_in + if ((*fromAddrLen) > (int32_t)sizeof(struct rsi_sockaddr_in6)) { + *fromAddrLen = sizeof(struct rsi_sockaddr_in6); + } + memcpy(fromAddr, &peer6_address, *fromAddrLen); + } + } + SL_PRINTF(SL_SOCKET_RECVFROM_EXIT_2, NETWORK, LOG_INFO, "copy length: %4x", copy_length); + return copy_length; +} +/*==============================================*/ +/** + * @brief Enable socket to listen for remote connection request in passive mode. This is a blocking API. + * @param[in] sockID - Socket descriptor ID + * @param[in] backlog - Maximum number of pending connections requests + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +/// @private + +int32_t rsi_socket_listen(int32_t sockID, int32_t backlog) +{ + SL_PRINTF(SL_SOCKET_LISTEN_ENTRY, NETWORK, LOG_INFO); + int32_t status = RSI_SUCCESS; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SOCKET_LISTEN_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + // If socket is in init state + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_LISTEN_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_LISTEN_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check if socket is TCP or not + if ((rsi_socket_pool[sockID].sock_type & 0xF) != SOCK_STREAM) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EPROTOTYPE, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EPROTOTYPE); +#endif + SL_PRINTF(SL_SOCKET_LISTEN_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is not binded + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_BIND) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_LISTEN_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Set minimum backlog + if (backlog < TCP_LISTEN_MIN_BACKLOG) { + backlog = TCP_LISTEN_MIN_BACKLOG; + } + + // Create socket + status = rsi_socket_create_async(sockID, RSI_SOCKET_TCP_SERVER, backlog); + + if (status == RSI_SUCCESS) { + // If fails memset socket info + // Save backlogs + rsi_socket_pool[sockID].backlogs = backlog; + // Set as master socket + rsi_socket_pool[sockID].ltcp_socket_type = RSI_LTCP_PRIMARY_SOCKET; + } else { +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); + status = RSI_SOCK_ERROR; +#endif + } + SL_PRINTF(SL_SOCKET_LISTEN_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Close the socket specified in a socket descriptor. This is a blocking API. + * @param[in] sockID : Socket descriptor ID + * @param[in] how 0: Close the specified socket, \n + * 1: Close all the sockets open on a specified socket's source port number. \n + * @return 0 - Success \n + * @return Negative Value - Failure + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + * @note how = 1 is valid for passively open sockets (listen) with more than one backlogs specified. \n + * @note If EXT_TCP_IP_WAIT_FOR_SOCKET_CLOSE (BIT(16)) in RSI_EXT_TCPIP_FEATURE_BITMAP is enabled, then to close LTCP socket, argument "how" should be 1. \n + * @note If EXT_TCP_IP_WAIT_FOR_SOCKET_CLOSE (BIT(16)) in RSI_EXT_TCPIP_FEATURE_BITMAP is enabled, though remote socket has terminated connection, socket is disconnected and deleted only, if host issues rsi_shutdown(). + * + */ +/// @private +int32_t rsi_socket_shutdown(int32_t sockID, int32_t how) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SOCKET_SHUTDOWN_ENTRY, NETWORK, LOG_INFO); + + rsi_req_socket_close_t *close; + rsi_pkt_t *pkt = NULL; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + // If socket is in init state + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_SHUTDOWN_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_SHUTDOWN_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Memeset socket info + memset(&rsi_socket_pool[sockID], 0, sizeof(rsi_socket_info_t)); + + rsi_socket_pool_non_rom[sockID].close_pending = 0; + rsi_wlan_socket_set_status(RSI_SUCCESS, sockID); + // Return success + SL_PRINTF(SL_SOCKET_SHUTDOWN_EXIT_1, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } +#endif + + // If socket is not in connected state, do not send socket close command + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED) { + if (rsi_socket_pool[sockID].ltcp_socket_type != RSI_LTCP_PRIMARY_SOCKET) { + // Memset socket info + memset(&rsi_socket_pool[sockID], 0, sizeof(rsi_socket_info_t)); + + rsi_wlan_socket_set_status(RSI_SUCCESS, sockID); + // Return success + SL_PRINTF(SL_SOCKET_SHUTDOWN_SOCK_ERROR_3, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } else { + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_LISTEN) { + // Memeset socket info + memset(&rsi_socket_pool[sockID], 0, sizeof(rsi_socket_info_t)); + + rsi_wlan_socket_set_status(RSI_SUCCESS, sockID); + // Return success + SL_PRINTF(SL_SOCKET_SHUTDOWN_EXIT_2, NETWORK, LOG_INFO); + return RSI_SUCCESS; + } + how = 1; + } + } + + // Allocate packet + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + if (pkt == NULL) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_PKT_ALLOCATION_FAILURE, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_SHUTDOWN_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Fill socket close command + close = (rsi_req_socket_close_t *)pkt->data; + + if (how == 1) { + // Port based close for LTCP + rsi_uint16_to_2bytes(close->socket_id, 0); + rsi_uint16_to_2bytes(close->port_number, rsi_socket_pool[sockID].source_port); + } else { + // Socket descriptor based close + rsi_uint16_to_2bytes(close->socket_id, rsi_socket_pool[sockID].sock_id); + rsi_uint16_to_2bytes(close->port_number, 0); + } + +#ifndef RSI_SOCK_SEM_BITMAP + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap |= BIT(0); +#endif + + // Send socket close command + status = RSI_DRIVER_WLAN_SEND_CMD(RSI_WLAN_REQ_SOCKET_CLOSE, pkt); + + // Wait on socket semaphore + status = + rsi_wait_on_socket_semaphore(&rsi_socket_pool_non_rom[sockID].socket_sem, RSI_SOCKET_CLOSE_RESPONSE_WAIT_TIME); + if (status != RSI_ERROR_NONE) { + // Get WLAN/network command response status + rsi_wlan_socket_set_status(status, sockID); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_SHUTDOWN_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // Clear socket info + rsi_clear_sockets(sockID); + // Get socket command response status + status = rsi_wlan_socket_get_status(sockID); + if (status != RSI_SUCCESS) { +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_SHUTDOWN_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Return status + SL_PRINTF(SL_SOCKET_SHUTDOWN_EXIT_3, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Assign address to the socket. This is a non-blocking API for TCP and a blocking API for UDP. + * @param[in] sockID - Socket descriptor ID + * @param[in] localAddress - Address that needs to be assigned + * @param[in] addressLength - Length of the socket address + * @return 0 - Success \n + * @return Negative Value - Failure + * + * + */ +/// @private +int32_t rsi_socket_bind(int32_t sockID, struct rsi_sockaddr *localAddress, int32_t addressLength) +{ + int32_t local_port; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_SOCKET_BIND_ENTRY, NETWORK, LOG_INFO); + uint8_t i; + + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + // If socket is in init state + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is not created + if (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CREATE) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check for a valid input local address and address length input buffer + if ((localAddress == RSI_NULL) || (addressLength == 0)) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check address length + if (((localAddress->sa_family == AF_INET) && (addressLength != sizeof(struct rsi_sockaddr_in))) + || ((localAddress->sa_family == AF_INET6) && (addressLength != sizeof(struct rsi_sockaddr_in6)))) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check address family + if ((rsi_socket_pool[sockID].sock_type >> 4) != localAddress->sa_family) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); + +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Acquire mutex lock + RSI_MUTEX_LOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + // Pickup the local port + if (localAddress->sa_family == AF_INET) { + local_port = ntohs(((struct rsi_sockaddr_in *)localAddress)->sin_port); + } else { + local_port = ntohs(((struct rsi_sockaddr_in6 *)localAddress)->sin6_port); + } + + // Check whether local port is already used or not + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool[i].source_port == local_port) { + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); + +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_8, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + } + + // Port number is not used, save the port number + rsi_socket_pool[sockID].source_port = local_port; + + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + // Send socket create if it is UDP + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) { + status = rsi_socket_create_async(sockID, RSI_SOCKET_LUDP, 0); + + } else { + // Set socket state as bind + rsi_socket_pool[sockID].sock_state = RSI_SOCKET_STATE_BIND; + } + + if (status != RSI_SUCCESS) { +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SOCKET_BIND_SOCK_ERROR_9, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Return success + SL_PRINTF(SL_SOCKET_BIND_EXIT, NETWORK, LOG_INFO); + return RSI_SUCCESS; +} +/*==============================================*/ +/** + * @brief Wait for network semaphore + * @param[in] semaphore - Semaphore handle pointer + * @param[in] timeout_ms - Maximum time to wait to acquire semaphore. If timeout_ms is 0, then wait + * till semaphore is acquired. + * @return 0 - Success \n + * @return Negative Value - Failure + */ +/// @private + +rsi_error_t rsi_wait_on_socket_semaphore(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) +{ + SL_PRINTF(SL_WAIT_ON_SOCKET_SEMAPHORE_ENTRY, NETWORK, LOG_INFO); + // Wait on WLAN semaphore + if (rsi_semaphore_wait(semaphore, timeout_ms) != RSI_ERROR_NONE) { +#ifndef RSI_WAIT_TIMEOUT_EVENT_HANDLE_TIMER_DISABLE + if (rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb != NULL) { + rsi_driver_cb_non_rom->rsi_wait_timeout_handler_error_cb(RSI_ERROR_RESPONSE_TIMEOUT, SOCKET_CMD); + } +#endif + SL_PRINTF(SL_WAIT_ON_SOCKET_SEMAPHORE_RESPONSE_TIMEOUT, NETWORK, LOG_ERROR); + return RSI_ERROR_RESPONSE_TIMEOUT; + } + SL_PRINTF(SL_WAIT_ON_SOCKET_SEMAPHORE_ERROR_NONE, NETWORK, LOG_INFO); + return RSI_ERROR_NONE; +} +/** @} */ +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the application socket descriptor from module’s socket descriptor. This is a non-blocking API. + * @param[in] sock_id - Module's socket descriptor ID + * @return Positive Value - Application socket descriptor \n + * @return Negative Value - If socket is not found + * + */ +/// @private +int32_t rsi_application_socket_descriptor(int32_t sock_id) +{ + SL_PRINTF(SL_APPLICATION_SOCKET_DESCRIPTOR_ENTRY, NETWORK, LOG_INFO); + int i; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool[i].sock_id == sock_id && rsi_socket_pool[i].sock_state == RSI_SOCKET_STATE_CONNECTED +#ifdef SOCKET_CLOSE_WAIT + && !(rsi_socket_pool_non_rom[i].close_pending) +#endif + ) { + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + SL_PRINTF(SL_APPLICATION_SOCKET_DESCRIPTOR_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + SL_PRINTF(SL_APPLICATION_SOCKET_DESCRIPTOR_EXIT, NETWORK, LOG_INFO, "i: %d ", i); + return i; +} +/** @} */ +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get WLAN socket status. This is a non-blocking API + * @param[in] sockID - Application socket ID + * @return WLAN socket status + * + */ +int32_t rsi_wlan_socket_get_status(int32_t sockID) +{ + SL_PRINTF(SL_WLAN_SOCKET_GET_STATUS_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_pool_non_rom[sockID].socket_status; +} + +/*==============================================*/ +/** + * @brief Set WLAN status. This is a non-blocking API. + * @param[in] status - Status value to be set + * @param[in] sockID - Application socket ID + * @return Void + * + */ +void rsi_wlan_socket_set_status(int32_t status, int32_t sockID) +{ + SL_PRINTF(SL_WLAN_SOCKET_SET_STATUS_ENTRY, NETWORK, LOG_INFO); + rsi_socket_pool_non_rom[sockID].socket_status = status; +#ifndef RSI_WLAN_STATUS + rsi_wlan_set_status(status); +#endif +} + +/*==============================================*/ +/** + * @brief Get the status of the socket specified in the select ID. + * @param[in] selectid - Socket ID to get the status + * @return 0 - Success \n + * @return Negative Value - Failure + */ +int32_t rsi_select_get_status(int32_t selectid) +{ + SL_PRINTF(SL_SELECT_GET_STATUS_ENTRY, NETWORK, LOG_INFO); + return rsi_socket_select_info[selectid].select_status; +} + +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the status of the socket specified in the select ID. + * @param[in] status - Status value to be set + * @param[in] selectid - Socket ID on which the status is set + * @return Void + * @note **Precondition** - \ref rsi_socket()/ \ref rsi_socket_async() API needs to be called before this API. + */ +/// @private +void rsi_select_set_status(int32_t status, int32_t selectid) +{ + SL_PRINTF(SL_SELECT_SET_STATUS_ENTRY, NETWORK, LOG_INFO); + rsi_socket_select_info[selectid].select_status = status; +#ifndef RSI_WLAN_STATUS + rsi_wlan_set_status(status); +#endif +} +/*==============================================*/ +/** + * @brief Send data on a given socket asynchronously + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to data that needs to be sent to remote peer + * @param[in] msgLength - Length of data to send + * @param[in] flags - Reserved + * @param[in] data_transfer_complete_handler - Pointer to callback function called after complete data transfer + * @param[out] sockID - Socket Descriptor ID + * @param[out] length - Number of bytes transfered + * @return 0 - Success \n + * @return Negative Value - Failure + * @note The following table lists the maximum individual chunk of data that can be sent over each supported protocol. + + | Protocol | Maximum data chunk (bytes) | + |---------------------|----------------------------| + | TCP/LTCP socket | 1460 | + | LUDP socket | 1472 | + | Web socket | 1450 | + | TCP-SSL/LTCP-SSL | 1370 | + | Web socket over SSL | 1362 | + * + */ +/// @private +int32_t rsi_send_async_non_rom(int32_t sockID, + const int8_t *msg, + int32_t msgLength, + int32_t flags, + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length)) +{ + SL_PRINTF(SL_SEND_ASYNC_NON_ROM_ENTRY, NETWORK, LOG_INFO); + struct rsi_sockaddr_in fromAddr4; + struct rsi_sockaddr_in6 fromAddr6; + int32_t status = 0; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SEND_ASYNC_NON_ROM_SOCK_ERROR, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if ((rsi_socket_pool[sockID].sock_type >> 4) == AF_INET) { + + // Set socket family for IPv4 + fromAddr4.sin_family = AF_INET; + + // Set destination port + fromAddr4.sin_port = rsi_socket_pool[sockID].destination_port; + + // Set destination IPv4 address + memcpy(&fromAddr4.sin_addr.s_addr, rsi_socket_pool[sockID].destination_ip_addr.ipv4, RSI_IPV4_ADDRESS_LENGTH); + + status = rsi_sendto_async(sockID, + (int8_t *)msg, + msgLength, + flags, + (struct rsi_sockaddr *)&fromAddr4, + sizeof(fromAddr4), + data_transfer_complete_handler); + } else { + + // Set socket family for IPv6 + fromAddr6.sin6_family = AF_INET6; + + // Set destination port + fromAddr6.sin6_port = rsi_socket_pool[sockID].destination_port; + + // Set destination IPv6 address + memcpy(fromAddr6.sin6_addr._S6_un._S6_u8, + rsi_socket_pool[sockID].destination_ip_addr.ipv6, + RSI_IPV6_ADDRESS_LENGTH); + + status = rsi_sendto_async(sockID, + (int8_t *)msg, + msgLength, + flags, + (struct rsi_sockaddr *)&fromAddr6, + sizeof(fromAddr6), + data_transfer_complete_handler); + } + + // Return status + SL_PRINTF(SL_SEND_ASYNC_NON_ROM_EXIT, NETWORK, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Send data to specific remote peer on a given socket + * @param[in] sockID - Socket descriptor ID + * @param[in] msg - Pointer to data that needs to be sent to remote peer + * @param[in] msgLength - Length of data to send + * @param[in] flags - Reserved + * @param[in] destAddr - Remote peer address to send data + * @param[in] destAddrLen - Remote peer address length + * @param[in] data_transfer_complete_handler - Pointer to callback function called after complete data transfer + * @param[out] sockID - Socket Descriptor ID + * @param[out] length - Number of bytes transfered + * @return Positive Value - Success, Number of bytes sent successfully \n + * @return Negative Value - Failure \n + * @return 0 - Socket close error + * + */ +/// @private +int32_t rsi_sendto_async_non_rom(int32_t sockID, + int8_t *msg, + int32_t msgLength, + int32_t flags, + struct rsi_sockaddr *destAddr, + int32_t destAddrLen, + void (*data_transfer_complete_handler)(int32_t sockID, uint16_t length)) +{ + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_ENTRY, NETWORK, LOG_INFO); + UNUSED_PARAMETER(destAddrLen); //Added to resolve compilation warning, value is unchanged + int32_t status = RSI_SUCCESS; + int32_t maximum_limit = 0; + uint8_t buffers_required; + UNUSED_PARAMETER(flags); // Added to resolve compilation warning, value is unchanged + rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *sock_info = &global_cb_p->rsi_socket_pool[sockID]; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + +#ifdef SOCKET_CLOSE_WAIT + if (rsi_socket_pool[sockID].sock_state > RSI_SOCKET_STATE_INIT && rsi_socket_pool_non_rom[sockID].close_pending) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_ECONNABORTED, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ECONNABORTED); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_1, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +#endif + + if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_ERROR_EBADF, NETWORK, LOG_ERROR); + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + return RSI_SOCK_ERROR; + } + // If sockID is not in available range + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EBADF, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EBADF); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_2, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // If socket is in init state for UDP + if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) + && (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_INIT)) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EPROTOTYPE, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EPROTOTYPE); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_3, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED)) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EPROTOTYPE, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EPROTOTYPE); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_4, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Check socket family + if (destAddr->sa_family != (rsi_socket_pool[sockID].sock_type >> 4)) { + // Set error + rsi_wlan_socket_set_status(RSI_ERROR_EFAULT, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EFAULT); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_5, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Register the callback + rsi_wlan_cb_non_rom->nwk_callbacks.data_transfer_complete_handler = data_transfer_complete_handler; + + // Acquire mutex lock + RSI_MUTEX_LOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) + && (rsi_socket_pool[sockID].sock_state != RSI_SOCKET_STATE_CONNECTED)) { + if ((rsi_socket_pool[sockID].sock_type >> 4) == AF_INET) { + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv4, + &(((struct rsi_sockaddr_in *)destAddr)->sin_addr.s_addr), + RSI_IPV4_ADDRESS_LENGTH); + rsi_socket_pool[sockID].destination_port = ntohs(((struct rsi_sockaddr_in *)destAddr)->sin_port); + } else { + memcpy(rsi_socket_pool[sockID].destination_ip_addr.ipv6, + ((struct rsi_sockaddr_in6 *)destAddr)->sin6_addr._S6_un._S6_u32, + RSI_IPV6_ADDRESS_LENGTH); + rsi_socket_pool[sockID].destination_port = ntohs(((struct rsi_sockaddr_in6 *)destAddr)->sin6_port); + } + // Create socket + status = rsi_socket_create_async(sockID, RSI_SOCKET_LUDP, 0); + if (status != RSI_SUCCESS) { + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_EXIT_1, NETWORK, LOG_ERROR); + return status; + } + } + + // Find maximum limit based on the protocol + if ((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_DGRAM) { + // If it is a UDP socket + maximum_limit = 1472; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && ((rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_SSL) + || (rsi_socket_pool_non_rom[sockID].ssl_bitmap))) { + // If it is a SSL socket/SSL websocket + maximum_limit = rsi_socket_pool_non_rom[sockID].mss - RSI_SSL_HEADER_SIZE; + } else if (((rsi_socket_pool[sockID].sock_type & 0xF) == SOCK_STREAM) + && (rsi_socket_pool[sockID].sock_bitmap & RSI_SOCKET_FEAT_WEBS_SUPPORT)) { + // If it is a websocket + maximum_limit = 1450; + } else { + maximum_limit = rsi_socket_pool_non_rom[sockID].mss; + } + + // Check maximum allowed length value + if (msgLength > maximum_limit) { + rsi_wlan_socket_set_status(RSI_ERROR_EMSGSIZE, sockID); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_EMSGSIZE); +#endif + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + return RSI_SOCK_ERROR; + } + if (sock_info->sock_bitmap & RSI_SOCKET_FEAT_TCP_ACK_INDICATION) { + // Return if buffers are not available + if (sock_info->current_available_buffer_count == 0) { + // Set no buffers status and return + rsi_wlan_socket_set_status(RSI_ERROR_ENOBUFS, sockID); + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); +#ifdef RSI_WITH_OS + rsi_set_os_errno(RSI_ERROR_ENOBUFS); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_6, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } + + // Calculate buffers required for sending this length + buffers_required = calculate_buffers_required(sock_info->sock_type, msgLength); + + if (buffers_required > sock_info->current_available_buffer_count) { + // Calculate length can be sent with available buffers + msgLength = global_cb_p->rom_apis_p->ROM_WL_calculate_length_to_send(global_cb_p, + sock_info->sock_type, + sock_info->current_available_buffer_count); + sock_info->current_available_buffer_count = 0; + } else { + // Subtract buffers required to send this packet + if (sock_info->current_available_buffer_count > buffers_required) { + sock_info->current_available_buffer_count -= buffers_required; + } else { + sock_info->current_available_buffer_count = 0; + } + } + + // Set expected response based on the callback + if (data_transfer_complete_handler != NULL) { +#ifdef RSI_UART_INTERFACE + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_UART_DATA_ACK; +#else + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_ASYNCHRONOUS; +#endif + } else { + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_TCP_ACK_INDICATION; + } + } else { +#ifdef RSI_UART_INTERFACE + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_UART_DATA_ACK; +#else + rsi_driver_cb->wlan_cb->expected_response = RSI_WLAN_RSP_ASYNCHRONOUS; +#endif + } + + // Send data send command + status = rsi_driver_send_data(sockID, (uint8_t *)msg, msgLength, destAddr); + + // Release mutex lock + RSI_MUTEX_UNLOCK(&rsi_driver_cb->wlan_cb->wlan_mutex); + + if (status == RSI_SUCCESS) { + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_EXIT_2, NETWORK, LOG_INFO); + return msgLength; + } else { +#ifdef RSI_WITH_OS + status = rsi_get_error(sockID); + rsi_set_os_errno(status); +#endif + SL_PRINTF(SL_SENDTO_ASYNC_NON_ROM_SOCK_ERROR_7, NETWORK, LOG_ERROR); + return RSI_SOCK_ERROR; + } +} +/*==============================================*/ +/** + * @brief Clear socket information + * @param[in] sockID - Socket descriptor ID + * @return Void + * + * + */ +/// @private +void rsi_clear_sockets_non_rom(int32_t sockID) +{ + SL_PRINTF(SL_CLEAR_SOCKET_NON_ROM_ENTRY, NETWORK, LOG_INFO); + int i; + int32_t sock_id = -1; + uint16_t port_number; + int32_t status = RSI_SUCCESS; + + // rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb; + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + if (sockID == RSI_CLEAR_ALL_SOCKETS) { + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + // Memset socket info + memset(&rsi_socket_pool[i], 0, sizeof(rsi_socket_info_t)); + } + } else if (rsi_socket_pool[sockID].sock_state == RSI_SOCKET_STATE_LISTEN) { + port_number = rsi_socket_pool[sockID].source_port; + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if ((rsi_socket_pool[i].source_port == port_number) && ((rsi_socket_pool[i].sock_type & 0xF) == SOCK_STREAM)) { + // Memset socket info + memset(&rsi_socket_pool[i], 0, sizeof(rsi_socket_info_t)); + rsi_wlan_socket_set_status(status, i); + // Wait on select semaphore + rsi_post_waiting_socket_semaphore(i); + } + } + + } else { + if (sockID < 0 || sockID >= NUMBER_OF_SOCKETS) { + return; + } + if ((rsi_socket_pool[sockID].ltcp_socket_type == RSI_LTCP_PRIMARY_SOCKET)) { + if (rsi_socket_pool[sockID].backlog_current_count) { + rsi_socket_pool[sockID].sock_state = RSI_SOCKET_STATE_LISTEN; + rsi_socket_pool[sockID].backlog_current_count--; + } + } else if (rsi_socket_pool[sockID].ltcp_socket_type == RSI_LTCP_SECONDARY_SOCKET) { + sock_id = rsi_get_primary_socket_id((uint8_t *)&rsi_socket_pool[sockID].source_port); + if (sock_id >= 0) { + // Decrease backlog current count + rsi_socket_pool[sock_id].backlog_current_count--; + } + // Memset socket info + memset(&rsi_socket_pool[sockID], 0, sizeof(rsi_socket_info_t)); + + } else { + // Memset socket info + memset(&rsi_socket_pool[sockID], 0, sizeof(rsi_socket_info_t)); + } + } +} +/** @} */ + +/** @addtogroup DRIVER10 +* @{ +*/ +/*==============================================*/ +/** + * @brief Post a socket semaphore which is on wait + * @param[in] sockID - Socket descriptor ID + * @return Void + * + */ +///@private +#ifndef RSI_SOCK_SEM_BITMAP +void rsi_post_waiting_socket_semaphore(int32_t sockID) +{ + if (rsi_socket_pool_non_rom[sockID].socket_wait_bitmap & BIT(0)) { + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].socket_sem); + } + if (rsi_socket_pool_non_rom[sockID].socket_wait_bitmap & BIT(1)) { + rsi_socket_pool_non_rom[sockID].recv_pending_bit |= BIT(1); + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].sock_recv_sem); + } + if (rsi_socket_pool_non_rom[sockID].socket_wait_bitmap & BIT(2)) { + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].sock_send_sem); + } + rsi_socket_pool_non_rom[sockID].socket_wait_bitmap = 0; +} +#else +void rsi_post_waiting_socket_semaphore(int32_t sockID) +{ + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].socket_sem); + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].sock_recv_sem); + rsi_semaphore_post(&rsi_socket_pool_non_rom[sockID].sock_send_sem); +} +#endif + +#endif +/** @} */ diff --git a/wiseconnect/sapi/network/socket/rsi_socket_rom.c b/wiseconnect/sapi/network/socket/rsi_socket_rom.c new file mode 100644 index 00000000..bafffa14 --- /dev/null +++ b/wiseconnect/sapi/network/socket/rsi_socket_rom.c @@ -0,0 +1,183 @@ +/******************************************************************************* +* @file rsi_socket_rom.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#ifndef ROM_WIRELESS + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Get the application socket descriptor from module’s socket descriptor. This is a non-blocking API. + * @param[in] global_cb_p - Pointer to the global control block + * @param[in] sock_id - Module's socket descriptor + * @return Positive value - Application socket descriptor \n + * @return Negative value - If socket is not found + */ +/// @private +int32_t ROM_WL_rsi_get_application_socket_descriptor(global_cb_t *global_cb_p, int32_t sock_id) +{ + int i; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if (rsi_socket_pool[i].sock_id == sock_id) { + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + return -1; + } + + return i; +} + +/*==============================================*/ +/** + * @brief Get socket descriptor from port_number. \n + * This is a non-blocking API. + * @param[in] global_cb_p - Pointer to the global control block + * @param[in] port_number - Port number + * @return Positive value - Socket descriptor \n + * @return Negative value - If socket is not found + * + */ +/// @private +int32_t ROM_WL_rsi_get_primary_socket_id(global_cb_t *global_cb_p, uint16_t port_number) +{ + int i; + + rsi_socket_info_t *rsi_socket_pool = global_cb_p->rsi_socket_pool; + + for (i = 0; i < NUMBER_OF_SOCKETS; i++) { + if ((rsi_socket_pool[i].source_port == port_number) + && (rsi_socket_pool[i].ltcp_socket_type == RSI_LTCP_PRIMARY_SOCKET)) { + break; + } + } + + if (i >= NUMBER_OF_SOCKETS) { + return -1; + } + return i; +} + +/*==============================================*/ +/** + * @brief Calculate number of buffers required for the data packet. \n + * This is a non-blocking API. + * @param[in] global_cb_p - Pointer to the global control block + * @param[in] type - Type of socket to create + * @param[in] length - Length of the message + * @return Number of buffers required for the data packet + */ +/// @private +uint8_t ROM_WL_calculate_buffers_required(global_cb_t *global_cb_p, uint8_t type, uint16_t length) +{ + // Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + + uint8_t header_size, buffers_required = 1; + uint16_t first_buffer_available_size, remaining_length; + + // Calculate header size including extra 2 bytes based on the prototype + if ((type & 0xF) == SOCK_STREAM) { + header_size = 56; + } else { + header_size = 44; + } + + // Increase header size by 20 for IPv6 case + if ((type >> 4) == AF_INET6) { + header_size += 20; + } + + remaining_length = length; + + first_buffer_available_size = (512 - header_size - 252); + + if (length <= first_buffer_available_size) { + return 1; + } + + remaining_length -= first_buffer_available_size; + + do { + buffers_required++; + if (remaining_length > 512) { + remaining_length -= 512; + } else { + remaining_length = 0; + } + + } while (remaining_length); + + return buffers_required; +} +/*==============================================*/ +/** + * @brief Calculate the length available in the buffers for the message. This is a non-blocking API. + * @param[in] global_cb_p - Pointer to the global control block + * @param[in] type - Type of the socket stream + * @param[in] buffers - Available buffers + * @return Length available in the buffers for message + */ +/// @private +uint16_t ROM_WL_calculate_length_to_send(global_cb_t *global_cb_p, uint8_t type, uint8_t buffers) +{ + // Added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(global_cb_p); + uint8_t header_size; + uint16_t length; + + // Calculate header size including extra 2 bytes based on the prototype + if ((type & 0xF) == SOCK_STREAM) { + header_size = 56; + } else { + header_size = 44; + } + + // Increase header size by 20 for IPv6 case + if ((type >> 4) == AF_INET6) { + header_size += 20; + } + + length = (512 - header_size - 252); + + if (buffers == 1) { + return length; + } + + buffers--; + + while (buffers) { + length += 512; + buffers--; + } + + return length; +} +#endif +/** @} */ diff --git a/wiseconnect/sapi/rtos/freertos_wrapper/port.c b/wiseconnect/sapi/rtos/freertos_wrapper/port.c new file mode 100644 index 00000000..c1369e6d --- /dev/null +++ b/wiseconnect/sapi/rtos/freertos_wrapper/port.c @@ -0,0 +1,17 @@ +#include "rsi_board_configuration.h" + +#if defined(__ARMCC_VERSION) +#if defined(RSI_ARM_CM4F) +#include "RVDS/ARM_CM4F/port.c" +#else +#error Unknown MCU type +#endif +#elif defined(__GNUC__) || defined(__clang__) +#if defined(RSI_ARM_CM4F) +#include "GCC/ARM_CM4F/port.c" +#elif defined(RSI_ARM_CM33) +#include "GCC/ARM_CM33_NTZ/non_secure/port.c" +#else +#error Unknown MCU type +#endif +#endif diff --git a/wiseconnect/sapi/rtos/freertos_wrapper/portmacro.h b/wiseconnect/sapi/rtos/freertos_wrapper/portmacro.h new file mode 100644 index 00000000..c687c14d --- /dev/null +++ b/wiseconnect/sapi/rtos/freertos_wrapper/portmacro.h @@ -0,0 +1,25 @@ +#include "rsi_board_configuration.h" + +#if defined(__ARMCC_VERSION) +#if defined(RSI_ARM_CM4F) +#include "RVDS/ARM_CM4F/portmacro.h" +#else +#error Unknown MCU type +#endif +#elif defined(__GNUC__) || defined(__clang__) +#if defined(RSI_ARM_CM4F) +#include "GCC/ARM_CM4F/portmacro.h" +#elif defined(RSI_ARM_CM33) +#include "GCC/ARM_CM33_NTZ/non_secure/portmacro.h" +#else +#error Unknown MCU type +#endif +#elif defined(__ICCARM__) +#if defined(RSI_ARM_CM4F) +#include "IAR/ARM_CM4F/portmacro.h" +#elif defined(RSI_ARM_CM33) +#include "IAR/ARM_CM33_NTZ/non_secure/portmacro.h" +#else +#error Unknown MCU type +#endif +#endif diff --git a/wiseconnect/sapi/rtos/freertos_wrapper/rsi_os_wrapper.c b/wiseconnect/sapi/rtos/freertos_wrapper/rsi_os_wrapper.c new file mode 100644 index 00000000..473416a6 --- /dev/null +++ b/wiseconnect/sapi/rtos/freertos_wrapper/rsi_os_wrapper.c @@ -0,0 +1,731 @@ +/******************************************************************************* +* @file rsi_os_wrapper.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#ifndef RSI_FREE_RTOS +#define RSI_FREE_RTOS +#include +#ifdef RSI_WITH_OS +/** + * Include files + * */ +#include +#include +#include +#include +#include +#include "rsi_wlan_non_rom.h" +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; + +/* For Remove sapi Warnings */ +void vPortSetupTimerInterrupt(void); + +/** @addtogroup RTOS +* @{ +*/ +/*==============================================*/ +/** + * @fn rsi_reg_flags_t rsi_critical_section_entry() + * @brief Enter critical section + * @param[in] None + * @return Interrupt status before entering critical section + * + */ +rsi_reg_flags_t rsi_critical_section_entry() +{ + // hold interrupt status before entering critical section + // disable interrupts + rsi_reg_flags_t xflags; + // hold interrupt status before entering critical section + // disable interrupts + xflags = 0; +#ifndef RSI_M4_INTERFACE + rsi_hal_intr_mask(); +#endif + taskENTER_CRITICAL(); + + // return stored interrupt status + return (xflags); +} + +/*==============================================*/ +/** + * @fn rsi_critical_section_exit(rsi_reg_flags_t xflags) + * @brief Exit critical section by restoring interrupts. + * @param[in] xflags - Interrupt status to restore interrupt on exit from critical section + * @return Void + * + * + * + */ + +void rsi_critical_section_exit(rsi_reg_flags_t xflags) +{ + //This statement is added only to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(xflags); + // restore interrupts while exiting critical section + taskEXIT_CRITICAL(); +#ifndef RSI_M4_INTERFACE + rsi_hal_intr_unmask(); +#endif +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex) + * @brief Create and initialize the mutex + * @param[in] mutex - Mutex handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + * + */ + +rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex) +{ + SemaphoreHandle_t *p_mutex = (SemaphoreHandle_t *)mutex; + if (p_mutex == NULL) { + return RSI_ERROR_IN_OS_OPERATION; + } + + *p_mutex = (SemaphoreHandle_t)xSemaphoreCreateMutex(); + + if (*p_mutex == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_IN_OS_OPERATION; + } + + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex) + * @brief Lock the mutex + * @param[in] mutex - Mutex handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex) +{ + uint32_t timeout_ms = 0; + + SemaphoreHandle_t *p_mutex = (SemaphoreHandle_t *)mutex; + if (mutex == NULL || *p_mutex == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + if (!timeout_ms) { + timeout_ms = portMAX_DELAY; + } + if (xSemaphoreTake(*p_mutex, timeout_ms) == pdPASS) { + return RSI_ERROR_NONE; + } + return RSI_ERROR_IN_OS_OPERATION; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_lock_from_isr(volatile rsi_mutex_handle_t *mutex) + * @brief Lock the mutex from ISR context + * @param[in] mutex - Mutex handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +void rsi_mutex_lock_from_isr(volatile rsi_mutex_handle_t *mutex) +{ + BaseType_t xTaskWokenByReceive = pdFALSE; + SemaphoreHandle_t *xSemaphore = (SemaphoreHandle_t *)mutex; + (void)xSemaphoreTakeFromISR(*xSemaphore, &xTaskWokenByReceive); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex) + * @brief Unlock the mutex + * @param[in] mutex - Mutex handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex) +{ + SemaphoreHandle_t *p_mutex = (SemaphoreHandle_t *)mutex; + if (mutex == NULL || *p_mutex == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + if (xSemaphoreGive(*p_mutex) == pdPASS) { + return RSI_ERROR_NONE; + } + return RSI_ERROR_IN_OS_OPERATION; +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_unlock_from_isr(volatile rsi_mutex_handle_t *mutex) + * @brief Unlock the mutex from ISR context + * @param[in] mutex - Mutex handle pointer + * @return None + * + */ +void rsi_mutex_unlock_from_isr(volatile rsi_mutex_handle_t *mutex) +{ + BaseType_t xTaskWokenByReceive = pdFALSE; + SemaphoreHandle_t *xSemaphore = (SemaphoreHandle_t *)mutex; + (void)xSemaphoreGiveFromISR(*xSemaphore, &xTaskWokenByReceive); +} +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex) + * @brief Destroy the mutex + * @param[in] mutex - Mutex handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex) +{ + SemaphoreHandle_t *p_mutex = (SemaphoreHandle_t *)mutex; + if (mutex == NULL || *p_mutex == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + vSemaphoreDelete(*p_mutex); + + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore,uint32_t count) + * @brief Create and initialize the semaphore instance + * @param[in] semaphore - Semaphore handle pointer + * @param[in] count - Resource count + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore, uint32_t count) +{ + UNUSED_PARAMETER(count); //This statement is added only to resolve compilation warning, value is unchanged + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL) { + return RSI_ERROR_IN_OS_OPERATION; + } + *p_semaphore = xSemaphoreCreateBinary(); + + if (*p_semaphore == NULL) { + return RSI_ERROR_IN_OS_OPERATION; + } + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore) + * @brief Destroy the semaphore instance + * @param[in] semaphore - Semaphore handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + */ +rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore) +{ + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL || *p_semaphore == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + vSemaphoreDelete(*p_semaphore); + + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore) + * @brief Check whether the semaphore is created and destroy, if created. + * @param[in] semaphore - Semaphore handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ + +rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore) +{ + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL || *p_semaphore == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_NONE; // returning success since semaphore does not exists + } + vSemaphoreDelete(*p_semaphore); + + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms ) + * @brief Wait for semaphore + * @param[in] semaphore - Semaphore handle pointer + * @param[in] time_ms - Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait till semaphore is acquired. + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ + +rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms) +{ + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL || *p_semaphore == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + if (!timeout_ms) { + timeout_ms = portMAX_DELAY; + } + if (xSemaphoreTake(*p_semaphore, timeout_ms) == pdPASS) { + return RSI_ERROR_NONE; + } + return RSI_ERROR_IN_OS_OPERATION; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore) + * @brief Release semaphore, which is acquired + * @param[in] semaphore - Semaphore handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ + +rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore) +{ + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL || *p_semaphore == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + if (xSemaphoreGive(*p_semaphore) == pdPASS) { + return RSI_ERROR_NONE; + } + return RSI_ERROR_IN_OS_OPERATION; +} + +/*====================================================*/ +/** + * @fn rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore) + * @brief Release semaphore, which is acquired from ISR context + * @param[in] semphore - Semaphore handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ + +rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore) +{ + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL || *p_semaphore == NULL) //Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + + if (xSemaphoreGiveFromISR(*p_semaphore, NULL) == pdPASS) { + return RSI_ERROR_NONE; + } + return RSI_ERROR_IN_OS_OPERATION; +} + +/*==============================================*/ +/* + * @fn rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore) + * @brief Reset the semaphore + * @param[in] semphore - Semaphore handle pointer + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ +rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore) +{ + SemaphoreHandle_t *p_semaphore = NULL; + p_semaphore = (SemaphoreHandle_t *)semaphore; + + if (semaphore == NULL || *p_semaphore == NULL) //!Note : FreeRTOS porting + { + return RSI_ERROR_INVALID_PARAM; + } + vSemaphoreDelete(*p_semaphore); + + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_task_create( rsi_task_function_t task_function,uint8_t *task_name, + uint32_t stack_size, void *parameters, + uint32_t task_priority,rsi_task_handle_t *task_handle) + * @brief Create OS task/thread + * @param[in] task_function - Pointer to function to be executed by created thread. \n + * @param[in] task_name - Name of the created task \n + * @param[in] stack_size - Stack size given to the created task \n + * @param[in] parameters - Pointer to the parameters to be passed to task function \n + * @param[in] task_priority - Task priority \n + * @param[in] task_handle - Task handle/instance created \n + * @return 0 - Success \n + * @return Negative Value - Failure + * + */ + +rsi_error_t rsi_task_create(rsi_task_function_t task_function, + uint8_t *task_name, + uint32_t stack_size, + void *parameters, + uint32_t task_priority, + rsi_task_handle_t *task_handle) +{ +#ifdef SAPIS_BT_STACK_ON_HOST + task_priority = 7; +#endif + if (pdPASS + == xTaskCreate(task_function, + (char const *)task_name, + stack_size, + parameters, + task_priority, + (TaskHandle_t *)task_handle)) { + return RSI_ERROR_NONE; + } + + return RSI_ERROR_IN_OS_OPERATION; +} + +/*==============================================*/ +/** + * @fn void rsi_task_destroy(rsi_task_handle_t *task_handle) + * @brief Destroy the task created + * @param[in] task_handle - Task handle/instance to be deleted + * @return Void + * + */ + +void rsi_task_destroy(rsi_task_handle_t *task_handle) +{ + vTaskDelete((TaskHandle_t)task_handle); +} + +/*==============================================*/ +/** + * @fn void rsi_os_task_delay(uint32_t timeout_ms) + * @brief Induce required delay in milli seconds + * @param[in] timeout_ms - Expected delay in milli seconds + * @return Void + */ +void rsi_os_task_delay(uint32_t timeout_ms) +{ + vTaskDelay(timeout_ms); +} + +/*==============================================*/ +/** + * @fn void rsi_start_os_scheduler() + * @brief Schedule the tasks created + * @param[in] None + * @return Void + */ +void rsi_start_os_scheduler() +{ + vTaskStartScheduler(); +} +/*==============================================*/ +/** + * @fn void rsi_setup_timer_os_interrupt() + * @brief Setup the systick timer to generate the tick interrupts at the required frequency + * @param[in] None + * @return void + */ +void rsi_setup_timer_os_interrupt() +{ + vPortSetupTimerInterrupt(); +} +/*==============================================*/ +/** + * @fn void rsi_set_os_errno(int32_t error) + * @brief Sets the OS error . + * @param[in] error - Error + * @return Void + */ +void rsi_set_os_errno(int32_t error) +{ + UNUSED_PARAMETER(error); //This statement is added only to resolve compilation warning, value is unchanged +} + +/*==============================================*/ +/** + * @fn rsi_base_type_t rsi_task_notify_wait(uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, uint32_t timeout) + * @brief Allow a task to wait with optional timeout + * @param[in] ulBitsToClearOnEntry - Bits set here will be cleared in the task’s notification value on entry to the function. + * @param[in] ulBitsToClearOnExit - Bits to clear on exit + * @param[in] pulNotificationValue - Used to pass out the task notification value. Optional parameter + * @param[in] timeout - Maximum amount of time the calling task should remain in blocked state + * @return 0 - Success \n + * @return Negative Value - Failure + */ +rsi_base_type_t rsi_task_notify_wait(uint32_t ulBitsToClearOnEntry, + uint32_t ulBitsToClearOnExit, + uint32_t *pulNotificationValue, + uint32_t timeout) +{ + rsi_base_type_t xResult; + const TickType_t xMaxBlockTime = pdMS_TO_TICKS(timeout); + + /* Wait to be notified of an interrupt. */ + xResult = xTaskNotifyWait(ulBitsToClearOnEntry, /* Don't clear bits on entry. */ + ulBitsToClearOnExit, /* Clear all bits on exit. */ + pulNotificationValue, /* Stores the notified value. */ + xMaxBlockTime); + + return xResult; +} + +/*==============================================*/ +/** + * @fn rsi_base_type_t rsi_task_notify(rsi_task_handle_t xTaskToNotify, uint32_t ulValue) + * @brief Notify a task + * @param[in] xTaskToNotify - The handle of the task to which the notification is being sent + * @param[in] ulValue - How ulValue is used is dependent on the eNotifyAction value + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +rsi_base_type_t rsi_task_notify(rsi_task_handle_t xTaskToNotify, uint32_t ulValue) +{ + // eAction - an enumerated type that specifies how to update the receiving task’s notification value + eNotifyAction eAction = eSetBits; + if (xTaskToNotify != NULL) { + return xTaskNotify(xTaskToNotify, ulValue, (eNotifyAction)eAction); + } else { + return -1; + } +} + +/*==============================================*/ +/** + * @fn rsi_base_type_t rsi_task_notify_from_isr(rsi_task_handle_t xTaskToNotify, uint32_t ulValue, rsi_base_type_t *pxHigherPriorityTaskWoken ) + * @brief Notify a task from ISR context + * @param[in] xTaskToNotify - The handle of the task to which the notification is being sent + * @param[in] ulValue - How ulValue is used is dependent on the eNotifyAction value + * @param[in] pxHigherPriorityTaskWoken - Sets,if sending the notification caused a task to unblock, and the unblocked task has a priority higher than the currently running task. + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +rsi_base_type_t rsi_task_notify_from_isr(rsi_task_handle_t xTaskToNotify, + uint32_t ulValue, + rsi_base_type_t *pxHigherPriorityTaskWoken) +{ + // eAction - an enumerated type that specifies how to update the receiving task’s notification value + eNotifyAction eAction = eSetBits; + + if (xTaskToNotify != NULL) { + return xTaskNotifyFromISR(xTaskToNotify, ulValue, (eNotifyAction)eAction, pxHigherPriorityTaskWoken); + } else { + return -1; + } +} + +/*==============================================*/ +/** + * @fn uint32_t rsi_os_task_notify_take( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) + * @brief Allow a task in wait in blocked state for its notification value + * @param[in] xClearCountOnExit - Based on this value calling task notification value will be decremented/zero + * @param[in] xTicksToWait - Maximum amount of time calling task should remain in blocked state + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +uint32_t rsi_os_task_notify_take(BaseType_t xClearCountOnExit, TickType_t xTicksToWait) +{ + return ulTaskNotifyTake(xClearCountOnExit, xTicksToWait); +} + +/*==============================================*/ +/** + * @fn BaseType_t rsi_os_task_notify_give(rsi_task_handle_t xTaskToNotify) + * @brief Notify to a task + * @param[in] xTaskToNotify - Task handle to notify + * @return Task notification value - Success\n + * @return -1 - Failure + */ +BaseType_t rsi_os_task_notify_give(rsi_task_handle_t xTaskToNotify) +{ + if (xTaskToNotify != NULL) { + return xTaskNotifyGive(xTaskToNotify); + } else { + return -1; + } +} + +#ifdef RSI_WLAN_ENABLE + +/*==============================================*/ +/** + * @fn int32_t rsi_get_error(int32_t sockID) + * @brief Get WLAN status + * @param[in] sockID - Socket ID + * @return WLAN status + */ +/// @private +int32_t rsi_get_error(int32_t sockID) +{ + if (rsi_socket_pool_non_rom[sockID].socket_status == 0xFF87 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB38) { + return RSI_ERROR_ECONNREFUSED; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0x00D2) { + return RSI_ERROR_ECONNABORTED; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xFF6C + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF6A + || rsi_socket_pool_non_rom[sockID].socket_status == RSI_ERROR_RESPONSE_TIMEOUT + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBBD6) { + return RSI_ERROR_ETIMEDOUT; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0x0021 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF82 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF74 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB27 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF80 + || rsi_socket_pool_non_rom[sockID].socket_status == 0x00D1) { + return RSI_ERROR_EACCES; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0x00D3 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFFFE) { + return RSI_ERROR_EPERM; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xFF7E + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBBED + || rsi_socket_pool_non_rom[sockID].socket_status == 0x003E + || rsi_socket_pool_non_rom[sockID].socket_status == 0x0030 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB3E) { + return RSI_ERROR_EMSGSIZE; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xFF86) { + return RSI_ERROR_EBADF; + } else if ((rsi_socket_pool_non_rom[sockID].socket_status == 0x0015) + || (rsi_socket_pool_non_rom[sockID].socket_status == 0x0025)) { + return RSI_ERROR_EAGAIN; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xBB22 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB42) { + return RSI_ERROR_EISCONN; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xFFFF + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB50) { + return RSI_ERROR_ENOTCONN; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xBB33 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB23 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB45 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB46 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB50) { + return RSI_ERROR_EADDRINUSE; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == 0xBB36) { + return RSI_ERROR_ENOTSOCK; + } else if (rsi_socket_pool_non_rom[sockID].socket_status == RSI_ERROR_PKT_ALLOCATION_FAILURE) { + return RSI_ERROR_ENOMEM; + } else + return RSI_SOCK_ERROR; +} + +#endif + +/*==============================================*/ +/** + * @fn void *rsi_malloc (uint32_t size) + * @brief Allocate memory from the buffer which is maintained by freeRTOS. + * @param[in] size - Required bytes in size + * @return Void + */ + +void *rsi_malloc(uint32_t size) +{ + if (size == 0) { + return NULL; + } else { + return pvPortMalloc(size); + } +} + +/*==============================================*/ +/** + * @fn void rsi_free (void *ptr) + * @brief Free the memory pointed by 'ptr' + * @param[in] ptr - starting address of the memory to be freed + * @return Void + */ +void rsi_free(void *ptr) +{ + if (ptr == NULL) { + // do nothing + } else { + vPortFree(ptr); + } +} +/*==============================================*/ +/** + * @fn void rsi_vport_enter_critical(void) + * @brief Enter into critical section + * @param[in] void + * @return Void + */ +void rsi_vport_enter_critical(void) +{ + vPortEnterCritical(); +} + +/*==============================================*/ +/** + * @fn void rsi_vport_exit_critical(void) + * @brief Enter exit section + * @param[in] void + * @return Void + */ + +void rsi_vport_exit_critical(void) +{ + vPortExitCritical(); +} + +/*==============================================*/ +/** + * @fn void rsi_task_suspend(rsi_task_handle_t *task_handle) + * @brief Exit critical section + * @param[in] task_handle - Task handle to be suspended + * @return Void + */ +void rsi_task_suspend(rsi_task_handle_t *task_handle) +{ + vTaskSuspend((TaskHandle_t)task_handle); +} +#endif +#endif +/** @} */ diff --git a/wiseconnect/sapi/sapi.mk b/wiseconnect/sapi/sapi.mk new file mode 100644 index 00000000..18a55017 --- /dev/null +++ b/wiseconnect/sapi/sapi.mk @@ -0,0 +1,334 @@ +# Makefile +ifndef PROGNAME +$(error Must define PROGNAME) +endif + +ifndef RSI_SDK_PATH +$(error Must define RSI_SDK_PATH that is location of SDK) +endif + +# Try identify the platform from the MAKECMDGOALS +MATCHED_PLATFORMS:=$(wildcard $(addprefix $(RSI_SDK_PATH)/platforms/,$(MAKECMDGOALS))) +ifeq ($(MATCHED_PLATFORMS),) +$(info Available platforms:) +$(foreach d,$(notdir $(wildcard $(RSI_SDK_PATH)/platforms/*)),$(info - $d)) +$(error Must provide name of platform as an argument. See above for options) +else +ifeq ($(words $(MATCHED_PLATFORMS)),1) +PLATFORM :=$(subst $(RSI_SDK_PATH)/platforms/,,$(MATCHED_PLATFORMS)) +else +$(error More than one platform found: $(MATCHED_PLATFORMS)) +endif +endif + +# Include the platform makefile +include $(RSI_SDK_PATH)/platforms/$(PLATFORM)/$(PLATFORM).mk + + +# Try identify the bus +ifeq ($(words $(VALID_BUSES)),1) +BUS=$(VALID_BUSES) +else +BUS:=$(filter $(MAKECMDGOALS),$(VALID_BUSES)) +ifeq ($(words $(BUS)),0) +$(error No valid bus found. Please select from the following: $(VALID_BUSES)) +endif +ifneq ($(words $(BUS)),1) +$(error Too many buses. Please select from the following: $(BUS)) +endif +endif + +.PHONY: $(BUS) + +INCLUDES += -I . \ + -I $(RSI_SDK_PATH)/sapi/include \ + -I $(RSI_SDK_PATH)/sapi/network/protocols + +CFLAGS += -g -Wall $(INCLUDES) -Os + +# Interface options +uart_BUS_CFLAGS += -D RSI_UART_INTERFACE +spi_BUS_CFLAGS += -D RSI_SPI_INTERFACE +sdio_BUS_CFLAGS += -D RSI_SDIO_INTERFACE + +# Enable debug prints by default +CFLAGS+= -D RSI_ENABLE_DEBUG_PRINT -D RSI_DEBUG_PRINTS -D RSI_WLAN_ENABLE -D WISECONNECT + +CFLAGS+= -D RSI_SAMPLE_HAL +CFLAGS+= -D RSI_IPV6_ENABLE +CFLAGS+= -D APIS_ROM +CFLAGS+= -D APIS_NON_ROM + +wlan_CFLAGS += -D RSI_WLAN_API_ENABLE +mqtt_CFLAGS += -D ASYNC_MQTT \ + -I $(RSI_SDK_PATH)/third_party/mqtt_client/src \ + -I $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src +ble_CFLAGS += -D RSI_BLE_ENABLE +bt_CFLAGS += -D RSI_BT_ENABLE +prop_protocol_CFLAGS += -D RSI_PROP_PROTOCOL_ENABLE +zigbee_CFLAGS += -D RSI_ZB_ENABLE -D ZB_DEBUG +zigbee_mac_CFLAGS += -D ZB_MAC_API +homekit_CFLAGS += -D RSI_HOMEKIT_APP +puf_CFLAGS += -D RSI_PUF_ENABLE +crypto_CFLAGS += -D RSI_CRYPTO_ENABLE +aws_CFLAGS += -I $(RSI_SDK_PATH)/third_party/aws_sdk/include \ + -I $(RSI_SDK_PATH)/third_party/aws_sdk/platform/silabs/inc +certificates_CFLAGS += -I $(RSI_SDK_PATH)/resources/certificates +firmware_udpate_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +freertos_CFLAGS += -I $(RSI_SDK_PATH)/third_party/freertos/include \ + -I $(RSI_SDK_PATH)/third_party/freertos/portable/GCC/ARM_CM4F +firmware_update_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +mqtt_client_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols \ + -I $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src \ + -I $(RSI_SDK_PATH)/third_party/mqtt_client/src +http_server_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols/http_server +azure_CFLAGS += -I $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/inc \ + -I $(RSI_SDK_PATH)/third_party/azure_sdk/src/deps/umock-c/inc \ + -I $(RSI_SDK_PATH)/third_party/azure_sdk/src/deps/parson \ + -I $(RSI_SDK_PATH)/third_party/azure_sdk/src/deps/azure-macro-utils-c/inc \ + -I $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/inc \ + -I $(RSI_SDK_PATH)/third_party/azure_sdk/src/umqtt/inc \ + -I $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/inc + +multicast_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +pop3_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +smtp_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +sntp_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +web_socket_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +http_client_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +ftp_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols +sockets_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/socket + +WLAN_COMMON_SOURCES += $(RSI_SDK_PATH)/sapi/driver/rsi_setregion_countryinfo.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_nwk.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_wlan.c \ + $(RSI_SDK_PATH)/sapi/network/socket/rsi_socket.c \ + $(RSI_SDK_PATH)/sapi/network/socket/rsi_socket_rom.c \ + $(RSI_SDK_PATH)/sapi/wlan/rsi_wlan_apis.c + +sockets_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_dns.c \ + $(RSI_SDK_PATH)/sapi/network/protocols/rsi_emb_mqtt_client.c \ + $(RSI_SDK_PATH)/sapi/network/protocols/rsi_raw_data.c \ + $(RSI_SDK_PATH)/sapi/network/protocols/rsi_http_ota_fw_up.c \ + $(RSI_SDK_PATH)/sapi/network/protocols/rsi_dhcp_user_class.c + +ipv6_utils_SOURCES += $(RSI_SDK_PATH)/utilities/ipv6_utils/inet6.c \ + +logging_SOURCES += $(RSI_SDK_PATH)/sapi/logging/sl_app_logging.c \ + $(RSI_SDK_PATH)/sapi/logging/sleep_wakeup_logging.c \ + $(RSI_SDK_PATH)/sapi/logging/sl_fw_logging.c \ + $(RSI_SDK_PATH)/utilities/advanced_logging/firmware_logging/firmware_logging_utils.c \ + +firmware_update_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_firmware_upgradation.c + + +http_server_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/http_server/rsi_http_server.c \ + $(RSI_SDK_PATH)/sapi/network/protocols/http_server/rsi_json_handlers.c + +ftp_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_ftp.c + + +http_client_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_http_client.c + +mdns_CFLAGS += -I $(RSI_SDK_PATH)/sapi/network/protocols \ + -I $(RSI_SDK_PATH)/sapi/network/protocols/mdnsd_records +mdns_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_mdnsd.c \ + $(RSI_SDK_PATH)/sapi/network/protocols/mdnsd_records/rsi_mdnsd_records.c + +multicast_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_multicast.c +pop3_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_pop3_client.c +smtp_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_smtp_client.c +sntp_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_sntp_client.c +web_socket_SOURCES += $(RSI_SDK_PATH)/sapi/network/protocols/rsi_web_socket.c + +mqtt_client_SOURCES = $(RSI_SDK_PATH)/sapi/network/protocols/rsi_mqtt_client.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTClient.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTT_sapi_wrappers.c \ + $(mqtt_packet_SOURCES) + +mqtt_packet_SOURCES = $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTConnectClient.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTDeserializePublish.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTFormat.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTPacket.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTSerializePublish.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTSubscribeClient.c \ + $(RSI_SDK_PATH)/third_party/mqtt_client/src/MQTTPacket/src/MQTTUnsubscribeClient.c + +aws_SOURCES = $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client_connect.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client_common_internal.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client_subscribe.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client_publish.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_shadow_records.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_shadow_json.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/jsmn.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_json_utils.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_shadow_actions.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client_yield.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_mqtt_client_unsubscribe.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/src/aws_iot_shadow.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/platform/silabs/src/network_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/aws_sdk/platform/silabs/src/timer.c \ + $(mqtt_packet_SOURCES) + +# Only include FreeRTOS for embedded platforms +ifeq ($(filter $(PLATFORM),linux),) +freertos_SOURCES = $(RSI_SDK_PATH)/sapi/rtos/freertos_wrapper/rsi_os_wrapper.c \ + $(RSI_SDK_PATH)/third_party/freertos/croutine.c \ + $(RSI_SDK_PATH)/third_party/freertos/event_groups.c \ + $(RSI_SDK_PATH)/third_party/freertos/list.c \ + $(RSI_SDK_PATH)/third_party/freertos/queue.c \ + $(RSI_SDK_PATH)/third_party/freertos/stream_buffer.c \ + $(RSI_SDK_PATH)/third_party/freertos/tasks.c \ + $(RSI_SDK_PATH)/third_party/freertos/timers.c \ + $(RSI_SDK_PATH)/third_party/freertos/portable/GCC/ARM_CM4F/port.c \ + $(RSI_SDK_PATH)/third_party/freertos/portable/MemMang/heap_4.c +endif + +COMMON_SOURCES = $(RSI_SDK_PATH)/sapi/common/rsi_common_apis.c \ + $(RSI_SDK_PATH)/sapi/common/rsi_device_init_apis.c \ + $(RSI_SDK_PATH)/sapi/common/rsi_apis_rom.c \ + $(RSI_SDK_PATH)/sapi/common/rsi_apis_non_rom.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_driver.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_driver_event_handlers.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_events.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_os_none.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_pkt_mgmt.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_queue.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_device_init.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_scheduler.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_utils.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_timer.c \ + $(RSI_SDK_PATH)/sapi/driver/device_interface/spi/rsi_spi_frame_rd_wr.c \ + $(RSI_SDK_PATH)/sapi/driver/device_interface/spi/rsi_spi_functs.c \ + $(RSI_SDK_PATH)/sapi/driver/device_interface/spi/rsi_spi_iface_init.c \ + $(RSI_SDK_PATH)/sapi/driver/device_interface/spi/rsi_spi_mem_rd_wr.c \ + $(RSI_SDK_PATH)/sapi/driver/device_interface/spi/rsi_spi_reg_rd_wr.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_iap.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_common.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_scheduler_rom.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_pkt_mgmt_rom.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_utils_rom.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_queue_rom.c \ + $(RSI_SDK_PATH)/sapi/driver/rsi_events_rom.c \ + $(WLAN_COMMON_SOURCES) + +zigbee_SOURCES = $(ZB_CORE_SRC)/rsi_zb.c \ + $(ZB_CORE_SRC)/rsi_zb_utility.c \ + $(RSI_SDK_PATH)sapi/hal/rsi_timer.c \ + $(ZB_REF_APPS_SRC)/rsi_zb_apis.c + +zigbee_mac_SOURCES = $(ZB_MAC_SRC)/rsi_zigb_mac_apis.c + +BT_COMMON_SOURCES = $(RSI_SDK_PATH)/sapi/driver/rsi_bt_ble.c \ + $(RSI_SDK_PATH)/sapi/bluetooth/rsi_bt_common_apis.c + +ble_SOURCES = $(RSI_SDK_PATH)/sapi/bluetooth/rsi_ble_gap_apis.c \ + $(RSI_SDK_PATH)/sapi/bluetooth/rsi_ble_gatt_apis.c \ + $(BT_COMMON_SOURCES) + +ifeq ($(prop_protocol),1) +PROP_PROTOCOL_SOURCES = $(RSI_SDK_PATH)/sapi/prop_protocol/rsi_prop_protocol_apis.c +endif + +bt_SOURCES = $(RSI_SDK_PATH)/sapi/bluetooth/rsi_bt_gap_apis.c \ + $(RSI_SDK_PATH)/sapi/bluetooth/rsi_bt_spp_apis.c \ + $(RSI_SDK_PATH)/sapi/bluetooth/rsi_bt_a2dp_apis.c \ + $(RSI_SDK_PATH)/sapi/bluetooth/rsi_bt_avrcp_apis.c \ + $(BT_COMMON_SOURCES) + +crypto_SOURCES = $(RSI_SDK_PATH)/sapi/crypto/rsi_crypto.c + +azure_SOURCES = $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_client_core_ll.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_device_client_ll.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_message.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_client_authorization.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_client_diagnostic.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_client_ll_uploadtoblob.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothubtransportmqtt.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/blob.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothubtransport_mqtt_common.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_transport_ll_private.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/iothub_client/src/iothub_client_retry_control.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/string_tokenizer.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/singlylinkedlist.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/doublylinkedlist.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/constbuffer.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/strings.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/buffer.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/map.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/vector.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/httpapiex.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/httpapiexsas.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/httpheaders.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/urlencode.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/crt_abstractions.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/xlogging.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/azure_base64.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/sastoken.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/xio.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/optionhandler.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/http_proxy_io.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/consolelogger.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/hmacsha256.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/hmac.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/usha.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/sha1.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/sha224.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/sha384-512.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/src/string_token.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/c-utility/adapters/httpapi_compact.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/deps/parson/parson.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/agenttime_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/lock_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/platform_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/socketio_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/threadapi_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/tickcounter_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/platform/silabs/src/tlsio_openssl_sapi_wrapper.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/umqtt/src/mqtt_client.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/umqtt/src/mqtt_message.c \ + $(RSI_SDK_PATH)/third_party/azure_sdk/src/umqtt/src/mqtt_codec.c + +# $1 is the list of SDK source files +# $2 is file extension to append +define MAP_SDK_SOURCE +$(addsuffix .$2,$(addprefix output/,$(subst $(RSI_SDK_PATH)/,sdk/,$(sort $(1))))) +endef + +# $1 is the list of application source files +# $2 is file extension to append +define MAP_APPLICATION_SOURCE +$(addsuffix .$2,$(addprefix output/app/,$(1))) +endef + +# Include all existing .d dependency files +$(eval -include $(call MAP_APPLICATION_SOURCE, $(APPLICATION_SOURCES),d)) +$(eval -include $(call MAP_SDK_SOURCE, $(COMMON_SOURCES) $($(BUS)_BUS_SOURCES) $(foreach f,$(SDK_FEATURES),$($(f)_SOURCES)),d)) + +# Recipe to compile SDK source files +output/sdk/%.o: $(RSI_SDK_PATH)/% | output/sdk/%.directory + @echo $< : $@ + $(CC) $(CFLAGS) $(foreach f,$(SDK_FEATURES),$($(f)_CFLAGS)) $(LINKER_FLAGS) -o $@ -c $< + $(CC) $(CFLAGS) $(foreach f,$(SDK_FEATURES),$($(f)_CFLAGS)) $(LINKER_FLAGS) -MD -o $@ -c $< + +# Recipe to compile application source files +output/app/%.o: % | output/app/%.directory + @echo $< : $@ + $(CC) $(CFLAGS) $(foreach f,$(SDK_FEATURES),$($(f)_CFLAGS)) $(LINKER_FLAGS) -o $@ -c $< + $(CC) $(CFLAGS) $(foreach f,$(SDK_FEATURES),$($(f)_CFLAGS)) $(LINKER_FLAGS) -MD -o $@ -c $< + + +# Recipe to create directories +%.directory: + @mkdir -p $(dir $@) + +all: $(PROGNAME)$(PROG_EXTENSION) + @echo Building $(PROGNAME)$(PROG_EXTENSION) + +$(PROGNAME)$(PROG_EXTENSION): $(call APPLICATION_SOURCE_TO_OBJECTS, $(APPLICATION_SOURCES)) $(call SDK_SOURCE_TO_OBJECTS, $(COMMON_SOURCES) $($(BUS)_BUS_SOURCES) $(foreach f,$(SDK_FEATURES),$($(f)_SOURCES))) +$(PROGNAME)$(PROG_EXTENSION): $(call MAP_APPLICATION_SOURCE,$(APPLICATION_SOURCES),o) $(call MAP_SDK_SOURCE,$(COMMON_SOURCES) $($(BUS)_BUS_SOURCES) $(foreach f,$(SDK_FEATURES),$($(f)_SOURCES)),o) + @echo Linking $@ + $(CC) $(CFLAGS) $($(BUS)_BUS_CFLAGS) $(foreach f,$(SDK_FEATURES),$($(f)_CFLAGS)) $(LINKER_FLAGS) -o $@ $^ $(LIBS) + @echo "BUS selected is $(BUS)" diff --git a/wiseconnect/sapi/wlan/rsi_wlan_apis.c b/wiseconnect/sapi/wlan/rsi_wlan_apis.c new file mode 100644 index 00000000..535b13da --- /dev/null +++ b/wiseconnect/sapi/wlan/rsi_wlan_apis.c @@ -0,0 +1,7825 @@ +/******************************************************************************* +* @file rsi_wlan_apis.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +#include "rsi_driver.h" +#include "rsi_wlan_non_rom.h" +#define GAIN_TABLE_MAX_PAYLOAD_LEN 128 + +extern struct wpa_scan_results_arr *scan_results_array; + +/** @addtogroup WLAN +* @{ +*/ + +#ifdef PROCESS_SCAN_RESULTS_AT_HOST +/*==============================================*/ +/** + * @brief Sort the scan results in the order of RSSI. + * @param[in] scan_results_array - Contains the array of scan results that need to be sorted. + * @return Void + * @note **Precondition** - \ref rsi_wlan_scan_with_bitmap_options() API needs to be called before this API. + */ +void rsi_sort_scan_results_array_based_on_rssi(struct wpa_scan_results_arr *scan_results_array) +{ + SL_PRINTF(SL_SORT_SCAN_RESULTS_ENTRY, WLAN, LOG_INFO); + uint16_t i = 0, j = 0; + struct wpa_scan_res temp; + memset(&temp, 0, sizeof(struct wpa_scan_res)); + if (scan_results_array != NULL) { + for (i = 0; i < scan_results_array->num; i++) { + for (j = 0; j < ((scan_results_array->num) - i - 1); j++) { + if (scan_results_array->res[j].level < scan_results_array->res[j + 1].level) { + memcpy(&temp, &(scan_results_array->res[j]), sizeof(struct wpa_scan_res)); + memcpy(&(scan_results_array->res[j]), &(scan_results_array->res[j + 1]), sizeof(struct wpa_scan_res)); + memcpy(&(scan_results_array->res[j + 1]), &temp, sizeof(struct wpa_scan_res)); + } + } + } + } + SL_PRINTF(SL_SORT_SCAN_RESULTS_EXIT, WLAN, LOG_INFO); +} +#endif +/** @addtogroup WLAN +* @{ +*/ +/*==============================================*/ +/** + * @fn int32_t rsi_config_timeout(uint32_t timeout_bitmap,uint16_t timeout_value) + * @brief This API is used to set timeouts. \n This is a blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] timeout_type - It is used to identify which timeout to be set.\n + * if timeout_type is + * 1 - set for association and authentication timeout request in ms. + * 2 - set for the each channel active scan time in ms + * 3 - is set for the WLAN keep alive time in seconds + * @param[in] timeout_value - timeout value to be set. + * @note Packet is sent as Wlan Keep alive before \ref rsi_config_ipaddress() \n + * After \ref rsi_config_ipaddress() it is sent as gratuitous ARP. + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_config_timeout(uint32_t timeout_type, uint16_t timeout_value) +{ + int32_t status = RSI_SUCCESS; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + uint32_t timeout_bitmap = 0; + + // check whether valid timeout_type is given or not + if (timeout_type != AUTH_ASSOC_TIMEOUT && timeout_type != CHANNEL_ACTIVE_SCAN_TIMEOUT + && timeout_type != KEEP_ALIVE_TIMEOUT) { + return RSI_ERROR_INVALID_PARAM; + } + + // check whether module is in valid state range or not + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE || wlan_cb->state >= RSI_WLAN_STATE_INIT_DONE) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + + if (status == RSI_SUCCESS) { + + timeout_bitmap = BIT(timeout_type - 1); + + status = send_timeout(timeout_bitmap, timeout_value); + + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // return wlan command error + return status; + } + + // Return the status + return status; +} + +/*==============================================*/ +/** + * @fn int32_t send_timeout(uint32_t timeout_bitmap,uint16_t timeout_value) + * @brief This API is used to set timeouts. \n This is a blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] timeout_type - It is used to identify which timeout to be set.\n + * if timeout_type is + * 1 - set for association and authentication timeout request in ms. + * 2 - set for the each channel active scan time in ms + * 3 - is set for the WLAN keep alive time in seconds + * @param[in] timeout_value - timeout value to be set. + * @note Packet is sent as Wlan Keep alive before \ref rsi_config_ipaddress() \n + * After \ref rsi_config_ipaddress() it is sent as gratuitous ARP. + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ +int32_t send_timeout(uint32_t timeout_bitmap, uint16_t timeout_value) +{ + int32_t status = RSI_SUCCESS; + + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + rsi_pkt_t *pkt = NULL; + + rsi_req_timeout_t *rsi_timeout = NULL; + + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_timeout_t)); + + rsi_timeout = (rsi_req_timeout_t *)pkt->data; + + // Timeout Bitmap + rsi_uint32_to_4bytes(rsi_timeout->timeout_bitmap, timeout_bitmap); + + // Timeout value + rsi_uint16_to_2bytes(rsi_timeout->timeout_value, timeout_value); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // send configure timeout command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_TIMEOUT, pkt); + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_TIMEOUT_RESPONSE_WAIT_TIME); + // get wlan/network command response status + status = rsi_wlan_get_status(); + // Return the status + + return status; +} +/*==============================================*/ +/** + * @brief Scan surrounding access points and post scan response. You can call this API to get the scan results. This is a blocking API. + * @param[in] ssid - SSID of an access point to connect. \n SSID should be less than or equal to 32 bytes. \n + * Note: SSID is a null terminated string. + * @param[in] chno - Channel number of the access point. + * @param[out] result - Buffer address provided by the application to fill the scan response. + * @param[in] length - Length of the resulting buffer measured in bytes to hold scan results.\n + * Size of structure \ref rsi_rsp_scan_t is 54 bytes.\n + * Length for storing one scan result is sizeof( \ref rsi_scan_info_t), which is 44 bytes. \n + * Maximum of 11 scan results will be returned by the module, \n + * in this case, length should be configured as 8 + 11*sizeof( \ref rsi_scan_info_t). + * @param[in] scan_bitmap - Scan bitmap options. \n + * BIT[0] (QUICK SCAN feature) - It is valid only if channel number and ssid is given. \n + * BIT[1] (SCAN RESULTS TO HOST) - When it is enabled additional scan results are given to host. \n + * After getting scan results, host has to issue another scan request by disabling this bit in scan feature bitmap in same API \n + * or call \ref rsi_wlan_scan API before issuing join command. + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * + */ +int32_t rsi_wlan_scan_with_bitmap_options(int8_t *ssid, + uint8_t chno, + rsi_rsp_scan_t *result, + uint32_t length, + uint32_t scan_bitmap) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_SCAN_BITMAP_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE || wlan_cb->state >= RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SCAN_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)result; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + + // Call async scan to perform actual scan + status = rsi_wlan_scan_async_with_bitmap_options(ssid, chno, scan_bitmap, NULL); + + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_BITMAP_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR); + return status; + } + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_SCAN_WITH_BITMAP_RESPONSE_WAIT_TIME); + + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SCAN_BITMAP_WLAN_COMMAND_ERROR, WLAN, LOG_INFO, "status: %4x", status); + + return status; + } + // Return status + SL_PRINTF(SL_WLAN_SCAN_BITMAP_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Scan available access points and post scan response to application. + * Application must call this API to get the scan results. + * This is a non-blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] ssid - SSID of an access point to connect. \n + * SSID should be less than or equal to 32 bytes. + * @param[in] chno - Channel number of the access point. + * @param[in] bitmap - Scan feature bitmap \n + * BIT[0] (QUICK SCAN feature) - It is valid only if channel number and ssid is given. \n + * BIT[1] (SCAN RESULTS TO HOST) - When it is enabled additional scan results + * are given to host. \n After getting scan results, host has to issue another + * scan request by disabling this bit in scan feature bitmap in same api + * or call \ref rsi_wlan_scan api \n before issuing join command. + * @param[out] status - Response status + * @param[out] buffer - Buffer address provided by the application to fill the scan response. + * @param[out] length - Length of the response buffer measured + * in bytes to hold scan results. \n Size of structure + * \ref rsi_rsp_scan_t is 54 bytes. + * Length for storing one scan result is + * sizeof( \ref rsi_scan_info_t), which is 46 bytes. \n + * Maximum of 11 scan results will be returned by the + * module, \n in this case, length should be configured + * as 8 + 11*sizeof( \ref rsi_scan_info_t). + * @return 0 - Success \n + * Non-Zero Value - Failure + * + */ + +int32_t rsi_wlan_scan_async_with_bitmap_options(int8_t *ssid, + uint8_t chno, + uint32_t bitmap, + void (*scan_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)) + +{ + rsi_pkt_t *pkt = NULL; + rsi_req_scan_t *scan; + int32_t status = RSI_SUCCESS; + int32_t allow = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ENTRY, WLAN, LOG_INFO); + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + +#ifdef PROCESS_SCAN_RESULTS_AT_HOST + if (bitmap & RSI_SCAN_RESULTS_TO_HOST) { + memset(scan_results_array, 0, sizeof(struct wpa_scan_results_arr)); + rsi_wlan_cb_non_rom->scan_results_to_host = 1; + } +#endif + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE || wlan_cb->state >= RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + if (scan_response_handler != NULL) { + allow = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + } + if (allow == RSI_SUCCESS) { + switch (wlan_cb->state) { + case RSI_WLAN_STATE_OPERMODE_DONE: { + if (wlan_cb->field_valid_bit_map & RSI_SET_MAC_BIT) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_mac_address_t)); + + // Memcpy data + memcpy(&pkt->data, wlan_cb->mac_address, sizeof(rsi_req_mac_address_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set MAC command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_MAC_ADDRESS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_MAC_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR); + return status; + } + } +#if HE_PARAMS_SUPPORT + status = rsi_wlan_11ax_config(GUARD_INTERVAL); + if (status != RSI_SUCCESS) { + return status; + } +#endif + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_band_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send band command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BAND, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BAND_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR); + return status; + } + } + // No break + // Fall through + case RSI_WLAN_STATE_BAND_DONE: { + +#if RSI_TIMEOUT_SUPPORT + + status = send_timeout(RSI_TIMEOUT_BIT_MAP, RSI_TIMEOUT_VALUE); + if (status != RSI_SUCCESS) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_3, WLAN, LOG_ERROR); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // Send init command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_INIT, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_INIT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_4, WLAN, LOG_ERROR); + return status; + } +#if RSI_SET_REGION_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_5, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // Send set region command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_5, WLAN, LOG_ERROR); + return status; + } +#endif +#if RSI_SET_REGION_AP_SUPPORT + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE) { + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_ap_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send set region AP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION_AP, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_AP_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + return status; + } + } +#endif + } + // No break + // Fall through + case RSI_WLAN_STATE_SCAN_DONE: + case RSI_WLAN_STATE_INIT_DONE: + case RSI_WLAN_STATE_CONNECTED: { +#if RSI_WLAN_CONFIG_ENABLE + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_6, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // Send Configuration request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CONFIG, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WLAN_CONFIG_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_ERROR_IN_SENDING_COMMAND_6, WLAN, LOG_ERROR); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_PKT_ALLOCATION_FAILURE_7, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Fill SCAN parameters + scan = (rsi_req_scan_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_scan_t)); + + // Copy the channel number + rsi_uint32_to_4bytes(scan->channel, chno); + + // Copy SSID given by the application + if (ssid != NULL) { + rsi_strcpy(scan->ssid, ssid); + } + + scan->scan_feature_bitmap = bitmap; + + if (scan_response_handler != NULL) { + // Register scan response handler + rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler = scan_response_handler; + } else { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + + // Send scan command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SCAN, pkt); + } break; + case RSI_WLAN_STATE_NONE: + case RSI_WLAN_STATE_IP_CONFIG_DONE: + case RSI_WLAN_STATE_IPV6_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON: + case RSI_WLAN_STATE_AUTO_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_FAILED: + break; + + default: { + // Return status if command given in driver is an invalid state + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + if (scan_response_handler == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + } break; + } + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR); + return allow; + } + SL_PRINTF(SL_WLAN_SCAN_ASYNC_BITMAP_EXIT, WLAN, LOG_INFO, "status: %4x", status); + + return status; +} + +/*==============================================*/ +/** + * @brief Scan the surrounding access points. Invokes rsi_wlan_scan_async() API, which is an asynchronous call. This is a blocking API. + * @pre \ref rsi_wireless_init() API needs to be called before this API. + * @param[in] ssid - SSID size should be less than or equal to 32 bytes. Note: SSID is a null terminated string. + * @param[in] chno - Channel number to perform scan. If 0, then the module will scan all the channels. + * @param[out] result - Scanned Wi-Fi networks information. \n + * This output contains a maximum of 11 scan results \n + * The structure \ref rsi_rsp_scan_t contains members scan_count, which specifies the number of scan \n + * results followed by an array of structure type \ref rsi_scan_info_t, where each array element contains \n + * information about each network scanned. + * @param[in] length - Size that should be allocated to buffer that will store scan results. \n + * ## Channels supported in 2.4 GHz Band ## + * Channel numbers | chno + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * All Channels | 0 + * 1 | 1 + * 2 | 2 + * 3 | 3 + * 4 | 4 + * 5 | 5 + * 6 | 6 + * 7 | 7 + * 8 | 8 + * 9 | 9 + * 10 | 10 + * 11 | 11 + * 12 | 12 + * 13 | 13 + * 14 | 14 + * #### Channels supported in 5 GHz Band #### + * Channel numbers | chno + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * All Channels | 0 + * 36 | 36 + * 40 | 40 + * 44 | 44 + * 48 | 48 + * 149 | 149 + * 153 | 153 + * 157 | 157 + * 161 | 161 + * 165 | 165 + * #### DFS Channels supported in 5 GHz Band #### + * Channel numbers | chno + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * 52(DFS) | 52 + * 56(DFS) | 56 + * 60(DFS) | 60 + * 64(DFS) | 64 + * 100(DFS) | 100 + * 104(DFS) | 104 + * 108(DFS) | 108 + * 112(DFS) | 112 + * 116(DFS) | 116 + * 120(DFS) | 120 + * 124(DFS) | 124 + * 128(DFS) | 128 + * 132(DFS) | 132 + * 136(DFS) | 136 + * 140(DFS) | 140 + * 144(DFS) | 144 + * #### Channels supported in 4.9 GHz Band #### + * Channel numbers | chno + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * All Channels | 0 + * 184 | 184 + * 188 | 188 + * 192 | 192 + * 196 | 196 + * 8 | 8 + * 12 | 12 + * 16 | 16 + * @return 0 - Success + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0002, 0x0003, 0x0005, 0x000A, 0x0014, 0x0015, 0x001A, 0x0021,0x0024,0x0025,0x0026,0x002C,0x003c) \n + * ## Scan Info structure ## + * Structure Fields | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * rf_channel | Access point channel number + * security_mode | Security modes + * ^ 0 : Open + * ^ 1 : WPA + * ^ 2 : WPA2 + * ^ 3 : WEP + * ^ 4 : WPA Enterprise + * ^ 5 : WPA2 Enterprise + * ^ 6 : WPA3 + * rssi_val | RSSI value of the Access Point + * network_type | This is the type of the network + * ^ 1 : Infrastructure mode + * ssid | SSID of the access point + * bssid | MAC address of the access point + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * @note To set various timeouts, user should change the following macros in rsi_wlan_config.h \n + * #define RSI_TIMEOUT_SUPPORT RSI_ENABLE \n + * #define RSI_TIMEOUT_BIT_MAP 2 \n + * #define RSI_TIMEOUT_VALUE 150 (This macro can be configured based on user requirement) \n + * timeout_bitmap | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * timeout_bitmap[0] | Set timeout for association and authentication request.timeout_value : timeout value in ms(default 300ms). + * timeout_bitmap[1] | Sets each channel active scan time in ms (default 100ms) + * timeout_bitmap[2] | Used for WLAN keep alive timeout(default value is 30s) + * timeout_bitmap[31-3] | Reserved + * + * + */ +int32_t rsi_wlan_scan(int8_t *ssid, uint8_t chno, rsi_rsp_scan_t *result, uint32_t length) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_SCAN_ENTRY, WLAN, LOG_INFO); + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE || wlan_cb->state > RSI_WLAN_STATE_IP_CONFIG_DONE) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)result; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + + //Ccall async scan to perform actual scan + status = rsi_wlan_scan_async(ssid, chno, NULL); + + if (status != RSI_SUCCESS) { + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_SCAN_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SCAN_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_WLAN_SCAN_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Scan the surrounding access points. A scan response handler is registered with it to get the response for scan. This is a non-blocking API. + * @param[in] ssid - SSID to scan. If this input parameter is present, module will scan for that particular SSID only. SSID size should be less than or equal to 32 bytes \n + * Note: SSID is a null terminated string. + * @param[in] chno - Channel number to perform scan, if 0, then module will scan in all channels. + * @param[in] Scan_response_handler - Callback tht is called when the response for scan is received from the module. \n + * The parameters involved are status, buffer, & length. \n + *@param[out] Status - Response status. + *@param[out] Buffer - Response buffer \n + *@param[out] Length - Length of the response buffer measured in bytes to hold scan results. \n Size of structure \ref rsi_rsp_scan_t is 54 bytes. \n + * Length for storing one scan result is sizeof(rsi_scan_info_t) which is 44 bytes. \n + * Maximum of 11 scan results will be returned by the module, in this case, length must be configured as 8 + 11*sizeof(rsi_scan_info_t). + * ## Channels supported in 2.4 GHz Band ## + * Channel numbers | chno + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * All Channels | 0 + * 1 | 1 + * 2 | 2 + * 3 | 3 + * 4 | 4 + * 5 | 5 + * 6 | 6 + * 7 | 7 + * 8 | 8 + * 9 | 9 + * 10 | 10 + * 11 | 11 + * 12 | 12 + * 13 | 13 + * 14 | 14 + * #### Channels supported in 5 GHz Band #### + * Channel numbers | chno + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * All Channels | 0 + * 36 | 36 + * 40 | 40 + * 44 | 44 + * 48 | 48 + * 100 | 100 + * 104 | 104 + * 108 | 108 + * 116 | 116 + * 132 | 132 + * 136 | 136 + * 140 | 140 + * 149 | 149 + * 153 | 153 + * 157 | 157 + * 161 | 161 + * 165 | 165 + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0002, 0x0003, 0x0005, 0x000A, 0x0014, 0x0015, 0x001A, 0x0021,0x0024,0x0025,0x0026,0x002C,0x003c) \n + * #### Scan Response structure format #### + * Structure Fields | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * scan_count | Number of access points scanned. + * ^ scan_count[0] Contains the scan count. + * ^ scan_count[3-1] are reserved. + * scan_info | Information about scanned Access points in rsi_scan_info_t structure. + * ## Scan Info - rsi_scan_info_t structure ## + * Structure Fields | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * rf_channel | Access point channel number + * security_mode | Security mode0 : Open + * ^ 1 . WPA + * ^ 2 . WPA2 + * ^ 3 . WEP + * ^ 4 . WPA Enterprise + * ^ 5 . WPA2 Enterprise + * ^ 7 . WPA3 + * rssi_val | RSSI value of the Access Point + * network_type | Type of network + * ^ 1 . Infrastructure mode + * ssid | SSID of the access point + * bssid | MAC address of the access point + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note If status is Success , the argument buffer passed to scan_response_handler \n + * holds scan results in \ref rsi_rsp_scan_t structure format. + * @note To set various timeouts, user should change the following macros in rsi_wlan_config.h \n + * #define RSI_TIMEOUT_SUPPORT RSI_ENABLE \n + * #define RSI_TIMEOUT_BIT_MAP 4 \n + * #define RSI_TIMEOUT_VALUE 300 + * + * timeout_bitmap | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * timeout_bitmap[0] | Set timeout for association and authentication request.timeout_value : timeout value in ms(default 300ms). + * timeout_bitmap[1] | Sets each channel active scan time in ms (default 100ms) + * timeout_bitmap[2] | Used for WLAN keep alive timeout(default value is 30s) + * timeout_bitmap[31-3] | Reserved + * + */ + +int32_t rsi_wlan_scan_async(int8_t *ssid, + uint8_t chno, + void (*scan_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)) + +{ + rsi_pkt_t *pkt; + rsi_req_scan_t *scan; + int32_t status = RSI_SUCCESS; + int32_t allow = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_SCAN_ASYNC_ENTRY, WLAN, LOG_INFO); + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE || wlan_cb->state > RSI_WLAN_STATE_IP_CONFIG_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SCAN_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + if (scan_response_handler != NULL) { + allow = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + } + if (allow == RSI_SUCCESS) { + + switch (wlan_cb->state) { + case RSI_WLAN_STATE_OPERMODE_DONE: { + if (wlan_cb->field_valid_bit_map & RSI_SET_MAC_BIT) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_mac_address_t)); + + // Memcpy data + memcpy(&pkt->data, wlan_cb->mac_address, sizeof(rsi_req_mac_address_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set MAC command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_MAC_ADDRESS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_MAC_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } +#if HE_PARAMS_SUPPORT + status = rsi_wlan_11ax_config(GUARD_INTERVAL); + if (status != RSI_SUCCESS) { + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_band_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send band command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BAND, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BAND_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } + // No break + // Fall through + case RSI_WLAN_STATE_BAND_DONE: { +#if RSI_TIMEOUT_SUPPORT + status = send_timeout(RSI_TIMEOUT_BIT_MAP, RSI_TIMEOUT_VALUE); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_3, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_3, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send init command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_INIT, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_INIT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + return status; + } +#if RSI_SET_REGION_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // Send set region command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_4, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#endif +#if RSI_SET_REGION_AP_SUPPORT + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE) { + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_ap_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send set region AP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION_AP, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_AP_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + return status; + } + } +#endif + } + // No break + // Fall through + case RSI_WLAN_STATE_SCAN_DONE: + case RSI_WLAN_STATE_INIT_DONE: + case RSI_WLAN_STATE_CONNECTED: + case RSI_WLAN_STATE_IP_CONFIG_DONE: { +#if RSI_WLAN_CONFIG_ENABLE + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_5, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send Configuration request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CONFIG, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WLAN_CONFIG_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SCAN_ASYNC_ERROR_IN_SENDING_COMMAND_5, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_PKT_ALLOCATION_FAILURE_6, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Fill SCAN parameters + scan = (rsi_req_scan_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_scan_t)); + + // Copy the channel number + rsi_uint32_to_4bytes(scan->channel, chno); + + // Copy SSID given by the application + if (ssid != NULL) { + rsi_strcpy(scan->ssid, ssid); + } + + if (scan_response_handler != NULL) { + // Register scan response handler + rsi_wlan_cb_non_rom->callback_list.wlan_scan_response_handler = scan_response_handler; + } else { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + // Send scan command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SCAN, pkt); + } break; + case RSI_WLAN_STATE_NONE: + case RSI_WLAN_STATE_IPV6_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON: + case RSI_WLAN_STATE_AUTO_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_FAILED: + break; + default: { + // Return status if command given in driver is an invalid state + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + if (scan_response_handler == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + } break; + } + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SCAN_ASYNC_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return allow; + } + SL_PRINTF(SL_WLAN_SCAN_ASYNC_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Connect to the specified Wi-Fi network. This is a blocking API. + * @param[in] ssid - SSID of an access point to connect. SSID should be less than or equal to 32 bytes. + * @param[in] sec_type - Security type of the access point to connect. \n + * Value | Security Type + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * 0 | RSI_OPEN + * 1 | RSI_WPA + * 2 | RSI_WPA2 + * 3 | RSI_WEP + * 4 | RSI_WPA_EAP + * 5 | RSI_WPA2_EAP + * 6 | RSI_WPA_WPA2_MIXED + * 7 | RSI_WPA_PMK + * 8 | RSI_WPA2_PMK + * 9 | RSI_WPS_PIN + * 10 | RSI_USE_GENERATED_WPSPIN + * 11 | RSI_WPS_PUSH_BUTTON + * 12 | RSI_WPA_WPA2_MIXED_PMK + * 13 | RSI_WPA3 + * @param[in] secret_key - Pointer to a buffer that contains security information based on sec_type. \n + * Security type(sec_type) | Secret key structure format (secret_key) + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * RSI_OPEN | No secret key in open security mode. + * RSI_WPA | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes. + * RSI_WPA2 | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes. + * RSI_WEP | WEP keys should be in the following format: + * ^ typedef struct rsi_wep_keys_s + * ^ { + * ^ uint8_t index[2]; + * ^ uint8_t key[4][32]; + * ^ } rsi_wep_keys_t; + * ^ index: WEP key index to use for TX packet encryption. + * ^ key: 4 WEP keys, last three WEP keys are optional. If only first WEP key is valid then index should be 0. + * RSI_WPA_EAP | Enterprise credentials should be in the following format: + * ^ typedef struct rsi_eap_credentials_s + * ^ { + * ^ uint8_t username[64]; + * ^ uint8_t password[128]; + * ^ } rsi_eap_credentials_t; + * ^ username: username to be used in enterprise + * ^ password: password for the given username + * RSI_WPA2_EAP | Enterprise credentials should be in the following format: + * ^ typedef struct rsi_eap_credentials_s + * ^ { + * ^ uint8_t username[64]; + * ^ uint8_t password[128]; + * ^ } rsi_eap_credentials_t; + * ^ username: username to be used in enterprise + * ^ password: password for a given username. + * RSI_WPA_WPA2_MIXED | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes + * RSI_WPA_PMK | PMK string, should be 32 bytes in length + * RSI_WPA2_PMK | PMK string, should be 32 bytes in length + * RSI_WPS_PIN | 8-byte WPS PIN + * RSI_USE_GENERATED_WPSPIN| NULL string indicate to use PIN generated using rsi_wps_generate_pin API + * RSI_WPS_PUSH_BUTTON | NULL string indicate to generate push button event + * RSI_WPA3 | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes. + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0002,0x0003,0x0005,0x0008,0x0009,0x000A,0x000E,0x0014, \n + * 0x0015,0x0016,0x0019,0x001A,0x001E,0x0020,0x0021,0x0024,0x0025,0x0026,0x0028,0x0039,0x003C, \n + * 0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0xFFF8) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * @note To set various timeouts, user should change the following macros in rsi_wlan_config.h \n + * #define RSI_TIMEOUT_SUPPORT RSI_ENABLE. \n + * #define RSI_TIMEOUT_BIT_MAP 4. \n + * #define RSI_TIMEOUT_VALUE 300. \n + * + * timeout_bitmap | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * timeout_bitmap[0] | Set timeout for association and authentication request.timeout_value : timeout value in ms(default 300ms). + * timeout_bitmap[1] | Sets each channel active scan time in ms (default 100ms) + * timeout_bitmap[2] | Used for WLAN keep alive timeout(default value is 30s) + * timeout_bitmap[31-3] | Reserved + * @note To set Rejoin parameters, user should configure the following macros in rsi_wlan_config.h \n + * Macro | Description + * :------------------------------|:-------------------------------------------------------------------------------------------------- + * RSI_REJOIN_PARAMS_SUPPORT | Enable to send rejoin parameters command during Wi-Fi client connection \n + * RSI_REJOIN_MAX_RETRY | Number of maximum rejoin retries by module\n + * note | If Max retries is 0 , retries infinity times \n + * RSI_REJOIN_SCAN_INTERVAL | Periodicity of rejoin attempt \n + * RSI_REJOIN_BEACON_MISSED_COUNT | Number of consecutive beacon misses after which modules goes to unconnected state \n + * RSI_REJOIN_FIRST_TIME_RETRY | ENABLE - Try to rejoin in the first attempt after join failure. \n + * DISABLE - Try to rejoin based on maximum rejoin retries configured. \n + * @note When RSI_REJOIN_PARAMS_SUPPORT is enabled in the rsi_wlan_config.h, the rejoin frame will be sent to the firmware after the scan is done. + * @note This API internally handles following commands based on wlan_cb state and sends the next command and finally sends the join command. \n + * Set MAC address, Band, Timeout, Init, Set region, WMM parameters, Scan, EAP config, WMM PS parameters, WPS method, Set WEP keys, Host PSK, Rejoin params, Join \n + * @note For example, \n + * after calling rsi_wireless_init(), wlan_cb state is updated to OPERMODE_DONE state. So when we call this API, it will execute band, init, scan and join commands. \n + * @note For example, \n + * after calling rsi_wlan_disconnect() or else after rejoin failure, wlan_cb state is updated to BAND_DONE state. So when we call this API, it will execute init, scan and join commands. \n + * @note For example, \n + * after calling rsi_wlan_scan()/ rsi_wlan_scan_with_bitmap_options() API, wlan_cb state is updated to SCAN_DONE state. So when we call this API, it will execute join command directly. + * + */ + +int32_t rsi_wlan_connect(int8_t *ssid, rsi_security_mode_t sec_type, void *secret_key) +{ + + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_CONNECT_ENTRY, WLAN, LOG_INFO); + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Call async connect to call actual connect + status = rsi_wlan_connect_async(ssid, sec_type, secret_key, NULL); + + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_CONNECT_RESPONSE_WAIT_TIME); + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + } else { + // Return WLAN command error + return status; + } + // Execute post connect commands + status = rsi_wlan_execute_post_connect_cmds(); + + status = rsi_wlan_get_status(); + SL_PRINTF(SL_WLAN_CONNECT_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Connect to the specified Wi-Fi network. A join response handler is registered to get the response for join. This is a non-blocking API. + * @param[in] ssid - SSID of an access point to connect. SSID should be less than or equal to 32 bytes. + * @param[in] sec_type - Security type of the access point to connect. \n + * Value | Security Type + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * 0 | RSI_OPEN + * 1 | RSI_WPA + * 2 | RSI_WPA2 + * 3 | RSI_WEP + * 4 | RSI_WPA_EAP + * 5 | RSI_WPA2_EAP + * 6 | RSI_WPA_WPA2_MIXED + * 7 | RSI_WPA_PMK + * 8 | RSI_WPA2_PMK + * 9 | RSI_WPS_PIN + * 10 | RSI_USE_GENERATED_WPSPIN + * 11 | RSI_WPS_PUSH_BUTTON + * 12 | RSI_WPA_WPA2_MIXED_PMK + * 13 | RSI_WPA3 + * @param[in] secret_key - Pointer to a buffer that contains security information based on sec_type. \n + * Security type(sec_type) | Secret key structure format (secret_key) + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * RSI_OPEN | No secret key in open security mode. + * RSI_WPA | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes. + * RSI_WPA2 | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes. + * RSI_WEP | WEP keys should be in the following format: + * ^ typedef struct rsi_wep_keys_s + * ^ { + * ^ uint8_t index[2]; + * ^ uint8_t key[4][32]; + * ^ } rsi_wep_keys_t; + * ^ index: WEP key index to use for TX packet encryption. + * ^ key: 4 WEP keys, last three WEP keys are optional. If only first WEP key is valid then index should be 0. + * RSI_WPA_EAP | Enterprise credentials should be in the following format: + * ^ typedef struct rsi_eap_credentials_s + * ^ { + * ^ uint8_t username[64]; + * ^ uint8_t password[128]; + * ^ } rsi_eap_credentials_t; + * ^ username: username to be used in enterprise + * ^ password: password for the given username + * RSI_WPA2_EAP | Enterprise credentials should be in the following format: + * ^ typedef struct rsi_eap_credentials_s + * ^ { + * ^ uint8_t username[64]; + * ^ uint8_t password[128]; + * ^ } rsi_eap_credentials_t; + * ^ username: username to be used in enterprise + * ^ password: password for a given username. + * RSI_WPA_WPA2_MIXED | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes + * RSI_WPA_PMK | PMK string, should be 32 bytes in length + * RSI_WPA2_PMK | PMK string, should be 32 bytes in length + * RSI_WPS_PIN | 8-byte WPS PIN + * RSI_USE_GENERATED_WPSPIN| NULL string indicate to use PIN generated using rsi_wps_generate_pin API + * RSI_WPS_PUSH_BUTTON | NULL string indicate to generate push button event + * RSI_WPA3 | PSK string terminated with NULL. Length of PSK should be at least 8 and less than 64 bytes. + * @param[in] join_response_handler - Called when the response for join has been received from the module. \n + * Parameters involved are status, buffer, & length \n + * @param[out] Status - Response status. + * @param[out] Buffer - Response buffer. On successful execution of the command. \n GO_Status (1 byte, hex): 0x47 (ASCII "G") - If the module becomes a Group Owner (GO) after the GO + * negotiation stage or becomes an Access Point. \n 0x43 (ASCII "C") - If the module does not become a GO after the GO negotiation stage or becomes a client (or station). + * @param[out] length - Length of the response buffer. + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * @note The module gets a default IP of 192.168.100.76, if it becomes a Group Owner or Access Point in case of IPv4 and gets a default IP of 2001:db8:0:1:0:0:0:120 in case of IPv6. + * @note To set various timeouts, user should change the following macros in rsi_wlan_config.h \n + * #define RSI_TIMEOUT_SUPPORT RSI_ENABLE. \n + * #define RSI_TIMEOUT_BIT_MAP 4. \n + * #define RSI_TIMEOUT_VALUE 300. \n + * + * timeout_bitmap | Description + * :-----------------------|:-------------------------------------------------------------------------------------------------- + * timeout_bitmap[0] | Set timeout for association and authentication request.timeout_value : timeout value in ms(default 300ms). + * timeout_bitmap[1] | Sets each channel active scan time in ms (default 100ms) + * timeout_bitmap[2] | Used for WLAN keep alive timeout(default value is 30s) + * timeout_bitmap[31-3] | Reserved + * @note To set Rejoin parameters, user should configure the following macros in rsi_wlan_config.h \n + * Macro | Description + * :------------------------------|:-------------------------------------------------------------------------------------------------- + * RSI_REJOIN_PARAMS_SUPPORT | Enable to send rejoin parameters command during Wi-Fi client connection \n + * RSI_REJOIN_MAX_RETRY | Number of maximum rejoin retries by module\n + * note | If Max retries is 0 , retries infinity times \n + * RSI_REJOIN_SCAN_INTERVAL | Periodicity of rejoin attempt \n + * RSI_REJOIN_BEACON_MISSED_COUNT | Number of consecutive beacon misses after which modules goes to unconnected state \n + * RSI_REJOIN_FIRST_TIME_RETRY | ENABLE - Try to rejoin in the first attempt after join failure. \n + * DISABLE - Try to rejoin based on maximum rejoin retries configured. \n + * @note When RSI_REJOIN_PARAMS_SUPPORT is enabled in the rsi_wlan_config.h, the rejoin frame will be sent to the firmware after the scan is done. + * @note This API internally handles following commands based on wlan_cb state and sends the next command and finally sends the join command. \n + * Set MAC address, Band, Timeout, Init, Set region, WMM parameters, Scan, EAP config, WMM PS parameters, WPS method, Set WEP keys, Host PSK, Rejoin params, Join \n + * @note For example, \n + * after calling rsi_wireless_init(), wlan_cb state is updated to OPERMODE_DONE state. So when we call this API, it will execute band, init, scan and join commands. \n + * @note For example, \n + * after calling rsi_wlan_disconnect() or else after rejoin failure, wlan_cb state is updated to BAND_DONE state. So when we call this API, it will execute init, scan and join commands. \n + * @note For example, \n + * after calling rsi_wlan_scan()/ rsi_wlan_scan_with_bitmap_options() API, wlan_cb state is updated to SCAN_DONE state. So when we call this API, it will execute join command directly. + * + */ + +int32_t rsi_wlan_connect_async(int8_t *ssid, + rsi_security_mode_t sec_type, + void *secret_key, + void (*join_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)) +{ + rsi_eap_credentials_t *credentials; + rsi_req_wps_method_t *wps_method; + rsi_req_psk_t *psk; + rsi_wep_keys_t *wep_keys; + rsi_pkt_t *pkt; + rsi_req_scan_t *scan; + rsi_req_join_t *join; + rsi_req_eap_config_t *eap_config; + int32_t status = RSI_SUCCESS; + int32_t allow = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + if (join_response_handler != NULL) { + allow = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + } + + if (allow == RSI_SUCCESS) { + // Check whether PSK is provided or not for security modes + if ((sec_type != 0) && (secret_key == NULL) && (sec_type != RSI_WPS_PUSH_BUTTON) + && (sec_type != RSI_USE_GENERATED_WPSPIN)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Throw error in case of invalid parameters + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_1, WLAN, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + // Check whether module is in valid state range or not + if ((wlan_cb->opermode != RSI_WLAN_CONCURRENT_MODE && wlan_cb->state >= RSI_WLAN_STATE_CONNECTED) + || (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE && wlan_cb->state >= RSI_WLAN_STATE_CONNECTED + && wlan_cb->sta_state >= RSI_WLAN_STATE_CONNECTED)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Command given in wrong state + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE_1, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + if ((wlan_cb->opermode == RSI_WLAN_ENTERPRISE_CLIENT_MODE) + && !((sec_type == RSI_WPA_EAP) || (sec_type == RSI_WPA2_EAP))) { + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Throw error in case of invalid parameters + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_INVALID_PARAM_2, WLAN, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + switch (wlan_cb->state) { + case RSI_WLAN_STATE_OPERMODE_DONE: { + if (wlan_cb->field_valid_bit_map & RSI_SET_MAC_BIT) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_mac_address_t)); + // Memcpy data + memcpy(&pkt->data, wlan_cb->mac_address, sizeof(rsi_req_mac_address_t)); +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set MAC command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_MAC_ADDRESS, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_MAC_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR); + return status; + } + } +#if HE_PARAMS_SUPPORT + status = rsi_wlan_11ax_config(GUARD_INTERVAL); + if (status != RSI_SUCCESS) { + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_HE_PARAMS_SUPPORT, WLAN, LOG_INFO); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send band command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BAND, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BAND_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR); + return status; + } + } + // No break + // Fall through + case RSI_WLAN_STATE_BAND_DONE: { +#if RSI_TIMEOUT_SUPPORT + status = send_timeout(RSI_TIMEOUT_BIT_MAP, RSI_TIMEOUT_VALUE); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_3, WLAN, LOG_ERROR); + return status; + } +#endif + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send init command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_INIT, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_INIT_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_WLAN_CMD_STATE_CHANGED_TO_ALLOW, WLAN, LOG_INFO); + return status; + } +#if RSI_SET_REGION_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_5, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set region command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_4, WLAN, LOG_ERROR); + return status; + } +#endif +#if RSI_SET_REGION_AP_SUPPORT + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE) { + // allocate command buffer from wlan pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_ap_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // send set region AP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION_AP, pkt); + + // wait on wlan semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_AP_RESPONSE_WAIT_TIME); + + // get wlan/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return the status if error in sending command occurs + return status; + } + } +#endif + } + // No break + // Fall through + case RSI_WLAN_STATE_INIT_DONE: { +#if RSI_WMM_PS_ENABLE + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_6, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_wmm_ps_parms_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WMM parameters + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WMM_PS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WMM_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_5, WLAN, LOG_ERROR); + return status; + } + +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_7, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Give buffer as NULL, no need to give scan results to host + wlan_cb->app_buffer = NULL; + + // Length of the buffer is zero + wlan_cb->app_buffer_length = 0; + + // Send scan command + scan = (rsi_req_scan_t *)pkt->data; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_scan_t)); + + // Copy SSID given by the application + if (ssid != NULL) { + rsi_strcpy(scan->ssid, ssid); + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send scan command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SCAN, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_SCAN_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_6, WLAN, LOG_ERROR); + return status; + } + } + // No break + // Fall through + case RSI_WLAN_STATE_SCAN_DONE: { + + // Send EAP command for EAP security + if ((wlan_cb->opermode == RSI_WLAN_ENTERPRISE_CLIENT_MODE)) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_8, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + credentials = (rsi_eap_credentials_t *)secret_key; + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_req_eap_config_t)); + + eap_config = (rsi_req_eap_config_t *)pkt->data; + + // Copy username + memcpy(eap_config->user_identity, credentials->username, RSI_EAP_USER_NAME_LENGTH); + + // Copy password + memcpy(eap_config->password, credentials->password, RSI_EAP_PASSWORD_LENGTH); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send EAP config command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EAP_CONFIG, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_EAP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_7, WLAN, LOG_ERROR); + return status; + } + } + +#if RSI_WMM_PS_ENABLE + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_9, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset the packet data + memset(&pkt->data, 0, sizeof(rsi_wmm_ps_parms_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WMM parameters + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WMM_PS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WMM_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_8, WLAN, LOG_ERROR); + return status; + } + +#endif + if ((sec_type == RSI_WPS_PIN) && (wlan_cb->opermode != RSI_WLAN_ENTERPRISE_CLIENT_MODE)) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_10, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + wps_method = (rsi_req_wps_method_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_wps_method_t)); + + // Set configuration to validate WPS pin + rsi_uint16_to_2bytes(wps_method->wps_method, 1); + + // Set configuration to validate WPS pin + rsi_uint16_to_2bytes(wps_method->generate_pin, 0); + + // Copy WPS pin + memcpy(wps_method->wps_pin, secret_key, RSI_WPS_PIN_LEN); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS method command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WPS_METHOD, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WPS_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_9, WLAN, LOG_ERROR); + return status; + } + } else if (sec_type == RSI_WEP) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_11, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_wep_keys_t)); + + wep_keys = (rsi_wep_keys_t *)pkt->data; + + // Copy WEP keys + memcpy(wep_keys, secret_key, sizeof(rsi_wep_keys_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send PSK command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_WEP_KEYS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WEP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_10, WLAN, LOG_ERROR); + return status; + } + + } + // Send PSK command for PSK security + else if (((sec_type == RSI_WPA) || (sec_type == RSI_WPA2) || (sec_type == RSI_WPA3) + || (sec_type == RSI_WPA3_TRANSITION) || (sec_type == RSI_WPA_WPA2_MIXED) + || (sec_type == RSI_WPA_WPA2_MIXED_PMK) || (sec_type == RSI_WPA_PMK) || (sec_type == RSI_WPA2_PMK)) + && (wlan_cb->opermode != RSI_WLAN_ENTERPRISE_CLIENT_MODE)) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_12, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + psk = (rsi_req_psk_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_psk_t)); + + if ((sec_type == RSI_WPA2_PMK) || (sec_type == RSI_WPA_PMK) || (sec_type == RSI_WPA_WPA2_MIXED_PMK)) { + if (sec_type == RSI_WPA_WPA2_MIXED_PMK) { + sec_type = RSI_WPA_WPA2_MIXED; + } + // Set type as PMK + psk->type = 2; + + // Copy PMK + memcpy(psk->psk_or_pmk, secret_key, RSI_PMK_LEN); + + } else { + // Set type as PSK + psk->type = 1; + + // Copy PSK + memcpy(psk->psk_or_pmk, secret_key, RSI_PSK_LEN); + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send PSK command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HOST_PSK, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WPS_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_11, WLAN, LOG_ERROR); + return status; + } + } + +#if RSI_REJOIN_PARAMS_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_13, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_rejoin_params_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send rejoin params command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_REJOIN_PARAMS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REJOIN_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_ERROR_IN_SENDING_COMMAND_12, WLAN, LOG_ERROR); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_PKT_ALLOCATION_FAILURE_14, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_join_t)); + + join = (rsi_req_join_t *)pkt->data; + + // Fill security type + if (sec_type == RSI_WPA2_PMK) { + join->security_type = RSI_WPA2; + } else if (sec_type == RSI_WPA_PMK) { + join->security_type = RSI_WPA; + } else if ((sec_type == RSI_WPS_PIN) || (sec_type == RSI_USE_GENERATED_WPSPIN) + || (sec_type == RSI_WPS_PUSH_BUTTON)) { + join->security_type = RSI_OPEN; + } else if (sec_type == RSI_WPA3) { + join->security_type = SME_WPA3; + } else if (sec_type == RSI_WPA3_TRANSITION) { + join->security_type = SME_WPA3_TRANSITION; + } else { + join->security_type = sec_type; + } + + if (ssid != NULL) { + // Copy SSID and SSID len + join->ssid_len = rsi_strlen(ssid); + + // Copy Join SSID + rsi_strcpy(join->ssid, ssid); + } + + if (join_response_handler != NULL) { + // Register scan response handler + rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler = join_response_handler; + } else { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + // Send join command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_JOIN, pkt); + } break; + case RSI_WLAN_STATE_NONE: + case RSI_WLAN_STATE_CONNECTED: + case RSI_WLAN_STATE_IP_CONFIG_DONE: + case RSI_WLAN_STATE_IPV6_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON: + case RSI_WLAN_STATE_AUTO_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_FAILED: + break; + default: { + // Return status if command given in driver is in an invalid state + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + if (join_response_handler == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + } break; + } + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR); + return allow; + } + // Return status + SL_PRINTF(SL_WLAN_CONNECT_ASYNC_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Enable background scan and get the results or disable background scan. This is a blocking API. + * @param[in] cmd - Command given by user, to enable or disable bgscan. \n + * 0 - disable bgscan, \n + * 1 - enable bgscan + * @param[out] result - buffer to store bgscan results + * @param[in] length - Length of bgscan result buffer + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd, 0xfffffffc) \n + * @note **Precondition** - \ref rsi_wlan_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_bgscan_profile(uint8_t cmd, rsi_rsp_scan_t *result, uint32_t length) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_BGSCAN_PROFILE_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Check whether module is in valid state range or not + if (wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_BGSCAN_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)result; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_BGSCAN_PROFILE_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_bg_scan_t)); + + // Magic word + pkt->data[0] = 0xAB; + + // cmd + pkt->data[1] = cmd; +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // Send BG scan command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BG_SCAN, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BGSCAN_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_BGSCAN_PROFILE_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_BGSCAN_PROFILE_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Enable scan and roaming after connecting the module to the access point. This is a blocking API. + * @param[in] Void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffc,0x0006,0x0021,0x002C,0x004A,0x0025,0x0026) \n + * @note **Precondition** - \ref rsi_wlan_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +// Execute post connect commands +int32_t rsi_wlan_execute_post_connect_cmds(void) +{ +#if (RSI_BG_SCAN_SUPPORT || RSI_ROAMING_SUPPORT) + rsi_pkt_t *pkt; +#endif + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ENRTY, WLAN, LOG_INFO, "status: %4x", status); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Check whether module is in valid state range or not + if (wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { +#if RSI_BG_SCAN_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_bg_scan_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send BG scan command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BG_SCAN, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BGSCAN_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + +#endif +#if RSI_ROAMING_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_roam_params_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send roaming parameters command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_ROAM_PARAMS, pkt); + + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_ROAMING_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); +#endif + // Wait on WLAN semaphore + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_NWK_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_EXECUTE_POST_CONNECT_CMDS_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Start the WPS Push button in AP mode. This is a blocking API. + * @param[in] ssid - SSID of the Access Point. SSID should be same as that of given in AP start API. Length of the SSID should be less than or equal to 32 bytes. + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffc,0x0021) \n + * @note **Precondition** - \ref rsi_wlan_ap_start() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_wps_push_button_event(int8_t *ssid) +{ + rsi_pkt_t *pkt; + rsi_req_join_t *join; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_WPS_PUSH_BUTTON_EVENT_ENRTY, WLAN, LOG_INFO, "status: %4x", status); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_WPS_PUSH_BUTTON_EVENT_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_WPS_PUSH_BUTTON_EVENT_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_join_t)); + + join = (rsi_req_join_t *)pkt->data; + + if (ssid != NULL) { + // Copy SSID and SSID len + join->ssid_len = rsi_strlen(ssid); + + // Copy Join SSID + rsi_strcpy(join->ssid, ssid); + } + + // Deregister join response handler + rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler = NULL; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send join command to start wps + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_JOIN, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_JOIN_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_WPS_PUSH_BUTTON_EVENT_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_WPS_PUSH_BUTTON_EVENT_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Application to provide feedback of frequency error in KHz. This is a blocking API. + * @param[in] freq_offset_in_khz - Frequency deviation observed in KHz + * @return 0 - Success \n + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_send_freq_offset(int32_t freq_offset_in_khz) +{ + rsi_pkt_t *pkt; + rsi_freq_offset_t *freq_offset = NULL; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_SEND_FREQ_OFFSET_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SEND_FREQ_OFFSET_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SEND_FREQ_OFFSET_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_freq_offset_t)); + + freq_offset = (rsi_freq_offset_t *)pkt->data; + + freq_offset->freq_offset_in_khz = freq_offset_in_khz; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_FREQ_OFFSET, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_FREQ_OFFSET_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SEND_FREQ_OFFSET_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SEND_FREQ_OFFSET_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief RF calibration process. This API will command the firmware to update the existing Flash/EFuse calibration data. This is a blocking API. + * @param[in] Target - 0 - BURN_INTO_EFUSE (Burns calibration data to EFuse) \n + * 1 - BURN_INTO_FLASH (Burns calibration data to Flash) \n + * @param[in] Flags - Validate information \n + * Bit | MACRO | Description + * :---|:---------------------:|:--------------------------------------------------- + * 0 | RESERVED_0 | Reserved + * 1 | BURN_FREQ_OFFSET | 1 - Update XO Ctune to calibration data \n 0 - Skip XO Ctune update + * 2 | SW_XO_CTUNE_VALID | 1 - Use XO Ctune provided as argument to update calibration data. \n 0 - Use XO Ctune value as read from hardware register + * 3 | BURN_XO_FAST_DISABLE | Used to apply patch for cold temperature issue (host interface detection) observed on CC0/CC1 modules. \ref appendix + * 4 | BURN_GAIN_OFFSET_LOW | 1 - Update gain offset for low sub-band (2 GHz) \n 0 - Skip low sub-band gain-offset update + * 5 | BURN_GAIN_OFFSET_MID | 1 - Update gain offset for mid sub-band (2 GHz) \n 0 - Skip mid sub-band gain-offset update + * 6 | BURN_GAIN_OFFSET_HIGH| 1 - Update gain offset for high sub-band (2 GHz) \n 0 - Skip high sub-band gain-offset update + * 31-4 | | Reserved + * @param[in] gain_offset_low - gain_offset as observed in dBm in channel-1 + * @param[in] gain_offset_mid - gain_offset as observed in dBm in channel-6 + * @param[in] gain_offset_high - gain_offset as observed in dBm in channel-11 + * @param[in] xo_ctune - Allow user to directly update xo_ctune value to calibration data bypassing the freq offset loop, + * valid only when BURN_FREQ_OFFSET & SW_XO_CTUNE_VALID of flags is set. The range of xo_ctune is [0, 255], and the typical value is 80. + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_transmit_test_start(), \ref rsi_send_freq_offset() API needs to be called before this API. This API is relevant in PER mode only. + * @note For gain-offset calibration in 2.4 GHz, the user needs to calibrate gain-offset for low sub-band (channel-1), mid sub-band (channel-6), and high sub-band (channel-11) and input the three gain-offsets to this API and set the corresponding flags to validate it. \n + * @note Recalibration is not possible if EFuse is being used instead of flash as calibration data storage + */ + +int32_t rsi_calib_write(uint8_t target, + uint32_t flags, + int8_t gain_offset_low, + int8_t gain_offset_mid, + int8_t gain_offset_high, + int8_t xo_ctune) +{ + rsi_pkt_t *pkt; + rsi_calib_write_t *calib_wr = NULL; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_CALIB_WRITE_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_CALIB_WRITE_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CALIB_WRITE_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + calib_wr = (rsi_calib_write_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_calib_write_t)); + + // Target flash or efuse + calib_wr->target = target; + + // Flags + calib_wr->flags = flags; + + // Gain offset + calib_wr->gain_offset[0] = gain_offset_low; + calib_wr->gain_offset[1] = gain_offset_mid; + calib_wr->gain_offset[2] = gain_offset_high; + + // Freq offset + calib_wr->xo_ctune = xo_ctune; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CALIB_WRITE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_CALIB_WRITE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_CALIB_WRITE_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CALIB_WRITE_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief RF calibration process. This API reads the calibration data from the Flash/EFuse storage. This is a blocking API. + * @pre \ref rsi_wireless_init() needs to be called prior this API. + * @param[in] Target \n + * 0 - READ_FROM_EFUSE (read calibration data from the EFuse) \n + * 1 - READ_FROM_FLASH (read calibration data from the Flash) \n + * @param[out] gain_offset_low - gain_offset in dBm that will be applied for transmissions in channel-1. + * @param[out] gain_offset_mid - gain_offset in dBm that will be applied for transmissions in channel-6. + * @param[out] gain_offset_high -gain_offset in dBm that will be applied for transmissions in channel-11. + * @param[out] xo_ctune - xo_ctune value as read from the target memory. + * @return 0 - Success \n + * Non-Zero Value - Failure + */ + +int32_t rsi_calib_read(uint8_t target, rsi_calib_read_t *calib_data) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_CALIB_READ_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_CALIB_READ_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CALIB_READ_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, 4); + + // Target flash or efuse + pkt->data[0] = target; + + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)calib_data; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = sizeof(rsi_calib_read_t); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CALIB_READ, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_CALIB_READ_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_CALIB_READ_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CALIB_READ_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Parse and convert the given value in ASCII to the datatype of a given length.. This is a non-blocking API. + * @param[in] address - Address + * @param[in] length - Length + * @param[in] value - Value + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ +int16_t rsi_parse(void *address, uint16_t length, uint8_t *value) +{ + uint8_t temp_buff[15]; + uint16_t temp_offset = 0; + uint16_t offset; + + for (offset = 0; offset < length; offset++) { + uint16_t index = 0; + /* Copy the bytes until '.' ',' '\0' is reached */ + while ((value[temp_offset] != '.') && (value[temp_offset] != ',') && (value[temp_offset] != '\0')) { + if (index >= (sizeof(temp_buff) - 1)) + break; + temp_buff[index++] = value[temp_offset++]; + } + temp_buff[index] = '\0'; + temp_offset++; + if (length == RSI_PARSE_2_BYTES) { + *((uint16_t *)address) = rsi_atoi((int8_t *)temp_buff); + break; + } else if (length == RSI_PARSE_4_BYTES) { + *((uint32_t *)address) = rsi_atoi((int8_t *)temp_buff); + break; + } else + *((uint8_t *)address + offset) = rsi_atoi((int8_t *)temp_buff); + } + + return temp_offset; +} + +/*==============================================*/ +/** + * @brief Generate WPS pin. This is a blocking API. + * @param[out] wps_pin - 8-byte WPS pin generated by the device. + * @param[in] length - This is the length of the resulted buffer measured in bytes to hold WPS pin. + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffc,0x0021,0x002C,0x0025,0x0037,0x0038) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to Error Codes section for the description of the above error codes \ref error-codes. + * + */ + +int32_t rsi_wlan_wps_generate_pin(uint8_t *wps_pin, uint16_t length) +{ + rsi_pkt_t *pkt; + rsi_req_wps_method_t *wps_method; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_WPS_GENERATE_PIN_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_WPS_GENERATE_PIN_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_WPS_GENERATE_PIN_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + wps_method = (rsi_req_wps_method_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_wps_method_t)); + + // Set configuration to generate WPS pin + rsi_uint16_to_2bytes(wps_method->wps_method, 1); + + // Set configuration to generate WPS pin + rsi_uint16_to_2bytes(wps_method->generate_pin, 1); + + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)wps_pin; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WPS_METHOD, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WPS_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_WPS_GENERATE_PIN_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_WPS_GENERATE_PIN_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Validate WPS pin entered. This is a blocking API. + * @param[in] wps_pin - 8-byte valid wps pin + * @param[out] Same WPS pin if command is successful + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + */ + +int32_t rsi_wlan_wps_enter_pin(int8_t *wps_pin) +{ + rsi_pkt_t *pkt; + rsi_req_wps_method_t *wps_method; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_WPS_ENTER_PIN_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_WPS_ENTER_PIN_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_WPS_ENTER_PIN_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + wps_method = (rsi_req_wps_method_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_wps_method_t)); + + // Set configuration to validate WPS pin + rsi_uint16_to_2bytes(wps_method->wps_method, 1); + + // Set configuration to validate WPS pin + rsi_uint16_to_2bytes(wps_method->generate_pin, 0); + + // Copy WPS pin + memcpy(wps_method->wps_pin, wps_pin, RSI_WPS_PIN_LEN); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_WPS_METHOD, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WPS_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_WPS_ENTER_PIN_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_WPS_ENTER_PIN_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Get random bytes from the device. This is a blocking API. + * @param[in] result - Pointer to the buffer in which random data are copied from. + * @param[in] length - Length of the random data required + * @return 0 - Success \n + * @return Non-Zero Value - Failure + */ + +int32_t rsi_get_random_bytes(uint8_t *result, uint32_t length) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_GET_RANDOM_BYTES_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_GET_RANDOM_BYTES_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)result; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_RANDOM_BYTES_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_disassoc_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send get random number command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_GET_RANDOM, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WLAN_GET_RANDOM_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_GET_RANDOM_BYTES_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_GET_RANDOM_BYTES_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Disconnect the module from the connected access point. This is a blocking API. + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffc,0x0006,0x0021,0x002C,0x004A,0x0025,0x0026)\n + * @note **Precondition** - \ref rsi_wlan_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_disconnect(void) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_DISCONNECT_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_DISCONNECT_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_DISCONNECT_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_disassoc_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send disconnect command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DISCONNECT, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_DISCONNECT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_DISCONNECT_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_DISCONNECT_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Disconnect a connected station from the module in AP mode. This is a blocking API. + * @param[in] mac_address - Mac address (6 bytes) of the station to be disconnected. + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffc,0x0013,0x0021,0x002C,0x0015)\n + * @note **Precondition** - \ref rsi_wlan_ap_start() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_disconnect_stations(uint8_t *mac_address) +{ + rsi_pkt_t *pkt; + rsi_req_disassoc_t *disassoc_info; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_DISCONNECT_STATIONS_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_DISCONNECT_STATIONS_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_DISCONNECT_STATIONS_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + disassoc_info = (rsi_req_disassoc_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_disassoc_t)); + + // Set mode flag to represent AP mode + rsi_uint16_to_2bytes(disassoc_info->mode_flag, 1); + + // Copy MAC address of station to be disconnected + memcpy(disassoc_info->client_mac_address, mac_address, 6); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send disconnect command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DISCONNECT, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_DISCONNECT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_DISCONNECT_STATIONS_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_DISCONNECT_STATIONS_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup WLAN +* @{ +*/ + +/*==============================================*/ +/** + * @fn int32_t rsi_config_ipaddress(rsi_ip_version_t version, uint8_t mode, uint8_t *ip_addr, + * uint8_t *mask, uint8_t *gw, uint8_t *ipconfig_rsp, + * uint16_t length, uint8_t vap_id); + * @brief Configure the IP address to the module. This is a blocking API. + * @param[in] version - IP version to be used. RSI_IP_VERSION_4 (4) – to select IPv4, RSI_IP_VERSION_6 (6) – to select IPv6 + * @param[in] mode - 1 - DHCP mode ; 0 - static mode + * @param[in] ip_addr - Pointer to IP address + * IPv6 Address Description | Indices in the ip_addr + * :----------------------------------------------------|:----------------------------------------------------------- + * Prefix Length | ip_addr[0] + * Link Local Address (128 bits) | ip_addr[1] to ip_addr[4] + * Global Address (128 bits) | ip_addr[5] to ip_addr[8] + * Gateway Address (128 bits) | ip_addr[9] to ip_addr[12] + * @param[in] mask - Pointer to network mask + * @param[in] gw - Pointer to gateway address + * @param[in] ipconfig_rsp - Hold the IP configuration received using DHCP. + * @param[in] length - Length of ipconfig_rsp buffer + * @param[in] vap_id - VAP id to differentiate between AP and station in concurrent mode. 0 – for station, 1 – for Access point + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_wlan_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_config_ipaddress(rsi_ip_version_t version, + uint8_t mode, + uint8_t *ip_addr, + uint8_t *mask, + uint8_t *gw, + uint8_t *ipconfig_rsp, + uint16_t length, + uint8_t vap_id) +{ + rsi_pkt_t *pkt; + rsi_req_ipv4_parmas_t *ip_params; + rsi_req_ipv6_parmas_t *ipv6_params; + int32_t status = RSI_SUCCESS; + int32_t rsi_response_wait_time = 0; + // Get WLAN CB struct pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // WLAN radio init + status = rsi_wlan_radio_init(); + SL_PRINTF(SL_WLAN_CONFIG_IPADDRESS_ENTRY, WLAN, LOG_INFO); + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CONFIG_IPADDRESS_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CONFIG_IPADDRESS_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)ipconfig_rsp; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + + // If ipversion is IPv4 + if (version == RSI_IP_VERSION_4) { + // Fill all the ipv4 parameters + ip_params = (rsi_req_ipv4_parmas_t *)pkt->data; + + // Set DHCP mode + ip_params->dhcp_mode = mode; + + // Fill IP address only if static mode is selected + if (mode == RSI_STATIC) { + // Fill IP address + memcpy(ip_params->ipaddress, ip_addr, RSI_IPV4_ADDRESS_LENGTH); + + // Fill network mask + memcpy(ip_params->netmask, mask, RSI_IPV4_ADDRESS_LENGTH); + + // Fill gateway + memcpy(ip_params->gateway, gw, RSI_IPV4_ADDRESS_LENGTH); + } + + // Check for DHCP HOSTNAME feature + if ((mode & RSI_DHCP_HOSTNAME) == RSI_DHCP_HOSTNAME) { + // Copy DHCP client hostname + rsi_strcpy(ip_params->hostname, RSI_DHCP_HOST_NAME); + } + + // Set vap_id + ip_params->vap_id = vap_id; +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + + // Send ipconfig command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_IPCONFV4, pkt); + rsi_response_wait_time = RSI_IPCONFV4_RESPONSE_WAIT_TIME; + + } else if (version == RSI_IP_VERSION_6) { + // Fill all the IPv6 params + ipv6_params = (rsi_req_ipv6_parmas_t *)pkt->data; + + // Fill prefix length + rsi_uint16_to_2bytes(ipv6_params->prefixLength, 64); + + // Fill DHCP mode + rsi_uint16_to_2bytes(ipv6_params->mode, mode); + + // Fill IP address only if static mode is selected + if (mode == RSI_STATIC) { + // Fill IPv6 address + memcpy(ipv6_params->ipaddr6, ip_addr, RSI_IPV6_ADDRESS_LENGTH); + + // Fill gateway + memcpy(ipv6_params->gateway6, gw, RSI_IPV6_ADDRESS_LENGTH); + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send ipconfig command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_IPCONFV6, pkt); + rsi_response_wait_time = RSI_IPCONFV6_RESPONSE_WAIT_TIME; + } else { + + // Detach buffer + wlan_cb->app_buffer = NULL; + + // Make length of the buffer to 0 + wlan_cb->app_buffer_length = 0; + + // Update Throw error in case of invalid parameters + status = RSI_ERROR_INVALID_PARAM; + // Free the packet + rsi_pkt_free(&wlan_cb->wlan_tx_pool, pkt); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + SL_PRINTF(SL_WLAN_CONFIG_IPADDRESS_CHANGE_WLAN_CMD_STATE_TO_ALLOW, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_CONFIG_IPADDRESS_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_WLAN_CONFIG_IPADDRESS_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Write or erase certificate into module. This is a blocking API. + * @param[in] certificate_type - Type of certificate + * @param[in] cert_inx - Index of certificate + * @param[in] buffer - Certificate content + * @param[in] certificate_length - Certificate length + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0015,0x0021,0x0025,0x0026,0x002C) \n + * @note **Precondition** - \ref rsi_wireless_init() API must be called before this API. + * @note Index-based certificate loading is valid only for storing certificates on to RAM or flash but not both at the same time. \n + * @note Enable bit[27] in tcp_ip_feature_bit_map to load SSl certificate into RAM. \n + * @note Enable bit[31] in tcp_ip_feature_bit_map and bit[29] in ext_tcp_ip_feature_bit_map to open 3 SSL client sockets. \n + * Three SSL client sockets feature is supported only in WLAN mode. + * + * + */ +int32_t rsi_wlan_set_certificate_index(uint8_t certificate_type, + uint8_t cert_inx, + uint8_t *buffer, + uint32_t certificate_length) +{ + static uint32_t rem_len; + uint16_t chunk_size = 0; + static uint32_t offset; + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + rsi_req_set_certificate_t *rsi_chunk_ptr; + int32_t rsi_response_wait_time = 0; + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Check if command is in correct state or not + if ((wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE)) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + if ((buffer == NULL) && (certificate_length)) { + // Throw error in case of invalid parameters + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_INVALID_PARAM, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Get the certificate chunk size + chunk_size = (RSI_MAX_CERT_SEND_SIZE - sizeof(struct rsi_cert_info_s)); + + // Get certificate length + rem_len = certificate_length; + + // If certificate length is 0, erase certificate + if (rem_len == 0) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + rsi_chunk_ptr = (rsi_req_set_certificate_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, RSI_MAX_CERT_SEND_SIZE); + + //Set the total length of certificate + rsi_uint16_to_2bytes(rsi_chunk_ptr->cert_info.total_len, certificate_length); + + // Set the certificate type + rsi_chunk_ptr->cert_info.certificate_type = certificate_type; + + // Set the certificate index + rsi_chunk_ptr->cert_info.certificate_inx = cert_inx; + + // More chunks to send + rsi_chunk_ptr->cert_info.more_chunks = 0; + + // Set the length of the certificate chunk + rsi_uint16_to_2bytes(rsi_chunk_ptr->cert_info.certificate_length, 0); + + rsi_response_wait_time = RSI_CERTIFICATE_RESPONSE_WAIT_TIME; +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send the driver command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_CERTIFICATE, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } + while (rem_len) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + rsi_chunk_ptr = (rsi_req_set_certificate_t *)pkt->data; + // Memset the PKT + memset(&pkt->data, 0, RSI_MAX_CERT_SEND_SIZE); + + if (rem_len >= chunk_size) { + // Copy the certificate chunk + memcpy(rsi_chunk_ptr->certificate, buffer + offset, chunk_size); + + // Move the offset by chunk size + offset += chunk_size; + + // Subtract the rem_len by the chunk size + rem_len -= chunk_size; + + //Set the total length of certificate + rsi_uint16_to_2bytes(rsi_chunk_ptr->cert_info.total_len, certificate_length); + + // Set the certificate type + rsi_chunk_ptr->cert_info.certificate_type = certificate_type; + + // Set the certificate index + rsi_chunk_ptr->cert_info.certificate_inx = cert_inx; + + // More chunks to send + rsi_chunk_ptr->cert_info.more_chunks = 1; + + // Set the length of the certificate chunk + rsi_uint16_to_2bytes(rsi_chunk_ptr->cert_info.certificate_length, chunk_size); + + rsi_response_wait_time = RSI_CERTIFICATE_RESPONSE_WAIT_TIME; +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send the driver command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_CERTIFICATE, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + } else { + + // Copy the certificate chunk + memcpy(rsi_chunk_ptr->certificate, buffer + offset, rem_len); + + // Move the offset by chunk size + offset += rem_len; + + //Set the total length of certificate + rsi_uint16_to_2bytes(rsi_chunk_ptr->cert_info.total_len, certificate_length); + + // Set the certificate type + rsi_chunk_ptr->cert_info.certificate_type = certificate_type; + + // Set the certificate index + rsi_chunk_ptr->cert_info.certificate_inx = cert_inx; + + // Last chunks to send + rsi_chunk_ptr->cert_info.more_chunks = 0; + + // Set the length of the certificate chunk + rsi_uint16_to_2bytes(rsi_chunk_ptr->cert_info.certificate_length, rem_len); + + rsi_response_wait_time = RSI_CERTIFICATE_RESPONSE_WAIT_TIME; +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send the driver command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_CERTIFICATE, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_ERROR_IN_SENDING_COMMAND_3, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Reset rem_len and offset + rem_len = 0; + offset = 0; + } + } + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + // Return status + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_INDEX_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} +/** @} */ + +/** @addtogroup NETWORK16 +* @{ +*/ +/*==============================================*/ +/** + * @brief Load SSL/EAP certificate in the module. This is a blocking API. + * @param[in] certificate_type - Type of certificate \n + * These are the certificate types: \n + * Value | Certificate type + * |:---------|:---------------------- + * 1 | TLS client certificate \n + * 2 | FAST PAC file \n + * 3 | SSL Client Certificate \n + * 4 | SSL Client Private Key \n + * 5 | SSL CA Certificate \n + * 6 | SSL Server Certificate \n + * 7 | SSL Server Private Key \n + * @param[in] buffer - Pointer to a buffer which contains the certificate + * @param[in] certificate_length - Certificate length + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0015,0x0021,0x0025,0x0026,0x002C) \n + * @note **Precondition** - \ref rsi_wireless_init() API must be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_wlan_set_certificate(uint8_t certificate_type, uint8_t *buffer, uint32_t certificate_length) +{ + SL_PRINTF(SL_WLAN_SET_CERTIFICATE_EXIT, NETWORK, LOG_INFO); + return rsi_wlan_set_certificate_index(certificate_type, 0, buffer, certificate_length); +} +/** @} */ + +/** @addtogroup WLAN +* @{ +*/ +/*==============================================*/ +/** + * @brief Check the error code encountered during a call to a WLAN API or BSD sockets functions. This is a non-blocking API. + * @param[in] Void + * @return Returns the error code that previously occurred. If no error occurred, returns 0. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_wlan_get_status(void) +{ + SL_PRINTF(SL_WLAN_GET_STATUS_EXIT, WLAN, LOG_INFO); + return rsi_driver_cb->wlan_cb->status; +} + +/*==============================================*/ +/** + * @brief Get the required information based on the type of command. This is a blocking API. + * @param[in] cmd_type - Query command type: \n + * Value | Command Type + * :---|:--------------------- + * 1 | RSI_FW_VERSION \n + * 2 | RSI_MAC_ADDRESS \n + * 3 | RSI_RSSI \n + * 4 | RSI_WLAN_INFO \n + * 5 | RSI_CONNECTION_STATUS \n + * 6 | RSI_STATIONS_INFO \n + * 7 | RSI_SOCKETS_INFO \n + * 8 | RSI_CFG_GET \n + * 9 | RSI_GET_WLAN_STAT + * @param[out] response - Response of the requested command. + * @param[in] length - Length of the response buffer in bytes to hold result. + * @note RSI_WLAN_INFO is relevant in both station and AP mode. \n + * @note RSI_SOCKETS_INFO is relevant in both station mode and AP mode. \n + * @note RSI_STATIONS_INFO is relevant in AP mode \n + * @note RSI_GET_WLAN_STATS is relevant in AP and Station mode + * @return 0 - Success + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffc,0xfffffffa) \n + * @note **Precondition** - \ref rsi_wireless_init () API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ +int32_t rsi_wlan_get(rsi_wlan_query_cmd_t cmd_type, uint8_t *response, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt; + int32_t rsi_response_wait_time = 0; + + SL_PRINTF(SL_WLAN_GET_ENTRY, WLAN, LOG_INFO); + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Get common control block structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + // If state is not in card ready received state + if (common_cb->state == RSI_COMMON_STATE_NONE) { + if (cmd_type == RSI_FW_VERSION) { + while (common_cb->state != RSI_COMMON_CARDREADY) { +#ifndef RSI_WITH_OS + rsi_scheduler(&rsi_driver_cb->scheduler_cb); +#endif + } + } else { + // Command given in wrong state + SL_PRINTF(SL_WLAN_GET_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + } + + if (cmd_type == RSI_FW_VERSION) { + // Send firmware version query request + status = rsi_get_fw_version(response, length); + SL_PRINTF(SL_WLAN_GET_FW_VERSION_QUERY_REQ, WLAN, LOG_INFO, "status: %4x", status); + return status; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Copy query CMD type in driver control block + wlan_cb->query_cmd = cmd_type; + + if (response != NULL) { + // Attach the buffer given by user + wlan_cb->app_buffer = response; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + } else { + // Assign NULL to the app_buffer to avoid junk + wlan_cb->app_buffer = NULL; + + // Length of the buffer to 0 + wlan_cb->app_buffer_length = 0; + } + switch (cmd_type) { + case RSI_RSSI: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + rsi_response_wait_time = RSI_WLAN_RSSI_RESPONSE_WAIT_TIME; +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send RSSI query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_RSSI, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_MAC_ADDRESS: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send MAC address query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_MAC_ADDRESS, pkt); + rsi_response_wait_time = RSI_MAC_RESPONSE_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_CONNECTION_STATUS: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_3, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send MAC address query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CONNECTION_STATUS, pkt); + rsi_response_wait_time = RSI_CONNECT_RESPONSE_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_WLAN_INFO: { + if (length < sizeof(rsi_rsp_wireless_info_t)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + SL_PRINTF(SL_WLAN_GET_INSUFFICIENT_BUFFER_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + if (wlan_cb->opermode == RSI_WLAN_ACCESS_POINT_MODE) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send CMD for WLAN info in AP mode + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_QUERY_GO_PARAMS, pkt); + rsi_response_wait_time = RSI_WLAN_QUERY_NETWORK_PARAMS_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + } else if ((wlan_cb->opermode == RSI_WLAN_CLIENT_MODE) || (wlan_cb->opermode == RSI_WLAN_ENTERPRISE_CLIENT_MODE) + || (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE)) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_5, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send CMD for WLAN info in client mode + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_QUERY_NETWORK_PARAMS, pkt); + rsi_response_wait_time = RSI_WLAN_QUERY_NETWORK_PARAMS_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + } else if (wlan_cb->opermode == RSI_WLAN_WIFI_DIRECT_MODE) { + // No code here + } + } break; + case RSI_STATIONS_INFO: { + if (length < sizeof(rsi_rsp_stations_info_t)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + SL_PRINTF(SL_WLAN_GET_INSUFFICIENT_BUFFER_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_6, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send MAC address query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_QUERY_GO_PARAMS, pkt); + rsi_response_wait_time = RSI_WLAN_REQ_QUERY_GO_PARAMS; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_SOCKETS_INFO: { + if (length < sizeof(rsi_rsp_sockets_info_t)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + SL_PRINTF(SL_WLAN_GET_INSUFFICIENT_BUFFER_3, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_7, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send MAC address query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_QUERY_NETWORK_PARAMS, pkt); + rsi_response_wait_time = RSI_WLAN_QUERY_NETWORK_PARAMS_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_CFG_GET: { + if (length < sizeof(rsi_cfgGetFrameRcv_t)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + SL_PRINTF(SL_WLAN_GET_INSUFFICIENT_BUFFER_4, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_8, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send CFG_GET command for getting user store configuration + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_GET_CFG, pkt); + rsi_response_wait_time = RSI_WLAN_REQ_GET_CFG_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_GET_WLAN_STATS: { + + if (length < sizeof(rsi_rsp_wlan_stats_t)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + SL_PRINTF(SL_WLAN_GET_INSUFFICIENT_BUFFER_5, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send Wi-fi STATS query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_GET_STATS, pkt); + rsi_response_wait_time = RSI_WLAN_REQ_GET_STATS_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_WLAN_EXT_STATS: { + + if (length < sizeof(rsi_wlan_ext_stats_t)) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // SL_PRINTF(SL_WLAN_GET_INSUFFICIENT_BUFFER_5, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INSUFFICIENT_BUFFER; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + // SL_PRINTF(SL_WLAN_GET_PKT_ALLOCATION_FAILURE_9, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send Wi-fi STATS query request + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_EXT_STATS, pkt); + rsi_response_wait_time = RSI_WLAN_REQ_EXT_STATS_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + } break; + case RSI_FW_VERSION: + break; + default: + // Return status if command given in driver is in an invalid state + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + break; + } + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_GET_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_WLAN_GET_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Request configuration based on the command type. This is a blocking API. + * @param[in] cmd_type - Set command type: : \n + * Value | Command Type + * :---|:---------------------: + * 1 | RSI_SET_MAC_ADDRESS \n + * 2 | RSI_MULTICAST_FILTER \n + * 3 | RSI_JOIN_BSSID \n + * 4 | RSI_CFG_SAVE \n + * 5 | RSI_CFG_STORE \n + * @param[in] request - Request buffer + * @param[in] length - Length of the request buffer in bytes + * cmd type | Request structure + * :-----------------------|:--------------------------------------------------------------------------------------------------: + * RSI_SET_MAC_ADDRESS | uint8_t mac_address[6] + * RSI_MULTICAST_FILTER | typedef struct rsi_req_multicast_filter_info_s + * ^ { uint8_t cmd_type; + * ^ uint8_t mac_address[6]; + * ^ }rsi_req_multicast_filter_info_t; + * ^ cmd_type are : \n + * ^ 1 . RSI_ MULTICAST_MAC_ADD_BIT (To set particular bit in multicast bitmap) + * ^ 2 . RSI_MULTICAST_MAC_CLEAR_BIT (To reset particular bit in multicast bitmap + * ^ 3 . RSI_MULTICAST_MAC_CLEAR_ALL (To clear all the bits in multicast bitmap) \n + * ^ 4 . RSI_MULTICAST_MAC_SET_ALL (To set all the bits in multicast bitmap) \n + * RSI_JOIN_BSSID | uint8_t join_bssid[6] + * RSI_CFG_SAVE | This cmd_type is used to save the parameters into non-volatile memory which are used either to join to an Access point (auto-join mode) or to create an Access point(auto-create mode). + * RSI_CFG_STORE | This cmd_type is used to give the configuration values which are supposed to be stored in the module's non-volatile memory and that are used in auto-join or auto-create modes. + * ^ User configurations are stored in rsi_user_store_config_t structure. \n + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffc,0x0002, 0x0003, 0x0005, 0x000A, 0x0014, 0x0015, 0x001A, 0x0021,0x0024,0x0025,0x0026,0x002C,0x003c) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. \n + * For setting MAC address, call this API immediately after \n + * \ref rsi_wireless_init() and before calling any other API. \n + * \ref rsi_config_ipaddress() needs to be call for RSI_CFG_SAVE and RSI_CFG_STORE. + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ +int32_t rsi_wlan_set(rsi_wlan_set_cmd_t cmd_type, uint8_t *request, uint16_t length) +{ + // Statement added to resolve compilation warning, value is unchanged + UNUSED_PARAMETER(length); + int32_t status = RSI_SUCCESS; + + SL_PRINTF(SL_WLAN_SET_ENTRY, WLAN, LOG_INFO); + rsi_pkt_t *pkt; + rsi_user_store_config_t *user_store_ptr = NULL; + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + int32_t rsi_response_wait_time = 0; + // Get common control block structure pointer + rsi_common_cb_t *common_cb = rsi_driver_cb->common_cb; + + // If state is not in card ready received state + if (common_cb->state == RSI_COMMON_STATE_NONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SET_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + if (!(cmd_type == 4)) { + if (request == NULL) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SET_NVALID_PARAM, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + switch (cmd_type) { + case RSI_SET_MAC_ADDRESS: { + // Enable valid bit to ensure setting MAC id before every initilization + wlan_cb->field_valid_bit_map |= RSI_SET_MAC_BIT; + + // Copy MAC address in to WLAN control block + memcpy(wlan_cb->mac_address, request, 6); + + } break; + + case RSI_MULTICAST_FILTER: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SET_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_multicast_filter_info_t)); + + // Copy MAC address + memcpy((uint8_t *)&pkt->data, request, sizeof(rsi_req_multicast_filter_info_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Set multicast filter configuration + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_MULTICAST_FILTER, pkt); + rsi_response_wait_time = RSI_MULTICAST_FIL_RESPONSE_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + } break; + + case RSI_JOIN_BSSID: { + + // Copy MAC address in to WLAN control block + memcpy(rsi_wlan_cb_non_rom->join_bssid_non_rom, request, 6); + + } break; + + case RSI_CFG_SAVE: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SET_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send CFG_SAVE command for saving user store configuration. + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CFG_SAVE, pkt); + rsi_response_wait_time = RSI_WLAN_CFG_SAVE_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + case RSI_CFG_STORE: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SET_PKT_ALLOCATION_FAILURE_3, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + user_store_ptr = (rsi_user_store_config_t *)pkt->data; + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_user_store_config_t)); + // Copy user store configuration parameter to the packet + memcpy(user_store_ptr, (rsi_user_store_config_t *)request, sizeof(rsi_user_store_config_t)); +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send PSK command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_USER_STORE_CONFIG, pkt); + rsi_response_wait_time = RSI_USER_SC_RESPONSE_WAIT_TIME; + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, rsi_response_wait_time); + + } break; + + default: + // Return status if command given in driver is in an invalid state + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + break; + } + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SET_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_WLAN_SET_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_buffer_config(void) + * @brief Configure the TX and RX global buffers ratio. This is a blocking API. + * @param[in] dynamic_tx_pool - Configure the dynamic tx ratio + * @param[in] dynamic_rx_pool - Configure the dynamic rx ratio + * @param[in] dynamic_global_pool - Configure the dynamic global ratio + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0021) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ +int32_t rsi_wlan_buffer_config(void) +{ + rsi_pkt_t *pkt; + rsi_udynamic *dyn_buf; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_BUFFER_CONFIG_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_BUFFER_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_BUFFER_CONFIG_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in antenna select structure + dyn_buf = (rsi_udynamic *)pkt->data; + + // PLL mode value + dyn_buf->dynamic_tx_pool = TX_POOL_RATIO; + + // RF type + dyn_buf->dynamic_rx_pool = RX_POOL_RATIO; + + // Wireless mode + dyn_buf->dynamic_global_pool = GLOBAL_POOL_RATIO; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send antenna select command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DYNAMIC_POOL, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_DYNAMIC_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_BUFFER_CONFIG_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status + SL_PRINTF(SL_WLAN_BUFFER_CONFIG_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Start the module in access point mode with the given configuration. This is a blocking API. + * @param[in] ssid - SSID of the access point. Length of the SSID should be less than or equal to 32 bytes. + * @param[in] channel - Channel number. Refer the following channels for the valid channel numbers supported: \n + * 2.4GHz Band Channel Mapping, 5GHz Band Channel Mapping \n + * channel number 0 is to enable ACS feature + * ###The following table maps the channel number to the actual radio frequency in the 2.4 GHz spectrum### + * Channel numbers (2.4GHz)| Center frequencies for 20MHz channel width + * :----------------------:|:-----------------------------------------------: + * 1 | 2412 + * 2 | 2417 + * 3 | 2422 + * 4 | 2427 + * 5 | 2432 + * 6 | 2437 + * 7 | 2442 + * 8 | 2447 + * 9 | 2452 + * 10 | 2457 + * 11 | 2462 + * 12 | 2467 + * 13 | 2472 + * 14 | 2484 + * ###The following table maps the channel number to the actual radio frequency in the 5 GHz spectrum### + * Channel Numbers(5GHz) | Center frequencies for 20MHz channel width + * :--------------------:|:------------------------------------------: + * 36 |5180 + * 40 |5200 + * 44 |5220 + * 48 |5240 + * 144 |5700 + * 149 |5745 + * 153 |5765 + * 157 |5785 + * 161 |5805 + * 165 |5825 + * @param[in] security_type - Type of the security modes on which an access point needs to be operated: \n + * Value | Security type + * :----:|:------------------------------------------: + * 1 | RSI_OPEN \n + * 2 | RSI_WPA \n + * 3 | RSI_WPA2 \n + * 4 | RSI_WPA_WPA2_MIXED \n + * 5 | RSI_WPS_PUSH_BUTTON + * @param[in] encryption_mode - Type of the encryption mode: \n + * Value | Encryption mode + * :----:|:------------------------------------------: + * 0 | RSI_NONE \n + * 1 | RSI_TKIP \n + * 2 | RSI_CCMP + * @param[in] password - PSK to be used in security mode. \n + * Minimum and maximum length of PSK is 8 bytes and 63 bytes respectively + * @param[in] beacon_interval - Beacon interval in ms. Allowed values are integers from 100 to 1000 which are multiples of 100. + * @param[in] dtim_period - DTIM period. Allowed values are integers between 1 and 255. + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note DFS channels are not supported in AP mode. + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ +int32_t rsi_wlan_ap_start(int8_t *ssid, + uint8_t channel, + rsi_security_mode_t security_type, + rsi_encryption_mode_t encryption_mode, + uint8_t *password, + uint16_t beacon_interval, + uint8_t dtim_period) +{ + + rsi_pkt_t *pkt; + rsi_req_join_t *join; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_AP_START_ENTRY, WLAN, LOG_INFO); + rsi_req_ap_config_t *ap_config; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_AP_START_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + switch (wlan_cb->state) { + case RSI_WLAN_STATE_OPERMODE_DONE: { + if (wlan_cb->field_valid_bit_map & RSI_SET_MAC_BIT) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_1, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_mac_address_t)); + + // Memcpy data + memcpy(&pkt->data, wlan_cb->mac_address, sizeof(rsi_req_mac_address_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set MAC command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_MAC_ADDRESS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_MAC_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_2, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_band_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send band command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_BAND, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_BAND_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // If BAND command fails + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + } + // No break + // Fall through + case RSI_WLAN_STATE_BAND_DONE: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_3, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send init command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_INIT, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_INIT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_3, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#if RSI_SET_REGION_AP_SUPPORT + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset data + memset(&pkt->data, 0, sizeof(rsi_req_set_region_ap_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set region AP command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_REGION_AP, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_REGION_AP_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_4, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + } + // No break + // Fall through + case RSI_WLAN_STATE_CONNECTED: { + // Reject if AP is already up, allow if connected state is due to STA + if (wlan_cb->opermode == RSI_WLAN_CONCURRENT_MODE && wlan_cb->ap_state >= RSI_WLAN_STATE_CONNECTED) { + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + break; + } + } + // No break + // Fall through + case RSI_WLAN_STATE_IP_CONFIG_DONE: + case RSI_WLAN_STATE_IPV6_CONFIG_DONE: + case RSI_WLAN_STATE_INIT_DONE: { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_4, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset packet + memset(&pkt->data, 0, sizeof(rsi_req_ap_config_t)); + + ap_config = (rsi_req_ap_config_t *)pkt->data; + + // Copy channel by uint16 to 2 bytes conversion + rsi_uint16_to_2bytes(ap_config->channel, channel); + + if (ssid != NULL) { + // Copy Join SSID + rsi_strcpy(ap_config->ssid, ssid); + } + + // Security type + ap_config->security_type = security_type; + if (ap_config->security_type == RSI_WPA3) { + ap_config->security_type = SME_WPA3; + } + if (ap_config->security_type == RSI_WPA3_TRANSITION) { + ap_config->security_type = SME_WPA3_TRANSITION; + } + + // Encryption mode + ap_config->encryption_mode = encryption_mode; + + // If security is enabled + if (security_type) { + // Copy PSK + rsi_strcpy(ap_config->psk, password); + } + + // Copy beacon interval by uint16 to 2 bytes conversion + rsi_uint16_to_2bytes(ap_config->beacon_interval, beacon_interval); + + // Copy DTIM period by uint16 to 2 bytes conversion + rsi_uint16_to_2bytes(ap_config->dtim_period, dtim_period); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send AP config command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_AP_CONFIGURATION, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_AP_CONFIG_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + // Check status for AP config command + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_5, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + +#if RSI_MODE_11N_ENABLE + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_5, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset packet + memset(&pkt->data, 0, sizeof(rsi_req_ap_ht_caps_t)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send HT capabilities command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HT_CAPABILITIES, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_HT_CAPS_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_6, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } +#endif + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_AP_START_PKT_ALLOCATION_FAILURE_6, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_join_t)); + + join = (rsi_req_join_t *)pkt->data; + + if (ssid != NULL) { + // Copy SSID and SSID len + join->ssid_len = rsi_strlen(ssid); + + // Copy Join SSID + rsi_strcpy(join->ssid, ssid); + } + + // vap id of the current mode 0 - station mode, 1 - AP1 mode + // Applicable in cocurrent mode only +#if CONCURRENT_MODE + join->vap_id = 1; +#else + join->vap_id = 0; +#endif + + // Deregister join response handler + rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler = NULL; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send join command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_JOIN, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_JOIN_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + if (status != RSI_SUCCESS) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_7, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + } break; + + case RSI_WLAN_STATE_NONE: + case RSI_WLAN_STATE_SCAN_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON: + case RSI_WLAN_STATE_AUTO_CONFIG_DONE: + case RSI_WLAN_STATE_AUTO_CONFIG_FAILED: + + break; + default: { + // Return status if command given in driver is in an invalid state + status = RSI_ERROR_COMMAND_NOT_SUPPORTED; + } break; + } + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return NWK command error + SL_PRINTF(SL_WLAN_AP_START_NWK_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_AP_START_ERROR_IN_SENDING_COMMAND_8, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_power_save_with_listen_interval(uint8_t psp_mode, uint8_t psp_type,uint16_t listen_interval) + * @brief Set the power save profile in WLAN mode with listen interval-based wakeup. This is a blocking API. + * @param[in] psp_mode - PSP modes available are mentioned below + * Parameter | Description + * :----------------------|:-------------------------------------------------------------------------------------------------- + * Active(0) | In this mode, module is active and power save is disabled. \n + * RSI_SLEEP_MODE_1 (1) | Connected sleep mode. \n + * ^ In this sleep mode, SoC will never turn off, therefore no handshake is required before sending data to the module. \n + * RSI_SLEEP_MODE_2 (2) | In this sleep mode, SoC will go to LP/ULP (with/without RAM RETENTION) sleep based on the selected value set for RSI_SELECT_LP_OR_ULP_MODE in rsi_wlan_config.h. \n + * ^ Therefore handshake is required before sending data to the module. \n + * RSI_SLEEP_MODE_8 (8) | Deep sleep mode with ULP RAM RETENTION. In deep sleep mode, module will turn off the SoC and a GPIO or Message based handshake is required before sending commands to the module. \n + * RSI_SLEEP_MODE_10 (10) | Deep sleep mode without ULP RAM RETENTION. \n + * @param[in] psp_type - PSP types available are mentioned below + * Parameter | Description + * :----------------------|:-------------------------------------------------------------------------------------------------- + * RSI_MAX_PSP (0) | This psp_type will be used for max power saving. \n + * RSI_FAST_PSP (1) | This psp_type allows module to disable power save for any Tx / Rx packet for monitor interval of time \n + * ^ (monitor interval can be set by RSI_MONITOR_INTERVAL in rsi_wlan_config.h file, default value is 50 ms). \n + * ^ If there is no data for monitor interval of time then module will again enable power save. \n + * RSI_UAPSD (2) | This psp_type is used to enable WMM power save. + * @param[in] listen_interval - Used to configure sleep duration in power save and should be less than the listen interval configured by RSI_LISTEN_INTERVAL Macro in join command parameters in rsi_wlan_config.h file. \n + * Valid only if BIT (7) in join_feature_bit_map is set. This value is given in time units (1024 microsecond). \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note psp_type is only valid in psp_mode 1 and 2. \n + * @note psp_type: RSI_UAPSD is applicable only, if WMM_PS is enabled in rsi_wlan_config.h file. \n + * @note In RSI_MAX_PSP mode, Few access points will not aggregate the packets, when power save is enabled from STA. This may cause the drop in throughputs. + * @note For the power save mode 3, select RSI_SLEEP_MODE_2 in psp_mode and RSI_HAND_SHAKE_TYPE as MSG_BASED in rsi_wlan_config.h file. \n + * @note For the power save mode 9, select RSI_SLEEP_MODE_8 in psp_mode and RSI_HAND_SHAKE_TYPE as MSG_BASED in rsi_wlan_config.h file. \n + * @note For the deep sleep without ram retention case, select RSI_SLEEP_MODE_10 in psp_mode and RSI_HAND_SHAKE_TYPE as MSG_BASED for msg_based or GPIO_BASED for gpio_based. \n + * @note For LP sleep, select RSI_SLEEP_MODE_2 in psp_mode, select RSI_SELECT_LP_OR_ULP_MODE as RSI_LP_MODE and RSI_HAND_SHAKE_TYPE as MSG_BASED/GPIO_BASED in rsi_wlan_config.h file. \n + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa) \n + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_wlan_power_save_with_listen_interval(uint8_t psp_mode, uint8_t psp_type, uint16_t listen_interval) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_ENTRY, WLAN, LOG_INFO); + // Get commmon CB pointer + rsi_common_cb_t *rsi_common_cb = rsi_driver_cb->common_cb; + + // Keep backup of power save profile mode and type + rsi_common_cb->power_save.wlan_psp_type = psp_type; + + // Keep backup of power save profile mode and type + rsi_common_cb->power_save.wlan_psp_mode = psp_mode; + + rsi_wlan_cb_non_rom->ps_listen_interval = listen_interval; + + status = rsi_sleep_mode_decision(rsi_common_cb); + SL_PRINTF(SL_WLAN_POWER_SAVE_LISTEN_INTERVAL_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Set the power save profile in WLAN mode. This is a blocking API. + * @param[in] psp_mode - PSP modes available are mentioned below + * Parameter | Description + * :----------------------|:-------------------------------------------------------------------------------------------------- + * Active(0) | In this mode, module is active and power save is disabled. \n + * RSI_SLEEP_MODE_1 (1) | Connected sleep mode. \n + * ^ In this sleep mode, SoC will never turn off, therefore no handshake is required before sending data to the module. \n + * RSI_SLEEP_MODE_2 (2) | In this sleep mode, SoC will go to LP/ULP (with/without RAM RETENTION) sleep based on the selected value set for RSI_SELECT_LP_OR_ULP_MODE in rsi_wlan_config.h. \n + * ^ Therefore handshake is required before sending data to the module. \n + * RSI_SLEEP_MODE_8 (8) | Deep sleep mode with ULP RAM RETENTION. In deep sleep mode, module will turn off the SoC and a GPIO or Message based handshake is required before sending commands to the module. \n + * RSI_SLEEP_MODE_10 (10) | Deep sleep mode without ULP RAM RETENTION. \n + * @param[in] psp_type - PSP types available are mentioned below + * Parameter | Description + * :----------------------|:-------------------------------------------------------------------------------------------------- + * RSI_MAX_PSP (0) | This psp_type will be used for max power saving. \n + * RSI_FAST_PSP (1) | This psp_type allows module to disable power save for any Tx / Rx packet for monitor interval of time \n + * ^ (monitor interval can be set by RSI_MONITOR_INTERVAL in rsi_wlan_config.h file, default value is 50 ms). \n + * ^ If there is no data for monitor interval of time then module will again enable power save. \n + * RSI_UAPSD (2) | This psp_type is used to enable WMM power save. + * ### Enhanced max psp ### + * Enhanced max PSP is recommended. This is essentially a RSI_MAX_PSP but switches to RSI_FAST_PSP, if AP does not deliver data within 20ms for PS-Poll. \n + * To enable this mode, follow this procedure: \n + * Add ENABLE_ENHANCED_MAX_PSP (BIT[26]) in RSI_CONFIG_FEATURE_BITMAP, \n + * Set psp_type to RSI_FAST_PSP (1) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Configure the monitor interval using the RSI_MONITOR_INTERVAL macro in rsi_wlan_config.h file. (default value is 50 ms) \n + * @note psp_type is only valid in psp_mode 1 and 2. \n + * @note psp_type - UAPSD is applicable only if WMM_PS is enabled in rsi_wlan_config.h file. \n + * @note In RSI_MAX_PSP mode, Few Access points won't aggregate the packets, when power save is enabled from STA. This may cause the drop in throughputs.\n + * @note For the power save mode 3, select RSI_SLEEP_MODE_2 in psp_mode and RSI_HAND_SHAKE_TYPE as MSG_BASED in rsi_wlan_config.h file.\n + * @note For the power save mode 9, select RSI_SLEEP_MODE_8 in psp_mode and RSI_HAND_SHAKE_TYPE as MSG_BASED in rsi_wlan_config.h file.\n + * @note For the deep sleep without ram retention case, select RSI_SLEEP_MODE_10 in psp_mode and RSI_HAND_SHAKE_TYPE as MSG_BASED for msg_based or GPIO_BASED for gpio_based.\n + * @note For LP sleep, select RSI_SLEEP_MODE_2 in psp_mode, select RSI_SELECT_LP_OR_ULP_MODE as RSI_LP_MODE and RSI_HAND_SHAKE_TYPE as MSG_BASED/GPIO_BASED in rsi_wlan_config.h file.\n + * @note Powersave handshake option: \n + * - When sleep clock source is configured to '32KHz bypass clock on UULP_VBAT_GPIO_3', \n + * use UULP_VBAT_GPIO_0 for SLEEP_IND_FROM_DEV \n + * set RS9116_SILICON_CHIP_VER in 'RS9116.NB0.WC.GENR.OSI.X.X.X\host\sapis\include\rsi_user.h' to 'CHIP_VER_1P4_AND_ABOVE' \n + * - If not using external clock on UULP_VBAT_GPIO_3' as sleep clock source, \n + * use UULP_VBAT_GPIO_3 for SLEEP_IND_FROM_DEV \n + * set RS9116_SILICON_CHIP_VER in 'RS9116.NB0.WC.GENR.OSI.X.X.X\host\sapis\include\rsi_user.h' to 'CHIP_VER_1P3'. \n + * EXT_FEAT_LOW_POWER_MODE is not supported for 1.3 version chipset(CHIP_VER_1P3). + * ## Power save modes description ## + * + **Power Save Mode 0** \n + * - In this mode, module is active and power save is disabled. It can be configured any time, while the module is configured in Power Save mode 2 or 8.\n + * + **Power save Mode 1** \n + * - Once the module is configured to power save mode 1, it wakes up periodically based upon the DTIM interval configured in connected AP. \n + * In power mode 1, only the RF of the module is in power save while SOC continues to work normally. \n + * This command has to be given only when module is in connected state (with the AP). After having configured the module to power save mode, the Host can issue subsequent commands. \n + * In power save mode 1 the module can receive data from host at any point of time but it can send/receive the data to/from remote terminal only when it is awake at DTIM intervals. \n + * + **Power Save Mode 2** \n + * - Once the module is configured to power save mode 2, it can be woken up either by the Host or periodically during its sleep-wakeup cycle. \n + * Power Save mode 2 is GPIO based. \n + * In case of GPIO based mode, whenever host wants to send data to module, it gives wakeup request by asserting UULP GPIO #2. \n + * After wakeup, if the module is ready for data transfer, it sends wakeup indication to host by asserting UULP GPIO #3 or UULP GPIO #0. \n + * Host is required to wait until module gives wakeup indication before sending any data to the module. \n + * After the completion of data transfer, host can give sleep permission to module by de-asserting UULP GPIO #2. After recognizing sleep permission from host, \n + * module gives confirmation to host by de-asserting UULP GPIO #3 or UULP GPIO #0 and again goes back to its sleep-wakeup cycle. \n + * Module can send received packets or responses to host at any instant of time. No handshake is required on Rx path. \n + * + **Power Save mode 3** \n + * - Power Mode 3 is message based power save. In Power Mode 3, both radio and SOC of RS9116-WiSeConnect are in power save mode. \n + * This mode is significant when module is in associated state with AP. Module wakes up periodically upon every DTIM and gives wakeup message ("WKP") to host. \n + * Module can not be woken up asynchronously. Every time module intends to go to sleep it sends a sleep request message ("SLP") to the host and expects host to send the acknowledgement message ("ACK"). \n + * Host either send acknowledgement ("ACK") or any other pending message. But once ACK is sent, Host should not send any other message unless next wakeup message from module is received. \n + * Module shall not go into complete power-save state, if ACK is not received from host for given sleep message. Module can send received packets or responses to host at any instant of time. \n + * No handshake is required on Rx path. \n + * + **Power Save mode 8** \n + * - In Power save mode 8, both RF and SOC of the module are in complete power save mode. This mode is significant only when module is in un-connected state. \n + * Power Save mode 8 can be GPIO based. \n + * In case of GPIO based, host can wakeup the module from power save by asserting UULP GPIO #2. \n + * After wakeup, if the module is ready for data transfer, it sends wakeup indication to host by asserting UULP GPIO #3 or UULP GPIO #0. \n + * Host is required to wait until module gives wakeup indication before sending any data to the module. \n + * After the completion of data transfer, host can give sleep permission to module by de-asserting UULP GPIO #2. After recognizing sleep permission from host, + * module gives confirmation to host by de-asserting UULP GPIO #3 or UULP GPIO #0 and again goes back to its sleep-wakeup cycle. \n + * Module can send received packets or responses to host at any instant of time. No handshake is required on Rx path. \n + * + **Power save mode 9** \n + * - In Power Mode 9 both Radio and SOC of RS9116-WiSeConnect are in complete power save mode. This mode is significant when module is not connected with any AP. \n + * Once power mode 9 command is given, the module sends ("SLP") request to host and wait for the ("ACK") from host and goes to sleep when ACK is given by host. Timer starts when power save command is issued and it can be configured by host using \ref rsi_wlan_set_sleep_timer API. \n + * If host does not set any sleep time, then the timer is configured for 3sec by default. Upon wakeup module sends a wakeup message to the host and expects host to give ACK before \n + * it goes into next sleep cycle. Host either send ACK or any other messages but once ACK is sent no other packet should be sent before receiving next wakeup message. \n + * When ulp_mode_enable is set to '2', after waking up from sleep, the module sends WKP FRM SLEEP message to host when RAM retention is not enabled. \n + * After receiving WKP FRM SLEEP message, host needs to start giving commands from beginning as module's state is not retained. \n + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0xfffffffa,0x0021,0x0025,0x002C,0xFFF8,0x0015,0x0026,0x0052) \n + * @note If the user wants to enable power save in CoEx mode (WLAN + BT LE) mode - It is mandatory to enable WLAN power save along with BT power save. \n + * @note In CoEx mode, the device will enter into power save only if both protocol (WLAN, BLE) power save modes are enabled. \n + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_power_save_profile(uint8_t psp_mode, uint8_t psp_type) +{ + int32_t status = RSI_SUCCESS; + status = rsi_wlan_power_save_with_listen_interval(psp_mode, psp_type, 0); + SL_PRINTF(SL_WLAN_POWER_SAVE_PROFILE_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Disable or enable the power save feature. This is a blocking API. + * @param[in] psp_mode - Power save mode + * @param[in] psp_tye - Power save type + * @return 0 - Success \n + * @return Non-Zero Value - Failure \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note If RSI_SLEEP_MODE_10 is chosen as the sleep mode, commands should be recalled from driver_init() as this is without RAM retention. + * + * + */ +int32_t rsi_wlan_power_save_disable_and_enable(uint8_t psp_mode, uint8_t psp_type) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ENTRY, WLAN, LOG_INFO); + status = rsi_wlan_power_save_profile(RSI_ACTIVE, psp_type); + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + status = rsi_wlan_power_save_profile(psp_mode, psp_type); + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + SL_PRINTF(SL_WLAN_POWER_SAVE_DISABLE_ENABLE_EXIT, WLAN, LOG_INFO, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Start the transmit test. This is a blocking API. \n + * This API is relevant in PER mode. + * @param[in] power - Set TX power in dbm. The valid values are from 2dBm to 18dBm. \n + * @note User can configure the maximum power level allowed for the given frequncey in the configured region by providing 127 as power level \n + * @note User should configure a minimum delay (approx. 10 milliseconds) before and after \ref rsi_transmit_test_start API to observe a stable output at requested dBm level. \n + * @param[in] rate - Set transmit data rate + * @param[in] length - Configure length of the TX packet. \n + * The valid values are in the range of 24 to 1500 bytes in the burst mode and range of 24 to 260 bytes in the continuous mode. + * @param[in] mode - Below mentioned are the available modes + * Value | Parameter | Description + * :---------|:--------------------------------------------------|:------------------------------------------------- + * 0 | Burst Mode | DUT transmits a burst of packets with the given power, rate, length in the channel configured. + * ^ The burst size will be determined by the and if its zero, then DUT keeps transmitting till a rsi_transmit_test_stop API is called. + * 1 | Continuous Mode | The DUT transmits a unmodulated waveform continuously + * 2 | Continuous wave Mode (non modulation) in DC mode | The DUT transmits a spectrum only at the center frequency of the channel. + * ^ A basic signal with no modulation is that of a sine wave and is usually referred to as a continuous wave (CW) signal. + * ^ A basic signal source produces sine waves. Ideally, the sine wave is perfect. In the frequency domain, it is viewed as a single line at some specified frequency. + * 3 | Continuous wave Mode (non modulation) in single tone mode (center frequency -2.5MHz) | The DUT transmits a spectrum that is generated at -2.5MHz from the center frequency of the channel selected. + * ^ Some amount of carrier leakage will be seen at Center Frequency. Eg: for 2412MHz, the output will be seen at 2409.5MHz + * 4 | Continuous wave Mode (non modulation) in single tone mode (center frequency +5MHz) | The DUT transmits a spectrum that is generated at 5MHz from the center frequency of the channel selected. + * Some amount of carrier leakage will be seen at Center Frequency. Eg: for 2412MHz, the output will be seen at 2417MHz. + * @param[in] channel - Set the channel number in 2.4 GHz / 5GHz. + * ### Data Rates ### + * Data rate(Mbps) | Value of rate + * :--------------:|:-------------------: + * 1 | 0 + * 2 | 2 \n + * 5.5 | 4 \n + * 11 | 6 \n + * 6 | 139 \n + * 9 | 143 \n + * 12 | 138 \n + * 18 | 142 \n + * 24 | 137 \n + * 36 | 141 \n + * 48 | 136 \n + * 54 | 140 \n + * MCS0 | 256 \n + * MCS1 | 257 \n + * MCS2 | 258 \n + * MCS3 | 259 \n + * MCS4 | 260 \n + * MCS5 | 261 \n + * MCS6 | 262 \n + * MCS7 | 263 \n + * ###The following table maps the channel number to the actual radio frequency in the 2.4 GHz spectrum. ### + * Channel numbers (2.4GHz)| Center frequencies for 20MHz channel width + * :----------------------:|:-----------------------------------------------: + * 1 | 2412 + * 2 | 2417 + * 3 | 2422 + * 4 | 2427 + * 5 | 2432 + * 6 | 2437 + * 7 | 2442 + * 8 | 2447 + * 9 | 2452 + * 10 | 2457 + * 11 | 2462 + * 12 | 2467 + * 13 | 2472 + * 14 | 2484 + * ### The following table maps the channel number to the actual radio frequency in the 5 GHz spectrum for 20MHz channel bandwidth. The channel numbers in 5 GHz range is from 36 to 165. ### + * Channel Numbers(5GHz) | Center frequencies for 20MHz channel width + * :--------------------:|:------------------------------------------: + * 36 |5180 + * 40 |5200 + * 44 |5220 + * 48 |5240 + * 52 |5260 + * 56 |5280 + * 60 |5300 + * 64 |5320 + * 149 |5745 + * 153 |5765 + * 157 |5785 + * 161 |5805 + * 165 |5825 + * @note **Precondition** - \ref rsi_wlan_radio_init() API needs to be called before this API. + * @note Rate flags can be added in rsi_wlan_common_config.h file. \n + * In rate flags, BIT(6) - Immediate Transfer, set this bit to transfer packets immediately ignoring energy/traffic in channel \n + * @note Before starting Continuous Wave mode, user must start Continuous mode with power and channel values that are intended to be used in Continuous Wave mode i.e. \n + * - Start Continuous mode with intended power value and channel values - Pass any valid values for rate and length. \n + * - Stop Continuous mode \n + * - Start Continuous Wave mode \n + * @note If user wants to switch continuous wave mode, first need to stop the transmit test and again need to give continous wave mode which user wants to switch. + * @note In 2.4GHz, to start transmit test in 12,13,14 channels, configure set region parameters in rsi_wlan_config.h \n + * @return 0 - Success \n + * Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa,0x000A, 0x0021, 0x0025, 0x002C) \n + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_transmit_test_start(uint16_t power, uint32_t rate, uint16_t length, uint16_t mode, uint16_t channel) +{ + rsi_pkt_t *pkt; + rsi_req_tx_test_info_t *tx_test_info; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_TX_TEXT_START_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Check whether transmit test mode is selected + if (wlan_cb->opermode != RSI_WLAN_TRANSMIT_TEST_MODE) { + SL_PRINTF(SL_WLAN_TX_TEXT_START_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + // WLAN radio init + status = rsi_wlan_radio_init(); + + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_TX_TEXT_START_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Fill TX test info parameters + tx_test_info = (rsi_req_tx_test_info_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_tx_test_info_t)); + + // enable transmit test + rsi_uint16_to_2bytes(tx_test_info->enable, 1); + + // Configure transmit power of TX test + rsi_uint16_to_2bytes(tx_test_info->power, power); + + // Configure transmit rate of TX test + rsi_uint32_to_4bytes(tx_test_info->rate, rate); + + // Configure packet length of TX test + rsi_uint16_to_2bytes(tx_test_info->length, length); + + // Configure transmit mode of TX test + rsi_uint16_to_2bytes(tx_test_info->mode, mode); + + // Configure channel of TX test + rsi_uint16_to_2bytes(tx_test_info->channel, channel); + rsi_uint16_to_2bytes(tx_test_info->aggr_enable, RSI_TX_TEST_AGGR_ENABLE); +#ifdef CHIP_9117 + tx_test_info->enable_11ax = RSI_11AX_ENABLE; + if (tx_test_info->enable_11ax) { + tx_test_info->coding_type = RSI_CODING_TYPE; + tx_test_info->nominal_pe = RSI_NOMINAL_PE; + tx_test_info->he_ppdu_type = RSI_HE_PPDU_TYPE; + tx_test_info->beam_change = RSI_BEAM_CHANGE; + tx_test_info->BW = RSI_BW; + tx_test_info->UL_DL = RSI_UL_DL; + tx_test_info->STBC = RSI_STBC; + tx_test_info->Tx_BF = RSI_TX_BF; + tx_test_info->GI_LTF = RSI_GI_LTF; + tx_test_info->DCM = RSI_DCM; + tx_test_info->NSTS_MIDAMBLE = RSI_NSTS_MIDAMBLE; + tx_test_info->spatial_reuse = RSI_SPATIAL_REUSE; + tx_test_info->BSS_color = RSI_BSS_COLOR; + //tx_test_info->he_conf_params.HE_SIGA2_RESERVED = RSI_HE_SIGA2_RESERVED; + rsi_uint16_to_2bytes(tx_test_info->HE_SIGA2_RESERVED, RSI_HE_SIGA2_RESERVED); + tx_test_info->RU_ALLOCATION = RSI_RU_ALLOCATION; + tx_test_info->N_HELTF_TOT = RSI_N_HELTF_TOT; + tx_test_info->SIGB_DCM = RSI_SIGB_DCM; + tx_test_info->SIGB_MCS = RSI_SIGB_MCS; + //tx_test_info->he_conf_params.USER_STA_ID = RSI_USER_STA_ID; + rsi_uint16_to_2bytes(tx_test_info->USER_STA_ID, RSI_USER_STA_ID); + tx_test_info->USER_IDX = RSI_USER_IDX; + tx_test_info->SIGB_COMPRESSION_FIELD = RSI_SIGB_COMPRESSION_FIELD; + } +#endif +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_TX_TEST_MODE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_TRANSMIT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_TX_TEXT_START_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_TX_TEXT_START_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Stops the transmit test. This is a blocking API. \n + * This API is relevant in PER mode. + * @param[in] void + * @return 0 - Success + * @return Non Zero Value - Failure (**Possible Error Codes** - 0xfffffffa,0x0021, 0x0025, 0x002C) \n + * @note **Precondition** - \ref rsi_wlan_radio_init() API needs to be called before this API. + * @note User should configure a minimum delay (approx. 10 milliseconds) before and after \ref rsi_transmit_test_start API to observe a stable output at requested dBm level. \n + * @note Refer to Error Codes section for the description of the above error codes \ref error-codes. + * + */ + +int32_t rsi_transmit_test_stop(void) +{ + rsi_pkt_t *pkt; + rsi_req_tx_test_info_t *tx_test_info; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_TX_TEXT_STOP_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_TX_TEXT_STOP_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_TX_TEXT_STOP_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Fill TX test info parameters + tx_test_info = (rsi_req_tx_test_info_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_tx_test_info_t)); + + // Configure to stop TX test + rsi_uint16_to_2bytes(tx_test_info->enable, 0); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_TX_TEST_MODE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_TRANSMIT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_TX_TEXT_STOP_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_TX_TEXT_STOP_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Get the Transmit (TX) and Receive (RX) packets statistics. When this API is called by the host with valid channel number, + * the module gives the statistics to the host for every 1 second asynchronously. If wlan_receive_stats_response_handler() + * is registered through rsi_wlan_register_callbacks(), it's a non blocking API, otherwise, a blocking API. + * @param[in] channel - Valid channel number: 2.4GHz or 5GHz + * @return 0 - Success + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa,0x0021, 0x0025, 0x002c, 0x000A) \n + * @note **Precondition** - \ref rsi_wlan_radio_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_receive_stats_start(uint16_t channel) +{ + rsi_pkt_t *pkt; + rsi_req_rx_stats_t *rx_stats; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_RX_STATS_START_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_RX_STATS_START_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_RX_STATS_START_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Fill RX stats parameters + rx_stats = (rsi_req_rx_stats_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_rx_stats_t)); + + // Configure to start RX stats + rsi_uint16_to_2bytes(rx_stats->start, 0); + + // Copy the channel number + rsi_uint16_to_2bytes(rx_stats->channel, channel); + + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler == NULL) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + // Send command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_RX_STATS, pkt); + + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler == NULL) { + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_RX_STATS_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + } + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_RX_STATS_START_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_RX_STATS_START_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Stop the Transmit (TX) & Receive(RX) packets statistics. \n + * If wlan_receive_stats_response_handler() is registered through rsi_wlan_register_callbacks(), it's non blocking API, otherwise, a blocking API. + * @param[in] void + * @return 0 - Success + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa,0x0021, 0x0025, 0x002c) \n + * @note **Precondition** - \ref rsi_wlan_radio_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_wlan_receive_stats_stop(void) +{ + rsi_pkt_t *pkt; + rsi_req_rx_stats_t *rx_stats; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_RX_STATS_STOP_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_RX_STATS_STOP_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_RX_STATS_STOP_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Fill RX stats parameters + rx_stats = (rsi_req_rx_stats_t *)pkt->data; + + // Memset the PKT + memset(&pkt->data, 0, sizeof(rsi_req_rx_stats_t)); + + // Configure to stop RX stats + rsi_uint16_to_2bytes(rx_stats->start, 1); + + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler == NULL) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + // Send command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_RX_STATS, pkt); + + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler == NULL) { + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_RX_STATS_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + } + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_RX_STATS_STOP_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_RX_STATS_STOP_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*! \cond RS9116 */ +/*==============================================*/ +/** + * @brief Start discovery in Wi-Fi direct mode. \n + * If wlan_wfd_discovery_notify_handler() is registered through rsi_wlan_register_callbacks(), its non blocking API, otherwise blocking API. + * @param[in] go_intent - Determine whether the device is intended to form a GO (group owner) or work as a Wi-Fi Direct Peer node. \n + * Value used in the GO negotiation process, when the module negotiates with another Wi-Fi Direct Node on who would become the Group Owner. \n + * Valid range of values for this parameter is: 0 to 16. Higher the number, higher is the willingness of the module to become a GO. \n + * After the module becomes a GO in Wi-Fi Direct mode, it appears as an Access Point to the client devices. \n + * If the number is between 0 and 15, a GO negotiation takes place. If the value is 16, the module forms an Autonomous GO without negotiating with any other device. + * @param[in] device_name - Device name for the module. The maximum length of this field is 32 characters and the remaining bytes are filled with 0x00. \n + * Another Wi-Fi Direct device would see this name when it scans for Wi-Fi Direct nodes. \n + * @param[in] channel - Another Wi-Fi Direct device would see this name when it scans for Wi-Fi Direct nodes. \n + * @param[in] ssid_post_fix - Used to add a postfix to the SSID in Wi-Fi Direct GO mode and Autonomous GO mode. \n + * @param[in] psk - Passphrase of a maximum length of 63 characters (a null character should be supplied to make it 64 bytes in the structure). \n + * PSK used if the module becomes a GO owner. \n + * @param[in] wlan_wfd_discovery_notify_handler - Asynchronous message sent from module to the host when module finds any Wi-Fi Direct node. \n + * Parameters involved are status, buffer & length. + * Parameter | Description + * :--------------------:|:------------------------------------------: + * status | Response status + * buffer | Response buffer + * length | Response buffer length + * @param[in] wlan_wfd_connection_request_notify_handler - Asynchronous message sent from module to the host when module receives a connection request from any remote Wi-Fi Direct node. \n + * Parameters involved are status, buffer & length. + * Parameter | Description + * :--------------------:|:------------------------------------------: + * status | Response status + * buffer | Response buffer + * length | Response buffer length + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffd,0xfffffffa,0x001D, 0x0021, 0x002C, 0x0015) \n + * @pre **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_wfd_start_discovery( + uint16_t go_intent, + int8_t *device_name, + uint16_t channel, + int8_t *ssid_post_fix, + uint8_t *psk, + void (*wlan_wfd_discovery_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length), + void (*wlan_wfd_connection_request_notify_handler)(uint16_t status, uint8_t *buffer, const uint32_t length)) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_WFD_START_DISCOVERY_ENTRY, WLAN, LOG_INFO); + + rsi_req_configure_p2p_t *config_p2p; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Check whether Wi-Fi-Direct mode is selected + if (wlan_cb->opermode != RSI_WLAN_WIFI_DIRECT_MODE) { + SL_PRINTF(SL_WLAN_WFD_START_DISCOVERY_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + // WLAN radio init + status = rsi_wlan_radio_init(); + + if (status != RSI_SUCCESS) { + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_1, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_WFD_START_DISCOVERY_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + config_p2p = (rsi_req_configure_p2p_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_configure_p2p_t)); + + // Configure go intent + rsi_uint16_to_2bytes(config_p2p->go_intent, go_intent); + + if (device_name != NULL) { + // Copy device name + rsi_strcpy(config_p2p->device_name, device_name); + } + + // Configure operating channel + rsi_uint16_to_2bytes(config_p2p->operating_channel, channel); + + if (ssid_post_fix != NULL) { + // Copy SSID post fix + rsi_strcpy(config_p2p->ssid_post_fix, ssid_post_fix); + } + + if (psk != NULL) { + // Copy PSK + rsi_strcpy(config_p2p->psk, psk); + } + + if (wlan_wfd_discovery_notify_handler != NULL) { + rsi_wlan_cb_non_rom->callback_list.wlan_wfd_discovery_notify_handler = wlan_wfd_discovery_notify_handler; + } + + if (wlan_wfd_connection_request_notify_handler != NULL) { + rsi_wlan_cb_non_rom->callback_list.wlan_wfd_connection_request_notify_handler = + wlan_wfd_connection_request_notify_handler; + } + if ((wlan_wfd_discovery_notify_handler == NULL) && (wlan_wfd_connection_request_notify_handler == NULL)) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + // Send wi-fi direct discovery command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_CONFIGURE_P2P, pkt); + + if ((wlan_wfd_discovery_notify_handler == NULL) && (wlan_wfd_connection_request_notify_handler == NULL)) { + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_P2P_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_WFD_START_DISCOVERY_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_WFD_START_DISCOVERY_ERROR_IN_SENDING_COMMAND_2, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief A join_response_handler() API that connects to the specified Wi-Fi-Direct device.This is a non-blocking API. + * if join_response_handler() is registered through rsi_wlan_register_callbacks(), it's non blocking, otherwise, a blocking call. + * @pre \ref rsi_wlan_wfd_start_discovery() API needs to be called before this API. + * @param[in] device_name - Device name of the Wi-Fi Direct node to connect. \n + * @param[in] join_response_handler - Called when the response for join has come from the module \n + * @param[in] device_name - Device name of the Wi-Fi Direct node to connect. \n + * @param[in] join_response_handler - Called when the response for join has come from the module \n + * Parameters involved are status, buffer, & length. + * @param[out] status - Response status \n + * If status is zero, join response is stated as success + * @param[out] buffer - Response buffer. On successful execution of the command. \n + * GO_Status (1 byte, hex): 0x47 (ASCII "G") � If the module becomes a Group Owner (GO) after the GO negotiation stage, \n + * or becomes an Access Point. 0x43 (ASCII "C") � If the module does not become a GO after the GO negotiation stage, or becomes a client (or station). \n + * @param[out] length - Response buffer length + * @param[out] \n + * 'G' - GO \n + * 'C' - Client + * @note The module gets a default IP of 192.168.100.76 if it becomes a Group Owner or Access Point in case of IPv4. and gets a default IP of 2001:db8:0:1:0:0:0:120 in case of IPv6. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If return value is less than 0 \n + * -4 - Buffer not available to serve the command \n + * If return value is greater than 0 \n + * 0x0014, 0x0009, 0x0003, 0x0021, 0x0012c 0x0015 + * + */ + +int32_t rsi_wlan_wfd_connect(int8_t *device_name, + void (*join_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)) +{ + rsi_pkt_t *pkt; + rsi_req_join_t *join; + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_WFD_CONNECT_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_WFD_CONNECT_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_WFD_CONNECT_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_join_t)); + + join = (rsi_req_join_t *)pkt->data; + + if (device_name != NULL) { + // Copy SSID and SSID len + join->ssid_len = rsi_strlen(device_name); + + // Copy Join SSID + rsi_strcpy(join->ssid, device_name); + } + + if (join_response_handler != NULL) { + // Register scan response handler + rsi_wlan_cb_non_rom->callback_list.wlan_join_response_handler = join_response_handler; + } + + if (join_response_handler == NULL) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + } + // Send join command to start wps + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_JOIN, pkt); + + if (join_response_handler == NULL) { + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_JOIN_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_WFD_CONNECT_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_WFD_CONNECT_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*! \endcond */ +/*==============================================*/ +/** + * @brief Send the raw data in TCP/IP bypass mode. This is a blocking API. + * @param[in] buffer - Pointer to the buffer to send + * @param[in] length - Length of the buffer to send + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * If return value is less than 0 \n + * -2 - Invalid Parameters \n + * -4 - Buffer not available to serve the command \n + * If return value is greater than 0 \n + * 0x0021,0x002C,0x0025 + * + * + */ + +int32_t rsi_wlan_send_data(uint8_t *buffer, uint32_t length) +{ + int32_t status = RSI_SUCCESS; + uint8_t *host_desc; + rsi_pkt_t *pkt; + SL_PRINTF(SL_WLAN_SEND_DATA_ENTRY, WLAN, LOG_INFO); + // Get wlan cb structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // If buffer is not valid + if ((buffer == NULL) || (length == 0)) { + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SEND_DATA_INVALID_PARAM, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate packet to send data + pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool); + + if (pkt == NULL) { + SL_PRINTF(SL_WLAN_SEND_DATA_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + //Changing the wlan cmd state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Get host descriptor pointer + host_desc = pkt->desc; + + // Memset host descriptor + memset(host_desc, 0, RSI_HOST_DESC_LENGTH); + + // Fill host descriptor + rsi_uint16_to_2bytes(host_desc, (length & 0xFFF)); + + // Fill packet type + host_desc[1] |= (RSI_WLAN_DATA_Q << 4); + host_desc[2] |= 0x01; + + // Copy data to be sent + memcpy(pkt->data, buffer, length); + + // Enqueue packet to WLAN TX queue + rsi_enqueue_pkt(&rsi_driver_cb->wlan_tx_q, pkt); + +#ifndef RSI_SEND_SEM_BITMAP + rsi_driver_cb_non_rom->send_wait_bitmap |= BIT(0); +#endif + // Set TX packet pending event + rsi_set_event(RSI_TX_EVENT); + + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->send_data_sem, RSI_SEND_DATA_RESPONSE_WAIT_TIME); + + status = rsi_wlan_get_status(); + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + // Return status + SL_PRINTF(SL_WLAN_SEND_DATA_EXIT, WLAN, LOG_INFO, "status: %4x", status); + + return status; +} +/// @cond DOCS_9117 +/** + * @fn int32_t rsi_wlan_twt_config(uint8_t twt_enable, uint8_t twt_flow_id, twt_user_params_t *twt_req_params) + * @brief Configures TWT parameters. Enables or disables a TWT session. This is blocking API. + * @pre needs to be called after @ref rsi_wireless_init() OPERMODE command. + * @param[in] twt_enable - TWT session setup or teardown \n 1 - To setup TWT session with given parameters \n + * 0 - To teardown TWT session with given flow ID. + * @param[in] twt_flow_id - TWT session flow ID. \n 0 - 7 are valid flow IDs. \n 0xFF value is used to teardown all active sessions. + * @param[in] twt_req_params Configurable TWT parameters. Refer \ref twt_user_params_s. + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * @note Refer Error Codes section for above \ref error-codes . + */ +int32_t rsi_wlan_twt_config(uint8_t twt_enable, uint8_t twt_flow_id, twt_user_params_t *twt_req_params) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + rsi_twt_req_t *twt_req = NULL; + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + if (twt_enable == 0) { + if ((twt_flow_id != 0xFF) && (twt_flow_id > 7)) { + return RSI_ERROR_INVALID_PARAM; + } + } else if (twt_enable == 1) { + if (twt_flow_id > 7) { + return RSI_ERROR_INVALID_PARAM; + } + if (twt_req_params->wake_int_exp > 31) { + return RSI_ERROR_INVALID_PARAM; + } + if (twt_req_params->wake_int_exp_tol > 31) { + return RSI_ERROR_INVALID_PARAM; + } + if (twt_req_params->wake_duration_unit > 1) { + return RSI_ERROR_INVALID_PARAM; + } + if ((twt_req_params->un_announced_twt > 1) || (twt_req_params->triggered_twt > 1) + || (twt_req_params->restrict_tx_outside_tsp > 1)) { + return RSI_ERROR_INVALID_PARAM; + } + if (twt_req_params->twt_retry_limit > 15) { + return RSI_ERROR_INVALID_PARAM; + } + if (twt_req_params->twt_retry_interval < 5) { + return RSI_ERROR_INVALID_PARAM; + } + if (twt_req_params->req_type > 2) { + return RSI_ERROR_INVALID_PARAM; + } + if ((twt_req_params->req_type != 0) + && ((twt_req_params->wake_duration == 0) || (twt_req_params->wake_int_mantissa == 0) + || (((uint64_t)twt_req_params->wake_duration * (uint64_t)(twt_req_params->wake_duration_unit ? 1024 : 256)) + > ((uint64_t)twt_req_params->wake_int_mantissa * ((uint64_t)1 << twt_req_params->wake_int_exp))))) { + return RSI_ERROR_INVALID_PARAM; + } + if ((twt_req_params->twt_channel != 0) || (twt_req_params->twt_protection != 0) + || (twt_req_params->implicit_twt != 1)) { + return RSI_ERROR_INVALID_PARAM; + } + } else { + return RSI_ERROR_INVALID_PARAM; + } + + rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_twt_req_t)); + + twt_req = (rsi_twt_req_t *)pkt->data; + + /* copying input params into structure*/ + twt_req->twt_enable = twt_enable; + twt_req->twt_flow_id = twt_flow_id; + if (twt_enable) { + twt_req->wake_duration = twt_req_params->wake_duration; + twt_req->wake_duration_tol = twt_req_params->wake_duration_tol; + twt_req->wake_int_exp = twt_req_params->wake_int_exp; + twt_req->wake_int_exp_tol = twt_req_params->wake_int_exp_tol; + twt_req->wake_duration_unit = twt_req_params->wake_duration_unit; + rsi_uint16_to_2bytes(twt_req->wake_int_mantissa, twt_req_params->wake_int_mantissa); + rsi_uint16_to_2bytes(twt_req->wake_int_mantissa_tol, twt_req_params->wake_int_mantissa_tol); + twt_req->implicit_twt = twt_req_params->implicit_twt; + twt_req->un_announced_twt = twt_req_params->un_announced_twt; + twt_req->triggered_twt = twt_req_params->triggered_twt; + twt_req->negotiation_type = 0; //Only Individual TWT is supported for now. Not taking input from user. + twt_req->twt_channel = twt_req_params->twt_channel; + twt_req->twt_protection = twt_req_params->twt_protection; + twt_req->restrict_tx_outside_tsp = twt_req_params->restrict_tx_outside_tsp; + twt_req->twt_retry_limit = twt_req_params->twt_retry_limit; + twt_req->twt_retry_interval = twt_req_params->twt_retry_interval; + twt_req->req_type = twt_req_params->req_type; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send twt command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_TWT_PARAMS, pkt); + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WLAN_TWT_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + } + // Return status if error in sending command occurs + return status; +} +/// @endcond +/*==============================================*/ +/** + * @brief Send a ping request to the target IP address. \n + * If wlan_ping_response_handler() is registered through rsi_wlan_register_callbacks(), it's non blocking API, otherwise, a blocking API. + * @param[in] flags - BIT(0): RSI_IPV6 Set this bit to enable IPv6; by default, it is configured to IPv4 + * @param[in] ip_address - Target IP address. \n + * IPv4 address: 4 Bytes hexa-decimal, \n + * IPv6 address: 16 Bytes hexa-decimal + * @param[in] size - Ping data size to send. Maximum supported is 300 bytes. + * @param[in] wlan_ping_response_handler - Called when ping response has been received from the module. \n + * Parameters involved are status, buffer, & length. + * @param[out] status - Response status + * @param[out] buffer - Response buffer + * @param[out] length - Length of the response buffer + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffa,0x0015,0xBB21,0xBB4B,0xBB55) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API needs to be called before this API. + * @note The module can't receive ping packets whose length is more than 308 bytes. + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ + +int32_t rsi_wlan_ping_async(uint8_t flags, + uint8_t *ip_address, + uint16_t size, + void (*wlan_ping_response_handler)(uint16_t status, + const uint8_t *buffer, + const uint16_t length)) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt; + rsi_req_ping_t *ping; + SL_PRINTF(SL_WLAN_PING_ASYNC_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + if (wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_PING_ASYNC_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // If IP address is not valid + if ((ip_address == NULL) || (size == 0)) { + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_PING_ASYNC_INVALID_PARAM, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(NWK_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_PING_ASYNC_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_ping_t)); + + ping = (rsi_req_ping_t *)pkt->data; + + if (flags & RSI_IPV6) { + // Copy IP version + rsi_uint16_to_2bytes(ping->ip_version, (uint16_t)RSI_IP_VERSION_6); + + // Copy IPv6 address + memcpy(ping->ping_address.ipv6_address, ip_address, RSI_IPV6_ADDRESS_LENGTH); + } else { + // Copy IP version + rsi_uint16_to_2bytes(ping->ip_version, (uint16_t)RSI_IP_VERSION_4); + + // Copy IPv4 address + memcpy(ping->ping_address.ipv4_address, ip_address, RSI_IPV4_ADDRESS_LENGTH); + } + + // Copy ping size + rsi_uint16_to_2bytes(ping->ping_size, size); + + ping->timeout = RSI_PING_REQ_TIMEOUT; + + // Register ping response handler + if (wlan_ping_response_handler != NULL) { + rsi_wlan_cb_non_rom->callback_list.wlan_ping_response_handler = wlan_ping_response_handler; + rsi_wlan_cb_non_rom->nwk_cmd_rsp_pending |= PING_RESPONSE_PENDING; + } + + if (wlan_ping_response_handler == NULL) { +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->nwk_wait_bitmap |= BIT(0); +#endif + } + // Send ping command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_PING_PACKET, pkt); + + if (wlan_ping_response_handler == NULL) { + // Wait on WLAN semaphore + rsi_wait_on_nwk_semaphore(&rsi_driver_cb_non_rom->nwk_sem, RSI_PING_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_nwk_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(NWK_CMD, ALLOW); + } + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_PING_ASYNC_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_PING_ASYNC_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Register auto-configuration response handler.. This is a non-blocking API. + * @param[in] rsi_auto_config_rsp_handler - Pointer to rsi_auto_config_rsp_handler + * @param[out] status - Response status, 0 if success else failure. + * @param[out] state - BIT(1) RSI_AUTO_CONFIG_FAILED. \n + * BIT(2) RSI_AUTO_CONFIG_GOING_ON. \n + * BIT(3) RSI_AUTO_CONFIG_DONE + * @return Void + */ + +void rsi_register_auto_config_rsp_handler(void (*rsi_auto_config_rsp_handler)(uint16_t status, uint8_t state)) +{ + + // Register callback handler + SL_PRINTF(SL_WLAN_REGISTER_AUTO_CONFIG_RSP_HANDLER_EXIT, WLAN, LOG_INFO); + rsi_wlan_cb_non_rom->callback_list.auto_config_rsp_handler = rsi_auto_config_rsp_handler; +} + +/*==============================================*/ +/** + * @brief Add profile for auto configuration. This is a blocking API. + * @param[in] type - profile type. Supported profile types are: \n + * 1.RSI_WLAN_PROFILE_AP, \n + * 2.RSI_WLAN_PROFILE_CLIENT, \n + * 3.RSI_WLAN_PROFILE_EAP, \n + * 4.RSI_WLAN_PROFILE_P2P, \n + * 5.RSI_WLAN_PROFILE_ALL + * @param[in] profile - Pointer to config profile and profile structure \n + * ap_profile, \n + * eap_client_profile_t, \n + * client_profile_t, \n + * p2p_profile_t, \n + * rsi_config_profile_t + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa) \n + * @note **This API is not supported in current release.** + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_add_profile(uint32_t type, uint8_t *profile) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt; + uint16_t send_size = 0; + uint8_t *host_desc = NULL; + rsi_config_profile_t *config_profile; + SL_PRINTF(SL_WLAN_ADD_PROFILE_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_ADD_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_ADD_PROFILE_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_config_profile_t)); + + config_profile = (rsi_config_profile_t *)pkt->data; + + // Fill profile type + rsi_uint32_to_4bytes(config_profile->profile_type, type); + + // Fill WLAN profile + if (type == RSI_WLAN_PROFILE_AP) { + memcpy(&config_profile->wlan_profile_struct.ap_profile, (uint8_t *)profile, sizeof(ap_profile_t)); + } else if (type == RSI_WLAN_PROFILE_CLIENT) { + memcpy(&config_profile->wlan_profile_struct.client_profile, (uint8_t *)profile, sizeof(client_profile_t)); + } else if (type == RSI_WLAN_PROFILE_EAP) { + memcpy(&config_profile->wlan_profile_struct.eap_client_profile, (uint8_t *)profile, sizeof(eap_client_profile_t)); + } else if (type == RSI_WLAN_PROFILE_P2P) { + memcpy(&config_profile->wlan_profile_struct.p2p_profile, (uint8_t *)profile, sizeof(p2p_profile_t)); + } else { + // No code here + } + + // Using host descriptor to set payload length + send_size = sizeof(rsi_config_profile_t); + + // Get the host descriptor + host_desc = (pkt->desc); + + // Fill data length in the packet host descriptor + rsi_uint16_to_2bytes(host_desc, (send_size & 0xFFF)); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set profile command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_PROFILE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_SET_PROFILE_RESPONSE_WAIT_TIME); + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_ADD_PROFILE_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_ADD_PROFILE_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Get the current WLAN state.. This is a non-blocking API. + * @param[in] Void + * @return Current WLAN state. \n + WLAN states are as follows: \n + * @return RSI_WLAN_STATE_NONE = 0, \n + * @return RSI_WLAN_STATE_OPERMODE_DONE, \n + * @return RSI_WLAN_STATE_BAND_DONE, \n + * @return RSI_WLAN_STATE_INIT_DONE, \n + * @return RSI_WLAN_STATE_SCAN_DONE, \n + * @return RSI_WLAN_STATE_CONNECTED, \n + * @return RSI_WLAN_STATE_IP_CONFIG_DONE, \n + * @return RSI_WLAN_STATE_IPV6_CONFIG_DONE, \n + * @return RSI_WLAN_STATE_AUTO_CONFIG_GOING_ON, \n + * @return RSI_WLAN_STATE_AUTO_CONFIG_DONE, \n + * @return RSI_WLAN_STATE_AUTO_CONFIG_FAILED + * + */ + +uint8_t rsi_wlan_get_state(void) +{ + // Return WLAN state + SL_PRINTF(SL_WLAN_GET_STATE_EXIT, WLAN, LOG_INFO); + return rsi_driver_cb->wlan_cb->state; +} + +/*==============================================*/ +/** + * @brief Get the stored config profile. This is a blocking API. + * @param[in] type - Config profile type. \n + * Supported profile types are as follows: \n + * RSI_WLAN_PROFILE_AP, \n + * RSI_WLAN_PROFILE_CLIENT, \n + * RSI_WLAN_PROFILE_EAP, \n + * RSI_WLAN_PROFILE_P2P, \n + * RSI_WLAN_PROFILE_ALL + * @param[in] profile_rsp - Config profile response in the form of below structure: \n + * ap_profile, \n + * eap_client_profile_t, \n + * client_profile_t, \n + * p2p_profile_t, \n + * rsi_config_profile_t + * @param[in] length - Length of the config profile response + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa) \n + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + * @note **This API is not supported in current release.** + * @note Refer to \ref error-codes for the description of above error codes. + */ + +int32_t rsi_wlan_get_profile(uint32_t type, rsi_config_profile_t *profile_rsp, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + rsi_profile_req_t *profile_req = NULL; + SL_PRINTF(SL_WLAN_GET_PROFILE_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_GET_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_GET_PROFILE_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_profile_req_t)); + + profile_req = (rsi_profile_req_t *)pkt->data; + + // Fill profile type + rsi_uint32_to_4bytes(profile_req->profile_type, type); + + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)profile_rsp; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send get profile command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_GET_PROFILE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_GET_PROFILE_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_GET_PROFILE_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_GET_PROFILE_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Fill the config profile based on the profile type.. This is a non-blocking API. + * @param[in] Type - Profile type + * @param[in] Profile_buffer - Pointer to profile buffer + * @return Profile buffer + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + */ +/// @private + +uint8_t *rsi_fill_config_profile(uint32_t type, uint8_t *profile_buffer) +{ + SL_PRINTF(SL_WLAN_FILL_CONFIG_PROFILE_ENTRY, WLAN, LOG_INFO); + int i, j = 0; + uint32_t ip_addr = 0; + uint32_t mask = 0; + uint32_t gw = 0; + eap_client_profile_t *eap_client_profile_ptr = NULL; + network_profile_t *nwk_profile_ptr = NULL; + feature_frame_params_t *feature_frame_ptr = NULL; + client_profile_t *client_profile_ptr = NULL; + ap_profile_t *ap_profile_ptr = NULL; + p2p_profile_t *p2p_profile_ptr = NULL; + + if (type == RSI_WLAN_PROFILE_AP) { + ip_addr = RSI_CONFIG_AP_IP_ADDRESS; + mask = RSI_CONFIG_AP_SN_MASK_ADDRESS; + gw = RSI_CONFIG_AP_GATEWAY_ADDRESS; + + ap_profile_ptr = (ap_profile_t *)profile_buffer; + + nwk_profile_ptr = &ap_profile_ptr->network_profile; + + feature_frame_ptr = &ap_profile_ptr->feature_frame_params_s; + + memset(ap_profile_ptr, 0, sizeof(ap_profile_t)); + + // Fill AP WLAN feature bitmap + rsi_uint32_to_4bytes(ap_profile_ptr->wlan_feature_bit_map, RSI_CONFIG_AP_WLAN_FEAT_BIT_MAP); + + // Fill AP TCP_IP feature bitmap + rsi_uint32_to_4bytes(ap_profile_ptr->tcp_ip_feature_bit_map, RSI_CONFIG_AP_TCP_IP_FEAT_BIT_MAP); + + // Fill AP custom feature bitmap + rsi_uint32_to_4bytes(ap_profile_ptr->custom_feature_bit_map, RSI_CONFIG_AP_CUSTOM_FEAT_BIT_MAP); + + // Fill data rate + ap_profile_ptr->data_rate = RSI_CONFIG_AP_DATA_RATE; + + // Fill TX power + ap_profile_ptr->tx_power = RSI_CONFIG_AP_TX_POWER; + + // Fill AP band + ap_profile_ptr->band = RSI_CONFIG_AP_BAND; + + // Fill AP channel number + rsi_uint16_to_2bytes(ap_profile_ptr->channel, RSI_CONFIG_AP_CHANNEL); + + // Fill AP SSID + rsi_strcpy(ap_profile_ptr->ssid, RSI_CONFIG_AP_SSID); + + // Fill AP security type + ap_profile_ptr->security_type = RSI_CONFIG_AP_SECURITY_TYPE; + + // Fill AP encryption type + ap_profile_ptr->encryption_type = RSI_CONFIG_AP_ENCRYPTION_TYPE; + + // Fill AP PSK + if (RSI_CONFIG_AP_PSK) + rsi_strcpy(ap_profile_ptr->psk, RSI_CONFIG_AP_PSK); + + // Fill beacon interval + rsi_uint16_to_2bytes(ap_profile_ptr->beacon_interval, RSI_CONFIG_AP_BEACON_INTERVAL); + + // Fill DTIM period + rsi_uint16_to_2bytes(ap_profile_ptr->dtim_period, RSI_CONFIG_AP_DTIM); + + // Fill AP keep alive time + ap_profile_ptr->keep_alive_type = RSI_CONFIG_AP_KEEP_ALIVE_TYPE; + + // Fill AP keep alive counter + ap_profile_ptr->keep_alive_counter = RSI_CONFIG_AP_KEEP_ALIVE_COUNTER; + + // Fill AP max number of stations + rsi_uint16_to_2bytes(ap_profile_ptr->max_no_sta, RSI_CONFIG_AP_MAX_STATIONS_COUNT); + + nwk_profile_ptr->tcp_stack_used = RSI_CONFIG_AP_TCP_STACK_USED; + + if (nwk_profile_ptr->tcp_stack_used == 1) { + nwk_profile_ptr->dhcp_enable = 0; + + // Fill IP address + memcpy(nwk_profile_ptr->ip_address, (uint8_t *)&ip_addr, RSI_IPV4_ADDRESS_LENGTH); + + // Fill network mask + memcpy(nwk_profile_ptr->sn_mask, (uint8_t *)&mask, RSI_IPV4_ADDRESS_LENGTH); + + // Fill gateway + memcpy(nwk_profile_ptr->default_gw, (uint8_t *)&gw, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Not supported + } + // Fill feature frame params + feature_frame_ptr->pll_mode = PLL_MODE; + feature_frame_ptr->rf_type = RF_TYPE; + feature_frame_ptr->wireless_mode = WIRELESS_MODE; + feature_frame_ptr->enable_ppp = ENABLE_PPP; + feature_frame_ptr->afe_type = AFE_TYPE; + rsi_uint32_to_4bytes(feature_frame_ptr->feature_enables, FEATURE_ENABLES); + + } else if (type == RSI_WLAN_PROFILE_CLIENT) { + ip_addr = RSI_CONFIG_CLIENT_IP_ADDRESS; + mask = RSI_CONFIG_CLIENT_SN_MASK_ADDRESS; + gw = RSI_CONFIG_CLIENT_GATEWAY_ADDRESS; + + client_profile_ptr = (client_profile_t *)profile_buffer; + + nwk_profile_ptr = &client_profile_ptr->network_profile; + + feature_frame_ptr = &client_profile_ptr->feature_frame_params_s; + + memset(client_profile_ptr, 0, sizeof(client_profile_t)); + + // Fill WLAN feature bitmap + rsi_uint32_to_4bytes(client_profile_ptr->wlan_feature_bit_map, RSI_CONFIG_CLIENT_WLAN_FEAT_BIT_MAP); + + // Fill TCP_IP feature bitmap + rsi_uint32_to_4bytes(client_profile_ptr->tcp_ip_feature_bit_map, RSI_CONFIG_CLIENT_TCP_IP_FEAT_BIT_MAP); + + // Fill custom feature bitmap + rsi_uint32_to_4bytes(client_profile_ptr->custom_feature_bit_map, RSI_CONFIG_CLIENT_CUSTOM_FEAT_BIT_MAP); + + // Fill listen interval + rsi_uint32_to_4bytes(client_profile_ptr->listen_interval, RSI_CONFIG_CLIENT_LISTEN_INTERVAL); + + // Fill data rate + client_profile_ptr->data_rate = RSI_CONFIG_CLIENT_DATA_RATE; + + // Fill TX power + client_profile_ptr->tx_power = RSI_CONFIG_CLIENT_TX_POWER; + + // Fill AP band + client_profile_ptr->band = RSI_CONFIG_CLIENT_BAND; + + // Fill Client SSID + rsi_strcpy(client_profile_ptr->ssid, RSI_CONFIG_CLIENT_SSID); + + // Fill AP SSID length + client_profile_ptr->ssid_len = strlen(RSI_CONFIG_CLIENT_SSID); + + // Fill scan feature bitmap + client_profile_ptr->scan_feature_bitmap = RSI_CONFIG_CLIENT_SCAN_FEAT_BITMAP; + + // Fill client channel number + rsi_uint16_to_2bytes(client_profile_ptr->channel, RSI_CONFIG_CLIENT_CHANNEL); + + // Scan channel bitmap magic code + rsi_uint16_to_2bytes(client_profile_ptr->scan_chan_bitmap_magic_code, RSI_CONFIG_CLIENT_MAGIC_CODE); + + // Scan channel bitmap for 2_4 Ghz + rsi_uint32_to_4bytes(client_profile_ptr->scan_chan_bitmap_2_4_ghz, RSI_CONFIG_CLIENT_SCAN_CHAN_BITMAP_2_4_GHZ); + + // Scan channel bitmap for 5_0 Ghz + rsi_uint32_to_4bytes(client_profile_ptr->scan_chan_bitmap_5_0_ghz, RSI_CONFIG_CLIENT_SCAN_CHAN_BITMAP_5_0_GHZ); + + // Fill client security type + client_profile_ptr->security_type = RSI_CONFIG_CLIENT_SECURITY_TYPE; + + // Fill AP encryption type + client_profile_ptr->encryption_type = RSI_CONFIG_CLIENT_ENCRYPTION_TYPE; + + // Fill client PSK + if (RSI_CONFIG_CLIENT_PSK) + rsi_strcpy(client_profile_ptr->psk, RSI_CONFIG_CLIENT_PSK); + + // Fill client PMK + if (strlen(RSI_CONFIG_CLIENT_PMK)) { + for (i = 0, j = 0; i < 64 && j < 32; i += 2, j++) { + if (RSI_CONFIG_CLIENT_PMK[i] && RSI_CONFIG_CLIENT_PMK[i + 1]) { + client_profile_ptr->pmk[j] = ((uint16_t)convert_lower_case_to_upper_case(RSI_CONFIG_CLIENT_PMK[i])) * 16; + client_profile_ptr->pmk[j] += convert_lower_case_to_upper_case(RSI_CONFIG_CLIENT_PMK[i + 1]); + } else { + client_profile_ptr->pmk[j] = 0; + } + } + } + + nwk_profile_ptr->tcp_stack_used = RSI_CONFIG_CLIENT_TCP_STACK_USED; + + if (nwk_profile_ptr->tcp_stack_used == 1) { + nwk_profile_ptr->dhcp_enable = RSI_CONFIG_CLIENT_DHCP_MODE; + + // Fill IP address + memcpy(nwk_profile_ptr->ip_address, (uint8_t *)&ip_addr, RSI_IPV4_ADDRESS_LENGTH); + + // Fill network mask + memcpy(nwk_profile_ptr->sn_mask, (uint8_t *)&mask, RSI_IPV4_ADDRESS_LENGTH); + + // Fill gateway + memcpy(nwk_profile_ptr->default_gw, (uint8_t *)&gw, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Not supported + } + + // Fill feature frame params + feature_frame_ptr->pll_mode = PLL_MODE; + feature_frame_ptr->rf_type = RF_TYPE; + feature_frame_ptr->wireless_mode = WIRELESS_MODE; + feature_frame_ptr->enable_ppp = ENABLE_PPP; + feature_frame_ptr->afe_type = AFE_TYPE; + rsi_uint32_to_4bytes(feature_frame_ptr->feature_enables, FEATURE_ENABLES); + + } else if (type == RSI_WLAN_PROFILE_EAP) { + ip_addr = RSI_CONFIG_EAP_IP_ADDRESS; + mask = RSI_CONFIG_EAP_SN_MASK_ADDRESS; + gw = RSI_CONFIG_EAP_GATEWAY_ADDRESS; + + eap_client_profile_ptr = (eap_client_profile_t *)profile_buffer; + + nwk_profile_ptr = &eap_client_profile_ptr->network_profile; + + feature_frame_ptr = &eap_client_profile_ptr->feature_frame_params_s; + + memset(eap_client_profile_ptr, 0, sizeof(eap_client_profile_t)); + + // Fill WLAN feature bitmap + rsi_uint32_to_4bytes(eap_client_profile_ptr->wlan_feature_bit_map, RSI_CONFIG_EAP_WLAN_FEAT_BIT_MAP); + + // Fill TCP_IP feature bitmap + rsi_uint32_to_4bytes(eap_client_profile_ptr->tcp_ip_feature_bit_map, RSI_CONFIG_EAP_TCP_IP_FEAT_BIT_MAP); + + // Fill custom feature bitmap + rsi_uint32_to_4bytes(eap_client_profile_ptr->custom_feature_bit_map, RSI_CONFIG_EAP_CUSTOM_FEAT_BIT_MAP); + + // Fill data rate + eap_client_profile_ptr->data_rate = RSI_CONFIG_EAP_DATA_RATE; + + // Fill TX power + eap_client_profile_ptr->tx_power = RSI_CONFIG_EAP_TX_POWER; + + // Fill band + eap_client_profile_ptr->band = RSI_CONFIG_EAP_BAND; + + // Fill Client SSID + rsi_strcpy(eap_client_profile_ptr->ssid, RSI_CONFIG_EAP_SSID); + + // Fill AP SSID length + eap_client_profile_ptr->ssid_len = strlen(RSI_CONFIG_EAP_SSID); + + // Fill scan feature bitmap + eap_client_profile_ptr->scan_feature_bitmap = RSI_CONFIG_EAP_SCAN_FEAT_BITMAP; + + // Fill security type + eap_client_profile_ptr->security_type = RSI_CONFIG_EAP_SECURITY_TYPE; + + // Fill client channel number + rsi_uint16_to_2bytes(eap_client_profile_ptr->channel, RSI_CONFIG_EAP_CHANNEL); + + // Scan channel bitmap magic code + rsi_uint16_to_2bytes(eap_client_profile_ptr->scan_chan_bitmap_magic_code, RSI_CONFIG_EAP_CHAN_MAGIC_CODE); + + // Scan channel bitmap for 2_4 Ghz + rsi_uint32_to_4bytes(eap_client_profile_ptr->scan_chan_bitmap_2_4_ghz, RSI_CONFIG_EAP_SCAN_CHAN_BITMAP_2_4_GHZ); + + // Scan channel bitmap for 5_0 Ghz + rsi_uint32_to_4bytes(eap_client_profile_ptr->scan_chan_bitmap_5_0_ghz, RSI_CONFIG_EAP_SCAN_CHAN_BITMAP_5_0_GHZ); + + // Fill EAP method + rsi_strcpy(eap_client_profile_ptr->eap_method, RSI_CONFIG_EAP_METHOD); + + // Fill inner method + rsi_strcpy(eap_client_profile_ptr->inner_method, RSI_CONFIG_EAP_INNER_METHOD); + + // Fill user identity + rsi_strcpy(eap_client_profile_ptr->user_identity, RSI_CONFIG_EAP_USER_IDENTITY); + + // Fill password + rsi_strcpy(eap_client_profile_ptr->passwd, RSI_CONFIG_EAP_PASSWORD); + + nwk_profile_ptr->tcp_stack_used = RSI_CONFIG_EAP_TCP_STACK_USED; + + if (nwk_profile_ptr->tcp_stack_used == 1) { + nwk_profile_ptr->dhcp_enable = RSI_CONFIG_EAP_DHCP_MODE; + + // Fill IP address + memcpy(nwk_profile_ptr->ip_address, (uint8_t *)&ip_addr, RSI_IPV4_ADDRESS_LENGTH); + + // Fill network mask + memcpy(nwk_profile_ptr->sn_mask, (uint8_t *)&mask, RSI_IPV4_ADDRESS_LENGTH); + + // Fill gateway + memcpy(nwk_profile_ptr->default_gw, (uint8_t *)&gw, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Not supported + } + + // Fill feature frame params + feature_frame_ptr->pll_mode = PLL_MODE; + feature_frame_ptr->rf_type = RF_TYPE; + feature_frame_ptr->wireless_mode = WIRELESS_MODE; + feature_frame_ptr->enable_ppp = ENABLE_PPP; + feature_frame_ptr->afe_type = AFE_TYPE; + rsi_uint32_to_4bytes(feature_frame_ptr->feature_enables, FEATURE_ENABLES); + + } else if (type == RSI_WLAN_PROFILE_P2P) { + ip_addr = RSI_CONFIG_P2P_IP_ADDRESS; + mask = RSI_CONFIG_P2P_SN_MASK_ADDRESS; + gw = RSI_CONFIG_P2P_GATEWAY_ADDRESS; + + p2p_profile_ptr = (p2p_profile_t *)profile_buffer; + + nwk_profile_ptr = &p2p_profile_ptr->network_profile; + + // feature_frame_params_t *feature_frame_ptr = NULL; + + feature_frame_ptr = &p2p_profile_ptr->feature_frame_params_s; + + memset(p2p_profile_ptr, 0, sizeof(p2p_profile_t)); + + // Fill WLAN feature bitmap + rsi_uint32_to_4bytes(p2p_profile_ptr->wlan_feature_bit_map, RSI_CONFIG_P2P_WLAN_FEAT_BIT_MAP); + + // Fill TCP_IP feature bitmap + rsi_uint32_to_4bytes(p2p_profile_ptr->tcp_ip_feature_bit_map, RSI_CONFIG_P2P_TCP_IP_FEAT_BIT_MAP); + + // Fill custom feature bitmap + rsi_uint32_to_4bytes(p2p_profile_ptr->custom_feature_bit_map, RSI_CONFIG_P2P_CUSTOM_FEAT_BIT_MAP); + + // Fill Join SSID + rsi_strcpy(p2p_profile_ptr->join_ssid, RSI_CONFIG_P2P_JOIN_SSID); + + // Fill data rate + p2p_profile_ptr->data_rate = RSI_CONFIG_CLIENT_DATA_RATE; + + // Fill TX power + p2p_profile_ptr->tx_power = RSI_CONFIG_CLIENT_TX_POWER; + + // Fill AP band + p2p_profile_ptr->band = RSI_CONFIG_CLIENT_BAND; + + // Fill GO intent + rsi_uint16_to_2bytes(p2p_profile_ptr->go_intent, RSI_CONFIG_P2P_GO_INTNET); + + // Fill device name + rsi_strcpy(p2p_profile_ptr->device_name, RSI_CONFIG_P2P_DEVICE_NAME); + + // Fill operating channel + rsi_uint16_to_2bytes(p2p_profile_ptr->operating_channel, RSI_CONFIG_P2P_OPERATING_CHANNEL); + + // Fill SSID postfix + rsi_strcpy(p2p_profile_ptr->ssid_postfix, RSI_CONFIG_P2P_SSID_POSTFIX); + + // Fill PSK key + rsi_strcpy(p2p_profile_ptr->psk_key, RSI_CONFIG_P2P_PSK_KEY); + + nwk_profile_ptr->tcp_stack_used = RSI_CONFIG_P2P_TCP_STACK_USED; + + if (nwk_profile_ptr->tcp_stack_used == 1) { + nwk_profile_ptr->dhcp_enable = RSI_CONFIG_P2P_DHCP_MODE; + + // Fill IP address + memcpy(nwk_profile_ptr->ip_address, (uint8_t *)&ip_addr, RSI_IPV4_ADDRESS_LENGTH); + + // Fill network mask + memcpy(nwk_profile_ptr->sn_mask, (uint8_t *)&mask, RSI_IPV4_ADDRESS_LENGTH); + + // Fill gateway + memcpy(nwk_profile_ptr->default_gw, (uint8_t *)&gw, RSI_IPV4_ADDRESS_LENGTH); + } else { + // Not supported + } + + // Fill feature frame params + feature_frame_ptr->pll_mode = PLL_MODE; + feature_frame_ptr->rf_type = RF_TYPE; + feature_frame_ptr->wireless_mode = WIRELESS_MODE; + feature_frame_ptr->enable_ppp = ENABLE_PPP; + feature_frame_ptr->afe_type = AFE_TYPE; + rsi_uint32_to_4bytes(feature_frame_ptr->feature_enables, FEATURE_ENABLES); + + } else { + profile_buffer = NULL; + } + SL_PRINTF(SL_WLAN_FILL_CONFIG_PROFILE_EXIT, WLAN, LOG_INFO); + return profile_buffer; +} + +/*==============================================*/ +/** + * @brief Delete stored configuration based on profile type. This is a blocking API. + * @param[in] type - Profile type + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa) \n + * @note **This API is not supported in current release.** + * @note **Precondition** - \ref rsi_wireless_init() API needs to be called before this API. + */ + +int32_t rsi_wlan_delete_profile(uint32_t type) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + rsi_profile_req_t *profile_req = NULL; + SL_PRINTF(SL_WLAN_DELETE_PROFILE_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_DELETE_PROFILE_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_DELETE_PROFILE_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_profile_req_t)); + + profile_req = (rsi_profile_req_t *)pkt->data; + + // Fill profile type + rsi_uint32_to_4bytes(profile_req->profile_type, type); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send delete profile command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_DELETE_PROFILE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_DELETE_PROFILE_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_DELETE_PROFILE_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_DELETE_PROFILE_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Enable or disable auto-config with respect to profile. This is a blocking API. + * @param[in] enable - 0 - Disable the auto configuration feature. \n + * 1 - Enable the auto configuration feature on power up. \n + * 2 - Enable the auto configuration for profile based. + * @param[in] type - Profile type \n + * Value | Parameter | Macro + * :-------:|:------------------:|:------------------------------------------------------ + * 0 | Client profile | RSI_WLAN_PROFILE_CLIENT + * 1 | P2P profile | RSI_WLAN_PROFILE_P2P + * 2 | EAP profile | RSI_WLAN_PROFILE_EAP + * 6 | AP profile | RSI_WLAN_PROFILE_AP + * 0xF | All profiles | RSI_WLAN_PROFILE_ALL + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa) \n + * @note **Precondition** - \ref rsi_wlan_set() API needs to be called before this API. + * @note Currently Profile based feature is not supported. + * @note If user tries to give any other command during autojoin, then user gets error 0x002C. \n + * To avoid this, user have to disable auto_join feature and give other commands. + * @note The parameters of the following APIs are saved when rsi_wlan_enable_auto_config() is called: \n + * rsi_wireless_init(), rsi_wlan_scan(), rsi_wlan_scan_with_bitmap_options(), rsi_wlan_connect(), \n + * rsi_config_ipaddress(), rsi_wireless_antenna(), rsi_wlan_bgscan_profile(), rsi_radio_caps(), rsi_wlan_ap_start + * @note Refer to \ref error-codes for the description of above error codes. + * + * + */ + +int32_t rsi_wlan_enable_auto_config(uint8_t enable, uint32_t type) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + rsi_auto_config_enable_t *config_enable_req = NULL; + SL_PRINTF(SL_WLAN_ENABLE_AUTO_CONFIG_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_ENABLE_AUTO_CONFIG_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_ENABLE_AUTO_CONFIG_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_auto_config_enable_t)); + + config_enable_req = (rsi_auto_config_enable_t *)pkt->data; + + // Fill config profile enable/disable + config_enable_req->config_enable = enable; + + // Fill profile type + rsi_uint32_to_4bytes(config_enable_req->profile_type, type); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send delete profile command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_AUTO_CONFIG_ENABLE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_AUTO_CONFIG_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_ENABLE_AUTO_CONFIG_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_ENABLE_AUTO_CONFIG_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @brief Generate PMK if PSK and SSID are provided. This is a blocking API. + * @param[in] type - Possible values of this field are 1, 2, and 3, but we only pass 3 for generation of PMK. + * @param[in] psk - Expected parameters are pre-shared key(PSK) of the access point + * @param[in] ssid - Contain the SSID of the access point, this field will be valid only if TYPE value is 3. + * @param[in] pmk - PMK array + * @param[in] length - Length of PMK array + * @param[out] 32-byte PMK + * @return 0 - Success (If type value is 3) \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0x0021,0x0025,0x0026,0x0028,0x002C,0x0039,0x003a,0x003b) \n + * @note **Precondition** - \ref rsi_wlan_connect() API needs to be called before this API. + * @note Refer to \ref error-codes for the description of above error codes. + * + */ + +int32_t rsi_wlan_pmk_generate(int8_t type, int8_t *psk, int8_t *ssid, uint8_t *pmk, uint16_t length) +{ + int32_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + rsi_req_psk_t *psk_ptr = NULL; + SL_PRINTF(SL_WLAN_PMK_GENERATE_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_PMK_GENERATE_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_PMK_GENERATE_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + psk_ptr = (rsi_req_psk_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_psk_t)); + // + // Attach the buffer given by user + wlan_cb->app_buffer = (uint8_t *)pmk; + + // Length of the buffer provided by user + wlan_cb->app_buffer_length = length; + + // Assign type into structure member + psk_ptr->type = type; + + // Copy PSK given by user into structure member + rsi_strcpy(psk_ptr->psk_or_pmk, psk); + + // Copy SSID given by user into structure member + rsi_strcpy(psk_ptr->ap_ssid, ssid); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send PSK command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_HOST_PSK, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_PSK_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_PMK_GENERATE_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_PMK_GENERATE_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} +/*==============================================*/ +/** + * @fn int32_t rsi_wlan_11ax_config(void) + * @brief Configure the 11ax params. This is a blocking API. + * @pre \ref rsi_wlan_11ax_config() API needs to be called after opermode command only + * @return + * Non-Zero Value - Failure \n + * 0 - Success \n + * -2 - Invalid parameters \n + * -3 - Command given in wrong state \n + * -4 - Buffer not availableto serve the command \n + * If return value is greater than zero : 0x0021 + * @note Refer to Error Codes section for the description of the above error codes \ref SP16 + * Parameters given here are used internally by the API + * + * + */ +int32_t rsi_wlan_11ax_config(uint8_t gi_ltf) +{ + rsi_pkt_t *pkt; + int32_t status = RSI_SUCCESS; + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; +#if !(HE_PARAMS_SUPPORT) + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return command not supported error + return RSI_ERROR_COMMAND_NOT_SUPPORTED; +#endif + if (wlan_cb->state >= RSI_WLAN_STATE_INIT_DONE && wlan_cb->state < RSI_WLAN_STATE_CONNECTED) { + // Change WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return command given in wrong state error + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + wlan_11ax_config_params_t *config = (wlan_11ax_config_params_t *)pkt->data; + config->guard_interval = gi_ltf; + config->nominal_pe = NOMINAL_PE; + config->dcm_enable = DCM_ENABLE; + config->ldpc_enable = LDPC_ENABLE; + config->ng_cb_enable = NG_CB_ENABLE; + config->ng_cb_values = NG_CB_VALUES; + config->uora_enable = UORA_ENABLE; + config->trigger_rsp_ind = TRIGGER_RESP_IND; + config->ipps_valid_value = IPPS_VALID_VALUE; + config->tx_only_on_ap_trig = TX_ONLY_ON_AP_TRIG; + config->twt_support = TWT_SUPPORT; + config->config_er_su = CONFIG_ER_SU; + + // Send antenna select command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_11AX_PARAMS, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WLAN_11AX_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Return status + return status; +} +/*==============================================*/ +/** + * @brief Configure the sleep timer mode of the module to go into sleep during power save operation. This is a blocking API. + * @param[in] sleep_time - Sleep Time value in seconds. Minimum value is 1, and maximum value is 2100 + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * @note Can be issued any time in case of power save mode 8 with handshake type as MSG_BASED. + * + */ +int16_t rsi_wlan_set_sleep_timer(uint16_t sleep_time) +{ + int16_t status = RSI_SUCCESS; + rsi_pkt_t *pkt = NULL; + rsi_set_sleep_timer_t *timer = NULL; + SL_PRINTF(SL_WLAN_SET_SLEEP_TIMER_ENTRY, WLAN, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_SET_SLEEP_TIMER_COMMAND_GIVEN_IN_WRONG_STATE, WLAN, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_SET_SLEEP_TIMER_PKT_ALLOCATION_FAILURE, WLAN, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + timer = (rsi_set_sleep_timer_t *)pkt->data; + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_set_sleep_timer_t)); + + // Copy sleep_timer given by user into structure member + rsi_uint16_to_2bytes(timer->timeval, sleep_time); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send set sleep timer command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SET_SLEEP_TIMER, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_SET_SLEEP_TIMER_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_SET_SLEEP_TIMER_WLAN_COMMAND_ERROR, WLAN, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_SET_SLEEP_TIMER_ERROR_IN_SENDING_COMMAND, WLAN, LOG_ERROR, "status: %4x", status); + return status; +} + +/*====================================================*/ +/** + * @brief Register the WLAN callback functions. This is a non-blocking API. + * @param[in] callback_id - ID of the callback function. Table below displays supported IDs + * Parameter callback ID | Value + * :-----------------------------------------|:----------------------------------------------------------- + * RSI_JOIN_FAIL_CB | 0 + * RSI_IP_FAIL_CB | 1 + * RSI_REMOTE_SOCKET_TERMINATE_CB | 2 + * RSI_IP_CHANGE_NOTIFY_CB | 3 + * RSI_STATIONS_DISCONNECT_NOTIFY_CB | 4 + * RSI_STATIONS_CONNECT_NOTIFY_CB | 5 + * RSI_WLAN_DATA_RECEIVE_NOTIFY_CB | 6 + * RSI_WLAN_WFD_DISCOVERY_NOTIFY_CB | 7 + * RSI_WLAN_RECEIVE_STATS_RESPONSE_CB | 8 + * RSI_WLAN_WFD_CONNECTION_REQUEST_NOTIFY_CB | 9 + * RSI_WLAN_SCAN_RESPONSE_HANDLER | 10 + * RSI_WLAN_JOIN_RESPONSE_HANDLER | 11 + * RSI_WLAN_RAW_DATA_RECEIVE_HANDLER | 12 + * RSI_WLAN_SOCKET_CONNECT_NOTIFY_CB | 13 + * RSI_WLAN_SERVER_CERT_RECEIVE_NOTIFY_CB | 14 + * RSI_WLAN_ASYNC_STATS | 15 + * RSI_FLASH_WRITE_RESPONSE | 16 + * RSI_WLAN_ASSERT_NOTIFY_CB | 17 + * RSI_WLAN_MAX_TCP_WINDOW_NOTIFY_CB | 18 + * @param[in] callback_handler_ptr - Callback handler + * @param[out] status - Status of the asynchronous response + * @param[out] buffer - Payload of the asynchronous response + * @param[out] length - Length of the payload + * ### Prototypes of the callback functions with given callback id ### + * Callback id | Function Description + * :-----------------------------------------|:----------------------------------------------------------- + * RSI_JOIN_FAIL_CB | Called when asynchronous rejoin failure is received from the firmware. Application should try to re-join to the AP. This is valid in both AP and STA mode This callback is triggered when module fails to connect to AP in STA mode or when AP creation fails. \n + * ^ @note Need to call rsi_scan() API in STA mode, rsi_wlan_ap_start() API in AP mode. + * ^ @param buffer NULL \n + * ^ @param status Possible Error response codes - 0x0019,0x0045,0x0046,0x0047,0x0048,0x0049 + * RSI_IP_FAIL_CB | Called when asynchronous DHCP renewal failure is received from the firmware. Application should retry IP configuration. This is valid in both AP and STA mode. This callback is triggered when module fails to renew the DHCP. + * ^ @note Need to call rsi_wlan_connect() API. + * ^ @param buffer NULL \n + * ^ @param status Possible Error response codes - 0xFF9C, 0xFF9D + * RSI_REMOTE_SOCKET_TERMINATE_CB | Called when asynchronous remote TCP socket closed is received from the firmware. It is an indication given to application that the socket is terminated from remote. This is valid in both STA and AP mode. This callback is triggered when remote socket is terminated or closed + * ^ @note Need to connect to socket. + * ^ @param buffer rsi_rsp_socket_close_t ( \ref rsi_rsp_socket_close_s) response structure is provided in callback \n + * ^ @param status NA + * RSI_IP_CHANGE_NOTIFY_CB | Called when asynchronous IP change notification is received from the firmware. It is an indication given to application that the IP has been modified. This is valid only in STA mode. This callback is triggered when AP changes the IP address. + * ^ @note Need to call rsi_wlan_connect(),rsi_config_ipaddress() API. + * ^ @param buffer NULL \n + * ^ @param status RSI_SUCCESS + * RSI_STATIONS_DISCONNECT_NOTIFY_CB | Called when asynchronous station disconnect notification is received from the firmware in AP mode. It is an indication that the AP is disconnect. Application should retry to connect to the AP. This is valid when module acts as AP. This callback is triggered when stations are disconnected. + * ^ @note STA need to connect to the Accesspoint 9116. + * ^ @param buffer mac address is provided in response structure \n + * ^ @param status Response status @param length 6 + * RSI_STATIONS_CONNECT_NOTIFY_CB | Called when asynchronous station connect notification is received from the firmware in AP mode. It is an indication that the application is connected to the AP. This is valid when 9116 module acts as AP. This callback is triggered when stations are connected. + * ^ @pre STA need to connect to the accesspoint 9116. + * ^ @param buffer mac address is provided in response structure \n + * ^ @param status Response status + * ^ @param length 6 + * RSI_WLAN_DATA_RECEIVE_NOTIFY_CB | Called when asynchronous data is received from the firmware in TCP/IP bypass mode. This is valid in both AP and STA mode. This callback is triggered when data is received in TCP/IP bypass mode. + * ^ @pre Need to connect to socket. + * ^ @param buffer raw data received \n + * ^ @param status Response status + * RSI_WLAN_WFD_DISCOVERY_NOTIFY_CB | Called when Wi-Fi direct device discovery notification received from the firmware. This is valid in Wi-Fi Direct Mode only. This callback is triggered when a peer is discovered by the device. + * ^ @pre Need to call rsi_wireless_init() ,rsi_wlan_wfd_start_discovery API. + * ^ @param buffer NULL \n + * ^ @param status Response status + * RSI_WLAN_RECEIVE_STATS_RESPONSE_CB | Called when asynchronous receive statistics from the firmware in PER mode. This is valid in PER Mode only. This callback is triggered when module wants to receive statistics. + * ^ @pre Need to call rsi_wlan_radio_init() API. + * ^ @param buffer rsi_per_stats_rsp_t (\ref rsi_per_stats_rsp_s) response structure is provided in callback. \n + * ^ @param status Response status + * RSI_WLAN_WFD_CONNECTION_REQUEST_NOTIFY_CB | Called when Wi-Fi direct connection request from the firmware. This is valid in Wi-Fi Direct Mode only. This call back is triggered when there is a connection request from other peer device. + * ^ @pre Need to rsi_wireless_init() ,rsi_wlan_wfd_start_discovery() API. + * ^ @param buffer device name \n + * ^ @param status Response status + * ^ @param length 32 + * RSI_WLAN_SCAN_RESPONSE_HANDLER | Called when a response for scan request is received from the firmware. It is an indication to host that the scan is success or failed. This is valid only STA mode. This callback is triggered when module try to scan and receive response of all the available AP's. + * ^ @pre Need to call rsi_scan() API. + * ^ @param buffer NULL \n + * ^ @param status Response status. Possible error codes - 0x0002, 0x0003, 0x0005, 0x000A, 0x0014, 0x0015, 0x001A, 0x0021,0x0024,0x0025,0x0026,0x002C,0x003c + * RSI_WLAN_JOIN_RESPONSE_HANDLER | Called when a response for join request is received from the firmware. It is an indication to application that the join to AP is success or failed. This is valid in STA mode. This callback is triggered when station is successfully connected. + * ^ @pre Need to call rsi_scan API. + * ^ @param buffer NULL \n + * ^ @param status Response status. Possible Error response codes -0x0019, 0x0048,0x0045,0x0008 + * RSI_WLAN_RAW_DATA_RECEIVE_HANDLER | Called when raw data packets are received from the firmware. This is valid in both AP and STA mode. This callback is triggered when raw data is received in TCP/IP bypass mode. + * ^ @pre Need to connect to socket. + * ^ @param buffer raw data \n + * ^ @param status Response status. + * RSI_WLAN_SOCKET_CONNECT_NOTIFY_CB | Called when a socket connection response comes to the host. This is valid in both STA and AP mode. This callback is registered and triggered when socket connects. + * ^ @pre Need to create socket. + * ^ @param buffer rsi_rsp_socket_create_t ( \ref rsi_rsp_socket_create_s) \n + * ^ @param status Response status. + * RSI_WLAN_SERVER_CERT_RECEIVE_NOTIFY_CB | Reserved + * RSI_WLAN_ASYNC_STATS | Called when asynchronous response comes from the firmware to the host. Host can register this callback to get all the information regarding AP connectivity. + * ^ @param buffer rsi_state_notification_t ( \ref rsi_state_notification_s) response structure is provided in callback \n + * ^ @param status Response status + * RSI_WLAN_ASSERT_NOTIFY_CB | Called when WLAN assertion is triggered from firmware. It returns the assert value to the application. + * ^ @param buffer NULL \n + * ^ @param status Assert Value + * RSI_WLAN_MAX_TCP_WINDOW_NOTIFY_CB | Reserved + * + * ### RSI_WLAN_ASYNC_STATS ### + * • Asychronous messages are used to indicate module state to host. Asynchronous message are enabled by setting bit 10 of the custom feature bitmap in opermode. \n + * • In async messages time_stamp, state_code, reason_code, rsi_channel, rsi_rssi and rsi_bssid are logged. \n + * - time_stamp (4 bytes) + * - This is the value of the time stamp counter at the time of message; timestamps increment at intervals of 100ms. \n + * + * - state_code (1 byte) + * - This field indicates the state of the module. `state_code` contains two parts, the upper nibble and lower nibble. \n + * - The upper nibble indicates the state of the rejoin process. The following table documents the possible values of the upper nibble of state_code. \n + * State | Upper Nibble | Indication + *|:---------------------------------|:--------------|:----------------------------------------------------------------- + * Scan Trigger (State I) | `0x00` | Startup. Initial Roam + * ^ | `0x10` | Beacon Loss. Failover Roam + * ^ | `0x20` | De-authentication. AP induced roam / Disconnect from supplicant + * Scan Result/Decision (State II) | `0x50` | Current AP is best + * ^ | `0x60` | Better AP found + * ^ | `0x70` | No AP found + * Final Connection (State III) | `0x80` | Associated + * ^ | `0x90` | Unassociated + * - The lower nibble of state_code indicates the reason for a state change. The following table documents the possible values of the lower nibble of state_code. + * Lower Nibble | Reason for State Change + *|:--------------|:----------------------------------------------------------------------------------------- + * `0x00` | No reason specified + * `0x01` | No response from AP for authentication request(Authentication denial) + * `0x02` | Association denial + * `0x03` | User configured AP is not present + * `0x05` | EAPOL TX failure + * `0x06` | Deauthentication from user + * `0x07` | PSK not configured + * `0x08` | key-handshake failure during rejoin/roaming/after connection(Disconnection from supplicant) + * `0x09` | Roaming not enabled + * + * - reason_code (1 byte) + * - Indicates the reason for a failure. \n + * - These failures also include EAP connection errors for certificate parsing. \n + * - All supported reason codes are listed below + * reason_code | Reason codes + * |:-------|:---------------------- + * 0x00 | No reason specified + * 0x01 | No response from AP for authentication request(Authentication denial) + * 0x02 | Association denial + * 0x03 | User configured AP is not present + * 0x05 | EAPOL TX failure + * 0x06 | Deauthentication from user + * 0x07 | PSK not configured + * 0x08 | key-handshake failure during rejoin/roaming/after connection(Disconnection from supplicant) + * 0x09 | Roaming not enabled + * 0x10 | Beacon Loss (failover Roam) + * 0x20 | De-authentication (AP induced Roam/Deauth from supplicant) + * 0x28 |TLS CA Cert not present + * 0x29 |TLS PRIVATE key not present + * 0x2A |TLS Client Cert not present + * 0x2B |TLS no Cert present + * 0x2C |PEAP CA Cert not present + * 0x2D |Server Cert Invalid Key Type + * 0x2E |Server Intermediate CA Invalid Key Type + * 0x2F |Server Root CA Invalid Key Type + * 0x30 |Client Cert Invalid Key Type + * 0x31 |Client Root CA Invalid Key Type + * 0x32 |FIPS Server Cert Invalid Length + * 0x33 |FIPS Server Intermediate CA Invalid Length + * 0x34 |FIPS Server Root CA Invalid Length + * 0x35 |FIPS Client Cert Invlaid Length + * 0x36 |FIPS Client Root CA Invalid Length + * 0x37 |Server Cert 4096-bit length support is not enabled +|* 0x38 |Server Intermediate CA 4096-bit length support is not enabled +|* 0x39 |Server Root CA 4096-bit length support is not enabled +|* 0x3A |Client Cert 4096-bit length support is not enabled +|* 0x3B |Client Root CA 4096-bit length support is not enabled + * 0x3C |Server Cert Invalid Sign Alg + * 0x3D |Server Intermediate CA Invalid Sign Alg + * 0x3E |Server Root CA Invalid Sign Length + * 0x3F |Client Cert Invalid Sign Alg + * 0x40 |Client Root CA Invalid Sign Length + * 0x41 |Server Intermediate CA not Present + * 0x42 |Server Root CA Parse Error + * 0x43 |Server Intermediate Root CA Parse Error + * 0x44 |Sever Cert Parse Error + * 0x45 |Client Cert Parse Error + * 0x46 |Incorrect Private Key Password + * 0x47 |EAP Failure Received + * 0x48 |Client Cert Bad Date Error + * 0x49 |Server Cert Bad Date Error + * 0x4A |Server Root CA Bad Date Error + * 0x4B |Client Root CA Bad Date Error + * 0x4C |Server Intermediate Root CA Bad Date Error + * 0x4D |Pem Header Error + * 0x4E |Pem Footer Error + * 0x4F |Client Intermediate CA Invalid Sign Length + * 0x50 |Client Intermediate CA Invalid Length + * 0x51 |FIPS Client Intermediate CA Invalid Length + * 0x52 |Client Intermediate CA invalid Key Type + * 0x53 |Pem Error + * - In addition to the above, reason code received in Deauthentication/Disassociation frame from AP is added. This will set the MSB bit of reason_code. \n + * - If MSB bit is set in reason code, then mask it with 0x7f to get the acutal reason code received in Deauthentication/Disassociation frame. \n + * - In RS9116 Rev 1.4, above reason codes will come only in TCP/IP bypass mode. \n + * - Pem Header Error(0x4D) or Pem Footer Error(0x4E) are only applicable if certificates are loaded individually. In case if certificates are loaded combinedly in a single file, only Pem Error(0x53) will be triggered for Header or Footer errors. \n + */ +uint16_t rsi_wlan_register_callbacks(uint32_t callback_id, + void (*callback_handler_ptr)(uint16_t status, + uint8_t *buffer, + const uint32_t length)) +{ + SL_PRINTF(SL_WLAN_REGISTER_CALLBACKS_ENTRY, WLAN, LOG_INFO); + if (callback_id > RSI_MAX_NUM_CALLBACKS) { + /* + *Return , if the callback number exceeds the RSI_MAX_NUM_CALLBACKS ,or + * the callback is already registered + */ + SL_PRINTF(SL_WLAN_REGISTER_CALLBACKS_NUMBER_EXCEEDS_MAX_NUM_CALLBACKS_OR_CALLBACK_ALREADY_REG, WLAN, LOG_INFO); + return 1; + } + if (callback_id == RSI_JOIN_FAIL_CB) // check for NULL or not + { + // Register join fail callback handler + rsi_wlan_cb_non_rom->callback_list.join_fail_handler = callback_handler_ptr; + } else if (callback_id == RSI_IP_FAIL_CB) { + // Register IP renewal fail callback handler + rsi_wlan_cb_non_rom->callback_list.ip_renewal_fail_handler = callback_handler_ptr; + } else if (callback_id == RSI_REMOTE_SOCKET_TERMINATE_CB) { + // Register remote socket terminate callback handler + rsi_wlan_cb_non_rom->callback_list.remote_socket_terminate_handler = callback_handler_ptr; + } else if (callback_id == RSI_IP_CHANGE_NOTIFY_CB) { + // Register IP change notify callback handler + rsi_wlan_cb_non_rom->callback_list.ip_change_notify_handler = callback_handler_ptr; + } else if (callback_id == RSI_STATIONS_CONNECT_NOTIFY_CB) { + // Register station connect notify callback handler + rsi_wlan_cb_non_rom->callback_list.stations_connect_notify_handler = callback_handler_ptr; + } else if (callback_id == RSI_STATIONS_DISCONNECT_NOTIFY_CB) { + // Register station disconnect notify callback handler + rsi_wlan_cb_non_rom->callback_list.stations_disconnect_notify_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_DATA_RECEIVE_NOTIFY_CB) { + // Register WLAN data packet receive notify callback handler + rsi_wlan_cb_non_rom->callback_list.wlan_data_receive_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_RECEIVE_STATS_RESPONSE_CB) { + // Register WLAN receive stats notify callback handler + rsi_wlan_cb_non_rom->callback_list.wlan_receive_stats_response_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_WFD_DISCOVERY_NOTIFY_CB) { + // Register Wi-Fi direct device discovery notify callback handler + rsi_wlan_cb_non_rom->callback_list.wlan_wfd_discovery_notify_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_WFD_CONNECTION_REQUEST_NOTIFY_CB) { + // Register Wi-Fi direct connection request notify callback handler + rsi_wlan_cb_non_rom->callback_list.wlan_wfd_connection_request_notify_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_RAW_DATA_RECEIVE_HANDLER) { + // Register raw data receive notify callback handler + rsi_wlan_cb_non_rom->callback_list.raw_data_receive_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_RECEIVE_CSI_DATA) { + // Register CSI data receive notify callback handler + rsi_wlan_cb_non_rom->callback_list.wlan_receive_csi_data_response_handler = callback_handler_ptr; + } +#ifndef RSI_M4_INTERFACE + else if (callback_id == RSI_WLAN_SOCKET_CONNECT_NOTIFY_CB) { + // Register socket connection notify callback handler + rsi_wlan_cb_non_rom->callback_list.socket_connect_response_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_SERVER_CERT_RECEIVE_NOTIFY_CB) { + // Register certificate response callback handler + rsi_wlan_cb_non_rom->callback_list.certificate_response_handler = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_ASYNC_STATS) { + rsi_wlan_cb_non_rom->callback_list.wlan_async_module_state = callback_handler_ptr; + } +#endif + else if (callback_id == RSI_WLAN_ASSERT_NOTIFY_CB) { + // Register assert notify callback handler + rsi_wlan_cb_non_rom->callback_list.rsi_assertion_cb = callback_handler_ptr; + } else if (callback_id == RSI_WLAN_MAX_TCP_WINDOW_NOTIFY_CB) { + if ((RSI_TCP_IP_FEATURE_BIT_MAP & TCP_IP_FEAT_EXTENSION_VALID) + && (RSI_EXT_TCPIP_FEATURE_BITMAP & EXT_TCP_DYNAMIC_WINDOW_UPDATE_FROM_HOST)) { + // Register max available RX window callback handler + rsi_wlan_cb_non_rom->callback_list.rsi_max_available_rx_window = callback_handler_ptr; + } + } else if (callback_id == RSI_WLAN_TWT_RESPONSE_CB) { + rsi_wlan_cb_non_rom->callback_list.twt_response_handler = callback_handler_ptr; + } + SL_PRINTF(SL_WLAN_REGISTER_CALLBACKS_EXIT, WLAN, LOG_INFO); + return 0; +} +/** @} */ + +/** @addtogroup NETWORK5 +* @{ +*/ +/*==============================================*/ +/** + * @brief Set the socket configuration parameters. The configurations can be done using the Socket configuration in the rsi_wlan_config.h file. \n + * Using this API is highly recommended. Based on the socket configuration, module will use available buffers effectively. \n + * This is a blocking API. + * @param void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0x0021, 0x0025, 0x002C, 0xFF6D) \n + * @note **Precondition** - \ref rsi_config_ipaddress() API and socket creation should be done before this API is called. + * @note The following parameters are provided by user, + * Parameters | Description + * :-------------------------------|:-------------------------------------------------------------------------------------------------- + * total socket | Desired total number of sockets to open + * total_tcp_sockets | Desired total number of TCP sockets to open + * total_udp_sockets | Desired total number of UDP sockets to open + * tcp_tx_only_sockets | Desired total number of TCP sockets to open which are used only for data transmission + * tcp_rx_only_sockets | Desired total number of TCP sockets to open which are used only for data reception + * udp_tx_only_sockets | Desired total number of UDP sockets to open which are used only for data transmission + * udp_rx_only_sockets | Desired total number of UDP sockets to open which are used only for data reception + * tcp_rx_high_performance_sockets | Desired total number of high performance TCP sockets to open. High performance sockets can be \n + * ^ allocated with more buffers based on the buffers availability. This option is valid only for TCP \n + * ^ data receive sockets. Socket can be opened as high performance by setting high performance bit in \n + * ^ socket create command. + * tcp_rx_window_size_cap | Desired total to increase the TCP RX window size + * tcp_ack_window_div_factor | In case of high latency networks to configure the TCP ACK division factor with respective to the \n + * ^ window size; Increases the ACK frequency for asynchronous sockets \n + * ^ Note: \n + * ^ Default value is tcp_rx_window_size_cap. + * @note The following conditions must be met: \n + * @note total_sockets <= Maximum allowed sockets(10) \n + * @note (total_tcp_sockets + total_udp_sockets) <= total_sockets \n + * @note (total_tcp_tx_only_sockets + total_tcp_rx_only_sockets) <= total_tcp_sockets \n + * @note (total_udp_tx_only_sockets + total_udp_rx_only_sockets) <= total_udp_sockets \n + * @note total_tcp_rx_high_performance_sockets <= total_tcp_rx_only_sockets \n + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_socket_config(void) +{ + + rsi_pkt_t *pkt; + rsi_socket_config_t *rsi_socket_config; + int32_t status = RSI_SUCCESS; + + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_IP_CONFIG_DONE) { + // Command given in wrong state + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + // Take the user provided data and fill it in antenna select structure + rsi_socket_config = (rsi_socket_config_t *)pkt->data; + + // Total sockets + rsi_socket_config->total_sockets = TOTAL_SOCKETS; + + // Total TCP sockets + rsi_socket_config->total_tcp_sockets = TOTAL_TCP_SOCKETS; + + // Total UDP sockets + rsi_socket_config->total_udp_sockets = TOTAL_UDP_SOCKETS; + + // Total TCP TX sockets + rsi_socket_config->tcp_tx_only_sockets = TCP_TX_ONLY_SOCKETS; + + // Total TCP RX sockets + rsi_socket_config->tcp_rx_only_sockets = TCP_RX_ONLY_SOCKETS; + + // Total UDP TX sockets + rsi_socket_config->udp_tx_only_sockets = UDP_TX_ONLY_SOCKETS; + + // Total UDP RX sockets + rsi_socket_config->udp_rx_only_sockets = UDP_RX_ONLY_SOCKETS; + + // TCP RX high performance sockets + rsi_socket_config->tcp_rx_high_performance_sockets = TCP_RX_HIGH_PERFORMANCE_SOCKETS; + + // TCP RX windows size + rsi_socket_config->tcp_rx_window_size_cap = TCP_RX_WINDOW_SIZE_CAP; + + // TCP RX windows division factor + rsi_socket_config->tcp_rx_window_div_factor = TCP_RX_WINDOW_DIV_FACTOR; + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send socket configuration command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_SOCKET_CONFIG, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_SOCK_CONFIG_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + return status; + } + + // Return status + return status; +} +/** @} */ +/** @addtogroup NETWORK17 +* @{ +*/ + +/*==============================================*/ +/** + * @brief Register and Deregister WLAN radio. + * @param[in] enable - To register and deregister WLAN radio + * @param[out] RSI_SUCCESS + * @return 0 - Success \n + * @return Non-Zero Value - Failure + * + */ +/// @private +int32_t rsi_wlan_req_radio(uint8_t enable) +{ + rsi_pkt_t *pkt = NULL; + int32_t status = RSI_SUCCESS; + rsi_wlan_req_radio_t *wlan_radio = NULL; + SL_PRINTF(SL_WLAN_REQ_RADIO_ENTRY, NETWORK, LOG_INFO); + // Get WLAN CB structure pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + if (wlan_cb->state < RSI_WLAN_STATE_OPERMODE_DONE) { + // Command given in wrong state + SL_PRINTF(SL_WLAN_REQ_RADIO_COMMAND_GIVEN_IN_WRONG_STATE, NETWORK, LOG_ERROR); + return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; + } + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_REQ_RADIO_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + wlan_radio = (rsi_wlan_req_radio_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_wlan_req_radio_t)); + + wlan_radio->radio_req = enable; + if (wlan_radio->radio_req) { + rsi_wlan_cb_non_rom->wlan_radio = RSI_WLAN_RADIO_REGISTER; + } else { + rsi_wlan_cb_non_rom->wlan_radio = RSI_WLAN_RADIO_DEREGISTER; + } + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_RADIO, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_WLAN_RADIO_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_REQ_RADIO_WLAN_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_REQ_RADIO_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Deregister WLAN radio. This is a blocking API. + * @param[in] void + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0x0021,0x0067) \n + * @note If rsi_wlan_radio_deinit() API is called after rsi_wlan_scan(). Need to call rsi_wlan_scan() API again after the rsi_wlan_radio_init(). \n + * @note If rsi_wlan_radio_deinit() API is allowed before WLAN connected state only.\n + * ### Below APIs are allowed after rsi_wlan_radio_deinit() API ### + * 1. \ref rsi_wlan_radio_init() + * 2. \ref rsi_wlan_power_save_profile() + * 3. \ref rsi_wlan_get() In this API only RSI_MAC_ADDRESS and RSI_CONNECTION_STATUS cmd_type are allowed. + * 4. \ref rsi_wireless_deinit() + * 5. \ref rsi_switch_proto() + * 6. \ref rsi_get_ram_log() + * 7. \ref rsi_get_fw_version() + * 8. \ref rsi_common_debug_log() + * 9. \ref rsi_bt_power_save_profile() + * @note **Precondition** - The application should be in radio init and unconnected state before calling this function. \n + * \ref rsi_wlan_radio_deinit() API is called after \ref rsi_wlan_scan() + * + */ + +int32_t rsi_wlan_radio_deinit(void) +{ + int32_t status = RSI_SUCCESS; + // Req for WLAN radio + status = rsi_wlan_req_radio(RSI_DISABLE); + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_RADIO_DEINIT_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ +//#ifdef RSI_WAC_MFI_ENABLE + +#ifdef RSI_WAC_MFI_ENABLE +/** @addtogroup NETWORK18 +* @{ +*/ + +/*==============================================*/ +/** + * @brief Add the Apple defined IE elements to the beacon command request structure. + * @param[in] mfi_ie - Pointer to the IE element + * @param[in] ie_len - Length of the IE element + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffa)\n + */ +/// @private +int32_t rsi_wlan_add_mfi_ie(int8_t *mfi_ie, uint32_t ie_len) +{ + int32_t status = RSI_SUCCESS; + SL_PRINTF(SL_WLAN_ADD_MFI_IE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt; + rsi_req_add_mfi_ie_t *mfi_ie_req = NULL; + + // Get WLAN CB struct pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_ADD_MFI_IE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + mfi_ie_req = (rsi_req_add_mfi_ie_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_req_add_mfi_ie_t)); + + // Fill IE length + mfi_ie_req->mfi_ie_len = ie_len; + + // Copy IE + memcpy(mfi_ie_req->mfi_ie, mfi_ie, ie_len); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send WPS request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_ADD_MFI_IE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_ADD_MFI_IE_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_ADD_MFI_IE_WLAN_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_ADD_MFI_IE_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +#endif +/** @} */ + +/** @addtogroup WLAN +* @{ +*/ +/*==============================================*/ +/** + * @brief Assign the user configurable channel gain values in different regions to the module from user. This API is used for overwriting default gain tables that are present in firmware. \n + * You can load all the three gain tables (i.e., 2.4GHz-20Mhz, 5GHz-20Mhz, 5GHz-40Mhz) one after other by changing band and bandwidth values. This is a blocking API. + * @param[in] band - 0 : 2.4GHz \n + * 1 : 5GHz \n + * 2 : Dual band (2.4 Ghz and 5 Ghz) + * @param[in] bandwidth - 0 : 20 MHz \n + * 1 : 40 MHz + * @param[in] payload - Pass channel gain values for different regions in an given array format. + * @param[in] payload_len - Max payload length (table size) in 2.4GHz is 128 bytes. \n + * Max payload length (table size) in 5GHz is 64 bytes + * ### Gain Table Payload Format ### + * + * 1. Gain table Format for 2.4G Band: (Each entry of the table is 1 byte) + * In 2Ghz, Max Gain/Power obtained from certification should be doubled and loaded. + * = { + * , + * , , + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * . + * . + * . + * . + * . + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * , , + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * . + * . + * . + * . + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * , <2 * MAX POWER FOR b RATE>, <2 * MAX POWER FOR g RATE>, <2 * MAX POWER FOR n RATE>, + * }; + * + * Gain table Format for 5G Band: (Each entry of the table is 1 byte) + * In 5Ghz, Max Gain/Power obtained from certification should be loaded. + *
= { + * , + * , , + * , , , + * , , , + * , , , + * , , , + * , , , + * , , , + * , , , + * , , , + * . + * . + * . + * . + * . + * , , + * }; + * 2. Supported Region names: + * FCC, RED,TELEC + * The following are the regions and the values to be passed instead of macros in the example. + * Region | Macro Value + * ------------|-------------------- + * FCC | 0 + * RED | 1 + * TELEC | 2 + * 3. is a 8 bit value which is encoded as: + * If TX powers of all the channels are same, then use CHANNEL_CODE_2G as 17. In this case, mention channel number as 255. + * Tf TX power is not same for all channels, then indicate CHANNEL_CODE_2G as no-of channels. And specify tx power values for all the channels indicated. + * 4. is a 8 bit value encoded as number of rows in a region for 5G band. + * a. 5G is divided into 4 sub bands: + * band 1: channel number <= 48 + * band 2: channel number > 48 and channel number <= 64 + * band 3: channel number > 64 and channel number <= 144 + * band 4: channel number > 144 + * b. If any channel in a band has different set of power values, specify the channel number followed by power values. + * c. If all the channels in a band 1 has same power values, specify the band number as 1 followed by power value. + * d. If all the channels in a band 2 has same power values, specify the band number as 2 followed by power value. + * e. If all the channels in a band 3 has same power values, specify the band number as 3 followed by power value. + * f. If all the channels in a band 4 has same power values, specify the band number as 4 followed by power value. + * + * + * ### Example payload formats ### + * + * Examples: + * For 2.4Ghz Band in 20Mhz bandwidth + * {3, //NUM_OF_REGIONS + * FCC, 13, //NUM_OF_CHANNELS + * // rate, 11b, 11g, 11n + * 1, 34, 20, 20, + * 2, 34, 28, 28, + * 3, 34, 32, 32, + * 4, 34, 36, 36, + * 5, 34, 38, 38, + * 6, 34, 40, 40, + * 7, 34, 38, 38, + * 8, 34, 36, 36, + * 9, 34, 32, 32, + * 10, 34, 32, 32, + * 11, 34, 24, 24, + * 12, 34, 16, 24, + * 13, 34, 12, 12, + * TELEC, 17, + * 255, 20, 16, 16, + * }; //}}} + * + * For 5Ghz band in 20Mhz bandwidth + * {2, + * FCC, 6, + * 1, 9, 10, //band 1 + * 2, 8, 9, //band 2 + * 100, 4, 4, //band 3 + * 3, 6, 8, //band 3 + * 149, 3, 3, //band 4 + * TELEC, 4, + * 1, 9, 10, //band 1 + * 2, 8, 10, //band 2 + * 3, 6, 8, //band 3 + * 4, 6, 7, //band 4 + * }; + * + * + * For 5Ghz band in 40Mhz bandwidth + * {2, + * FCC, 8, + * 1, 9, 10, //band 1 + * 62, 8, 9, //band 2 + * 2, 8, 9, //band 2 + * 102, 4, 4, //band 3 + * 134, 6, 8, //band 3 + * 3, 6, 8, //band 3 + * 151, 3, 3, //band 4 + * 4, 6, 7, //band 4 + * TELEC, 4, + * 1, 9, 10, //band 1 + * 2, 8, 10, //band 2 + * 3, 6, 8, //band 3 + * 4, 6, 7, //band 4 + * }; + * + * ###Customers using Certified MARS antenna should use the gain table structures below:### + * + * For 2.4Ghz Band in 20Mhz bandwidth + * {3,//NUM_OF_REGIONS + * FCC, 0xD,//NUM_OF_CHANNELS + * // rate, 11b, 11g, 11n + * 1, 28, 32, 30, + * 2, 28, 32, 30, + * 3, 28, 32, 30, + * 4, 30, 28, 34, + * 5, 30, 28, 34, + * 6, 30, 28, 34, + * 7, 30, 28, 34, + * 8, 30, 28, 34, + * 9, 28, 30, 30, + * 10, 28, 30, 30, + * 11, 28, 30, 30, + * 12, 28, 30, 30, + * 13, 28, 30, 30, + * TELEC,0x11, //NA + * 255, 20, 16, 16, + * }; + * + * For 5Ghz band in 20Mhz bandwidth + * {2, + * FCC, 0x6, + * 1, 12, 12, //band 1 + * 2, 11, 11, //band 2 + * 100, 10, 12, //band 3 + * 3, 13, 13, //band 3 + * 140, 10, 11, //band 4 + * 4, 13, 13, //band 4 + * TELEC, 0x4, //NA + * 1, 9, 10, //band 1 + * 2, 8, 10, //band 2 + * 3, 6, 8, //band 3 + * 4, 6, 7, //band 4 + * }; + * + * + * For 5Ghz band in 40Mhz bandwidth + * {2, + * FCC, 0x8, + * 1, 9, 9, //band 1 + * 62, 8, 8, //band 2 + * 2, 9, 9, //band 2 + * 102, 9, 9, //band 3 + * 134, 12, 12, //band 3 + * 3, 10, 10, //band 3 + * 151, 11, 11, //band 4 + * 4, 11, 11, //band 4 + * TELEC, 0x4, //NA + * 1, 9, 10, //band 1 + * 2, 8, 10, //band 2 + * 3, 6, 8, //band 3 + * 4, 6, 7, //band 4 + * }; + * @return 0 - Success \n + * @return Non-Zero Value - Failure (**Possible Error Codes** - 0xfffffffe,0xfffffffd,0x0021,0x003E) \n + * @note **Precondition** - \ref rsi_radio_init() API needs to be called before this API + * @note Length of the payload should match with payload_len parameter value. + * @note 40Mhz is not supported in both 2.4GHz and 5GHz + * @note This API must be used by customers who has done FCC/RED/TELEC certification with their own antenna. Inappropriate use of this API may result in violation of FCC/RED/TELEC, or any certifications and Silicon labs is not liable for that. + * @note Internally firmware maintains two gain tables: Worldwide table & Region based table. Worldwide table is populated by firmware with maximum power values that chip can transmit that meets target specifications like EVM. Region based table has default gain value set. + * @note When certifying with your own antenna, region must be set to Worldwide and sweep the power from 0 to 21dBm. Arrive at maximum power level that is passing certification especially band-edge. + * @note These FCC/RED/TELEC maximum power level should be loaded in end-to-end mode via WLAN User Gain table. + * @note This API must be called after every boot-up since this information is not saved inside flash. + * @note Region based user gain table sent by application is copied onto Region based table. SoC uses this table in FCC/RED/TELEC to limit power and not to violate allowed limits. For Worldwide region firmware uses Worldwide table for transmit. \n + * For other regions (FCC/RED/TELEC), firmware uses minimum value of Worldwide and Region based table for transmit. + * @note There will be part to part variation across chips and offsets are estimated during manufacturing flow which will be applied as correction factor during normal mode of operation. + * @note Refer to \ref error-codes for the description of above error codes. + */ +int32_t rsi_wlan_update_gain_table(uint8_t band, uint8_t bandwidth, uint8_t *payload, uint16_t payload_len) +{ + int32_t status = 0; + SL_PRINTF(SL_WLAN_UPDATE_GAIN_TABLE_ENTRY, NETWORK, LOG_INFO); + rsi_pkt_t *pkt = NULL; + + rsi_gain_table_info_t *gain_table = NULL; + + // Get WLAN CB struct pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + // Check for gain table max supported payload length + if (payload_len > GAIN_TABLE_MAX_PAYLOAD_LEN) { + SL_PRINTF(SL_WLAN_UPDATE_GAIN_TABLE_INVALID_PARAM, NETWORK, LOG_ERROR); + return RSI_ERROR_INVALID_PARAM; + } + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_UPDATE_GAIN_TABLE_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + gain_table = (rsi_gain_table_info_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_gain_table_info_t)); + + // Fill band + gain_table->band = band; + + // Fill bandwidth + gain_table->bandwidth = bandwidth; + + // Fill payload length + gain_table->size = payload_len; + + // Fill payload content + memcpy(gain_table->gain_table, payload, payload_len); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_GAIN_TABLE, pkt); + + // Wait on WLAN semaphore + rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->wlan_cmd_sem, RSI_GAIN_TABLE_RESPONSE_WAIT_TIME); + + // Get WLAN/network command response status + status = rsi_wlan_get_status(); + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_UPDATE_GAIN_TABLE_WLAN_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_UPDATE_GAIN_TABLE_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} + +/*==============================================*/ +/** + * @brief Enable or disable CSI data retrieval with configured periodicity. + * @pre \ref rsi_wlan_scan() API needs to be called before this API. + * @param[in] enable - Enable or disable CSI data retrieval. + * @param[in] periodicity - Periodicity of CSI data retrieval in microseconds. + * @param[in] num_of_mac_addr - Number of MAC addresses. + * @param[in] mac_addr - Pointer to a 2-D matrix containing the list of MAC addresses. + * @param[in] rsi_wlan_csi_data_response_handler - Called when CSI data has been received from the module. + * @note Callback implementation example - \n + * void rsi_wlan_csi_data_response_handler(uint16_t status, rsi_rsp_csi_data_t *payload, const uint32_t payload_length) \n + * @param[out] status - Response status: 0 - Success, 0x21 - rsi_wlan_csi_config_async() called in wrong state + * @param[out] payload - Response buffer + * @param[out] payload_length - Length of the response buffer. Payload length will be sizeof(rsi_rsp_csi_data_t) bytes. + * @note \ref rsi_rsp_csi_data_s : Structure type supposed to hold incoming CSI data + * @return 0 - Success \n + * Non-Zero Value - Failure \n + * -1 - Callback not registered \n + * -4 - Buffer unavailable to serve the command + * @note Refer to Error Codes section for the description of the above error codes \ref error-codes + * + */ +int32_t rsi_wlan_csi_config_async(uint8_t enable, + uint32_t periodicity, + uint8_t num_of_mac_addr, + uint8_t (*mac_addr)[6], + void (*wlan_csi_data_response_handler)(uint16_t status, + uint8_t *buffer, + const uint32_t length)) +{ + int32_t status = 0; + rsi_pkt_t *pkt = NULL; + rsi_csi_config_t *rsi_csi_config = NULL; + + SL_PRINTF(SL_WLAN_CSI_CONFIG_ENTRY, NETWORK, LOG_INFO); + + if (rsi_wlan_cb_non_rom->callback_list.wlan_receive_csi_data_response_handler == NULL) { + if (wlan_csi_data_response_handler != NULL) { + rsi_wlan_cb_non_rom->callback_list.wlan_receive_csi_data_response_handler = wlan_csi_data_response_handler; + } else { + return RSI_FAILURE; + } + } + + // Get WLAN CB struct pointer + rsi_wlan_cb_t *wlan_cb = rsi_driver_cb->wlan_cb; + + status = rsi_check_and_update_cmd_state(WLAN_CMD, IN_USE); + if (status == RSI_SUCCESS) { + + // Allocate command buffer from WLAN pool + pkt = rsi_pkt_alloc(&wlan_cb->wlan_tx_pool); + + // If allocation of packet fails + if (pkt == NULL) { + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + // Return packet allocation failure error + SL_PRINTF(SL_WLAN_CSI_CONFIG_PKT_ALLOCATION_FAILURE, NETWORK, LOG_ERROR, "status: %4x", status); + return RSI_ERROR_PKT_ALLOCATION_FAILURE; + } + + rsi_csi_config = (rsi_csi_config_t *)pkt->data; + + // Memset buffer + memset(&pkt->data, 0, sizeof(rsi_csi_config_t)); + + // Fill enable/disable status + rsi_csi_config->csi_enable = enable; + + // Fill periodicity of receiving CSI data from module + rsi_csi_config->periodicity = periodicity; + + // Fill the number of mac addresses + rsi_csi_config->num_of_mac_addr = num_of_mac_addr; + + // Copy the MAC addresses + memcpy(rsi_csi_config->mac_addresses, mac_addr, num_of_mac_addr * RSI_MAC_ADDR_LEN); + +#ifndef RSI_WLAN_SEM_BITMAP + rsi_driver_cb_non_rom->wlan_wait_bitmap |= BIT(0); +#endif + // Send CSI data retrieval request command + status = rsi_driver_wlan_send_cmd(RSI_WLAN_REQ_GET_CSI_DATA, pkt); + + // Change the WLAN CMD state to allow + rsi_check_and_update_cmd_state(WLAN_CMD, ALLOW); + + } else { + // Return WLAN command error + SL_PRINTF(SL_WLAN_CSI_CONFIG_WLAN_COMMAND_ERROR, NETWORK, LOG_ERROR, "status: %4x", status); + return status; + } + + // Return status if error in sending command occurs + SL_PRINTF(SL_WLAN_CSI_CONFIG_ERROR_IN_SENDING_COMMAND, NETWORK, LOG_ERROR, "status: %4x", status); + return status; +} +/** @} */ diff --git a/wiseconnect/zephyr/rsi_hal_mcu_interrupt.c b/wiseconnect/zephyr/rsi_hal_mcu_interrupt.c new file mode 100644 index 00000000..086c427d --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_interrupt.c @@ -0,0 +1,156 @@ +/******************************************************************************* +* @file rsi_hal_mcu_interrupt.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ +#include "rsi_driver.h" +#include +#include +#include + +#define DT_DRV_COMPAT silabs_rs9116w + +static const struct gpio_dt_spec int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios); + +typedef void (* interrupt_callback_t)(void); + +static struct gpio_callback cb_data; + +static interrupt_callback_t callback; + +void int_callback(const struct device *port, + struct gpio_callback *cb, gpio_port_pins_t pins) +{ + callback(); +} + +/*===================================================*/ +/** + * @fn void rsi_hal_intr_config(void (* rsi_interrupt_handler)()) + * @brief Starts and enables the SPI interrupt + * @param[in] rsi_interrupt_handler() ,call back function to handle interrupt + * @param[out] none + * @return none + * @description This HAL API should contain the code to initialize the register/pins + * related to interrupts and enable the interrupts. + */ +void rsi_hal_intr_config(void (* rsi_interrupt_handler)(void)) +{ + + + //! Configure interrupt pin/register in input mode and register the interrupt handler + callback = rsi_interrupt_handler; + + gpio_pin_configure_dt(&int_gpio, GPIO_INPUT); + + gpio_init_callback(&cb_data, int_callback, BIT(int_gpio.pin)); + gpio_add_callback(int_gpio.port, &cb_data); + + return; + +} + + +/*===================================================*/ +/** + * @fn void rsi_hal_intr_mask(void) + * @brief Disables the SPI Interrupt + * @param[in] none + * @param[out] none + * @return none + * @description This HAL API should contain the code to mask/disable interrupts. + */ +void rsi_hal_intr_mask(void) +{ + + //! Mask/Disable the interrupt + gpio_pin_interrupt_configure_dt(&int_gpio, GPIO_INT_DISABLE); + return; + +} + + +/*===================================================*/ +/** + * @fn void rsi_hal_intr_unmask(void) + * @brief Enables the SPI interrupt + * @param[in] none + * @param[out] none + * @return none + * @description This HAL API should contain the code to enable interrupts. + */ +void rsi_hal_intr_unmask(void) +{ + + //! Unmask/Enable the interrupt + gpio_pin_interrupt_configure_dt(&int_gpio, GPIO_INT_EDGE_RISING); + return; + +} + + + +/*===================================================*/ +/** + * @fn void rsi_hal_intr_clear(void) + * @brief Clears the pending interrupt + * @param[in] none + * @param[out] none + * @return none + * @description This HAL API should contain the code to clear the handled interrupts. + */ +void rsi_hal_intr_clear(void) +{ + //! Clear the interrupt + + return; + + +} + + +/*===================================================*/ +/** + * @fn void rsi_hal_intr_pin_status(void) + * @brief Checks the SPI interrupt at pin level + * @param[in] none + * @param[out] uint8_t, interrupt status + * @return none + * @description This API is used to check interrupt pin status(pin level whether it is high/low). + */ +uint8_t rsi_hal_intr_pin_status(void) +{ + + volatile uint8_t status = 0; + + //! Return interrupt pin status(high(1) /low (0)) + status = rsi_hal_get_gpio(RSI_HAL_MODULE_INTERRUPT_PIN); + + return status; +} + diff --git a/wiseconnect/zephyr/rsi_hal_mcu_ioports.c b/wiseconnect/zephyr/rsi_hal_mcu_ioports.c new file mode 100644 index 00000000..11cf7d47 --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_ioports.c @@ -0,0 +1,176 @@ +/******************************************************************************* +* @file rsi_hal_mcu_ioports.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ +#include "rsi_driver.h" + +#include +#include +#include + +#define DT_DRV_COMPAT silabs_rs9116w + +/** + * Global Variales + */ + +static const struct gpio_dt_spec reset_gpio = + GPIO_DT_SPEC_INST_GET(0, reset_gpios); +static const struct gpio_dt_spec int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios); + +#if DT_INST_NODE_HAS_PROP(0, sleep_wake_indication_gpios) +static const struct gpio_dt_spec wake_gpio = + GPIO_DT_SPEC_INST_GET(0, sleep_wake_indication_gpios); +#endif + +#if DT_INST_NODE_HAS_PROP(0, sleep_wake_confirmation_gpios) +static const struct gpio_dt_spec sleep_gpio = + GPIO_DT_SPEC_INST_GET(0, sleep_wake_confirmation_gpios); +#endif + +static const struct gpio_dt_spec *get_gpio(uint8_t gpio_number) +{ + switch (gpio_number) { + case RSI_HAL_RESET_PIN: + return &reset_gpio; + break; + case RSI_HAL_MODULE_INTERRUPT_PIN: + return &int_gpio; + break; +#if DT_INST_NODE_HAS_PROP(0, sleep_wake_indication_gpios) + case RSI_HAL_WAKEUP_INDICATION_PIN: + return &wake_gpio; + break; +#endif +#if DT_INST_NODE_HAS_PROP(0, sleep_wake_confirmation_gpios) + case RSI_HAL_SLEEP_CONFIRM_PIN: + case RSI_HAL_LP_SLEEP_CONFIRM_PIN: + return &sleep_gpio; + break; +#endif + default: + return NULL; + break; + } +} + +/*===========================================================*/ +/** + * @fn void rsi_hal_config_gpio(uint8_t gpio_number,uint8_t + * mode,uint8_t value) + * @brief Configures gpio pin in output mode,with a value + * @param[in] uint8_t gpio_number, gpio pin number to be configured + * @param[in] uint8_t mode , input/output mode of the gpio pin to configure + * 0 - input mode + * 1 - output mode + * @param[in] uint8_t value, default value to be driven if gpio is + * configured in output mode 0 - low 1 - high + * @param[out] none + * @return none + * @description This API is used to configure host gpio pin in output mode. + */ +void rsi_hal_config_gpio(uint8_t gpio_number, uint8_t mode, uint8_t value) +{ + + //! Initialise the gpio pins in input/output mode + + //! Drive a default value on gpio if gpio is configured in output mode + + gpio_flags_t pin_flags; + if (mode) { + pin_flags = value ? GPIO_OUTPUT_ACTIVE : GPIO_OUTPUT_INACTIVE; + } else { + pin_flags = GPIO_INPUT; + } + const struct gpio_dt_spec *gpio = get_gpio(gpio_number); + gpio_pin_configure(gpio->port, gpio->pin, pin_flags); + + return; +} + +/*===========================================================*/ +/** + * @fn void rsi_hal_set_gpio(uint8_t gpio_number) + * @brief Makes/drives the gpio value high + * @param[in] uint8_t gpio_number, gpio pin number + * @param[out] none + * @return none + * @description This API is used to drives or makes the host gpio value high. + */ +void rsi_hal_set_gpio(uint8_t gpio_number) +{ + + //! drives a high value on GPIO + + const struct gpio_dt_spec *gpio = get_gpio(gpio_number); + gpio_pin_set_raw(gpio->port, gpio->pin, 1); + + return; +} + +/*===========================================================*/ +/** + * @fn uint8_t rsi_hal_get_gpio(void) + * @brief get the gpio pin value + * @param[in] uint8_t gpio_number, gpio pin number + * @param[out] none + * @return gpio pin value + * @description This API is used to configure get the gpio pin value. + */ +uint8_t rsi_hal_get_gpio(uint8_t gpio_number) +{ + uint8_t gpio_value = 0; + + //! Get the gpio value + const struct gpio_dt_spec *gpio = get_gpio(gpio_number); + gpio_value = gpio_pin_get_raw(gpio->port, gpio->pin); + + return gpio_value; +} + +/*===========================================================*/ +/** + * @fn void rsi_hal_set_gpio(uint8_t gpio_number) + * @brief Makes/drives the gpio value to low + * @param[in] uint8_t gpio_number, gpio pin number + * @param[out] none + * @return none + * @description This API is used to drives or makes the host gpio value low. + */ +void rsi_hal_clear_gpio(uint8_t gpio_number) +{ + + //! drives a low value on GPIO + + const struct gpio_dt_spec *gpio = get_gpio(gpio_number); + gpio_pin_set_raw(gpio->port, gpio->pin, 0); + + return; +} diff --git a/wiseconnect/zephyr/rsi_hal_mcu_platform_init.c b/wiseconnect/zephyr/rsi_hal_mcu_platform_init.c new file mode 100644 index 00000000..13130660 --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_platform_init.c @@ -0,0 +1,72 @@ +/******************************************************************************* +* @file rsi_hal_mcu_platform_init.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ + +#include "rsi_driver.h" + + +/*==============================================*/ +/** + * @fn void rsi_hal_board_init() + * @brief This function Initializes the platform + * @param[in] none + * @param[out] none + * @return none + * @section description + * This function initializes the platform + * + */ +void rsi_hal_board_init(void) +{ + //! Initializes the platform +} + + +/*==============================================*/ +/** + * @fn void rsi_switch_to_high_clk_freq() + * @brief This function intializes SPI to high clock + * @param[in] none + * @param[out] none + * @return none + * @section description + * This function intializes SPI to high clock + * + * + */ +void rsi_switch_to_high_clk_freq(void) +{ + //! Initializes the high clock +} + + + + diff --git a/wiseconnect/zephyr/rsi_hal_mcu_random.c b/wiseconnect/zephyr/rsi_hal_mcu_random.c new file mode 100644 index 00000000..b4b02478 --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_random.c @@ -0,0 +1,54 @@ +/******************************************************************************* +* @file rsi_hal_mcu_random.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ +#include "rsi_driver.h" +#include + +/** + * Global Variables + */ + + +/*==================================================================*/ +/** + * @fn uint32_t rsi_get_random_number(void) + * @param[in] None + * @return Random number + * @description This API is used to return random number. + */ +uint32_t rsi_get_random_number(void) +{ + + //! Call the API which generates random number + + return sys_rand32_get(); +} + diff --git a/wiseconnect/zephyr/rsi_hal_mcu_spi.c b/wiseconnect/zephyr/rsi_hal_mcu_spi.c new file mode 100644 index 00000000..c0db1ce8 --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_spi.c @@ -0,0 +1,122 @@ +/******************************************************************************* +* @file rsi_hal_mcu_spi.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ + +#include "rsi_driver.h" +#include +#include +#include +#include + +#define DT_DRV_COMPAT silabs_rs9116w + +struct rs9116w_config { + struct spi_dt_spec spi; +}; + +static struct rs9116w_config rs9116w_conf = { + .spi = SPI_DT_SPEC_INST_GET(0, SPI_OP_MODE_MASTER | SPI_WORD_SET(8), 2) +}; + +/** + * Global Variables + */ + + +/*==================================================================*/ +/** + * @fn int16_t cs_enable() + * @param[out] None + * @return 0, 0=success + * @section description + * This API is used to enable the spi chip select pin in SPI interface. + */ +void cs_enable(void) +{ + //! enables the spi chip select pin on SPI interface + +} + +/*==================================================================*/ +/** + * @fn int16_t cs_disable() + * @param[out] None + * @return 0, 0=success + * @section description + * This API is used to disable the spi chip select pin in SPI interface. + */ +void cs_disable(void) +{ + + //! disables the spi chip select pin on SPI interface + +} +/*==================================================================*/ +/** + * @fn int16_t rsi_spi_transfer(uint8_t *ptrBuf,uint16_t bufLen,uint8_t *valBuf,uint8_t mode) + * @param[in] uint8_t *tx_buff, pointer to the buffer with the data to be transfered + * @param[in] uint8_t *rx_buff, pointer to the buffer to store the data received + * @param[in] uint16_t transfer_length, Number of bytes to send and receive + * @param[in] uint8_t mode, To indicate mode 8 BIT/32 BIT mode transfers. + * @param[out] None + * @return 0, 0=success + * @section description + * This API is used to tranfer/receive data to the Wi-Fi module through the SPI interface. + */ +int16_t rsi_spi_transfer(uint8_t *tx_buff, uint8_t *rx_buff, uint16_t transfer_length,uint8_t mode) +{ + #ifdef RSI_SPI_INTERFACE + if(!spi_is_ready_dt(&rs9116w_conf.spi)) { + printk("spi bus %s not ready", rs9116w_conf.spi.bus->name); + return -ENODEV; + } + + struct spi_buf rx_buf, tx_buf; + rx_buf.buf = rx_buff; + rx_buf.len = transfer_length; + tx_buf.buf = tx_buff; + tx_buf.len = transfer_length; + struct spi_buf_set rx, tx; + rx.buffers = &rx_buf; + rx.count = 1; + tx.buffers = &tx_buf; + tx.count = 1; + + int rc = spi_transceive_dt(&rs9116w_conf.spi, (const struct spi_buf_set *)&tx, (const struct spi_buf_set *)&rx); + + return rc; + + #else + + return 0; + + #endif +} diff --git a/wiseconnect/zephyr/rsi_hal_mcu_timer.c b/wiseconnect/zephyr/rsi_hal_mcu_timer.c new file mode 100644 index 00000000..6a394282 --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_timer.c @@ -0,0 +1,185 @@ +/******************************************************************************* +* @file rsi_hal_mcu_timer.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ + +#include "rsi_driver.h" +#include + +static volatile uint32_t _dwTickCount ; //systick cout variable + +/*===================================================*/ +/** + * @fn int32_t rsi_timer_start(uint8_t timer_no, uint8_t mode,uint8_t type,uint32_t duration,void (* rsi_timer_expiry_handler)()) + * @brief Starts and configures timer + * @param[in] timer_node, timer node to be configured. + * @param[in] mode , mode of the timer + * 0 - Micro seconds mode + * 1 - Milli seconds mode + * @param[in] type, type of the timer + * 0 - single shot type + * 1 - periodic type + * @param[in] duration, timer duration + * @param[in] rsi_timer_expiry_handler() ,call back function to handle timer interrupt + * @param[out] none + * @return 0 - success + * !0 - Failure + * @description This HAL API should contain the code to initialize the timer and start the timer + * + */ + +int32_t rsi_timer_start(uint8_t timer_node, uint8_t mode, uint8_t type, uint32_t duration, void (* rsi_timer_expiry_handler)(void)) +{ + + //! Initialise the timer + + + //! register the call back + + + //! Start timer + + return 0; +} + + +/*===================================================*/ +/** + * @fn int32_t rsi_timer_stop(uint8_t timer_no) + * @brief Stops timer + * @param[in] timer_node, timer node to stop + * @param[out] none + * @return 0 - success + * !0 - Failure + * @description This HAL API should contain the code to stop the timer + * + */ + +int32_t rsi_timer_stop(uint8_t timer_node) +{ + + //! Stop the timer + + return 0; + + +} + + + + +/*===================================================*/ +/** + * @fn uint32_t rsi_timer_read(uint8_t timer_node) + * @brief read timer + * @param[in] timer_node, timer node to read + * @param[out] none + * @return timer value + * @description This HAL API should contain API to read the timer + * + */ + +uint32_t rsi_timer_read(uint8_t timer_node) +{ + + volatile uint32_t timer_val = 0; + + //! read the timer and return timer value + + return timer_val; + + +} + + + + + + +/*===================================================*/ +/** + * @fn void rsi_delay_us(uint32_t delay) + * @brief create delay in micro seconds + * @param[in] delay_us, timer delay in micro seconds + * @param[out] none + * @return none + * @description This HAL API should contain the code to create delay in micro seconds + * + */ +void rsi_delay_us(uint32_t delay_us) +{ + + //! call the API for delay in micro seconds + + k_usleep(delay_us); + + return; + +} + +/*===================================================*/ +/** + * @fn void rsi_delay_ms(uint32_t delay) + * @brief create delay in milli seconds + * @param[in] delay, timer delay in milli seconds + * @param[out] none + * @return none + * @description This HAL API should contain the code to create delay in milli seconds + */ +void rsi_delay_ms(uint32_t delay_ms) +{ + k_msleep(delay_ms); + + return; +} + + +/*===================================================*/ +/** + * @fn uint32_t rsi_hal_gettickcount() + * @brief provides a tick value in milliseconds + * @return tick value + * @description This HAL API should contain the code to read the timer tick count value in milliseconds + * + */ + +uint32_t rsi_hal_gettickcount(void) +{ + return k_uptime_get_32(); +} + + + + + + + + + diff --git a/wiseconnect/zephyr/rsi_hal_mcu_uart.c b/wiseconnect/zephyr/rsi_hal_mcu_uart.c new file mode 100644 index 00000000..2b66e513 --- /dev/null +++ b/wiseconnect/zephyr/rsi_hal_mcu_uart.c @@ -0,0 +1,67 @@ +/******************************************************************************* +* @file rsi_hal_mcu_uart.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2022 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * Includes + */ +#include "rsi_driver.h" + +/** + * Global Variables + */ + +/*==================================================================*/ +/** + * @fn int16_t rsi_uart_send(uint8_t *ptrBuf,uint16_t bufLen) + * @param[in] uint8 *ptrBuf, pointer to the buffer with the data to be sent/received + * @param[in] uint16 bufLen, number of bytes to send + * @param[out] None + * @return 0, 0=success + * @section description + * This API is used to send data to the Wi-Fi module through the UART interface. + */ +int16_t rsi_uart_send(uint8_t *ptrBuf, uint16_t bufLen) +{ + return 0; +} + + +/*==================================================================*/ +/** + * @fn int16_t rsi_uart_recv(uint8_t *ptrBuf,uint16_t bufLen) + * @param[in] uint8_t *ptrBuf, pointer to the buffer with the data to be sent/received + * @param[in] uint16_t bufLen, number of bytes to send + * @param[out] None + * @return 0, 0=success + * @description + * This API is used to receive data from Wi-Fi module through the UART interface. + */ +int16_t rsi_uart_recv(uint8_t *ptrBuf, uint16_t bufLen) +{ + return 0; +} diff --git a/wiseconnect/zephyr/rsi_os_wrapper.c b/wiseconnect/zephyr/rsi_os_wrapper.c new file mode 100644 index 00000000..2378e32d --- /dev/null +++ b/wiseconnect/zephyr/rsi_os_wrapper.c @@ -0,0 +1,715 @@ +/******************************************************************************* +* @file rsi_os_wrapper.c +* @brief +******************************************************************************* +* # License +* Copyright 2020 Silicon Laboratories Inc. http://www.silabs.com/ +******************************************************************************* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +/* + * Copyright (c) 2021 T-Mobile USA, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef RSI_ZEPHYR +#define RSI_ZEPHYR + +#include +#ifdef RSI_WITH_OS +#include +#include +#include "rsi_wlan_non_rom.h" + +K_SEM_DEFINE(sem_mgmt, 1, 1); +K_SEM_DEFINE(mut_mgmt, 1, 1); + +static struct k_mutex muts[32]; +uint32_t mut_map = 0; +static struct k_sem sems[64]; +uint64_t sem_map = 0; + +extern rsi_socket_info_non_rom_t *rsi_socket_pool_non_rom; + + +/*==============================================*/ +/** + * @fn rsi_reg_flags_t rsi_critical_section_entry() + * @brief This API's to enter critical section + * @param[in] none, + * @return flags, interrupt status before entering critical section + * + * + * @section description + * This API disable interrupt to enter crtical section. + * + * + */ +rsi_reg_flags_t rsi_critical_section_entry() +{ + //! hold interrupt status before entering critical section + //! disable interrupts + rsi_reg_flags_t xflags; + //! hold interrupt status before entering critical section + //! disable interrupts + xflags = 0; + + //taskENTER_CRITICAL(); + xflags = irq_lock(); + + //! return stored interrupt status + return (xflags); +} + + + +/*==============================================*/ +/** + * @fn rsi_critical_section_exit(rsi_reg_flags_t xflags) + * @brief This API to exit critical section + * @param[in] xflags, interrupt status to restore interrupt on exit from critical section + * @return None + * + * + * @section description + * This API to exit/restore critical section. + * + * + */ + +void rsi_critical_section_exit(rsi_reg_flags_t xflags) +{ + //! restore interrupts while exiting critical section + irq_unlock(xflags); + +} + + + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex) + * @brief This API is creates the mutex + * @param[in] mutex handle pointer + * @param[out] Mutex created + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which creates the mutex + * + * + */ + +rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex) +{ + struct k_mutex *kmutex; + if (mutex == NULL){ + return RSI_ERROR_IN_OS_OPERATION; + } + *mutex = 0; + k_sem_take(&mut_mgmt, K_FOREVER); + for (int i = 0; i < 32; i++){ + if (!(mut_map & BIT(i))){ + mut_map |= BIT(i); + *mutex = i + 1; + kmutex = &muts[i]; + k_mutex_init(kmutex); + break; + } + } + k_sem_give(&mut_mgmt); + if (*mutex == 0) { + return RSI_ERROR_IN_OS_OPERATION; + } + + return RSI_ERROR_NONE; +} + + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex) + * @brief This API is takes the mutex + * @param[in] mutex handle pointer + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which takes the mutex + * + * + */ +rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex) +{ + if (mutex == NULL || *mutex < 1 || *mutex > ARRAY_SIZE(muts) || !(mut_map & BIT((*mutex - 1)))){ + return RSI_ERROR_INVALID_PARAM; + } + + struct k_mutex *kmutex = &muts[*mutex - 1]; + + if(k_mutex_lock(kmutex, K_FOREVER) == 0) + { + return RSI_ERROR_NONE; + } + + return RSI_ERROR_IN_OS_OPERATION; +} + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex) + * @brief This API is gives the mutex + * @param[in] mutex handle pointer + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which gives the mutex + * + */ +rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex) +{ + if (mutex == NULL || *mutex < 1 || *mutex > ARRAY_SIZE(muts) || !(mut_map & BIT((*mutex - 1)))){ + return RSI_ERROR_INVALID_PARAM; + } + + struct k_mutex *kmutex = &muts[*mutex - 1]; + + if (k_mutex_unlock(kmutex) == 0) + { + return RSI_ERROR_NONE; + } + + return RSI_ERROR_IN_OS_OPERATION; +} + + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex) + * @brief This API is destroyes the mutex + * @param[in] mutex handle pointer + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which destroy/delete the mutex + * + */ +rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex) +{ + if (mutex == NULL || *mutex < 1 || *mutex > ARRAY_SIZE(muts)){ + return RSI_ERROR_INVALID_PARAM; + } + + k_sem_take(&mut_mgmt, K_FOREVER); + mut_map &= ~BIT((*mutex - 1)); + k_sem_give(&mut_mgmt); + + return RSI_ERROR_NONE; +} + + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore,uint32_t count) + * @brief This API is creates the semaphore instance + * @param[in] Semaphore handle pointer + * @param[in] resource count + * @param[out] Semaphore handler created + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which creates the semaphore + * + */ +rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore,uint32_t count) +{ + struct k_sem *ksem; + if (semaphore == NULL){ + return RSI_ERROR_INVALID_PARAM; + } + *semaphore = 0; + k_sem_take(&sem_mgmt, K_FOREVER); + for (int i = 0; i < 64; i++){ + if (!(sem_map & BIT(i))){ + sem_map |= BIT(i); + *semaphore = i + 1; + ksem = &sems[i]; + k_sem_init(ksem, count, 1); + break; + } + } + k_sem_give(&sem_mgmt); + if (*semaphore == 0) { + return RSI_ERROR_IN_OS_OPERATION; + } + + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore) + * @brief This API is destroys the semaphore instance + * @param[in] Semaphore handle pointer + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which destroys the semaphore + * + */ +rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore) +{ + if (semaphore == NULL || *semaphore < 1 || *semaphore > ARRAY_SIZE(sems)){ + return RSI_ERROR_INVALID_PARAM; + } + + if (!(sem_map & BIT((*semaphore - 1)))) { + return RSI_ERROR_IN_OS_OPERATION; + } + + sem_map &= ~BIT((*semaphore - 1)); + return RSI_ERROR_NONE; +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore) + * @brief This API should check whether semaphore is created or not, It + * destroys the semaphore instance,if its created, otherwise should return success + * @param[in] Semaphore handle pointer + * @return 0 = success + * <0 = failure + * @section description + * This function is OS Abstraction layer API which destroys the semaphore + * + */ + +rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore) +{ + if (semaphore == NULL){ + return RSI_ERROR_INVALID_PARAM; + } + if (*semaphore < 1 || *semaphore > ARRAY_SIZE(sems) || !(sem_map & BIT((*semaphore - 1)))) { + return RSI_ERR_NONE; + } + + sem_map &= ~BIT((*semaphore - 1)); + + return RSI_ERROR_NONE; +} + + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms ) + * @brief This API is used by wireless library to acquire or wait for semaphore. + * @param[in] Semaphore handle pointer + * @param[in] Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait + till acquire semaphore. + * @return 0 = Success + * <0 = failure + * @section description + * This API is used by Wireless Library to acquire or wait for semaphore. + * + */ + +rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms ) +{ + if (semaphore == NULL || *semaphore < 1 || *semaphore > ARRAY_SIZE(sems)){ + return RSI_ERROR_INVALID_PARAM; + } + + struct k_sem *ksem = &sems[*semaphore - 1]; + k_timeout_t timeout; + + if(!timeout_ms) { + timeout = K_FOREVER; + } else { + timeout = K_MSEC(timeout_ms); + } + + if(k_sem_take(ksem, timeout) == 0) { + return RSI_ERROR_NONE; + } + + return RSI_ERROR_IN_OS_OPERATION; +} + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore) + * @brief This API is used by wireless library to release semaphore, which was acquired. + * @param[in] Semaphore handle pointer + * @param[in] Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait + till acquire semaphore. + * @return 0 = Success + * <0 = failure + * @section description + * This API is used by Wireless Library to acquire or wait for semaphore. + * + */ + + +rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore) +{ + if (semaphore == NULL || *semaphore < 1 || *semaphore > ARRAY_SIZE(sems)){ + return RSI_ERROR_INVALID_PARAM; + } + + struct k_sem *ksem = &sems[*semaphore - 1]; + k_sem_give(ksem); + return RSI_ERR_NONE; +} + +/*====================================================*/ +/** + * @fn rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore) + * @brief This API is used by wireless library to release semaphore, which was acquired. + * @param[in] Semaphore handle pointer + * @return + * 0 = Success + * <0 = failure + * @section description + * This API is used by Wireless Library to acquire or wait for semaphore. + */ + +rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore) +{ + return rsi_semaphore_post(semaphore); +} + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore) + * @brief This API is used by wireless library Wireless Library to the semaphore to initial state + * @param[in] Semaphore handle pointer + * @return 0 = Success + * <0 = failure + * @section description + * This API is used by Wireless Library to reset the semaphore. + * + */ +rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore) +{ + if (semaphore == NULL || *semaphore < 1 || *semaphore > ARRAY_SIZE(sems)){ + return RSI_ERROR_INVALID_PARAM; + } + + struct k_sem *ksem = &sems[*semaphore - 1]; + k_sem_reset(ksem); + return RSI_ERROR_NONE; +} + + +/*==============================================*/ +/** + * @fn rsi_error_t rsi_task_create( rsi_task_function_t task_function,uint8_t *task_name, + uint32_t stack_size, void *parameters, + uint32_t task_priority,rsi_task_handle_t *task_handle) + * @brief This API is used to create different tasks in OS supported platforms + * @param[in] Pointer to function to be executed by created thread. Prototype of the function + * @param[in] Name of the created task + * @param[in] Stack size given to the created task + * @param[in] Pointer to the parameters to be passed to task function + * @param[in] task priority + * @param[in] task handle/instance created + * @return 0 = Success + * <0 = Failure + * @section description + * This API is used by Wireless Library to create platform specific OS + * task/thread. + * + * + */ + + +rsi_error_t rsi_task_create( rsi_task_function_t task_function,uint8_t *task_name, + uint32_t stack_size, void *parameters, + uint32_t task_priority, rsi_task_handle_t *task_handle) +{ + //Not needed? + return RSI_ERROR_IN_OS_OPERATION; +} + + +/*==============================================*/ +/** + * @fn void rsi_task_destroy(rsi_task_handle_t *task_handle) + * @brief This function deletes the task created + * @param[in] Task handle/instance to be deleted + * @return None + * @section description + * This API is used to delete/destroy the task created + * + */ + + +void rsi_task_destroy(rsi_task_handle_t *task_handle) +{ + //Not needed? + return; +} + + + +/*==============================================*/ +/** + * @fn void rsi_os_task_delay(uint32_t timeout_ms) + * @brief This function induces required delay in milli seconds + * @param[in] Expected delay in milli seconds + * @return None + * @section description + * This API is used to induce OS delay + * + */ +void rsi_os_task_delay(uint32_t timeout_ms) +{ + //Not needed? + k_msleep(timeout_ms); +} + + + + +/*==============================================*/ +/** + * @fn void rsi_start_os_scheduler() + * @brief This function schedules the tasks created + * @param[in] None + * @return None + * @section description + * This API Schedules the tasks created + * + */ +void rsi_start_os_scheduler() +{ + //Not needed? + //vTaskStartScheduler(); +} + +/*==============================================*/ +/** + * @fn int32_t rsi_get_error(void) + * @brief This sets the os error . + * @param[in] Error + * @param[out] None + * @return None + * + * @section description + * This sets the os error. + * + */ +void rsi_set_os_errno(int32_t error) +{ + int z_error; + switch (error) { + case RSI_ERROR_ECONNREFUSED: + z_error = ECONNREFUSED; + break; + case RSI_ERROR_ECONNABORTED: + z_error = ECONNABORTED; + break; + case RSI_ERROR_ETIMEDOUT: + z_error = ETIMEDOUT; + break; + case RSI_ERROR_EACCES: + z_error = EACCES; + break; + case RSI_ERROR_EPERM: + z_error = EPERM; + break; + case RSI_ERROR_EMSGSIZE: + z_error = EMSGSIZE; + break; + case RSI_ERROR_EBADF: + z_error = EBADF; + break; + case RSI_ERROR_EAGAIN: + z_error = EAGAIN; + break; + case RSI_ERROR_EISCONN: + z_error = EISCONN; + break; + case RSI_ERROR_ENOTCONN: + z_error = ENOTCONN; + break; + case RSI_ERROR_EADDRINUSE: + z_error = EADDRINUSE; + break; + case RSI_ERROR_ENOTSOCK: + z_error = ENOTSOCK; + break; + case RSI_ERROR_ENOMEM: + z_error = ENOMEM; + break; + case RSI_ERROR_EINVAL: + z_error = EINVAL; + break; + default: + z_error = error; + break; + } + errno = z_error; +} + +/*==============================================*/ +/** + * @fn int32_t rsi_get_error(void) + * @brief Returns wlan status + * @param[in] None + * @param[out] None + * @return wlan status + * + * @section description + * This function returns wlan status + * + */ +int32_t rsi_get_error(int32_t sockID) +{ + if(rsi_socket_pool_non_rom[sockID].socket_status == 0xFF87 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB38) + { + return RSI_ERROR_ECONNREFUSED; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0x00D2) + { + return RSI_ERROR_ECONNABORTED; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xFF6C + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF6A + || rsi_socket_pool_non_rom[sockID].socket_status == RSI_ERROR_RESPONSE_TIMEOUT + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBBD6) + { + return RSI_ERROR_ETIMEDOUT; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0x0021 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF82 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF74 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB27 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFF80 + || rsi_socket_pool_non_rom[sockID].socket_status == 0x00D1) + { + return RSI_ERROR_EACCES; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0x00D3 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xFFFE) + { + return RSI_ERROR_EPERM; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xFF7E + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBBED + || rsi_socket_pool_non_rom[sockID].socket_status == 0x003E + || rsi_socket_pool_non_rom[sockID].socket_status == 0x0030 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB3E) + { + return RSI_ERROR_EMSGSIZE; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xFF86) + { + return RSI_ERROR_EBADF; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0x0015) + { + return RSI_ERROR_EAGAIN; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xBB22 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB42) + { + return RSI_ERROR_EISCONN; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xFFFF + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB50) + { + return RSI_ERROR_ENOTCONN; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xBB33 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB23 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB45 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB46 + || rsi_socket_pool_non_rom[sockID].socket_status == 0xBB50) + { + return RSI_ERROR_EADDRINUSE; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == 0xBB36) + { + return RSI_ERROR_ENOTSOCK; + } + else if(rsi_socket_pool_non_rom[sockID].socket_status == RSI_ERROR_PKT_ALLOCATION_FAILURE) + { + return RSI_ERROR_ENOMEM; + } + return RSI_ERROR_EINVAL; +} + + + +/*==============================================*/ +/**n + * @fn void *rsi_malloc (uint32_t size) + * @brief Returns allocated memory starting address + * @param[in] required bytes in size + * @param[out] None + * @return Returns starting address of allocated memory + * + * @section description + * This function allocates memory from the buffer which is maintained by freertos + * + */ + +void *rsi_malloc (uint32_t size) +{ + if(size == 0) + { + return NULL; + } + else + { + return k_malloc(size); + } +} + +/*==============================================*/ +/** + * @fn void rsi_free (void *ptr) + * @brief frees the memory pointed by 'ptr' + * @param[in] starting address of the memory to be freed + * @param[out] None + * @return None + * + * @section description + * This function frees the memory pointed by 'ptr' + * + */ +void rsi_free (void *ptr) +{ + if(ptr == NULL) + { + //! do nothing + } + else + { + k_free(ptr); + } +} +#endif +#endif diff --git a/zephyr/Kconfig b/zephyr/Kconfig index d6a861fd..7b680cbf 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -1,3 +1,5 @@ # This file is required by Zephyr build system to properly y-select # CONFIG_TAINT_* symbols when blobs are downloaded with the `west blobs` # command. + +source "$(ZEPHYR_SILABS_MODULE_DIR)/wiseconnect/Kconfig"