1 /*
2  * Copyright (C) 2021 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 OHOS_CELL_INFORMATION_H
17 #define OHOS_CELL_INFORMATION_H
18 
19 #include "parcel.h"
20 
21 namespace OHOS {
22 namespace Telephony {
23 class CellInformation : public Parcelable {
24 public:
25     static const int32_t MAX_CELL_NUM = 10;
26     /**
27      * @brief Cell type
28      */
29     enum class CellType {
30         CELL_TYPE_NONE = 0,
31         /**
32          * Global System for Mobile Communications (GSM) cell type
33          */
34         CELL_TYPE_GSM,
35         /**
36          * Code Division Multiple Access (CDMA) cell type
37          */
38         CELL_TYPE_CDMA,
39         /**
40          * Wideband Code Division Multiple Access (WCDMA) cell type
41          */
42         CELL_TYPE_WCDMA,
43         /**
44          * Time Division-Synchronous Code Division Multiple Access (TD-SCDMA) cell type
45          */
46         CELL_TYPE_TDSCDMA,
47         /**
48          * Long Term Evolution (LTE) cell type
49          */
50         CELL_TYPE_LTE,
51         /**
52          * 5G New Radio (NR) cell type
53          */
54         CELL_TYPE_NR
55     };
56     CellInformation() = default;
57     virtual ~CellInformation() = default;
58     virtual bool Marshalling(Parcel &parcel) const = 0;
59     static CellInformation *Unmarshalling(Parcel &parcel);
60     virtual bool ReadFromParcel(Parcel &parcel) = 0;
61     virtual CellInformation::CellType GetNetworkType() const = 0;
62     virtual std::string ToString() const = 0;
63     void Init(int32_t mcc, int32_t mnc, int32_t cellId);
64     void Init(std::string mcc, std::string mnc, int32_t cellId);
65 
66     /**
67      * @brief Obtain the cell Id
68      *
69      * @return Cell Id
70      */
71     virtual int32_t GetCellId() const;
72     /**
73      * @brief Obtain the Mobile Country Code
74      *
75      * @return Mobile Country Code
76      */
77     virtual std::string GetMcc() const;
78     /**
79      * @brief Obtain the Mobile Network Code
80      *
81      * @return Mobile Network Code
82      */
83     virtual std::string GetMnc() const;
84     virtual uint64_t GetTimeStamp() const;
85     virtual int32_t GetSignalLevel() const;
86     virtual int32_t GetSignalIntensity() const;
87     virtual bool GetIsCamped() const;
88     virtual void SetIsCamped(bool isCamped);
89     virtual void SetSignalIntensity(int32_t signalIntensity);
90     virtual void SetSignalLevel(int32_t signalLevel);
91 
92 protected:
93     std::string mcc_ = "";
94     std::string mnc_ = "";
95     int32_t cellId_ = 0;
96     uint64_t timeStamp_ = 0;
97     int32_t signalIntensity_ = 0;
98     int32_t signalLevel_ = 0;
99     bool isCamped_ = false;
100 };
101 
102 class GsmCellInformation : public CellInformation {
103 public:
104     GsmCellInformation() = default;
105     virtual ~GsmCellInformation() = default;
106     bool Marshalling(Parcel &parcel) const override;
107     static GsmCellInformation *Unmarshalling(Parcel &parcel);
108     bool ReadFromParcel(Parcel &parcel) override;
109     CellInformation::CellType GetNetworkType() const override;
110     std::string ToString() const override;
111     void SetGsmParam(int32_t bsic, int32_t lac, int32_t arfcn);
112     void UpdateLocation(int32_t cellId, int32_t lac);
113     GsmCellInformation(const GsmCellInformation &gsmCell);
114     GsmCellInformation &operator=(const GsmCellInformation &gsmCell);
115     bool operator==(const GsmCellInformation &other) const;
116     /**
117      * @brief Obtain the Location Area Code
118      *
119      * @return Location Area Code
120      */
121     int32_t GetLac() const;
122     /**
123      * @brief Obtain the Base Station Identity Code
124      *
125      * @return Base Station Identity Code
126      */
127     int32_t GetBsic() const;
128     /**
129      * @brief Obtain the Absolute RF Channel Number
130      *
131      * @return Absolute RF Channel Number
132      */
133     int32_t GetArfcn() const;
134 
135 private:
136     int32_t lac_ = 0;
137     int32_t bsic_ = 0;
138     int32_t arfcn_ = 0;
139 };
140 
141 class LteCellInformation : public CellInformation {
142 public:
143     LteCellInformation() = default;
144     virtual ~LteCellInformation() = default;
145     bool Marshalling(Parcel &parcel) const override;
146     static LteCellInformation *Unmarshalling(Parcel &parcel);
147     bool ReadFromParcel(Parcel &parcel) override;
148     CellInformation::CellType GetNetworkType() const override;
149     std::string ToString() const override;
150     void SetLteParam(int32_t pci, int32_t tac, int32_t arfcn);
151     LteCellInformation(const LteCellInformation &lteCell);
152     LteCellInformation &operator=(const LteCellInformation &lteCell);
153     bool operator==(const LteCellInformation &other) const;
154     void UpdateLocation(int32_t cellId, int32_t tac);
155     /**
156      * @brief Obtain the Physical Cell Id
157      *
158      * @return Physical Cell Id
159      */
160     int32_t GetPci() const;
161     /**
162      * @brief Obtain the Tracking Area Code
163      *
164      * @return Tracking Area Code
165      */
166     int32_t GetTac() const;
167     /**
168      * @brief Obtain the Absolute RF Channel Number
169      *
170      * @return Absolute RF Channel Number
171      */
172     int32_t GetArfcn() const;
173 
174 private:
175     int32_t pci_ = 0;
176     int32_t tac_ = 0;
177     int32_t earfcn_ = 0;
178 };
179 
180 class WcdmaCellInformation : public CellInformation {
181 public:
182     WcdmaCellInformation() = default;
183     virtual ~WcdmaCellInformation() = default;
184     bool Marshalling(Parcel &parcel) const override;
185     static WcdmaCellInformation *Unmarshalling(Parcel &parcel);
186     bool ReadFromParcel(Parcel &parcel) override;
187     CellInformation::CellType GetNetworkType() const override;
188     std::string ToString() const override;
189     void SetWcdmaParam(int32_t psc, int32_t lac, int32_t arfcn);
190     WcdmaCellInformation(const WcdmaCellInformation &wcdmaCell);
191     WcdmaCellInformation &operator=(const WcdmaCellInformation &wcdmaCell);
192     bool operator==(const WcdmaCellInformation &other) const;
193     void UpdateLocation(int32_t cellId, int32_t lac);
194     /**
195      * @brief Obtain the Primary Scrambling Code
196      *
197      * @return Primary Scrambling Code
198      */
199     int32_t GetPsc() const;
200     /**
201      * @brief Obtain the Location Area Code
202      *
203      * @return Location Area Code
204      */
205     int32_t GetLac() const;
206     /**
207      * @brief Obtain the Absolute RF Channel Number
208      *
209      * @return Absolute RF Channel Number
210      */
211     int32_t GetArfcn() const;
212 
213 private:
214     int32_t lac_ = 0;
215     int32_t psc_ = 0;
216     int32_t uarfcn_ = 0;
217 };
218 
219 class TdscdmaCellInformation : public CellInformation {
220 public:
221     TdscdmaCellInformation() = default;
222     virtual ~TdscdmaCellInformation() = default;
223     bool Marshalling(Parcel &parcel) const override;
224     static TdscdmaCellInformation *Unmarshalling(Parcel &parcel);
225     bool ReadFromParcel(Parcel &parcel) override;
226     CellInformation::CellType GetNetworkType() const override;
227     std::string ToString() const override;
228     void SetTdscdmaParam(int32_t psc, int32_t lac, int32_t arfcn);
229     TdscdmaCellInformation(const TdscdmaCellInformation &wcdmaCell);
230     TdscdmaCellInformation &operator=(const TdscdmaCellInformation &wcdmaCell);
231     bool operator==(const TdscdmaCellInformation &other) const;
232     void UpdateLocation(int32_t cellId, int32_t lac);
233     /**
234      * @brief Obtain the Cell Parameters ID
235      *
236      * @return Cell Parameters ID
237      */
238     int32_t GetCpid() const;
239     /**
240      * @brief Obtain the Location Area Code
241      *
242      * @return Location Area Code
243      */
244     int32_t GetLac() const;
245     /**
246      * @brief Obtain the Absolute RF Channel Number
247      *
248      * @return Absolute RF Channel Number
249      */
250     int32_t GetArfcn() const;
251 
252 private:
253     int32_t lac_ = 0;
254     int32_t cpid_ = 0;
255     int32_t uarfcn_ = 0;
256 };
257 
258 class CdmaCellInformation : public CellInformation {
259 public:
260     CdmaCellInformation() = default;
261     virtual ~CdmaCellInformation() = default;
262     bool Marshalling(Parcel &parcel) const override;
263     static CdmaCellInformation *Unmarshalling(Parcel &parcel);
264     bool ReadFromParcel(Parcel &parcel) override;
265     CellInformation::CellType GetNetworkType() const override;
266     std::string ToString() const override;
267     void SetCdmaParam(int32_t baseId, int32_t latitude, int32_t longitude, int32_t nid, int32_t sid);
268     CdmaCellInformation(const CdmaCellInformation &cdmaCell);
269     CdmaCellInformation &operator=(const CdmaCellInformation &cdmaCell);
270     bool operator==(const CdmaCellInformation &other) const;
271     void UpdateLocation(int32_t baseId, int32_t latitude, int32_t longitude);
272     /**
273      * @brief Obtain cdma base station identification number
274      *
275      * @return CDMA base station identification number
276      */
277     int32_t GetBaseId() const;
278     /**
279      * @brief Obtain cdma base station latitude
280      *
281      * @return CDMA base station latitude
282      */
283     int32_t GetLatitude() const;
284     /**
285      * @brief Obtain cdma base station longitude
286      *
287      * @return CDMA base station longitude
288      */
289     int32_t GetLongitude() const;
290     /**
291      * @brief Obtain cdma network identification number
292      *
293      * @return CDMA network identification number
294      */
295     int32_t GetNid() const;
296     /**
297      * @brief Obtain cdma system identification number
298      *
299      * @return CDMA system identification number
300      */
301     int32_t GetSid() const;
302 
303 private:
304     int32_t baseId_ = 0;
305     int32_t latitude_ = 0;
306     int32_t longitude_ = 0;
307     int32_t nid_ = 0;
308     int32_t sid_ = 0;
309 };
310 
311 class NrCellInformation : public CellInformation {
312 public:
313     NrCellInformation() = default;
314     virtual ~NrCellInformation() = default;
315     bool Marshalling(Parcel &parcel) const override;
316     static NrCellInformation *Unmarshalling(Parcel &parcel);
317     bool ReadFromParcel(Parcel &parcel) override;
318     bool ReadIntFromParcel(Parcel &parcel);
319     CellInformation::CellType GetNetworkType() const override;
320     std::string ToString() const override;
321     void SetNrParam(int32_t nrArfcn, int32_t pci, int32_t tac, int64_t nci);
322     void SetNrSignalParam(int32_t rsrp, int32_t rsrq);
323     NrCellInformation(const NrCellInformation &nrCell);
324     NrCellInformation &operator=(const NrCellInformation &nrCell);
325     bool operator==(const NrCellInformation &other) const;
326     void UpdateLocation(int32_t pci, int32_t tac);
327     /**
328      * @return Absolute RF Channel Number
329      */
330     int32_t GetArfcn() const;
331     /**
332      * @brief Obtain the Physical Cell Id
333      *
334      * @return Physical Cell Id
335      */
336     int32_t GetPci() const;
337     /**
338      * @brief Obtain the Tracking Area Code
339      *
340      * @return Tracking Area Code
341      */
342     int32_t GetTac() const;
343     /**
344      * @brief Obtain the NR(New Radio 5G) Cell Identity
345      *
346      * @return NR(New Radio 5G) Cell Identity
347      */
348     int64_t GetNci() const;
349 
350 private:
351     int32_t nrArfcn_ = 0;
352     int32_t pci_ = 0;
353     int32_t tac_ = 0;
354     int64_t nci_ = 0;
355     int32_t rsrp_ = 0;
356     int32_t rsrq_ = 0;
357 };
358 } // namespace Telephony
359 } // namespace OHOS
360 #endif // OHOS_CELL_INFORMATION_H