|
1 // Copyright (c) 2006-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 // rawip.cpp - Raw IP socket support |
|
15 // This implements the raw IP socket protocol module |
|
16 // |
|
17 |
|
18 #include "inet6log.h" |
|
19 #include "rawip.h" |
|
20 #include "in_net.h" |
|
21 #include <icmp6_hdr.h> |
|
22 #include <in_pkt.h> |
|
23 |
|
24 _LIT(KRawIpName, "rawip"); |
|
25 |
|
26 // |
|
27 // CProtocolRawIp |
|
28 // ************* |
|
29 // The implementation and methods of the CProtocolRawIp4/6 is totally internal |
|
30 // to this module. No other module needs to be aware of this. |
|
31 // Thus the class definition is included here. |
|
32 // |
|
33 class CProtocolRawIp : public CProtocolInet6Network |
|
34 { |
|
35 public: |
|
36 CProtocolRawIp(); |
|
37 virtual ~CProtocolRawIp(); |
|
38 virtual CServProviderBase *NewSAPL(TUint aSockType); |
|
39 virtual TInt Send(RMBufChain &aPacket,CProtocolBase* aSourceProtocol=NULL); |
|
40 virtual void Identify(TServerProtocolDesc *) const; |
|
41 virtual void BindToL(CProtocolBase *aProtocol); |
|
42 protected: |
|
43 }; |
|
44 |
|
45 // ***** |
|
46 // RAWIP |
|
47 // ***** |
|
48 CProtocolBase *RAWIP::NewL() |
|
49 { |
|
50 return new (ELeave) CProtocolRawIp(); |
|
51 } |
|
52 |
|
53 void RAWIP::Identify(TServerProtocolDesc &aEntry) |
|
54 { |
|
55 aEntry.iName = KRawIpName; |
|
56 aEntry.iProtocol = KProtocolInetRawIp; |
|
57 aEntry.iAddrFamily = KAfInet; |
|
58 aEntry.iSockType = KSockRaw; |
|
59 aEntry.iVersion = TVersion(KInet6MajorVersionNumber, KInet6MinorVersionNumber, KInet6BuildVersionNumber); |
|
60 aEntry.iByteOrder = EBigEndian; |
|
61 aEntry.iServiceInfo = KRAWIPServiceInfo; |
|
62 aEntry.iNamingServices = KRAWIPNameServiceInfo; |
|
63 aEntry.iSecurity = KSocketNoSecurity; |
|
64 aEntry.iMessageSize = KRAWIPMaxDatagramSize; |
|
65 aEntry.iServiceTypeInfo = KRAWIPServiceTypeInfo; |
|
66 aEntry.iNumSockets = KRAWIPMaxSockets; |
|
67 } |
|
68 |
|
69 // |
|
70 |
|
71 // |
|
72 // CProtocolRawIp* constructors and destructors |
|
73 // ******************************************* |
|
74 |
|
75 CProtocolRawIp::CProtocolRawIp() |
|
76 { |
|
77 } |
|
78 |
|
79 CProtocolRawIp::~CProtocolRawIp() |
|
80 { |
|
81 } |
|
82 |
|
83 // |
|
84 // CProtocolRawIp::NewSAPL |
|
85 // Create a new instance of a CServProviderBase (SAP) for the |
|
86 // socket manager. The caller is responsible for the bookkeeping |
|
87 // and destruction of this created object! |
|
88 // |
|
89 CServProviderBase* CProtocolRawIp::NewSAPL(TUint aSockType) |
|
90 { |
|
91 return RAWIP::NewSAPL(aSockType, this); |
|
92 } |
|
93 |
|
94 void CProtocolRawIp::Identify(TServerProtocolDesc *aInfo) const |
|
95 { |
|
96 RAWIP::Identify(*aInfo); |
|
97 } |
|
98 |
|
99 |
|
100 void CProtocolRawIp::BindToL(CProtocolBase *aProtocol) |
|
101 /** |
|
102 * Bind to another protocol. |
|
103 * |
|
104 * The rawIP must be configured to bind to IP6. However, when instantiated |
|
105 * it will not know what actual protocols it will be requesting from the |
|
106 * IP layer. It will know this only after the actual socket has been opened. |
|
107 * |
|
108 * Thus, this only records the presense of the network. |
|
109 */ |
|
110 { |
|
111 ASSERT(this != aProtocol); |
|
112 TServerProtocolDesc info; |
|
113 aProtocol->Identify(&info); |
|
114 if (iNetwork == NULL && info.iProtocol == KProtocolInet6Ip) |
|
115 { |
|
116 // The network bind detected (aProtocol is IP6 instance!) |
|
117 iNetwork = ((CProtocolInet6Binder *)aProtocol)->NetworkService(); |
|
118 // Following Open will be cancelled by the destructor of CProtocolInet6Binder |
|
119 aProtocol->Open(); |
|
120 return; |
|
121 } |
|
122 User::Leave(KErrNotSupported); |
|
123 } |
|
124 |
|
125 // |
|
126 // CProtocolRawIp::Send() |
|
127 // |
|
128 // Pass the packet as is to the IP layer. This method is |
|
129 // supposed to be used by the Raw IP Service provider modules |
|
130 // to forward their packets down the stack. |
|
131 TInt CProtocolRawIp::Send(RMBufChain &aPacket,CProtocolBase* /*aSourceProtocol*/) |
|
132 { |
|
133 return iNetwork->Send(aPacket); |
|
134 } |
|
135 |
|
136 |