|
1 // Copyright (c) 2005-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 // sblpapi.cpp - SBLP QoS API |
|
15 // |
|
16 |
|
17 #include "sblpextn.h" |
|
18 #include "qosextn_constants.h" |
|
19 #include "qosextn_log.h" |
|
20 #include <networking/qosparameters.h> |
|
21 |
|
22 // Buffer size |
|
23 const TUint KSblpApiBufSize = 8192; |
|
24 const TUint KNumberOfElementsPerFlowId = 2; |
|
25 // Note that KAuthorizationTokenAdjustedStringLength value should be calculated |
|
26 // very carefully to fit the string inside the config block used by the pfqoslib. |
|
27 // if KAuthorizationTokenActualStringLength = 255, KAuthorizationTokenAdjustedStringLength should |
|
28 // be 260. |
|
29 const TUint KAuthorizationTokenActualStringLength = 255; |
|
30 const TUint KAuthorizationTokenStringZeroTerminated = KAuthorizationTokenActualStringLength + 1; |
|
31 const TUint KAuthorizationTokenAdjustedStringLength = KAuthorizationTokenStringZeroTerminated + 4; |
|
32 |
|
33 |
|
34 EXPORT_C CSblpParameters::CSblpParameters() |
|
35 { |
|
36 iAuthorizationToken = KNullDesC8; |
|
37 } |
|
38 |
|
39 EXPORT_C CSblpParameters::~CSblpParameters() |
|
40 { |
|
41 iFlowIds.Reset(); |
|
42 } |
|
43 |
|
44 EXPORT_C CSblpParameters& CSblpParameters::operator= (const CSblpParameters& f) |
|
45 { |
|
46 if (this != &f) |
|
47 { |
|
48 SetMAT(f.iAuthorizationToken); |
|
49 SetFlowIds(f.iFlowIds); |
|
50 } |
|
51 return *this; |
|
52 } |
|
53 |
|
54 EXPORT_C TInt CSblpParameters::GetMAT(TAuthorizationToken &aAuthToken) const |
|
55 { |
|
56 aAuthToken = iAuthorizationToken; |
|
57 return KErrNone; |
|
58 } |
|
59 |
|
60 EXPORT_C void CSblpParameters::SetMAT(const TAuthorizationToken &aAuthToken ) |
|
61 { |
|
62 iAuthorizationToken = aAuthToken; |
|
63 } |
|
64 |
|
65 EXPORT_C CSblpParameters::TFlowIdentifier& CSblpParameters::GetFlowId(TInt aIndex) |
|
66 { |
|
67 __ASSERT_DEBUG(aIndex<iFlowIds.Count(),User::Panic(_L("Sblp"),KErrArgument)); |
|
68 return iFlowIds[aIndex]; |
|
69 } |
|
70 |
|
71 EXPORT_C void CSblpParameters::SetFlowIds(const RArray<TFlowIdentifier> &aFlowIds) |
|
72 { |
|
73 iFlowIds.Reset(); |
|
74 TInt i; |
|
75 for(i=0; i<aFlowIds.Count();i++) |
|
76 { |
|
77 this->iFlowIds.Append(aFlowIds[i]); |
|
78 } |
|
79 } |
|
80 |
|
81 EXPORT_C TInt CSblpParameters::GetFlowIds(RArray<TFlowIdentifier>& aFlowIds) |
|
82 { |
|
83 aFlowIds.Reset(); |
|
84 TInt i; |
|
85 for(i=0; i<iFlowIds.Count();i++) |
|
86 { |
|
87 aFlowIds.Append(this->iFlowIds[i]); |
|
88 } |
|
89 return KErrNone; |
|
90 } |
|
91 |
|
92 EXPORT_C TInt CSblpParameters::NrOfFlowIds() |
|
93 { |
|
94 return iFlowIds.Count(); |
|
95 } |
|
96 |
|
97 // |
|
98 // CSblpPolicy |
|
99 // |
|
100 EXPORT_C CSblpPolicy* CSblpPolicy::NewL() |
|
101 { |
|
102 CSblpPolicy* policy = new (ELeave) CSblpPolicy(); |
|
103 CleanupStack::PushL(policy); |
|
104 policy->ConstructL(); |
|
105 CleanupStack::Pop(); |
|
106 return policy; |
|
107 } |
|
108 |
|
109 CSblpPolicy::CSblpPolicy() |
|
110 { |
|
111 iType = KPfqosExtensionSBLP; |
|
112 } |
|
113 |
|
114 void CSblpPolicy::ConstructL() |
|
115 { |
|
116 iData = HBufC8::NewL(KSblpApiBufSize); |
|
117 iSblp = new (ELeave) CSblpParameters; |
|
118 } |
|
119 |
|
120 EXPORT_C CSblpPolicy::~CSblpPolicy() |
|
121 { |
|
122 delete iSblp; |
|
123 //iData is deleted in the base |
|
124 } |
|
125 |
|
126 static void SetIntValue(pfqos_configblock_int& data, TInt aValue, |
|
127 const TDesC8& aName) |
|
128 { |
|
129 data.len = sizeof(pfqos_configblock_int)/8; |
|
130 data.padding = data.reserved = 0; |
|
131 data.type = KPfqosTypeInteger; |
|
132 data.value = aValue; |
|
133 Mem::FillZ(data.id, KPfqosMaxName); |
|
134 Mem::Copy(data.id, aName.Ptr(), aName.Length()); |
|
135 } |
|
136 |
|
137 |
|
138 |
|
139 static void SetStringBlockHeader(pfqos_configblock& data, |
|
140 TDesC8& /*aValue*/, const TDesC8& aName) |
|
141 { |
|
142 data.len = (sizeof(pfqos_configblock) + KAuthorizationTokenAdjustedStringLength )/8; |
|
143 data.padding = data.reserved = 0; |
|
144 data.type = KPfqosTypeString; |
|
145 Mem::FillZ(data.id, KPfqosMaxName); |
|
146 Mem::Copy(data.id, aName.Ptr(), aName.Length()); |
|
147 } |
|
148 |
|
149 EXPORT_C TDesC8& CSblpPolicy::Data() |
|
150 { |
|
151 TPtr8 bufPtr = iData->Des(); |
|
152 bufPtr.SetLength(0); |
|
153 const TInt byte_len = (sizeof(pfqos_configure)+ |
|
154 sizeof(pfqos_extension)+ |
|
155 sizeof(pfqos_configblock)+ |
|
156 KAuthorizationTokenAdjustedStringLength+ |
|
157 KNumberOfElementsPerFlowId * iSblp->NrOfFlowIds() * |
|
158 sizeof(pfqos_configblock_int)); |
|
159 |
|
160 pfqos_configure header; |
|
161 header.pfqos_configure_len = (TUint16)((byte_len + 7) / 8); |
|
162 header.pfqos_ext_type = EPfqosExtExtension; |
|
163 header.reserved = 0; |
|
164 header.protocol_id = 0; |
|
165 bufPtr.Append((TUint8*)&header, sizeof(pfqos_configure)); |
|
166 |
|
167 pfqos_extension extensionType; |
|
168 extensionType.pfqos_ext_len = 0; |
|
169 extensionType.pfqos_ext_type = EPfqosExtExtension; |
|
170 extensionType.pfqos_extension_type = KPfqosExtensionSBLP; |
|
171 bufPtr.Append((TUint8*)&extensionType, sizeof(pfqos_extension)); |
|
172 |
|
173 /* MAT |
|
174 |
|
175 MAT is a string |
|
176 The string is put after pfqos_configblock |
|
177 The pfqos_configblock length is the size of pfqos_configblock |
|
178 plus the string length |
|
179 */ |
|
180 TAuthorizationToken authToken; |
|
181 pfqos_configblock stringBlock; |
|
182 iSblp->GetMAT(authToken); |
|
183 SetStringBlockHeader(stringBlock,authToken,KDescSblpMediaAuthorizationToken); |
|
184 bufPtr.Append((TUint8*)&stringBlock, sizeof(pfqos_configblock)); |
|
185 // put the string now |
|
186 authToken.ZeroTerminate(); |
|
187 bufPtr.Append((TUint8*)authToken.Ptr(),KAuthorizationTokenAdjustedStringLength); |
|
188 |
|
189 |
|
190 // Flowids |
|
191 pfqos_configblock_int ext; |
|
192 TInt i; |
|
193 for(i=0; i<iSblp->NrOfFlowIds();i++) |
|
194 { |
|
195 CSblpParameters::TFlowIdentifier& flowId = iSblp->GetFlowId(i); |
|
196 SetIntValue(ext,flowId.iMediaComponentNumber,KDescSblpMediaComponentNumber); |
|
197 bufPtr.Append((TUint8*)&ext, sizeof(pfqos_configblock_int)); |
|
198 SetIntValue(ext,flowId.iIPFlowNumber,KDescSblpIPFlowNumber); |
|
199 bufPtr.Append((TUint8*)&ext, sizeof(pfqos_configblock_int)); |
|
200 } |
|
201 |
|
202 bufPtr.AppendFill(0, header.pfqos_configure_len * 8 - byte_len); |
|
203 return *iData; |
|
204 } |
|
205 |
|
206 EXPORT_C TInt CSblpPolicy::ParseMessage(const TDesC8& /*aData*/) |
|
207 { |
|
208 return KErrNone; |
|
209 } |
|
210 |
|
211 EXPORT_C CExtensionBase* CSblpPolicy::CreateL() |
|
212 { |
|
213 CSblpPolicy *extension = CSblpPolicy::NewL(); |
|
214 return extension; |
|
215 } |
|
216 |
|
217 EXPORT_C TInt CSblpPolicy::Copy(const CExtensionBase& aExtension) |
|
218 { |
|
219 if (aExtension.Type() != iType) |
|
220 return KErrArgument; |
|
221 const CSblpPolicy& policy = (CSblpPolicy&)aExtension; |
|
222 policy.GetSblpParameters(*iSblp); |
|
223 return KErrNone; |
|
224 } |
|
225 |
|
226 EXPORT_C void CSblpPolicy::SetSblpParameters(const CSblpParameters& aSblp) |
|
227 { |
|
228 |
|
229 *iSblp = aSblp; |
|
230 |
|
231 LOG( |
|
232 // following code is to create logs |
|
233 TAuthorizationToken authToken; |
|
234 iSblp->GetMAT (authToken); |
|
235 RArray<CSblpParameters::TFlowIdentifier> flowIds; |
|
236 iSblp->GetFlowIds(flowIds); |
|
237 TBuf<KAuthorizationTokenSize> label; |
|
238 label.Copy(authToken); |
|
239 |
|
240 Log::Printf(_L("<------------------------------------------------\n")); |
|
241 Log::Printf(_L("CSblpPolicy::SetSblpParameters")); |
|
242 Log::Printf(_L("\n")); |
|
243 Log::Printf(_L("SBLP VALUES SUPPLIED BY CLIENT IS \n")); |
|
244 Log::Printf(_L("\n")); |
|
245 Log::Printf(_L("[MAT string : = %S]\n"),&label); |
|
246 |
|
247 TInt i; |
|
248 for(i=0; i<flowIds.Count();i++) |
|
249 { |
|
250 Log::Printf(_L("Media component number : = %d]\n"),flowIds[i].iMediaComponentNumber); |
|
251 Log::Printf(_L("IP flow number : = %d]\n"),flowIds[i].iIPFlowNumber); |
|
252 } |
|
253 Log::Printf(_L("------------------------------------------------>\n")); |
|
254 flowIds.Close(); |
|
255 ) |
|
256 |
|
257 } |
|
258 |
|
259 EXPORT_C void CSblpPolicy::GetSblpParameters(CSblpParameters& aSblp) const |
|
260 { |
|
261 aSblp = *iSblp; |
|
262 } |