|
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: Send request data packets to the connected wlan network. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32svr.h> |
|
21 |
|
22 #include "cipapputilsaddressresolver.h" |
|
23 #include "dhcpconstants.h" |
|
24 #include "dhcpdatasender.h" |
|
25 #include "dhcppsylogging.h" |
|
26 |
|
27 _LIT8 (KDhcpWlanMacAddressFrmt, "" ); |
|
28 const TInt KDhcpWlanMacAddressLength = 0x20; |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // NewL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CDhcpDataRequestor* CDhcpDataRequestor::NewL(RSocket& aSocket) |
|
37 { |
|
38 CDhcpDataRequestor* self = new( ELeave ) CDhcpDataRequestor(aSocket); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Destructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CDhcpDataRequestor::~CDhcpDataRequestor() |
|
50 { |
|
51 TRACESTRING( "CDhcpDataRequestor::~CDhcpDataRequestor" ); |
|
52 Cancel(); |
|
53 delete iIpAppUtilsResolver; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // Constructor |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CDhcpDataRequestor::CDhcpDataRequestor(RSocket& aSocket): |
|
61 CActive ( EPriorityStandard ), iSocket ( aSocket ) |
|
62 { |
|
63 CActiveScheduler::Add( this ); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // For sending a DHCP message. If a DHCP server address has been found then we |
|
68 // use that, but if it has not been found then we try broadcasting. |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CDhcpDataRequestor::SendDHCPMessageL(TInetAddr aDhcpSrvAddr, TUint32 aIapProfileId, |
|
72 TRequestStatus& aStatus ) |
|
73 { |
|
74 TRACESTRING2( "CDhcpDataRequestor::SendDHCPMessageL, dhcp server address: %u", |
|
75 aDhcpSrvAddr.Address() ); |
|
76 |
|
77 // Make location request message. |
|
78 iIapProfileId = aIapProfileId; |
|
79 |
|
80 TBuf8<KDhcpWlanMacAddressLength> wlanMacAddress (KNullDesC8); |
|
81 |
|
82 User::LeaveIfError( |
|
83 iIpAppUtilsResolver->GetWlanMACAddress(wlanMacAddress, |
|
84 KDhcpWlanMacAddressFrmt) |
|
85 ); |
|
86 |
|
87 User::LeaveIfError ( |
|
88 iIpAppUtilsResolver->GetLocalIpAddressFromIap(iInetLclIpAddress, aIapProfileId) |
|
89 ); |
|
90 |
|
91 TRACESTRING2( "CDhcpDataRequestor::SendDHCPMessage, local Ipaddres address: %u", |
|
92 iInetLclIpAddress.Address() ); |
|
93 |
|
94 iLocationRequestMsg.MakeDhcpInformMsg (iInetLclIpAddress.Address(), |
|
95 wlanMacAddress ); |
|
96 |
|
97 aStatus = KRequestPending; |
|
98 iClientStatus = &aStatus; |
|
99 TInetAddr inetAddr (aDhcpSrvAddr) ; |
|
100 inetAddr.SetPort( KDhcpDefaultSrvPort ); |
|
101 iSocket.SendTo( iLocationRequestMsg, inetAddr, 0, iStatus, iLen ); |
|
102 SetActive(); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // TransActionIdToFollow |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 TUint32 CDhcpDataRequestor::TransActionIdToFollow () |
|
110 { |
|
111 return iLocationRequestMsg.TransactionId(); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // ContructL |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CDhcpDataRequestor::ConstructL () |
|
119 { |
|
120 iIpAppUtilsResolver = CIPAppUtilsAddressResolver::NewL (); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // RunL |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CDhcpDataRequestor::RunL () |
|
128 { |
|
129 TRACESTRING2( "CDhcpDataRequestor::RunL %d", iStatus.Int()); |
|
130 TRequestStatus *status = iClientStatus; |
|
131 User::RequestComplete (status, iStatus.Int()); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CDhcpDataRequestor::DoCancel |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CDhcpDataRequestor::DoCancel () |
|
139 { |
|
140 TRACESTRING( "CDhcpDataRequestor::DoCancel" ); |
|
141 iSocket.CancelSend(); |
|
142 } |