Skip to content

Commit

Permalink
commit faf307c (HEAD -> feature/SARA-R510-NCP-FW-update, origin/featu…
Browse files Browse the repository at this point in the history
…re/SARA-R510-NCP-FW-update)

Author: Technobly <[email protected]>
Date:   Wed Dec 15 16:26:50 2021 -0600

    reduce specificity of expected publishEvent calls

commit c9d846b
Author: Technobly <[email protected]>
Date:   Wed Dec 15 13:24:25 2021 -0600

    update CI unit tests to output verbose logs on failure

commit 62c8fd9
Author: Technobly <[email protected]>
Date:   Tue Dec 14 13:17:39 2021 -0600

    addresses final PR comments

    - Adds SaraNcpFwUpdateLock to make user interfaces thread-safe
    - Fixes issue with sUrcHandlers not retaining unique pointers
    - Allows cellular disconnect timeouts to proceed
    - Adds cellular_lock() before accessing variables used in urcHandlers
    - Fixes errors with comm. unit_tests caused by some initial code added for ncp_fw_update testing
    - Moves all NCPFW_LOG statements during SAFE_MODE to NCPFW_LOG_DEBUG to reduce size

commit b509fbf
Author: Technobly <[email protected]>
Date:   Fri Dec 10 22:42:52 2021 -0600

    adds system_errors and diagnostics

commit ac13d10
Author: Technobly <[email protected]>
Date:   Tue Nov 30 23:20:27 2021 -0600

    adds SaraNcpFwUpdate unit tests

commit 41f4093
Author: Technobly <[email protected]>
Date:   Mon Nov 22 23:19:58 2021 -0600

    [hal] cellular add/remove urc handler

commit 7c0d8f9
Author: Technobly <[email protected]>
Date:   Mon Nov 15 12:21:38 2021 -0600

    skeleton for SaraNcpFwUpdate unit tests

commit 5bb6334
Author: Technobly <[email protected]>
Date:   Fri Oct 29 20:59:23 2021 -0500

    addresses most PR comments

commit d22aaf6
Author: Technobly <[email protected]>
Date:   Fri Oct 22 15:13:34 2021 -0500

    prevent a dependency issue causing a safe mode loop

commit f762226
Author: Technobly <[email protected]>
Date:   Thu Sep 30 10:36:21 2021 -0500

    Implements background modem update checks, Cellular.updateStatus(), Cellular.enableUpdates()

commit 3d09a76
Author: Technobly <[email protected]>
Date:   Wed Sep 29 13:27:24 2021 -0500

    rebase and whitespace fixes

commit 6c2f5e9
Author: Technobly <[email protected]>
Date:   Mon Sep 27 10:34:43 2021 -0500

    Move modem firmware version check to sara_ncp_client

commit ca5cd65
Author: Technobly <[email protected]>
Date:   Tue Sep 21 17:21:37 2021 -0500

    Revert "Remove more R510 FOTA support"

    This reverts commit 532acce.

commit 59b5ec8
Author: Technobly <[email protected]>
Date:   Mon Sep 20 17:13:28 2021 -0500

    Revert "Remove R510 FOTA support"

    This reverts commit a0b92dd.

commit 6ececed
Author: Technobly <[email protected]>
Date:   Fri Sep 17 22:40:41 2021 -0500

    Removes System feature FEATURE_NCP_FW_UPDATES and some cleanup

commit a78f8c1
Author: Technobly <[email protected]>
Date:   Fri Sep 10 17:04:29 2021 -0500

    Remove R510 support for Gen2

commit 82b8b9f
Author: Technobly <[email protected]>
Date:   Fri Aug 13 09:57:55 2021 -0500

    implements System feature FEATURE_NCP_FW_UPDATES and performs NCP FW update in Safe Mode
  • Loading branch information
technobly committed Jul 19, 2022
1 parent 38d4581 commit e1df053
Show file tree
Hide file tree
Showing 34 changed files with 3,547 additions and 113 deletions.
2 changes: 1 addition & 1 deletion ci/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rm -rf .build/*
mkdir -p .build/
cd .build/
cmake $cmake_args ..
make all test coverage
make all test coverage CTEST_OUTPUT_ON_FAILURE=TRUE

cmake_unit_tests=$?

Expand Down
27 changes: 26 additions & 1 deletion hal/inc/cellular_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,32 @@ cellular_result_t cellular_process(void* reserved, void* reserved1);
/**
* Start NCP FW Update
*/
int cellular_start_ncp_firmware_update(bool update = false, void* reserved = NULL);
int cellular_start_ncp_firmware_update(bool update, void* reserved);

/**
* Get NCP firmware version as a uint32_t
*/
int cellular_get_ncp_firmware_version(uint32_t* version, void* reserved);

/**
* Get modem firmware update status result
*/
int cellular_update_status(void* reserved);

/**
* Enable modem firmware updates (blocking call, requires a pending update)
*/
int cellular_enable_updates(void* reserved);

/**
* Add URC handler
*/
int cellular_add_urc_handler(const char* prefix, hal_cellular_urc_callback_t cb, void* context);

/**
* Remove URC handler
*/
int cellular_remove_urc_handler(const char* prefix);

#ifdef __cplusplus
}
Expand Down
2 changes: 2 additions & 0 deletions hal/inc/cellular_hal_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef int (*_CALLBACKPTR_MDM)(int type, const char* buf, int len, void* param)

typedef void (*_CELLULAR_SMS_CB_MDM)(void* data, int index);

typedef int (*hal_cellular_urc_callback_t)(const char* data, void* context);

#ifdef __cplusplus
// Todo - is storing raw string pointers correct here? These will only be valid
// If they are stored as constants in the application.
Expand Down
2 changes: 2 additions & 0 deletions hal/inc/hal_dynalib_cellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ DYNALIB_FN(36, hal_cellular, cellular_credentials_clear, int(void*))
DYNALIB_FN(37, hal_cellular, cellular_global_identity, cellular_result_t(CellularGlobalIdentity*, void*))
DYNALIB_FN(38, hal_cellular, cellular_registration_timeout_set, cellular_result_t(system_tick_t, void*))
DYNALIB_FN(39, hal_cellular, cellular_urcs, cellular_result_t(bool, void*))
DYNALIB_FN(40, hal_cellular, cellular_update_status, int(void*))
DYNALIB_FN(41, hal_cellular, cellular_enable_updates, int(void*))

DYNALIB_END(hal_cellular)

Expand Down
4 changes: 4 additions & 0 deletions hal/inc/hal_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@
#define HAL_PLATFORM_NCP_COUNT (0)
#endif // HAL_PLATFORM_NCP_COUNT

#ifndef HAL_PLATFORM_NCP_FW_UPDATE
#define HAL_PLATFORM_NCP_FW_UPDATE (0)
#endif // HAL_PLATFORM_NCP_FW_UPDATE

#ifndef HAL_PLATFORM_WIFI_COMPAT
#define HAL_PLATFORM_WIFI_COMPAT (0)
#endif // HAL_PLATFORM_WIFI_COMPAT
Expand Down
96 changes: 96 additions & 0 deletions hal/network/ncp/cellular/cellular_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ifapi.h"

#include "system_network.h" // FIXME: For network_interface_index
#include "spark_wiring_vector.h"

#include "str_util.h"
#include "endian_util.h"
Expand All @@ -35,6 +36,8 @@
#include "cellular_enums_hal.h"
#include "cellular_ncp_dev_mapping.h"

#include "ncp_fw_update.h"

#include <limits>

namespace {
Expand Down Expand Up @@ -106,6 +109,37 @@ hal_net_access_tech_t fromCellularAccessTechnology(CellularAccessTechnology rat)
}
}

struct CellularHalUrcHandler {
CellularHalUrcHandler(const char* prefix, hal_cellular_urc_callback_t callback, void* context) :
prefix(prefix),
callback(callback),
context(context) {
}
const char* prefix;
hal_cellular_urc_callback_t callback;
void* context;
};

Vector<std::unique_ptr<CellularHalUrcHandler>> sUrcHandlers;

static int commonUrcHandler(AtResponseReader* reader, const char* prefix, void* data) {
auto handler = static_cast<CellularHalUrcHandler*>(data);

const size_t atResponseSize = 64;
std::unique_ptr<char[]> atResponse(new(std::nothrow) char[atResponseSize]);
CHECK_TRUE(atResponse.get(), SYSTEM_ERROR_NO_MEMORY);

const auto n = reader->readLine(atResponse.get(), atResponseSize - 1);
if (n < 0) {
return n;
}
atResponse[n] = '\0';
handler->callback(atResponse.get(), handler->context);
atResponse.reset();

return SYSTEM_ERROR_NONE;
}

} // unnamed

int cellular_on(void* reserved) {
Expand Down Expand Up @@ -506,6 +540,43 @@ int cellular_command(_CALLBACKPTR_MDM cb, void* param, system_tick_t timeout_ms,
return mdmTypeToResult(mdmType);
}

int cellular_add_urc_handler(const char* prefix, hal_cellular_urc_callback_t cb, void* context) {
const auto mgr = cellularNetworkManager();
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
const auto client = mgr->ncpClient();
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);
const auto parser = client->atParser();

const NcpClientLock lock(client);

auto entry = std::make_unique<CellularHalUrcHandler>(prefix, cb, context);
CHECK_TRUE(entry, SYSTEM_ERROR_NO_MEMORY);
sUrcHandlers.append(std::move(entry));
auto handler = sUrcHandlers.last().get();

return parser->addUrcHandler(prefix, commonUrcHandler, handler);
}

int cellular_remove_urc_handler(const char* prefix) {
const auto mgr = cellularNetworkManager();
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
const auto client = mgr->ncpClient();
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);
const auto parser = client->atParser();

const NcpClientLock lock(client);

parser->removeUrcHandler(prefix);
for (int i = 0; i < sUrcHandlers.size(); ++i) {
if (strcmp(sUrcHandlers.at(i).get()->prefix, prefix) == 0) {
sUrcHandlers.removeAt(i);
break;
}
}

return SYSTEM_ERROR_NONE;
}

int cellular_data_usage_set(CellularDataHal* data, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}
Expand Down Expand Up @@ -608,3 +679,28 @@ int cellular_start_ncp_firmware_update(bool update, void* reserved) {
CHECK(client->startNcpFwUpdate(update));
return SYSTEM_ERROR_NONE;
}

int cellular_get_ncp_firmware_version(uint32_t* version, void* reserved) {
const auto mgr = cellularNetworkManager();
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
const auto client = mgr->ncpClient();
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);
CHECK(client->getNcpFirmwareVersion(version));
return SYSTEM_ERROR_NONE;
}

int cellular_update_status(void* reserved) {
#if HAL_PLATFORM_NCP_FW_UPDATE
return services::SaraNcpFwUpdate::instance()->updateStatus();
#else
return SYSTEM_ERROR_NOT_SUPPORTED;
#endif
}

int cellular_enable_updates(void* reserved) {
#if HAL_PLATFORM_NCP_FW_UPDATE
return services::SaraNcpFwUpdate::instance()->enableUpdates();
#else
return SYSTEM_ERROR_NOT_SUPPORTED;
#endif
}
1 change: 1 addition & 0 deletions hal/network/ncp/cellular/cellular_ncp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class CellularNcpClient: public NcpClient {
virtual int getMtu() = 0;
virtual int urcs(bool enable) = 0;
virtual int startNcpFwUpdate(bool update) = 0;
virtual int getNcpFirmwareVersion(uint32_t* version) = 0;
};

inline CellularNcpClientConfig::CellularNcpClientConfig() :
Expand Down
4 changes: 4 additions & 0 deletions hal/network/ncp_client/quectel/quectel_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,10 @@ int QuectelNcpClient::startNcpFwUpdate(bool update) {
return 0;
}

int QuectelNcpClient::getNcpFirmwareVersion(uint32_t* version) {
return 0;
}

void QuectelNcpClient::connectionState(NcpConnectionState state) {
if (ncpState_ == NcpState::DISABLED) {
return;
Expand Down
1 change: 1 addition & 0 deletions hal/network/ncp_client/quectel/quectel_ncp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class QuectelNcpClient: public CellularNcpClient {
virtual int getMtu() override;
virtual int urcs(bool enable) override;
virtual int startNcpFwUpdate(bool update) override;
virtual int getNcpFirmwareVersion(uint32_t* version) override;

auto getMuxer() {
return &muxer_;
Expand Down
Loading

0 comments on commit e1df053

Please sign in to comment.