|
1 // Copyright (c) 2003-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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 /** |
|
19 @file |
|
20 @publishedAll |
|
21 @released |
|
22 */ |
|
23 |
|
24 #ifndef __OBEXBASE_H |
|
25 #define __OBEXBASE_H |
|
26 |
|
27 #include <obextypes.h> |
|
28 #include <mobexnotify.h> |
|
29 |
|
30 class CObexTransportControllerBase; |
|
31 class TObexTransportInfo; |
|
32 class CObexPacket; |
|
33 class CObexNotifyHandlerBase; |
|
34 |
|
35 /** |
|
36 @publishedAll |
|
37 @released |
|
38 |
|
39 This class is the common base class for any object which wishes |
|
40 to use the Obex Server or Client. |
|
41 The class which owns a CObexClient or CObexServer must be provide an object |
|
42 derived from this class to handle the call from the Server/Client for a request |
|
43 for a Password. |
|
44 @see CObex::SetCallBack |
|
45 */ |
|
46 class MObexAuthChallengeHandler |
|
47 { |
|
48 public: |
|
49 /** |
|
50 Indicates that the server/client has received an Authentication challenge. The challenge |
|
51 can only be responded to once a password has been retrieved by some means and passed |
|
52 back to the calling class. The password is passed back via CObex::UserPasswordL |
|
53 @param aRealm This will contain the Realm specified by the unit forcing the |
|
54 Authentication, if no UserID was supplied then this parameter will be of zero length. |
|
55 */ |
|
56 virtual void GetUserPasswordL(const TDesC& aRealm) = 0; |
|
57 |
|
58 /** |
|
59 Returns a null aObject if the extension is not implemented, or a pointer to another interface if it is. |
|
60 @param aInterface UID of the interface to return |
|
61 @param aObject the container for another interface as specified by aInterface |
|
62 */ |
|
63 IMPORT_C virtual void MOACH_ExtensionInterfaceL(TUid aInterface, void*& aObject); |
|
64 }; |
|
65 |
|
66 /** |
|
67 This class is the common base class for CObexClient and CObexServer. It is |
|
68 an abstract class and cannot be instantiated in itself. However, it does |
|
69 contain user functionality common to both client and server connections. |
|
70 |
|
71 Provides the basic OBEX transport functionality (sending and receiving |
|
72 files) |
|
73 Client and server provide the more specialied APIs for |
|
74 - initiation or response to puts & gets |
|
75 - (possible) handling of more generalised 'objects' (prob. with data buffered through a file). |
|
76 |
|
77 This class is not designed for user derivation |
|
78 |
|
79 @publishedAll |
|
80 @released |
|
81 */ |
|
82 NONSHARABLE_CLASS(CObex) : public CBase, protected MObexNotify |
|
83 { |
|
84 public: |
|
85 /** |
|
86 Describes the information set or received in a SETPATH command. |
|
87 |
|
88 The first bit of iFlags, 0, can be set to indicate to the receiver of SETPATH to backup a level before applying the path name. |
|
89 The second bit of iFlags, 1, can be set to indicate to the receiver of SETPATH to NOT create the directory if it doesn't exist. |
|
90 The iConstants variable is always set to zero as it is reserved. |
|
91 The iName variable indicates the directory to create or go to, and does not include the root directory of the receiver (i.e. |
|
92 if the directory to be set is C:\notes then iName is set to "notes"). |
|
93 If a name is not set then set CObex::TSetPathInfo::iNamePresent to false. |
|
94 */ |
|
95 NONSHARABLE_CLASS(TSetPathInfo) |
|
96 { |
|
97 public: |
|
98 IMPORT_C TSetPathInfo(); |
|
99 TSetPathInfo(const TObexSetPathData& aData); |
|
100 IMPORT_C TBool Parent() const; |
|
101 TUint8 iFlags; |
|
102 TUint8 iConstants; |
|
103 TBuf<KObexObjectDescriptionSize> iName; |
|
104 /** Whether iName is present in this SETPATH info */ |
|
105 TBool iNamePresent; |
|
106 private: |
|
107 // This data padding has been added to help prevent future binary compatibility breaks |
|
108 // Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used |
|
109 TUint32 iPadding1; |
|
110 TUint32 iPadding2; |
|
111 }; |
|
112 |
|
113 /** |
|
114 Current obex connection state |
|
115 In general, the further through the enum the values are, |
|
116 the further through the connection process the state machine |
|
117 will be. |
|
118 */ |
|
119 enum TConnectState |
|
120 { |
|
121 EConnIdle, /** Nothing is happening */ |
|
122 EConnTransport, /** Transport Link connected not yet established true Link */ |
|
123 EConnObex, /** full connection established */ |
|
124 ESimpleConnRequest, /** Connect without Auth has been sent by ClientReceived by Server */ |
|
125 EConnChallRxed, /** Server has issued a challenge, to a Client cionnect */ |
|
126 ESimpleConnChallIssued, /** Server, received Simple Connect but Server Challenge issued */ |
|
127 EChallConnRequested, /** Connect with Auth has been sent by Client/Received by Server */ |
|
128 EChallConnChallIssued, /** Server has sent a Challenge & Resp to a Client EChallConnRequest */ |
|
129 EWaitForFinalResponse, /** Client, waiting for final success/fail not chall-response expected |
|
130 Server, Waiting for final Resp fromm Client to Challenge */ |
|
131 EFinalResponseReceived, /** Server, the final response has been received */ |
|
132 EFinalChallRxed, /** Server, Client connect with challenge, Server responds with challenge, Client re-issued original/new challenge */ |
|
133 EWaitForUserInput, /** waiting for the user */ |
|
134 EDropLink /** drop the link */ |
|
135 }; |
|
136 |
|
137 /** |
|
138 The Obex operation currently being performed. |
|
139 */ |
|
140 enum TOperation |
|
141 { |
|
142 EOpConnect = 0x00, /** Connect */ |
|
143 EOpDisconnect = 0x01, /** Disconnect */ |
|
144 EOpPut = 0x02, /** Put */ |
|
145 EOpGet = 0x03, /** Get */ |
|
146 EOpSetPath = 0x05, /** SetPath */ |
|
147 EOpAbort = 0xFF, /** Abort - must fit in one pkt so final bit is always set */ |
|
148 EOpAbortNoFBit = 0x7F, /** Abort (internal, never transmitted) */ |
|
149 EOpGetResponse = 0xFD, /** Internal - not actually an obex operation. */ |
|
150 EOpIdle = 0xFE, /** Internal - not actually an obex operation. */ |
|
151 }; |
|
152 |
|
153 /** |
|
154 Flags to suppress the authentication elements of the authentication challenge header. |
|
155 */ |
|
156 enum TObexSuppressedAuthElements |
|
157 { |
|
158 EObexNoSuppressedAuthElements = 0x00, |
|
159 EObexSuppressChallengeOptionsAuthElement = 0x01, |
|
160 EObexSuppressRealmAuthElement = 0x02, |
|
161 EObexSuppressAllAuthElements = EObexSuppressChallengeOptionsAuthElement | EObexSuppressRealmAuthElement // Must be last |
|
162 }; |
|
163 |
|
164 virtual ~CObex(); |
|
165 IMPORT_C void SetCallBack(MObexAuthChallengeHandler& aCallBack); |
|
166 IMPORT_C TBool IsConnected() const; |
|
167 IMPORT_C TBool IsStrictPeer() const; |
|
168 IMPORT_C const TObexConnectInfo& LocalInfo() const; |
|
169 IMPORT_C TInt SetLocalWho(const TDesC8& aInfo); |
|
170 IMPORT_C const TObexConnectInfo& RemoteInfo() const; |
|
171 IMPORT_C void SuppressAuthenticationHeaderElements(TObexSuppressedAuthElements aSuppressedObexAuthElements); |
|
172 |
|
173 // Implementation of MObexNotify Interface |
|
174 /** |
|
175 @internalTechnology |
|
176 */ |
|
177 virtual void Process(CObexPacket& aPacket); |
|
178 /** |
|
179 @internalTechnology |
|
180 */ |
|
181 virtual void Error(TInt aError) ; |
|
182 /** Call back to start the obex session |
|
183 @internalTechnology |
|
184 */ |
|
185 virtual void TransportUp(); |
|
186 /** |
|
187 @internalTechnology |
|
188 */ |
|
189 virtual void TransportDown(TBool aForceTransportDeletion); |
|
190 |
|
191 virtual void UserPasswordL( const TDesC& aPassword) = 0; |
|
192 IMPORT_C void RemoteAddr(TSockAddr& anAddr); |
|
193 |
|
194 TConnectState GetConnectState() const; |
|
195 |
|
196 IMPORT_C TBool IsAuthenticating() const; |
|
197 |
|
198 protected: |
|
199 CObex(); |
|
200 virtual void ConstructL(TObexTransportInfo& aObexTransportInfo); |
|
201 virtual TInt ParseConnectPacket(CObexPacket& aPacket) = 0; |
|
202 void SetConnectState(TConnectState aNewState); |
|
203 IMPORT_C TConnectState ConnectState() const; // same as GetConnectState - has to be maintained here for BC |
|
204 virtual void OnPacketReceive(CObexPacket& aPacket) =0; |
|
205 virtual void OnError(TInt aError) =0; |
|
206 virtual void OnTransportUp() =0; |
|
207 virtual void OnTransportDown() =0; |
|
208 void ProcessChallengeL(const TObexInternalHeader& hdr); //process the received challenge |
|
209 void ProcessChallResponseL(const TObexInternalHeader& hdr); //process the response to challenge |
|
210 TInt GenerateChallenge(CObexPacket& aPacket); //generate a challenge |
|
211 void PrepareChallResponseL(const TDesC& aPassword); //generate a response a respose to challenge |
|
212 //after user Password input |
|
213 void ForcedTransportDown(); |
|
214 void ControlledTransportDown(); |
|
215 void RemoteInfoCleanup(); |
|
216 void CObex::CancelObexConnection(); |
|
217 protected: |
|
218 TConnectState iConnectState; |
|
219 CObexTransportControllerBase* iTransportController; |
|
220 TObexConnectInfo iLocalInfo; |
|
221 TObexConnectInfo iRemoteInfo; |
|
222 MObexAuthChallengeHandler* iCallBack; |
|
223 TNonce iOutgoingNonce; //nonce used when challenging |
|
224 TNonce iIncomingNonce; //nonce used when receiving a challenge |
|
225 HBufC8* iChallPassword; //password used when challenging |
|
226 HBufC8* iRespPassword; //password used when responding to a challenge |
|
227 HBufC8* iRxChallenge; |
|
228 TBuf8<KChallResponseSize> iOutgoingChallResp;//response to the previously issued challenge |
|
229 //16 nonce, 16 digest resp, 20 UserID, 3*(tag+size) |
|
230 TBuf8<KChallResponseSize> iIncomingChallResp;//response received from previous challenge |
|
231 TBuf8<KObexRespSize> iIncomingRequestDigest; |
|
232 HBufC* iRemoteUID; //UID of remote device |
|
233 HBufC* iRemoteRealm;//Realm of remote device |
|
234 CObexAuthenticator* iAuthEngine; |
|
235 TBool iChallenge; //to challenge or not to challenge? |
|
236 TBool iUserIDRequested; //does the challenge insist that a UserID is returned |
|
237 TBool iReserved; //released boolean now available for future use |
|
238 TOperation iCurrentOperation; |
|
239 CObexNotifyHandlerBase* iNotifyHandler; |
|
240 TUint iSuppressedObexAuthElements; |
|
241 }; |
|
242 |
|
243 #endif // __OBEXBASE_H |