• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "mmi_code_utils.h"
17 
18 #include <regex>
19 
20 #include "cellular_call_supplement.h"
21 #include "standardize_utils.h"
22 #include "telephony_log_wrapper.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 // 3GPP TS 22.030 V16.0.0 (2020-07) 6.5.3.2	Handling of not-implemented supplementary services
operator ""_hash(char const * p,size_t s)27 constexpr unsigned long long operator"" _hash(char const *p, size_t s)
28 {
29     return StandardizeUtils::HashCompileTime(p);
30 }
31 
IsNeedExecuteMmi(const std::string & analyseString)32 bool MMICodeUtils::IsNeedExecuteMmi(const std::string &analyseString)
33 {
34     if (analyseString.empty()) {
35         TELEPHONY_LOGE("IsNeedExecuteMmi return, analyseString is empty.");
36         return false;
37     }
38     if (RegexMatchMmi(analyseString)) {
39         return true;
40     }
41 
42     // 3GPP TS 22.030 V16.0.0 (2020-07) 6.5.3.2	Handling of not-implemented supplementary services
43     if (analyseString.back() == '#') {
44         TELEPHONY_LOGI("IsNeedExecuteMmi, analyseString is end of #");
45         mmiData_.fullString = analyseString;
46         return true;
47     }
48 
49     return false;
50 }
51 
ExecuteMmiCode(int32_t slotId)52 bool MMICodeUtils::ExecuteMmiCode(int32_t slotId)
53 {
54     TELEPHONY_LOGI("ExecuteMmiCode entry.");
55     CellularCallSupplement supplement;
56 
57     /**
58      * "30" Processing caller ID
59      * "31" Processing calling number display
60      * "21" Deal with unconditional transfer
61      * "61" Handling no answer transfer
62      * "62" Handling no signal transfer
63      * "67" Deal with busy transfer
64      * "002" Process all transfers
65      * "004" Handle transfer under all conditions
66      * "33" Processing limits all outgoing calls
67      * "330" Processing all restrictions
68      * "331" Processing limits all international calls
69      * "332" Handling international outgoing calls belonging to foreign countries when roaming is
70      * restricted
71      * "35" Processing limits all incoming calls
72      * "351" Handle all incoming calls when roaming is restricted
73      * "03" Processing network password
74      * "43" Handling call waiting
75      */
76     if (!mmiData_.serviceCode.empty()) {
77         switch (StandardizeUtils::Hash_(mmiData_.serviceCode.c_str())) {
78             // 3GPP TS 22.030 V4.0.0 (2001-03) 6.5.6.2  Calling Line Identification Presentation (CLIP)
79             // 3GPP TS 22.030 V4.0.0 (2001-03) Annex B (normative):Codes for defined Supplementary Services
80             case "30"_hash:
81                 supplement.GetClip(slotId, mmiData_);
82                 return true;
83 
84             // 3GPP TS 22.081 V4.0.0 (2001-03) 2 Calling Line Identification Restriction (CLIR)
85             // 3GPP TS 22.030 V4.0.0 (2001-03) Annex B (normative):Codes for defined Supplementary Services
86             case "31"_hash:
87                 supplement.GetClir(slotId, mmiData_);
88                 return true;
89 
90             // 3GPP TS 22.081 V4.0.0 (2001-03)
91             // 3GPP TS 22.030 V4.0.0 (2001-03) Annex B (normative):Codes for defined Supplementary Services
92             // 3GPP TS 24.082 V4.0.0 (2001-03) 1 Call Forwarding Unconditional (CFU)
93             // 3GPP TS 24.082 V4.0.0 (2001-03) 2 Call Forwarding on mobile subscriber Busy (CFB)
94             // 3GPP TS 24.082 V4.0.0 (2001-03) 3 Call Forwarding on No Reply (CFNRy)
95             // 3GPP TS 24.082 V4.0.0 (2001-03) 4 Call Forwarding on mobile subscriber Not Reachable (CFNRc)
96             case "21"_hash:
97             case "61"_hash:
98             case "62"_hash:
99             case "67"_hash:
100             case "002"_hash:
101             case "004"_hash:
102                 supplement.DealCallTransfer(slotId, mmiData_);
103                 return true;
104 
105             // 27007-430_2001 7.4	Facility lock +CLCK
106             // 3GPP TS 22.088 [6] 1	Barring of outgoing calls
107             // 3GPP TS 22.088 [6] 2	Barring of incoming calls
108             /* 3GPP TS 22.030 V4.0.0 (2001-03) Annex B (normative):Codes for defined Supplementary Services
109              * BAOC	                33
110              * BAOIC	            331
111              * BAOIC exc home	    332
112              * BAIC	                35
113              * BAIC roaming	        351
114              * all Barring Serv.	330
115              * Outg. Barr. Serv.	333
116              * Inc. Barr. Serv.	    353
117              */
118             case "33"_hash:
119             case "330"_hash:
120             case "331"_hash:
121             case "332"_hash:
122             case "35"_hash:
123             case "351"_hash:
124                 supplement.DealCallRestriction(slotId, mmiData_);
125                 return true;
126 
127             // 3GPP TS 22.030 V4.0.0 (2001-03)  6.5.4 Registration of new password
128             case "03"_hash:
129                 return true;
130 
131             // 27007-430_2001 7.12	Call waiting +CCWA
132             // 3GPP TS 22.083 [5] 1	Call waiting (CW)
133             // 3GPP TS 22.030 V4.0.0 (2001-03) Annex B (normative):Codes for defined Supplementary Services
134             case "43"_hash:
135                 supplement.DealCallWaiting(slotId, mmiData_);
136                 return true;
137             default:
138                 TELEPHONY_LOGI("ExecuteMmiCode, default case, need check serviceCode.");
139                 break;
140         }
141     }
142 
143     if (!mmiData_.fullString.empty()) {
144         TELEPHONY_LOGI("ExecuteMmiCode, fullString is not empty.");
145         supplement.SendUssd(slotId, mmiData_.fullString);
146         return true;
147     }
148 
149     TELEPHONY_LOGW("ExecuteMmiCode, default case, need check.");
150     return false;
151 }
152 
RegexMatchMmi(const std::string & analyseString)153 bool MMICodeUtils::RegexMatchMmi(const std::string &analyseString)
154 {
155     std::string symbols =
156         "((\\*|#|\\*#|\\*\\*|##)(\\d{2,3})(\\*([^*#]*)(\\*([^*#]*)(\\*([^*#]*)(\\*([^*#]*))?)?)?)?#)(.*)";
157     std::regex pattern(symbols);
158     std::smatch results;
159     if (regex_match(analyseString, results, pattern)) {
160         TELEPHONY_LOGI("MMICodeUtils::RegexMatchMmi, regex_match ture");
161 
162         /**
163          * The following sequence of functions shall be used for the control of Supplementary Services:
164          *  SELECT:	Entry of the procedure information (may be a digit or a sequence of characters).
165          *  SEND: Transmission of the information to the network.
166          *  INDICATION:	Call progress indications.
167          */
168         int32_t fullString = 1;
169         int32_t action = 2;
170         // 3GPP TS 22.030 V4.0.0 (2001-03)  6.5.2 Structure of the MMI
171         // This structure consists of the following parts:
172         //     Service Code, SC( (2 or 3 digits)
173         //     Supplementary Information, SI (variable length).
174         int32_t serviceCode = 3;
175         int32_t sia = 5;
176         int32_t sib = 7;
177         int32_t sic = 9;
178         int32_t pwdConfirm = 11;
179         int32_t dialingNumber = 12;
180         mmiData_.fullString = results.str(fullString);
181         mmiData_.actionString = results.str(action);
182         mmiData_.serviceCode = results.str(serviceCode);
183         mmiData_.serviceInfoA = results.str(sia);
184         mmiData_.serviceInfoB = results.str(sib);
185         mmiData_.serviceInfoC = results.str(sic);
186         mmiData_.pwdString = results.str(pwdConfirm);
187         mmiData_.dialString = results.str(dialingNumber);
188 
189         /* 3GPP TS 22.030 V4.0.0 (2001-03)  6.5.2 Structure of the MMI
190          * The procedure always starts with *, #, **, ## or *# and is finished by #.
191          * Each part within the procedure is separated by *.
192          */
193         if (analyseString.back() == '#' && !mmiData_.dialString.empty() && mmiData_.dialString.back() == '#') {
194             mmiData_.fullString = analyseString;
195         }
196         return true;
197     }
198     return false;
199 }
200 
GetMMIData()201 MMIData MMICodeUtils::GetMMIData()
202 {
203     return mmiData_;
204 }
205 } // namespace Telephony
206 } // namespace OHOS
207