1 /*
2 * Copyright (C) 2017 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_lte.h>
17
18 namespace general_test {
19
validateIdentity(const struct chreWwanCellIdentityLte identity)20 bool CellInfoLte::validateIdentity(
21 const struct chreWwanCellIdentityLte identity) {
22 bool valid = false;
23
24 if (!isBoundedInt32(identity.mcc, 0, 999, INT32_MAX)) {
25 sendFatalFailureInt32(
26 "Invalid LTE Mobile Country Code: %d", identity.mcc);
27 } else if (!isBoundedInt32(identity.mnc, 0, 999, INT32_MAX)) {
28 sendFatalFailureInt32(
29 "Invalid LTE Mobile Network Code: %d", identity.mnc);
30 } else if (!isBoundedInt32(identity.ci, 0, 268435455, INT32_MAX)) {
31 sendFatalFailureInt32("Invalid LTE Cell Identity: %d", identity.ci);
32 } else if (!isBoundedInt32(identity.pci, 0, 503, INT32_MAX)) {
33 sendFatalFailureInt32("Invalid LTE Physical Cell Id: %d", identity.pci);
34 } else if (!isBoundedInt32(identity.tac, 0, 65535, INT32_MAX)) {
35 sendFatalFailureInt32(
36 "Invalid LTE Tracking Area Code: %d", identity.tac);
37 } else if (!isBoundedInt32(identity.earfcn, 0, 262144, INT32_MAX)) {
38 sendFatalFailureInt32("Invalid LTE Absolute RF Channel Number: %d",
39 identity.earfcn);
40 } else {
41 valid = true;
42 }
43
44 return valid;
45 }
46
validateSignalStrength(const struct chreWwanSignalStrengthLte strength)47 bool CellInfoLte::validateSignalStrength(
48 const struct chreWwanSignalStrengthLte strength) {
49 bool valid = false;
50 constexpr int32_t max = INT32_MAX;
51
52 if (!isBoundedInt32(strength.signalStrength, 0, 31, 99)) {
53 sendFatalFailureInt32("Invalid LTE Signal Strength: %d",
54 strength.signalStrength);
55 } else if (!isBoundedInt32(strength.rsrp, 44, 140, max)) {
56 sendFatalFailureInt32("Invalid LTE Reference Signal Receive Power: %d",
57 strength.rsrp);
58 } else if (!isBoundedInt32(strength.rsrq, 3, 20, max)) {
59 sendFatalFailureInt32(
60 "Invalid LTE Reference Signal Receive Quality: %d",
61 strength.rsrq);
62 } else if (!isBoundedInt32(strength.rssnr, -200, 300, max)) {
63 sendFatalFailureInt32(
64 "Invalid LTE Reference Signal Signal-to-noise Ratio: %d",
65 strength.rssnr);
66 } else if (!isBoundedInt32(strength.cqi, 0, 15, max)) {
67 sendFatalFailureInt32("Invalid LTE Channel Quality Indicator: %d",
68 strength.cqi);
69 } else if (!isBoundedInt32(strength.timingAdvance, 0, max, max)) {
70 sendFatalFailureInt32("Invalid LTE Timing Advance (ms): %d",
71 strength.timingAdvance);
72 } else {
73 valid = true;
74 }
75
76 return valid;
77 }
78
validate(const struct chreWwanCellInfoLte & cell)79 bool CellInfoLte::validate(const struct chreWwanCellInfoLte& cell) {
80 return (validateIdentity(cell.cellIdentityLte)
81 && validateSignalStrength(cell.signalStrengthLte));
82 }
83
84 } // namespace general_test
85