|
1 // Copyright (c) 1997-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 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #if !defined(__ProtocolHeaders_H__) |
|
22 #define __ProtocolHeaders_H__ |
|
23 |
|
24 #define DotToIp(a,b,c,d) (((a)<<24) | ((b)<<16) | ((c)<<8) | (d)) |
|
25 |
|
26 const TUint KUDPHeaderSize = 8; |
|
27 const TUint KIPMinHeaderSize = 20; |
|
28 const TUint KIPDefaultTOS = 0; |
|
29 const TInt KIPDefaultTTL = 255; |
|
30 const TUint KIPVersion = 4; |
|
31 |
|
32 struct TGenericHeader |
|
33 { |
|
34 }; |
|
35 |
|
36 /** |
|
37 IP message header |
|
38 */ |
|
39 struct TIpHdr |
|
40 { |
|
41 public: |
|
42 //inline TUint32 DestAddr() const {return(BigEndian::Get32(iDestAddr.Begin()));}; |
|
43 //inline TUint32 SrcAddr() const {return(BigEndian::Get32(iSrcAddr.Begin()));}; |
|
44 //inline TUint16 FragOffset() const {return(BigEndian::Get16(iFragOffset.Begin()));}; |
|
45 /** Bits 7..4 of iVersion */ |
|
46 inline TUint Version() const {return (iVersion>>4); }; |
|
47 inline void SetVersion(TUint aVal) { iVersion = (TUint8)((iVersion&0xf)|((aVal&0xf)<<4)); }; |
|
48 /** Bits 3..0 of iVersion */ |
|
49 inline TUint HdrLen() const { return (iVersion&0xf)<<2; }; |
|
50 inline void SetHdrLen(TUint aVal) { iVersion = |
|
51 (TUint8)((iVersion&0xf0)|((TUint8)(aVal>>2)&0xf)); }; |
|
52 inline TUint TOS() { return iTOS; }; |
|
53 inline void SetTOS(TUint aVal) { iTOS = (TUint8)(aVal&0xff); }; |
|
54 inline TUint16 Length() { return BigEndian::Get16((TUint8*)&iLength); }; |
|
55 inline void SetLength(TUint16 aVal) { BigEndian::Put16((TUint8*)&iLength,aVal); }; |
|
56 inline TUint16 Ident() { return BigEndian::Get16((TUint8*)&iIdent); }; |
|
57 inline void SetIdent(TUint16 aVal) { BigEndian::Put16((TUint8*)&iIdent,aVal); }; |
|
58 inline TUint8 TTL() { return iTTL; }; |
|
59 inline void SetTTL(TUint aVal) { iTTL = (TUint8)(aVal&0xff); }; |
|
60 inline TUint8 Protocol() { return iProtocol; }; |
|
61 inline void SetProtocol(TUint aVal) { iProtocol = (TUint8)(aVal&0xff); }; |
|
62 inline TUint16 Checksum() { return BigEndian::Get16((TUint8*)&iChecksum); }; |
|
63 inline void SetChecksum(TUint16 aVal) { BigEndian::Put16((TUint8*)&iChecksum,aVal); }; |
|
64 inline TUint32 DestAddr() const {return(BigEndian::Get32(iDestAddr));}; |
|
65 inline TUint32 SrcAddr() const {return(BigEndian::Get32(iSrcAddr));}; |
|
66 inline TUint16 FragOffset() const {return BigEndian::Get16(iFragOffset);}; |
|
67 inline void SetDestAddr(TUint32 aVal) const { BigEndian::Put32((TUint8*)(&iDestAddr),aVal);}; |
|
68 inline void SetSrcAddr(TUint32 aVal) const { BigEndian::Put32((TUint8*)(&iSrcAddr),aVal);}; |
|
69 inline void SetFragOffset(TUint16 aVal) const {BigEndian::Put16((TUint8*)(&iFragOffset),aVal);}; |
|
70 protected: |
|
71 TUint8 iVersion; |
|
72 TUint8 iTOS; |
|
73 TUint16 iLength; |
|
74 TUint16 iIdent; |
|
75 //TFixedArray<TUint8,2> iFragOffset; |
|
76 TUint8 iFragOffset[2]; |
|
77 TUint8 iTTL; |
|
78 TUint8 iProtocol; |
|
79 TUint16 iChecksum; |
|
80 //TFixedArray<TUint8,4> iSrcAddr; |
|
81 //TFixedArray<TUint8,4> iDestAddr; |
|
82 TUint8 iSrcAddr[4]; |
|
83 TUint8 iDestAddr[4]; |
|
84 }; |
|
85 |
|
86 #endif |