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 namespace general_test {
21 namespace {
22 constexpr int32_t kInvalid = INT32_MAX;
23 } // namespace
24
validateIdentity(const struct chreWwanCellIdentityNr & identity,bool registered)25 bool CellInfoNr::validateIdentity(const struct chreWwanCellIdentityNr &identity,
26 bool registered) {
27 bool valid = false;
28
29 if (!isBoundedInt32(identity.mcc, 0, 999, kInvalid, !registered)) {
30 sendFatalFailureInt32("Invalid NR Mobile Country Code: %d", identity.mcc);
31 } else if (!isBoundedInt32(identity.mnc, 0, 999, kInvalid, !registered)) {
32 sendFatalFailureInt32("Invalid NR Mobile Network Code: %d", identity.mnc);
33 } else if (!isBoundedInt64(chreWwanUnpackNrNci(&identity), 0, 68719476735,
34 INT64_MAX)) {
35 chreLog(CHRE_LOG_ERROR, "Invalid NR Cell Identity: %" PRId64,
36 chreWwanUnpackNrNci(&identity));
37 sendFatalFailure("Invalid NR Cell Identity");
38 } else if (!isBoundedInt32(identity.pci, 0, 1007, kInvalid,
39 false /* invalidAllowed*/)) {
40 sendFatalFailureInt32("Invalid NR Physical Cell Id: %d", identity.pci);
41 } else if (!isBoundedInt32(identity.tac, 0, 16777215, kInvalid)) {
42 sendFatalFailureInt32("Invalid NR Tracking Area Code: %d", identity.tac);
43 } else if (!isBoundedInt32(identity.nrarfcn, 0, 3279165, kInvalid,
44 false /* invalidAllowed */)) {
45 sendFatalFailureInt32("Invalid NR Absolute RF Channel Number: %d",
46 identity.nrarfcn);
47 } else {
48 valid = true;
49 }
50
51 return valid;
52 }
53
validateSignalStrength(const struct chreWwanSignalStrengthNr & strength)54 bool CellInfoNr::validateSignalStrength(
55 const struct chreWwanSignalStrengthNr &strength) {
56 bool valid = false;
57
58 if (!isBoundedInt32(strength.ssRsrp, 44, 140, kInvalid)) {
59 sendFatalFailureInt32("Invalid NR SS RSRP: %d", strength.ssRsrp);
60 } else if (!isBoundedInt32(strength.ssRsrq, -86, 41, kInvalid)) {
61 sendFatalFailureInt32("Invalid NR SS RSRQ: %d", strength.ssRsrq);
62 } else if (!isBoundedInt32(strength.ssSinr, -46, 81, kInvalid)) {
63 sendFatalFailureInt32("Invalid NR SS SINR: %d", strength.ssSinr);
64 } else if (!isBoundedInt32(strength.csiRsrp, 44, 140, kInvalid)) {
65 sendFatalFailureInt32("Invalid NR CSI RSRP: %d", strength.csiRsrp);
66 } else if (!isBoundedInt32(strength.csiRsrq, -86, 41, kInvalid)) {
67 sendFatalFailureInt32("Invalid NR CSI RSRQ: %d", strength.csiRsrq);
68 } else if (!isBoundedInt32(strength.csiSinr, -46, 81, kInvalid)) {
69 sendFatalFailureInt32("Invalid NR CSI SINR: %d", strength.csiSinr);
70 } else {
71 valid = true;
72 }
73
74 return valid;
75 }
76
validate(const struct chreWwanCellInfoNr & cell,bool registered)77 bool CellInfoNr::validate(const struct chreWwanCellInfoNr &cell,
78 bool registered) {
79 return (validateIdentity(cell.cellIdentityNr, registered) &&
80 validateSignalStrength(cell.signalStrengthNr));
81 }
82
83 } // namespace general_test
84