From 7634bcfed0ea186175e9f59672a38d2a86fbf025 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 16 Jun 2020 11:50:20 +0300 Subject: GP-654: Add SIM card-based carrier detection This commit adds implementation of the SIM-based carrier detection. The goal for this implementation is to replace various places in the firmware that previously relied on the ICCID-based carrier detection, provide some layer of abstraction and forward compatibility for such places. It is particularly useful for fwSwitch radios with AUTO firmware selection capability. --- include/mts/MTS_IO_CellularRadio.h | 4 ++++ include/mts/MTS_IO_ICellularRadio.h | 21 ++++++++++++++++++ src/MTS_IO_CellularRadio.cpp | 43 +++++++++++++++++++++++++++++++++++++ src/MTS_IO_ICellularRadio.cpp | 4 ++++ 4 files changed, 72 insertions(+) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index 7f4ed2b..e65eb4e 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -81,6 +81,7 @@ namespace MTS { CODE convertCellModesToString(CELLULAR_MODES eCellModes, std::string& sCellModes) override; CODE unlockSimCard(const Json::Value& jArgs) override; + CODE getMtsSimCarrierCode(std::string& sCarrier) override; CODE getMipProfile(Json::Value& jMipProfile) override; CODE validateMsl(const Json::Value& jArgs) override; @@ -164,6 +165,9 @@ namespace MTS { */ virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) = 0; + //! Get MTS carrier code based on the SIM card ID (ICCID) + virtual CODE getMtsSimCarrierCode(const std::string& sIccid, std::string& sCarrier); + void initMipProfile(Json::Value& jData); bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index c301191..98c886d 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -127,6 +127,7 @@ namespace MTS { static const char *KEY_ICCID; //!< Integrated Circuit Card Identifier static const char *KEY_MSL; //!< Master Subsidy Lock static const char *KEY_SUPPORTED_CELL_MODES; //!< Comma-separated list of all supported cellular modes (2g,3g,4g) + static const char *KEY_MTS_SIM_CARRIER_CODE; //!< MTS-specific carrier code fetched from the SIM card //Network Status Data @@ -200,6 +201,10 @@ namespace MTS { static const char *VALUE_ABND_DCS_1800; static const char *VALUE_ABND_PCS_1900; + //Values - MTS carrier code + static const char *VALUE_MTS_CARRIER_CODE_VERIZON; + static const char *VALUE_MTS_CARRIER_CODE_ATT; + static const std::vector DEFAULT_BAIL_STRINGS; virtual ~ICellularRadio() = 0; @@ -290,6 +295,22 @@ namespace MTS { */ virtual CODE unlockSimCard(const Json::Value& jArgs) = 0; + /** + * @brief getMtsSimCarrierCode - get MTS-specific carrier code from the SIM card. + * + * @param sCarrier - a string to be populated with one of the carrier codes: + * + * - VALUE_MTS_CARRIER_CODE_VERIZON - Verizon + * - VALUE_MTS_CARRIER_CODE_ATT - AT&T + * - VALUE_UNKNOWN - Unknown carrier + * - other values may be defined in the future + * + * @return CODE::SUCCESS when carrier name retrieved, + * CODE::ERROR otherwise (i.e. when modem is not responding, + * when SIM card is removed or on any other error). + */ + virtual CODE getMtsSimCarrierCode(std::string& sCarrier) = 0; + //! Gather details of the radio's Mobile IP Profile /*! \param Json::Value object that will be populated with MIP data diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 648894f..bef15e9 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -912,6 +912,49 @@ ICellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { return SUCCESS; } +ICellularRadio::CODE CellularRadio::getMtsSimCarrierCode(std::string& sCarrierCode) { + std::string sIccid; + CODE rc; + + printTrace("%s| Get MTS carrier code from the SIM card installed", m_sName.c_str()); + + rc = getIccid(sIccid); + if (rc != SUCCESS) { + printError("%s| Unable to determine SIM carrier: Failed to fetch SIM identifier", m_sName.c_str()); + return rc; + } + + printTrace("%s| Fetched ICCID: [%s]", m_sName.c_str(), sIccid.c_str()); + + rc = getMtsSimCarrierCode(sIccid, sCarrierCode); + if (rc != SUCCESS) { + printError("%s| Unable to determine SIM carrier: Unable to extract carrier from the SIM identifier", m_sName.c_str()); + return rc; + } + + printTrace("%s| Detected MTS carrier code: [%s]", m_sName.c_str(), sCarrierCode.c_str()); + return rc; +} + +ICellularRadio::CODE CellularRadio::getMtsSimCarrierCode(const std::string& sIccid, std::string& sCarrierCode) { + const char* ICCID_PREFIX_VZW = "891480"; + const char* ICCID_PREFIX_ATT = "8901410"; + + if (sIccid.find(ICCID_PREFIX_VZW) == 0) { + printTrace("%s| Verizon SIM detected", m_sName.c_str()); + sCarrierCode = VALUE_MTS_CARRIER_CODE_VERIZON; + } else if (sIccid.find(ICCID_PREFIX_ATT) == 0) { + printTrace("%s| AT&T SIM detected", m_sName.c_str()); + sCarrierCode = VALUE_MTS_CARRIER_CODE_ATT; + } else { + // All other carriers for which ICCID prefixes are not defined + printWarning("%s| Carrier is unknown for this SIM ID: [%s]", m_sName.c_str(), sIccid.c_str()); + sCarrierCode = VALUE_UNKNOWN; + } + + return SUCCESS; // no error cases for now +} + ICellularRadio::CODE CellularRadio::validateMsl(const Json::Value&) { printTrace("%s| Validate MSL", m_sName.c_str()); diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index 53c8faa..e83ce80 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -50,6 +50,7 @@ const char *MTS::IO::ICellularRadio::KEY_MDN = "mdn"; //!< Mobile Dir const char *MTS::IO::ICellularRadio::KEY_ICCID = "iccid"; //!< Integrated Circuit Card Identifier const char *MTS::IO::ICellularRadio::KEY_MSL = "msl"; //!< Master Subsidy Lock const char *MTS::IO::ICellularRadio::KEY_SUPPORTED_CELL_MODES = "supportedCellularModes"; //!< Comma-separated list of all supported cellular modes (2g,3g,4g) +const char *MTS::IO::ICellularRadio::KEY_MTS_SIM_CARRIER_CODE = "mtsSimCarrierCode"; //!< MTS-specific carrier code fetched from the SIM card //Dynamic Data const char *MTS::IO::ICellularRadio::KEY_ROAMING = "roaming"; //!< Indicates whether or not using Home Network @@ -112,6 +113,9 @@ const char *MTS::IO::ICellularRadio::VALUE_ABND_GSM_900 = "GSM 900"; const char *MTS::IO::ICellularRadio::VALUE_ABND_DCS_1800 = "DCS 1800"; const char *MTS::IO::ICellularRadio::VALUE_ABND_PCS_1900 = "PCS 1900"; +const char *MTS::IO::ICellularRadio::VALUE_MTS_CARRIER_CODE_VERIZON = "vz"; +const char *MTS::IO::ICellularRadio::VALUE_MTS_CARRIER_CODE_ATT = "att"; + const std::vector MTS::IO::ICellularRadio::DEFAULT_BAIL_STRINGS = { MTS::IO::ICellularRadio::RSP_OK, MTS::IO::ICellularRadio::RSP_ERROR }; MTS::IO::ICellularRadio::~ICellularRadio() -- cgit v1.2.3 From 747b898f36c4764475e61f20847ba4bbb3a81404 Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 16 Jun 2020 15:37:02 +0300 Subject: [GP-654] Add SIM card-based carrier detection Changes after a code review: - renamed "MTS Carrier Code" to the "Carrier Code"; - fixed descriptions for the new field and methods. --- include/mts/MTS_IO_CellularRadio.h | 6 +++--- include/mts/MTS_IO_ICellularRadio.h | 19 ++++++++++--------- src/MTS_IO_CellularRadio.cpp | 14 +++++++------- src/MTS_IO_ICellularRadio.cpp | 7 +++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h index e65eb4e..ed87a24 100644 --- a/include/mts/MTS_IO_CellularRadio.h +++ b/include/mts/MTS_IO_CellularRadio.h @@ -81,7 +81,7 @@ namespace MTS { CODE convertCellModesToString(CELLULAR_MODES eCellModes, std::string& sCellModes) override; CODE unlockSimCard(const Json::Value& jArgs) override; - CODE getMtsSimCarrierCode(std::string& sCarrier) override; + CODE getSimCarrierCode(std::string& sCarrierCode) override; CODE getMipProfile(Json::Value& jMipProfile) override; CODE validateMsl(const Json::Value& jArgs) override; @@ -165,8 +165,8 @@ namespace MTS { */ virtual CODE getSimLockAttempts(int& iAttemptsPin, int& iAttemptsPuk) = 0; - //! Get MTS carrier code based on the SIM card ID (ICCID) - virtual CODE getMtsSimCarrierCode(const std::string& sIccid, std::string& sCarrier); + //! Get carrier code based on the SIM card ID (ICCID) + virtual CODE getSimCarrierCode(const std::string& sIccid, std::string& sCarrierCode); void initMipProfile(Json::Value& jData); bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue); diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h index 98c886d..f2d4dfe 100644 --- a/include/mts/MTS_IO_ICellularRadio.h +++ b/include/mts/MTS_IO_ICellularRadio.h @@ -127,7 +127,7 @@ namespace MTS { static const char *KEY_ICCID; //!< Integrated Circuit Card Identifier static const char *KEY_MSL; //!< Master Subsidy Lock static const char *KEY_SUPPORTED_CELL_MODES; //!< Comma-separated list of all supported cellular modes (2g,3g,4g) - static const char *KEY_MTS_SIM_CARRIER_CODE; //!< MTS-specific carrier code fetched from the SIM card + static const char *KEY_SIM_CARRIER_CODE; //!< Unique carrier identifier based on the SIM card information. //Network Status Data @@ -201,9 +201,9 @@ namespace MTS { static const char *VALUE_ABND_DCS_1800; static const char *VALUE_ABND_PCS_1900; - //Values - MTS carrier code - static const char *VALUE_MTS_CARRIER_CODE_VERIZON; - static const char *VALUE_MTS_CARRIER_CODE_ATT; + //Values - Carrier code; abstraction over PLMN IDs, IINs and other identifiers + static const char *VALUE_CARRIER_CODE_VERIZON; + static const char *VALUE_CARRIER_CODE_ATT; static const std::vector DEFAULT_BAIL_STRINGS; @@ -296,20 +296,21 @@ namespace MTS { virtual CODE unlockSimCard(const Json::Value& jArgs) = 0; /** - * @brief getMtsSimCarrierCode - get MTS-specific carrier code from the SIM card. + * @brief getSimCarrierCode - get unique carrier identifier based on + * the SIM card information. * * @param sCarrier - a string to be populated with one of the carrier codes: * - * - VALUE_MTS_CARRIER_CODE_VERIZON - Verizon - * - VALUE_MTS_CARRIER_CODE_ATT - AT&T + * - VALUE_CARRIER_CODE_VERIZON - Verizon + * - VALUE_CARRIER_CODE_ATT - AT&T * - VALUE_UNKNOWN - Unknown carrier * - other values may be defined in the future * - * @return CODE::SUCCESS when carrier name retrieved, + * @return CODE::SUCCESS when carrier code retrieved, * CODE::ERROR otherwise (i.e. when modem is not responding, * when SIM card is removed or on any other error). */ - virtual CODE getMtsSimCarrierCode(std::string& sCarrier) = 0; + virtual CODE getSimCarrierCode(std::string& sCarrierCode) = 0; //! Gather details of the radio's Mobile IP Profile /*! diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index bef15e9..b18478e 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -912,11 +912,11 @@ ICellularRadio::CODE CellularRadio::unlockSimCard(const Json::Value& jArgs) { return SUCCESS; } -ICellularRadio::CODE CellularRadio::getMtsSimCarrierCode(std::string& sCarrierCode) { +ICellularRadio::CODE CellularRadio::getSimCarrierCode(std::string& sCarrierCode) { std::string sIccid; CODE rc; - printTrace("%s| Get MTS carrier code from the SIM card installed", m_sName.c_str()); + printTrace("%s| Get carrier code from the SIM card installed", m_sName.c_str()); rc = getIccid(sIccid); if (rc != SUCCESS) { @@ -926,26 +926,26 @@ ICellularRadio::CODE CellularRadio::getMtsSimCarrierCode(std::string& sCarrierCo printTrace("%s| Fetched ICCID: [%s]", m_sName.c_str(), sIccid.c_str()); - rc = getMtsSimCarrierCode(sIccid, sCarrierCode); + rc = getSimCarrierCode(sIccid, sCarrierCode); if (rc != SUCCESS) { printError("%s| Unable to determine SIM carrier: Unable to extract carrier from the SIM identifier", m_sName.c_str()); return rc; } - printTrace("%s| Detected MTS carrier code: [%s]", m_sName.c_str(), sCarrierCode.c_str()); + printTrace("%s| Detected carrier code: [%s]", m_sName.c_str(), sCarrierCode.c_str()); return rc; } -ICellularRadio::CODE CellularRadio::getMtsSimCarrierCode(const std::string& sIccid, std::string& sCarrierCode) { +ICellularRadio::CODE CellularRadio::getSimCarrierCode(const std::string& sIccid, std::string& sCarrierCode) { const char* ICCID_PREFIX_VZW = "891480"; const char* ICCID_PREFIX_ATT = "8901410"; if (sIccid.find(ICCID_PREFIX_VZW) == 0) { printTrace("%s| Verizon SIM detected", m_sName.c_str()); - sCarrierCode = VALUE_MTS_CARRIER_CODE_VERIZON; + sCarrierCode = VALUE_CARRIER_CODE_VERIZON; } else if (sIccid.find(ICCID_PREFIX_ATT) == 0) { printTrace("%s| AT&T SIM detected", m_sName.c_str()); - sCarrierCode = VALUE_MTS_CARRIER_CODE_ATT; + sCarrierCode = VALUE_CARRIER_CODE_ATT; } else { // All other carriers for which ICCID prefixes are not defined printWarning("%s| Carrier is unknown for this SIM ID: [%s]", m_sName.c_str(), sIccid.c_str()); diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index e83ce80..12d7916 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -50,8 +50,7 @@ const char *MTS::IO::ICellularRadio::KEY_MDN = "mdn"; //!< Mobile Dir const char *MTS::IO::ICellularRadio::KEY_ICCID = "iccid"; //!< Integrated Circuit Card Identifier const char *MTS::IO::ICellularRadio::KEY_MSL = "msl"; //!< Master Subsidy Lock const char *MTS::IO::ICellularRadio::KEY_SUPPORTED_CELL_MODES = "supportedCellularModes"; //!< Comma-separated list of all supported cellular modes (2g,3g,4g) -const char *MTS::IO::ICellularRadio::KEY_MTS_SIM_CARRIER_CODE = "mtsSimCarrierCode"; //!< MTS-specific carrier code fetched from the SIM card - +const char *MTS::IO::ICellularRadio::KEY_SIM_CARRIER_CODE = "simCarrierCode"; //!< Unique carrier identifier based on the SIM card information. //Dynamic Data const char *MTS::IO::ICellularRadio::KEY_ROAMING = "roaming"; //!< Indicates whether or not using Home Network const char *MTS::IO::ICellularRadio::KEY_DATETIME = "datetime"; //!< Date and Time from tower @@ -113,8 +112,8 @@ const char *MTS::IO::ICellularRadio::VALUE_ABND_GSM_900 = "GSM 900"; const char *MTS::IO::ICellularRadio::VALUE_ABND_DCS_1800 = "DCS 1800"; const char *MTS::IO::ICellularRadio::VALUE_ABND_PCS_1900 = "PCS 1900"; -const char *MTS::IO::ICellularRadio::VALUE_MTS_CARRIER_CODE_VERIZON = "vz"; -const char *MTS::IO::ICellularRadio::VALUE_MTS_CARRIER_CODE_ATT = "att"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_CODE_VERIZON = "vz"; +const char *MTS::IO::ICellularRadio::VALUE_CARRIER_CODE_ATT = "att"; const std::vector MTS::IO::ICellularRadio::DEFAULT_BAIL_STRINGS = { MTS::IO::ICellularRadio::RSP_OK, MTS::IO::ICellularRadio::RSP_ERROR }; -- cgit v1.2.3