1 /* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NAPI_RADIO_H 17 #define NAPI_RADIO_H 18 19 #include <codecvt> 20 #include <condition_variable> 21 #include <locale> 22 #include <mutex> 23 #include <string> 24 25 #include "cell_information.h" 26 #include "napi/native_api.h" 27 #include "napi/native_node_api.h" 28 #include "napi_ims_reg_info_callback.h" 29 #include "napi_radio_types.h" 30 #include "napi_util.h" 31 #include "network_information.h" 32 #include "network_search_result.h" 33 #include "network_state.h" 34 #include "signal_information.h" 35 #include "telephony_napi_common_error.h" 36 #include "telephony_napi_hril_error_code.h" 37 #include "telephony_types.h" 38 39 namespace OHOS { 40 namespace Telephony { 41 constexpr int DEFAULT_ERROR = ERROR_SERVICE_UNAVAILABLE; 42 constexpr int BUF_SIZE = 32; 43 constexpr int CALLBACK_VALUES_SIZE = 1; 44 constexpr int WAIT_TIME_SECOND = 60 * 3; 45 constexpr int WAIT_NETWORK_MANUAL_SEARCH_TIME_SECOND = 60 * 5; 46 const static std::string GSM = "GSM"; 47 const static std::string GPRS = "GPRS"; 48 const static std::string WCDMA = "WCDMA"; 49 const static std::string LTE = "LTE"; 50 const static std::string NR = "NR"; 51 const int32_t ARRAY_INDEX_FIRST = 0; 52 const int32_t ARRAY_INDEX_SECOND = 1; 53 const int32_t ARRAY_INDEX_THIRD = 2; 54 const int32_t ARRAY_INDEX_FOURTH = 3; 55 56 enum NativeSelectionMode { NATIVE_NETWORK_SELECTION_AUTOMATIC = 0, NATIVE_NETWORK_SELECTION_MANUAL = 1 }; 57 58 enum NetworkSelectionMode { 59 /** Unknown network selection modes. */ 60 NETWORK_SELECTION_UNKNOWN, 61 62 /** Automatic network selection modes. */ 63 NETWORK_SELECTION_AUTOMATIC, 64 65 /** Manual network selection modes. */ 66 NETWORK_SELECTION_MANUAL 67 }; 68 69 enum NetworkInformationState { 70 /** Indicates that the network state is unknown. */ 71 NETWORK_UNKNOWN, 72 73 /** Indicates that the network is available for registration. */ 74 NETWORK_AVAILABLE, 75 76 /** Indicates that you have already registered with the network. */ 77 NETWORK_CURRENT, 78 79 /** Indicates that the network is unavailable for registration. */ 80 NETWORK_FORBIDDEN 81 }; 82 83 enum NrOptionMode { 84 /** Indicates unknown NR networking mode. */ 85 NR_OPTION_UNKNOWN, 86 87 /** Indicates that the NR networking mode is NSA only. */ 88 NR_OPTION_NSA_ONLY, 89 90 /** Indicates that the NR networking mode is SA only. */ 91 NR_OPTION_SA_ONLY, 92 93 /** Indicates that the NR networking mode is NSA and SA. */ 94 NR_OPTION_NSA_AND_SA, 95 }; 96 97 enum SlotIdState { SLOTID_INPUT_ERROR = 111, ENUMERATION_INPUT_ERROR = 222 }; 98 99 enum PreferredNetwork { 100 PREFERRED_NETWORK_MODE_AUTO = 0, 101 PREFERRED_NETWORK_MODE_GSM = 1, 102 PREFERRED_NETWORK_MODE_WCDMA = 2, 103 PREFERRED_NETWORK_MODE_LTE = 3, 104 PREFERRED_NETWORK_MODE_LTE_WCDMA = 4, 105 PREFERRED_NETWORK_MODE_LTE_WCDMA_GSM = 5, 106 PREFERRED_NETWORK_MODE_WCDMA_GSM = 6, 107 PREFERRED_NETWORK_MODE_CDMA = 7, 108 PREFERRED_NETWORK_MODE_EVDO = 8, 109 PREFERRED_NETWORK_MODE_EVDO_CDMA = 9, 110 PREFERRED_NETWORK_MODE_WCDMA_GSM_EVDO_CDMA = 10, 111 PREFERRED_NETWORK_MODE_LTE_EVDO_CDMA = 11, 112 PREFERRED_NETWORK_MODE_LTE_WCDMA_GSM_EVDO_CDMA = 12, 113 PREFERRED_NETWORK_MODE_TDSCDMA = 13, 114 PREFERRED_NETWORK_MODE_TDSCDMA_GSM = 14, 115 PREFERRED_NETWORK_MODE_TDSCDMA_WCDMA = 15, 116 PREFERRED_NETWORK_MODE_TDSCDMA_WCDMA_GSM = 16, 117 PREFERRED_NETWORK_MODE_LTE_TDSCDMA = 17, 118 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_GSM = 18, 119 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_WCDMA = 19, 120 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_WCDMA_GSM = 20, 121 PREFERRED_NETWORK_MODE_TDSCDMA_WCDMA_GSM_EVDO_CDMA = 21, 122 PREFERRED_NETWORK_MODE_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA = 22, 123 PREFERRED_NETWORK_MODE_NR = 31, 124 PREFERRED_NETWORK_MODE_NR_LTE = 32, 125 PREFERRED_NETWORK_MODE_NR_LTE_WCDMA = 33, 126 PREFERRED_NETWORK_MODE_NR_LTE_WCDMA_GSM = 34, 127 PREFERRED_NETWORK_MODE_NR_LTE_EVDO_CDMA = 35, 128 PREFERRED_NETWORK_MODE_NR_LTE_WCDMA_GSM_EVDO_CDMA = 36, 129 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA = 37, 130 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_GSM = 38, 131 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA = 39, 132 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA_GSM = 40, 133 PREFERRED_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA = 41, 134 }; 135 136 struct AsyncContext { 137 int32_t slotId = DEFAULT_SIM_SLOT_ID; 138 napi_async_work work = nullptr; 139 napi_deferred deferred = nullptr; 140 napi_ref callbackRef = nullptr; 141 int status = DEFAULT_ERROR; 142 int32_t result = DEFAULT_ERROR; 143 }; 144 145 struct CallbackContext : BaseContext { 146 std::mutex callbackMutex; 147 std::condition_variable cv; 148 bool callbackEnd = false; 149 bool sendRequest = false; 150 int32_t errorCode = HRIL_ERR_GENERIC_FAILURE; 151 }; 152 153 struct RadioTechContext : BaseContext { 154 int32_t slotId = DEFAULT_SIM_SLOT_ID; 155 int32_t csTech = DEFAULT_ERROR; 156 int32_t psTech = DEFAULT_ERROR; 157 }; 158 159 struct SignalInfoListContext : BaseContext { 160 int32_t slotId = DEFAULT_SIM_SLOT_ID; 161 std::vector<sptr<SignalInformation>> signalInfoList {}; 162 }; 163 164 struct GetSelectModeContext : CallbackContext { 165 int32_t slotId = DEFAULT_SIM_SLOT_ID; 166 int32_t selectMode = DEFAULT_ERROR; 167 }; 168 169 struct SetSelectModeContext : CallbackContext { 170 int32_t slotId = DEFAULT_SIM_SLOT_ID; 171 int32_t selectMode = DEFAULT_ERROR; 172 std::string operatorName = ""; 173 std::string operatorNumeric = ""; 174 int32_t state = NETWORK_UNKNOWN; 175 std::string radioTech = ""; 176 bool resumeSelection = false; 177 bool setResult = false; 178 }; 179 180 struct GetSearchInfoContext : CallbackContext { 181 int32_t slotId = DEFAULT_SIM_SLOT_ID; 182 sptr<NetworkSearchResult> searchResult = nullptr; 183 }; 184 185 struct GetStateContext : BaseContext { 186 int32_t slotId = DEFAULT_SIM_SLOT_ID; 187 std::string longOperatorName = ""; 188 std::string shortOperatorName = ""; 189 std::string plmnNumeric = ""; 190 int32_t psRoamingStatus = 0; 191 int32_t csRoamingStatus = 0; 192 int32_t cfgTech = 0; 193 bool isRoaming = false; 194 int32_t regStatus = 0; 195 int32_t nsaState = static_cast<int32_t>(NsaState::NSA_STATE_NOT_SUPPORT); 196 bool isCaActive = false; 197 bool isEmergency = false; 198 }; 199 200 struct GetISOCountryCodeContext : BaseContext { 201 int32_t slotId = DEFAULT_SIM_SLOT_ID; 202 std::string countryCode = ""; 203 }; 204 205 struct IsRadioOnContext : CallbackContext { 206 int32_t slotId = DEFAULT_SIM_SLOT_ID; 207 bool isRadioOn = false; 208 bool sendRequestSlot2 = false; 209 }; 210 211 struct SwitchRadioContext : CallbackContext { 212 int32_t slotId = DEFAULT_SIM_SLOT_ID; 213 bool sendRequestSlot2 = false; 214 }; 215 216 struct GetOperatorNameContext : BaseContext { 217 int32_t slotId = DEFAULT_SIM_SLOT_ID; 218 char operatorName[BUF_SIZE + 1] = { 0 }; 219 size_t operatorNameLength = 0; 220 }; 221 222 struct PreferredNetworkModeContext : CallbackContext { 223 int32_t slotId = DEFAULT_SIM_SLOT_ID; 224 int32_t preferredNetworkMode = DEFAULT_ERROR; 225 }; 226 227 struct NetworkCapabilityContext : CallbackContext { 228 int32_t slotId = DEFAULT_SIM_SLOT_ID; 229 int32_t networkCapabilityType = DEFAULT_ERROR; 230 int32_t networkCapabilityState = DEFAULT_ERROR; 231 }; 232 233 struct GetIMEIContext : BaseContext { 234 int32_t slotId = DEFAULT_SIM_SLOT_ID; 235 std::string getIMEIResult = ""; 236 }; 237 238 struct GetIMEISVContext : BaseContext { 239 int32_t slotId = DEFAULT_SIM_SLOT_ID; 240 std::string getIMEISVResult = ""; 241 }; 242 243 struct GetMEIDContext : BaseContext { 244 int32_t slotId = DEFAULT_SIM_SLOT_ID; 245 std::string getMEIDResult = ""; 246 }; 247 248 struct SendUpdateCellLocationRequest : CallbackContext { 249 int32_t slotId = DEFAULT_SIM_SLOT_ID; 250 bool sendRequestSlot2 = false; 251 }; 252 253 struct CellInformationContext : BaseContext { 254 int32_t slotId = DEFAULT_SIM_SLOT_ID; 255 std::vector<sptr<CellInformation>> cellInformations {}; 256 napi_value callbackValue = nullptr; 257 }; 258 259 struct GetPrimarySlotIdContext : BaseContext { 260 int32_t slotId = DEFAULT_SIM_SLOT_ID; 261 }; 262 263 struct GetUniqueDeviceIdContext : BaseContext { 264 int32_t slotId = DEFAULT_SIM_SLOT_ID; 265 std::string getUniqueDeviceId = ""; 266 }; 267 268 struct NrOptionModeContext : CallbackContext { 269 int32_t slotId = DEFAULT_SIM_SLOT_ID; 270 int32_t nrOptionMode = DEFAULT_ERROR; 271 }; 272 273 struct FactoryResetContext : BaseContext { 274 int32_t slotId = DEFAULT_SIM_SLOT_ID; 275 }; 276 277 struct SetPrimarySlotIdContext : BaseContext { 278 int32_t slotId = DEFAULT_SIM_SLOT_ID; 279 bool setResult = false; 280 }; 281 282 struct GetImsRegInfoContext : BaseContext { 283 int32_t slotId = DEFAULT_SIM_SLOT_ID; 284 int32_t imsSrvType = DEFAULT_ERROR; 285 ImsRegInfo imsRegInfo; 286 }; 287 288 struct ImsRegInfoContext : BaseContext { 289 int32_t slotId = DEFAULT_SIM_SLOT_ID; 290 ImsRegInfo imsRegInfo; 291 }; 292 293 struct ImsRegStateCallback { 294 napi_env env = nullptr; 295 napi_ref thisVar = nullptr; 296 napi_ref callbackRef = nullptr; 297 int32_t slotId = DEFAULT_SIM_SLOT_ID; 298 ImsServiceType imsSrvType = ImsServiceType::TYPE_VOICE; 299 sptr<ImsRegInfoCallback> imsCallback = nullptr; 300 }; 301 302 struct ImsStateWorker { 303 ImsRegInfo info; 304 ImsRegStateCallback callback; 305 }; 306 307 struct GetBasebandVersionContext : BaseContext { 308 int32_t slotId = DEFAULT_SIM_SLOT_ID; 309 std::string getBasebandVersion = ""; 310 }; 311 } // namespace Telephony 312 } // namespace OHOS 313 #endif // NAPI_RADIO_H