Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[boron|bsom] u-blox R510 FOTA over HTTPS support #2358

Open
wants to merge 1 commit into
base: develop-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -413,6 +413,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 @@ -164,6 +164,7 @@ class CellularNcpClient: public NcpClient {
virtual int urcs(bool enable) = 0;
virtual int startNcpFwUpdate(bool update) = 0;
virtual int dataModeError(int error) = 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 @@ -1634,6 +1634,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 @@ -75,6 +75,7 @@ class QuectelNcpClient: public CellularNcpClient {
virtual int urcs(bool enable) override;
virtual int startNcpFwUpdate(bool update) override;
virtual int dataModeError(int error) override;
virtual int getNcpFirmwareVersion(uint32_t* version) override;

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