blob: 5c00f8bc8028d1cf987f2d8d5725cf838618eeed [file] [log] [blame]
/*
*
* 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.
*/
#pragma once
#include <platform/NetworkCommissioning.h>
#include <vector>
namespace chip {
namespace DeviceLayer {
namespace NetworkCommissioning {
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
class TizenWiFiDriver final : public WiFiDriver
{
public:
class WiFiNetworkIterator final : public NetworkIterator
{
public:
WiFiNetworkIterator(TizenWiFiDriver * aDriver) : driver(aDriver) {}
size_t Count() override;
bool Next(Network & item) override;
void Release() override { delete this; }
~WiFiNetworkIterator() = default;
private:
TizenWiFiDriver * driver;
bool exhausted = false;
};
struct WiFiNetwork
{
uint8_t ssid[DeviceLayer::Internal::kMaxWiFiSSIDLength];
uint8_t ssidLen = 0;
uint8_t credentials[DeviceLayer::Internal::kMaxWiFiKeyLength];
uint8_t credentialsLen = 0;
};
// BaseDriver
NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); }
CHIP_ERROR Init(BaseDriver::NetworkStatusChangeCallback * networkStatusChangeCallback) override;
CHIP_ERROR Shutdown() override { return CHIP_NO_ERROR; }
// WirelessDriver
uint8_t GetMaxNetworks() override { return 1; }
uint8_t GetScanNetworkTimeoutSeconds() override { return 10; }
uint8_t GetConnectNetworkTimeoutSeconds() override { return 20; }
CHIP_ERROR CommitConfiguration() override;
CHIP_ERROR RevertConfiguration() override;
Status RemoveNetwork(ByteSpan networkId) override;
Status ReorderNetwork(ByteSpan networkId, uint8_t index) override;
void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override;
// WiFiDriver
Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override;
void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override;
private:
bool NetworkMatch(const WiFiNetwork & network, ByteSpan networkId);
WiFiNetworkIterator mWiFiIterator = WiFiNetworkIterator(this);
WiFiNetwork mSavedNetwork;
WiFiNetwork mStagingNetwork;
};
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
} // namespace NetworkCommissioning
} // namespace DeviceLayer
} // namespace chip