28
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* implementation for NTB16 build class
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
/**
|
|
22 |
@file
|
|
23 |
@internalComponent
|
|
24 |
*/
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
#include <es_sock.h>
|
|
29 |
#ifndef __OVER_DUMMYUSBSCLDD__
|
|
30 |
#include <nifmbuf.h>
|
|
31 |
#else
|
|
32 |
#include <usb/testncm/ethinter.h>
|
|
33 |
#endif
|
|
34 |
#include "ncmntb16builder.h"
|
|
35 |
#include "ncmntbbuildpolicy.h"
|
|
36 |
#include "ncmpktdrvcommon.h"
|
|
37 |
#include "OstTraceDefinitions.h"
|
|
38 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
39 |
#include "ncmntb16builderTraces.h"
|
|
40 |
#endif
|
|
41 |
|
|
42 |
|
|
43 |
const TInt KNtb16InMaxSize = 32768;
|
|
44 |
|
|
45 |
|
|
46 |
const TInt KNth16Signature = 0x484D434E;
|
|
47 |
const TInt KNth16Length = 0x0C;
|
|
48 |
|
|
49 |
const TInt KNdp16Signature = 0x304D434E;
|
|
50 |
const TInt KNdp16HeaderSize = 8;
|
|
51 |
const TInt KNdp16EntrySize = 4;
|
|
52 |
const TInt KNdp16InDivisor = 4;
|
|
53 |
const TInt KNdp16InRemainder = 0;
|
|
54 |
const TInt KNdp16InAlignment = 4;
|
|
55 |
|
|
56 |
|
|
57 |
// ======== MEMBER FUNCTIONS ========
|
|
58 |
//
|
|
59 |
|
|
60 |
|
|
61 |
CNcmNtbBuilder* CNcmNtb16Builder::NewL(MNcmNtbBuildObserver& aObserver)
|
|
62 |
{
|
|
63 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_NEWL_ENTRY, ( TUint )&( aObserver ) );
|
|
64 |
CNcmNtb16Builder *self=new (ELeave) CNcmNtb16Builder(aObserver);
|
59
|
65 |
|
|
66 |
CleanupStack::PushL(self);
|
28
|
67 |
self->ConstructL();
|
59
|
68 |
CleanupStack::Pop(self);
|
|
69 |
|
28
|
70 |
OstTraceFunctionExit0( CNCMNTB16BUILDER_NEWL_EXIT );
|
|
71 |
return self;
|
|
72 |
}
|
|
73 |
|
|
74 |
CNcmNtb16Builder::CNcmNtb16Builder(MNcmNtbBuildObserver& aObserver)
|
|
75 |
: CNcmNtbBuilder(aObserver)
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
void CNcmNtb16Builder::ConstructL()
|
|
80 |
{
|
59
|
81 |
iNtbInMaxSize = KNtb16InMaxSize;
|
28
|
82 |
iNdpInDivisor = KNdp16InDivisor;
|
|
83 |
iNdpInPayloadRemainder = KNdp16InRemainder;
|
|
84 |
iNdpInAlignment = KNdp16InAlignment;
|
|
85 |
}
|
|
86 |
|
|
87 |
CNcmNtb16Builder::~CNcmNtb16Builder()
|
|
88 |
{
|
|
89 |
iPacketsArray.Reset();
|
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
TInt CNcmNtb16Builder::SetNtbInMaxSize(TInt aSize)
|
|
94 |
{
|
|
95 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_SETNTBINMAXSIZE_ENTRY, this );
|
|
96 |
if (aSize > KNtb16InMaxSize || aSize < MinNtbInMaxSize())
|
|
97 |
{
|
|
98 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_SETNTBINMAXSIZE_EXIT, this );
|
|
99 |
return KErrArgument;
|
|
100 |
}
|
|
101 |
iNtbInMaxSize = aSize;
|
|
102 |
OstTraceFunctionExit1( CNCMNTB_DUP116BUILDER_SETNTBINMAXSIZE_EXIT, this );
|
|
103 |
return KErrNone;
|
|
104 |
}
|
|
105 |
|
|
106 |
//
|
|
107 |
//construct NTB header information
|
|
108 |
//
|
|
109 |
|
|
110 |
void CNcmNtb16Builder::BuildNtbHeader()
|
|
111 |
{
|
|
112 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_BUILDNTBHEADER_ENTRY, this );
|
|
113 |
TPtr8 buf(iBuffer.iPtr, KNth16Length, KNth16Length);
|
|
114 |
TInt pos = 0;
|
|
115 |
LittleEndian::Put32(&buf[pos], KNth16Signature);
|
|
116 |
pos += 4;
|
|
117 |
LittleEndian::Put16(&buf[pos], KNth16Length);
|
|
118 |
pos += 2;
|
|
119 |
LittleEndian::Put16(&buf[pos], iSequence);
|
|
120 |
pos += 2;
|
|
121 |
LittleEndian::Put32(&buf[pos], iNdpOffset+iNdpLength);
|
|
122 |
pos += 2;
|
|
123 |
LittleEndian::Put16(&buf[pos], iNdpOffset);
|
|
124 |
pos += 2;
|
|
125 |
|
|
126 |
OstTraceExt3( TRACE_NORMAL, CNCMNTB16BUILDER_BUILDNTBHEADER, "CNcmNtb16Builder::BuildNtbHeader %d %d %d", iSequence, iNdpOffset, iNdpOffset+iNdpLength );
|
|
127 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_BUILDNTBHEADER_EXIT, this );
|
|
128 |
}
|
|
129 |
|
|
130 |
|
|
131 |
//
|
|
132 |
//construct NDP inforamtion
|
|
133 |
//
|
|
134 |
|
|
135 |
void CNcmNtb16Builder::BuildNdp()
|
|
136 |
{
|
|
137 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_BUILDNDP_ENTRY, this );
|
|
138 |
TPtr8 buf(iBuffer.iPtr+iNdpOffset, iNdpLength, iNdpLength);
|
|
139 |
TInt pos = 0;
|
|
140 |
|
|
141 |
LittleEndian::Put32(&buf[pos], KNdp16Signature);
|
|
142 |
pos += 4;
|
|
143 |
LittleEndian::Put16(&buf[pos], iNdpLength);
|
|
144 |
pos += 2;
|
|
145 |
LittleEndian::Put16(&buf[pos], 0);
|
|
146 |
pos += 2;
|
|
147 |
|
|
148 |
TInt i;
|
|
149 |
for (i=0 ; i<iPacketsArray.Count() ; i++)
|
|
150 |
{
|
|
151 |
LittleEndian::Put16(&buf[pos], iPacketsArray[i].iWDatagramIndex);
|
|
152 |
pos += 2;
|
|
153 |
LittleEndian::Put16(&buf[pos], iPacketsArray[i].iWDatagramLength);
|
|
154 |
pos += 2;
|
|
155 |
}
|
|
156 |
LittleEndian::Put16(&buf[pos], 0);
|
|
157 |
pos += 2;
|
|
158 |
LittleEndian::Put16(&buf[pos], 0);
|
|
159 |
pos += 2;
|
|
160 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_BUILDNDP_EXIT, this );
|
|
161 |
}
|
|
162 |
|
|
163 |
|
|
164 |
//
|
|
165 |
//Append a datagram to NTB
|
|
166 |
//
|
|
167 |
|
|
168 |
TInt CNcmNtb16Builder::AppendPacket(const RMBufChain& aPacket)
|
|
169 |
{
|
|
170 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_APPENDPACKET_ENTRY, this );
|
|
171 |
// datagram must align with iNdpInDivisor and remainder is iNdpInPayloadRemainder, refer to NCM spec 3.34 for detail
|
|
172 |
TInt len = aPacket.Length();
|
|
173 |
TInt alignedDataOffset;
|
|
174 |
int remainder = iDatagramOffset%iNdpInDivisor;
|
|
175 |
if (iNdpInPayloadRemainder < remainder)
|
|
176 |
{
|
|
177 |
alignedDataOffset = iDatagramOffset + iNdpInDivisor - remainder + iNdpInPayloadRemainder;
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
alignedDataOffset = iDatagramOffset + (iNdpInPayloadRemainder-remainder);
|
|
182 |
}
|
|
183 |
TInt newDatagramOffset = alignedDataOffset+len;
|
|
184 |
// NDP must align with iNdpInAlignment, refer to NCM spec Table 6-3 for detail
|
|
185 |
TInt newNdpOffset = (newDatagramOffset+iNdpInAlignment-1)&~(iNdpInAlignment-1);
|
|
186 |
|
|
187 |
// must have a zero entry in the end of NDP, so the NDP length is added with KNdp16EntrySize
|
|
188 |
TInt newNdpLen = iNdpLength + KNdp16EntrySize;
|
|
189 |
|
|
190 |
// iBuffer.iMaxLength and iNtbInMaxSize may not same.
|
|
191 |
if (newNdpLen+newNdpOffset > iBuffer.iMaxLength || newNdpLen+newNdpOffset > iNtbInMaxSize)
|
|
192 |
{
|
|
193 |
CompleteNtbBuild();
|
|
194 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_APPENDPACKET_EXIT, this );
|
|
195 |
return KErrBufferFull;
|
|
196 |
}
|
|
197 |
|
|
198 |
TPtr8 ptr((TUint8*)(alignedDataOffset+iBuffer.iPtr), len, len);
|
|
199 |
aPacket.CopyOut(ptr);
|
|
200 |
TDatagramEntry entry;
|
|
201 |
entry.iWDatagramIndex = alignedDataOffset;
|
|
202 |
entry.iWDatagramLength = len;
|
|
203 |
iPacketsArray.Append(entry);
|
|
204 |
iNdpOffset = newNdpOffset;
|
|
205 |
iNdpLength = newNdpLen;
|
|
206 |
iDatagramOffset = newDatagramOffset;
|
|
207 |
if (iBuildPolicy)
|
|
208 |
{
|
|
209 |
iBuildPolicy->UpdateNtb(iNdpOffset+iNdpLength);
|
|
210 |
}
|
|
211 |
OstTraceFunctionExit1( CNCMNTB_DUP116BUILDER_APPENDPACKET_EXIT, this );
|
|
212 |
return KErrNone;
|
|
213 |
}
|
|
214 |
|
|
215 |
//
|
|
216 |
//complete a NTB, is called by buildpolicy or current NTB is full.
|
|
217 |
//
|
|
218 |
|
|
219 |
|
|
220 |
void CNcmNtb16Builder::CompleteNtbBuild()
|
|
221 |
{
|
|
222 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_COMPLETENTBBUILD_ENTRY, this );
|
|
223 |
|
|
224 |
BuildNtbHeader();
|
|
225 |
BuildNdp();
|
|
226 |
iBuffer.iLen = iNdpOffset+iNdpLength;
|
|
227 |
SendNtbPayload();
|
|
228 |
CNcmNtbBuilder::CompleteNtbBuild();
|
|
229 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_COMPLETENTBBUILD_EXIT, this );
|
|
230 |
}
|
|
231 |
|
|
232 |
|
|
233 |
//
|
|
234 |
//start a new ntb, is called by sender
|
|
235 |
//
|
|
236 |
|
|
237 |
void CNcmNtb16Builder::StartNewNtb(const TNcmBuffer& aBuffer)
|
|
238 |
{
|
|
239 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_STARTNEWNTB_ENTRY, this );
|
|
240 |
|
|
241 |
iBuffer = aBuffer;
|
|
242 |
iNdpOffset = 0;
|
|
243 |
iNdpLength = 0;
|
|
244 |
iPacketsArray.Reset();
|
|
245 |
iDatagramOffset = KNth16Length;
|
|
246 |
// NDP must align with iNdpInAlignment, refer to NCM spec Table 6-3 for detail
|
|
247 |
iNdpOffset = (iDatagramOffset+iNdpInAlignment-1)&~(iNdpInAlignment-1);
|
|
248 |
// must have a zero entry in the end of NDP, so the NDP length is added with KNdp16EntrySize
|
|
249 |
iNdpLength = KNdp16HeaderSize + KNdp16EntrySize;
|
|
250 |
|
|
251 |
if (iBuildPolicy)
|
|
252 |
{
|
|
253 |
iBuildPolicy->StartNewNtb();
|
|
254 |
}
|
|
255 |
CNcmNtbBuilder::StartNewNtb(aBuffer);
|
|
256 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_STARTNEWNTB_EXIT, this );
|
|
257 |
}
|
|
258 |
|
|
259 |
|
|
260 |
void CNcmNtb16Builder::Reset()
|
|
261 |
{
|
|
262 |
OstTraceFunctionEntry1( CNCMNTB16BUILDER_RESET_ENTRY, this );
|
|
263 |
iNtbInMaxSize = KNtb16InMaxSize;
|
|
264 |
iNdpOffset = 0;
|
|
265 |
iNdpLength = 0;
|
|
266 |
iDatagramOffset = 0;
|
|
267 |
iPacketsArray.Reset();
|
|
268 |
CNcmNtbBuilder::Reset();
|
|
269 |
OstTraceFunctionExit1( CNCMNTB16BUILDER_RESET_EXIT, this );
|
|
270 |
}
|
|
271 |
|
|
272 |
|
|
273 |
|