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