|
1 // Copyright (c) 1997-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 // Interface to IR-LAN |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #if !defined(__IRLAN_H__) |
|
24 #define __IRLAN_H__ |
|
25 |
|
26 #define _MKLOG |
|
27 //#define __TRACEWIN__ |
|
28 |
|
29 #include <ir_sock.h> |
|
30 #include "IRLANDAT.H" |
|
31 |
|
32 #include <comms-infras/nifif.h> |
|
33 |
|
34 const TUint KIrlanMajorVersionNumber=1; //< Constant specifies Major version number. |
|
35 const TUint KIrlanMinorVersionNumber=0; //< Constant specifies Minor version number. |
|
36 const TUint KIrlanBuildVersionNumber=7; //< Constant specifies Build version number. |
|
37 |
|
38 class CInternalSocket; |
|
39 class CInternalNetDB; |
|
40 class CInternalHostResolver; |
|
41 class CIrlanControlEngine; |
|
42 |
|
43 /** |
|
44 @internalComponent |
|
45 */ |
|
46 NONSHARABLE_CLASS(CIrlanPktDrvFactory) : public CPktDrvFactory |
|
47 { |
|
48 public: |
|
49 CIrlanPktDrvFactory(); |
|
50 virtual CPktDrvBase* NewDriverL(CLANLinkCommon* aParent); |
|
51 virtual TVersion Version() const; |
|
52 }; |
|
53 |
|
54 inline CIrlanPktDrvFactory::CIrlanPktDrvFactory() |
|
55 { |
|
56 } |
|
57 |
|
58 /** |
|
59 Specific packet drivers are implemented as separate DLLs. |
|
60 @internalComponent |
|
61 */ |
|
62 NONSHARABLE_CLASS(CIrlanPktDrv) : public CPktDrvBase |
|
63 { |
|
64 public: |
|
65 CIrlanPktDrv(CPktDrvFactory& aFactory); |
|
66 virtual ~CIrlanPktDrv(); |
|
67 virtual void ConstructL(CLANLinkCommon* aParent); |
|
68 virtual TInt TestSend(TDesC8& /*aBuffer*/){return KErrNone;}; |
|
69 virtual TInt StartInterface(); |
|
70 virtual TInt StopInterface(); |
|
71 virtual TInt ResetInterface(); |
|
72 virtual TInt SetRxMode(TRxMode AMode); |
|
73 virtual TInt GetRxMode() const; |
|
74 virtual TInt AccessType(); |
|
75 virtual TInt ReleaseType(); |
|
76 virtual TInt SetInterfaceAddress(const THWAddr&); |
|
77 virtual TUint8* GetInterfaceAddress()const; |
|
78 virtual TInt GetMulticastList(const THWAddr* aAddr, TInt& n) const; |
|
79 virtual TInt SetMulticastList(const THWAddr* aAddr, TInt n); |
|
80 virtual TInt InterfacePowerUp(); |
|
81 virtual TInt InterfacePowerDown(); |
|
82 virtual TInt InterfaceSleep(); |
|
83 virtual TInt InterfaceResume(); |
|
84 virtual TInt Info(TNifIfInfo& aInfo, TInt aIndex) const; //< need to instantiate pure virtuals from CNifIfBase ETHER_802 |
|
85 virtual void FoundMACAddr(); |
|
86 virtual TInt Send(RMBufChain& aPdu); |
|
87 virtual TInt Notification(enum TAgentToNifEventType aEvent, void* aInfo); |
|
88 virtual TInt Control(TUint aLevel,TUint aName,TDes8& aOption, TAny* aSource=0); |
|
89 |
|
90 // Other functions |
|
91 void LinkLayerUp(); |
|
92 void Process(RMBufChain& aPdu); |
|
93 private: |
|
94 CIrlanPktDrv(); |
|
95 |
|
96 private: |
|
97 CEther802LLCBase* iMACLayer; |
|
98 CIrlanControlEngine *iControl; |
|
99 }; |
|
100 |
|
101 class CIrlanSender; |
|
102 class CIrlanReceiver; |
|
103 class CIrlanControlEngineTimers; |
|
104 |
|
105 /** |
|
106 Main Irlan control object. State machine implemented with as an active object. |
|
107 @internalComponent |
|
108 */ |
|
109 NONSHARABLE_CLASS(CIrlanControlEngine) : public CActive , public MResolverNotify , public MSocketNotify |
|
110 { |
|
111 public: |
|
112 friend class CIrlanSender; |
|
113 friend class CIrlanReceiver; |
|
114 private: |
|
115 enum TIrlanState |
|
116 { |
|
117 E_Idle,E_PassiveIdle,E_Query,E_Conn,E_Info,E_Media,E_FilterConfig,E_FilterOperation, |
|
118 E_FilterBroadcast,E_Open,E_Wait,E_Arb,E_Data,E_Close,E_Sync, |
|
119 }; |
|
120 enum TIrlanMode |
|
121 { |
|
122 EAccessPoint,EPeerToPeer,EHosted, |
|
123 }; |
|
124 public: |
|
125 static CIrlanControlEngine *NewL(CIrlanPktDrv* aPktDrv); |
|
126 ~CIrlanControlEngine(); |
|
127 void RunL(); |
|
128 void StartL(); |
|
129 void DoCancel(); |
|
130 // Notifier functions for internal sockets to call. |
|
131 void NewData(TUint aCount); |
|
132 void CanSend(); |
|
133 TInt Send(RMBufChain& aPdu, TAny* aSource=0); |
|
134 void ConnectComplete(); |
|
135 void ConnectComplete(const TDesC8& aConnectData); |
|
136 void ConnectComplete(CServProviderBase& aSSP); |
|
137 void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData); |
|
138 void CanClose(TDelete aDelete=EDelete); |
|
139 void CanClose(const TDesC8& aDisconnectData,TDelete aDelete=EDelete); |
|
140 void Error(TInt anError,TUint anOperationMask=EErrorAllOperations); |
|
141 void Disconnect(void); |
|
142 void Disconnect(TDesC8& aDisconnectData); |
|
143 void IoctlComplete(TDesC8 *aBuf); |
|
144 void NoBearer(const TDesC8& aConnectionParams); |
|
145 void Bearer(const TDesC8& aConnectionInfo); |
|
146 // Notifier functions for internal host resolver/netDB to call. |
|
147 void QueryComplete(TInt aError); |
|
148 // Other public functions |
|
149 TUint8* GetInterfaceAddress(); |
|
150 // static TInt SendCallBack(TAny* aSource); |
|
151 static TInt IrlanControlEngineTimerExpired(TAny *aIrlan); |
|
152 private: |
|
153 CIrlanControlEngine(); |
|
154 void ConstructL(CIrlanPktDrv* aNotify); |
|
155 void ActivateStateMachine(TInt aStat=KErrNone); |
|
156 // IrLAN state machine asynchronous actions: |
|
157 TInt AttemptingDiscoveryL(); |
|
158 TInt PassiveIdleTransitionL(); |
|
159 TInt QueryRemoteIASL(); |
|
160 TInt ConnectToProviderL(); |
|
161 void ParseControlCommand(); |
|
162 |
|
163 TInt GetInfoCmd(); |
|
164 TInt GetInfoReply(); |
|
165 void ParseInfoReply(); |
|
166 TInt GetMediaCmd(); |
|
167 TInt GetMediaReply(); |
|
168 TInt ParseMediaReply(); |
|
169 TInt OpenDataCmd(); |
|
170 void ParseOpenDataReply(); |
|
171 TInt GetDirectedFilterConfigCmd(); |
|
172 void ParseDirectedFilterConfigReply(); |
|
173 TInt SetDirectedFilterOperationCmd(); |
|
174 void ParseDirectedFilterOperationReply(); |
|
175 TInt SetBroadcastFilterOperationCmd(); |
|
176 void ParseBroadcastFilterOperationReply(); |
|
177 TInt ConnectToDataChannelL(); |
|
178 void SendIrlanControlFrame(RMBufChain& aPdu); |
|
179 void SendIrlanResponseFrame(RMBufChain& aPdu); |
|
180 void QueueWaitForControlCommand(); |
|
181 void QueueWaitForControlResponse(); |
|
182 void ProcessReceivedPacketL(); |
|
183 |
|
184 // Private utility functions |
|
185 CIrlanParameter* LookUpParameter(const TDesC8& aName); |
|
186 void HandleErrorL(); |
|
187 TInt DoIASQuery(const TDesC8& aClassName, |
|
188 const TDesC8& aAttributeName,TUint aRemDevAddr); |
|
189 TInt DoControlConnect(); |
|
190 TInt DoDataConnect(); |
|
191 |
|
192 // printing routines |
|
193 void PrintState(); |
|
194 void PrintIASResults(); |
|
195 void PrintIASError(TInt aError); |
|
196 void PrintResultCode(TIrlanQueryResult aResult); |
|
197 private: |
|
198 CIrlanPktDrv* iNotify; |
|
199 TUint8 iHWAddr[9]; |
|
200 |
|
201 HBufC8* iRecvBuffer; |
|
202 TUint iRecvBufLength; |
|
203 TPtr8 iRecvBufPtr; |
|
204 |
|
205 CIrlanControlEngineTimers *iTimers; |
|
206 TInt iDiscoveryAttempts; |
|
207 TIrlanMode iAccessType; |
|
208 TBool iAwaitingResponse; |
|
209 TInt iAwaitingCommand; |
|
210 TIrlanState iState; |
|
211 CIrlanPktDrv *iPktDrv; |
|
212 TUint iDiscoveredDevice; |
|
213 CIrlanSender* iSender; |
|
214 CIrlanReceiver* iReceiver; |
|
215 TProtocolDesc iProtInfo; |
|
216 CProtocolBase *iProtocol; |
|
217 CInternalHostResolver *iHostResolver; |
|
218 /** discovery log */ |
|
219 TNameEntry iLog; |
|
220 |
|
221 CInternalNetDB *iNetDatabase; |
|
222 TIASQuery iQuery; |
|
223 TIASResponse iResults; |
|
224 // listening |
|
225 CInternalSocket *iListenSock; |
|
226 CInternalSocket *iAcceptControlSock; |
|
227 |
|
228 // sending |
|
229 CInternalSocket *iControlSock; |
|
230 CInternalSocket *iDataSock; |
|
231 TRequestStatus iSendStat; |
|
232 TRequestStatus iRecvStat; |
|
233 TUint iOpenRetries; |
|
234 TInt iIrlanControlPortNum; |
|
235 TInt iIrlanDataPortNum; |
|
236 TDblQue<CIrlanParameter> iIrlanParameterList; |
|
237 RMBufPktQ iDataSendQ; |
|
238 }; |
|
239 |
|
240 /** |
|
241 @internalComponent |
|
242 */ |
|
243 NONSHARABLE_CLASS(CIrlanSender) : public CActive |
|
244 { |
|
245 public: |
|
246 static CIrlanSender* NewL(CIrlanControlEngine* aParent,CInternalSocket* aSock); |
|
247 ~CIrlanSender(); |
|
248 void QueueSend(RMBufChain& aPdu); |
|
249 void KickSender(); |
|
250 virtual void RunL(); |
|
251 virtual void DoCancel(); |
|
252 private: |
|
253 CIrlanSender(); |
|
254 void InitL(CIrlanControlEngine* aParent,CInternalSocket* aSock); |
|
255 void SeeIfPacketToSend(); |
|
256 private: |
|
257 CIrlanControlEngine* iParent; |
|
258 CInternalSocket* iDataSock; |
|
259 }; |
|
260 |
|
261 /** |
|
262 @internalComponent |
|
263 */ |
|
264 NONSHARABLE_CLASS(CIrlanReceiver) : public CActive |
|
265 { |
|
266 public: |
|
267 static CIrlanReceiver* NewL(CIrlanControlEngine* aParent,CInternalSocket* aSock); |
|
268 ~CIrlanReceiver(); |
|
269 void QueueRead(); |
|
270 virtual void RunL(); |
|
271 virtual void DoCancel(); |
|
272 private: |
|
273 CIrlanReceiver(); |
|
274 void InitL(CIrlanControlEngine* aParent,CInternalSocket* aSock); |
|
275 private: |
|
276 CIrlanControlEngine* iParent; |
|
277 CInternalSocket* iDataSock; |
|
278 }; |
|
279 |
|
280 /** |
|
281 @internalComponent |
|
282 */ |
|
283 NONSHARABLE_CLASS(CIrlanControlEngineTimers) : public CBase |
|
284 { |
|
285 public: |
|
286 friend class CIrlanControlEngine; |
|
287 virtual ~CIrlanControlEngineTimers(); |
|
288 static CIrlanControlEngineTimers *NewL(CIrlanControlEngine *aIrlan); |
|
289 void StartIrlanControlEngineTimer(TCallBack aCallBack,TInt aTimeout); |
|
290 void StopIrlanControlEngineTimer(); |
|
291 void DoIrlanControlEngineTimerExpired(); |
|
292 private: |
|
293 CIrlanControlEngineTimers(CIrlanControlEngine *aIrlan); |
|
294 private: |
|
295 CIrlanControlEngine *iIrlanControlEngine; |
|
296 TDeltaTimerEntry iIrlanControlEngineTimer; |
|
297 TDeltaTimerEntry *iIrlanControlEngineTimerH; |
|
298 }; |
|
299 |
|
300 #endif |
|
301 |
|
302 |
|
303 |