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 // Implements the adding and removal of tag headers. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
23 |
|
24 #include "IPTagHeader.h" |
|
25 #include "Constants.h" |
|
26 |
|
27 /** |
|
28 Default constructor. |
|
29 */ |
|
30 CIPTagHeader::CIPTagHeader(CBttLogger* aTheLogger) |
|
31 : iTheLogger(aTheLogger) |
|
32 { |
|
33 iHeaderByte.SetMax(); |
|
34 iHeaderByte.FillZ(); |
|
35 } |
|
36 |
|
37 /** |
|
38 Default destructor. |
|
39 */ |
|
40 CIPTagHeader::~CIPTagHeader() |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 This method will set the type of the IP header. |
|
46 |
|
47 @param aType IP header type |
|
48 */ |
|
49 void CIPTagHeader::SetType(TUint16 aType) |
|
50 { |
|
51 _LOG_L1C1(_L8("CIPTagHeader::SetType")); |
|
52 |
|
53 iHeaderByte[0] = (TUint8)(aType>>8); |
|
54 iHeaderByte[1] = (TUint8)(aType&0xff); |
|
55 } |
|
56 |
|
57 /** |
|
58 This method will add a two-byte header to the send buffer detailing the |
|
59 protocol the aDes data packet is encoded with; in this case an IPv4 |
|
60 header tag is appended. |
|
61 |
|
62 @param aDes the send buffer |
|
63 */ |
|
64 void CIPTagHeader::AddHeader(TDes8& aDes) |
|
65 { |
|
66 _LOG_L1C1(_L8("CIPTagHeader::AddHeader")); |
|
67 |
|
68 // Add the protocol code as a header to the buffer |
|
69 aDes.Insert(0,iHeaderByte); |
|
70 } |
|
71 |
|
72 /** |
|
73 This method will remove the two-byte header from the received data, |
|
74 which specifies whether it is an IPv4/IPv6 packet. This information |
|
75 will be stored in protocolCode and returned to the caller. |
|
76 |
|
77 @param aPdu The received data packet |
|
78 @return The protocol header tag stripped from aPdu |
|
79 */ |
|
80 TUint16 CIPTagHeader::RemoveHeader(RMBufChain& aPdu) |
|
81 { |
|
82 _LOG_L1C1(_L8("CIPTagHeader::RemoveHeader")); |
|
83 |
|
84 if (aPdu.Length() > KIPTagHeaderLength) |
|
85 { |
|
86 //Strip off the first part of the header |
|
87 aPdu.TrimStart(1); |
|
88 //Read the remaining part of the header as this contains the protocol code |
|
89 TUint8* payloadPtr = aPdu.First()->Ptr(); |
|
90 TUint16 protocolCode = static_cast<TUint16>(*payloadPtr); |
|
91 //Strip off the remaining protocol code part of the header |
|
92 |
|
93 aPdu.TrimStart(1); |
|
94 |
|
95 return protocolCode; |
|
96 } |
|
97 |
|
98 return 0; |
|
99 } |
|
100 |
|
101 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|