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

[cellular] fixes handling of 00 or 000 MNC #2726

Merged
merged 1 commit into from
Jan 18, 2024
Merged
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
4 changes: 2 additions & 2 deletions hal/network/ncp/cellular/cellular_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ cellular_result_t cellular_global_identity(CellularGlobalIdentity* cgi, void* re
const auto client = mgr->ncpClient();
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);

// Load cached data into result struct
// Load data into result struct
CHECK(client->getCellularGlobalIdentity(cgi));

// Validate cache
CHECK_TRUE(0 != cgi->mobile_country_code, SYSTEM_ERROR_BAD_DATA);
CHECK_TRUE(0 != cgi->mobile_network_code, SYSTEM_ERROR_BAD_DATA);
// MNC may be 00 or 000. In case of incorrect parsing getCellularGlobalIdentity() should have failed anyway
CHECK_TRUE(0xFFFF != cgi->location_area_code, SYSTEM_ERROR_BAD_DATA);
CHECK_TRUE(0xFFFFFFFF != cgi->cell_id, SYSTEM_ERROR_BAD_DATA);

Expand Down
6 changes: 5 additions & 1 deletion hal/network/ncp_client/quectel/quectel_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,12 @@ int QuectelNcpClient::queryAndParseAtCops(CellularSignalQuality* qual) {
cgi_.cgi_flags &= ~CGI_FLAG_TWO_DIGIT_MNC;
}

// `atoi` returns zero on error, which is an invalid `mcc` and `mnc`
// NOTE: MCC cannot be zero, MNC may be 00 or even 000
// We should not need to check whether str -> int coversion works
// as scanf() above along with the return value check guarantees that we've
// scanned the correct MCC MNC combo returned from +COPS.
cgi_.mobile_country_code = static_cast<uint16_t>(::atoi(mobileCountryCode));
CHECK_TRUE(cgi_.mobile_country_code != 0, SYSTEM_ERROR_BAD_DATA);
cgi_.mobile_network_code = static_cast<uint16_t>(::atoi(mobileNetworkCode));

switch (static_cast<CellularAccessTechnology>(act)) {
Expand Down
6 changes: 5 additions & 1 deletion hal/network/ncp_client/sara/sara_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,12 @@ int SaraNcpClient::queryAndParseAtCops(CellularSignalQuality* qual) {
cgi_.cgi_flags &= ~CGI_FLAG_TWO_DIGIT_MNC;
}

// `atoi` returns zero on error, which is an invalid `mcc` and `mnc`
// NOTE: MCC cannot be zero, MNC may be 00 or even 000
// We should not need to check whether str -> int coversion works
// as scanf() above along with the return value check guarantees that we've
// scanned the correct MCC MNC combo returned from +COPS.
cgi_.mobile_country_code = static_cast<uint16_t>(::atoi(mobileCountryCode));
CHECK_TRUE(cgi_.mobile_country_code != 0, SYSTEM_ERROR_BAD_DATA);
cgi_.mobile_network_code = static_cast<uint16_t>(::atoi(mobileNetworkCode));

if (ncpId() == PLATFORM_NCP_SARA_R410 || ncpId() == PLATFORM_NCP_SARA_R510) {
Expand Down