|
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+CPWD command |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <mmretrieve.h> // AO |
|
20 |
|
21 #include "cpwdcommandhandler.h" |
|
22 |
|
23 #include "debug.h" |
|
24 |
|
25 |
|
26 // password types |
|
27 _LIT8(KATCPWDPS, "PS"); // Phone lock |
|
28 _LIT8(KATCPWDP2, "P2"); // PIN2 |
|
29 _LIT8(KATCPWDSC, "SC"); // PIN |
|
30 _LIT8(KATCPWDAB, "AB"); // All Barring code |
|
31 |
|
32 |
|
33 |
|
34 // strings for debugging trace |
|
35 _LIT8(KDbgStr, "+CPWD: %s \r\n"); |
|
36 _LIT8(KDbgTDes, "+CPWD: %s%S\r\n"); |
|
37 |
|
38 // constant for Set All barring code service - originally defined in mw/PSetConstants.h |
|
39 const TInt KPsetAllSSServices = 0; |
|
40 // Max buffer length for an MD5 digest - originally defined in SCPServerInterface.h |
|
41 const TInt KSCPMaxHashLength( 32 ); |
|
42 |
|
43 |
|
44 |
|
45 CCPWDCommandHandler* CCPWDCommandHandler::NewL(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) |
|
46 { |
|
47 TRACE_FUNC_ENTRY |
|
48 CCPWDCommandHandler* self = new (ELeave) CCPWDCommandHandler(aCallback, aATCmdParser, aPhone); |
|
49 TRACE_FUNC_EXIT |
|
50 return self; |
|
51 } |
|
52 |
|
53 CCPWDCommandHandler::CCPWDCommandHandler(MATMiscCmdPlugin* aCallback, TAtCommandParser& aATCmdParser, RMobilePhone& aPhone) : |
|
54 CATCmdAsyncBase(aCallback, aATCmdParser, aPhone) |
|
55 { |
|
56 TRACE_FUNC_ENTRY |
|
57 TRACE_FUNC_EXIT |
|
58 } |
|
59 |
|
60 CCPWDCommandHandler::~CCPWDCommandHandler() |
|
61 { |
|
62 TRACE_FUNC_ENTRY |
|
63 Cancel(); |
|
64 TRACE_FUNC_EXIT |
|
65 } |
|
66 |
|
67 void CCPWDCommandHandler::HandleCommand( const TDesC8& /*aCmd*/, |
|
68 RBuf8& /*aReply*/, |
|
69 TBool /*aReplyNeeded*/ ) |
|
70 { |
|
71 TRACE_FUNC_ENTRY |
|
72 TAtCommandParser::TCommandHandlerType cmdHandlerType = iATCmdParser.CommandHandlerType(); |
|
73 switch (cmdHandlerType) |
|
74 { |
|
75 case (TAtCommandParser::ECmdHandlerTypeTest): |
|
76 { |
|
77 // Get supported passwords with max. length of them. AT+CPWD=? |
|
78 // return hardcoded supported password with max. length |
|
79 _LIT8(KCPWDTestValue, "\r\n+CPWD: (\"PS\",10),(\"SC\",8),(\"AB\",4),(\"P2\",8)\r\n\r\nOK\r\n"); |
|
80 iCallback->CreateReplyAndComplete( EReplyTypeOther, KCPWDTestValue ); |
|
81 break; |
|
82 } |
|
83 case (TAtCommandParser::ECmdHandlerTypeSet): |
|
84 { |
|
85 // Change password. AT+CPWD="nn","xxxx","yyyy" |
|
86 ChangePassword(); |
|
87 break; |
|
88 } |
|
89 default: |
|
90 { |
|
91 iCallback->CreateReplyAndComplete(EReplyTypeError); |
|
92 } |
|
93 } |
|
94 TRACE_FUNC_EXIT |
|
95 } |
|
96 |
|
97 void CCPWDCommandHandler::HandleCommandCancel() |
|
98 { |
|
99 TRACE_FUNC_ENTRY |
|
100 Cancel(); |
|
101 TRACE_FUNC_EXIT |
|
102 } |
|
103 |
|
104 |
|
105 void CCPWDCommandHandler::ChangePassword() |
|
106 { |
|
107 TRACE_FUNC_ENTRY |
|
108 |
|
109 // Get parameters from AT command |
|
110 TInt ret1; |
|
111 TInt ret2; |
|
112 TInt ret3; |
|
113 TPtrC8 passwordType = iATCmdParser.NextTextParam(ret1); |
|
114 TPtrC8 oldPassword = iATCmdParser.NextTextParam(ret2); |
|
115 TPtrC8 newPassword = iATCmdParser.NextTextParam(ret3); |
|
116 |
|
117 if(ret1 != KErrNone || ret2 != KErrNone || ret3 != KErrNone |
|
118 || iATCmdParser.NextParam().Compare(KNullDesC8) != 0) |
|
119 { |
|
120 Trace(KDbgStr, "invalid arguments"); |
|
121 iCallback->CreateReplyAndComplete( EReplyTypeError); |
|
122 TRACE_FUNC_EXIT |
|
123 return; |
|
124 } |
|
125 |
|
126 if(passwordType.Compare(KATCPWDPS) == 0) // Phone lock |
|
127 { |
|
128 // "PS" PH-SIM (lock PHone to SIM/UICC card) (MT asks password when other than current SIM/UICC card |
|
129 // inserted; MT may remember certain amount of previously used cards thus not requiring password when they |
|
130 // are inserted) |
|
131 RMobilePhone::TMobilePhonePasswordChangeV1 passwordChange; |
|
132 |
|
133 // Phone lock password is hashed in RSPClient and NokiaTSY. See CSCPServer::HashISACode() for details. |
|
134 TBuf8<KSCPMaxHashLength> hashOldPwd; |
|
135 TBuf8<KSCPMaxHashLength> hashNewPwd; |
|
136 iATCmdParser.HashSecurityCode(oldPassword, hashOldPwd); |
|
137 iATCmdParser.HashSecurityCode(newPassword, hashNewPwd); |
|
138 |
|
139 ChangeSecurityCode(RMobilePhone::ESecurityCodePhonePassword, hashOldPwd, hashNewPwd); |
|
140 } |
|
141 else if(passwordType.Compare(KATCPWDSC) == 0) // SIM pin |
|
142 { |
|
143 // "SC" SIM (lock SIM/UICC card) (SIM/UICC asks password in MT power-up and when this lock command |
|
144 // issued) |
|
145 |
|
146 // todo: if it is required to return +CME code according to SIM Lock status, |
|
147 // should check SIM Lock is on here and return an error if it is off. |
|
148 ChangeSecurityCode(RMobilePhone::ESecurityCodePin1, oldPassword, newPassword); |
|
149 } |
|
150 else if(passwordType.Compare(KATCPWDP2) == 0) // SIM pin2 |
|
151 { |
|
152 ChangeSecurityCode(RMobilePhone::ESecurityCodePin2, oldPassword, newPassword); |
|
153 } |
|
154 else if(passwordType.Compare(KATCPWDAB) == 0) // All Barring services |
|
155 { |
|
156 // "AB" All Barring services (refer 3GPP TS 22.030 [19]) (applicable only for <mode>=0) |
|
157 RMobilePhone::TMobilePhonePasswordChangeV2 passwordChange; |
|
158 passwordChange.iOldPassword.Copy(oldPassword); |
|
159 passwordChange.iNewPassword.Copy(newPassword); |
|
160 passwordChange.iVerifiedPassword.Copy(newPassword); |
|
161 RMobilePhone::TMobilePhonePasswordChangeV2Pckg pwdPckg ( passwordChange ); |
|
162 // The current S60 use SetSSPassword for All Barring services code. |
|
163 // see CPsetCallBarring::ChangePasswordL for details. |
|
164 iPhone.SetSSPassword(iStatus, pwdPckg, KPsetAllSSServices); |
|
165 iPendingEvent = EMobilePhoneSetSSPassword; |
|
166 SetActive(); |
|
167 |
|
168 } |
|
169 else // other unsupported arguments |
|
170 { |
|
171 Trace(KDbgTDes, "unknown password type:", &passwordType); |
|
172 iCallback->CreateCMEReplyAndComplete(KErrUnknown); |
|
173 } |
|
174 |
|
175 TRACE_FUNC_EXIT |
|
176 return; |
|
177 } |
|
178 |
|
179 void CCPWDCommandHandler::RunL() |
|
180 { |
|
181 TRACE_FUNC_ENTRY |
|
182 |
|
183 if (iStatus.Int() == KErrNone) |
|
184 { // complete without error |
|
185 Trace(KDbgStr, "complete OK." ); |
|
186 iCallback->CreateReplyAndComplete( EReplyTypeOk ); |
|
187 } |
|
188 else |
|
189 { // if there is an error |
|
190 iCallback->CreateCMEReplyAndComplete(iStatus.Int()); |
|
191 } |
|
192 TRACE_FUNC_EXIT |
|
193 } |
|
194 |
|
195 void CCPWDCommandHandler::DoCancel() |
|
196 { |
|
197 TRACE_FUNC_ENTRY |
|
198 Trace(KDbgStr, "Request cancelled." ); |
|
199 iPhone.CancelAsyncRequest(iPendingEvent); |
|
200 TRACE_FUNC_EXIT |
|
201 } |
|
202 |
|
203 |
|
204 void CCPWDCommandHandler::ChangeSecurityCode(RMobilePhone::TMobilePhoneSecurityCode aType, TDesC8& aOldPassword, TDesC8& aNewPassword) |
|
205 { |
|
206 RMobilePhone::TMobilePhonePasswordChangeV1 passwordChange; |
|
207 passwordChange.iOldPassword.Copy(aOldPassword); |
|
208 passwordChange.iNewPassword.Copy(aNewPassword); |
|
209 iPhone.ChangeSecurityCode(iStatus, aType, passwordChange); |
|
210 iPendingEvent = EMobilePhoneChangeSecurityCode; |
|
211 SetActive(); |
|
212 } |