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_wcdma.h>
17 
18 namespace general_test {
19 
validateIdentity(const struct chreWwanCellIdentityWcdma & identity)20 bool CellInfoWcdma::validateIdentity(
21     const struct chreWwanCellIdentityWcdma &identity) {
22   bool valid = false;
23 
24   if (!isBoundedInt32(identity.mcc, 0, 999, INT32_MAX)) {
25     sendFatalFailureInt32("Invalid WCDMA Mobile Country Code: %d",
26                           identity.mcc);
27   } else if (!isBoundedInt32(identity.mnc, 0, 999, INT32_MAX)) {
28     sendFatalFailureInt32("Invalid WCDMA Mobile Network Code: %d",
29                           identity.mnc);
30   } else if (!isBoundedInt32(identity.lac, 0, 65535, INT32_MAX)) {
31     sendFatalFailureInt32("Invalid WCDMA Location Area Code: %d", identity.lac);
32   } else if (!isBoundedInt32(identity.cid, 0, 268435455, INT32_MAX)) {
33     sendFatalFailureInt32("Invalid WCDMA Cell Identity: %d", identity.cid);
34   } else if (!isBoundedInt32(identity.psc, 0, 511, INT32_MAX)) {
35     sendFatalFailureInt32("Invalid WCDMA Primary Scrambling Code: %d",
36                           identity.psc);
37   } else if (!isBoundedInt32(identity.uarfcn, 0, 65535, INT32_MAX)) {
38     sendFatalFailureInt32("Invalid WCDMA Absolute RF Channel Number: %d",
39                           identity.uarfcn);
40   } else {
41     valid = true;
42   }
43 
44   return valid;
45 }
46 
validateSignalStrength(const struct chreWwanSignalStrengthWcdma & strength)47 bool CellInfoWcdma::validateSignalStrength(
48     const struct chreWwanSignalStrengthWcdma &strength) {
49   bool valid = false;
50 
51   if (!isBoundedInt32(strength.signalStrength, 0, 31, INT32_MAX) &&
52       strength.signalStrength != 99) {
53     sendFatalFailureInt32("Invalid WCDMA Signal Strength: %d",
54                           strength.signalStrength);
55   } else if (!isBoundedInt32(strength.bitErrorRate, 0, 7, INT32_MAX) &&
56              strength.bitErrorRate != 99) {
57     sendFatalFailureInt32("Invalid WCDMA Bit Error Rate: %d",
58                           strength.bitErrorRate);
59   } else {
60     valid = true;
61   }
62 
63   return valid;
64 }
65 
validate(const struct chreWwanCellInfoWcdma & cell)66 bool CellInfoWcdma::validate(const struct chreWwanCellInfoWcdma &cell) {
67   return (validateIdentity(cell.cellIdentityWcdma) &&
68           validateSignalStrength(cell.signalStrengthWcdma));
69 }
70 
71 }  // namespace general_test
72