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 * |
|
16 */ |
|
17 /** |
|
18 @file |
|
19 @internalComponent |
|
20 */ |
|
21 #ifndef NCMNTBPARSER_H |
|
22 #define NCMNTBPARSER_H |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 //DEBUG MACRO to dump the parsed NDP info. |
|
27 //#define DEBUG_DUMP_NTBINNER |
|
28 #ifdef DEBUG_DUMP_NTBINNER |
|
29 #include <e32debug.h> |
|
30 #endif |
|
31 |
|
32 #ifndef __OVER_DUMMYUSBSCLDD__ |
|
33 #include <nifmbuf.h> |
|
34 #else |
|
35 #include <usb/testncm/pktdrv.h> |
|
36 #endif |
|
37 |
|
38 #include "ncmpktdrvcommon.h" |
|
39 |
|
40 /** |
|
41 * interface for parsed NDP(ethernet frame). |
|
42 */ |
|
43 NONSHARABLE_CLASS(MNcmNdpFrameObserver) |
|
44 { |
|
45 public: |
|
46 virtual void ProcessEtherFrame(RMBufPacket&) = 0; |
|
47 virtual void ExpireBuffer(TAny*) = 0; |
|
48 }; |
|
49 |
|
50 #ifdef DEBUG_DUMP_NTBINNER |
|
51 class NTHNDPDumper : public MNcmNdpFrameObserver |
|
52 { |
|
53 public: |
|
54 inline void ProcessEtherFrame(RMBufPacket& aPacket) |
|
55 { |
|
56 RDebug::Printf("NTHNDPDumper::parsed Ethernet Frame, length=%d", aPacket.Length()); |
|
57 aPacket.Free(); |
|
58 } |
|
59 inline void ExpireBuffer(TAny* aBuf) |
|
60 { |
|
61 } |
|
62 inline void FatalError(TInt aErrCode) |
|
63 { |
|
64 RDebug::Printf("NTHNDPDumper::Fatal Error=%d", aErrCode); |
|
65 } |
|
66 }; |
|
67 #endif //DEBUG_DUMP_NTBINNER |
|
68 |
|
69 /** |
|
70 * NCM NTH for NTB16 |
|
71 */ |
|
72 NONSHARABLE_CLASS(TNcmNth16) |
|
73 { |
|
74 public: |
|
75 TUint8 dwSignature[4]; |
|
76 TUint16 wHeaderLength; |
|
77 TUint16 wSequence; |
|
78 TUint16 wBlockLength; |
|
79 TUint16 wNdpIndex; |
|
80 |
|
81 public: |
|
82 inline void Dump(); |
|
83 }; |
|
84 |
|
85 /** |
|
86 * NCM NDP 16 |
|
87 */ |
|
88 NONSHARABLE_CLASS(TNcmNdp16) |
|
89 { |
|
90 public: |
|
91 TUint8 dwSignature[4]; |
|
92 TUint16 wLength; |
|
93 TUint16 wNextNdpIndex; |
|
94 TUint16 wDatagram0Index; |
|
95 TUint16 wDatagram0Length; |
|
96 TUint16 wDatagram1Index; |
|
97 TUint16 wDatagram1Length; |
|
98 |
|
99 public: |
|
100 inline void Dump(); |
|
101 }; |
|
102 |
|
103 /** |
|
104 * NCM packet parser |
|
105 * NOTE:the buffer to be parsed was not guaranteed as a whole USB transfer. |
|
106 * So, a internal state is used to remember previous parsed result. |
|
107 */ |
|
108 NONSHARABLE_CLASS(CNcmNtbParser) : public CBase |
|
109 { |
|
110 public: |
|
111 virtual TInt Parse(const TUint8* aBuf, TInt aBufLen, TBool aZlp = EFalse) = 0; |
|
112 virtual void Reset(TInt aResetType=0) = 0; |
|
113 virtual TUint NtbOutMaxSize() const = 0; |
|
114 virtual ~CNcmNtbParser(); |
|
115 |
|
116 protected: |
|
117 inline CNcmNtbParser(MNcmNdpFrameObserver&); |
|
118 |
|
119 MNcmNdpFrameObserver& iObserver; |
|
120 }; |
|
121 |
|
122 /** |
|
123 * NCM NTB 16 parser |
|
124 */ |
|
125 NONSHARABLE_CLASS(CNcmNtb16Parser): public CNcmNtbParser |
|
126 { |
|
127 public: |
|
128 //From CNcmNtbParser |
|
129 TInt Parse(const TUint8* aBuf, TInt aBufLen, TBool aZlp = EFalse); |
|
130 TUint NtbOutMaxSize() const; |
|
131 void Reset(TInt aType = 0); |
|
132 |
|
133 virtual ~CNcmNtb16Parser(); |
|
134 |
|
135 static CNcmNtb16Parser* NewL(MNcmNdpFrameObserver&); |
|
136 |
|
137 private: |
|
138 inline CNcmNtb16Parser(MNcmNdpFrameObserver&); |
|
139 //parse NTH |
|
140 TInt ParseNcmNtb16Header(const TUint8* aBuf, TInt aBufLen, TBool aZlp); |
|
141 //parse NDP |
|
142 TInt ParseNcmNtb16Ndp(const TUint8* aBuf, TInt aBufLen); |
|
143 //parse NdpDatagram |
|
144 TInt ParseNcmNtb16NdpDatagram(const TUint8* aBuf, TInt aBufLen); |
|
145 //queue buffer. |
|
146 TInt QueueBuf(const TUint8* aBuf, TInt aBufLen); |
|
147 TUint8 DataTUint8(TUint aOffset, const TUint8* aBuf, TInt aBufLen); |
|
148 TUint16 DataTUint16(TUint aOffset, const TUint8* aBuf, TInt aBufLen); |
|
149 TInt DataPacket(const TUint8* aBuf, TInt aBufLen); |
|
150 //search NCMH in the stream if the NTH header signature is wrong. |
|
151 TInt SearchNcmHead(const TUint8* aBuf, TInt aBufLen); |
|
152 |
|
153 |
|
154 enum TNcmNtb16ResetType |
|
155 { |
|
156 ENcmNtb16TypeResetAll = 0, |
|
157 ENcmNtb16TypeResetQueue = 1, |
|
158 ENcmNtb16TypeResetData = 2 |
|
159 }; |
|
160 |
|
161 enum TNcmNtb16ParseState |
|
162 { |
|
163 //initial state, NTH is not ready. |
|
164 ENcmNtb16ParseStateUninitialized = 0, |
|
165 //NTH is ready, NDP is not ready. |
|
166 ENcmNtb16ParseStateNdpParsing, |
|
167 //NDP is ready, NdpDatagram is not finished. |
|
168 ENcmNtb16ParseStateNdpSeeking, |
|
169 //Error state or NULL NDP, ignore coming bytes until this NTB end. |
|
170 ENcmNtb16ParseStateSkipBytes |
|
171 }; |
|
172 |
|
173 enum TNcmNtb16ParseNdpState |
|
174 { |
|
175 ENcmNtb16ParseNdpStateUninitialized = 0, |
|
176 ENcmNtb16ParseNdpStateDatagramed |
|
177 }; |
|
178 |
|
179 private: |
|
180 TNcmNth16 iNth; |
|
181 TNcmNdp16 iNdp; |
|
182 |
|
183 TNcmNtb16ParseState iState; |
|
184 |
|
185 TUint iDataLen; //NTB data length. |
|
186 TUint iQueLen; //Queue length. |
|
187 TUint iDataOffset; //start offset in first buffer in queue. |
|
188 RArray<TPtrC8> iBufQueue; |
|
189 |
|
190 TNcmNtb16ParseNdpState iNdpState; |
|
191 TUint iNdpDataOffset; |
|
192 TUint iNdpBound; |
|
193 TUint16 iDatagramIndex; |
|
194 TUint16 iDatagramLength; |
|
195 |
|
196 RMBufPacket iPacket; |
|
197 |
|
198 #ifdef _DEBUG |
|
199 //error statistics |
|
200 TUint16 iPrevSeq; |
|
201 TUint iTotalSeq; |
|
202 #endif |
|
203 |
|
204 TUint16 iMaxSize; |
|
205 }; |
|
206 |
|
207 // inline functions |
|
208 #include "ncmntbparser.inl" |
|
209 |
|
210 #endif /* NCMNTBPARSER_H_ */ |
|