|
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 // Provides constants common across DHCP component |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file DHCP_Std.h |
|
20 */ |
|
21 |
|
22 #ifndef __DHCP_STD_H__ |
|
23 #define __DHCP_STD_H__ |
|
24 |
|
25 #include <e32def.h> |
|
26 |
|
27 #include <es_sock.h> |
|
28 #include <es_enum.h> |
|
29 #include <in_sock.h> |
|
30 #include <cflog.h> |
|
31 #include <es_sock_partner.h> |
|
32 |
|
33 #ifdef _DEBUG |
|
34 const TUid KMyPropertyCat = {0x101FD9C5}; |
|
35 const TUint32 KMyPropertyDestPortv4 = 67; |
|
36 const TUint32 KMyPropertyDestPortv6 = 547; |
|
37 #endif |
|
38 |
|
39 __CFLOG_STMT(_LIT8(KLogSubSysDHCP, "DHCP");) // subsystem name |
|
40 |
|
41 IMPORT_C TInt E32Main(); |
|
42 |
|
43 #ifdef EKA2 |
|
44 _LIT(KDHCPServerName,"!DHCPServ"); |
|
45 #else |
|
46 _LIT(KDHCPServerName,"DHCPServ"); |
|
47 #endif |
|
48 |
|
49 _LIT(KDHCPProcessName,"DhcpServ"); |
|
50 |
|
51 _LIT(KDHCPExeName, "DHCPexe.exe"); |
|
52 _LIT(KDHCPDLLName,"DHCPServ.dll"); |
|
53 |
|
54 //persistence TIDs for DHCPv4 & DHCPv6 (cooked-up numbers to be able distinguish |
|
55 //what's been stored. Doesn't have to be system wide unique |
|
56 const TInt KDHCPv6Persinstence = 0x01DFA341; |
|
57 const TInt KDHCPv4Persinstence = 0x01DFA342; |
|
58 const TInt KDHCPv6PersinstenceId = 1; |
|
59 const TInt KDHCPv4PersinstenceId = 1; |
|
60 const TInt KDHCPv4MaxRetryCount = 3; |
|
61 |
|
62 const TInt KDHCPSrvMajorVersionNumber=1; |
|
63 const TInt KDHCPSrvMinorVersionNumber=0; |
|
64 const TInt KDHCPSrvBuildVersionNumber=0; |
|
65 |
|
66 const TUint8 KDhcpParameterRequestListLen = 7; |
|
67 const TUint16 KDhcpMaxMsgSizeIP4 = 576; |
|
68 |
|
69 const TUint8 KIp4AddrByteLength = 4; |
|
70 const TUint8 KIp4ChAddrMaxLength = 16; |
|
71 const TUint8 KHwAddrOffset = 8; |
|
72 #ifdef SYMBIAN_NETWORKING_ADDRESS_PROVISION |
|
73 const TUint KHwAddrLength = 6; |
|
74 #endif //SYMBIAN_NETWORKING_ADDRESS_PROVISION |
|
75 |
|
76 #ifdef _DEBUG |
|
77 const TUint8 KDhcpWrongSrcPort = 34; |
|
78 const TUint8 KDhcpWrongDestPort = 33; |
|
79 #else |
|
80 const TUint8 KDhcpSrcPort = 68; |
|
81 const TUint8 KDhcpDestPort = 67; |
|
82 #endif |
|
83 |
|
84 #ifdef SYMBIAN_NETWORKING_DHCPSERVER |
|
85 // now that we are having both dhcp client and server implemantation within |
|
86 // DHCPServe.exe, we explicitly mentioned the client and server port to avoid confusion |
|
87 const TUint8 KDhcpClientPort = 68; |
|
88 const TUint8 KDhcpServerPort = 67; |
|
89 |
|
90 /** 6 hours, magic number which is set on the rational that |
|
91 anything bigger than this number would not be required as a mobile device might |
|
92 not be used as a DHCP server for more than 6hours continuously |
|
93 anything less than this lease time would mean more DHCP network traffic to reconfigure/renew |
|
94 when the lease time expires |
|
95 */ |
|
96 const TUint32 KDefaultLeaseTime = 21600; |
|
97 |
|
98 // Constant used for setting custom lease time for the DHCP server |
|
99 // using RProperty::Define and RProperty::Set API's |
|
100 // Only on Debug builds |
|
101 #ifdef _DEBUG |
|
102 const TUint32 KMyDefaultLeaseTime = 21600; |
|
103 #endif |
|
104 |
|
105 #endif // SYMBIAN_NETWORKING_DHCPSERVER |
|
106 |
|
107 |
|
108 const TUint KOneSecond = 1; |
|
109 const TInt KInfinity = -1; |
|
110 const TUint KHalfSecondInMicroSeconds = 500000; |
|
111 const TUint KZeroSecond = 0; |
|
112 const TUint KFailTimeOut = 10; |
|
113 const TUint KWaitForResponseTime = 512; // in seconds |
|
114 const TUint KReallyLongLease = 0x7fffffff; // over 68 years - a virtual freehold |
|
115 |
|
116 const TTimeIntervalSeconds KManualRenewTimeout = 2*KWaitForResponseTime; |
|
117 |
|
118 //------------------------------------------------------------------------------------ |
|
119 //-- Debug heap control functions definition for the DHCP daemon. |
|
120 //-- Access to these function is provided by RConnection Ioctl functionality. |
|
121 //-- Note that this Ioctl level KDhcpMemDbgIoctl is not standard. |
|
122 //------------------------------------------------------------------------------------ |
|
123 |
|
124 #ifdef _DEBUG |
|
125 #define __DHCP_HEAP_CHECK_CONTROL |
|
126 #endif |
|
127 |
|
128 //-- IOCTL level for heap debug control functions |
|
129 const TUint KDhcpMemDbgIoctl = KConnWriteUserDataBit | 0x1000; |
|
130 |
|
131 //-- debug heap control functions numbers |
|
132 |
|
133 const TUint KDHCP_DbgMarkHeap = 1; //-- start heap mark. |
|
134 const TUint KDHCP_DbgCheckHeap = 2; //-- check heap, required a paremeter - number of expected allocated cells. |
|
135 const TUint KDHCP_DbgMarkEnd = 3; //-- mark the end of heap checking, required a paremeter - number of expected allocated cells. |
|
136 const TUint KDHCP_DbgFailNext = 4; //-- simulate heap alloc failure. Requires a parameter - failure rate. if param <0 resets. |
|
137 const TUint KDHCP_DbgFlags = 5; //-- set debug flags. |
|
138 |
|
139 //-- debug flags used with KDHCP_DbgFlags |
|
140 const TUint KDHCP_FailDiscover = 1; //-- force init task to fail (state machine returns -KErrTimeOut) |
|
141 const TUint KDHCP_FailRenew = 2; //-- force renew task to fail (state machine returns -KErrTimeOut) |
|
142 const TUint KDHCP_FailRebind = 4; //-- force rebind task to fail (state machine returns -KErrTimeOut) |
|
143 const TUint KDHCP_SetShortLease = 8; //-- set short lease as defined in KDHCP_ShortLeaseSec |
|
144 const TUint KDHCP_SetShortRetryTimeOut = 16; //-- set short lease as defined in KDHCP_ShortRetryTimeOutSec |
|
145 const TUint KDHCP_ForceDiscovery = 32; //-- ignore lease time in commDB. |
|
146 const TUint KDHCP_Dad = 64; // simulate a duplicate ip address has been found |
|
147 const TUint KDHCP_ShortLeaseRenewTime = 20; // |
|
148 const TUint KDHCP_ShortLeaseRebindTime = 70; // must be greater than timeout for test 5_6, so we know that renew worked |
|
149 const TUint KDHCP_ShortLeaseLeaseTime = 110; // |
|
150 const TUint KDHCP_ShortRetryTimeOut = 7; // |
|
151 const TUint KDHCP_RequestIP4BroadcastOffer = 128; //-- override setting unicast bit in offers |
|
152 |
|
153 |
|
154 //-- buffer for storing function number |
|
155 typedef TPckgBuf<TInt> TDhcpMemDbgParamBuf; |
|
156 |
|
157 |
|
158 //-- IOCTL level for per-interface debug functions. |
|
159 // specific numbers must have KConnWriteUserDataBit/KConnReadUserDataBit set as appropriate |
|
160 const TUint KDhcpInterfaceDbgIoctl = 0x2000; |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 class TDhcpRnd |
|
168 /** |
|
169 * Little random number generator class |
|
170 * |
|
171 * @internalTechnology |
|
172 */ |
|
173 { |
|
174 public: |
|
175 TDhcpRnd(); |
|
176 TInt Rnd(TInt aMin, TInt aMax); |
|
177 TUint32 Xid() const; |
|
178 void SetXid(TUint32 aXid); |
|
179 void Init(); |
|
180 void Init6(); |
|
181 private: |
|
182 TInt64 iSeed; |
|
183 TUint32 iXid; |
|
184 }; |
|
185 |
|
186 inline void TDhcpRnd::SetXid(TUint32 aXid) |
|
187 /** |
|
188 * Sets transaction id |
|
189 * |
|
190 * @internalTechnology |
|
191 * |
|
192 */ |
|
193 { |
|
194 iXid = aXid; |
|
195 } |
|
196 |
|
197 inline TUint32 TDhcpRnd::Xid() const |
|
198 /** |
|
199 * Returns transaction id |
|
200 * |
|
201 * @internalTechnology |
|
202 * |
|
203 */ |
|
204 { |
|
205 return iXid; |
|
206 } |
|
207 |
|
208 inline void TDhcpRnd::Init6() |
|
209 /** |
|
210 * Initialises class to a random value |
|
211 * |
|
212 * @internalTechnology |
|
213 */ |
|
214 { |
|
215 SetXid(static_cast<TUint32>(Rnd(0,0xFFFFFF))); |
|
216 } |
|
217 |
|
218 inline void TDhcpRnd::Init() |
|
219 /** |
|
220 * Initialises class to a random value |
|
221 * |
|
222 * @internalTechnology |
|
223 */ |
|
224 { |
|
225 SetXid(static_cast<TUint32>(Rnd(0,KMaxTInt))); |
|
226 } |
|
227 |
|
228 /** |
|
229 Byte-to byte copying one object to another. Using Mem::Copy allows to avoid system crash on target platform |
|
230 if the destination address isn't aligned to machine word boundary (e.g if it is a middle of some buffer). |
|
231 Also performs a kind of type-check. |
|
232 |
|
233 @param apDst destination address |
|
234 @param apSrc pointer to the source object |
|
235 @return pointer to the destination object |
|
236 */ |
|
237 template<class T> |
|
238 inline T* ObjectByteCopy(T* apDst, const T* apSrc) |
|
239 { |
|
240 return reinterpret_cast<T*>( Mem::Copy(apDst, apSrc ,sizeof(T))); |
|
241 } |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 #endif // __DHCP_STD_H__ |
|
247 |