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_tdscdma.h>
17
18 namespace general_test {
19
validateIdentity(const struct chreWwanCellIdentityTdscdma identity)20 bool CellInfoTdscdma::validateIdentity(
21 const struct chreWwanCellIdentityTdscdma identity) {
22 bool valid = false;
23
24 if (!isBoundedInt32(identity.mcc, 0, 999, INT32_MAX)) {
25 sendFatalFailureInt32(
26 "Invalid TDSCDMA Mobile Country Code: %d", identity.mcc);
27 } else if (!isBoundedInt32(identity.mnc, 0, 999, INT32_MAX)) {
28 sendFatalFailureInt32(
29 "Invalid TDSCDMA Mobile Network Code: %d", identity.mnc);
30 } else if (!isBoundedInt32(identity.lac, 0, 65535, INT32_MAX)) {
31 sendFatalFailureInt32(
32 "Invalid TDSCDMA Location Area Code: %d", identity.lac);
33 } else if (!isBoundedInt32(identity.cid, 0, 65535, INT32_MAX)) {
34 sendFatalFailureInt32(
35 "Invalid TDSCDMA Cell Identity: %d", identity.cid);
36 } else if (!isBoundedInt32(identity.cpid, 0, 127, INT32_MAX)) {
37 sendFatalFailureInt32(
38 "Invalid TDSCDMA Cell Parameters ID: %d", identity.cpid);
39 } else {
40 valid = true;
41 }
42
43 return valid;
44 }
45
validateSignalStrength(const struct chreWwanSignalStrengthTdscdma strength)46 bool CellInfoTdscdma::validateSignalStrength(
47 const struct chreWwanSignalStrengthTdscdma strength) {
48 bool valid = false;
49
50 if (!isBoundedInt32(strength.rscp, 25, 120, INT32_MAX)) {
51 sendFatalFailureInt32("Invalid TDSCDMA Received Signal Code Power: %d",
52 strength.rscp);
53 } else {
54 valid = true;
55 }
56
57 return valid;
58 }
59
validate(const struct chreWwanCellInfoTdscdma & cell)60 bool CellInfoTdscdma::validate(const struct chreWwanCellInfoTdscdma& cell) {
61 return (validateIdentity(cell.cellIdentityTdscdma)
62 && validateSignalStrength(cell.signalStrengthTdscdma));
63 }
64
65 } // namespace general_test
66