|
1 // Copyright (c) 2004-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 // sap.cpp - Packet Probe Hook |
|
15 // |
|
16 |
|
17 #include "sap.h" |
|
18 |
|
19 CProviderProbe::CProviderProbe(CProtocolProbe* aProtocol) : iProtocol(aProtocol) |
|
20 { |
|
21 __DECLARE_NAME(_S("CProviderProbe")); |
|
22 iQueueLimit = 8000; |
|
23 } |
|
24 |
|
25 CProviderProbe::~CProviderProbe() |
|
26 { |
|
27 if (iProtocol) |
|
28 iProtocol->CancelSAP(this); |
|
29 } |
|
30 |
|
31 void CProviderProbe::Start() |
|
32 { |
|
33 } |
|
34 |
|
35 TInt CProviderProbe::GetOption(TUint /*aLevel*/, TUint /*aName*/, TDes8& /*aOption*/) const |
|
36 { |
|
37 return KErrNotSupported; |
|
38 } |
|
39 |
|
40 TInt CProviderProbe::SetOption(TUint /*aLevel*/, TUint /*aName*/, const TDesC8& /*aOption*/) |
|
41 { |
|
42 // return KErrNotSupported; |
|
43 return KErrNone; |
|
44 } |
|
45 |
|
46 void CProviderProbe::Ioctl(TUint /*level*/,TUint /*name*/,TDes8* /*anOption*/) |
|
47 { |
|
48 Panic(EProbePanic_NotSupported); |
|
49 } |
|
50 |
|
51 void CProviderProbe::CancelIoctl(TUint /*aLevel*/,TUint /*aName*/) |
|
52 { |
|
53 Panic(EProbePanic_NotSupported); |
|
54 } |
|
55 |
|
56 |
|
57 TUint CProviderProbe::Write(const TDesC8 &/*aDesc*/, TUint /*aOptions*/, TSockAddr* /*aAddr*/) |
|
58 { |
|
59 // For now, Write does nothing on probe socket |
|
60 return 1; |
|
61 } |
|
62 |
|
63 void CProviderProbe::Shutdown(TCloseType /*option*/,const TDesC8& /*aDisconnectionData*/) |
|
64 { |
|
65 Panic(EProbePanic_NotSupported); |
|
66 } |
|
67 |
|
68 void CProviderProbe::Shutdown(TCloseType aOption) |
|
69 { |
|
70 switch(aOption) |
|
71 { |
|
72 case EStopInput: |
|
73 iInputStopped = ETrue; |
|
74 iRecvQ.Free(); |
|
75 iSocket->Error(KErrNone,MSocketNotify::EErrorClose); // Complete KErrNone |
|
76 break; |
|
77 |
|
78 case EStopOutput: |
|
79 iSocket->Error(KErrNone,MSocketNotify::EErrorClose); // Complete KErrNone |
|
80 break; |
|
81 |
|
82 default: |
|
83 if (aOption != EImmediate) |
|
84 iSocket->CanClose(); |
|
85 } |
|
86 } |
|
87 |
|
88 TInt CProviderProbe::SetLocalName(TSockAddr &/*aAddr*/) |
|
89 { |
|
90 return 0; // Ignore silently |
|
91 } |
|
92 |
|
93 void CProviderProbe::AutoBind() |
|
94 { |
|
95 // Ignore silently |
|
96 } |
|
97 |
|
98 // CProviderProbe::Error |
|
99 // ********************* |
|
100 // Soft errors are not immediately reported to the socket server. |
|
101 // A soft error is indicated by a zero aOperationMask. |
|
102 // |
|
103 // The socket error can be cleared by calling this routing with |
|
104 // aError == KErrNone. |
|
105 // |
|
106 void CProviderProbe::Error(TInt aError, TUint aOperationMask) |
|
107 { |
|
108 if (aError <= KErrNone && !FatalState()) |
|
109 { |
|
110 if (aError == KErrNone) |
|
111 iErrorMask = aOperationMask; |
|
112 else |
|
113 iErrorMask |= aOperationMask; |
|
114 if (iSocket && aOperationMask) |
|
115 iSocket->Error(aError, aOperationMask); |
|
116 } |
|
117 } |
|
118 |
|
119 // |
|
120 // CProviderProbe::Process() |
|
121 // ************************* |
|
122 // Process incoming data from the protocol object. |
|
123 // |
|
124 void CProviderProbe::Process(RMBufChain& aPacket, CProtocolBase * /*aSourceProtocol*/) |
|
125 { |
|
126 // iInputStopped is set at ShutDown() and no packets should be coming |
|
127 // from the protocol after that. However, without knowing the exact |
|
128 // details of the process model/threads, it could be possible that |
|
129 // a Process() call has been initiated by the protocol and interrupted |
|
130 // before the shutdown, thus there may be a need for this iInputStopped |
|
131 // flag, although I would prefer to do without... NEED TO VERIFY IF |
|
132 // iInputStopped is really needed!!! -- msa |
|
133 // |
|
134 if(!(iInputStopped || |
|
135 (iErrorMask & (MSocketNotify::EErrorFatal|MSocketNotify::EErrorConnect|MSocketNotify::EErrorRecv)))) |
|
136 { |
|
137 iQueueLimit -= RMBufPacketBase::PeekInfoInChain(aPacket)->iLength; |
|
138 iRecvQ.Append(aPacket); |
|
139 iSocket->NewData(1); |
|
140 } |
|
141 else |
|
142 aPacket.Free(); |
|
143 } |
|
144 |
|
145 // CProviderProbe::IsReceiving |
|
146 // *************************** |
|
147 // |
|
148 TBool CProviderProbe::IsReceiving(const RMBufPktInfo & /*aInfo*/) |
|
149 { |
|
150 if (iQueueLimit < 0) |
|
151 { |
|
152 // Receive Queue limit is full, cannot receive this packet |
|
153 iPacketsDropped++; |
|
154 return FALSE; |
|
155 } |
|
156 return TRUE; |
|
157 } |
|
158 |
|
159 |
|
160 // CProviderProbe::GetData |
|
161 // *********************** |
|
162 void CProviderProbe::GetData(TDes8 &aDesc, TUint aOptions, TSockAddr *anAddr) |
|
163 { |
|
164 RMBufPacketBase packet; |
|
165 if (!iRecvQ.Remove(packet)) |
|
166 Panic(EProbePanic_NoData); |
|
167 |
|
168 const RMBufPktInfo *const info = packet.Unpack(); |
|
169 |
|
170 packet.CopyOut(aDesc, 0); |
|
171 |
|
172 if (anAddr!=NULL) |
|
173 *anAddr = info->iSrcAddr; |
|
174 |
|
175 if (aOptions & KSockReadPeek) |
|
176 { |
|
177 packet.Pack(); |
|
178 iRecvQ.Prepend(packet); |
|
179 iSocket->NewData(1); |
|
180 } |
|
181 else |
|
182 { |
|
183 iQueueLimit += info->iLength; // Allow more packets in.. |
|
184 packet.Free(); |
|
185 } |
|
186 } |
|
187 |
|
188 #ifdef TCPIP6_CAPABILITY |
|
189 TInt CProviderProbe::SecurityCheck(MProvdSecurityChecker *aChecker) |
|
190 { |
|
191 _LIT_SECURITY_POLICY_C1(KPolicyNetworkControl, ECapabilityNetworkControl); |
|
192 return aChecker->CheckPolicy(KPolicyNetworkControl, "PROBE HOOK SAP"); |
|
193 } |
|
194 #endif |