|
1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This file contains the implementation of the AT+CPIN command |
|
15 // |
|
16 // |
|
17 |
|
18 #include "cpincommandhandler.h" |
|
19 |
|
20 #include <mmretrieve.h> // define AO wrapper |
|
21 #include <EXTERROR.H> // Additional RMobilePhone error code |
|
22 |
|
23 #include "debug.h" |
|
24 |
|
25 CCPINCommandHandler* CCPINCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) |
|
26 { |
|
27 TRACE_FUNC_ENTRY |
|
28 CCPINCommandHandler* self = new (ELeave) CCPINCommandHandler(aCallback, aATCmdParser, aPhone); |
|
29 TRACE_FUNC_EXIT |
|
30 return self; |
|
31 } |
|
32 |
|
33 CCPINCommandHandler::CCPINCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) : |
|
34 CATCmdAsyncBase(aCallback, aATCmdParser, aPhone), |
|
35 iLockInfoPckg(iLockInfo) |
|
36 { |
|
37 TRACE_FUNC_ENTRY |
|
38 TRACE_FUNC_EXIT |
|
39 } |
|
40 |
|
41 CCPINCommandHandler::~CCPINCommandHandler() |
|
42 { |
|
43 TRACE_FUNC_ENTRY |
|
44 Cancel(); |
|
45 TRACE_FUNC_EXIT |
|
46 } |
|
47 |
|
48 void CCPINCommandHandler::HandleCommand(const TDesC8& /*aCmd*/, |
|
49 RBuf8& /*aReply*/, |
|
50 TBool /*aReplyNeeded*/) |
|
51 { |
|
52 TRACE_FUNC_ENTRY |
|
53 |
|
54 switch (iATCmdParser.CommandHandlerType()) |
|
55 { |
|
56 case (TAtCommandParser::ECmdHandlerTypeTest): |
|
57 // AT+CPIN=? - simply return OK. |
|
58 { |
|
59 iCallback->CreateReplyAndComplete( EReplyTypeOk); |
|
60 break; |
|
61 } |
|
62 |
|
63 case(TAtCommandParser::ECmdHandlerTypeRead): |
|
64 // AT+CPIN? - Get PIN require status. return +CPIN: READY/SIM PUK |
|
65 case (TAtCommandParser::ECmdHandlerTypeSet): |
|
66 // AT+CPIN="puk","pin" - Change password when PUK is required. |
|
67 { |
|
68 // call GetLockInfo to check if PUK is required |
|
69 iPhone.GetLockInfo(iStatus, RMobilePhone::ELockICC, iLockInfoPckg); |
|
70 iPendingEvent = EMobilePhoneGetLockInfo; |
|
71 SetActive(); |
|
72 break; |
|
73 } |
|
74 default: |
|
75 { |
|
76 // unsupported command |
|
77 iCallback->CreateReplyAndComplete(EReplyTypeError); |
|
78 break; |
|
79 } |
|
80 } |
|
81 |
|
82 TRACE_FUNC_EXIT |
|
83 } |
|
84 |
|
85 void CCPINCommandHandler::HandleCommandCancel() |
|
86 { |
|
87 TRACE_FUNC_ENTRY |
|
88 Cancel(); |
|
89 TRACE_FUNC_EXIT |
|
90 } |
|
91 |
|
92 void CCPINCommandHandler::ChangePassword() |
|
93 { |
|
94 TRACE_FUNC_ENTRY |
|
95 TRequestStatus status; |
|
96 |
|
97 // Get parameters from AT command |
|
98 TInt ret1; |
|
99 TInt ret2; |
|
100 TPtrC8 pukCode8 = iATCmdParser.NextTextParam(ret1); |
|
101 TPtrC8 pinCode8 = iATCmdParser.NextTextParam(ret2); |
|
102 if(ret1 != KErrNone || ret2 != KErrNone |
|
103 || iATCmdParser.NextParam().Compare(KNullDesC8) != 0) |
|
104 { |
|
105 iCallback->CreateReplyAndComplete( EReplyTypeError); |
|
106 TRACE_FUNC_EXIT |
|
107 return; |
|
108 } |
|
109 |
|
110 RMobilePhone::TMobilePassword pukCode; |
|
111 RMobilePhone::TMobilePassword pinCode; |
|
112 pukCode.Copy(pukCode8); |
|
113 pinCode.Copy(pinCode8); |
|
114 iPhone.VerifySecurityCode(iStatus, RMobilePhone::ESecurityCodePuk1, pinCode, pukCode); |
|
115 // re-use the AO for VerifySecurityCode |
|
116 iPendingEvent = EMobilePhoneVerifySecurityCode; |
|
117 SetActive(); |
|
118 |
|
119 TRACE_FUNC_EXIT |
|
120 return; |
|
121 } |
|
122 |
|
123 void CCPINCommandHandler::RunL() |
|
124 { |
|
125 TRACE_FUNC_ENTRY |
|
126 |
|
127 if( iPendingEvent == EMobilePhoneGetLockInfo) |
|
128 { // after calling GetLockInfo |
|
129 HandleGetLockInfo(); |
|
130 } |
|
131 else |
|
132 { // after calling VerifySecurityCode |
|
133 ASSERT(iPendingEvent == EMobilePhoneVerifySecurityCode); |
|
134 HandleVerifySecurityCode(); |
|
135 } |
|
136 TRACE_FUNC_EXIT |
|
137 } |
|
138 |
|
139 void CCPINCommandHandler::HandleGetLockInfo() |
|
140 { |
|
141 TRACE_FUNC_ENTRY |
|
142 TAtCommandParser::TCommandHandlerType handleType = iATCmdParser.CommandHandlerType(); |
|
143 |
|
144 switch(iStatus.Int()) |
|
145 { |
|
146 case KErrNone: |
|
147 { |
|
148 // log lock info |
|
149 _LIT8(KDbgPhoneLockInfo, "GetLockInfo: Status %d, Lock %d, Setting %d"); |
|
150 Trace(KDbgPhoneLockInfo, iStatus.Int(), iLockInfo.iStatus, iLockInfo.iSetting); |
|
151 |
|
152 if(handleType == TAtCommandParser::ECmdHandlerTypeRead ) |
|
153 { |
|
154 // complete without error |
|
155 _LIT8(KCPINReady, "\r\n+CPIN: READY\r\n\r\nOK\r\n"); |
|
156 iCallback->CreateReplyAndComplete( EReplyTypeOther, KCPINReady); |
|
157 } |
|
158 else |
|
159 { |
|
160 ASSERT( handleType== TAtCommandParser::ECmdHandlerTypeSet ); |
|
161 // PUK/PIN is not required |
|
162 iCallback->CreateCMEReplyAndComplete(KErrGsm0707OperationNotAllowed); |
|
163 } |
|
164 break; |
|
165 } |
|
166 case KErrAccessDenied: |
|
167 { |
|
168 if(handleType == TAtCommandParser::ECmdHandlerTypeRead ) |
|
169 { |
|
170 // reply PUK is required |
|
171 _LIT8(KCPINSimPuk, "\r\n+CPIN: SIM PUK\r\n\r\nOK\r\n"); |
|
172 iCallback->CreateReplyAndComplete( EReplyTypeOther, KCPINSimPuk); |
|
173 } |
|
174 else |
|
175 |
|
176 { |
|
177 // change PIN with a PUK code |
|
178 ChangePassword(); |
|
179 } |
|
180 break; |
|
181 } |
|
182 default: |
|
183 { |
|
184 // any other errors, such as KErrGeneral when SIM card is not available |
|
185 Trace(KDebugPrintD, "Complete CPIN with error ", iStatus.Int()); |
|
186 iCallback->CreateReplyAndComplete( EReplyTypeError ); |
|
187 break; |
|
188 } |
|
189 } |
|
190 TRACE_FUNC_EXIT |
|
191 } |
|
192 |
|
193 void CCPINCommandHandler::HandleVerifySecurityCode() |
|
194 { |
|
195 TRACE_FUNC_ENTRY |
|
196 |
|
197 // check error after change PUK |
|
198 if (iStatus.Int() == KErrNone) |
|
199 { // complete without error |
|
200 iCallback->CreateReplyAndComplete( EReplyTypeOk ); |
|
201 } |
|
202 else |
|
203 { // if there is an error |
|
204 iCallback->CreateCMEReplyAndComplete(iStatus.Int()); |
|
205 } |
|
206 |
|
207 TRACE_FUNC_EXIT |
|
208 } |
|
209 |
|
210 void CCPINCommandHandler::DoCancel() |
|
211 { |
|
212 TRACE_FUNC_ENTRY |
|
213 iPhone.CancelAsyncRequest(iPendingEvent); |
|
214 TRACE_FUNC_EXIT |
|
215 } |
|
216 |