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