diff --git a/.gitmodules b/.gitmodules index 477eb44fbd22d3..010744e0e06505 100644 --- a/.gitmodules +++ b/.gitmodules @@ -184,3 +184,6 @@ [submodule "third_party/mbed-mcu-boot/repo"] path = third_party/mbed-mcu-boot/repo url = https://github.com/ATmobica/mcuboot.git +[submodule "third_party/webos_sdk"] + path = third_party/webos_sdk + url = https://github.com/cabin15/webos-ose-ndk diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 2592b62be53a49..4e597f6e52c225 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -99,6 +99,14 @@ if (_chip_defaults.custom_toolchain != "") { } else if (target_os == "tizen") { _default_toolchain = "${_build_overrides.build_root}/toolchain/tizen:tizen_${target_cpu}" +} else if (target_os == "webos") { + if (target_cpu == "arm" || target_cpu == "arm64") { + print("target_os = webos / target_cpu = ${target_cpu}") + _default_toolchain = "//build/toolchain/webos" + } else { + assert(false, + "Unsupported target_cpu: ${current_cpu}. Shall be arm for webOS") + } } else { assert(false, "No toolchain specified, please specify custom_toolchain") } diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index f08497920fa488..6c16e492d3b6bc 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -23,6 +23,15 @@ if (current_os == "mac") { import("${build_root}/config/mac/mac_sdk.gni") } +if (current_os == "webos") { + import("${build_root}/config/webos/webos_sdk.gni") + target_defines += [] + target_cflags += [ "--sysroot=" + sysroot_webos ] + target_cflags_cc += [] + target_cflags_c += [] + target_ldflags += [ "--sysroot=" + sysroot_webos ] +} + declare_args() { # Enable -Werror. This can be disabled if using a different compiler # with unfixed or unsupported wanings. @@ -191,7 +200,7 @@ config("warnings_common") { } if (current_os != "mac" && current_os != "ios" && current_os != "linux" && - current_os != "win" && current_os != "tizen") { + current_os != "win" && current_os != "tizen" && current_os != "webos") { cflags += [ "-Wstack-usage=8192" ] } } @@ -207,6 +216,13 @@ config("strict_warnings") { "-Wformat-security", ] + if (current_os == "webos") { + cflags -= [ + "-Wshadow", + "-Wvla", + ] + } + cflags_cc = [ "-Wnon-virtual-dtor" ] ldflags = [] @@ -271,7 +287,7 @@ config("runtime_default") { "$dir_pw_toolchain/host_clang:xcode_sysroot", ] } - if (current_os == "linux" || current_os == "tizen") { + if (current_os == "linux" || current_os == "tizen" || current_os == "webos") { libs = [ "dl", "pthread", diff --git a/build/config/webos/webos_sdk.gni b/build/config/webos/webos_sdk.gni new file mode 100644 index 00000000000000..21c25c8c18d4e8 --- /dev/null +++ b/build/config/webos/webos_sdk.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2021 Project CHIP Authors +# +# 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. + +declare_args() { + sysroot_webos = "" +} diff --git a/build/toolchain/webos/BUILD.gn b/build/toolchain/webos/BUILD.gn new file mode 100644 index 00000000000000..edee5e5eae58f8 --- /dev/null +++ b/build/toolchain/webos/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright 2020 The Pigweed Authors +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +import("webos_toolchain.gni") + +print(target_os) + +webos_toolchain("webos") { + toolchain_args = { + target_os = "linux" + target_cpu = "${current_cpu}" + } +} diff --git a/build/toolchain/webos/webos_toolchain.gni b/build/toolchain/webos/webos_toolchain.gni new file mode 100644 index 00000000000000..e1c603f7107af1 --- /dev/null +++ b/build/toolchain/webos/webos_toolchain.gni @@ -0,0 +1,37 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +declare_args() { + cc_webos = "" + cxx_webos = "" + ar_webos = "" + ld_webos = "" +} + +import("//build/toolchain/gcc_toolchain.gni") + +template("webos_toolchain") { + print("WebOS_ToolChian") + gcc_toolchain(target_name) { + ar = ar_webos + cc = cc_webos + " -O2 -Wno-format-security -Wno-error -Wno-cpp" + cxx = cxx_webos + " -O2 -Wno-format-security -Wno-error -Wno-cpp" + toolchain_args = { + current_cpu = "${current_cpu}" + current_os = invoker.current_os + is_clang = false + forward_variables_from(invoker.toolchain_args, "*") + } + } +} diff --git a/scripts/examples/webos_example.sh b/scripts/examples/webos_example.sh new file mode 100755 index 00000000000000..b067499bfef51a --- /dev/null +++ b/scripts/examples/webos_example.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2022 Project CHIP Authors +# +# 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. +# + +# Activating connectedhomeip build environment +source scripts/activate.sh + +# Extract webOS SDK +cat third_party/webos_sdk/v2.14.1/webos_sdk.tar* | ( + cd third_party/webos_sdk/v2.14.1/ + tar xvzf - +) + +# Grant execute permission for NDK install script +chmod 555 third_party/webos_sdk/v2.14.1/webos-sdk-x86_64-cortexa7t2hf-neon-vfpv4-toolchain-2.14.1.g.sh + +# Install webOS OSE NDK +echo "##### Install webOS OSE NDK #####" +third_party/webos_sdk/v2.14.1/webos-sdk-x86_64-cortexa7t2hf-neon-vfpv4-toolchain-2.14.1.g.sh -d third_party/webos_sdk/v2.14.1 -y + +# Activating webOS NDK build environment +echo "##### Activating webOS NDK build environment #####" +source third_party/webos_sdk/v2.14.1/environment-setup-cortexa7t2hf-neon-vfpv4-webos-linux-gnueabi +echo "" + +# Build webos example +echo "##### Build webos example #####" +echo "##### Performing gn gen #####" +gn gen out/host --args="is_debug=false target_os=\"webos\" target_cpu=\"arm\" chip_enable_python_modules=false ar_webos=\"$AR\" cc_webos=\"$CC\" cxx_webos=\"$CXX\" sysroot_webos=\"$PKG_CONFIG_SYSROOT_DIR\" chip_build_tests=false enable_syslog=true chip_config_network_layer_ble=false" + +echo "##### Building by ninja #####" +ninja -C out/host diff --git a/src/crypto/crypto.gni b/src/crypto/crypto.gni index 651acb3237d0ab..aa477e95f8221a 100644 --- a/src/crypto/crypto.gni +++ b/src/crypto/crypto.gni @@ -21,7 +21,7 @@ declare_args() { if (chip_crypto == "") { if (current_os == "android" || current_os == "freertos" || - current_os == "zephyr" || current_os == "mbed") { + current_os == "zephyr" || current_os == "mbed" || current_os == "webos") { chip_crypto = "mbedtls" } else { chip_crypto = "openssl" diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 5709d0544f4b78..2a373ee7cf5465 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -69,7 +69,7 @@ if (chip_device_platform != "none") { if (chip_stack_lock_tracking == "auto") { if (chip_device_platform == "linux" || chip_device_platform == "tizen" || - chip_device_platform == "android") { + chip_device_platform == "android" || chip_device_platform == "webos") { # TODO: should be fatal for development. Change once bugs are fixed chip_stack_lock_tracking = "log" } else { @@ -222,6 +222,14 @@ if (chip_device_platform != "none") { "CHIP_DEVICE_LAYER_TARGET_CYW30739=1", "CHIP_DEVICE_LAYER_TARGET=CYW30739", ] + } else if (chip_device_platform == "webos") { + defines += [ + "CHIP_DEVICE_LAYER_TARGET_WEBOS=1", + "CHIP_DEVICE_LAYER_TARGET=Linux", + "CHIP_DEVICE_CONFIG_ENABLE_WIFI=${chip_enable_wifi}", + ] + defines -= + [ "CHIP_DEVICE_CONFIG_ENABLE_WPA=${chip_device_config_enable_wpa}" ] } } } else { @@ -348,6 +356,8 @@ if (chip_device_platform != "none") { _platform_target = "P6" } else if (chip_device_platform == "ameba") { _platform_target = "Ameba" + } else if (chip_device_platform == "webos") { + _platform_target = "webos" } else if (chip_device_platform == "fake") { _platform_target = "fake" } else if (chip_device_platform == "cyw30739") { diff --git a/src/platform/device.gni b/src/platform/device.gni index 3cdc24e356854b..61dddb0ec8ae72 100755 --- a/src/platform/device.gni +++ b/src/platform/device.gni @@ -36,6 +36,8 @@ if (chip_device_platform == "auto") { chip_device_platform = "tizen" } else if (current_os == "android") { chip_device_platform = "android" + } else if (current_os == "webos") { + chip_device_platform = "webos" } else { chip_device_platform = "none" } @@ -55,7 +57,8 @@ declare_args() { chip_enable_wifi = chip_device_platform == "linux" || chip_device_platform == "esp32" || chip_device_platform == "mbed" || chip_device_platform == "tizen" || - chip_device_platform == "android" || chip_device_platform == "ameba" + chip_device_platform == "android" || chip_device_platform == "ameba" || + chip_device_platform == "webos" # Enable ble support. if (chip_device_platform == "fake") { @@ -73,7 +76,7 @@ declare_args() { # Select DNS-SD implementation if (chip_device_platform == "linux" || chip_device_platform == "esp32" || chip_device_platform == "mbed" || chip_device_platform == "p6" || - chip_device_platform == "ameba") { + chip_device_platform == "ameba" || chip_device_platform == "webos") { chip_mdns = "minimal" } else if (chip_device_platform == "darwin" || chip_device_platform == "cc13x2_26x2" || current_os == "android" || @@ -116,6 +119,8 @@ if (chip_device_platform == "cc13x2_26x2") { _chip_device_layer = "Ameba" } else if (chip_device_platform == "cyw30739") { _chip_device_layer = "CYW30739" +} else if (chip_device_platform == "webos") { + _chip_device_layer = "webos" } if (chip_device_platform != "external") { @@ -160,5 +165,6 @@ assert( chip_device_platform == "k32w0" || chip_device_platform == "qpg" || chip_device_platform == "telink" || chip_device_platform == "mbed" || chip_device_platform == "p6" || chip_device_platform == "android" || - chip_device_platform == "ameba" || chip_device_platform == "cyw30739", + chip_device_platform == "ameba" || chip_device_platform == "cyw30739" || + chip_device_platform == "webos", "Please select a valid value for chip_device_platform") diff --git a/src/platform/webos/BLEManagerImpl.cpp b/src/platform/webos/BLEManagerImpl.cpp new file mode 100644 index 00000000000000..0140e06ba60c5d --- /dev/null +++ b/src/platform/webos/BLEManagerImpl.cpp @@ -0,0 +1,207 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2018 Nest Labs, Inc. + * + * 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 + * Provides an implementation of the BLEManager singleton object + * for webOS platforms. + */ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + +using namespace ::nl; +using namespace ::chip::Ble; + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +BLEManagerImpl BLEManagerImpl::sInstance; + +CHIP_ERROR BLEManagerImpl::_Init() +{ + CHIP_ERROR err; + return err; +} + +CHIP_ERROR BLEManagerImpl::_Shutdown() +{ + // ensure scan resources are cleared (e.g. timeout timers) + mDeviceScanner.reset(); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR BLEManagerImpl::_SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::_GetDeviceName(char * buf, size_t bufSize) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::ConfigureBle(uint32_t aAdapterId, bool aIsCentral) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::StartBLEAdvertising() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR BLEManagerImpl::StopBLEAdvertising() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {} + +void BLEManagerImpl::HandlePlatformSpecificBLEEvent(const ChipDeviceEvent * apEvent) {} + +uint16_t BLEManagerImpl::GetMTU(BLE_CONNECTION_OBJECT conId) const {} + +bool BLEManagerImpl::SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) +{ + return true; +} + +bool BLEManagerImpl::UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const ChipBleUUID * charId) +{ + return true; +} + +bool BLEManagerImpl::CloseConnection(BLE_CONNECTION_OBJECT conId) +{ + return true; +} + +bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + chip::System::PacketBufferHandle pBuf) +{ + return true; +} + +bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + chip::System::PacketBufferHandle pBuf) +{ + return true; +} + +bool BLEManagerImpl::SendReadRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + chip::System::PacketBufferHandle pBuf) +{ + ChipLogError(Ble, "SendReadRequest: Not implemented"); + return true; +} + +bool BLEManagerImpl::SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, + const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId) +{ + ChipLogError(Ble, "SendReadRBluezonse: Not implemented"); + return true; +} + +void BLEManagerImpl::HandleNewConnection(BLE_CONNECTION_OBJECT conId) {} + +void BLEManagerImpl::HandleConnectFailed(CHIP_ERROR error) {} + +void BLEManagerImpl::HandleWriteComplete(BLE_CONNECTION_OBJECT conId) {} + +void BLEManagerImpl::HandleSubscribeOpComplete(BLE_CONNECTION_OBJECT conId, bool subscribed) {} + +void BLEManagerImpl::HandleTXCharChanged(BLE_CONNECTION_OBJECT conId, const uint8_t * value, size_t len) {} + +void BLEManagerImpl::HandleRXCharWrite(BLE_CONNECTION_OBJECT conId, const uint8_t * value, size_t len) {} + +void BLEManagerImpl::CHIPoBluez_ConnectionClosed(BLE_CONNECTION_OBJECT conId) {} + +void BLEManagerImpl::HandleTXCharCCCDWrite(BLE_CONNECTION_OBJECT conId) {} + +void BLEManagerImpl::HandleTXComplete(BLE_CONNECTION_OBJECT conId) {} + +void BLEManagerImpl::DriveBLEState() {} + +void BLEManagerImpl::DriveBLEState(intptr_t arg) +{ + sInstance.DriveBLEState(); +} + +void BLEManagerImpl::NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) +{ + ChipLogProgress(Ble, "Got notification regarding chip connection closure"); +} + +void BLEManagerImpl::InitiateScan(BleScanState scanType) {} + +void BLEManagerImpl::CleanScanConfig() {} + +void BLEManagerImpl::InitiateScan(intptr_t arg) {} + +void BLEManagerImpl::NewConnection(BleLayer * bleLayer, void * appState, const uint16_t connDiscriminator) {} + +CHIP_ERROR BLEManagerImpl::CancelConnection() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void BLEManagerImpl::NotifyBLEPeripheralRegisterAppComplete(bool aIsSuccess, void * apAppstate) {} + +void BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(bool aIsSuccess, void * apAppstate) {} + +void BLEManagerImpl::NotifyBLEPeripheralAdvStartComplete(bool aIsSuccess, void * apAppstate) {} + +void BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(bool aIsSuccess, void * apAppstate) {} + +void BLEManagerImpl::OnDeviceScanned(BluezDevice1 * device, const chip::Ble::ChipBLEDeviceIdentificationInfo & info) {} + +void BLEManagerImpl::OnScanComplete() {} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE diff --git a/src/platform/webos/BLEManagerImpl.h b/src/platform/webos/BLEManagerImpl.h new file mode 100644 index 00000000000000..df5c9f2fa7a83d --- /dev/null +++ b/src/platform/webos/BLEManagerImpl.h @@ -0,0 +1,252 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 + * Provides an implementation of the BLEManager singleton object + * for the webOS platforms. + */ + +#pragma once + +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +void HandleIncomingBleConnection(Ble::BLEEndPoint * bleEP); + +struct BLEAdvConfig +{ + char * mpBleName; + uint32_t mAdapterId; + uint8_t mMajor; + uint8_t mMinor; + uint16_t mVendorId; + uint16_t mProductId; + uint64_t mDeviceId; + uint8_t mPairingStatus; + ChipAdvType mType; + uint16_t mDuration; + const char * mpAdvertisingUUID; +}; + +enum class BleScanState : uint8_t +{ + kNotScanning, + kScanForDiscriminator, + kScanForAddress, + kConnecting, +}; + +struct BLEScanConfig +{ + // If an active scan for connection is being performed + BleScanState mBleScanState = BleScanState::kNotScanning; + + // If scanning by discriminator, what are we scanning for + uint16_t mDiscriminator = 0; + + // If scanning by address, what address are we searching for + std::string mAddress; + + // Optional argument to be passed to callback functions provided by the BLE scan/connect requestor + void * mAppState = nullptr; +}; + +/** + * Concrete implementation of the BLEManagerImpl singleton object for the webOS platforms. + */ +class BLEManagerImpl final : public BLEManager, + private Ble::BleLayer, + private Ble::BlePlatformDelegate, + private Ble::BleApplicationDelegate, + private Ble::BleConnectionDelegate, + private ChipDeviceScannerDelegate +{ + // Allow the BLEManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend BLEManager; + +public: + CHIP_ERROR ConfigureBle(uint32_t aAdapterId, bool aIsCentral); + + // Driven by BlueZ IO + static void HandleNewConnection(BLE_CONNECTION_OBJECT conId); + static void HandleConnectFailed(CHIP_ERROR error); + static void HandleWriteComplete(BLE_CONNECTION_OBJECT conId); + static void HandleSubscribeOpComplete(BLE_CONNECTION_OBJECT conId, bool subscribed); + static void HandleTXCharChanged(BLE_CONNECTION_OBJECT conId, const uint8_t * value, size_t len); + static void HandleRXCharWrite(BLE_CONNECTION_OBJECT user_data, const uint8_t * value, size_t len); + static void CHIPoBluez_ConnectionClosed(BLE_CONNECTION_OBJECT user_data); + static void HandleTXCharCCCDWrite(BLE_CONNECTION_OBJECT user_data); + static void HandleTXComplete(BLE_CONNECTION_OBJECT user_data); + + static void NotifyBLEPeripheralRegisterAppComplete(bool aIsSuccess, void * apAppstate); + static void NotifyBLEPeripheralAdvConfiguredComplete(bool aIsSuccess, void * apAppstate); + static void NotifyBLEPeripheralAdvStartComplete(bool aIsSuccess, void * apAppstate); + static void NotifyBLEPeripheralAdvStopComplete(bool aIsSuccess, void * apAppstate); + +private: + // ===== Members that implement the BLEManager internal interface. + + CHIP_ERROR _Init(); + CHIP_ERROR _Shutdown(); + CHIPoBLEServiceMode _GetCHIPoBLEServiceMode(); + CHIP_ERROR _SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); + bool _IsAdvertisingEnabled(); + CHIP_ERROR _SetAdvertisingEnabled(bool val); + bool _IsAdvertising(); + CHIP_ERROR _SetAdvertisingMode(BLEAdvertisingMode mode); + CHIP_ERROR _GetDeviceName(char * buf, size_t bufSize); + CHIP_ERROR _SetDeviceName(const char * deviceName); + uint16_t _NumConnections(); + + void _OnPlatformEvent(const ChipDeviceEvent * event); + void HandlePlatformSpecificBLEEvent(const ChipDeviceEvent * event); + BleLayer * _GetBleLayer(); + + // ===== Members that implement virtual methods on BlePlatformDelegate. + + bool SubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, + const Ble::ChipBleUUID * charId) override; + bool UnsubscribeCharacteristic(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, + const Ble::ChipBleUUID * charId) override; + bool CloseConnection(BLE_CONNECTION_OBJECT conId) override; + uint16_t GetMTU(BLE_CONNECTION_OBJECT conId) const override; + bool SendIndication(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + System::PacketBufferHandle pBuf) override; + bool SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + System::PacketBufferHandle pBuf) override; + bool SendReadRequest(BLE_CONNECTION_OBJECT conId, const Ble::ChipBleUUID * svcId, const Ble::ChipBleUUID * charId, + System::PacketBufferHandle pBuf) override; + bool SendReadResponse(BLE_CONNECTION_OBJECT conId, BLE_READ_REQUEST_CONTEXT requestContext, const Ble::ChipBleUUID * svcId, + const Ble::ChipBleUUID * charId) override; + + // ===== Members that implement virtual methods on BleApplicationDelegate. + + void NotifyChipConnectionClosed(BLE_CONNECTION_OBJECT conId) override; + + // ===== Members that implement virtual methods on BleConnectionDelegate. + + void NewConnection(BleLayer * bleLayer, void * appState, uint16_t connDiscriminator) override; + CHIP_ERROR CancelConnection() override; + + // ===== Members that implement virtual methods on ChipDeviceScannerDelegate + void OnDeviceScanned(BluezDevice1 * device, const chip::Ble::ChipBLEDeviceIdentificationInfo & info) override; + void OnScanComplete() override; + + // ===== Members for internal use by the following friends. + + friend BLEManager & BLEMgr(); + friend BLEManagerImpl & BLEMgrImpl(); + + static BLEManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. + enum class Flags : uint16_t + { + kAsyncInitCompleted = 0x0001, /**< One-time asynchronous initialization actions have been performed. */ + kBluezBLELayerInitialized = 0x0002, /**< The Bluez layer has been initialized. */ + kAppRegistered = 0x0004, /**< The CHIPoBLE application has been registered with the Bluez layer. */ + kAdvertisingConfigured = 0x0008, /**< CHIPoBLE advertising has been configured in the Bluez layer. */ + kAdvertising = 0x0010, /**< The system is currently CHIPoBLE advertising. */ + kControlOpInProgress = 0x0020, /**< An async control operation has been issued to the ESP BLE layer. */ + kAdvertisingEnabled = 0x0040, /**< The application has enabled CHIPoBLE advertising. */ + kFastAdvertisingEnabled = 0x0080, /**< The application has enabled fast advertising. */ + kUseCustomDeviceName = 0x0100, /**< The application has configured a custom BLE device name. */ + kAdvertisingRefreshNeeded = 0x0200, /**< The advertising configuration/state in BLE layer needs to be updated. */ + }; + + enum + { + kMaxConnections = 1, // TODO: right max connection + kMaxDeviceNameLength = 20, // TODO: right-size this + kMaxAdvertismentDataSetSize = 31 // TODO: verify this + }; + + CHIP_ERROR StartBLEAdvertising(); + CHIP_ERROR StopBLEAdvertising(); + + void DriveBLEState(); + static void DriveBLEState(intptr_t arg); + + void InitiateScan(BleScanState scanType); + static void InitiateScan(intptr_t arg); + void CleanScanConfig(); + + CHIPoBLEServiceMode mServiceMode; + BLEAdvConfig mBLEAdvConfig; + BLEScanConfig mBLEScanConfig; + BitFlags mFlags; + char mDeviceName[kMaxDeviceNameLength + 1]; + bool mIsCentral = false; + BluezEndpoint * mpEndpoint = nullptr; + std::unique_ptr mDeviceScanner; +}; + +/** + * Returns a reference to the public interface of the BLEManager singleton object. + * + * Internal components should use this to access features of the BLEManager object + * that are common to all platforms. + */ +inline BLEManager & BLEMgr() +{ + return BLEManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the BLEManager singleton object. + * + * Internal components can use this to gain access to features of the BLEManager + * that are specific to the webOS platforms. + */ +inline BLEManagerImpl & BLEMgrImpl() +{ + return BLEManagerImpl::sInstance; +} + +inline Ble::BleLayer * BLEManagerImpl::_GetBleLayer() +{ + return this; +} + +inline BLEManager::CHIPoBLEServiceMode BLEManagerImpl::_GetCHIPoBLEServiceMode() +{ + return mServiceMode; +} + +inline bool BLEManagerImpl::_IsAdvertisingEnabled() +{ + return mFlags.Has(Flags::kAdvertisingEnabled); +} + +inline bool BLEManagerImpl::_IsAdvertising() +{ + return mFlags.Has(Flags::kAdvertising); +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE diff --git a/src/platform/webos/BUILD.gn b/src/platform/webos/BUILD.gn new file mode 100644 index 00000000000000..d7634ffbb2d7ed --- /dev/null +++ b/src/platform/webos/BUILD.gn @@ -0,0 +1,132 @@ +# Copyright (c) 2021-2022 Project CHIP Authors +# +# 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. + +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") + +import("${build_root}/config/linux/pkg_config.gni") + +import("${chip_root}/src/platform/device.gni") + +assert(chip_device_platform == "webos") + +declare_args() { + # Support syslog along instead of stdout(printf) + enable_syslog = true +} + +if (chip_enable_openthread) { + import("//build_overrides/openthread.gni") + import("//build_overrides/ot_br_posix.gni") +} + +if (chip_mdns != "none") { + pkg_config("avahi_client_config") { + packages = [ "avahi-client" ] + } +} + +pkg_config("glib") { + packages = [ + "glib-2.0", + "gio-unix-2.0", + ] +} + +pkg_config("luna-service") { + packages = [ + "luna-service2", + "PmLogLib", + "pbnjson_cpp", + ] +} + +static_library("webos") { + if (enable_syslog) { + print("### enable syslog logging ###") + defines = [ "USE_SYSLOG=1" ] + } + sources = [ + "../DeviceSafeQueue.cpp", + "../DeviceSafeQueue.h", + "../Linux/CHIPLinuxStorage.cpp", + "../Linux/CHIPLinuxStorage.h", + "../Linux/CHIPLinuxStorageIni.cpp", + "../Linux/CHIPLinuxStorageIni.h", + "../Linux/ConfigurationManagerImpl.cpp", + "../Linux/ConfigurationManagerImpl.h", + "../Linux/ConnectivityUtils.cpp", + "../Linux/ConnectivityUtils.h", + "../Linux/DiagnosticDataProviderImpl.cpp", + "../Linux/DiagnosticDataProviderImpl.h", + "../Linux/InetPlatformConfig.h", + "../Linux/KeyValueStoreManagerImpl.cpp", + "../Linux/KeyValueStoreManagerImpl.h", + "../Linux/PlatformManagerImpl.cpp", + "../Linux/PlatformManagerImpl.h", + "../Linux/PosixConfig.cpp", + "../Linux/PosixConfig.h", + "../Linux/SystemTimeSupport.cpp", + "../SingletonConfigurationManager.cpp", + "BLEManagerImpl.cpp", + "BLEManagerImpl.h", + "BlePlatformConfig.h", + "CHIPDevicePlatformConfig.h", + "CHIPDevicePlatformEvent.h", + "CHIPPlatformConfig.h", + "ConnectivityManagerImpl.cpp", + "ConnectivityManagerImpl.h", + "DeviceNetworkProvisioningDelegateImpl.cpp", + "DeviceNetworkProvisioningDelegateImpl.h", + "Logging.cpp", + "SystemPlatformConfig.h", + ] + + deps = [ "${chip_root}/src/setup_payload" ] + + public_deps = [ + "${chip_root}/src/platform:platform_base", + "${chip_root}/third_party/inipp", + ] + + public_configs = [] + + if (chip_mdns != "none") { + sources += [ + "../Linux/DnssdImpl.cpp", + "../Linux/DnssdImpl.h", + ] + + deps += [ "${chip_root}/src/lib/dnssd:platform_header" ] + + public_configs += [ + ":avahi_client_config", + ":glib", + ":luna-service", + ] + } + + print("### enable_wifi = ${chip_enable_wifi}") + if (chip_enable_wifi) { + # TBD: Use webOS specific Wi-Fi resource + #public_deps += [ "dbus/wpa" ] + } + + print("### enable_ble = ${chip_enable_ble}") + + if (chip_enable_ble) { + # TBD: Use webOS specific Bluetooth resource + #public_deps += [ "dbus/bluez" ] + } +} diff --git a/src/platform/webos/BlePlatformConfig.h b/src/platform/webos/BlePlatformConfig.h new file mode 100644 index 00000000000000..97ebdb565f6b05 --- /dev/null +++ b/src/platform/webos/BlePlatformConfig.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 + * Platform-specific configuration overrides for the CHIP BLE + * Layer on webOS platforms. + * + */ + +#pragma once + +namespace chip { +namespace DeviceLayer { +namespace Internal { +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +// ==================== Platform Adaptations ==================== +#define BLE_CONNECTION_UNINITIALIZED nullptr +// ========== Platform-specific Configuration Overrides ========= + +/* none so far */ diff --git a/src/platform/webos/CHIPDevicePlatformConfig.h b/src/platform/webos/CHIPDevicePlatformConfig.h new file mode 100644 index 00000000000000..9a8fe4f699ebaa --- /dev/null +++ b/src/platform/webos/CHIPDevicePlatformConfig.h @@ -0,0 +1,88 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 + * Platform-specific configuration overrides for the chip Device Layer + * on webOS platforms. + */ + +#pragma once + +// ==================== Platform Adaptations ==================== + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 +#else +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 +#endif + +#ifndef CHIP_DEVICE_CONFIG_ENABLE_THREAD +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ENABLE_OPENTHREAD +#endif + +#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 0 +#endif + +#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 0 + +#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1 + +// ========== Platform-specific Configuration ========= + +// These are configuration options that are unique to webOs platforms. +// These can be overridden by the application as needed. + +/** + * @def CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY + * + * The priority of the SoftDevice observer event handler registered by the + * CHIP BleLayer. + */ +#ifndef CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY +#define CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY 3 +#endif // CHIP_DEVICE_LAYER_BLE_OBSERVER_PRIORITY + +/** + * @def CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG + * + * The SoftDevice BLE connection configuration tag used by the CHIP + * BleLayer. + */ +#ifndef CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG +#define CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG 1 +#endif // CHIP_DEVICE_LAYER_BLE_CONN_CFG_TAG + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 8192 +#endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE + +#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 +#endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE + +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY 0 +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 + +// TODO: CHIP has redesigned the crypto interface, pending on the final version of CHIP HASH APIs +#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0 diff --git a/src/platform/webos/CHIPDevicePlatformEvent.h b/src/platform/webos/CHIPDevicePlatformEvent.h new file mode 100644 index 00000000000000..69f1ed58bcd410 --- /dev/null +++ b/src/platform/webos/CHIPDevicePlatformEvent.h @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * 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 + * Defines platform-specific event types and data for the chip + * Device Layer on webOS platforms. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { + +namespace DeviceEventType { + +/** + * Enumerates webOS platform-specific event types that are visible to the application. + */ +enum PublicPlatformSpecificEventTypes +{ + /* None currently defined */ +}; + +/** + * Enumerates webOS platform-specific event types that are internal to the chip Device Layer. + */ +enum InternalPlatformSpecificEventTypes +{ + /* None currently defined */ +}; + +} // namespace DeviceEventType + +/** + * Represents platform-specific event information for webOS platforms. + */ +struct ChipDevicePlatformEvent +{ + union + { + /* None currently defined */ + }; +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/CHIPPlatformConfig.h b/src/platform/webos/CHIPPlatformConfig.h new file mode 100644 index 00000000000000..56f591e74b9a72 --- /dev/null +++ b/src/platform/webos/CHIPPlatformConfig.h @@ -0,0 +1,125 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 + * Platform-specific configuration overrides for CHIP on + * webOS platforms. + */ + +#pragma once + +// ==================== General Platform Adaptations ==================== + +#define CHIP_CONFIG_ABORT() abort() + +// TODO:(#756) Add FabricState support +#define CHIP_CONFIG_ENABLE_FABRIC_STATE 0 + +using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *; +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 16 + +#define CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY "life-count" + +#define CHIP_CONFIG_TIME_ENABLE_CLIENT 1 +#define CHIP_CONFIG_TIME_ENABLE_SERVER 0 + +#define CHIP_CONFIG_ERROR_FORMAT_AS_STRING 1 +#define CHIP_CONFIG_ERROR_SOURCE 1 + +#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 1 + +// ==================== Security Adaptations ==================== + +#define CHIP_CONFIG_USE_OPENSSL_ECC 0 +#define CHIP_CONFIG_USE_MICRO_ECC 0 + +#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 1 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 +#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0 +#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 1 +#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 0 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_CHIPDRBG 1 +#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 + +#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 0 +#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1 +#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1 + +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1 + +#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 0 + +#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 0 + +// ==================== General Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_PEER_NODES +#define CHIP_CONFIG_MAX_PEER_NODES 16 +#endif // CHIP_CONFIG_MAX_PEER_NODES + +#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS +#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 8 +#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + +#ifndef CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS +#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS 8 +#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS + +#ifndef CHIP_CONFIG_MAX_ACTIVE_CHANNELS +#define CHIP_CONFIG_MAX_ACTIVE_CHANNELS 16 +#endif // CHIP_CONFIG_MAX_ACTIVE_CHANNELS + +#ifndef CHIP_CONFIG_MAX_CHANNEL_HANDLES +#define CHIP_CONFIG_MAX_CHANNEL_HANDLES 32 +#endif // CHIP_CONFIG_MAX_CHANNEL_HANDLES + +#ifndef CHIP_LOG_FILTERING +#define CHIP_LOG_FILTERING 0 +#endif // CHIP_LOG_FILTERING + +#ifndef CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS +#define CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS 1 +#endif // CHIP_CONFIG_BDX_MAX_NUM_TRANSFERS + +// ==================== Security Configuration Overrides ==================== + +#ifndef CHIP_CONFIG_MAX_APPLICATION_GROUPS +#define CHIP_CONFIG_MAX_APPLICATION_GROUPS 4 +#endif // CHIP_CONFIG_MAX_APPLICATION_GROUPS + +#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION +#define CHIP_CONFIG_DEBUG_CERT_VALIDATION 0 +#endif // CHIP_CONFIG_DEBUG_CERT_VALIDATION + +#ifndef CHIP_CONFIG_ENABLE_CASE_RESPONDER +#define CHIP_CONFIG_ENABLE_CASE_RESPONDER 1 +#endif // CHIP_CONFIG_ENABLE_CASE_RESPONDER + +#ifndef CHIP_CONFIG_KVS_PATH +#define CHIP_CONFIG_KVS_PATH "/tmp/chip_kvs" +#endif // CHIP_CONFIG_KVS_PATH diff --git a/src/platform/webos/ConnectivityManagerImpl.cpp b/src/platform/webos/ConnectivityManagerImpl.cpp new file mode 100644 index 00000000000000..261bbf72074d10 --- /dev/null +++ b/src/platform/webos/ConnectivityManagerImpl.cpp @@ -0,0 +1,253 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2019 Nest Labs, Inc. + * + * 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 +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +#include +#endif + +#ifndef CHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD +#define CHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD "dhclient -nw %s" +#endif + +using namespace ::chip; +using namespace ::chip::TLV; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceLayer::Internal; +using namespace ::chip::app::Clusters::GeneralDiagnostics; +using namespace ::chip::app::Clusters::WiFiNetworkDiagnostics; + +using namespace ::chip::DeviceLayer::NetworkCommissioning; + +namespace chip { +namespace DeviceLayer { + +ConnectivityManagerImpl ConnectivityManagerImpl::sInstance; + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI +char ConnectivityManagerImpl::sWiFiIfName[]; +#endif + +WiFiDriver::ScanCallback * ConnectivityManagerImpl::mpScanCallback; +NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * ConnectivityManagerImpl::mpConnectCallback; + +CHIP_ERROR ConnectivityManagerImpl::_Init() +{ + return CHIP_NO_ERROR; +} + +void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) {} + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +bool ConnectivityManagerImpl::mAssociattionStarted = false; +BitFlags::ConnectivityFlags> + ConnectivityManagerImpl::mConnectivityFlag; +struct GDBusWpaSupplicant ConnectivityManagerImpl::mWpaSupplicant; +std::mutex ConnectivityManagerImpl::mWpaSupplicantMutex; + +ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode() +{ + return mWiFiStationMode; +} + +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode(ConnectivityManager::WiFiStationMode val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +System::Clock::Timeout ConnectivityManagerImpl::_GetWiFiStationReconnectInterval() +{ + return mWiFiStationReconnectInterval; +} + +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationReconnectInterval(System::Clock::Timeout val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +bool ConnectivityManagerImpl::_IsWiFiStationEnabled() +{ + return true; +} + +bool ConnectivityManagerImpl::_IsWiFiStationConnected() +{ + return true; +} + +bool ConnectivityManagerImpl::_IsWiFiStationApplicationControlled() +{ + return mWiFiStationMode == ConnectivityManager::kWiFiStationMode_ApplicationControlled; +} + +bool ConnectivityManagerImpl::_IsWiFiStationProvisioned() +{ + return true; +} + +void ConnectivityManagerImpl::_ClearWiFiStationProvision() {} + +bool ConnectivityManagerImpl::_CanStartWiFiScan() +{ + return true; +} + +CHIP_ERROR ConnectivityManagerImpl::_SetWiFiAPMode(WiFiAPMode val) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void ConnectivityManagerImpl::_DemandStartWiFiAP() {} + +void ConnectivityManagerImpl::_StopOnDemandWiFiAP() {} + +void ConnectivityManagerImpl::_MaintainOnDemandWiFiAP() {} + +void ConnectivityManagerImpl::_SetWiFiAPIdleTimeout(System::Clock::Timeout val) {} + +void ConnectivityManagerImpl::_OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Interface * proxy, GVariant * changed_properties, + const gchar * const * invalidated_properties, gpointer user_data) +{} + +void ConnectivityManagerImpl::_OnWpaInterfaceProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data) {} + +void ConnectivityManagerImpl::_OnWpaBssProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data) {} + +void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * source_object, GAsyncResult * res, gpointer user_data) {} + +void ConnectivityManagerImpl::_OnWpaInterfaceAdded(WpaFiW1Wpa_supplicant1 * proxy, const gchar * path, GVariant * properties, + gpointer user_data) +{} + +void ConnectivityManagerImpl::_OnWpaInterfaceRemoved(WpaFiW1Wpa_supplicant1 * proxy, const gchar * path, GVariant * properties, + gpointer user_data) +{} + +void ConnectivityManagerImpl::_OnWpaProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data) {} + +void ConnectivityManagerImpl::StartWiFiManagement() {} + +bool ConnectivityManagerImpl::IsWiFiManagementStarted() +{ + return true; +} + +void ConnectivityManagerImpl::DriveAPState() {} + +CHIP_ERROR ConnectivityManagerImpl::ConfigureWiFiAP() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void ConnectivityManagerImpl::ChangeWiFiAPState(WiFiAPState newState) {} + +void ConnectivityManagerImpl::DriveAPState(::chip::System::Layer * aLayer, void * aAppState) +{ + sInstance.DriveAPState(); +} + +CHIP_ERROR +ConnectivityManagerImpl::ConnectWiFiNetworkAsync(ByteSpan ssid, ByteSpan credentials, + NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * apCallback) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void ConnectivityManagerImpl::_ConnectWiFiNetworkAsyncCallback(GObject * source_object, GAsyncResult * res, gpointer user_data) {} + +CHIP_ERROR ConnectivityManagerImpl::ProvisionWiFiNetwork(const char * ssid, const char * key) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +void ConnectivityManagerImpl::PostNetworkConnect() {} + +CHIP_ERROR ConnectivityManagerImpl::CommitConfig() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ConnectivityManagerImpl::GetWiFiBssId(ByteSpan & value) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ConnectivityManagerImpl::GetWiFiSecurityType(uint8_t & securityType) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ConnectivityManagerImpl::GetWiFiVersion(uint8_t & wiFiVersion) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ConnectivityManagerImpl::GetConnectedNetwork(NetworkCommissioning::Network & network) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ConnectivityManagerImpl::StopAutoScan() +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR ConnectivityManagerImpl::StartWiFiScan(ByteSpan ssid, WiFiDriver::ScanCallback * callback) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +bool ConnectivityManagerImpl::_GetBssInfo(const gchar * bssPath, NetworkCommissioning::WiFiScanResponse & result) +{ + return true; +} + +void ConnectivityManagerImpl::_OnWpaInterfaceScanDone(GObject * source_object, GAsyncResult * res, gpointer user_data) {} + +#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/ConnectivityManagerImpl.h b/src/platform/webos/ConnectivityManagerImpl.h new file mode 100644 index 00000000000000..24ee5ec40444ad --- /dev/null +++ b/src/platform/webos/ConnectivityManagerImpl.h @@ -0,0 +1,271 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * Copyright (c) 2018 Nest Labs, Inc. + * + * 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. + */ + +#pragma once + +#include +#include +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#include +#else +#include +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#else +#include +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +#include +#else +#include +#endif + +#include +#include + +namespace chip { +namespace Inet { +class IPAddress; +} // namespace Inet +} // namespace chip + +namespace chip { +namespace DeviceLayer { + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +struct GDBusWpaSupplicant +{ + enum + { + INIT, + WPA_CONNECTING, + WPA_CONNECTED, + WPA_NOT_CONNECTED, + WPA_NO_INTERFACE_PATH, + WPA_GOT_INTERFACE_PATH, + WPA_INTERFACE_CONNECTED, + } state; + + enum + { + WIFI_SCANNING_IDLE, + WIFI_SCANNING, + } scanState; + + WpaFiW1Wpa_supplicant1 * proxy; + WpaFiW1Wpa_supplicant1Interface * iface; + WpaFiW1Wpa_supplicant1BSS * bss; + gchar * interfacePath; + gchar * networkPath; +}; +#endif + +/** + * Concrete implementation of the ConnectivityManager singleton object for webOs platforms. + */ +class ConnectivityManagerImpl final : public ConnectivityManager, +#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + public Internal::GenericConnectivityManagerImpl_BLE, +#else + public Internal::GenericConnectivityManagerImpl_NoBLE, +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + public Internal::GenericConnectivityManagerImpl_Thread, +#else + public Internal::GenericConnectivityManagerImpl_NoThread, +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + public Internal::GenericConnectivityManagerImpl_WiFi, +#else + public Internal::GenericConnectivityManagerImpl_NoWiFi, +#endif + public Internal::GenericConnectivityManagerImpl +{ + // Allow the ConnectivityManager interface class to delegate method calls to + // the implementation methods provided by this class. + friend class ConnectivityManager; + +public: +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + CHIP_ERROR ProvisionWiFiNetwork(const char * ssid, const char * key); + CHIP_ERROR ConnectWiFiNetworkAsync(ByteSpan ssid, ByteSpan credentials, + NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * connectCallback); + void PostNetworkConnect(); + static void _ConnectWiFiNetworkAsyncCallback(GObject * source_object, GAsyncResult * res, gpointer user_data); + CHIP_ERROR CommitConfig(); + + void StartWiFiManagement(); + bool IsWiFiManagementStarted(); + CHIP_ERROR GetWiFiBssId(ByteSpan & value); + CHIP_ERROR GetWiFiSecurityType(uint8_t & securityType); + CHIP_ERROR GetWiFiVersion(uint8_t & wiFiVersion); + CHIP_ERROR GetConnectedNetwork(NetworkCommissioning::Network & network); + CHIP_ERROR StartWiFiScan(ByteSpan ssid, NetworkCommissioning::WiFiDriver::ScanCallback * callback); +#endif + + const char * GetEthernetIfName() { return (mEthIfName[0] == '\0') ? nullptr : mEthIfName; } + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + static const char * GetWiFiIfName() { return (sWiFiIfName[0] == '\0') ? nullptr : sWiFiIfName; } +#endif + +private: + // ===== Members that implement the ConnectivityManager abstract interface. + + struct WiFiNetworkScanned + { + // The fields matches WiFiInterfaceScanResult::Type. + uint8_t ssid[Internal::kMaxWiFiSSIDLength]; + uint8_t ssidLen; + uint8_t bssid[6]; + int8_t rssi; + uint16_t frequencyBand; + uint8_t channel; + uint8_t security; + }; + + CHIP_ERROR _Init(); + void _OnPlatformEvent(const ChipDeviceEvent * event); + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + WiFiStationMode _GetWiFiStationMode(); + CHIP_ERROR _SetWiFiStationMode(ConnectivityManager::WiFiStationMode val); + System::Clock::Timeout _GetWiFiStationReconnectInterval(); + CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val); + bool _IsWiFiStationEnabled(); + bool _IsWiFiStationConnected(); + bool _IsWiFiStationApplicationControlled(); + bool _IsWiFiStationProvisioned(); + void _ClearWiFiStationProvision(); + bool _CanStartWiFiScan(); + + WiFiAPMode _GetWiFiAPMode(); + CHIP_ERROR _SetWiFiAPMode(WiFiAPMode val); + bool _IsWiFiAPActive(); + bool _IsWiFiAPApplicationControlled(); + void _DemandStartWiFiAP(); + void _StopOnDemandWiFiAP(); + void _MaintainOnDemandWiFiAP(); + System::Clock::Timeout _GetWiFiAPIdleTimeout(); + void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); + static CHIP_ERROR StopAutoScan(); + + static void _OnWpaProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data); + static void _OnWpaInterfaceRemoved(WpaFiW1Wpa_supplicant1 * proxy, const gchar * path, GVariant * properties, + gpointer user_data); + static void _OnWpaInterfaceAdded(WpaFiW1Wpa_supplicant1 * proxy, const gchar * path, GVariant * properties, gpointer user_data); + static void _OnWpaPropertiesChanged(WpaFiW1Wpa_supplicant1Interface * proxy, GVariant * changed_properties, + const gchar * const * invalidated_properties, gpointer user_data); + static void _OnWpaInterfaceReady(GObject * source_object, GAsyncResult * res, gpointer user_data); + static void _OnWpaInterfaceProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data); + static void _OnWpaBssProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data); + static void _OnWpaInterfaceScanDone(GObject * source_object, GAsyncResult * res, gpointer user_data); + + static bool _GetBssInfo(const gchar * bssPath, NetworkCommissioning::WiFiScanResponse & result); + + static bool mAssociattionStarted; + static BitFlags mConnectivityFlag; + static struct GDBusWpaSupplicant mWpaSupplicant; + static std::mutex mWpaSupplicantMutex; +#endif + + // ==================== ConnectivityManager Private Methods ==================== + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + void DriveAPState(); + CHIP_ERROR ConfigureWiFiAP(); + void ChangeWiFiAPState(WiFiAPState newState); + static void DriveAPState(::chip::System::Layer * aLayer, void * aAppState); +#endif + + // ===== Members for internal use by the following friends. + + friend ConnectivityManager & ConnectivityMgr(); + friend ConnectivityManagerImpl & ConnectivityMgrImpl(); + + static ConnectivityManagerImpl sInstance; + + // ===== Private members reserved for use by this class only. + + char mEthIfName[IFNAMSIZ]; + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA + ConnectivityManager::WiFiStationMode mWiFiStationMode; + ConnectivityManager::WiFiAPMode mWiFiAPMode; + WiFiAPState mWiFiAPState; + System::Clock::Timestamp mLastAPDemandTime; + System::Clock::Timeout mWiFiStationReconnectInterval; + System::Clock::Timeout mWiFiAPIdleTimeout; +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + static char sWiFiIfName[IFNAMSIZ]; +#endif + + static NetworkCommissioning::WiFiDriver::ScanCallback * mpScanCallback; + static NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * mpConnectCallback; +}; + +#if CHIP_DEVICE_CONFIG_ENABLE_WPA +inline ConnectivityManager::WiFiAPMode ConnectivityManagerImpl::_GetWiFiAPMode() +{ + return mWiFiAPMode; +} + +inline bool ConnectivityManagerImpl::_IsWiFiAPActive() +{ + return mWiFiAPState == kWiFiAPState_Active; +} + +inline bool ConnectivityManagerImpl::_IsWiFiAPApplicationControlled() +{ + return mWiFiAPMode == kWiFiAPMode_ApplicationControlled; +} + +inline System::Clock::Timeout ConnectivityManagerImpl::_GetWiFiAPIdleTimeout() +{ + return mWiFiAPIdleTimeout; +} + +#endif + +/** + * Returns the public interface of the ConnectivityManager singleton object. + * + * chip applications should use this to access features of the ConnectivityManager object + * that are common to all platforms. + */ +inline ConnectivityManager & ConnectivityMgr() +{ + return ConnectivityManagerImpl::sInstance; +} + +/** + * Returns the platform-specific implementation of the ConnectivityManager singleton object. + * + * chip applications can use this to gain access to features of the ConnectivityManager + * that are specific to the ESP32 platform. + */ +inline ConnectivityManagerImpl & ConnectivityMgrImpl() +{ + return ConnectivityManagerImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/webos/DeviceNetworkProvisioningDelegateImpl.cpp new file mode 100644 index 00000000000000..8faa2822ea1487 --- /dev/null +++ b/src/platform/webos/DeviceNetworkProvisioningDelegateImpl.cpp @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 "DeviceNetworkProvisioningDelegateImpl.h" + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionWiFiNetwork(const char * ssid, const char * key) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/DeviceNetworkProvisioningDelegateImpl.h b/src/platform/webos/DeviceNetworkProvisioningDelegateImpl.h new file mode 100644 index 00000000000000..60fd94ec10433b --- /dev/null +++ b/src/platform/webos/DeviceNetworkProvisioningDelegateImpl.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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. + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { + +namespace Internal { + +template +class GenericDeviceNetworkProvisioningDelegateImpl; + +} // namespace Internal + +class DeviceNetworkProvisioningDelegateImpl final + : public Internal::GenericDeviceNetworkProvisioningDelegateImpl +{ + friend class GenericDeviceNetworkProvisioningDelegateImpl; + +private: + CHIP_ERROR _ProvisionWiFiNetwork(const char * ssid, const char * passwd); + CHIP_ERROR _ProvisionThreadNetwork(ByteSpan threadData) { return CHIP_ERROR_NOT_IMPLEMENTED; } +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/InetPlatformConfig.h b/src/platform/webos/InetPlatformConfig.h new file mode 100644 index 00000000000000..bde1ae20aa1285 --- /dev/null +++ b/src/platform/webos/InetPlatformConfig.h @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 + * Platform-specific configuration overrides for the CHIP Inet + * Layer on webOS platforms. + * + */ + +#pragma once + +// ==================== Platform Adaptations ==================== + +#ifndef INET_CONFIG_ENABLE_IPV4 +#error Inet IPv4 configuration should be configured at build generation time +#endif + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef INET_CONFIG_NUM_TCP_ENDPOINTS +#define INET_CONFIG_NUM_TCP_ENDPOINTS 32 +#endif // INET_CONFIG_NUM_TCP_ENDPOINTS + +#ifndef IPV6_MULTICAST_IMPLEMENTED +#define IPV6_MULTICAST_IMPLEMENTED +#endif + +#ifndef INET_CONFIG_NUM_UDP_ENDPOINTS +#define INET_CONFIG_NUM_UDP_ENDPOINTS 32 +#endif // INET_CONFIG_NUM_UDP_ENDPOINTS + +// On linux platform, we have sys/socket.h, so HAVE_SO_BINDTODEVICE should be set to 1 +#define HAVE_SO_BINDTODEVICE 1 diff --git a/src/platform/webos/Logging.cpp b/src/platform/webos/Logging.cpp new file mode 100644 index 00000000000000..5f8aeb57e73575 --- /dev/null +++ b/src/platform/webos/Logging.cpp @@ -0,0 +1,52 @@ +/* See Project CHIP LICENSE file for licensing information. */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +/** + * Called whenever a log message is emitted by chip or LwIP. + * + * This function is intended be overridden by the application to, e.g., + * schedule output of queued log entries. + */ +void __attribute__((weak)) OnLogOutput() {} + +} // namespace DeviceLayer + +namespace Logging { +namespace Platform { + +/** + * CHIP log output functions. + */ +void ENFORCE_FORMAT(3, 0) LogV(const char * module, uint8_t category, const char * msg, va_list v) +{ + struct timeval tv; + + // Should not fail per man page of gettimeofday(), but failed to get time is not a fatal error in log. The bad time value will + // indicate the error occurred during getting time. + gettimeofday(&tv, nullptr); + + printf("[%" PRIu64 ".%06" PRIu64 "][%lld:%lld] CHIP:%s: ", static_cast(tv.tv_sec), static_cast(tv.tv_usec), + static_cast(syscall(SYS_getpid)), static_cast(syscall(SYS_gettid)), module); + vprintf(msg, v); + printf("\n"); + fflush(stdout); + + // Let the application know that a log message has been emitted. + DeviceLayer::OnLogOutput(); +} + +} // namespace Platform +} // namespace Logging +} // namespace chip diff --git a/src/platform/webos/SystemPlatformConfig.h b/src/platform/webos/SystemPlatformConfig.h new file mode 100644 index 00000000000000..6a74853d884b78 --- /dev/null +++ b/src/platform/webos/SystemPlatformConfig.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * 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 + * Platform-specific configuration overrides for the CHIP System + * Layer on webOS platforms. + * + */ + +#pragma once + +#include + +namespace chip { +namespace DeviceLayer { +struct ChipDeviceEvent; +} // namespace DeviceLayer +} // namespace chip + +// ==================== Platform Adaptations ==================== + +#define CHIP_SYSTEM_CONFIG_POSIX_LOCKING 1 +#define CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING 0 +#define CHIP_SYSTEM_CONFIG_NO_LOCKING 0 +#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1 +#define CHIP_SYSTEM_CONFIG_POOL_USE_HEAP 1 + +// ========== Platform-specific Configuration Overrides ========= + +#ifndef CHIP_SYSTEM_CONFIG_NUM_TIMERS +#define CHIP_SYSTEM_CONFIG_NUM_TIMERS 16 +#endif // CHIP_SYSTEM_CONFIG_NUM_TIMERS + +#define CHIP_CONFIG_MDNS_CACHE_SIZE 4 diff --git a/src/platform/webos/args.gni b/src/platform/webos/args.gni new file mode 100644 index 00000000000000..beaab239d840fc --- /dev/null +++ b/src/platform/webos/args.gni @@ -0,0 +1,15 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# 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. + +chip_device_platform = "webos" diff --git a/third_party/webos_sdk b/third_party/webos_sdk new file mode 160000 index 00000000000000..53dbcce3f50024 --- /dev/null +++ b/third_party/webos_sdk @@ -0,0 +1 @@ +Subproject commit 53dbcce3f50024d9ac0c7742286a579c3a8b63a9