hardware/ril
Revision | 964b483df580ef27664669610250318228aac23f (tree) |
---|---|
Time | 2018-10-06 12:15:57 |
Author | android-build-team Robot <android-build-team-robot@goog...> |
Commiter | android-build-team Robot |
Snap for 5053079 from 5f438e18ba37089a8ae58fca529ab1cb964e9f81 to pi-qpr2-release
Change-Id: Ie86cd6aae2b1ad9fa68af015827da13623bd1e52
@@ -1360,14 +1360,18 @@ typedef struct { | ||
1360 | 1360 | |
1361 | 1361 | typedef struct { |
1362 | 1362 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1363 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1363 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1364 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1365 | + INT_MAX if unknown */ | |
1364 | 1366 | int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ |
1365 | 1367 | int cid; /* 16-bit GSM Cell Identity described in TS 27.007, 0..65535, INT_MAX if unknown */ |
1366 | 1368 | } RIL_CellIdentityGsm; |
1367 | 1369 | |
1368 | 1370 | typedef struct { |
1369 | 1371 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1370 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1372 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1373 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1374 | + INT_MAX if unknown */ | |
1371 | 1375 | int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ |
1372 | 1376 | int cid; /* 16-bit GSM Cell Identity described in TS 27.007, 0..65535, INT_MAX if unknown */ |
1373 | 1377 | int arfcn; /* 16-bit GSM Absolute RF channel number; this value must be reported */ |
@@ -1376,7 +1380,9 @@ typedef struct { | ||
1376 | 1380 | |
1377 | 1381 | typedef struct { |
1378 | 1382 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1379 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1383 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1384 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1385 | + INT_MAX if unknown */ | |
1380 | 1386 | int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ |
1381 | 1387 | int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ |
1382 | 1388 | int psc; /* 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511, INT_MAX if unknown */ |
@@ -1384,7 +1390,9 @@ typedef struct { | ||
1384 | 1390 | |
1385 | 1391 | typedef struct { |
1386 | 1392 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1387 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1393 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1394 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1395 | + INT_MAX if unknown */ | |
1388 | 1396 | int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ |
1389 | 1397 | int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ |
1390 | 1398 | int psc; /* 9-bit UMTS Primary Scrambling Code described in TS 25.331, 0..511; this value must be reported */ |
@@ -1408,7 +1416,9 @@ typedef struct { | ||
1408 | 1416 | |
1409 | 1417 | typedef struct { |
1410 | 1418 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1411 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1419 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1420 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1421 | + INT_MAX if unknown */ | |
1412 | 1422 | int ci; /* 28-bit Cell Identity described in TS ???, INT_MAX if unknown */ |
1413 | 1423 | int pci; /* physical cell id 0..503, INT_MAX if unknown */ |
1414 | 1424 | int tac; /* 16-bit tracking area code, INT_MAX if unknown */ |
@@ -1416,7 +1426,9 @@ typedef struct { | ||
1416 | 1426 | |
1417 | 1427 | typedef struct { |
1418 | 1428 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1419 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1429 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1430 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1431 | + INT_MAX if unknown */ | |
1420 | 1432 | int ci; /* 28-bit Cell Identity described in TS ???, INT_MAX if unknown */ |
1421 | 1433 | int pci; /* physical cell id 0..503; this value must be reported */ |
1422 | 1434 | int tac; /* 16-bit tracking area code, INT_MAX if unknown */ |
@@ -1425,7 +1437,9 @@ typedef struct { | ||
1425 | 1437 | |
1426 | 1438 | typedef struct { |
1427 | 1439 | int mcc; /* 3-digit Mobile Country Code, 0..999, INT_MAX if unknown */ |
1428 | - int mnc; /* 2 or 3-digit Mobile Network Code, 0..999, INT_MAX if unknown */ | |
1440 | + int mnc; /* 2 or 3-digit Mobile Network Code, 0..999; | |
1441 | + the most significant nibble encodes the number of digits - {2, 3, 0 (unset)}; | |
1442 | + INT_MAX if unknown */ | |
1429 | 1443 | int lac; /* 16-bit Location Area Code, 0..65535, INT_MAX if unknown */ |
1430 | 1444 | int cid; /* 28-bit UMTS Cell Identity described in TS 25.331, 0..268435455, INT_MAX if unknown */ |
1431 | 1445 | int cpid; /* 8-bit Cell Parameters ID described in TS 25.331, 0..127, INT_MAX if unknown */ |
@@ -0,0 +1,149 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2018 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 | + | |
17 | +#ifndef RIL_MNC_H | |
18 | +#define RIL_MNC_H | |
19 | + | |
20 | +#include <climits> | |
21 | +#include <cstdio> | |
22 | +#include <string> | |
23 | + | |
24 | +namespace ril { | |
25 | +namespace util { | |
26 | +namespace mnc { | |
27 | + | |
28 | +/** | |
29 | + * Decode an MNC with an optional length indicator provided in the most-significant nibble. | |
30 | + * | |
31 | + * @param mnc an encoded MNC value; if no encoding is provided, then the string is returned | |
32 | + * as a minimum length string representing the provided integer. | |
33 | + * | |
34 | + * @return string representation of an encoded MNC or an empty string if the MNC is not a valid | |
35 | + * MNC value. | |
36 | + */ | |
37 | +static inline std::string decode(int mnc) { | |
38 | + if (mnc == INT_MAX || mnc < 0) return ""; | |
39 | + unsigned umnc = mnc; | |
40 | + char mncNumDigits = (umnc >> (sizeof(int) * 8 - 4)) & 0xF; | |
41 | + | |
42 | + umnc = (umnc << 4) >> 4; | |
43 | + if (umnc > 999) return ""; | |
44 | + | |
45 | + char mncStr[4] = {0}; | |
46 | + switch (mncNumDigits) { | |
47 | + case 0: | |
48 | + // Legacy MNC report hasn't set the number of digits; preserve current | |
49 | + // behavior and make a string of the minimum number of required digits. | |
50 | + return std::to_string(umnc); | |
51 | + | |
52 | + case 2: | |
53 | + snprintf(mncStr, sizeof(mncStr), "%03.3u", umnc); | |
54 | + return mncStr + 1; | |
55 | + | |
56 | + case 3: | |
57 | + snprintf(mncStr, sizeof(mncStr), "%03.3u", umnc); | |
58 | + return mncStr; | |
59 | + | |
60 | + default: | |
61 | + // Error case | |
62 | + return ""; | |
63 | + } | |
64 | + | |
65 | +} | |
66 | + | |
67 | +/** | |
68 | + * Encode an MNC of the given value and a given number of digits | |
69 | + * | |
70 | + * @param mnc an MNC value 0-999 or INT_MAX if unknown | |
71 | + * @param numDigits the number of MNC digits {2, 3} or 0 if unknown | |
72 | + * | |
73 | + * @return an encoded MNC with embedded length information | |
74 | + */ | |
75 | +static inline int encode(int mnc, int numDigits) { | |
76 | + if (mnc > 999 || mnc < 0) return INT_MAX; | |
77 | + switch (numDigits) { | |
78 | + case 0: // fall through | |
79 | + case 2: // fall through | |
80 | + case 3: | |
81 | + break; | |
82 | + | |
83 | + default: | |
84 | + return INT_MAX; | |
85 | + }; | |
86 | + | |
87 | + return (numDigits << (sizeof(int) * 8 - 4)) | mnc; | |
88 | +} | |
89 | + | |
90 | +/** | |
91 | + * Encode an MNC of the given value | |
92 | + * | |
93 | + * @param mnc the string representation of the MNC, with the length equal to the length of the | |
94 | + * provided string. | |
95 | + * | |
96 | + * @return an encoded MNC with embedded length information | |
97 | + */ | |
98 | +static inline int encode(const std::string & mnc) { | |
99 | + return encode(std::stoi(mnc), mnc.length()); | |
100 | +} | |
101 | + | |
102 | +// echo -e "#include \"hardware/ril/include/telephony/ril_mnc.h\"\nint main()"\ | |
103 | +// "{ return ril::util::mnc::test(); }" > ril_test.cpp \ | |
104 | +// && g++ -o /tmp/ril_test -DTEST_RIL_MNC ril_test.cpp; \ | |
105 | +// rm ril_test.cpp; /tmp/ril_test && [ $? ] && echo "passed" | |
106 | +#ifdef TEST_RIL_MNC | |
107 | +static int test() { | |
108 | + const struct mnc_strings { const char * in; const char * out; } mncs[] = { | |
109 | + {"0001",""}, | |
110 | + {"9999",""}, | |
111 | + {"0",""}, | |
112 | + {"9",""}, | |
113 | + {"123","123"}, | |
114 | + {"000","000"}, | |
115 | + {"001","001"}, | |
116 | + {"011","011"}, | |
117 | + {"111","111"}, | |
118 | + {"00","00"}, | |
119 | + {"01","01"}, | |
120 | + {"11","11"}, | |
121 | + {"09","09"}, | |
122 | + {"099","099"}, | |
123 | + {"999", "999"}}; | |
124 | + | |
125 | + for (int i=0; i< sizeof(mncs) / sizeof(struct mnc_strings); i++) { | |
126 | + if (decode(encode(mncs[i].in)).compare(mncs[i].out)) return 1; | |
127 | + } | |
128 | + | |
129 | + const struct mnc_ints { const int in; const char * out; } legacy_mncs[] = { | |
130 | + {INT_MAX, ""}, | |
131 | + {1, "1"}, | |
132 | + {11, "11"}, | |
133 | + {111, "111"}, | |
134 | + {0, "0"}, | |
135 | + {9999, ""}, | |
136 | + }; | |
137 | + | |
138 | + for (int i=0; i < sizeof(legacy_mncs) / sizeof(struct mnc_ints); i++) { | |
139 | + if (decode(legacy_mncs[i].in).compare(legacy_mncs[i].out)) return 1; | |
140 | + } | |
141 | + | |
142 | + return 0; | |
143 | +} | |
144 | +#endif | |
145 | + | |
146 | +} | |
147 | +} | |
148 | +} | |
149 | +#endif /* !defined(RIL_MNC_H) */ |
@@ -25,6 +25,8 @@ | ||
25 | 25 | |
26 | 26 | #include <hwbinder/IPCThreadState.h> |
27 | 27 | #include <hwbinder/ProcessState.h> |
28 | +#include <telephony/ril.h> | |
29 | +#include <telephony/ril_mnc.h> | |
28 | 30 | #include <ril_service.h> |
29 | 31 | #include <hidl/HidlTransportSupport.h> |
30 | 32 | #include <utils/SystemClock.h> |
@@ -3549,7 +3551,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 & | ||
3549 | 3551 | cellIdentity.cellIdentityGsm[0].mcc = |
3550 | 3552 | std::to_string(rilCellIdentity.cellIdentityGsm.mcc); |
3551 | 3553 | cellIdentity.cellIdentityGsm[0].mnc = |
3552 | - std::to_string(rilCellIdentity.cellIdentityGsm.mnc); | |
3554 | + ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc); | |
3553 | 3555 | cellIdentity.cellIdentityGsm[0].lac = rilCellIdentity.cellIdentityGsm.lac; |
3554 | 3556 | cellIdentity.cellIdentityGsm[0].cid = rilCellIdentity.cellIdentityGsm.cid; |
3555 | 3557 | cellIdentity.cellIdentityGsm[0].arfcn = rilCellIdentity.cellIdentityGsm.arfcn; |
@@ -3562,7 +3564,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 & | ||
3562 | 3564 | cellIdentity.cellIdentityWcdma[0].mcc = |
3563 | 3565 | std::to_string(rilCellIdentity.cellIdentityWcdma.mcc); |
3564 | 3566 | cellIdentity.cellIdentityWcdma[0].mnc = |
3565 | - std::to_string(rilCellIdentity.cellIdentityWcdma.mnc); | |
3567 | + ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc); | |
3566 | 3568 | cellIdentity.cellIdentityWcdma[0].lac = rilCellIdentity.cellIdentityWcdma.lac; |
3567 | 3569 | cellIdentity.cellIdentityWcdma[0].cid = rilCellIdentity.cellIdentityWcdma.cid; |
3568 | 3570 | cellIdentity.cellIdentityWcdma[0].psc = rilCellIdentity.cellIdentityWcdma.psc; |
@@ -3586,7 +3588,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 & | ||
3586 | 3588 | cellIdentity.cellIdentityLte[0].mcc = |
3587 | 3589 | std::to_string(rilCellIdentity.cellIdentityLte.mcc); |
3588 | 3590 | cellIdentity.cellIdentityLte[0].mnc = |
3589 | - std::to_string(rilCellIdentity.cellIdentityLte.mnc); | |
3591 | + ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc); | |
3590 | 3592 | cellIdentity.cellIdentityLte[0].ci = rilCellIdentity.cellIdentityLte.ci; |
3591 | 3593 | cellIdentity.cellIdentityLte[0].pci = rilCellIdentity.cellIdentityLte.pci; |
3592 | 3594 | cellIdentity.cellIdentityLte[0].tac = rilCellIdentity.cellIdentityLte.tac; |
@@ -3599,7 +3601,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 & | ||
3599 | 3601 | cellIdentity.cellIdentityTdscdma[0].mcc = |
3600 | 3602 | std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc); |
3601 | 3603 | cellIdentity.cellIdentityTdscdma[0].mnc = |
3602 | - std::to_string(rilCellIdentity.cellIdentityTdscdma.mnc); | |
3604 | + ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc); | |
3603 | 3605 | cellIdentity.cellIdentityTdscdma[0].lac = rilCellIdentity.cellIdentityTdscdma.lac; |
3604 | 3606 | cellIdentity.cellIdentityTdscdma[0].cid = rilCellIdentity.cellIdentityTdscdma.cid; |
3605 | 3607 | cellIdentity.cellIdentityTdscdma[0].cpid = rilCellIdentity.cellIdentityTdscdma.cpid; |
@@ -7863,7 +7865,7 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce | ||
7863 | 7865 | cellInfoGsm->cellIdentityGsm.mcc = |
7864 | 7866 | std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc); |
7865 | 7867 | cellInfoGsm->cellIdentityGsm.mnc = |
7866 | - std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc); | |
7868 | + ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc); | |
7867 | 7869 | cellInfoGsm->cellIdentityGsm.lac = |
7868 | 7870 | rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac; |
7869 | 7871 | cellInfoGsm->cellIdentityGsm.cid = |
@@ -7887,7 +7889,7 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce | ||
7887 | 7889 | cellInfoWcdma->cellIdentityWcdma.mcc = |
7888 | 7890 | std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc); |
7889 | 7891 | cellInfoWcdma->cellIdentityWcdma.mnc = |
7890 | - std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc); | |
7892 | + ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc); | |
7891 | 7893 | cellInfoWcdma->cellIdentityWcdma.lac = |
7892 | 7894 | rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac; |
7893 | 7895 | cellInfoWcdma->cellIdentityWcdma.cid = |
@@ -7935,7 +7937,7 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce | ||
7935 | 7937 | cellInfoLte->cellIdentityLte.mcc = |
7936 | 7938 | std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc); |
7937 | 7939 | cellInfoLte->cellIdentityLte.mnc = |
7938 | - std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc); | |
7940 | + ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc); | |
7939 | 7941 | cellInfoLte->cellIdentityLte.ci = |
7940 | 7942 | rillCellInfo->CellInfo.lte.cellIdentityLte.ci; |
7941 | 7943 | cellInfoLte->cellIdentityLte.pci = |
@@ -7965,7 +7967,8 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce | ||
7965 | 7967 | cellInfoTdscdma->cellIdentityTdscdma.mcc = |
7966 | 7968 | std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc); |
7967 | 7969 | cellInfoTdscdma->cellIdentityTdscdma.mnc = |
7968 | - std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc); | |
7970 | + ril::util::mnc::decode( | |
7971 | + rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc); | |
7969 | 7972 | cellInfoTdscdma->cellIdentityTdscdma.lac = |
7970 | 7973 | rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac; |
7971 | 7974 | cellInfoTdscdma->cellIdentityTdscdma.cid = |