|
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 // |
|
15 |
|
16 |
|
17 #include <in_sock.h> |
|
18 |
|
19 #include "pfqos_stream.h" |
|
20 |
|
21 EXPORT_C CPfqosStream::CPfqosStream() : iSendBuf(0,0) |
|
22 { |
|
23 iBuf=NULL; |
|
24 } |
|
25 |
|
26 EXPORT_C void CPfqosStream::ConstructL(TUint aBufSize) |
|
27 { |
|
28 iBuf = HBufC8::NewL(aBufSize); |
|
29 TPtr8 tmp(iBuf->Des()); |
|
30 iSendBuf.Set(tmp); |
|
31 } |
|
32 |
|
33 EXPORT_C CPfqosStream* CPfqosStream::NewL(TUint aBufSize) |
|
34 { |
|
35 CPfqosStream* msg = new (ELeave) CPfqosStream(); |
|
36 CleanupStack::PushL(msg); |
|
37 msg->ConstructL(aBufSize); |
|
38 CleanupStack::Pop(); |
|
39 return msg; |
|
40 } |
|
41 |
|
42 EXPORT_C CPfqosStream::~CPfqosStream() |
|
43 { |
|
44 delete iBuf; |
|
45 } |
|
46 |
|
47 |
|
48 EXPORT_C void CPfqosStream::Init(TUint8 aMsgType, TUint32 aSeq) |
|
49 { |
|
50 struct pfqos_msg msg; |
|
51 msg.pfqos_msg_version = KPfqosMsgV1; |
|
52 msg.pfqos_msg_type = aMsgType; |
|
53 msg.pfqos_msg_errno = 0; |
|
54 msg.pfqos_msg_reserved = 0; |
|
55 msg.pfqos_msg_seq = aSeq; |
|
56 msg.pfqos_msg_pid = 0; |
|
57 // All policies added by QoS API are dynamic! |
|
58 msg.pfqos_msg_options = KPfqosOptionDynamic; |
|
59 |
|
60 iSendBuf.Zero(); |
|
61 iSendBuf.SetLength(0); |
|
62 iLength = msg.pfqos_msg_len = sizeof(struct pfqos_msg) / 8; |
|
63 iSendBuf.Copy((TUint8 *)&msg, sizeof(struct pfqos_msg)); |
|
64 } |
|
65 |
|
66 |
|
67 EXPORT_C void CPfqosStream::AddSelector(TUint8 aProtocol, |
|
68 const TUidType& aUid, TUint32 aPolicyType, TUint32 aIapId, |
|
69 TUint32 aPriority, const TDesC& aName) |
|
70 { |
|
71 struct pfqos_selector ext; |
|
72 const int byte_len = sizeof(struct pfqos_selector); |
|
73 ext.pfqos_selector_len = (byte_len + 7) / 8; |
|
74 ext.pfqos_ext_type = EPfqosExtSelector; |
|
75 ext.protocol = aProtocol; |
|
76 ext.uid1 = aUid[0].iUid; |
|
77 ext.uid2 = aUid[1].iUid; |
|
78 ext.uid3 = aUid[2].iUid; |
|
79 ext.iap_id = aIapId; |
|
80 ext.policy_type = aPolicyType; |
|
81 ext.priority = aPriority; |
|
82 ext.reserved = 0; |
|
83 |
|
84 TPtr8 namePtr((TUint8*)ext.name, 0, KMaxName); |
|
85 if (namePtr.MaxLength() >= aName.Length()) |
|
86 { |
|
87 namePtr.Copy(aName); |
|
88 } |
|
89 namePtr.ZeroTerminate(); |
|
90 |
|
91 iSendBuf.Append((TUint8*)&ext, sizeof(ext)); |
|
92 iSendBuf.AppendFill(0, ext.pfqos_selector_len * 8 - byte_len); |
|
93 iLength = (TUint16)(iLength + ext.pfqos_selector_len); |
|
94 } |
|
95 |
|
96 |
|
97 EXPORT_C void CPfqosStream::AddChannel(TUint32 aChannelId) |
|
98 { |
|
99 struct pfqos_channel ext; |
|
100 const int byte_len = sizeof(pfqos_channel); |
|
101 ext.pfqos_channel_len = (byte_len + 7) / 8; |
|
102 ext.pfqos_ext_type = EPfqosExtChannel; |
|
103 ext.channel_id = aChannelId; |
|
104 |
|
105 iSendBuf.Append((TUint8*)&ext, sizeof(ext)); |
|
106 iSendBuf.AppendFill(0, ext.pfqos_channel_len * 8 - byte_len); |
|
107 iLength = (TUint16)(iLength + ext.pfqos_channel_len); |
|
108 } |
|
109 |
|
110 |
|
111 EXPORT_C void CPfqosStream::AddConfigFile(const TDesC& aName) |
|
112 { |
|
113 struct pfqos_config_file ext; |
|
114 |
|
115 const int byte_len = sizeof(pfqos_config_file); |
|
116 ext.pfqos_config_file_len = (byte_len + 7) / 8; |
|
117 ext.pfqos_ext_type = EPfqosExtConfigFile; |
|
118 TPtr8 nameptr((TUint8*)ext.filename, 0, KMaxFileName); |
|
119 if (nameptr.MaxLength() >= aName.Length()) |
|
120 { |
|
121 nameptr.Copy(aName); |
|
122 } |
|
123 nameptr.ZeroTerminate(); |
|
124 ext.reserved = 0; |
|
125 |
|
126 iSendBuf.Append((TUint8*)&ext, sizeof(ext)); |
|
127 iSendBuf.AppendFill(0, ext.pfqos_config_file_len * 8 - byte_len); |
|
128 iLength = (TUint16)(iLength + ext.pfqos_config_file_len); |
|
129 } |
|
130 |
|
131 |
|
132 EXPORT_C void CPfqosStream::AddQoSParameters(const TQoSParameters& |
|
133 aParameters) |
|
134 { |
|
135 struct pfqos_flowspec ext; |
|
136 const int byte_len = sizeof(pfqos_flowspec); |
|
137 |
|
138 ext.pfqos_flowspec_len = (byte_len + 7) / 8; |
|
139 ext.pfqos_ext_type = EPfqosExtFlowspec; |
|
140 |
|
141 // Uplink parameters |
|
142 ext.uplink_bandwidth = aParameters.GetUplinkBandwidth(); |
|
143 ext.uplink_maximum_burst_size = aParameters.GetUpLinkMaximumBurstSize(); |
|
144 ext.uplink_maximum_packet_size = aParameters.GetUpLinkMaximumPacketSize(); |
|
145 ext.uplink_average_packet_size = aParameters.GetUpLinkAveragePacketSize(); |
|
146 ext.uplink_delay = aParameters.GetUpLinkDelay(); |
|
147 ext.uplink_priority = static_cast< TUint16 >( |
|
148 aParameters.GetUpLinkPriority()); |
|
149 |
|
150 // Downlink parameters |
|
151 ext.downlink_bandwidth = aParameters.GetDownlinkBandwidth(); |
|
152 ext.downlink_maximum_burst_size = |
|
153 aParameters.GetDownLinkMaximumBurstSize(); |
|
154 ext.downlink_maximum_packet_size = |
|
155 aParameters.GetDownLinkMaximumPacketSize(); |
|
156 ext.downlink_average_packet_size = |
|
157 aParameters.GetDownLinkAveragePacketSize(); |
|
158 ext.downlink_delay = aParameters.GetDownLinkDelay(); |
|
159 ext.downlink_priority = static_cast< TUint16 >( |
|
160 aParameters.GetDownLinkPriority()); |
|
161 |
|
162 ext.flags = aParameters.Flags(); |
|
163 ext.reserved = 0; |
|
164 |
|
165 // name |
|
166 ext.name.Copy(aParameters.GetName()); |
|
167 |
|
168 iSendBuf.Append((TUint8*)&ext, sizeof(ext)); |
|
169 iSendBuf.AppendFill(0, ext.pfqos_flowspec_len * 8 - byte_len); |
|
170 iLength = (TUint16)(iLength + ext.pfqos_flowspec_len); |
|
171 } |
|
172 |
|
173 |
|
174 EXPORT_C void CPfqosStream::AddModulespec(TUint32 aProtocolId, TUint32 aFlags, |
|
175 const TDesC& aModuleName, const TDesC& aFileName, |
|
176 const TDesC8& aConfigData) |
|
177 { |
|
178 struct pfqos_modulespec ext; |
|
179 const int byte_len = sizeof(pfqos_modulespec)+aConfigData.Length(); |
|
180 |
|
181 ext.pfqos_modulespec_len = (TUint16)((byte_len + 7) / 8); |
|
182 ext.pfqos_ext_type = EPfqosExtModulespec; |
|
183 ext.protocol_id = aProtocolId; |
|
184 ext.flags = aFlags; |
|
185 ext.reserved = 0; |
|
186 TPtr8 namePtr((TUint8*)ext.name, 0, KMaxName); |
|
187 if (namePtr.MaxLength() >= aModuleName.Length()) |
|
188 { |
|
189 namePtr.Copy(aModuleName); |
|
190 } |
|
191 |
|
192 namePtr.ZeroTerminate(); |
|
193 TPtr8 fileNamePtr((TUint8*)ext.path, 0, KMaxFileName); |
|
194 if (fileNamePtr.MaxLength() >= aFileName.Length()) |
|
195 { |
|
196 fileNamePtr.Copy(aFileName); |
|
197 } |
|
198 fileNamePtr.ZeroTerminate(); |
|
199 |
|
200 iSendBuf.Append((TUint8*)&ext, sizeof(ext)); |
|
201 iSendBuf.AppendFill(0, ext.pfqos_modulespec_len * 8 - byte_len); |
|
202 iSendBuf.Append(aConfigData); |
|
203 |
|
204 iLength = (TUint16)(iLength + ext.pfqos_modulespec_len); |
|
205 } |
|
206 |
|
207 |
|
208 EXPORT_C void CPfqosStream::AddExtensionPolicy(TDesC8 &aData) |
|
209 { |
|
210 TInt len = (aData.Length() + 7) / 8; |
|
211 |
|
212 iSendBuf.Append(aData); |
|
213 iLength = (TUint16)(iLength + len); |
|
214 } |
|
215 |
|
216 |
|
217 EXPORT_C void CPfqosStream::AddExtensionHeader(TUint16 aExtension) |
|
218 { |
|
219 struct pfqos_configure header; |
|
220 struct pfqos_extension extension; |
|
221 const int byte_len = sizeof(pfqos_extension) + sizeof(pfqos_configure); |
|
222 |
|
223 header.pfqos_configure_len = (byte_len + 7) / 8; |
|
224 header.pfqos_ext_type = EPfqosExtExtension; |
|
225 header.protocol_id = 0; |
|
226 header.reserved = 0; |
|
227 extension.pfqos_ext_len = (byte_len + 7) / 8; |
|
228 extension.pfqos_ext_type = EPfqosExtExtension; |
|
229 extension.pfqos_extension_type = aExtension; |
|
230 |
|
231 iSendBuf.Append((TUint8*)&header, sizeof(header)); |
|
232 iSendBuf.Append((TUint8*)&extension, sizeof(extension)); |
|
233 iSendBuf.AppendFill(0, header.pfqos_configure_len * 8 - byte_len); |
|
234 iLength = (TUint16)(iLength + header.pfqos_configure_len); |
|
235 } |
|
236 |
|
237 |
|
238 EXPORT_C void CPfqosStream::AddSrcAddress(const TInetAddr &anAddr, |
|
239 const TInetAddr &aMask, TUint16 aPortMax) |
|
240 { |
|
241 AddAddress(anAddr, aMask, EPfqosExtSrcAddress, aPortMax); |
|
242 _LIT(KText1, "ADDRESS_SRC"); |
|
243 __ASSERT_ALWAYS(iLength * 8 == iSendBuf.Length(), User::Panic(KText1, 0)); |
|
244 } |
|
245 |
|
246 |
|
247 EXPORT_C void CPfqosStream::AddDstAddress(const TInetAddr &anAddr, |
|
248 const TInetAddr &aMask, TUint16 aPortMax) |
|
249 { |
|
250 AddAddress(anAddr, aMask, EPfqosExtDstAddress, aPortMax); |
|
251 _LIT(KText2, "ADDRESS_SRC"); |
|
252 __ASSERT_ALWAYS(iLength * 8 == iSendBuf.Length(), User::Panic(KText2, 0)); |
|
253 } |
|
254 |
|
255 |
|
256 EXPORT_C TInt CPfqosStream::Send(RSocket &aSocket) |
|
257 { |
|
258 TRequestStatus status; |
|
259 TPtrC8 len = TPtrC8((TUint8 *)&iLength, sizeof(iLength)); |
|
260 iSendBuf.Replace(_FOFF(struct pfqos_msg, pfqos_msg_len), |
|
261 sizeof(((struct pfqos_msg *)0)->pfqos_msg_len), len); |
|
262 aSocket.Write(iSendBuf, status); |
|
263 User::WaitForRequest(status); |
|
264 return status.Int(); |
|
265 } |
|
266 |
|
267 |
|
268 EXPORT_C void CPfqosStream::Send(RSocket &aSocket, TRequestStatus& aStatus) |
|
269 { |
|
270 TPtrC8 len = TPtrC8((TUint8 *)&iLength, sizeof(iLength)); |
|
271 iSendBuf.Replace(_FOFF(struct pfqos_msg, pfqos_msg_len), |
|
272 sizeof(((struct pfqos_msg *)0)->pfqos_msg_len), len); |
|
273 aSocket.Write(iSendBuf, aStatus); |
|
274 } |
|
275 |
|
276 |
|
277 |
|
278 EXPORT_C TInt CPfqosStream::Send(RInternalSocket &aSocket) |
|
279 { |
|
280 TRequestStatus status; |
|
281 TPtrC8 len = TPtrC8((TUint8 *)&iLength, sizeof(iLength)); |
|
282 iSendBuf.Replace(_FOFF(struct pfqos_msg, pfqos_msg_len), |
|
283 sizeof(((struct pfqos_msg *)0)->pfqos_msg_len), len); |
|
284 aSocket.Write(iSendBuf, status); |
|
285 User::WaitForRequest(status); |
|
286 return status.Int(); |
|
287 } |
|
288 |
|
289 |
|
290 EXPORT_C void CPfqosStream::Send(RInternalSocket &aSocket, TRequestStatus& |
|
291 aStatus) |
|
292 { |
|
293 TPtrC8 len = TPtrC8((TUint8 *)&iLength, sizeof(iLength)); |
|
294 iSendBuf.Replace(_FOFF(struct pfqos_msg, pfqos_msg_len), |
|
295 sizeof(((struct pfqos_msg *)0)->pfqos_msg_len), len); |
|
296 aSocket.Write(iSendBuf, aStatus); |
|
297 } |
|
298 |
|
299 |
|
300 |
|
301 EXPORT_C void CPfqosStream::AddAddress(const TInetAddr &anAddr, |
|
302 const TInetAddr &aMask, TUint8 aType, TUint16 aPortMax) |
|
303 { |
|
304 struct pfqos_address address; |
|
305 const int byte_len = sizeof(struct pfqos_address) + sizeof(TInetAddr) + |
|
306 sizeof(TInetAddr); |
|
307 |
|
308 address.pfqos_address_len = (byte_len + 7) / 8; |
|
309 address.pfqos_ext_type = aType; |
|
310 address.reserved = 0; |
|
311 address.pfqos_port_max = aPortMax; |
|
312 iSendBuf.Append((TUint8*)&address, sizeof(address)); |
|
313 iSendBuf.Append((TUint8*)&anAddr, sizeof(TInetAddr)); |
|
314 iSendBuf.Append((TUint8*)&aMask, sizeof(TInetAddr)); |
|
315 iSendBuf.AppendFill(0, address.pfqos_address_len * 8 - byte_len); |
|
316 |
|
317 iLength = (TUint16)(iLength + address.pfqos_address_len); |
|
318 } |
|
319 |
|
320 |