From 0e9ec10bcf7c9b6a5433174fb8a07d8578201b7c Mon Sep 17 00:00:00 2001 From: Seth Rickard Date: Wed, 21 Apr 2021 13:55:43 -0500 Subject: [PATCH] [cc13x2x7_26x2x7] Fix BLE Provisioning issues for TE#2 (#6152) * Fix BLE Provisioning issues for TE#2 * Adds default SLAAC configuration to enable final step of BLE provisioning flow with GUA assignment. * Removes unused OpenThread configuration in platform_includes * Addresses runtime issues with BLE provisioning Co-Authored-by: Alexander D'Abreu * Restyled by gn * Restyled by prettier-markdown * fix ccs programming markdown formatting Code text was not properly quoted. * Restyled by prettier-markdown Co-authored-by: Alexander D'Abreu Co-authored-by: Restyled.io --- examples/lock-app/cc13x2x7_26x2x7/README.md | 54 +++- .../cc13x2x7_26x2x7/doc/programming-ccs.md | 130 ++++----- .../lock-app/cc13x2x7_26x2x7/main/AppTask.cpp | 10 +- .../main/include/OpenThreadConfig.h | 2 + .../project_include/OpenThreadConfig.h | 181 ------------ src/platform/cc13x2_26x2/BLEManagerImpl.cpp | 274 +++++++++++------- src/platform/cc13x2_26x2/BLEManagerImpl.h | 16 +- .../cc13x2_26x2/CHIPDevicePlatformConfig.h | 10 +- src/platform/cc13x2_26x2/chipOBleProfile.c | 4 +- 9 files changed, 308 insertions(+), 373 deletions(-) delete mode 100644 examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h diff --git a/examples/lock-app/cc13x2x7_26x2x7/README.md b/examples/lock-app/cc13x2x7_26x2x7/README.md index 64e6b1b9577240..8ec2c4402d78f3 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/README.md +++ b/examples/lock-app/cc13x2x7_26x2x7/README.md @@ -62,7 +62,8 @@ advertisements. ### Preparation Some initial setup is necessary for preparing the build environment. This -section will need to be done when migrating to new versions of the SDK. +section will need to be done when migrating to new versions of the SDK. This +guide assumes that the environment is linux based, and recommends Ubuntu 20.04. - An engineering SDK from TI is required. Please request access for it [here][ti_cc13x2_26x2_r7_chip_request]. @@ -74,8 +75,8 @@ section will need to be done when migrating to new versions of the SDK. packaged with the TI SDK. Check the following section for a list of changes needed. -- Download and install [SysConfig][sysconfig] - ([sysconfig-1.5.0_1397][sysconfig-1.5.0_1397]) +- Download and install [SysConfig][sysconfig] ([recommended + version][sysconfig_recommended]) - This may have already been installed with your SimpleLink SDK install. @@ -95,11 +96,43 @@ section will need to be done when migrating to new versions of the SDK. - You will have to ensure that the default version of Python 3 is Python 3.8. + - Check python3 version: + + ``` + $ python3 --version + Python 3.8.0 + ``` + + - If it is not Python 3.8: + + ``` + $ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 + ``` + + - This may affect your environment in other ways if there was a + specific dependency on the prior python3 version (e.g. apt). + After completing the build process for this example, you can + revert the python3 version, for instance: + + ``` + $ sudo update-alternatives --config python3 + There are 2 choices for the alternative python3 (providing /usr/bin/python3). + + Selection Path Priority Status + ------------------------------------------------------------- + 0 /usr/bin/python3.8 1 auto mode + 1 /usr/bin/python3.6 1 manual mode + * 2 /usr/bin/python3.8 1 manual mode + + Press to keep the current choice[*], or type selection number: 1 + update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in manual mode + ``` + - Run the bootstrap script to setup the build environment. ``` $ cd ~/connectedhomeip - $ source ./script/bootstrap.sh + $ source ./scripts/bootstrap.sh ``` @@ -112,7 +145,7 @@ Ninja to build the executable. ``` $ cd ~/connectedhomeip - $ source ./script/activate.sh + $ source ./scripts/activate.sh ``` @@ -120,11 +153,12 @@ Ninja to build the executable. TI SimpleLink SDK and Sysconfig are located in a `ti` folder in the user's home directory, and you must provide the absolute path to them. For example `/home/username/ti/simplelink_cc13x2_26x2_sdk_4_40_05_02_eng` and - `/home/username/ti/sysconfig_1.6.0`. On Windows the default directory is - `C:\ti` + `/home/username/ti/sysconfig_1.7.0`. On Windows the default directory is + `C:\ti`. Take note of this install path, as it will be used in the next + step. ``` - $ cd ~/connectedhomeip/examples/lock-app/cc13x2_26x2 + $ cd ~/connectedhomeip/examples/lock-app/cc13x2x7_26x2x7 $ export TI_SIMPLELINK_SDK_ROOT= $ export TI_SYSCONFIG_ROOT= $ gn gen out/debug --args="ti_simplelink_sdk_root=\"${TI_SIMPLELINK_SDK_ROOT}\" ti_sysconfig_root=\"${TI_SYSCONFIG_ROOT}\"" @@ -223,8 +257,8 @@ Additionally, we welcome any feedback. [simplelink_sdk_4.30.00.54]: https://www.ti.com/tool/download/SIMPLELINK-CC13X2-26X2-SDK/4.30.00.54 [sysconfig]: https://www.ti.com/tool/SYSCONFIG -[sysconfig-1.5.0_1397]: - http://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.5.0_1397-setup.run +[sysconfig_recommended]: + https://software-dl.ti.com/ccs/esd/sysconfig/sysconfig-1.7.0_1746-setup.run [ti_thread_dnd]: https://www.ti.com/wireless-connectivity/thread/design-development.html [ti_cc13x2_26x2_r7_chip_request]: https://ti.com/chip_sdk diff --git a/examples/lock-app/cc13x2x7_26x2x7/doc/programming-ccs.md b/examples/lock-app/cc13x2x7_26x2x7/doc/programming-ccs.md index f56fc6057011c9..a6cc18964f013b 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/doc/programming-ccs.md +++ b/examples/lock-app/cc13x2x7_26x2x7/doc/programming-ccs.md @@ -15,101 +15,101 @@ Copyright (c) 2008-2019 Texas Instruments Incorporated. All rights reserved. Scanning USB buses for supported XDS110 devices... - ``` -<<<< Device 0 >>>> + <<<< Device 0 >>>> + + VID: 0x0451 PID: 0xbef3 Device Name: XDS110 Embed with CMSIS-DAP Version: + 3.0.0.13 Manufacturer: Texas Instruments Serial Num: L4100652 Mode: Runtime + Configuration: Standard -VID: 0x0451 PID: 0xbef3 Device Name: XDS110 Embed with CMSIS-DAP Version: -3.0.0.13 Manufacturer: Texas Instruments Serial Num: L4100652 Mode: Runtime -Configuration: Standard + Found 1 device. -Found 1 device. + ``` -``` -In this example, my LaunchPad's XDS110 has a serial number of `L4100652`. + In this example, my LaunchPad's XDS110 has a serial number of `L4100652`. -- Start a new Code Composer Studio Workspace. This can be named anything you -would like. But it is recommended that you use a blank workspace. +- Start a new Code Composer Studio Workspace. This can be named anything you + would like. But it is recommended that you use a blank workspace. -![CCS step 1](images/ccs-1.jpg) + ![CCS step 1](images/ccs-1.jpg) -- Create a new Target Configuration File by selecting `File` >> `New` >> -`Target Configuration File`. This file can also be exported from UniFlash -with the `download ccxml` function. +- Create a new Target Configuration File by selecting `File` >> `New` >> + `Target Configuration File`. This file can also be exported from UniFlash + with the `download ccxml` function. -![CCS step 2](images/ccs-2.jpg) + ![CCS step 2](images/ccs-2.jpg) -- Name the new ccxml file a useful name. Here I use the XDS110 serial number -from before. Leave the Location as the shared location and click `Finish` to -create the file. +- Name the new ccxml file a useful name. Here I use the XDS110 serial number + from before. Leave the Location as the shared location and click `Finish` to + create the file. -![CCS step 3](images/ccs-3.jpg) + ![CCS step 3](images/ccs-3.jpg) -- In the new ccxml, select the `Connection` and the `Board or Device`. This may -be different for your setup, but all LaunchPads will use the `Texas -Instruments XDS110 USB Debug Probe` for the target connection. And the and a -`CC1352R1F3` is mounted on the `CC1352R1_LAUNCHXL` LaunchPads. Builds for -other LaunchPads should use the corresponding SoC name. +- In the new ccxml, select the `Connection` and the `Board or Device`. This + may be different for your setup, but all LaunchPads will use the + `Texas Instruments XDS110 USB Debug Probe` for the target connection. And + the and a `CC1352R1F3` is mounted on the `CC1352R1_LAUNCHXL` LaunchPads. + Builds for other LaunchPads should use the corresponding SoC name. -![CCS step 4](images/ccs-4.jpg) + ![CCS step 4](images/ccs-4.jpg) -- Now set the XDS110 serial number in the advanced tab of the ccxml. First -select the `Advanced` tab at the bottom of the window. Then select the Debug -Probe in the connection tree. Then select `Select by serial number` in the -`Debug Probe Selection`. Then enter the serial number from `xdsdfu` earlier -in the `Enter the serial number` text field. Finally click `Save` to save -your ccxml. +- Now set the XDS110 serial number in the advanced tab of the ccxml. First + select the `Advanced` tab at the bottom of the window. Then select the Debug + Probe in the connection tree. Then select `Select by serial number` in the + `Debug Probe Selection`. Then enter the serial number from `xdsdfu` earlier + in the `Enter the serial number` text field. Finally click `Save` to save + your ccxml. -![CCS step 5](images/ccs-5.jpg) + ![CCS step 5](images/ccs-5.jpg) -- Clicking `Test Connection` with the LaunchPad connected will cause a JTAG -Integrity scan with the Debug Probe. This is a nice way to check that your -ccxml is setup correctly. +- Clicking `Test Connection` with the LaunchPad connected will cause a JTAG + Integrity scan with the Debug Probe. This is a nice way to check that your + ccxml is setup correctly. -![CCS step 6](images/ccs-6.jpg) + ![CCS step 6](images/ccs-6.jpg) -- Now open the Debug Configurations dialog to setup a new debug configuration. -Select `Run` >> `Debug Configurations...`. +- Now open the Debug Configurations dialog to setup a new debug configuration. + Select `Run` >> `Debug Configurations...`. -![CCS step 7](images/ccs-7.jpg) + ![CCS step 7](images/ccs-7.jpg) -- Create a new launch configuration from the default CCS launch configuration. -Select `Code Composer Studio - Device Debugging` and then create a new launch -configuration with the `New launch configuration` button. +- Create a new launch configuration from the default CCS launch configuration. + Select `Code Composer Studio - Device Debugging` and then create a new + launch configuration with the `New launch configuration` button. -![CCS step 8](images/ccs-8.jpg) + ![CCS step 8](images/ccs-8.jpg) -- Name your new configuration. Update the `Target Configuration` field with the -ccxml you created earlier. Click `Apply` to save the launch configuration. +- Name your new configuration. Update the `Target Configuration` field with + the ccxml you created earlier. Click `Apply` to save the launch + configuration. -Once the launch configuration is created you do not need to re-create it -every time. The Debug session can be started with the `Debug` button in the -`Debug Configurations` dialog, or by selecting `Run` >> `Debug History` >> -``. + Once the launch configuration is created you do not need to re-create it + every time. The Debug session can be started with the `Debug` button in the + `Debug Configurations` dialog, or by selecting `Run` >> `Debug History` >> + ``. -![CCS step 9](images/ccs-9.jpg) + ![CCS step 9](images/ccs-9.jpg) -- Now that the Debug session is started we can connect to the target. Make sure -that the right Debug Probe is selected in the `Debug` window and click -`Connect Target`. +- Now that the Debug session is started we can connect to the target. Make + sure that the right Debug Probe is selected in the `Debug` window and click + `Connect Target`. -![CCS step 9](images/ccs-10.jpg) + ![CCS step 9](images/ccs-10.jpg) -- The target MCU is connected. The MCU is halted on connection by default. -Select the `Load Program...` option to select the ELF image to load. +- The target MCU is connected. The MCU is halted on connection by default. + Select the `Load Program...` option to select the ELF image to load. -![CCS step 9](images/ccs-11.jpg) + ![CCS step 9](images/ccs-11.jpg) -- Navigate to the ELF file -(`${connectedhomeip}/examples/lock-app/cc13x2_26x2/out/debug/chip-cc13x2_26x2-lock-example.out` -file) in the `Load Program` dialog. Click `OK` to begin loading the target. +- Navigate to the ELF file + (`${connectedhomeip}/examples/lock-app/cc13x2_26x2/out/debug/chip-cc13x2_26x2-lock-example.out` + file) in the `Load Program` dialog. Click `OK` to begin loading the target. -![CCS step 9](images/ccs-12.jpg) + ![CCS step 9](images/ccs-12.jpg) -- After loacating the source file for `main.cpp` we can step through the code -as it executes. +- After loacating the source file for `main.cpp` we can step through the code + as it executes. -![CCS step 9](images/ccs-13.jpg) + ![CCS step 9](images/ccs-13.jpg) [ccs]: https://www.ti.com/tool/CCSTUDIO -``` diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp index ef8023ac5be0e2..2daf8f933ad6f5 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/lock-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -329,8 +329,14 @@ void AppTask::DispatchEvent(AppEvent * aEvent) // Enable BLE advertisements if (!ConnectivityMgr().IsBLEAdvertisingEnabled()) { - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - PLAT_LOG("Enabled BLE Advertisements"); + if (OpenDefaultPairingWindow(chip::ResetAdmins::kNo) == CHIP_NO_ERROR) + { + PLAT_LOG("Enabled BLE Advertisement"); + } + else + { + PLAT_LOG("OpenDefaultPairingWindow() failed"); + } } } break; diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h index 29138dcf1b8a1f..48b12b2dae3ac6 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h +++ b/examples/lock-app/cc13x2x7_26x2x7/main/include/OpenThreadConfig.h @@ -50,6 +50,8 @@ #define UART_AS_SERIAL_TRANSPORT 1 #define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 +#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 + // Use the TI-supplied default platform configuration for remainder #include "openthread-core-cc13x2_26x2-config.h" diff --git a/examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h b/examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h deleted file mode 100644 index 8b00bf4a4cb223..00000000000000 --- a/examples/platform/cc13x2_26x2/project_include/OpenThreadConfig.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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 - * Overrides to default OpenThread configuration. - * - */ - -#ifndef OPENTHREAD_PLATFORM_CONFIG_H -#define OPENTHREAD_PLATFORM_CONFIG_H - -// use the logging in the CHIP platform layer -#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_APP - -// Turn on a moderate level of logging in OpenThread -// Enable use of external heap allocator (calloc/free) for OpenThread. -#define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 1 - -// Reduced for RAM consumption reasons -#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 22 - -/* Define to 1 if you want to enable CoAP to an application. */ -#define OPENTHREAD_CONFIG_COAP_API_ENABLE 1 - -/* Define to 1 to enable the border agent feature. */ -#define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 0 - -/* Define to 1 if you want to enable Border Router */ -#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 0 - -/* Define to 1 if you want to enable log for certification test */ -#define OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE 0 - -/* Define to 1 if you want to enable channel manager feature */ -#define OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE 0 - -/* Define to 1 if you want to use channel monitor feature */ -#define OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE 0 - -/* Define to 1 if you want to use child supervision feature */ -#define OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE 0 - -/* Define to 1 to enable the commissioner role. */ -#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0 - -/* Define as 1 to enable support for adding of auto-configured SLAAC addresses by OpenThread */ -#define OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE 1 - -/* Define to 1 if you want to enable multicast DHCPv6 Solicit messages */ -#define OPENTHREAD_ENABLE_DHCP6_MULTICAST_SOLICIT 1 - -/* Define to 1 if you want to enable DHCPv6 Client */ -#define OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE 1 - -/* Define to 1 if you want to enable DHCPv6 Server */ -#define OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE 0 - -/* Define to 1 if you want to use diagnostics module */ -#define OPENTHREAD_CONFIG_DIAG_ENABLE 1 - -/* Define to 1 if you want to enable DNS Client */ -#define OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE 0 - -/* Define to 1 to enable dtls support. */ -#define OPENTHREAD_CONFIG_DTLS_ENABLE 1 - -/* Define to 1 if you want to use jam detection feature */ -#define OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE 0 - -/* Define to 1 to enable the joiner role. */ -#define OPENTHREAD_CONFIG_JOINER_ENABLE 1 - -/* Define to 1 if you want to use legacy network support */ -#define OPENTHREAD_CONFIG_LEGACY_ENABLE 0 - -/* Define to 1 if you want to use MAC filter feature */ -#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 0 - -/* Define to 1 to enable network diagnostic for MTD. */ -#define OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE 0 - -/* Define to 1 if you want to enable support for multiple OpenThread - instances. */ -#define OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE 0 - -/* Define to 1 to enable the NCP SPI interface. */ -#define OPENTHREAD_CONFIG_NCP_SPI_ENABLE 0 - -/* Define to 1 if using NCP Spinel Encrypter */ -#define OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER 0 - -/* Define to 1 to enable the NCP UART interface. */ -#define OPENTHREAD_CONFIG_NCP_UART_ENABLE 1 - -/* Define to 1 if using NCP vendor hook */ -#define OPENTHREAD_ENABLE_NCP_VENDOR_HOOK 0 - -/* Define to 1 if you want to enable raw link-layer API */ -#define OPENTHREAD_CONFIG_LINK_RAW_ENABLE 1 - -/* Define to 1 if you want to enable Service */ -#define OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 0 - -/* Define to 1 to enable the UDP proxy feature. */ -#define OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE 0 - -#define ENABLE_ALL_LOGS_TO_UART 0 -#if ENABLE_ALL_LOGS_TO_UART -/* Enable volumous logging via the below */ - -/* Where should logs go? - * For details & options see: - * ${openthread}/src/core/openthread-core-default-config.h - * Note: Default is: OPENTHREAD_CONFIG_LOG_OUTPUT_NONE - */ -#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_DEBUG_UART - -/* Details of the debug uart can be found in the file: - * 'platform/dbg_uart.c' file within the examples. - */ - -/* - * This enables the Debug Uart, disabled by default - */ -#define OPENTHREAD_CONFIG_ENABLE_DEBUG_UART 1 - -/* - * For details & selections see: - * ${openthread}/include/openthread/platform/logging.h - */ -#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_DEBG - -/* Each significant area openthread can be configured to log, or not log - * The areas are enabled via various #defines, see below for a partial list. - * For more details, see the openthread internal ".hpp" - * - * See: ${openthread}/openthread/src/core/common/logging.hpp - * Also note above level is defined in the single ".h" log header - * Whereas each area is controlled by the C++ header ".hpp" log header. - */ -#define OPENTHREAD_CONFIG_LOG_API 1 -#define OPENTHREAD_CONFIG_LOG_ARP 1 -#define OPENTHREAD_CONFIG_LOG_CLI 1 -#define OPENTHREAD_CONFIG_LOG_COAP 1 -#define OPENTHREAD_CONFIG_LOG_ICMP 1 -#define OPENTHREAD_CONFIG_LOG_IP6 1 -#define OPENTHREAD_CONFIG_LOG_MAC 1 -#define OPENTHREAD_CONFIG_LOG_MEM 1 -#define OPENTHREAD_CONFIG_LOG_MLE 1 -#define OPENTHREAD_CONFIG_LOG_NETDATA 1 -#define OPENTHREAD_CONFIG_LOG_NETDIAG 1 -#define OPENTHREAD_CONFIG_LOG_PKT_DUMP 1 -#define OPENTHREAD_CONFIG_LOG_PLATFORM 1 -#define OPENTHREAD_CONFIG_LOG_PREPEND_LEVEL 1 -#define OPENTHREAD_CONFIG_LOG_PREPEND_REGION 1 - -#endif - -/* match the output buffer size to Diag process max buffer. - * size = 256. Otherwise some output chars are chopped - */ -#define OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH 256 - -#endif // OPENTHREAD_PLATFORM_CONFIG_H diff --git a/src/platform/cc13x2_26x2/BLEManagerImpl.cpp b/src/platform/cc13x2_26x2/BLEManagerImpl.cpp index 1ff8c713e38225..6837481e22c9f9 100644 --- a/src/platform/cc13x2_26x2/BLEManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/BLEManagerImpl.cpp @@ -1,3 +1,4 @@ + /* * * Copyright (c) 2020-2021 Project CHIP Authors @@ -86,6 +87,7 @@ TaskHandle_t BLEManagerImpl::sBleTaskHndl; ICall_EntityID BLEManagerImpl::sSelfEntity; ICall_SyncHandle BLEManagerImpl::sSyncEvent; QueueHandle_t BLEManagerImpl::sEventHandlerMsgQueueID; + chipOBleProfileCBs_t BLEManagerImpl::CHIPoBLEProfile_CBs = { // Provisioning GATT Characteristic value change callback CHIPoBLEProfile_charValueChangeCB @@ -200,7 +202,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) strncpy(mDeviceName, deviceName, strlen(deviceName)); mFlags.Set(Flags::kBLEStackGATTNameUpdate); - + mFlags.Set(Flags::kAdvertisingRefreshNeeded); ret = DriveBLEState(); } else @@ -362,6 +364,7 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const ChipBle PacketBufferHandle pBuf) { /* Unsupported on TI peripheral device implementation */ + BLEMGR_LOG("BLEMGR: BLE SendWriteRequest"); return false; } @@ -387,13 +390,11 @@ void BLEManagerImpl::HandleIncomingBleConnection(BLEEndPoint * bleEP) // ===== Helper Members that implement the Low level BLE Stack behavior. /********************************************************************* - * @fn AdvInit + * @fn ConfigureAdvertisements * - * @brief Initialize CHIPoBLE Advertisement. - * - * @param pMsg - message to process + * @brief Initialize CHIPoBLE Advertisements. */ -void BLEManagerImpl::AdvInit(void) +void BLEManagerImpl::ConfigureAdvertisements(void) { bStatus_t status = FAILURE; uint16_t deviceDiscriminator; @@ -402,14 +403,27 @@ void BLEManagerImpl::AdvInit(void) uint8_t advIndex = 0; uint8_t scanResLength; uint8_t advLength; - uint8_t * advDatachipOBle; - uint8_t * scanResDatachipOBle; - BLEMGR_LOG("BLEMGR: AdvInit"); + GapAdv_params_t advParams = { .eventProps = GAP_ADV_PROP_CONNECTABLE | GAP_ADV_PROP_LEGACY | GAP_ADV_PROP_SCANNABLE, + .primIntMin = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN, + .primIntMax = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN, + .primChanMap = GAP_ADV_CHAN_ALL, + .peerAddrType = PEER_ADDRTYPE_PUBLIC_OR_PUBLIC_ID, + .peerAddr = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa }, + .filterPolicy = GAP_ADV_WL_POLICY_ANY_REQ, + .txPower = GAP_ADV_TX_POWER_NO_PREFERENCE, + .primPhy = GAP_ADV_PRIM_PHY_1_MBPS, + .secPhy = GAP_ADV_SEC_PHY_1_MBPS, + .sid = 0 }; + + BLEMGR_LOG("BLEMGR: ConfigureAdvertisements"); ChipBLEDeviceIdentificationInfo mDeviceIdInfo; ConfigurationMgr().GetBLEDeviceIdentificationInfo(mDeviceIdInfo); + memset(sInstance.mScanResDatachipOBle, 0, CHIPOBLE_ADV_DATA_MAX_SIZE); + memset(sInstance.mAdvDatachipOBle, 0, CHIPOBLE_ADV_DATA_MAX_SIZE); + // Verify device name was not already set if (!sInstance.mFlags.Has(Flags::kBLEStackGATTNameSet)) { @@ -431,66 +445,88 @@ void BLEManagerImpl::AdvInit(void) } else { + sInstance.mFlags.Clear(Flags::kBLEStackGATTNameUpdate); + localDeviceNameLen = strlen(sInstance.mDeviceName); } scanResLength = localDeviceNameLen + CHIPOBLE_SCANRES_SIZE_NO_NAME; - scanResDatachipOBle = (uint8_t *) ICall_malloc(scanResLength); + /* Verify scan response data length */ + assert(scanResLength < CHIPOBLE_ADV_DATA_MAX_SIZE); - scanResDatachipOBle[scanIndex++] = localDeviceNameLen + 1; - scanResDatachipOBle[scanIndex++] = GAP_ADTYPE_LOCAL_NAME_COMPLETE; - memcpy(&scanResDatachipOBle[scanIndex], sInstance.mDeviceName, localDeviceNameLen); + sInstance.mScanResDatachipOBle[scanIndex++] = localDeviceNameLen + 1; + sInstance.mScanResDatachipOBle[scanIndex++] = GAP_ADTYPE_LOCAL_NAME_COMPLETE; + memcpy(&sInstance.mScanResDatachipOBle[scanIndex], sInstance.mDeviceName, localDeviceNameLen); scanIndex += localDeviceNameLen; - scanResDatachipOBle[scanIndex++] = 0x03; - scanResDatachipOBle[scanIndex++] = GAP_ADTYPE_16BIT_COMPLETE; - scanResDatachipOBle[scanIndex++] = static_cast(LO_UINT16(CHIPOBLE_SERV_UUID)); - scanResDatachipOBle[scanIndex++] = static_cast(HI_UINT16(CHIPOBLE_SERV_UUID)); + sInstance.mScanResDatachipOBle[scanIndex++] = 0x03; + sInstance.mScanResDatachipOBle[scanIndex++] = GAP_ADTYPE_16BIT_COMPLETE; + sInstance.mScanResDatachipOBle[scanIndex++] = static_cast(LO_UINT16(CHIPOBLE_SERV_UUID)); + sInstance.mScanResDatachipOBle[scanIndex++] = static_cast(HI_UINT16(CHIPOBLE_SERV_UUID)); for (uint8_t temp = 0; temp < scanIndex; temp++) { - BLEMGR_LOG("BLEMGR: AdvInit Scan Response Data: %x", scanResDatachipOBle[temp]); + BLEMGR_LOG("BLEMGR: AdvInit Scan Response Data: %x", sInstance.mScanResDatachipOBle[temp]); } - advLength = sizeof(static_cast(CHIPOBLE_SERV_UUID)) + static_cast(sizeof(mDeviceIdInfo)) + 1; - advDatachipOBle = (uint8_t *) ICall_malloc(CHIPOBLE_ADV_SIZE_NO_DEVICE_ID_INFO + advLength); + advLength = sizeof(static_cast(CHIPOBLE_SERV_UUID)) + static_cast(sizeof(mDeviceIdInfo)) + 1; + + /* Verify advertising data length */ + assert((CHIPOBLE_ADV_SIZE_NO_DEVICE_ID_INFO + advLength) < CHIPOBLE_ADV_DATA_MAX_SIZE); BLEMGR_LOG("BLEMGR: AdvInit: MDeviceIDInfo Size: %d", sizeof(mDeviceIdInfo)); BLEMGR_LOG("BLEMGR: AdvInit: advlength: %d", advLength); BLEMGR_LOG("BLEMGR: AdvInit:Desc : %d", mDeviceIdInfo.GetDeviceDiscriminator()); - advDatachipOBle[advIndex++] = 0x02; - advDatachipOBle[advIndex++] = GAP_ADTYPE_FLAGS; - advDatachipOBle[advIndex++] = GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED | GAP_ADTYPE_FLAGS_GENERAL; - advDatachipOBle[advIndex++] = advLength; - advDatachipOBle[advIndex++] = GAP_ADTYPE_SERVICE_DATA; - advDatachipOBle[advIndex++] = static_cast(LO_UINT16(CHIPOBLE_SERV_UUID)); - advDatachipOBle[advIndex++] = static_cast(HI_UINT16(CHIPOBLE_SERV_UUID)); - memcpy(&advDatachipOBle[advIndex], (void *) &mDeviceIdInfo, static_cast(sizeof(mDeviceIdInfo))); + sInstance.mAdvDatachipOBle[advIndex++] = 0x02; + sInstance.mAdvDatachipOBle[advIndex++] = GAP_ADTYPE_FLAGS; + sInstance.mAdvDatachipOBle[advIndex++] = GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED | GAP_ADTYPE_FLAGS_LIMITED; + sInstance.mAdvDatachipOBle[advIndex++] = advLength; + sInstance.mAdvDatachipOBle[advIndex++] = GAP_ADTYPE_SERVICE_DATA; + sInstance.mAdvDatachipOBle[advIndex++] = static_cast(LO_UINT16(CHIPOBLE_SERV_UUID)); + sInstance.mAdvDatachipOBle[advIndex++] = static_cast(HI_UINT16(CHIPOBLE_SERV_UUID)); + memcpy(&sInstance.mAdvDatachipOBle[advIndex], (void *) &mDeviceIdInfo, static_cast(sizeof(mDeviceIdInfo))); // Setup and start Advertising // For more information, see the GAP section in the User's Guide: // http://software-dl.ti.com/lprf/ble5stack-latest/ - // Create Advertisement set #1 and assign handle - status = (bStatus_t) GapAdv_create(&advCallback, &advParams1, &sInstance.advHandleLegacy); - assert(status == SUCCESS); + if (!sInstance.mFlags.Has(Flags::kBLEStackAdvInitialized)) + { + // Create Advertisement set #1 and assign handle + status = (bStatus_t) GapAdv_create(&advCallback, &advParams, &sInstance.advHandleLegacy); + assert(status == SUCCESS); + + // Set event mask for set #1 + status = (bStatus_t) GapAdv_setEventMask(sInstance.advHandleLegacy, + GAP_ADV_EVT_MASK_START_AFTER_ENABLE | GAP_ADV_EVT_MASK_END_AFTER_DISABLE | + GAP_ADV_EVT_MASK_SET_TERMINATED); + + Util_constructClock(&sInstance.clkAdvTimeout, AdvTimeoutHandler, ADV_TIMEOUT, 0, false, (uintptr_t) NULL); + } + if (sInstance.mFlags.Has(Flags::kBLEStackAdvInitialized)) + + { + // Don't free anything since we're going to use the same buffer to re-load + GapAdv_prepareLoadByHandle(sInstance.advHandleLegacy, GAP_ADV_FREE_OPTION_DONT_FREE); + } // Load advertising data for set #1 that is statically allocated by the app status = (bStatus_t) GapAdv_loadByHandle(sInstance.advHandleLegacy, GAP_ADV_DATA_TYPE_ADV, - CHIPOBLE_ADV_SIZE_NO_DEVICE_ID_INFO + advLength, advDatachipOBle); - - // Load scan response data for set #1 that is statically allocated by the app - status = - (bStatus_t) GapAdv_loadByHandle(sInstance.advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP, scanResLength, scanResDatachipOBle); + CHIPOBLE_ADV_SIZE_NO_DEVICE_ID_INFO + advLength, sInstance.mAdvDatachipOBle); assert(status == SUCCESS); - // Set event mask for set #1 - status = (bStatus_t) GapAdv_setEventMask(sInstance.advHandleLegacy, - GAP_ADV_EVT_MASK_START_AFTER_ENABLE | GAP_ADV_EVT_MASK_END_AFTER_DISABLE | - GAP_ADV_EVT_MASK_SET_TERMINATED); + if (sInstance.mFlags.Has(Flags::kBLEStackAdvInitialized)) + { - Util_constructClock(&sInstance.clkAdvTimeout, AdvTimeoutHandler, ADV_TIMEOUT, 0, false, (uintptr_t) NULL); + // Don't free anything since we're going to use the same buffer to re-load + GapAdv_prepareLoadByHandle(sInstance.advHandleLegacy, GAP_ADV_FREE_OPTION_DONT_FREE); + } + + // Load scan response data for set #1 that is statically allocated by the app + status = (bStatus_t) GapAdv_loadByHandle(sInstance.advHandleLegacy, GAP_ADV_DATA_TYPE_SCAN_RSP, scanResLength, + sInstance.mScanResDatachipOBle); + assert(status == SUCCESS); } /********************************************************************* @@ -587,6 +623,7 @@ void BLEManagerImpl::EventHandler_init(void) // Initialize array to store connection handle and RSSI values InitPHYRSSIArray(); + BLEMGR_LOG("BLEMGR: EventHandler_init Done"); } /********************************************************************* @@ -755,70 +792,75 @@ void BLEManagerImpl::ProcessEvtHdrMsg(QueuedEvt_t * pMsg) bStatus_t status; /* Verify BLE service mode is enabled */ - if (sInstance.mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled) + if ((sInstance.mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled) && + sInstance.mFlags.Has(Flags::kBLEStackInitialized)) { - /* Advertising flag set, either advertising or fast adv is enabled: Do nothing */ - /* Advertising flag not set, neither advertising nor fast adv is enabled: do nothing */ - /* Advertising flag not set, either advertising or fast adv is enabled: Turn on */ - if (!sInstance.mFlags.Has(Flags::kAdvertising)) + if (sInstance.mFlags.Has(Flags::kAdvertisingEnabled)) { - BLEMGR_LOG("BLEMGR: BLE Process Application Message: Not advertising"); + BLEMGR_LOG("BLEMGR: BLE Process Application Message: kAdvertisingEnabled"); - if (sInstance.mFlags.Has(Flags::kAdvertisingEnabled)) + if (sInstance.mFlags.Has(Flags::kAdvertisingRefreshNeeded)) { - // Enable legacy advertising for set #1 - status = (bStatus_t) GapAdv_enable(sInstance.advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0); + BLEMGR_LOG("BLEMGR: BLE Process Application Message: kAdvertisingRefreshNeeded"); - assert(status == SUCCESS); + // Disable advertisements and proceed with updates + sInstance.mFlags.Clear(Flags::kAdvertisingRefreshNeeded); - sInstance.mFlags.Set(Flags::kAdvertising); + GapAdv_disable(sInstance.advHandleLegacy); + sInstance.mFlags.Clear(Flags::kAdvertising); + uint16_t newParamMax = 0, newParamMin = 0; if (sInstance.mFlags.Has(Flags::kFastAdvertisingEnabled)) { - BLEMGR_LOG("BLEMGR: BLE Process Application Message: Fast Advertising Enabled"); + // Update advertising interval + BLEMGR_LOG("BLEMGR: ConfigureAdvertisements: Fast Advertising Enabled"); + newParamMax = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX; + newParamMin = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN; } else { - BLEMGR_LOG("BLEMGR: BLE Process Application Message: Slow Advertising Enabled"); - - // Start advertisement timer - Util_startClock(&sInstance.clkAdvTimeout); + // Decrease advertising interval + BLEMGR_LOG("BLEMGR: ConfigureAdvertisements: Slow Advertising Enabled"); + newParamMax = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX; + newParamMin = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN; } - } - } - /* Advertising flag set, neither advertising nor fast adv is enabled: Turn off*/ - else if (!sInstance.mFlags.Has(Flags::kAdvertisingEnabled) && !sInstance.mFlags.Has(Flags::kFastAdvertisingEnabled)) - { - BLEMGR_LOG("BLEMGR: BLE Process Application Message: Advertising disables"); - // Stop advertising - GapAdv_disable(sInstance.advHandleLegacy); - sInstance.mFlags.Clear(Flags::kAdvertising); - mFlags.Set(Flags::kFastAdvertisingEnabled, true); + // Set a parameter + GapAdv_setParam(sInstance.advHandleLegacy, GAP_ADV_PARAM_PRIMARY_INTERVAL_MAX, &newParamMax); + GapAdv_setParam(sInstance.advHandleLegacy, GAP_ADV_PARAM_PRIMARY_INTERVAL_MIN, &newParamMin); - Util_stopClock(&sInstance.clkAdvTimeout); + // Update advertisement parameters + ConfigureAdvertisements(); + } } - /* Other case is that advertising is already working, but should be restarted, as its settings changed */ - else if (sInstance.mFlags.Has(Flags::kAdvertisingRefreshNeeded)) + + // Turn on advertisements + if (sInstance.mFlags.Has(Flags::kAdvertisingEnabled) && !sInstance.mFlags.Has(Flags::kAdvertising)) { - sInstance.mFlags.Clear(Flags::kAdvertisingRefreshNeeded); - GapAdv_disable(sInstance.advHandleLegacy); + // Send notification to thread manager that CHIPoBLE advertising is starting // Enable legacy advertising for set #1 status = (bStatus_t) GapAdv_enable(sInstance.advHandleLegacy, GAP_ADV_ENABLE_OPTIONS_USE_MAX, 0); + assert(status == SUCCESS); + + // Start advertisement timeout timer + Util_startClock(&sInstance.clkAdvTimeout); + sInstance.mFlags.Set(Flags::kAdvertising); } - } - if (sInstance.mFlags.Has(Flags::kBLEStackGATTNameUpdate)) - { - sInstance.mFlags.Clear(Flags::kBLEStackGATTNameUpdate); - // Indicate that Device name has been set externally - mFlags.Set(Flags::kBLEStackGATTNameSet); + // Advertising should be disabled + if ((!sInstance.mFlags.Has(Flags::kAdvertisingEnabled)) && sInstance.mFlags.Has(Flags::kAdvertising)) + { + BLEMGR_LOG("BLEMGR: BLE Process Application Message: ADvertisements disabled"); + + // Stop advertising + GapAdv_disable(sInstance.advHandleLegacy); + sInstance.mFlags.Clear(Flags::kAdvertising); - // Set the Device Name characteristic in the GAP GATT Service - GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, sInstance.mDeviceName); + Util_stopClock(&sInstance.clkAdvTimeout); + } } } break; @@ -833,6 +875,10 @@ void BLEManagerImpl::ProcessEvtHdrMsg(QueuedEvt_t * pMsg) case BLEManagerIMPL_CHIPOBLE_TX_IND_EVT: { uint8_t dataLen = ((CHIPoBLEIndEvt_t *) (pMsg->pData))->len; + uint16_t i = 0; + void * connHandle; + ConnRec_t * activeConnObj = NULL; + ChipDeviceEvent event; CHIPoBLEProfile_SetParameter(CHIPOBLEPROFILE_TX_CHAR, dataLen, (void *) (((CHIPoBLEIndEvt_t *) (pMsg->pData))->pData), BLEManagerImpl::sSelfEntity); @@ -841,6 +887,21 @@ void BLEManagerImpl::ProcessEvtHdrMsg(QueuedEvt_t * pMsg) ICall_free((void *) (((CHIPoBLEIndEvt_t *) (pMsg->pData))->pData)); + // Find active connection + for (i = 0; i < MAX_NUM_BLE_CONNS; i++) + { + if (sInstance.connList[i].connHandle != 0xffff) + { + activeConnObj = &sInstance.connList[i]; + } + } + + connHandle = (void *) &activeConnObj->connHandle; + + event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm; + event.CHIPoBLEIndicateConfirm.ConId = connHandle; + PlatformMgr().PostEvent(&event); + dealloc = TRUE; } break; @@ -907,8 +968,8 @@ void BLEManagerImpl::ProcessEvtHdrMsg(QueuedEvt_t * pMsg) CHIPoBLEProfile_GetParameter(CHIPOBLEPROFILE_CCCWrite, &cccValue, 1); - // Check whether it is a sub/unsub event. 0x1 = Notofications enabled, 0x2 = Indications enabled - if (cccValue & 2) + // Check whether it is a sub/unsub event. 0x1 = Notifications enabled, 0x2 = Indications enabled + if (cccValue & 1) { // Post event to CHIP BLEMGR_LOG("BLEMGR: BLE Process Application Message: CHIPOBLE_CHAR_CHANGE_EVT, Subscrbe"); @@ -1023,9 +1084,10 @@ void BLEManagerImpl::ProcessGapMessage(gapEventHdr_t * pMsg) // Set Device Info Service Parameter DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId); - AdvInit(); + ConfigureAdvertisements(); sInstance.mFlags.Set(Flags::kBLEStackInitialized); + sInstance.mFlags.Set(Flags::kBLEStackAdvInitialized); /* Trigger post-initialization state update */ DriveBLEState(); @@ -1056,17 +1118,11 @@ void BLEManagerImpl::ProcessGapMessage(gapEventHdr_t * pMsg) DMMPolicy_updateStackState(DMMPolicy_StackRole_BlePeripheral, DMMPOLICY_BLE_HIGH_BANDWIDTH); - if (numActive < MAX_NUM_BLE_CONNS) - { - // Start advertising since there is room for more connections. Advertisements stop automatically following connection. - sInstance.mFlags.Clear(Flags::kAdvertising); - } - else + if (numActive >= MAX_NUM_BLE_CONNS) { // Stop advertising since there is no room for more connections BLEMGR_LOG("BLEMGR: BLE event GAP_LINK_ESTABLISHED_EVENT: MAX connections"); sInstance.mFlags.Clear(Flags::kAdvertisingEnabled).Clear(Flags::kAdvertising); - mFlags.Set(Flags::kFastAdvertisingEnabled, true); } /* Stop advertisement timeout timer */ @@ -1171,7 +1227,6 @@ uint8_t BLEManagerImpl::ProcessGATTMsg(gattMsgEvent_t * pMsg) if (pMsg->method == ATT_FLOW_CTRL_VIOLATED_EVENT) { // ATT request-response or indication-confirmation flow control is - // violated. All subsequent ATT requests or indications will be dropped. // The app is informed in case it wants to drop the connection. } else if (pMsg->method == ATT_MTU_UPDATED_EVENT) @@ -1332,22 +1387,32 @@ CHIP_ERROR BLEManagerImpl::ProcessParamUpdate(uint16_t connHandle) status_t BLEManagerImpl::EnqueueEvtHdrMsg(uint8_t event, void * pData) { uint8_t success; - QueuedEvt_t * pMsg = (QueuedEvt_t *) ICall_malloc(sizeof(QueuedEvt_t)); - BLEMGR_LOG("BLEMGR: EnqueueEvtHdrMsg"); - // Create dynamic pointer to message. - if (pMsg) + if (sInstance.mFlags.Has(Flags::kBLEStackInitialized)) { - pMsg->event = event; - pMsg->pData = pData; + QueuedEvt_t * pMsg = (QueuedEvt_t *) ICall_malloc(sizeof(QueuedEvt_t)); + BLEMGR_LOG("BLEMGR: EnqueueEvtHdrMsg"); - // Enqueue the message. - success = Util_enqueueMsg(sEventHandlerMsgQueueID, BLEManagerImpl::sSyncEvent, (uint8_t *) pMsg); + // Create dynamic pointer to message. + if (pMsg) + { + pMsg->event = event; + pMsg->pData = pData; - return (success) ? SUCCESS : FAILURE; - } + // Enqueue the message. + success = Util_enqueueMsg(sEventHandlerMsgQueueID, BLEManagerImpl::sSyncEvent, (uint8_t *) pMsg); - return bleMemAllocError; + BLEMGR_LOG("BLEMGR: Util_enqueueMsg compelte"); + + return (success) ? SUCCESS : FAILURE; + } + + return bleMemAllocError; + } + else + { + return true; + } } /********************************************************************* @@ -1569,9 +1634,11 @@ void BLEManagerImpl::UpdateBLERPA(void) void BLEManagerImpl::EventHandler(void * arg) { BLEMGR_LOG("BLEMGR: EventHandler"); - + PlatformMgr().LockChipStack(); sInstance.EventHandler_init(); + PlatformMgr().UnlockChipStack(); + for (;;) { uint32_t events; @@ -1691,7 +1758,6 @@ void BLEManagerImpl::AdvTimeoutHandler(uintptr_t arg) BLEMGR_LOG("BLEMGR: AdvTimeoutHandler ble adv 15 minute timeout"); sInstance.mFlags.Clear(Flags::kAdvertisingEnabled); - sInstance.mFlags.Set(Flags::kFastAdvertisingEnabled); /* Send event to process state change request */ DriveBLEState(); diff --git a/src/platform/cc13x2_26x2/BLEManagerImpl.h b/src/platform/cc13x2_26x2/BLEManagerImpl.h index 51f616e43becc6..4b577d34b27b79 100644 --- a/src/platform/cc13x2_26x2/BLEManagerImpl.h +++ b/src/platform/cc13x2_26x2/BLEManagerImpl.h @@ -72,6 +72,8 @@ using namespace chip::Ble; #define CHIPOBLE_SCANRES_SIZE_NO_NAME (6) +#define CHIPOBLE_ADV_DATA_MAX_SIZE (GAP_DEVICE_NAME_LEN + CHIPOBLE_SCANRES_SIZE_NO_NAME) + // How often to read current current RPA (in ms) #define READ_RPA_EVT_PERIOD 3000 @@ -267,10 +269,11 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla kAdvertisingEnabled = 0x0001, /* App enabled CHIPoBLE advertising */ kFastAdvertisingEnabled = 0x0002, /* App enabled Fash CHIPoBLE advertising */ kAdvertising = 0x0004, /* TI BLE stack actively advertising */ - kBLEStackInitialized = 0x0008, /* TI BLE Stack GAP Intilization complete */ - kBLEStackGATTNameUpdate = 0x0010, /* Trigger TI BLE Stack name update, must be performed prior to adv start */ - kBLEStackGATTNameSet = 0x0020, /* Device name has been set externally*/ - kAdvertisingRefreshNeeded = 0x0040, /* Advertising settings changed and it should be restarted */ + kBLEStackInitialized = 0x0008, /* TI BLE Stack GAP/GATT Intilization complete */ + kBLEStackAdvInitialized = 0x0010, /* TI BLE Stack Advertisement Intilization complete */ + kBLEStackGATTNameUpdate = 0x0020, /* Trigger TI BLE Stack name update, must be performed prior to adv start */ + kBLEStackGATTNameSet = 0x0040, /* Device name has been set externally*/ + kAdvertisingRefreshNeeded = 0x0080, /* Advertising settings changed and it should be restarted */ }; @@ -289,13 +292,16 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla // Current Random Private Address uint8_t rpa[B_ADDR_LEN] = { 0 }; + uint8_t mAdvDatachipOBle[CHIPOBLE_ADV_DATA_MAX_SIZE]; + uint8_t mScanResDatachipOBle[CHIPOBLE_ADV_DATA_MAX_SIZE]; + ClockP_Struct clkRpaRead; ClockP_Struct clkAdvTimeout; // Memory to pass RPA read event ID to clock handler ClockEventData_t argRpaRead = { .event = READ_RPA_EVT }; // ===== Private BLE Stack Helper functions. - void AdvInit(void); + void ConfigureAdvertisements(void); void EventHandler_init(void); void InitPHYRSSIArray(void); CHIP_ERROR CreateEventHandler(void); diff --git a/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h b/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h index bd7b642a495d28..4700846fe96aaa 100644 --- a/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h +++ b/src/platform/cc13x2_26x2/CHIPDevicePlatformConfig.h @@ -19,9 +19,7 @@ /** * @file * Platform-specific configuration overrides for the chip Device Layer - * for the Texas Instruments CC1352 platform. - * - * NOTE: currently a bare-bones implementation to allow for building. + * for the Texas Instruments CC2652R7 platform. */ #pragma once @@ -43,6 +41,10 @@ #define BLEMANAGER_EVENT_HANDLER_STACK_SIZE (4096) #define BLEMANAGER_EVENT_HANDLER_PRIORITY (2) -#define CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART 0 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1 + +// Per 5.2.5.2. Commencement Section of CHIP spec, BLE advertisement is +// disabled for Locks and Barrier Access Devices. +#define CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART 0 +#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART 0 diff --git a/src/platform/cc13x2_26x2/chipOBleProfile.c b/src/platform/cc13x2_26x2/chipOBleProfile.c index d587ecf900949a..0cc8e66b317701 100644 --- a/src/platform/cc13x2_26x2/chipOBleProfile.c +++ b/src/platform/cc13x2_26x2/chipOBleProfile.c @@ -60,7 +60,7 @@ const uint8 chipOBleProfileRxCharUUID[ATT_UUID_SIZE] = { static const gattAttrType_t chipoBleProfile = { ATT_UUID_SIZE, chipOBleServUUID }; // ChipOBLE Tx Characteristic Properties -static uint8_t chipOBleProfileTxCharProps = GATT_PROP_READ | GATT_PROP_INDICATE; +static uint8_t chipOBleProfileTxCharProps = GATT_PROP_READ | GATT_PROP_NOTIFY; // ChipOBLE Tx Characteristic Value static uint8_t chipOBleProfileTxCharVal[CHIPOBLEPROFILE_CHAR_LEN] = { 0x00 }; @@ -359,7 +359,7 @@ static bStatus_t CHIPoBLEProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_ notifyApp = CHIPOBLEPROFILE_CCCWrite; - status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_INDICATE); + status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY); } else {