1 /* |
|
2 * Copyright (c) 2007 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: Resolve ip address of the DHCP server at the WLAN network |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <es_sock.h> |
|
21 #include "dhcppsylogging.h" |
|
22 #include "dhcpconstants.h" |
|
23 #include "dhcpserveripaddressresolver.h" |
|
24 |
|
25 const TInt KDhcpPeriodicTimerInterval05Sec(500000); |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // NewL |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CDhcpPsyDhcpServerIPResolver* CDhcpPsyDhcpServerIPResolver::NewL( RConnection& aConnection, |
|
34 TRequestStatus& aStatus ) |
|
35 { |
|
36 TRACESTRING ( "CDhcpPsyDhcpServerIPResolver::NewL" ); |
|
37 CDhcpPsyDhcpServerIPResolver* self = new( ELeave ) CDhcpPsyDhcpServerIPResolver( |
|
38 aConnection, aStatus ); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Destructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CDhcpPsyDhcpServerIPResolver::~CDhcpPsyDhcpServerIPResolver() |
|
50 { |
|
51 TRACESTRING( "CDhcpPsyDhcpServerIPResolver::~CDhcpPsyDhcpServerIPResolver" ); |
|
52 Cancel(); |
|
53 delete iPeriodicTimer; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // C++ onstructor |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CDhcpPsyDhcpServerIPResolver::CDhcpPsyDhcpServerIPResolver( RConnection& aConnection, |
|
61 TRequestStatus& aStatus) : CActive ( EPriorityStandard ), iConnection(aConnection), |
|
62 iClientStatus (aStatus) |
|
63 { |
|
64 TRACESTRING( "CDhcpPsyDhcpServerIPResolver::CDhcpPsyDhcpServerIPResolver" ); |
|
65 CActiveScheduler::Add( this ); |
|
66 iInetAddress.Init (KAfInet6); |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // ConstructL |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CDhcpPsyDhcpServerIPResolver::ConstructL() |
|
74 { |
|
75 TRACESTRING( "CDhcpPsyDhcpServerIPResolver::ConstructL" ); |
|
76 iClientStatus = KRequestPending; |
|
77 iPckg().iAddr.SetFamily( KAfInet6 ); // Ipv 6, contains support both |
|
78 // ipv4 and ipv6 versions |
|
79 // |
|
80 iConnection.Ioctl( KCOLConfiguration, KConnGetServerAddr, |
|
81 iStatus, &iPckg ); |
|
82 |
|
83 SetActive (); |
|
84 |
|
85 // Initialize the periodic timer. |
|
86 iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
87 // Start the periodic timer, when ever the time elapsed |
|
88 // the PeriodicTimerCallBack() will get called. |
|
89 iPeriodicTimer->Start(KDhcpPeriodicTimerInterval05Sec, |
|
90 KDhcpPeriodicTimerInterval05Sec, TCallBack(PeriodicTimerCallBack, |
|
91 this)); |
|
92 |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // RunL |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CDhcpPsyDhcpServerIPResolver::RunL() |
|
100 { |
|
101 TRACESTRING( "CDhcpPsyDhcpServerIPResolver::RunL"); |
|
102 iDhcpResponseReceived = ETrue; |
|
103 TInt result = iStatus.Int(); |
|
104 TRACESTRING2( "CDhcpPsyDhcpServerIPResolver::RunL, result %d",result); |
|
105 if (result==KErrNone) |
|
106 { |
|
107 iInetAddress = TInetAddr::Cast(iPckg().iAddr); |
|
108 } |
|
109 iPeriodicTimer->Cancel(); |
|
110 CompleteRequest (result); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // DhcpServerAddress |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 TInetAddr& CDhcpPsyDhcpServerIPResolver::DhcpServerInetAddress () |
|
118 { |
|
119 TRACESTRING2 ( "CDhcpPsyDhcpServerIPResolver::DhcpServerInetAddress, %u ", |
|
120 iInetAddress.Address()); |
|
121 return iInetAddress; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // DoCancel |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CDhcpPsyDhcpServerIPResolver::DoCancel() |
|
129 { |
|
130 TRACESTRING( "CDhcpPsyDhcpServerIPResolver::DoCancel" ); |
|
131 iConnection.CancelIoctl(); |
|
132 if (iPeriodicTimer) |
|
133 { |
|
134 iPeriodicTimer->Cancel(); |
|
135 } |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // CDhcpPsyDhcpServerIPResolver::CancelOutstandigRequest |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CDhcpPsyDhcpServerIPResolver::CancelOutstandigRequest () |
|
143 { |
|
144 TRACESTRING ( "CDhcpPsyDhcpServerIPResolver::CancelOutstandigRequest "); |
|
145 iConnection.CancelIoctl(); |
|
146 if (!iDhcpResponseReceived) |
|
147 { |
|
148 // If real dhcp server can't found, we have to use the broadcast address |
|
149 // Most probaply, device is behind of wlan subnet which has not own dhcp server. |
|
150 iInetAddress.SetAddress(KInetAddrBroadcast); |
|
151 } |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // CDhcpPsyDhcpServerIPResolver::CompleteRequest |
|
156 // ---------------------------------------------------------------------------- |
|
157 // |
|
158 void CDhcpPsyDhcpServerIPResolver::CompleteRequest (TInt aStatusCode) |
|
159 { |
|
160 TRACESTRING2 ( "CDhcpPsyDhcpServerIPResolver::CompleteRequest, status %d ", |
|
161 aStatusCode); |
|
162 TRequestStatus* status = &iClientStatus; |
|
163 User::RequestComplete(status, aStatusCode); |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CDhcpPsyDhcpServerIPResolver::PeriodicTimerCallBack |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CDhcpPsyDhcpServerIPResolver::PeriodicTimerCallBack(TAny* aAny) |
|
171 { |
|
172 TRACESTRING ( "CDhcpPsyDhcpServerIPResolver::PeriodicTimerCallBack "); |
|
173 CDhcpPsyDhcpServerIPResolver* self = STATIC_CAST(CDhcpPsyDhcpServerIPResolver*, aAny); |
|
174 // Cancel outstanding requests |
|
175 self->CancelOutstandigRequest(); |
|
176 return KErrNone; |
|
177 } |
|
178 |
|
179 // End of file |
|