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