1 /*
2 * Copyright (c) 2023-2024 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 #include "nr_ssb_info.h"
17
18 #include "network_search_manager.h"
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
NrSsbInfo(std::weak_ptr<NetworkSearchManager> networkSearchManager,int32_t slotId)23 NrSsbInfo::NrSsbInfo(std::weak_ptr<NetworkSearchManager> networkSearchManager, int32_t slotId)
24 : networkSearchManager_(networkSearchManager), slotId_(slotId)
25 {
26 nrCellSsbIdsInfo_ = std::make_shared<NrCellSsbInfo>();
27 }
28
FillNrSsbIdInformation(const std::shared_ptr<NrSsbInformation> & nrCellSsbIdsInfo)29 bool NrSsbInfo::FillNrSsbIdInformation(const std::shared_ptr<NrSsbInformation> &nrCellSsbIdsInfo)
30 {
31 std::lock_guard<std::mutex> lock(mutex_);
32 if (nrCellSsbIdsInfo == nullptr) {
33 TELEPHONY_LOGE("nrCellSsbIdsInfo is null");
34 return false;
35 }
36 nrCellSsbIdsInfo->SetSsbBaseParam(nrCellSsbIdsInfo_->arfcn, nrCellSsbIdsInfo_->cid, nrCellSsbIdsInfo_->pci,
37 nrCellSsbIdsInfo_->rsrp, nrCellSsbIdsInfo_->sinr, nrCellSsbIdsInfo_->timeAdvance);
38 nrCellSsbIdsInfo->SetSCellSsbList(nrCellSsbIdsInfo_->sCellSsbList);
39 nrCellSsbIdsInfo->SetNbCellSsbList(nrCellSsbIdsInfo_->nbCellCount, nrCellSsbIdsInfo_->nbCellSsbList);
40 return true;
41 }
42
ProcessGetNrSsbId(const AppExecFwk::InnerEvent::Pointer & event)43 bool NrSsbInfo::ProcessGetNrSsbId(const AppExecFwk::InnerEvent::Pointer &event)
44 {
45 std::lock_guard<std::mutex> lock(mutex_);
46 if (event == nullptr) {
47 TELEPHONY_LOGE("Event is nullptr");
48 return false;
49 }
50 std::shared_ptr<NrCellSsbIds> nrCellSsbIds = event->GetSharedObject<NrCellSsbIds>();
51 if (nrCellSsbIds == nullptr) {
52 TELEPHONY_LOGE("NrCellSsbIds is nullptr");
53 return false;
54 }
55
56 if (!UpdateNrSsbIdInfo(slotId_, nrCellSsbIds)) {
57 TELEPHONY_LOGE("Get ssb info is failed");
58 return false;
59 }
60 return true;
61 }
62
UpdateNrSsbIdInfo(int32_t slotId,std::shared_ptr<NrCellSsbIds> nrCellSsbIds)63 bool NrSsbInfo::UpdateNrSsbIdInfo(int32_t slotId, std::shared_ptr<NrCellSsbIds> nrCellSsbIds)
64 {
65 if (nrCellSsbIds == nullptr || nrCellSsbIdsInfo_ == nullptr) {
66 TELEPHONY_LOGE("nrCellSsbIds or nrCellSsbIdsInfo_ is nullptr");
67 return false;
68 }
69 if (nrCellSsbIds->nbCellCount > NrSsbInformation::MAX_NBCELL_COUNT) {
70 TELEPHONY_LOGE("nbCellCount:%{public}d > MAX_NBCELL_COUNT", nrCellSsbIds->nbCellCount);
71 return false;
72 }
73 nrCellSsbIdsInfo_->arfcn = nrCellSsbIds->arfcn;
74 nrCellSsbIdsInfo_->cid = nrCellSsbIds->cid;
75 nrCellSsbIdsInfo_->pci = nrCellSsbIds->pic;
76 nrCellSsbIdsInfo_->rsrp = nrCellSsbIds->rsrp;
77 nrCellSsbIdsInfo_->sinr = nrCellSsbIds->sinr;
78 nrCellSsbIdsInfo_->timeAdvance = nrCellSsbIds->timeAdvance;
79 nrCellSsbIdsInfo_->nbCellCount = nrCellSsbIds->nbCellCount;
80 for (const auto &info : nrCellSsbIds->sCellSsbList) {
81 SsbInfo ssbInfo;
82 ssbInfo.ssbId = info.ssbId;
83 ssbInfo.rsrp = info.rsrp;
84 nrCellSsbIdsInfo_->sCellSsbList.push_back(ssbInfo);
85 }
86 for (int32_t i = 0; i < nrCellSsbIds->nbCellCount; i++) {
87 NeighboringCellSsbInformation neighboringCellSsbInfo;
88 neighboringCellSsbInfo.pci = nrCellSsbIds->nbCellSsbList[i].pci;
89 neighboringCellSsbInfo.arfcn = nrCellSsbIds->nbCellSsbList[i].arfcn;
90 neighboringCellSsbInfo.rsrp = nrCellSsbIds->nbCellSsbList[i].rsrp;
91 neighboringCellSsbInfo.sinr = nrCellSsbIds->nbCellSsbList[i].sinr;
92 for (const auto &info : nrCellSsbIds->nbCellSsbList[i].ssbIdList) {
93 SsbInfo ssbInfo;
94 ssbInfo.ssbId = info.ssbId;
95 ssbInfo.rsrp = info.rsrp;
96 neighboringCellSsbInfo.ssbList.push_back(ssbInfo);
97 }
98 nrCellSsbIdsInfo_->nbCellSsbList.push_back(neighboringCellSsbInfo);
99 }
100 return true;
101 }
102 } // namespace Telephony
103 } // namespace OHOS