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_gsm.h>
17
18 namespace general_test {
19
validateIdentity(const struct chreWwanCellIdentityGsm & identity)20 bool CellInfoGsm::validateIdentity(
21 const struct chreWwanCellIdentityGsm &identity) {
22 bool valid = false;
23
24 if (!isBoundedInt32(identity.mcc, 0, 999, INT32_MAX)) {
25 sendFatalFailureInt32("Invalid GSM Mobile Country Code: %d", identity.mcc);
26 } else if (!isBoundedInt32(identity.mnc, 0, 999, INT32_MAX)) {
27 sendFatalFailureInt32("Invalid GSM Mobile Network Code: %d", identity.mnc);
28 } else if (!isBoundedInt32(identity.lac, 0, 65535, INT32_MAX)) {
29 sendFatalFailureInt32("Invalid GSM Location Area Code", identity.lac);
30 } else if (!isBoundedInt32(identity.cid, 0, 65535, INT32_MAX)) {
31 sendFatalFailureInt32("Invalid GSM Cell Identity: %d", identity.cid);
32 } else if (!isBoundedInt32(identity.arfcn, 0, 65535, INT32_MAX)) {
33 sendFatalFailureInt32("Invalid GSM Absolute RF Channel Number: %d",
34 identity.arfcn);
35 } else if ((identity.bsic > 63) && (identity.bsic != UINT8_MAX)) {
36 sendFatalFailureUint8("Invalid GSM Base Station Identity Code: %d",
37 identity.bsic);
38 } else {
39 valid = true;
40
41 for (uint8_t byte : identity.reserved) {
42 if (byte != 0) {
43 valid = false;
44 sendFatalFailureUint8("Invalid GSM reserved byte: %d", byte);
45 }
46
47 if (!valid) {
48 break;
49 }
50 }
51 }
52
53 return valid;
54 }
55
validateSignalStrength(const struct chreWwanSignalStrengthGsm & strength)56 bool CellInfoGsm::validateSignalStrength(
57 const struct chreWwanSignalStrengthGsm &strength) {
58 bool valid = false;
59
60 if (!isBoundedInt32(strength.signalStrength, 0, 31, INT32_MAX) &&
61 strength.signalStrength != 99) {
62 sendFatalFailureInt32("Invalid GSM signal strength: %d",
63 strength.signalStrength);
64 } else if (!isBoundedInt32(strength.bitErrorRate, 0, 7, INT32_MAX) &&
65 strength.bitErrorRate != 99) {
66 sendFatalFailureInt32("Invalid GSM bit error rate: %d",
67 strength.bitErrorRate);
68 } else {
69 valid = true;
70 }
71
72 return valid;
73 }
74
validate(const struct chreWwanCellInfoGsm & cell)75 bool CellInfoGsm::validate(const struct chreWwanCellInfoGsm &cell) {
76 return (validateIdentity(cell.cellIdentityGsm) &&
77 validateSignalStrength(cell.signalStrengthGsm));
78 }
79
80 } // namespace general_test
81