|
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 // DHCPv6 Message receiver implementation file. Receiver keeps reading from socket untill the whole |
|
15 // message has been read |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include "DhcpIP6MsgRcvr.h" |
|
24 #include "DHCPServer.h" |
|
25 |
|
26 #ifdef _DEBUG |
|
27 #include <e32property.h> |
|
28 #endif |
|
29 |
|
30 CAsynchEvent* CDhcpIP6MessageReader::ProcessL(TRequestStatus& aStatus) |
|
31 /** |
|
32 * Keeps reading from socket util the full UDP datagram has been received |
|
33 * |
|
34 * @internalTechnology |
|
35 * |
|
36 */ |
|
37 { |
|
38 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDhcpIP6MessageReader::ProcessL"))); |
|
39 |
|
40 DHCPv6::CDHCPMessageHeaderIP6* v6Msg = DHCPIPv6().DhcpMessage(); |
|
41 TPtr8 v6MsgDes = v6Msg->Message().Des(); |
|
42 TInt length = v6MsgDes.Length(); |
|
43 |
|
44 if (iIncomingMsgDataPtr.Length() == 0) |
|
45 { |
|
46 v6MsgDes.Zero(); |
|
47 // Create a pointer to the memory location represented by the HBufC |
|
48 // containing the incoming message |
|
49 iIncomingMsgDataPtr.Set(const_cast<TUint8*>(v6MsgDes.Ptr()), 0, v6MsgDes.MaxLength()); |
|
50 } |
|
51 else if (iUnreadLength() > 0) |
|
52 { |
|
53 // Resize the message buffer for the remaining data |
|
54 iStateMachine->ReAllocL(iUnreadLength()); |
|
55 |
|
56 // Move the access pointer to the end of the previously read data ready |
|
57 // for the start of the remainder |
|
58 iIncomingMsgDataPtr.Set(const_cast<TUint8*>(v6MsgDes.Ptr() + v6MsgDes.Length()), 0, iUnreadLength()); |
|
59 |
|
60 v6MsgDes.SetLength(length + iIncomingMsgDataPtr.Length()); |
|
61 } |
|
62 else |
|
63 { |
|
64 // We've finished reading the message, complete the request |
|
65 v6MsgDes.SetLength(length + iIncomingMsgDataPtr.Length()); |
|
66 iIncomingMsgDataPtr.SetLength(0); |
|
67 |
|
68 TRequestStatus* p = &aStatus; |
|
69 User::RequestComplete(p, KErrNone); |
|
70 |
|
71 __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDhcpIP6MessageReader::ProcessL - finished"))); |
|
72 return iNext; |
|
73 } |
|
74 |
|
75 iRcvAddr.SetAddress(KAFUnspec); |
|
76 #ifdef _DEBUG |
|
77 // Simulate initialisation, renewal or rebind failure by using the wrong port. |
|
78 if( ( CDHCPServer::DebugFlags() & KDHCP_FailDiscover ) || ( CDHCPServer::DebugFlags() & KDHCP_FailRenew ) || ( CDHCPServer::DebugFlags() & KDHCP_FailRebind ) ) |
|
79 { |
|
80 iRcvAddr.SetPort(KDhcpv6WrongSrcPort); |
|
81 } |
|
82 else |
|
83 { |
|
84 TInt destPort; |
|
85 RProperty::Get(KMyPropertyCat, KMyPropertyDestPortv6, destPort); |
|
86 iRcvAddr.SetPort(destPort - 1); |
|
87 } |
|
88 #else |
|
89 iRcvAddr.SetPort(KDhcpv6SrcPort); |
|
90 #endif |
|
91 |
|
92 DHCPIPv6().iSocket.RecvFrom(iIncomingMsgDataPtr, iRcvAddr, KSockSelectReadContinuation, aStatus, iUnreadLength); |
|
93 |
|
94 return this; |
|
95 } |