1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <general_test/cell_info_nr.h>
17
18 #include <cinttypes>
19
20 #include <chre/util/nanoapp/log.h>
21
22 #define LOG_TAG "[CellInfoNr]"
23
24 namespace general_test {
25 namespace {
26 constexpr int32_t kInvalid = INT32_MAX;
27 } // namespace
28
validateIdentity(const struct chreWwanCellIdentityNr & identity,bool registered)29 bool CellInfoNr::validateIdentity(const struct chreWwanCellIdentityNr &identity,
30 bool registered) {
31 bool valid = false;
32
33 if (!isBoundedInt32(identity.mcc, 0, 999, kInvalid, !registered)) {
34 sendFatalFailureInt32("Invalid NR Mobile Country Code: %d", identity.mcc);
35 } else if (!isBoundedInt32(identity.mnc, 0, 999, kInvalid, !registered)) {
36 sendFatalFailureInt32("Invalid NR Mobile Network Code: %d", identity.mnc);
37 } else if (!isBoundedInt64(chreWwanUnpackNrNci(&identity), 0, 68719476735,
38 INT64_MAX)) {
39 LOGE("Invalid NR Cell Identity: %" PRId64, chreWwanUnpackNrNci(&identity));
40 sendFatalFailure("Invalid NR Cell Identity");
41 } else if (!isBoundedInt32(identity.pci, 0, 1007, kInvalid,
42 false /* invalidAllowed*/)) {
43 sendFatalFailureInt32("Invalid NR Physical Cell Id: %d", identity.pci);
44 } else if (!isBoundedInt32(identity.tac, 0, 16777215, kInvalid)) {
45 sendFatalFailureInt32("Invalid NR Tracking Area Code: %d", identity.tac);
46 } else if (!isBoundedInt32(identity.nrarfcn, 0, 3279165, kInvalid,
47 false /* invalidAllowed */)) {
48 sendFatalFailureInt32("Invalid NR Absolute RF Channel Number: %d",
49 identity.nrarfcn);
50 } else {
51 valid = true;
52 }
53
54 return valid;
55 }
56
validateSignalStrength(const struct chreWwanSignalStrengthNr & strength)57 bool CellInfoNr::validateSignalStrength(
58 const struct chreWwanSignalStrengthNr &strength) {
59 bool valid = false;
60
61 if (!isBoundedInt32(strength.ssRsrp, 44, 140, kInvalid)) {
62 sendFatalFailureInt32("Invalid NR SS RSRP: %d", strength.ssRsrp);
63 } else if (!isBoundedInt32(strength.ssRsrq, -86, 41, kInvalid)) {
64 sendFatalFailureInt32("Invalid NR SS RSRQ: %d", strength.ssRsrq);
65 } else if (!isBoundedInt32(strength.ssSinr, -46, 81, kInvalid)) {
66 sendFatalFailureInt32("Invalid NR SS SINR: %d", strength.ssSinr);
67 } else if (!isBoundedInt32(strength.csiRsrp, 44, 140, kInvalid)) {
68 sendFatalFailureInt32("Invalid NR CSI RSRP: %d", strength.csiRsrp);
69 } else if (!isBoundedInt32(strength.csiRsrq, -86, 41, kInvalid)) {
70 sendFatalFailureInt32("Invalid NR CSI RSRQ: %d", strength.csiRsrq);
71 } else if (!isBoundedInt32(strength.csiSinr, -46, 81, kInvalid)) {
72 sendFatalFailureInt32("Invalid NR CSI SINR: %d", strength.csiSinr);
73 } else {
74 valid = true;
75 }
76
77 return valid;
78 }
79
validate(const struct chreWwanCellInfoNr & cell,bool registered)80 bool CellInfoNr::validate(const struct chreWwanCellInfoNr &cell,
81 bool registered) {
82 return (validateIdentity(cell.cellIdentityNr, registered) &&
83 validateSignalStrength(cell.signalStrengthNr));
84 }
85
86 } // namespace general_test
87