1 // |
|
2 // * Copyright 2004 Neusoft America Inc. |
|
3 // * All rights reserved. |
|
4 // * This component and the accompanying materials are made available |
|
5 // * under the terms of the 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 // * Contributors: |
|
10 // * Keith Collins (Neusoft America Inc.) original software development and additional code and modifications. |
|
11 // * Thomas Gahagen (Neusoft America Inc.) additional code and modifications. |
|
12 // * Zhen Yuan (Neusoft America Inc.) additional code and modifications. |
|
13 // * |
|
14 // * Description: The CChannelMgrCmdData class defines a single 3GPP 27.010 based logical channel |
|
15 // * called DLC. Derived control and data channel add specific behavior. |
|
16 // |
|
17 |
|
18 // ChannelMgrCmdData.cpp |
|
19 |
|
20 /** @file ChannelMgrCmdData.cpp |
|
21 * |
|
22 */ |
|
23 |
|
24 #include "ChannelMgrCmdData.h" |
|
25 #include "PortC32InterfaceBase.h" |
|
26 #include "PortC32Interface.h" |
|
27 #include "CsyMsgBufBPFrame.h" |
|
28 #include "CsyDebugLogger.h" |
|
29 |
|
30 CChannelMgrCmdData* CChannelMgrCmdData::NewL(const TUint8 aDlcNum, |
|
31 CPortFactory& aPortFactory, |
|
32 CMux0710Protocol& aMux0710Protocol) |
|
33 /** |
|
34 * This methods uses two phase construction and the cleanup stack to create |
|
35 * an instance of class CChannelMgrCmd. |
|
36 * @param aDlcNum - DLC number of this channel |
|
37 * @param aPortFactory - Reference to the port factory |
|
38 * @param aMux0710Protocol - Pointer to the 27.010 mux protocol |
|
39 * @return Pointer to the created instance |
|
40 */ |
|
41 { |
|
42 _LOG_L4C2("CChannelMgrCmdData::NewL [aDlcNum=%d]", aDlcNum); |
|
43 |
|
44 CChannelMgrCmdData* p = new(ELeave) CChannelMgrCmdData(aDlcNum, aPortFactory, |
|
45 aMux0710Protocol); |
|
46 CleanupStack::PushL(p); |
|
47 p->ConstructL(); |
|
48 CleanupStack::Pop(p); |
|
49 return p; |
|
50 } |
|
51 |
|
52 CChannelMgrCmdData::~CChannelMgrCmdData() |
|
53 /** |
|
54 * Destructor. Delete all resources and memory allocated by this object. |
|
55 * Disconnect the channel from the multiplexer. |
|
56 */ |
|
57 { |
|
58 _LOG_L4C1("CChannelMgrData::~CChannelMgrCmdData"); |
|
59 } |
|
60 |
|
61 |
|
62 CChannelMgrCmdData::CChannelMgrCmdData(const TUint8 aDlcNum, |
|
63 CPortFactory& aPortFactory, |
|
64 CMux0710Protocol& aMux0710Protocol) |
|
65 : CChannelMgrBase(aDlcNum, aPortFactory, aMux0710Protocol), |
|
66 iCount(0) |
|
67 /** |
|
68 * Constructor. |
|
69 * @param aDlcNum - DLC number of this channel |
|
70 * @param aPortFactory - Reference to the port factory |
|
71 * @param aMux0710Protocol - Reference to the 27.010 mux protocol |
|
72 */ |
|
73 { |
|
74 iCsyAllowedToSendFrames = EFlowControlOn; |
|
75 } |
|
76 |
|
77 void CChannelMgrCmdData::ConstructL() |
|
78 /** |
|
79 * Create any instances and allocate any memory used by this object. |
|
80 */ |
|
81 { |
|
82 CChannelMgrBase::ConstructL(); |
|
83 } |
|
84 |
|
85 void CChannelMgrCmdData::Open(CPortC32InterfaceBase* aPort) |
|
86 /** |
|
87 * Open the port |
|
88 * |
|
89 * @param aPort - Pointer to CPortC32Interface |
|
90 */ |
|
91 { |
|
92 _LOG_L4C2(">>CChannelMgrCmdData::Open [aPort=0x%x]",aPort); |
|
93 |
|
94 iCount++; |
|
95 if (iCount == 1) |
|
96 { |
|
97 _LOG_L4C1("First client of port"); |
|
98 |
|
99 if (aPort->GetClientType() == CPortFactory::EC32ClientIpNif) |
|
100 { |
|
101 ParameterNegotiate(); |
|
102 } |
|
103 else |
|
104 { |
|
105 TInt err = Connect(); |
|
106 if (err != KErrNone) |
|
107 _LOG_L4C2("Open Connect error =%d",err); |
|
108 } |
|
109 } |
|
110 iPortArray.Insert(aPort,0); |
|
111 SetOwner(aPort); |
|
112 |
|
113 _LOG_L4C2("<<CChannelMgrCmdData::Open [iCount=%d]",iCount); |
|
114 } |
|
115 |
|
116 void CChannelMgrCmdData::Close(CPortC32InterfaceBase* aPort) |
|
117 /** |
|
118 * Close the port |
|
119 * |
|
120 * @param aPort - Pointer to CPortC32Interface |
|
121 */ |
|
122 { |
|
123 _LOG_L4C2(">>CChannelMgrCmdData::Close [aPort=%d]",aPort->GetPortNumber()); |
|
124 |
|
125 iCount--; |
|
126 if (iCount < 1) |
|
127 { |
|
128 _LOG_L4C1("Last client of port"); |
|
129 Disconnect(); |
|
130 iCount = 0; // reset counter |
|
131 iChannelReady = EFalse; |
|
132 } |
|
133 |
|
134 // remove port from the port list, set next port in the queue to be the port owner |
|
135 TInt index; |
|
136 index = iPortArray.Find(aPort); |
|
137 if (index == KErrNotFound) |
|
138 { |
|
139 _LOG_L1C2("** Close() - Port %d not found **", aPort); |
|
140 } |
|
141 else |
|
142 { |
|
143 iPortArray.Remove(index); |
|
144 if (iPortC32Interface == aPort) |
|
145 { |
|
146 // close the current owner of the channel, set owership to the first one in the port list |
|
147 // if there are one |
|
148 if (iPortArray.Count() > 0) |
|
149 SetOwner(iPortArray[0]); |
|
150 else |
|
151 SetOwner(NULL); |
|
152 } |
|
153 } |
|
154 |
|
155 _LOG_L4C2("<<CChannelMgrCmdData::Close [iCount=%d]",iCount); |
|
156 } |
|
157 |
|
158 void CChannelMgrCmdData::SetOwner(CPortC32InterfaceBase* aPort) |
|
159 /** |
|
160 * Set owner to the pointer |
|
161 * @param aPort - Pointer to new owner, which is a CPortC32Interface instance |
|
162 */ |
|
163 { |
|
164 _LOG_L4C1(">>CChannelMgrCmdData::SetOwner"); |
|
165 |
|
166 if (iPortC32Interface == aPort) |
|
167 return; |
|
168 |
|
169 if (iPortC32Interface != NULL) |
|
170 iPortC32Interface->CompleteOutstandingRequest(); |
|
171 |
|
172 if (aPort == NULL) |
|
173 { |
|
174 iPortC32Interface = aPort; |
|
175 _LOG_L4C1("<<CChannelMgrCmdData::SetOwner aPort was Null"); |
|
176 return; |
|
177 } |
|
178 |
|
179 TInt index; |
|
180 index = iPortArray.Find(aPort); |
|
181 if (index == KErrNotFound) |
|
182 { |
|
183 _LOG_L1C2("** Port %d not found **", aPort); |
|
184 } |
|
185 else |
|
186 { |
|
187 iPortC32Interface = aPort; |
|
188 } |
|
189 |
|
190 _LOG_L4C1("<<CChannelMgrCmdData::SetOwner"); |
|
191 } |
|
192 |
|
193 void CChannelMgrCmdData::SetupCmdChannelsForATCmdsL() |
|
194 /** |
|
195 * Set up and prepare the ports for AT commands |
|
196 */ |
|
197 { |
|
198 _LOG_L4C1("CChannelMgrCmdData::SetupCmdChannelsForATCmdsL"); |
|
199 #if defined DSAMPLE || defined H2 |
|
200 _LOG_L4C1("Setting up for DSample/H2 (or P2Sample on Wins)"); |
|
201 #endif |
|
202 #ifdef P2SAMPLE |
|
203 _LOG_L4C1("Setting up for P2Sample on TARGET"); |
|
204 #endif |
|
205 |
|
206 TBuf8<20> temp; |
|
207 temp.Copy(KATCmdSetup); |
|
208 iMux0710Protocol.Create0710DataFrames(temp, (TInt8)GetDlcNumber()); |
|
209 } |
|
210 |
|
211 void CChannelMgrCmdData::ProcessRecvUihFrame(CCsyMsgBufBpFrame* aBpFrame) |
|
212 /** |
|
213 * Process a received UIH frame. Set flow control off if an "ok" is received |
|
214 * and we are still initializing. |
|
215 * |
|
216 * @param aBpFrame - Pointer to the frame received from the baseband |
|
217 */ |
|
218 { |
|
219 #ifdef _DEBUG |
|
220 // The dlcNum is only needed for logging when _DEBUG is set. |
|
221 // Otherwise we get a warning for ARM v5 |
|
222 TInt dlcNum; |
|
223 dlcNum = aBpFrame->GetDlcNum(); |
|
224 #endif |
|
225 |
|
226 if(!iInitFinished) |
|
227 { |
|
228 if (iChannelState != ECsyChannelStateConnected) |
|
229 { |
|
230 _LOG_L4C1("Waiting for AT interpreter"); |
|
231 if (aBpFrame->iMsg.Find(KATInitialised) != KErrNotFound) |
|
232 { |
|
233 _LOG_L3C2E("AT interpreter ready [dlcNum=%d]", dlcNum); |
|
234 iChannelState = ECsyChannelStateConnected; |
|
235 // Send initial AT command |
|
236 TRAP_IGNORE(SetupCmdChannelsForATCmdsL()); |
|
237 } |
|
238 else |
|
239 { |
|
240 _LOG_L3C2E("Throw away unexpected response dlcNum=%d", dlcNum); |
|
241 } |
|
242 } |
|
243 else |
|
244 { |
|
245 _LOG_L4C1("Waiting for response to initial AT command"); |
|
246 if (aBpFrame->iMsg.Find(_L8("OK")) != KErrNotFound) |
|
247 { |
|
248 _LOG_L1C2E("**** Init completed [dlcNum=%d] ****", dlcNum); |
|
249 NotifyChannelReady(); |
|
250 ModemAndCsyToClientFlowCtrl(EFlowControlOff); |
|
251 } |
|
252 /*else if (aBpFrame->iMsg.Find(_L8("ERROR")) != KErrNotFound) |
|
253 { |
|
254 _LOG_L1C2E("**** Init completed [dlcNum=%d] ****ERROR****", dlcNum); |
|
255 NotifyChannelReady(); |
|
256 ModemAndCsyToClientFlowCtrl(EFlowControlOff); |
|
257 } |
|
258 */ |
|
259 else |
|
260 { |
|
261 _LOG_L3C2E("Throw away unexpected response dlcNum=%d", dlcNum); |
|
262 } |
|
263 } |
|
264 iMux0710Protocol.AddFrameFreeQ(aBpFrame); |
|
265 } |
|
266 else if (iPortC32Interface) |
|
267 { |
|
268 // don't need to add to the mux's queue if we are not defragging messages |
|
269 // simply add to the port object's queue |
|
270 // send frame to client |
|
271 iPortC32Interface->SendFrameToClient(aBpFrame); |
|
272 } |
|
273 else |
|
274 { |
|
275 _LOG_L1C2E("** NULL C32 PORT ** dlcNum=%d", dlcNum); |
|
276 iMux0710Protocol.AddFrameFreeQ(aBpFrame); |
|
277 // MAF __ASSERT_DEBUG(EFalse, PANIC(KPanicIllegalState)); |
|
278 } |
|
279 } |
|
280 |
|
281 |
|
282 |
|