|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 #include "pannapuplinkauthorisationnotifier.h" |
|
17 |
|
18 #include <networking/panuiinterfaces.h> |
|
19 #include <e32cons.h> |
|
20 #include <btsdp.h> // For PAN UUIDs |
|
21 |
|
22 _LIT(KNapUplinkAuthorisationNotifierConsoleName, "PAN NAP Uplink Authorisation Notifier"); |
|
23 _LIT(KYes,"Yes"); |
|
24 _LIT(KNo,"No"); |
|
25 |
|
26 /*static*/ CPanNapUplinkAuthorisationNotifier* CPanNapUplinkAuthorisationNotifier::NewLC() |
|
27 { |
|
28 CPanNapUplinkAuthorisationNotifier* self = new (ELeave)CPanNapUplinkAuthorisationNotifier(); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CPanNapUplinkAuthorisationNotifier::~CPanNapUplinkAuthorisationNotifier() |
|
35 { |
|
36 delete iSelectorEngine; |
|
37 } |
|
38 |
|
39 CPanNapUplinkAuthorisationNotifier::CPanNapUplinkAuthorisationNotifier() |
|
40 { |
|
41 iNotifierInfo.iUid = KBTPanNapUplinkAuthorisationNotifierUid; |
|
42 iNotifierInfo.iChannel = TUid::Uid(KScreenOutputChannelNumber); |
|
43 iNotifierInfo.iPriority = ENotifierPriorityVLow; |
|
44 } |
|
45 |
|
46 void CPanNapUplinkAuthorisationNotifier::ConstructL() |
|
47 { |
|
48 iSelectorEngine = CPanNapUplinkAuthorisationNotifierEngine::NewL(*this); |
|
49 } |
|
50 |
|
51 |
|
52 // From MNotifierBase2 |
|
53 |
|
54 void CPanNapUplinkAuthorisationNotifier::Release() |
|
55 { |
|
56 Cancel(); |
|
57 delete this; |
|
58 } |
|
59 |
|
60 CPanNapUplinkAuthorisationNotifier::TNotifierInfo CPanNapUplinkAuthorisationNotifier::RegisterL() |
|
61 { |
|
62 return iNotifierInfo; |
|
63 } |
|
64 |
|
65 CPanNapUplinkAuthorisationNotifier::TNotifierInfo CPanNapUplinkAuthorisationNotifier::Info() const |
|
66 { |
|
67 return iNotifierInfo; |
|
68 } |
|
69 |
|
70 TPtrC8 CPanNapUplinkAuthorisationNotifier::StartL(const TDesC8& /*aBuffer*/) |
|
71 { |
|
72 // Sync calls not supported. |
|
73 User::Leave(KErrNotSupported); |
|
74 return KNullDesC8(); |
|
75 } |
|
76 |
|
77 void CPanNapUplinkAuthorisationNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage) |
|
78 { |
|
79 iReplySlot = aReplySlot; |
|
80 iMessage = RMessage2(aMessage); |
|
81 iMessageOutstanding = ETrue; |
|
82 |
|
83 iSelectorEngine->GetLocalServiceL(aBuffer); |
|
84 } |
|
85 |
|
86 void CPanNapUplinkAuthorisationNotifier::Cancel() |
|
87 { |
|
88 iSelectorEngine->Cancel(); |
|
89 CompleteNotifier(KErrCancel, EDisallowNewNapConnection); |
|
90 } |
|
91 |
|
92 TPtrC8 CPanNapUplinkAuthorisationNotifier::UpdateL(const TDesC8& /*aBuffer*/) |
|
93 { |
|
94 User::Leave(KErrNotSupported); |
|
95 return KNullDesC8(); |
|
96 } |
|
97 |
|
98 |
|
99 // From MPanNapUplinkAuthorisationNotifierNotifier |
|
100 void CPanNapUplinkAuthorisationNotifier::CompleteNotifier(TInt aError, TNapConnectionResult aResult) |
|
101 { |
|
102 if(aError == KErrNone) |
|
103 { |
|
104 iResultPckg = aResult; |
|
105 aError = iMessage.Write(iReplySlot, iResultPckg); |
|
106 } |
|
107 |
|
108 if(iMessageOutstanding) |
|
109 { |
|
110 iMessage.Complete(aError); |
|
111 iMessageOutstanding = EFalse; |
|
112 } |
|
113 } |
|
114 |
|
115 |
|
116 |
|
117 /*static*/ CPanNapUplinkAuthorisationNotifierEngine* CPanNapUplinkAuthorisationNotifierEngine::NewL(MPanNapUplinkAuthorisationNotifierNotifier& aNotifier) |
|
118 { |
|
119 CPanNapUplinkAuthorisationNotifierEngine* self = new (ELeave)CPanNapUplinkAuthorisationNotifierEngine(aNotifier); |
|
120 CleanupStack::PushL(self); |
|
121 self->ConstructL(); |
|
122 CleanupStack::Pop(); |
|
123 return self; |
|
124 } |
|
125 |
|
126 CPanNapUplinkAuthorisationNotifierEngine::~CPanNapUplinkAuthorisationNotifierEngine() |
|
127 { |
|
128 delete iConsole; |
|
129 } |
|
130 |
|
131 CPanNapUplinkAuthorisationNotifierEngine::CPanNapUplinkAuthorisationNotifierEngine(MPanNapUplinkAuthorisationNotifierNotifier& aNotifier) |
|
132 : CActive(CActive::EPriorityStandard), |
|
133 iNotifier(aNotifier) |
|
134 { |
|
135 CActiveScheduler::Add(this); |
|
136 } |
|
137 |
|
138 void CPanNapUplinkAuthorisationNotifierEngine::ConstructL() |
|
139 { |
|
140 } |
|
141 |
|
142 void CPanNapUplinkAuthorisationNotifierEngine::GetLocalServiceL(const TDesC8& aBuffer) |
|
143 { |
|
144 iConsole = Console::NewL(KNapUplinkAuthorisationNotifierConsoleName, TSize(KConsFullScreen, KConsFullScreen)); |
|
145 iConnectionListPckg.Copy(aBuffer); |
|
146 |
|
147 DrawExistingConnections(); |
|
148 DrawInstructionsAndWaitForInput(); |
|
149 } |
|
150 |
|
151 void CPanNapUplinkAuthorisationNotifierEngine::DrawExistingConnections() |
|
152 { |
|
153 TBuf<20> bdAddrBuf; |
|
154 const TBTDevAddr* panConnAddr = NULL; |
|
155 const TPanConnection* existingPanConnection = NULL; |
|
156 |
|
157 iConsole->ClearScreen(); |
|
158 |
|
159 // Get the requested connection address |
|
160 panConnAddr = iConnectionListPckg().RequestedConnectionAddr(); |
|
161 |
|
162 if(panConnAddr) |
|
163 { |
|
164 panConnAddr->GetReadable(bdAddrBuf); |
|
165 iConsole->Printf(_L("New connection requested from device [%S]\n"), &bdAddrBuf); |
|
166 } |
|
167 else |
|
168 { |
|
169 iConsole->Printf(_L("New connection requested from device [**Unknown**]\n")); |
|
170 } |
|
171 |
|
172 // Draw existing connections |
|
173 existingPanConnection = iConnectionListPckg().GetFirstRemoteConnection(); |
|
174 if(existingPanConnection) |
|
175 { |
|
176 // Print the current local role. |
|
177 if(iConnectionListPckg().CurrentLocalRole() == TUUID(KPanUUUID)) |
|
178 { |
|
179 iConsole->Printf(_L("Current local role [PAN-U]\n")); |
|
180 } |
|
181 else if(iConnectionListPckg().CurrentLocalRole() == TUUID(KPanGnUUID)) |
|
182 { |
|
183 iConsole->Printf(_L("Current local role [PAN-GN]\n")); |
|
184 } |
|
185 else if(iConnectionListPckg().CurrentLocalRole() == TUUID(KPanNapUUID)) |
|
186 { |
|
187 iConsole->Printf(_L("Current local role [PAN-NAP]\n")); |
|
188 } |
|
189 else |
|
190 { |
|
191 iConsole->Printf(_L("Current local role [**Unknown**]\n")); |
|
192 } |
|
193 |
|
194 iConsole->Printf(_L("\n\nExisting connections\n")); |
|
195 iConsole->Printf(_L("\nAddress Has Uplink Access\n")); |
|
196 |
|
197 while(existingPanConnection) |
|
198 { |
|
199 existingPanConnection->RemoteDeviceAddress().GetReadable(bdAddrBuf); |
|
200 iConsole->Printf(_L(" [%S] %S\n"), &bdAddrBuf, existingPanConnection->UplinkAccessAllowed() ? &KYes : &KNo); |
|
201 |
|
202 existingPanConnection = iConnectionListPckg().GetNextRemoteConnection(); |
|
203 } |
|
204 } |
|
205 else |
|
206 { |
|
207 iConsole->Printf(_L("\n -- No existing connections --\n")); |
|
208 } |
|
209 } |
|
210 |
|
211 void CPanNapUplinkAuthorisationNotifierEngine::DrawInstructionsAndWaitForInput() |
|
212 { |
|
213 iConsole->Printf(_L("\n\nPress 'd' to disallow new connection\n")); |
|
214 iConsole->Printf(_L("Press 'n' to give the remote device network access\n")); |
|
215 iConsole->Printf(_L("Press 'l' to give the remote device access to the local network\n")); |
|
216 iConsole->Printf(_L("-> ")); |
|
217 |
|
218 iConsole->Read(iStatus); |
|
219 SetActive(); |
|
220 } |
|
221 |
|
222 void CPanNapUplinkAuthorisationNotifierEngine::RunL() |
|
223 { |
|
224 TChar key = iConsole->KeyCode(); |
|
225 switch(key) |
|
226 { |
|
227 case 'd': |
|
228 iNotifier.CompleteNotifier(KErrNone, EDisallowNewNapConnection); |
|
229 CloseConsoleWindow(); |
|
230 break; |
|
231 |
|
232 case 'l': |
|
233 iNotifier.CompleteNotifier(KErrNone, EAcceptNapConnectionDisallowUplinkAccess); |
|
234 CloseConsoleWindow(); |
|
235 break; |
|
236 |
|
237 case 'n': |
|
238 iNotifier.CompleteNotifier(KErrNone, EAcceptNapConnectionAllowUplinkAccess); |
|
239 CloseConsoleWindow(); |
|
240 break; |
|
241 |
|
242 default: |
|
243 // Invalid character - request input again. |
|
244 DrawExistingConnections(); |
|
245 iConsole->Printf(_L("\n *** Invalid option [%c] Please try again ***\n"), TUint(key)); |
|
246 DrawInstructionsAndWaitForInput(); |
|
247 break; |
|
248 }; |
|
249 } |
|
250 |
|
251 void CPanNapUplinkAuthorisationNotifierEngine::DoCancel() |
|
252 { |
|
253 iConsole->ReadCancel(); |
|
254 |
|
255 CloseConsoleWindow(); |
|
256 } |
|
257 |
|
258 void CPanNapUplinkAuthorisationNotifierEngine::CloseConsoleWindow() |
|
259 { |
|
260 // Delete the console window |
|
261 delete iConsole; |
|
262 iConsole = NULL; |
|
263 } |
|
264 |