Skip to content

Commit

Permalink
Revert "[nxp noup][platform][mw320] Adding platform code changes"
Browse files Browse the repository at this point in the history
This reverts commit b760c08.

Signed-off-by: Dina Benamar <[email protected]>
  • Loading branch information
dinabenamar committed Feb 26, 2024
1 parent 42ca5db commit f1a2b5a
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 698 deletions.
87 changes: 9 additions & 78 deletions src/lib/shell/MainLoopMW320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <lib/shell/Engine.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/CommissionableDataProvider.h>
#include <platform/nxp/mw320/ConnectivityUtils.h>

#include <ctype.h>
#include <stdio.h>
Expand All @@ -29,11 +28,7 @@

extern "C" {
#include "wlan.h"
#include "network_flash_storage.h"
void test_wlan_scan(int argc, char ** argv);
}
#include "AppTask.h"
#include "mw320_ota.h"

using chip::FormatCHIPError;
using chip::Shell::Engine;
Expand Down Expand Up @@ -156,6 +151,7 @@ int TokenizeLine(char * buffer, char ** tokens, int max_tokens)
} // namespace

extern const char * mw320_get_verstr(void);
extern void save_network(char * ssid, char * pwd);
namespace chip {
namespace Shell {

Expand Down Expand Up @@ -183,7 +179,8 @@ static void AtExitShell(void)

static CHIP_ERROR VersionHandler(int argc, char ** argv)
{
streamer_printf(streamer_get(), "mw320 firmware: %s\r\n", mw320_get_verstr());
// streamer_printf(streamer_get(), "CHIP %s\r\n", CHIP_VERSION_STRING);
streamer_printf(streamer_get(), "CHIP %s\r\n", mw320_get_verstr());
return CHIP_NO_ERROR;
}

Expand All @@ -201,12 +198,12 @@ static CHIP_ERROR SetDefAPHandler(int argc, char ** argv)
{
VerifyOrReturnError(argc == 2, CHIP_ERROR_INVALID_ARGUMENT);
PRINTF("[%s], [%s] \r\n", argv[0], argv[1]);
GetAppTask().SaveNetwork(argv[0], argv[1]);
save_network(argv[0], argv[1]);

return CHIP_NO_ERROR;
}

static CHIP_ERROR WlanStateHandler(int argc, char ** argv)
static CHIP_ERROR wlan_state_handler(int argc, char ** argv)
{
enum wlan_connection_state state;
int result;
Expand Down Expand Up @@ -240,89 +237,23 @@ static CHIP_ERROR WlanStateHandler(int argc, char ** argv)
return CHIP_NO_ERROR;
}

static CHIP_ERROR WlanAbortHandler(int argc, char ** argv)
static CHIP_ERROR wlan_abort_handler(int argc, char ** argv)
{
#ifdef WIFI_CONN_ABORT_SUPPORT
wlan_abort_connect();
#endif // WIFI_CONN_ABORT_SUPPORT
return CHIP_NO_ERROR;
}

static CHIP_ERROR WlanConnHandler(int argc, char ** argv)
{
VerifyOrReturnError(argc == 2, CHIP_ERROR_INVALID_ARGUMENT);
PRINTF("[%s], [%s] \r\n", argv[0], argv[1]);
//::connect_wifi_network(argv[0], argv[1]);
chip::DeviceLayer::Internal::ConnectivityUtils::ConnectWiFiNetwork(argv[0], argv[1]);
return CHIP_NO_ERROR;
}

static CHIP_ERROR WlanScanHandler(int argc, char ** argv)
{
test_wlan_scan(0, NULL);
return CHIP_NO_ERROR;
}

static CHIP_ERROR FactoryRstHandler(int argc, char **argv)
{
// Eraseing the saved parameters
::erase_all_params();
// Do factory reset from Matter Stack
chip::Server::GetInstance().ScheduleFactoryReset();
if (argc == 1) {
if (!strcmp(argv[0], "1")) {
// Set default AP
GetAppTask().SaveNetwork((char*)DEFAP_SSID, (char*)DEFAP_PWD);
// Set op_state to working
GetAppTask().SetOpState(work_state);
}
}
// Reboot the device
::mw320_dev_reset(1000);

return CHIP_NO_ERROR;
}

static CHIP_ERROR SetOpStatHandler(int argc, char ** argv)
{
op_state_t opstat;
VerifyOrReturnError(argc == 1, CHIP_ERROR_INVALID_ARGUMENT);
opstat = (op_state_t)atoi(argv[0]);
VerifyOrReturnError(opstat < max_op_state, CHIP_ERROR_INVALID_ARGUMENT);
PRINTF("Operation State: %d\r\n", (int)opstat);
GetAppTask().SetOpState(opstat);
return CHIP_NO_ERROR;
}

static CHIP_ERROR GetOpStatHandler(int argc, char ** argv)
{
op_state_t opstat = GetAppTask().GetOpState();
PRINTF("Current operation state: %d \r\n", (int)opstat);
return CHIP_NO_ERROR;
}

static CHIP_ERROR CmdRebootHandler(int argc, char ** argv)
{
::mw320_dev_reset(1000);
return CHIP_NO_ERROR;
}


static void RegisterMetaCommands(void)
{
static shell_command_t sCmds[] = {
{ &ShutdownHandler, "shutdown", "Exit the shell application" },
{ &VersionHandler, "version", "Output the software version" },
{ &SetPinCodeHandler, "pincode", "Set the pin code" },
{ &SetDefAPHandler, "set-defap", "Set default AP SSID/PWD" },
{ &WlanStateHandler, "wlan-stat", "Check the wifi status" },
{ &WlanAbortHandler, "wlan-abort", "Abort the scan/reconnect" },
{ &WlanConnHandler, "wlan-connect", "Connect to AP" },
{ &WlanScanHandler, "wlan-scan", "Scan the environment"},
{ &FactoryRstHandler, "factory-reset", "Do factory reset"},
{ &SetOpStatHandler, "set-opstate", "Set the Operation State [0:factory_rest|1:work]"},
{ &GetOpStatHandler, "get-opstate", "Get the Operation State [0:factory_rest|1:work]"},
{ &CmdRebootHandler, "reboot", "Reboot the device"},
{ &SetDefAPHandler, "set_defap", "Set default AP SSID/PWD" },
{ &wlan_state_handler, "wlan-stat", "Check the wifi status" },
{ &wlan_abort_handler, "wlan-abort", "Abort the scan/reconnect" },
};

std::atexit(AtExitShell);
Expand Down
20 changes: 2 additions & 18 deletions src/platform/nxp/mw320/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ if (chip_enable_openthread) {
import("//build_overrides/openthread.gni")
}

if (chip_crypto == "platform") {
import("//build_overrides/mbedtls.gni")
}


static_library("mw320") {
sources = [
"../../FreeRTOS/SystemTimeSupport.cpp",
Expand Down Expand Up @@ -66,8 +61,8 @@ static_library("mw320") {

if (chip_with_factory_data == 1) {
sources += [
"MW320FactoryDataProvider.cpp",
"MW320FactoryDataProvider.h",
"FactoryDataProvider.cpp",
"FactoryDataProvider.h",
]
}

Expand All @@ -83,17 +78,6 @@ static_library("mw320") {

public_deps = [ "${chip_root}/src/platform:platform_base" ]

if (chip_crypto == "platform") {
if (chip_crypto_flavour == "tinycrypt") {
sources += [
"${chip_root}/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp",
]
public_deps += [
"${mbedtls_root}:mbedtls",
]
}
}

if (chip_enable_openthread) {
sources += [
"../../OpenThread/OpenThreadUtils.cpp",
Expand Down
11 changes: 3 additions & 8 deletions src/platform/nxp/mw320/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@
#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

// mdns/mdns_sd ++
//#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DISCOVERY 1
#define CHIP_DEVICE_CONFIG_ENABLE_DNSSD 1
// mdns/dns_sd --
#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
2 changes: 2 additions & 0 deletions src/platform/nxp/mw320/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ inline CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * b
wifi_get_device_mac_addr(&mac_addr);

memcpy(buf, mac_addr.mac, 6);
PRINTF("MAC: %02x:%02x:%02x:%02x:%02x:%02x \r\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
// return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
return CHIP_NO_ERROR;
}

Expand Down
16 changes: 1 addition & 15 deletions src/platform/nxp/mw320/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/GenericConnectivityManagerImpl_UDP.ipp>
#include <platform/nxp/mw320/ConnectivityManagerImpl.h>
#include <platform/nxp/mw320/ConnectivityUtils.h>

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <platform/internal/GenericConnectivityManagerImpl_TCP.ipp>
Expand All @@ -46,7 +45,6 @@ void test_wlan_scan(int argc, char ** argv);
void test_wlan_add(int argc, char ** argv);
static struct wlan_network sta_network;
}
#include "AppTask.h"

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.ipp>
Expand Down Expand Up @@ -117,14 +115,6 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
{
// Forward the event to the generic base classes as needed.
switch (event->Type)
{
case DeviceEventType::kCommissioningComplete:
PRINTF("====> DeviceEventType::kCommissioningComplete\r\n");
break;
default:
break;
}
}

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
Expand Down Expand Up @@ -345,11 +335,7 @@ ConnectivityManagerImpl::ConnectWiFiNetworkAsync(ByteSpan ssid, ByteSpan credent
//
memcpy(sCfgSSID, ssidStr, ssid.size());
sCfgSSIDLen = ssid.size();

ChipLogProgress(DeviceLayer, "ConnectWiFiNetworkAsync: [ssid, pwd]=[%s, %s]", ssidStr, keyStr);
// Do connection
chip::DeviceLayer::Internal::ConnectivityUtils::ConnectWiFiNetwork(ssidStr, keyStr);

//
mpConnectCallback = apCallback;
#if (MW320_CONNECT_SCAN_SYNC == 1)
if (mpConnectCallback != nullptr)
Expand Down
64 changes: 8 additions & 56 deletions src/platform/nxp/mw320/ConnectivityUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ CHIP_ERROR ConnectivityUtils::GetInterfaceIPv6Addrs(const char * ifname, uint8_t
return CHIP_NO_ERROR;
}

for (i = 0; i < CONFIG_MAX_IPV6_ADDRESSES; i++)
for (i = 0; i < MAX_IPV6_ADDRESSES; i++)
{
if (sta_network.ip.ipv6[i].addr_state == IP6_ADDR_INVALID)
{
Expand Down Expand Up @@ -341,46 +341,39 @@ CHIP_ERROR ConnectivityUtils::GetWiFiRssi(const char * ifname, int8_t & rssi)
return err;
}


CHIP_ERROR ConnectivityUtils::GetWiFiBeaconRxCount(const char * ifname, uint32_t & beaconRxCount)
{
CHIP_ERROR err = CHIP_NO_ERROR;
#ifdef GET_FROM_SDK
int ret;
static wifi_pkt_stats_t stats;
wifi_pkt_stats_t stats;

ret = wifi_get_log(&stats);
if (ret != WM_SUCCESS)
{
ChipLogError(DeviceLayer, "wifi_get_log failed ");
}

beaconRxCount = stats.bcn_rcv_cnt;
ChipLogProgress(DeviceLayer, "GetWiFiBeaconRxCount [%ld] -> working in sdk", beaconRxCount);
#else
beaconRxCount = 1024;
ChipLogProgress(DeviceLayer, "GetWiFiBeaconRxCount [%ld]", beaconRxCount);
#endif //GET_FROM_SDK

return err;
}

CHIP_ERROR ConnectivityUtils::GetWiFiBeaconLostCount(const char * ifname, uint32_t & beaconLostCount)
{
CHIP_ERROR err = CHIP_NO_ERROR;
#ifdef GET_FROM_SDK
int ret;
static wifi_pkt_stats_t stats;
wifi_pkt_stats_t stats;

ret = wifi_get_log(&g_stats);
ret = wifi_get_log(&stats);
if (ret != WM_SUCCESS)
{
ChipLogError(DeviceLayer, "wifi_get_log failed ");
}

beaconLostCount = stats.bcn_miss_cnt;
ChipLogProgress(DeviceLayer, "GetWiFiBeaconLostCount [%ld] -> working in sdk", beaconLostCount);
#else
beaconLostCount = 0;
ChipLogProgress(DeviceLayer, "GetWiFiBeaconLostCount [%ld]", beaconLostCount);
#endif //GET_FROM_SDK

return err;
}

Expand All @@ -400,47 +393,6 @@ CHIP_ERROR ConnectivityUtils::GetEthInterfaceName(char * ifname, size_t bufSize)
return err;
}

extern "C" {
void test_wlan_add(int argc, char ** argv);
};

CHIP_ERROR ConnectivityUtils::ConnectWiFiNetwork(const char * ssid, const char * key)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int ret_mcuXpresso;
char arg0[] = "wlan-add";
char arg1[32];
char arg2[] = "ssid";
char arg3[32];
char arg4[] = "wpa2";
char arg5[64];
char * argv[] = { &arg0[0], &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], NULL };
int argc = (int) (sizeof(argv) / sizeof(argv[0])) - 1;

sprintf((char *) arg1, "%s", ssid);
sprintf((char *) arg3, "%s", ssid);
sprintf((char *) arg5, "%s", key);
test_wlan_add(argc, &argv[0]);
ret_mcuXpresso = wlan_connect(argv[1]);
if (ret_mcuXpresso == WLAN_ERROR_STATE)
{
ChipLogProgress(DeviceLayer, "Error: connect manager not running");
err = CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY;
}
if (ret_mcuXpresso == -WM_E_INVAL)
{
ChipLogProgress(DeviceLayer, "Error: specify a network to connect");
err = CHIP_ERROR_INVALID_ARGUMENT;
}
else
{
ChipLogProgress(DeviceLayer,
"Connecting to network...\r\nUse 'wlan-stat' for "
"current connection status.");
}
return err;
}

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
1 change: 0 additions & 1 deletion src/platform/nxp/mw320/ConnectivityUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ConnectivityUtils
static CHIP_ERROR GetEthInterfaceName(char * ifname, size_t bufSize);
// static CHIP_ERROR GetEthPHYRate(const char * ifname, app::Clusters::EthernetNetworkDiagnostics::PHYRateEnum & pHYRate);
// static CHIP_ERROR GetEthFullDuplex(const char * ifname, bool & fullDuplex);
static CHIP_ERROR ConnectWiFiNetwork(const char * ssid, const char * key);

private:
static uint16_t Map2400MHz(const uint8_t inChannel);
Expand Down
Loading

0 comments on commit f1a2b5a

Please sign in to comment.