1 // Copyright (c) 2009 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 // Implements a AT extension plugin |
|
15 // |
|
16 // |
|
17 |
|
18 #include "pamplugin.h" |
|
19 #include "pamplugindebug.h" |
|
20 #include "pamengine.h" |
|
21 |
|
22 #include <badesca.h> |
|
23 #include <etel3rdparty.h> |
|
24 |
|
25 |
|
26 _LIT8(KNqapString, "*NQAP: "); |
|
27 _LIT8(KNqapTestString, "AT*NQAP=?"); |
|
28 _LIT8(KNqapInternetString, "AT*NQAP=0"); |
|
29 _LIT8(KNqapWapString, "AT*NQAP=1"); |
|
30 _LIT8(KNqapInternetAndWapString, "AT*NQAP=2"); |
|
31 _LIT8(KErrorString, "\r\nERROR\r\n"); |
|
32 _LIT8(KOkString, "\r\nOK\r\n"); |
|
33 _LIT8(KCrlfString, "\r\n"); |
|
34 _LIT8(KNcnnString, "AT*NCNN"); |
|
35 |
|
36 /** |
|
37 Create a new instance |
|
38 */ |
|
39 CPamPlugin* CPamPlugin::NewL() |
|
40 { |
|
41 CPamPlugin* self = new (ELeave) CPamPlugin(); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 |
|
49 /** |
|
50 Destructor |
|
51 */ |
|
52 CPamPlugin::~CPamPlugin() |
|
53 { |
|
54 TRACE_FUNC_ENTRY |
|
55 delete iPAMEngine; |
|
56 TRACE_FUNC_EXIT |
|
57 } |
|
58 |
|
59 TBool CPamPlugin::IsCommandSupported( const TDesC8& aCmd ) |
|
60 { |
|
61 TRACE_FUNC_ENTRY |
|
62 TBool ret = EFalse; |
|
63 if (aCmd.FindF(KNqapTestString) == 0) |
|
64 { |
|
65 ret = ETrue; |
|
66 } |
|
67 else if (aCmd.FindF(KNqapInternetString) == 0) |
|
68 { |
|
69 ret = ETrue; |
|
70 } |
|
71 else if (aCmd.FindF(KNqapWapString) == 0) |
|
72 { |
|
73 ret = ETrue; |
|
74 } |
|
75 else if (aCmd.FindF(KNqapInternetAndWapString) == 0) |
|
76 { |
|
77 ret = ETrue; |
|
78 } |
|
79 else if (aCmd.FindF(KNcnnString) == 0) |
|
80 { |
|
81 ret = ETrue; |
|
82 } |
|
83 return ret; |
|
84 } |
|
85 |
|
86 |
|
87 void CPamPlugin::HandleCommand( const TDesC8& aCmd, RBuf8& aReply, TBool aReplyNeeded ) |
|
88 { |
|
89 TRACE_FUNC_ENTRY |
|
90 TRACE_INFO((_L8("CPamPlugin::HandleCommand cmd '%S' reply '%S'"), &aCmd, &aReply)) |
|
91 |
|
92 if ( !aReplyNeeded ) |
|
93 { |
|
94 return; |
|
95 } |
|
96 |
|
97 const TInt KInternet = 0; |
|
98 const TInt KWap = 1; |
|
99 const TInt KWapInternet = 2; |
|
100 |
|
101 TInt err(KErrNotSupported); |
|
102 |
|
103 if (aCmd.FindF(KNqapTestString) >= 0) |
|
104 { |
|
105 SupportedAccessPointL( aReply ); |
|
106 err = KErrNone; |
|
107 } |
|
108 |
|
109 else if (aCmd.FindF(KNqapInternetString) >= 0) |
|
110 { |
|
111 ReadAccessPointL( KInternet, aReply ); |
|
112 err = KErrNone; |
|
113 } |
|
114 else if (aCmd.FindF(KNqapWapString) >= 0) |
|
115 { |
|
116 ReadAccessPointL( KWap, aReply ); |
|
117 err = KErrNone; |
|
118 } |
|
119 else if (aCmd.FindF(KNqapInternetAndWapString) >= 0) |
|
120 { |
|
121 ReadAccessPointL( KWapInternet, aReply ); |
|
122 err = KErrNone; |
|
123 } |
|
124 else if (aCmd.FindF(KNcnnString) >= 0) |
|
125 { |
|
126 iReply = &aReply; |
|
127 iPAMEngine->GetServiceProviderName(); |
|
128 return; |
|
129 } |
|
130 else |
|
131 { |
|
132 err = KErrNotSupported; |
|
133 } |
|
134 |
|
135 if(err != KErrNone) |
|
136 HandleCommandCompleted(err, EReplyTypeUndefined); |
|
137 else |
|
138 HandleCommandCompleted(KErrNone, EReplyTypeOk); |
|
139 |
|
140 TRACE_FUNC_EXIT |
|
141 } |
|
142 |
|
143 |
|
144 void CPamPlugin::NameReqCallback( const TDesC8& aName ) |
|
145 { |
|
146 TRACE_FUNC_ENTRY |
|
147 if ( aName == KNullDesC8() ) |
|
148 { |
|
149 iReply->Zero(); |
|
150 iReply->Create( KErrorString ); |
|
151 } |
|
152 else |
|
153 { |
|
154 TBuf8<32> buf; |
|
155 buf.Zero(); |
|
156 buf.Append( KCrlfString ); |
|
157 buf.Append( aName ); |
|
158 buf.Append( KCrlfString ); |
|
159 buf.Append( KOkString ); |
|
160 iReply->Zero(); |
|
161 iReply->Create( buf ); |
|
162 } |
|
163 HandleCommandCompleted(KErrNone, EReplyTypeOk); |
|
164 TRACE_FUNC_EXIT |
|
165 } |
|
166 |
|
167 /** |
|
168 Used by AT*NQAP=? |
|
169 */ |
|
170 void CPamPlugin::SupportedAccessPointL( RBuf8& aReply ) |
|
171 { |
|
172 TRACE_FUNC_ENTRY |
|
173 |
|
174 const TInt Kbufsize = 16; |
|
175 const TInt Kresponcebufsize = 64; |
|
176 |
|
177 HBufC16* supportedAp = HBufC16::NewL( Kbufsize ); |
|
178 iPAMEngine->SupportedAccessPoints( supportedAp ); |
|
179 TBuf8<Kresponcebufsize> buf; |
|
180 |
|
181 buf.Zero(); |
|
182 buf.Append( KCrlfString ); |
|
183 buf.Append( KNqapString ); |
|
184 buf.Append( *supportedAp ); |
|
185 buf.Append( KCrlfString ); |
|
186 buf.Append( KOkString ); |
|
187 |
|
188 aReply.Zero(); |
|
189 aReply.Create( buf ); |
|
190 |
|
191 TRACE_FUNC_EXIT |
|
192 return; |
|
193 } |
|
194 |
|
195 /** |
|
196 Used by AT*NQAP=<> |
|
197 */ |
|
198 void CPamPlugin::ReadAccessPointL(TInt aAccessPoint, RBuf8& aReply ) |
|
199 { |
|
200 TRACE_FUNC_ENTRY |
|
201 |
|
202 const TInt KreplyBufferLength = 1024; |
|
203 |
|
204 CDesC8ArrayFlat* apArray = new(ELeave) CDesC8ArrayFlat(4); |
|
205 CleanupStack::PushL( apArray ); |
|
206 |
|
207 iPAMEngine->ReadAccessPointTableL( aAccessPoint, apArray ); |
|
208 |
|
209 TInt apArrayLength = apArray->Count(); |
|
210 if ( apArrayLength > 0) |
|
211 { |
|
212 HBufC8* buf = HBufC8::NewL( KreplyBufferLength ); |
|
213 buf->Des().Zero(); |
|
214 buf->Des().Append( KCrlfString ); |
|
215 for (TInt i=0; i < apArrayLength; i++ ) |
|
216 { |
|
217 // AT*NQAP=<n> responce |
|
218 buf->Des().Append( KNqapString ); |
|
219 buf->Des().Append( (*apArray)[i] ); |
|
220 buf->Des().Append( KCrlfString ); |
|
221 } |
|
222 buf->Des().Append( KOkString ); |
|
223 aReply.Zero(); |
|
224 aReply.Create( *buf ); |
|
225 } |
|
226 else |
|
227 { |
|
228 aReply.Zero(); |
|
229 aReply.Create( KOkString ); |
|
230 } |
|
231 CleanupStack::PopAndDestroy( apArray ); |
|
232 TRACE_FUNC_EXIT |
|
233 return; |
|
234 } |
|
235 |
|
236 |
|
237 TInt CPamPlugin::HandleRunError(TInt /*aErr*/) |
|
238 { |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 |
|
243 CPamPlugin::CPamPlugin() : CATExtPluginBase() |
|
244 { |
|
245 TRACE_FUNC |
|
246 } |
|
247 |
|
248 |
|
249 void CPamPlugin::ConstructL() |
|
250 { |
|
251 iPAMEngine = CPamEngine::NewL( this ); |
|
252 TRACE_FUNC |
|
253 } |
|
254 |
|
255 void CPamPlugin::ReportConnectionName( const TDesC8& /*aName*/ ) |
|
256 { |
|
257 } |
|
258 |
|
259 void CPamPlugin::HandleCommandCancel() |
|
260 { |
|
261 } |
|
262 |
|
263 TInt CPamPlugin::NextReplyPartLength() |
|
264 { |
|
265 return 0; |
|
266 } |
|
267 TInt CPamPlugin::GetNextPartOfReply(RBuf8& /*aNextReply*/) |
|
268 { |
|
269 return 0; |
|
270 } |
|
271 |
|
272 void CPamPlugin::ReceiveUnsolicitedResult() |
|
273 { |
|
274 } |
|
275 |
|
276 void CPamPlugin::ReceiveUnsolicitedResultCancel() |
|
277 { |
|
278 } |
|
279 |
|
280 void CPamPlugin::ReportNvramStatusChange( const TDesC8& /*aNvram*/ ) |
|
281 { |
|
282 } |
|
283 |
|
284 void CPamPlugin::ReportExternalHandleCommandError() |
|
285 { |
|
286 } |
|
287 |
|
288 // End of File |
|