|
1 // Copyright (c) 2008-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 // implementation of UDP and TCP tranlation |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 |
|
24 #include "hookdefs.h" |
|
25 #include "naptinterface.h" |
|
26 #include "naptutil.h" |
|
27 #include "naptconfigtable.h" |
|
28 |
|
29 void CNaptClientConfigMgr::ConstructL() |
|
30 /** |
|
31 * This is a phase2 constructor for this object. |
|
32 * @param None |
|
33 * @return None |
|
34 * |
|
35 **/ |
|
36 { |
|
37 |
|
38 } |
|
39 |
|
40 CNaptClientConfigMgr :: CNaptClientConfigMgr(CProtocolNapt& aProtocol):iProtocol(aProtocol) |
|
41 /** |
|
42 * This is a constructor for config manager class. |
|
43 * @param None |
|
44 * @return None |
|
45 * |
|
46 **/ |
|
47 { |
|
48 |
|
49 } |
|
50 |
|
51 CNaptClientConfigMgr :: ~CNaptClientConfigMgr() |
|
52 /** |
|
53 * This is a destructor for config manager class. |
|
54 * @param None |
|
55 * @return None |
|
56 * |
|
57 **/ |
|
58 { |
|
59 iConfigList.ResetAndDestroy(); |
|
60 } |
|
61 |
|
62 CNaptClientConfigMgr* CNaptClientConfigMgr::NewL(CProtocolNapt& aProtocol) |
|
63 /** |
|
64 * This is a static method to create an instance of CNaptClientConfigMgr class |
|
65 * @param CProtocolNapt& - Reference to protocol instance object |
|
66 * @return CNaptClientConfigMgr* - Pointer to created object intance |
|
67 * |
|
68 **/ |
|
69 { |
|
70 CNaptClientConfigMgr* self = new(ELeave) CNaptClientConfigMgr(aProtocol); |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 CleanupStack::Pop(); |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 TNaptConfigInfo* CNaptClientConfigMgr :: FindConfig(TUint32 aIfIndex, TInt aIfFlag) |
|
79 /** |
|
80 * This method finds a configuration from config list based on interface index or private IAP. |
|
81 * @param aIfIndex - Interface index |
|
82 * @return None |
|
83 * |
|
84 **/ |
|
85 { |
|
86 TNaptConfigInfo* cinfo = NULL; |
|
87 TUint32 ifindex = 0; |
|
88 /*Loop through the list to find an entry corresponding to aIapId*/ |
|
89 for(TUint index = 0; index < iConfigList.Count(); index++) |
|
90 { |
|
91 (aIfFlag)?(ifindex = iConfigList[index]->iIfIndex):(ifindex = iConfigList[index]->iPrivateIap); |
|
92 if(ifindex != aIfIndex) |
|
93 continue; |
|
94 else |
|
95 { |
|
96 /*Found a matching entry here so break out of the loop*/ |
|
97 cinfo = iConfigList[index]; |
|
98 break; |
|
99 } |
|
100 |
|
101 } |
|
102 /*return configuration info*/ |
|
103 return cinfo; |
|
104 } |
|
105 |
|
106 void CNaptClientConfigMgr :: DeleteConfig(TUint32 aIapId) |
|
107 /** |
|
108 * This method deletes a configuration from config list based on IAP Id. |
|
109 * @param aIapId - IAP Identifier |
|
110 * @return None |
|
111 * |
|
112 **/ |
|
113 { |
|
114 /*Loop through the list to find an entry corresponding to aIapId*/ |
|
115 for(TUint index = 0; index < iConfigList.Count(); index++) |
|
116 { |
|
117 if(iConfigList[index]->iPrivateIap != aIapId) |
|
118 continue; |
|
119 else |
|
120 { |
|
121 /*Found a matching entry here so break out of the loop*/ |
|
122 delete iConfigList[index]; |
|
123 iConfigList[index] = NULL; |
|
124 iConfigList.Remove(index); |
|
125 break; |
|
126 } |
|
127 } |
|
128 iConfigList.Compress(); |
|
129 } |
|
130 |
|
131 void CNaptClientConfigMgr :: DeleteConfig(TNaptConfigInfo *aConfigInfo) |
|
132 /** |
|
133 * This method deletes a configuration from config list using a pointer |
|
134 * @param aIfIndex - Interface index |
|
135 * @return None |
|
136 * |
|
137 **/ |
|
138 { |
|
139 TInt index = iConfigList.Find(aConfigInfo); |
|
140 if(index != KErrNotFound) |
|
141 { |
|
142 delete iConfigList[index]; |
|
143 iConfigList[index] = NULL; |
|
144 iConfigList.Remove(index); |
|
145 iConfigList.Compress(); |
|
146 } |
|
147 |
|
148 } |
|
149 |
|
150 |
|
151 TInt CNaptClientConfigMgr::UpdateConfigL(const TInterfaceLockInfo* aInfo, CSapNapt* aSap) |
|
152 /** |
|
153 * This method updates the configuration in the list. In case configuration is already present it updates |
|
154 * the existing configuration corresponsing to interface index else it creates a new config and adds it |
|
155 * the configuration list. |
|
156 * @param const TInterfaceLockInfo* aInfo - Interface structure used for provisioning info |
|
157 * @param CSapNapt* - Pointer to SAP thru which provisioning is being done. |
|
158 * @return TInt - KErrNone in case of success. |
|
159 * |
|
160 **/ |
|
161 { |
|
162 |
|
163 TInt err = KErrNone; |
|
164 TNaptConfigInfo* cinfo = NULL; |
|
165 |
|
166 if(aInfo != NULL) |
|
167 { |
|
168 cinfo = aSap->GetConfigInfo(); |
|
169 if(cinfo == NULL) |
|
170 { |
|
171 cinfo = FindConfig(aInfo->iIfIndex); |
|
172 if(!cinfo) |
|
173 cinfo = new(ELeave)TNaptConfigInfo; |
|
174 else |
|
175 { |
|
176 //Interface Index is already in Use, aborting operation |
|
177 err = KErrAbort; |
|
178 return err; |
|
179 } |
|
180 } |
|
181 //cinfo is initialized above, hence Pointer NULL check is not required here. |
|
182 cinfo->iPublicIap = aInfo->iPublicIap; |
|
183 cinfo->iPrivateIap = aInfo->iPrivateIap; |
|
184 TInetAddr::Cast(cinfo->iPublicGatewayIP).SetV4MappedAddress((aInfo->iPublicIp).Address()); |
|
185 TInetAddr::Cast(cinfo->iPrivateIp).SetV4MappedAddress((aInfo->iPrivateIp).Address()); |
|
186 //converting masklength to v6 mapped.So it will be 128-8 for class A, 128-16 for class B |
|
187 //128-24 for class C |
|
188 cinfo->iNetMaskLength = 128-(aInfo->iNetmaskLength); |
|
189 cinfo->iIfIndex = aInfo->iIfIndex; |
|
190 #ifdef SYMBIAN_NETWORKING_ADDRESS_PROVISION |
|
191 cinfo->iUplinkAccess = aInfo->iUplinkAccess; |
|
192 //Get the client IP which DHCP will offer from IAP table |
|
193 //This is a not proper and will be fixed later for full DHCP impl |
|
194 err = TNaptUtil::GetClientIp(aInfo->iPrivateIap, cinfo->iProvisionedIp); |
|
195 #endif |
|
196 if(!aSap->GetConfigInfo()) |
|
197 { |
|
198 AddConfigL(cinfo); |
|
199 aSap->SetConfigInfo(cinfo); |
|
200 } |
|
201 } |
|
202 return err; |
|
203 } |
|
204 |
|
205 |
|
206 void CNaptClientConfigMgr::AddConfigL(const TNaptConfigInfo* aConfigInfo) |
|
207 /** |
|
208 * This method adds the configuration to the config list. |
|
209 * |
|
210 * @param const TNaptConfigInfo* aConfigInfo - Config Info to be added |
|
211 * @return None |
|
212 * |
|
213 **/ |
|
214 { |
|
215 iConfigList.AppendL(aConfigInfo); |
|
216 } |