|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Receiver of UDP datagrams |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <in_sock.h> |
|
20 |
|
21 #include "ikedatainterface.h" |
|
22 #include "ikemsgheader.h" |
|
23 |
|
24 // CLASS HEADER |
|
25 #include "ikev1receiver.h" |
|
26 |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Two-phased constructor. |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CIkev1Receiver* CIkev1Receiver::NewL( MIkeDataInterface& aDataInterface, |
|
35 MIkev1ReceiverCallback& aCallback ) |
|
36 { |
|
37 CIkev1Receiver* self = new (ELeave) CIkev1Receiver( aDataInterface, |
|
38 aCallback ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Destructor. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CIkev1Receiver::~CIkev1Receiver() |
|
50 { |
|
51 Cancel(); |
|
52 |
|
53 delete iUdpData; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // Constructor. |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CIkev1Receiver::CIkev1Receiver( MIkeDataInterface& aDataInterface, |
|
61 MIkev1ReceiverCallback& aCallback ) |
|
62 : CActive( EPriorityStandard ), |
|
63 iUdpData( NULL ), |
|
64 iDataInterface( aDataInterface ), |
|
65 iCallback( aCallback ) |
|
66 { |
|
67 CActiveScheduler::Add( this ); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Second phase construction. |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CIkev1Receiver::ConstructL() |
|
75 { |
|
76 StartReceive(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Starts receive. |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CIkev1Receiver::StartReceive() |
|
84 { |
|
85 DoReceive(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // From class CActive |
|
90 // Handles completion of receive. |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CIkev1Receiver::RunL() |
|
94 { |
|
95 if ( iStatus.Int() == KErrNone ) |
|
96 { |
|
97 __ASSERT_DEBUG( iUdpData != NULL, |
|
98 User::Invariant() ); |
|
99 |
|
100 const ThdrISAKMP* ikeHdr = ThdrISAKMP::Ptr( iUdpData->Des() ); |
|
101 TInt msgLth = iUdpData->Length(); |
|
102 |
|
103 // Ignore possible <non-ESP marker> in the beginning of IKE message. |
|
104 TUint32 ikeMsgHdrOctets = GET32( ikeHdr ); |
|
105 if ( ikeMsgHdrOctets == NON_ESP_MARKER ) |
|
106 { |
|
107 ikeHdr = ikeHdr->GotoOffset( NON_ESP_MARKER_SIZE ); |
|
108 msgLth -= NON_ESP_MARKER_SIZE; |
|
109 } |
|
110 |
|
111 iCallback.IkeMsgReceivedL( *ikeHdr, iSrcAddr, iLocalPort ); |
|
112 } |
|
113 else |
|
114 { |
|
115 iCallback.ReceiveError( iStatus.Int() ); |
|
116 } |
|
117 |
|
118 delete iUdpData; |
|
119 iUdpData = NULL; |
|
120 |
|
121 if ( iStatus.Int() == KErrNone ) |
|
122 { |
|
123 // Continue receiving. |
|
124 DoReceive(); |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // From class CActive |
|
130 // Handles cancellation of receive. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 void CIkev1Receiver::DoCancel() |
|
134 { |
|
135 iDataInterface.CancelReceive(); |
|
136 |
|
137 delete iUdpData; |
|
138 iUdpData = NULL; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // Handles a leave occurring in RunL(). |
|
143 // Handles cancellation of receive. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CIkev1Receiver::RunError( TInt aError ) |
|
147 { |
|
148 delete iUdpData; |
|
149 iUdpData = NULL; |
|
150 |
|
151 iCallback.ReceiveError( aError ); |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Receives UDP data. |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CIkev1Receiver::DoReceive() |
|
160 { |
|
161 iDataInterface.ReceiveUdpData( iUdpData, iSrcAddr, iLocalPort, iStatus ); |
|
162 SetActive(); |
|
163 } |
|
164 |
|
165 |