|
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 // prt.cpp - Packet Probe Hook |
|
15 // |
|
16 |
|
17 #include <e32std.h> |
|
18 #include <e32base.h> |
|
19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
20 #include <es_prot_internal.h> |
|
21 #endif |
|
22 |
|
23 #include "family.h" |
|
24 #include "prt.h" |
|
25 #include "sap.h" |
|
26 #include "inet6log.h" |
|
27 |
|
28 |
|
29 CProtocolProbe::CProtocolProbe(TUint aId) : iId(aId) |
|
30 { |
|
31 LOG(Log::Printf(_L("Probe::CProtocolProbe()\r\n"));) |
|
32 } |
|
33 |
|
34 void CProtocolProbe::InitL(TDesC& aTag) |
|
35 { |
|
36 LOG(Log::Printf(_L("Probe::InitL()\r\n"));) |
|
37 CProtocolBase::InitL(aTag); |
|
38 } |
|
39 |
|
40 |
|
41 void CProtocolProbe::StartL() |
|
42 { |
|
43 // __ASSERT_DEBUG(iProtocol != NULL, User::Leave(KErrGeneral)); |
|
44 } |
|
45 |
|
46 CProtocolProbe::~CProtocolProbe() |
|
47 { |
|
48 LOG(Log::Printf(_L("Probe::~CProtocolProbe()\r\n"));) |
|
49 } |
|
50 |
|
51 |
|
52 CProtocolProbe *CProtocolProbe::NewL(TUint aId) |
|
53 { |
|
54 return new (ELeave) CProtocolProbe(aId); |
|
55 } |
|
56 |
|
57 void CProtocolProbe::FillIdentification(TServerProtocolDesc& anEntry, TUint aId) |
|
58 { |
|
59 anEntry.iName=_S("probe"); |
|
60 if (aId > 1) |
|
61 anEntry.iName.AppendNum(aId-1); |
|
62 anEntry.iAddrFamily = KAfProbe; |
|
63 anEntry.iSockType = KSockDatagram; |
|
64 anEntry.iProtocol = aId; |
|
65 anEntry.iVersion = TVersion(1, 0, 0); |
|
66 anEntry.iByteOrder = EBigEndian; |
|
67 anEntry.iServiceInfo = KSIDatagram | KSIConnectionLess; |
|
68 anEntry.iNamingServices = 0; |
|
69 anEntry.iSecurity = KSocketNoSecurity; |
|
70 anEntry.iMessageSize = 0xffff; |
|
71 anEntry.iServiceTypeInfo = ESocketSupport; |
|
72 anEntry.iNumSockets = KUnlimitedSockets; |
|
73 } |
|
74 |
|
75 void CProtocolProbe::Identify(TServerProtocolDesc *aDesc) const |
|
76 { |
|
77 FillIdentification(*aDesc, iId); |
|
78 } |
|
79 |
|
80 |
|
81 CServProviderBase* CProtocolProbe::NewSAPL(TUint aProtocol) |
|
82 { |
|
83 LOG(Log::Printf(_L("Probe::NewSAPL(%d)\r\n"), aProtocol);) |
|
84 |
|
85 if (aProtocol != KSockDatagram) |
|
86 User::Leave(KErrNotSupported); |
|
87 CProviderProbe* sap = new (ELeave) CProviderProbe(this); |
|
88 sap->iNext = iList; |
|
89 iList = sap; |
|
90 return sap; |
|
91 } |
|
92 |
|
93 // |
|
94 // CProtocolProbe::CancelSAP |
|
95 // ************************* |
|
96 // Disconnect SAP from the protocol |
|
97 // |
|
98 void CProtocolProbe::CancelSAP(const CServProviderBase* aSAP) |
|
99 { |
|
100 CProviderProbe **h, *sap; |
|
101 for (h = &iList; (sap = *h) != NULL; h = &sap->iNext) |
|
102 if (sap == aSAP) |
|
103 { |
|
104 *h = sap->iNext; |
|
105 break; |
|
106 } |
|
107 } |
|
108 |
|
109 |
|
110 // CProtocolProbe::NetworkAttachedL |
|
111 // ******************************** |
|
112 // When network becomes available, do the hooking! |
|
113 // |
|
114 void CProtocolProbe::NetworkAttachedL() |
|
115 { |
|
116 NetworkService()->BindL(this, MIp6Hook::BindPostHook()); |
|
117 NetworkService()->BindL(this, MIp6Hook::BindPostHook()+1); |
|
118 } |
|
119 |
|
120 // |
|
121 // CProtocolProbe::Deliver |
|
122 // *********************** |
|
123 // Generate a copy of the packet to every bound provider |
|
124 // |
|
125 void CProtocolProbe::Deliver(RMBufChain &aPacket) |
|
126 { |
|
127 const RMBufPktInfo *const info = RMBufPacketBase::PeekInfoInChain(aPacket); |
|
128 |
|
129 for (CProviderProbe* sap = iList; sap != NULL; sap = sap->iNext) |
|
130 { |
|
131 if (sap->IsReceiving(*info)) |
|
132 { |
|
133 RMBufPacketBase copy; |
|
134 TRAPD(err, copy.CopyPackedL(aPacket)); |
|
135 if (err == KErrNone) |
|
136 sap->Process(copy, this); |
|
137 else |
|
138 copy.Free(); |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 |
|
144 TInt CProtocolProbe::Send(RMBufChain &aPacket, CProtocolBase* aSrc) |
|
145 { |
|
146 Deliver(aPacket); |
|
147 return CProtocolPosthook::Send(aPacket, aSrc); |
|
148 } |
|
149 |
|
150 void CProtocolProbe::Process(RMBufChain &aPacket, CProtocolBase* aSrc) |
|
151 { |
|
152 Deliver(aPacket); |
|
153 CProtocolPosthook::Process(aPacket, aSrc); |
|
154 } |