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