1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 * @file |
|
20 * @internalComponent |
|
21 */ |
|
22 |
|
23 #include <e32debug.h> |
|
24 #include <commdb.h> |
|
25 |
|
26 #ifdef OVERDUMMY_NCMCC |
|
27 #include <usb/testncmcc/dummy_essock.h> |
|
28 #else |
|
29 #include <commdbconnpref.h> |
|
30 #endif |
|
31 |
|
32 #include <commsdattypesv1_1.h> |
|
33 |
|
34 #include "ncmiapreaderobserver.h" |
|
35 #include "ncmiapreader.h" |
|
36 |
|
37 // For OST Tracing |
|
38 #include "OstTraceDefinitions.h" |
|
39 #ifdef OST_TRACE_COMPILER_IN_USE |
|
40 #include "ncmiapreaderTraces.h" |
|
41 #endif |
|
42 |
|
43 |
|
44 _LIT(KNcmIapReaderPanic, "UsbNcmIapReader"); // must be <=16 chars |
|
45 |
|
46 // Panic codes |
|
47 enum TNcmIapReaderPanicCode |
|
48 { |
|
49 ENcmIapReaderPanicOutstandingRequest = 1, |
|
50 ENcmIapReaderPanicTooManyIAPs = 2, |
|
51 ENcmIapReaderEndMark |
|
52 }; |
|
53 |
|
54 // NCM configuration item names |
|
55 _LIT(KBearerNifName, "ethint"); |
|
56 _LIT(KBearerLddFileName, "eusbcsc"); |
|
57 _LIT(KBearerPktDrvName, "ncmpkt.drv"); |
|
58 |
|
59 /** |
|
60 * Constructs a CNcmIapReader object. |
|
61 * @param aObserver An MNcmIAPReaderObserver instance which handles IAP reading completing |
|
62 * @param aConnPref The reference of the NCM connection aConnPref |
|
63 */ |
|
64 CNcmIapReader::CNcmIapReader(MNcmIAPReaderObserver& aObserver, TCommDbConnPref& aConnPref) |
|
65 : CActive(CActive::EPriorityStandard), |
|
66 iObserver(aObserver), |
|
67 iConnPref(aConnPref) |
|
68 { |
|
69 OstTraceFunctionEntryExt( CNCMIAPREADER_CNCMIAPREADER_ENTRY, this ); |
|
70 CActiveScheduler::Add(this); |
|
71 OstTraceFunctionExit1( CNCMIAPREADER_CNCMIAPREADER_EXIT, this ); |
|
72 } |
|
73 |
|
74 /** |
|
75 * Destructor. |
|
76 */ |
|
77 CNcmIapReader::~CNcmIapReader() |
|
78 { |
|
79 OstTraceFunctionEntry0( CNCMIAPREADER_CNCMIAPREADER_ENTRY_DESTRUCTOR ); |
|
80 |
|
81 Cancel(); |
|
82 OstTraceFunctionExit0( CNCMIAPREADER_CNCMIAPREADER_ENTRY_DESTRUCTOR_EXIT ); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Start the connection. |
|
87 */ |
|
88 void CNcmIapReader::Start() |
|
89 { |
|
90 OstTraceFunctionEntry0( CNCMIAPREADER_START_ENTRY ); |
|
91 |
|
92 __ASSERT_ALWAYS(!IsActive(), |
|
93 User::Panic(KNcmIapReaderPanic, ENcmIapReaderPanicOutstandingRequest)); |
|
94 |
|
95 SetActive(); |
|
96 TRequestStatus* status = &iStatus; |
|
97 User::RequestComplete(status, KErrNone); |
|
98 |
|
99 OstTraceFunctionExit0( CNCMIAPREADER_START_EXIT ); |
|
100 } |
|
101 |
|
102 /** |
|
103 * Implements cancellation of an outstanding request. |
|
104 */ |
|
105 void CNcmIapReader::DoCancel() |
|
106 { |
|
107 OstTraceFunctionEntry0( CNCMIAPREADER_DOCANCEL_ENTRY ); |
|
108 |
|
109 TRequestStatus* status = &iStatus; |
|
110 User::RequestComplete(status, KErrCancel); |
|
111 OstTraceFunctionExit0( CNCMIAPREADER_DOCANCEL_EXIT ); |
|
112 } |
|
113 |
|
114 /** |
|
115 * Simulate an async way and give |
|
116 * the scheduler a chance to schedule all AOs. |
|
117 */ |
|
118 void CNcmIapReader::RunL() |
|
119 { |
|
120 OstTraceFunctionEntry0( CNCMIAPREADER_RUNL_ENTRY ); |
|
121 |
|
122 // Reading |
|
123 TRAPD(err, SearchNcmIapL()) |
|
124 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_RUNL_GETIAP, "Get NCM IAP with error code %d", err ); |
|
125 |
|
126 |
|
127 // Complete connection manager |
|
128 iObserver.MicoHandleIAPReadingComplete(err); |
|
129 OstTraceFunctionExit0( CNCMIAPREADER_RUNL_EXIT ); |
|
130 } |
|
131 |
|
132 /** |
|
133 * Search NCM IAP in current commDB and set it into the ncm connection manager. |
|
134 */ |
|
135 void CNcmIapReader::SearchNcmIapL() |
|
136 { |
|
137 OstTraceFunctionEntry0( CNCMIAPREADER_GETNCMIAPIDL_ENTRY ); |
|
138 |
|
139 using namespace CommsDat; |
|
140 CMDBSession* dbs = CMDBSession::NewLC(KCDLatestVersion); // Current version is 1.1 |
|
141 |
|
142 CMDBRecordSet<CCDLANBearerRecord>* lanBearerTable = |
|
143 new (ELeave) CMDBRecordSet<CCDLANBearerRecord>(KCDTIdLANBearerRecord); |
|
144 CleanupStack::PushL(lanBearerTable); |
|
145 // Load the table into memory |
|
146 lanBearerTable->LoadL(*dbs); |
|
147 |
|
148 TInt numLanBearers = lanBearerTable->iRecords.Count(); |
|
149 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_COUNT_LAN_BEARER, "Found %d Lan Bearer!", numLanBearers ); |
|
150 TInt chosenLanBearer = KErrNotFound; |
|
151 TInt i = 0; |
|
152 for(i = 0; i<numLanBearers; i++) |
|
153 { |
|
154 CCDLANBearerRecord* lanBearer = |
|
155 static_cast<CCDLANBearerRecord*>(lanBearerTable->iRecords[i]); |
|
156 if ((lanBearer->iLanBearerNifName.GetL().Compare(KBearerNifName()) == 0) && |
|
157 (lanBearer->iLanBearerLddFilename.GetL().Compare(KBearerLddFileName()) == 0) && |
|
158 (lanBearer->iLanBearerPacketDriverName.GetL().Compare(KBearerPktDrvName()) == 0)) |
|
159 { |
|
160 // Matched all check points. We found LAN bearer for NCM |
|
161 chosenLanBearer = lanBearer->RecordId(); |
|
162 break; |
|
163 } |
|
164 } |
|
165 CleanupStack::PopAndDestroy(lanBearerTable); // lanBearerTable |
|
166 if (KErrNotFound == chosenLanBearer) |
|
167 { |
|
168 OstTrace0( TRACE_ERROR, CNCMIAPREADER_GETNCMIAPIDL, "Can not find NCM Lan Bearer!" ); |
|
169 User::Leave(KErrNotFound); |
|
170 } |
|
171 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_CHOSEN_LAN_BEARER, "Chosen Lan Bearer %d!", chosenLanBearer ); |
|
172 |
|
173 CMDBRecordSet<CCDIAPRecord> * iapTable = |
|
174 new (ELeave) CMDBRecordSet<CCDIAPRecord>(KCDTIdIAPRecord); |
|
175 CleanupStack::PushL(iapTable); |
|
176 // Load the table into memory |
|
177 iapTable->LoadL(*dbs); |
|
178 |
|
179 TInt numIaps = iapTable->iRecords.Count(); |
|
180 TInt chosenIAP = KErrNotFound; |
|
181 TInt iapLanBearer = KErrNotFound; |
|
182 for (i = 0; i < numIaps; i++) |
|
183 { |
|
184 CCDIAPRecord* iap = |
|
185 static_cast<CCDIAPRecord*> (iapTable->iRecords[i]); |
|
186 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_RECORD_ID, "Id of current IAP is %d!", iap->RecordId() ); |
|
187 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_RECORD_BEARER_ID, "Lan Bearer Id of current IAP is %d!", TMDBElementId(iap->iBearer) ); |
|
188 iapLanBearer = TMDBElementId(iap->iBearer); |
|
189 if ((iap->iBearerType.GetL().Compare(TPtrC(KCDTypeNameLANBearer)) == 0) && |
|
190 (iapLanBearer == chosenLanBearer)) |
|
191 { |
|
192 // NCM IAP found! |
|
193 // Panic if there is more than NCM IAP found |
|
194 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_SEARCHNCMIAPL_ONLY_ONE_NCM_IAP, "NCM IAP found: Current chosenIAP value is %d", chosenIAP ); |
|
195 |
|
196 __ASSERT_ALWAYS(KErrNotFound == chosenIAP, User::Panic(KNcmIapReaderPanic, ENcmIapReaderPanicTooManyIAPs)); |
|
197 chosenIAP = iap->RecordId(); |
|
198 break; |
|
199 } |
|
200 } |
|
201 CleanupStack::PopAndDestroy(2, dbs); // iapTable, dbs |
|
202 if(chosenIAP == KErrNotFound) |
|
203 { |
|
204 OstTrace0( TRACE_ERROR, CNCMIAPREADER_GETNCMIAPIDL_NOT_FOUND, "Can not find NCM IAP!" ); |
|
205 User::Leave(KErrNotFound); |
|
206 } |
|
207 OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_CHOSEN_IAP_ID, "Chosen IAP is %d!", chosenIAP ); |
|
208 iConnPref.SetIapId(chosenIAP); |
|
209 OstTraceFunctionExit0( CNCMIAPREADER_GETNCMIAPIDL_EXIT ); |
|
210 } |
|