20 #include "bcatoisc.h" |
20 #include "bcatoisc.h" |
21 #include "bcatoisctrace.h" |
21 #include "bcatoisctrace.h" |
22 #include "iscdefinitions.h" |
22 #include "iscdefinitions.h" |
23 #include <cdbcols.h> |
23 #include <cdbcols.h> |
24 |
24 |
|
25 #include <nsisi.h> |
|
26 #include <pipeisi.h> |
|
27 #include <pn_const.h> |
|
28 #include <iscnokiadefinitions.h> |
|
29 #include "pep_bca_types.h" |
|
30 |
|
31 |
|
32 const TUint8 KDataLength = 7; |
|
33 const TUint8 KStatusIndex = 0; |
|
34 const TUint8 KDevIdIndex = 5; |
|
35 const TUint8 KObjIdIndex = 6; |
|
36 const TUint8 KPadding = 0; |
|
37 const TUint KDefaultReceiveBufferSize = 2048; |
|
38 |
25 using namespace BasebandChannelAdaptation; |
39 using namespace BasebandChannelAdaptation; |
|
40 |
|
41 /** |
|
42 * Utility function to complete a pending request and NULL request pointer. |
|
43 */ |
|
44 |
|
45 static void CompleteRequest(TRequestStatus* &aReqStatus, const TInt aError) |
|
46 { |
|
47 if(( aReqStatus ) && |
|
48 ( *aReqStatus == KRequestPending )) |
|
49 { |
|
50 // Only realy need to trace if we actually complete the request. |
|
51 C_TRACE( (_T("CompleteRequest completing client request with aError %d ->"), aError ) ); |
|
52 |
|
53 //Complete clients request |
|
54 User::RequestComplete( aReqStatus, aError ); |
|
55 |
|
56 aReqStatus = NULL; |
|
57 } |
|
58 } |
26 |
59 |
27 |
60 |
28 /** |
61 /** |
29 * Default constructor to create a CNotifyFlowControlMonitor instance. |
62 * Default constructor to create a CNotifyFlowControlMonitor instance. |
30 */ |
63 */ |
31 CNotifyFlowControlMonitor::CNotifyFlowControlMonitor(RIscApi& aIscApi) |
64 CNotifyFlowControlMonitor::CNotifyFlowControlMonitor(RIscApi& aIscApi) |
32 :CActive(EPriorityStandard), |
65 :CActive(EPriorityHigh), |
33 iIscApi(aIscApi) |
66 iIscApi(aIscApi), |
34 { |
67 iWriteStatus(NULL) |
35 C_TRACE( (_T("CNotifyFlowControlMonitor::CNotifyFlowControlMonitor RIscAapi 0x%x ->"), &aIscApi ) ); |
68 { |
36 |
69 C_TRACE( (_T("CNotifyFlowControlMonitor::CNotifyFlowControlMonitor RIscApi 0x%x ->"), &aIscApi ) ); |
37 CActiveScheduler::Add(this); |
70 CActiveScheduler::Add(this); |
38 |
|
39 C_TRACE( (_T("CNotifyFlowControlMonitor::CNotifyFlowControlMonitor <-") ) ); |
71 C_TRACE( (_T("CNotifyFlowControlMonitor::CNotifyFlowControlMonitor <-") ) ); |
40 } |
72 } |
41 |
73 |
42 void CNotifyFlowControlMonitor::NotifyFlowControlStatus() |
74 void CNotifyFlowControlMonitor::NotifyFlowControlStatus() |
43 { |
75 { |
44 C_TRACE( (_T("CNotifyFlowControlMonitor::NotifyFlowControlStatus() ->") ) ); |
76 C_TRACE( (_T("CNotifyFlowControlMonitor::NotifyFlowControlStatus() ->") ) ); |
45 |
77 |
46 ASSERT(!IsActive()); |
78 ASSERT(!IsActive()); |
47 |
79 |
48 iFlowControlValue = iIscApi.FlowControlStatus(); |
80 iFlowControlValue = iIscApi.FlowControlStatus(); |
49 |
81 |
50 C_TRACE( (_T("CNotifyFlowControlMonitor::NotifyFlowControlStatus initial iFlowControlValue %d ->"), iFlowControlValue ) ); |
82 C_TRACE( (_T("CNotifyFlowControlMonitor::NotifyFlowControlStatus initial iFlowControlValue %d ->"), iFlowControlValue ) ); |
56 } |
88 } |
57 |
89 |
58 void CNotifyFlowControlMonitor::RequestFlowcontrolChange( TRequestStatus& aStatus ) |
90 void CNotifyFlowControlMonitor::RequestFlowcontrolChange( TRequestStatus& aStatus ) |
59 { |
91 { |
60 C_TRACE( (_T("CNotifyFlowControlMonitor::RequestFlowcontrolChange ->") ) ); |
92 C_TRACE( (_T("CNotifyFlowControlMonitor::RequestFlowcontrolChange ->") ) ); |
61 |
|
62 iWriteStatus = &aStatus; |
93 iWriteStatus = &aStatus; |
63 *iWriteStatus = KRequestPending; |
94 *iWriteStatus = KRequestPending; |
64 |
|
65 |
|
66 C_TRACE( (_T("CNotifyFlowControlMonitor::RequestFlowcontrolChange <-") ) ); |
95 C_TRACE( (_T("CNotifyFlowControlMonitor::RequestFlowcontrolChange <-") ) ); |
67 } |
96 } |
68 |
97 |
|
98 void CNotifyFlowControlMonitor::CompleteFlowcontrolChangeWithCancel() |
|
99 { |
|
100 C_TRACE( (_T("CNotifyFlowControlMonitor::CompleteFlowcontrolChangeWithCancel() ->") ) ); |
|
101 // If pending request, complete as cancelled |
|
102 CompleteRequest(iWriteStatus, KErrCancel); |
|
103 C_TRACE( (_T("CNotifyFlowControlMonitor::CompleteFlowcontrolChangeWithCancel() <-") ) ); |
|
104 } |
|
105 |
69 void CNotifyFlowControlMonitor::RunL() |
106 void CNotifyFlowControlMonitor::RunL() |
70 { |
107 { |
71 C_TRACE( (_T("CNotifyFlowControlMonitor::RunL() iStatus %d ->"), iStatus.Int() ) ); |
108 C_TRACE( (_T("CNotifyFlowControlMonitor::RunL() iStatus %d ->"), iStatus.Int() ) ); |
72 |
109 |
|
110 ASSERT( iStatus.Int() == KErrNone); |
|
111 |
73 iFlowControlValue = iIscApi.FlowControlStatus(); |
112 iFlowControlValue = iIscApi.FlowControlStatus(); |
74 |
113 |
75 |
|
76 C_TRACE( (_T("CNotifyFlowControlMonitor::RunL flow control Value has changed and is now: (%d)"), iFlowControlValue ) ); |
114 C_TRACE( (_T("CNotifyFlowControlMonitor::RunL flow control Value has changed and is now: (%d)"), iFlowControlValue ) ); |
77 |
115 |
78 if( *iWriteStatus == KRequestPending ) |
116 if( iFlowControlValue == EIscFlowControlOff) |
79 { |
117 { |
80 User::RequestComplete(iWriteStatus, KErrNone); |
118 // If pending request, complete it as flow control is now OFF |
81 } |
119 CompleteRequest(iWriteStatus,KErrNone); |
82 |
120 } |
83 if( iStatus == KErrNone ) |
121 |
84 { |
122 //Check for further flow control status changes |
85 //Check for further flow control status changes |
123 iIscApi.NotifyFlowControl(iStatus, iFlowControlValue); |
86 iIscApi.NotifyFlowControl(iStatus, iFlowControlValue); |
124 SetActive(); |
87 SetActive(); |
|
88 } |
|
89 |
|
90 C_TRACE( (_T("CNotifyFlowControlMonitor::RunL() <-") ) ); |
125 C_TRACE( (_T("CNotifyFlowControlMonitor::RunL() <-") ) ); |
91 } |
126 } |
92 |
127 |
93 TInt CNotifyFlowControlMonitor::GetFlowControlState() |
128 TInt CNotifyFlowControlMonitor::GetFlowControlState() |
94 { |
129 { |
|
130 C_TRACE( (_T("CNotifyFlowControlMonitor::GetFlowControlState() flowcontrol value %d <->"), iFlowControlValue ) ); |
95 return iFlowControlValue; |
131 return iFlowControlValue; |
96 } |
132 } |
97 |
133 |
98 void CNotifyFlowControlMonitor::DoCancel() |
134 void CNotifyFlowControlMonitor::DoCancel() |
99 { |
135 { |
100 C_TRACE( (_T("CNotifyFlowControlMonitor::DoCancel() ->") ) ); |
136 C_TRACE( (_T("CNotifyFlowControlMonitor::DoCancel() ->") ) ); |
101 |
137 // If pending request, complete it as cancelled |
|
138 CompleteRequest(iWriteStatus, KErrCancel); |
|
139 C_TRACE( (_T("CNotifyFlowControlMonitor::DoCancel() req is completed") ) ); |
|
140 |
102 iIscApi.NotifyFlowControlCancel(); |
141 iIscApi.NotifyFlowControlCancel(); |
103 |
142 |
104 C_TRACE( (_T("CNotifyFlowControlMonitor::DoCancel() <-") ) ); |
143 C_TRACE( (_T("CNotifyFlowControlMonitor::DoCancel() <-") ) ); |
105 } |
144 } |
106 |
145 |
107 CNotifyFlowControlMonitor::~CNotifyFlowControlMonitor() |
146 CNotifyFlowControlMonitor::~CNotifyFlowControlMonitor() |
108 { |
147 { |
109 C_TRACE( (_T("CNotifyFlowControlMonitor::~CNotifyFlowControlMonitor() ->") ) ); |
148 C_TRACE( (_T("CNotifyFlowControlMonitor::~CNotifyFlowControlMonitor() ->") ) ); |
110 |
149 |
111 Cancel(); |
150 Cancel(); |
112 |
151 |
113 C_TRACE( (_T("CNotifyFlowControlMonitor::~CNotifyFlowControlMonitor() <-") ) ); |
152 C_TRACE( (_T("CNotifyFlowControlMonitor::~CNotifyFlowControlMonitor() <-") ) ); |
114 } |
153 } |
115 |
154 |
116 |
155 |
117 CNotifyWriteStatusMonitor::CNotifyWriteStatusMonitor( CBcaToIsc& aUser, RIscApi& aIscApi ) |
156 CNotifyWriteStatusMonitor::CNotifyWriteStatusMonitor( CBcaToIsc& aUser, RIscApi& aIscApi ) |
118 :CActive(EPriorityHigh), |
157 :CActive(EPriorityStandard), |
119 iUser(aUser), |
158 iUser(aUser), |
120 iIscApi(aIscApi) |
159 iIscApi(aIscApi) |
121 { |
160 { |
122 C_TRACE( (_T("CNotifyWriteStatusMonitor::CNotifyWriteStatusMonitor ->") ) ); |
161 C_TRACE( (_T("CNotifyWriteStatusMonitor::CNotifyWriteStatusMonitor ->") ) ); |
123 // iBuf = new TPtr8( NULL, 0, 0 ); |
|
124 CActiveScheduler::Add(this); |
162 CActiveScheduler::Add(this); |
125 C_TRACE( (_T("CNotifyWriteStatusMonitor::CNotifyWriteStatusMonitor <-") ) ); |
163 C_TRACE( (_T("CNotifyWriteStatusMonitor::CNotifyWriteStatusMonitor <-") ) ); |
126 } |
164 } |
127 |
165 |
128 |
166 |
129 void CNotifyWriteStatusMonitor::Write( TRequestStatus& aStatus, const TDesC8& aBuf ) |
167 void CNotifyWriteStatusMonitor::Write( TRequestStatus& aStatus, const TDesC8& aBuf ) |
130 { |
168 { |
131 |
169 C_TRACE( (_T("CNotifyWriteStatusMonitor::Write ->") ) ); |
132 iBuf = &aBuf; |
170 iBuf = &aBuf; |
133 iClientStatus = &aStatus; |
171 iClientStatus = &aStatus; |
134 *iClientStatus = KRequestPending; |
172 *iClientStatus = KRequestPending; |
135 |
173 |
136 if( iUser.iFlowControlMonitor->GetFlowControlState() == EIscFlowControlOff ) |
174 if( iUser.iFlowControlMonitor->GetFlowControlState() == EIscFlowControlOff ) |
137 { |
175 { |
138 //iIscApi.DataSend( aStatus, aBuf ); |
176 SendAndComplete(KErrNone); |
139 SendAndComplete(); |
|
140 } |
177 } |
141 else //flow control on |
178 else //flow control on |
142 { |
179 { |
143 |
|
144 //iBuf = &aBuf; |
|
145 // iBuf->Set( const_cast<TUint8*>(aBuf.Ptr()), aBuf.Length(), aBuf.Length() ); |
|
146 // iClientStatus = &aStatus; |
|
147 // *iClientStatus = KRequestPending; |
|
148 iUser.iFlowControlMonitor->RequestFlowcontrolChange( iStatus ); |
180 iUser.iFlowControlMonitor->RequestFlowcontrolChange( iStatus ); |
149 SetActive(); |
181 SetActive(); |
150 } |
182 } |
151 |
183 C_TRACE( (_T("CNotifyWriteStatusMonitor::Write <-") ) ); |
152 } |
184 } |
|
185 |
153 void CNotifyWriteStatusMonitor::RunL() |
186 void CNotifyWriteStatusMonitor::RunL() |
154 { |
187 { |
155 C_TRACE( (_T("CNotifyWriteStatusMonitor::RunL() iStatus %d ->"), iStatus.Int() ) ); |
188 C_TRACE( (_T("CNotifyWriteStatusMonitor::RunL() iStatus %d ->"), iStatus.Int() ) ); |
156 |
189 // KARI ei kutsu IASC apin data sendiä jos erksa OK? |
157 SendAndComplete(); |
190 SendAndComplete(iStatus.Int()); |
158 //iIscApi.DataSend( *iClientStatus, *iBuf ); |
|
159 |
191 |
160 C_TRACE( (_T("CNotifyWriteStatusMonitor::RunL() <-") ) ); |
192 C_TRACE( (_T("CNotifyWriteStatusMonitor::RunL() <-") ) ); |
161 } |
193 } |
162 |
194 |
163 void CNotifyWriteStatusMonitor::SendAndComplete() |
195 void CNotifyWriteStatusMonitor::SendAndComplete(TInt aError) |
164 { |
196 { |
165 TInt error = KErrGeneral; |
197 C_TRACE( (_T("CNotifyWriteStatusMonitor::SendAndComplete() ->"))); |
166 |
198 |
167 error = iIscApi.DataSend( *iBuf ); |
199 // We may have had the request cancelled, in which case do not send the write data |
168 User::RequestComplete(iClientStatus, error); |
200 if (aError == KErrNone) |
|
201 { |
|
202 C_TRACE( (_T("CNotifyWriteStatusMonitor::SendAndComplete() iIscApi.DataSend "))); |
|
203 aError = iIscApi.DataSend( *iBuf ); |
|
204 } |
|
205 |
|
206 // If pending request, complete it as specified by the error status |
|
207 // This could be OK or canncelled |
|
208 CompleteRequest(iClientStatus, aError); |
|
209 |
|
210 C_TRACE( (_T("CNotifyWriteStatusMonitor::SendAndComplete() <-") ) ); |
169 } |
211 } |
170 |
212 |
171 |
213 |
172 void CNotifyWriteStatusMonitor::DoCancel() |
214 void CNotifyWriteStatusMonitor::DoCancel() |
173 { |
215 { |
174 C_TRACE( (_T("CNotifyWriteStatusMonitor::DoCancel() ->") ) ); |
216 C_TRACE( (_T("CNotifyWriteStatusMonitor::DoCancel() ->") ) ); |
175 |
217 |
176 if( *iClientStatus == KRequestPending ) |
218 iUser.iFlowControlMonitor->CompleteFlowcontrolChangeWithCancel(); |
177 { |
219 |
178 C_TRACE( (_T("CNotifyWriteStatusMonitor::DoCancel completing client request with KErrCancel ->") ) ); |
220 // If pending request, complete it as cancelled |
179 //Complete clients request |
221 CompleteRequest(iClientStatus, KErrCancel); |
180 User::RequestComplete( iClientStatus, KErrCancel ); |
|
181 } |
|
182 |
222 |
183 C_TRACE( (_T("CNotifyWriteStatusMonitor::DoCancel() <-") ) ); |
223 C_TRACE( (_T("CNotifyWriteStatusMonitor::DoCancel() <-") ) ); |
184 } |
224 } |
185 |
225 |
186 |
226 |
280 TPtrC digit = aChannelId.Mid(numPos); |
342 TPtrC digit = aChannelId.Mid(numPos); |
281 TLex16 channelParser(digit); |
343 TLex16 channelParser(digit); |
282 error = channelParser.Val(channelid, EDecimal); |
344 error = channelParser.Val(channelid, EDecimal); |
283 } |
345 } |
284 ASSERT( KErrNone == error ); |
346 ASSERT( KErrNone == error ); |
|
347 C_TRACE( (_T("CBcaToIsc::Open parsed channel id: 0x%x"), channelid ) ); |
285 if( error == KErrNone ) |
348 if( error == KErrNone ) |
286 { |
349 { |
287 error = iIscApi.Loan( channelid ); |
350 TInt index( 0 ); |
288 iChannelNumber = error == KErrNone ? channelid : iChannelNumber; |
351 TBool channelOpened( EFalse ); |
289 } |
352 TRequestStatus status( KRequestPending ); |
290 ASSERT( KErrNone == error ); |
353 for( index = 0; index < iChannelList.Length(); index++ ) |
291 TRequestStatus* request = &aStatus; |
354 { |
292 User::RequestComplete( request, error ); |
355 status = KRequestPending; |
|
356 iIscApi.Open( iChannelList[index], status, EOwnerThread ); |
|
357 User::WaitForRequest( status ); |
|
358 if( KErrNone == status.Int() ) |
|
359 { |
|
360 C_TRACE( (_T("CBcaToIsc::Open channel 0x%x opened"), iChannelList[index] ) ); |
|
361 channelOpened = ETrue; |
|
362 break; |
|
363 } |
|
364 } |
|
365 |
|
366 if( !channelOpened ) |
|
367 { |
|
368 C_TRACE( (_T("CBcaToIsc::Open channel opening failed") ) ); |
|
369 User::RequestComplete( iClientOpenStatus, KErrGeneral ); |
|
370 iClientOpenStatus = NULL; |
|
371 } |
|
372 else if( KErrNone == SendNameAddReq( iChannelList[index], channelid ) ) |
|
373 { |
|
374 iFlowControlMonitor->NotifyFlowControlStatus(); |
|
375 iChannelNumber = status.Int() == KErrNone ? iChannelList[index] : iChannelNumber; |
|
376 |
|
377 iMessageBufferPtr.SetLength( 0 ); |
|
378 iStatus = KRequestPending; |
|
379 iIscApi.Receive( iStatus, iMessageBufferPtr, iReadLength ); |
|
380 SetActive(); |
|
381 } |
|
382 else |
|
383 { |
|
384 C_TRACE( (_T("CBcaToIsc::Open sending of PNS_NAME_ADD_REQ failed") ) ); |
|
385 iIscApi.Close(); |
|
386 User::RequestComplete( iClientOpenStatus, KErrGeneral ); |
|
387 iClientOpenStatus = NULL; |
|
388 } |
|
389 } |
|
390 else |
|
391 { |
|
392 User::RequestComplete( iClientOpenStatus, error ); |
|
393 iClientOpenStatus = NULL; |
|
394 } |
|
395 |
293 C_TRACE( (_T("CBcaToIsc::Open <-") ) ); |
396 C_TRACE( (_T("CBcaToIsc::Open <-") ) ); |
294 |
|
295 } |
397 } |
296 |
398 |
297 /** |
399 /** |
298 Shuts the BCA channel down in a graceful manner. BCA releases its resources. |
400 Shuts the BCA channel down in a graceful manner. BCA releases its resources. |
299 Cancels all outstanding operations: Writes, Reads and Ioctls. |
401 Cancels all outstanding operations: Writes, Reads and Ioctls. |
431 C_TRACE( (_T("CBcaToIsc::CancelIoctl() ->") ) ); |
546 C_TRACE( (_T("CBcaToIsc::CancelIoctl() ->") ) ); |
432 C_TRACE( (_T("CBcaToIsc::CancelIoctl() <-") ) ); |
547 C_TRACE( (_T("CBcaToIsc::CancelIoctl() <-") ) ); |
433 |
548 |
434 } |
549 } |
435 |
550 |
|
551 /** |
|
552 * Sends PNS_NAME_ADD_REQ |
|
553 |
|
554 * @param aObjId object id for the name to be added |
|
555 * @return KErrNone if message sent succesfully, otherwise error code |
|
556 */ |
|
557 TInt CBcaToIsc::SendNameAddReq( TUint16& aObjId, TUint16& aClientObjId ) |
|
558 { |
|
559 C_TRACE( (_T("CBcaToIsc::SendNameAddReq() ->") ) ); |
|
560 |
|
561 HBufC8* message = HBufC8::New( ISI_HEADER_SIZE + SIZE_PNS_NAME_ADD_REQ ); |
|
562 TInt err( KErrGeneral ); |
|
563 |
|
564 if( message ) |
|
565 { |
|
566 TPtr8 messageptr = message->Des(); |
|
567 messageptr.FillZ(); |
|
568 |
|
569 // Add 32bit name (Big-endian) |
|
570 iName.Append( aClientObjId ); |
|
571 iName.Append( PN_PEP_SUB_TYPE_SYMBIAN_INTERNAL ); |
|
572 iName.Append( PN_PEP_TYPE_COMMON ); |
|
573 iName.Append( PN_PIPE ); |
|
574 TUint8 nameOffset( ISI_HEADER_SIZE + PNS_NAME_ADD_REQ_OFFSET_NAMEENTRY ); |
|
575 |
|
576 TIsiSend isimessage( messageptr, ISI_HEADER_SIZE + SIZE_PNS_NAME_ADD_REQ ); |
|
577 isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_NAMESERVICE ); |
|
578 isimessage.Set8bit( ISI_HEADER_OFFSET_TRANSID, 0 ); |
|
579 isimessage.Set8bit( ISI_HEADER_OFFSET_MESSAGEID, PNS_NAME_ADD_REQ ); |
|
580 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_ADD_REQ_OFFSET_RESERVED1, KPadding ); |
|
581 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_ADD_REQ_OFFSET_RESERVED2, KPadding ); |
|
582 isimessage.Set8bit( nameOffset, iName[0] ); |
|
583 isimessage.Set8bit( nameOffset + 1, iName[1] ); |
|
584 isimessage.Set8bit( nameOffset + 2, iName[2] ); |
|
585 isimessage.Set8bit( nameOffset + 3, iName[3] ); |
|
586 isimessage.Set8bit( nameOffset + PN_NAME_SRV_ITEM_STR_OFFSET_DEV, THIS_DEVICE ); |
|
587 isimessage.Set8bit( nameOffset + PN_NAME_SRV_ITEM_STR_OFFSET_OBJ, aObjId ); |
|
588 isimessage.Set8bit( nameOffset + PN_NAME_SRV_ITEM_STR_OFFSET_FLAGS, PN_NAME_UNDEF ); |
|
589 isimessage.Set8bit( nameOffset + PN_NAME_SRV_ITEM_STR_OFFSET_RESERVED, KPadding ); |
|
590 isimessage.Complete(); |
|
591 |
|
592 err = iIscApi.Send( messageptr ); |
|
593 C_TRACE( (_T("CBcaToIsc::SendNameAddReq() success: 0x%x"), err ) ); |
|
594 delete message; |
|
595 } |
|
596 else |
|
597 { |
|
598 C_TRACE( (_T("CBcaToIsc::SendNameAddReq() memory allocation failed") ) ); |
|
599 ASSERT(0); |
|
600 } |
|
601 |
|
602 C_TRACE( (_T("CBcaToIsc::SendNameAddReq() <-") ) ); |
|
603 return err; |
|
604 } |
|
605 |
|
606 /** |
|
607 * Sends PNS_NAME_REMOVE_REQ |
|
608 |
|
609 * @return KErrNone if message sent succesfully, otherwise error code |
|
610 */ |
|
611 TInt CBcaToIsc::SendNameRemoveReq() |
|
612 { |
|
613 C_TRACE( (_T("CBcaToIsc::SendNameRemoveReq() ->") ) ); |
|
614 |
|
615 HBufC8* message = HBufC8::New( ISI_HEADER_SIZE + SIZE_PNS_NAME_REMOVE_REQ ); |
|
616 TInt err( KErrGeneral ); |
|
617 if( message ) |
|
618 { |
|
619 TPtr8 messageptr = message->Des(); |
|
620 messageptr.FillZ(); |
|
621 TUint8 nameOffset( ISI_HEADER_SIZE + PNS_NAME_REMOVE_REQ_OFFSET_NAME ); |
|
622 |
|
623 TIsiSend isimessage( messageptr, ISI_HEADER_SIZE + SIZE_PNS_NAME_REMOVE_REQ ); |
|
624 isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_NAMESERVICE ); |
|
625 isimessage.Set8bit( ISI_HEADER_OFFSET_TRANSID , 0 ); |
|
626 isimessage.Set8bit( ISI_HEADER_OFFSET_MESSAGEID, PNS_NAME_REMOVE_REQ ); |
|
627 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_REMOVE_REQ_OFFSET_RESERVED1, KPadding ); |
|
628 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_NAME_REMOVE_REQ_OFFSET_RESERVED2, KPadding ); |
|
629 isimessage.Set8bit( nameOffset, iName[0] ); |
|
630 isimessage.Set8bit( nameOffset + 1, iName[1] ); |
|
631 isimessage.Set8bit( nameOffset + 2, iName[2] ); |
|
632 isimessage.Set8bit( nameOffset + 3, iName[3] ); |
|
633 isimessage.Complete(); |
|
634 err = iIscApi.Send( messageptr ); |
|
635 C_TRACE( (_T("CBcaToIsc::SendNameRemoveReq() success: 0x%x"), err ) ); |
|
636 delete message; |
|
637 } |
|
638 else |
|
639 { |
|
640 C_TRACE( (_T("CBcaToIsc::SendNameRemoveReq() memory allocation failed") ) ); |
|
641 ASSERT(0); |
|
642 } |
|
643 |
|
644 C_TRACE( (_T("CBcaToIsc::SendNameRemoveReq() <-") ) ); |
|
645 return err; |
|
646 } |
|
647 |
|
648 /** |
|
649 * Sends PNS_PEP_CTRL_RESP |
|
650 |
|
651 * @return KErrNone if message sent succesfully, otherwise error code |
|
652 */ |
|
653 TInt CBcaToIsc::SendPepCtrlResp( |
|
654 TUint8 aTrId, |
|
655 TUint8 aReceiverDev, |
|
656 TUint8 aReceiverObj, |
|
657 TUint8 aPipeHandle, |
|
658 TUint8 aPepCtrlId, |
|
659 TUint8 aPepType, |
|
660 TUint8 aResult ) |
|
661 { |
|
662 C_TRACE( (_T("CBcaToIsc::SendPepCtrlResp() ->") ) ); |
|
663 |
|
664 HBufC8* message = HBufC8::New( ISI_HEADER_SIZE + SIZE_PNS_PEP_CTRL_RESP ); |
|
665 TInt err( KErrGeneral ); |
|
666 |
|
667 if( message ) |
|
668 { |
|
669 TPtr8 messageptr = message->Des(); |
|
670 messageptr.FillZ(); |
|
671 |
|
672 TIsiSend isimessage( messageptr, ISI_HEADER_SIZE + SIZE_PNS_PEP_CTRL_RESP ); |
|
673 isimessage.Set8bit( ISI_HEADER_OFFSET_RECEIVERDEVICE, aReceiverDev); |
|
674 isimessage.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_PIPE); |
|
675 isimessage.Set8bit( ISI_HEADER_OFFSET_RECEIVEROBJECT, aReceiverObj); |
|
676 isimessage.Set8bit( ISI_HEADER_OFFSET_TRANSID , aTrId); |
|
677 isimessage.Set8bit( ISI_HEADER_OFFSET_MESSAGEID, PNS_PEP_CTRL_RESP ); |
|
678 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PEP_CTRL_RESP_OFFSET_PIPEHANDLE, aPipeHandle ); |
|
679 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PEP_CTRL_RESP_OFFSET_PEPCTRLID, aPepCtrlId ); |
|
680 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PEP_CTRL_RESP_OFFSET_PEPTYPE, aPepType ); |
|
681 isimessage.Set8bit( ISI_HEADER_SIZE + PNS_PEP_CTRL_RESP_OFFSET_ERRORCODE, aResult ); |
|
682 isimessage.Complete(); |
|
683 err = iIscApi.Send( messageptr ); |
|
684 C_TRACE( (_T("CBcaToIsc::SendPepCtrlResp() success: 0x%x"), err ) ); |
|
685 delete message; |
|
686 } |
|
687 else |
|
688 { |
|
689 C_TRACE( (_T("CBcaToIsc::SendPepCtrlResp() memory allocation failed") ) ); |
|
690 ASSERT(0); |
|
691 } |
|
692 |
|
693 C_TRACE( (_T("CBcaToIsc::SendPepCtrlResp() <-") ) ); |
|
694 return err; |
|
695 } |
|
696 |
|
697 /** |
|
698 * Handles received messages |
|
699 |
|
700 * @param aObjId object id for the name to be added |
|
701 * @return KErrNone if message sent succesfully, otherwise error code |
|
702 */ |
|
703 void CBcaToIsc::RunL() |
|
704 { |
|
705 C_TRACE( (_T("CBcaToIsc::RunL() ->") ) ); |
|
706 |
|
707 if ( KErrNone == iStatus.Int() ) |
|
708 { |
|
709 HandleReceivedMsg( TIsiReceiveC( iMessageBufferPtr ) ); |
|
710 } |
|
711 else |
|
712 { |
|
713 C_TRACE( (_T("CBcaToIsc::RunL() error occured: 0x%x"), iStatus.Int() ) ); |
|
714 ASSERT(0); |
|
715 } |
|
716 |
|
717 C_TRACE( (_T("CBcaToIsc::RunL() <-") ) ); |
|
718 } |
|
719 |
|
720 /** |
|
721 * Handles cancel operation for this active object |
|
722 |
|
723 */ |
|
724 void CBcaToIsc::DoCancel() |
|
725 { |
|
726 C_TRACE( (_T("CBcaToIsc::DoCancel() ->") ) ); |
|
727 iIscApi.ReceiveCancel(); |
|
728 C_TRACE( (_T("CBcaToIsc::DoCancel() <-") ) ); |
|
729 } |
|
730 |
|
731 /** |
|
732 * Handles received message |
|
733 |
|
734 */ |
|
735 void CBcaToIsc::HandleReceivedMsg( const TIsiReceiveC& aIsiMsg ) |
|
736 { |
|
737 C_TRACE( (_T("CBcaToIsc::HandleReceivedMsg() ->") ) ); |
|
738 |
|
739 TInt resource( aIsiMsg.Get8bit( ISI_HEADER_OFFSET_RESOURCEID ) ); |
|
740 |
|
741 switch( resource ) |
|
742 { |
|
743 case PN_NAMESERVICE: |
|
744 { |
|
745 HandleNameServiceMsg( aIsiMsg ); |
|
746 break; |
|
747 } |
|
748 case PN_PIPE: |
|
749 { |
|
750 HandlePipeMsg( aIsiMsg ); |
|
751 break; |
|
752 } |
|
753 default: |
|
754 { |
|
755 C_TRACE( (_T("CBcaToIsc::HandleReceivedMsg() unknown resource 0x%x"), resource ) ); |
|
756 ASSERT(0); |
|
757 break; |
|
758 } |
|
759 } |
|
760 |
|
761 C_TRACE( (_T("CBcaToIsc::HandleReceivedMsg() <-") ) ); |
|
762 } |
|
763 |
|
764 /** |
|
765 * Handles received messages from resource PN_NAME |
|
766 |
|
767 */ |
|
768 void CBcaToIsc::HandleNameServiceMsg( const TIsiReceiveC& aIsiMsg ) |
|
769 { |
|
770 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() ->") ) ); |
|
771 |
|
772 TInt msgId( aIsiMsg.Get8bit( ISI_HEADER_OFFSET_MESSAGEID ) ); |
|
773 switch( msgId ) |
|
774 { |
|
775 case PNS_NAME_ADD_RESP: |
|
776 { |
|
777 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() PNS_NAME_ADD_RESP") ) ); |
|
778 TUint8 reason( aIsiMsg.Get8bit( |
|
779 ISI_HEADER_SIZE + PNS_NAME_ADD_RESP_OFFSET_REASON ) ); |
|
780 if( PN_NAME_OK != reason ) |
|
781 { |
|
782 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() Name adding failed: 0x%x"), reason ) ); |
|
783 if( iClientOpenStatus ) |
|
784 { |
|
785 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() completing open") ) ); |
|
786 User::RequestComplete( iClientOpenStatus, KErrGeneral ); |
|
787 iClientOpenStatus = NULL; |
|
788 iIscApi.Close(); |
|
789 } |
|
790 // no else |
|
791 } |
|
792 else |
|
793 { |
|
794 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() Name added succesfully") ) ); |
|
795 iMessageBufferPtr.SetLength( 0 ); |
|
796 iStatus = KRequestPending; |
|
797 iIscApi.Receive( iStatus, iMessageBufferPtr, iReadLength ); |
|
798 SetActive(); |
|
799 } |
|
800 break; |
|
801 } |
|
802 case PNS_NAME_REMOVE_RESP: |
|
803 { |
|
804 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() PNS_NAME_REMOVE_RESP") ) ); |
|
805 TUint8 reason( aIsiMsg.Get8bit( |
|
806 ISI_HEADER_SIZE + PNS_NAME_ADD_RESP_OFFSET_REASON ) ); |
|
807 if( PN_NAME_OK != reason ) |
|
808 { |
|
809 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() Name removing failed: 0x%x"), reason ) ); |
|
810 ASSERT(0); |
|
811 if( iClientShutdownStatus ) |
|
812 { |
|
813 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() completing shutdown") ) ); |
|
814 User::RequestComplete(iClientShutdownStatus, KErrGeneral ); |
|
815 iClientShutdownStatus = NULL; |
|
816 } |
|
817 } |
|
818 else |
|
819 { |
|
820 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() Name removed succesfully") ) ); |
|
821 iName.Zero(); |
|
822 iMessageBufferPtr.SetLength( 0 ); |
|
823 iStatus = KRequestPending; |
|
824 iIscApi.Receive( iStatus, iMessageBufferPtr, iReadLength ); |
|
825 SetActive(); |
|
826 } |
|
827 break; |
|
828 } |
|
829 default: |
|
830 { |
|
831 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() unknown msg 0x%x"), msgId ) ); |
|
832 break; |
|
833 } |
|
834 } |
|
835 |
|
836 C_TRACE( (_T("CBcaToIsc::HandleNameServiceMsg() <-") ) ); |
|
837 } |
|
838 |
|
839 /** |
|
840 * Handles received messages from resource PN_PIPE |
|
841 |
|
842 */ |
|
843 void CBcaToIsc::HandlePipeMsg( const TIsiReceiveC& aIsiMsg ) |
|
844 { |
|
845 C_TRACE( (_T("CBcaToIsc::HandlePipeMsg() ->") ) ); |
|
846 |
|
847 TInt msgId( aIsiMsg.Get8bit( ISI_HEADER_OFFSET_MESSAGEID ) ); |
|
848 switch( msgId ) |
|
849 { |
|
850 case PNS_PEP_CTRL_REQ: |
|
851 { |
|
852 C_TRACE( (_T("CBcaToIsc::HandlePipeMsg() PNS_PEP_CTRL_REQ") ) ); |
|
853 HandlePepCtrlReq( aIsiMsg ); |
|
854 break; |
|
855 } |
|
856 default: |
|
857 { |
|
858 C_TRACE( (_T("CBcaToIsc::HandlePipeMsg() unknown msg 0x%x"), msgId ) ); |
|
859 ASSERT(0); |
|
860 break; |
|
861 } |
|
862 } |
|
863 |
|
864 C_TRACE( (_T("CBcaToIsc::HandlePipeMsg() <-") ) ); |
|
865 } |
|
866 |
|
867 /** |
|
868 * Handles PNS_PEP_CTRL_REQ |
|
869 |
|
870 */ |
|
871 void CBcaToIsc::HandlePepCtrlReq( const TIsiReceiveC& aIsiMsg ) |
|
872 { |
|
873 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() ->") ) ); |
|
874 |
|
875 TUint8 pipeHandle( aIsiMsg.Get8bit( |
|
876 ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PIPEHANDLE ) ); |
|
877 TUint8 pepCtrlId( aIsiMsg.Get8bit( |
|
878 ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PEPCTRLID ) ); |
|
879 TUint8 pepType( aIsiMsg.Get8bit( |
|
880 ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PEPTYPE ) ); |
|
881 TUint8 result( PN_PIPE_ERR_NOT_SUPPORTED ); |
|
882 |
|
883 TUint8 trId( aIsiMsg.Get8bit( |
|
884 ISI_HEADER_OFFSET_TRANSID ) ); |
|
885 // Get sender device |
|
886 TUint8 senderDevice( aIsiMsg.Get8bit( |
|
887 ISI_HEADER_OFFSET_SENDERDEVICE ) ); |
|
888 // Get sender object |
|
889 TUint8 senderObject( aIsiMsg.Get8bit( |
|
890 ISI_HEADER_OFFSET_SENDEROBJECT ) ); |
|
891 |
|
892 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() pipe handle: 0x%x"), pipeHandle ) ); |
|
893 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() pep ctrl id: 0x%x"), pepCtrlId ) ); |
|
894 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() pep type: 0x%x"), pepType ) ); |
|
895 |
|
896 TBuf8<KDataLength> data( aIsiMsg.GetData( |
|
897 ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PEPCTRLDATA, |
|
898 KDataLength ) ); |
|
899 |
|
900 TUint8 devId( data[KDevIdIndex] ); |
|
901 TUint8 objId( data[KObjIdIndex] ); |
|
902 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() dev id: 0x%x"), devId ) ); |
|
903 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() obj id: 0x%x"), objId ) ); |
|
904 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() iChannelNumber: 0x%x"), iChannelNumber ) ); |
|
905 |
|
906 if( PN_PEP_TYPE_BCA == pepType && |
|
907 THIS_DEVICE == devId && |
|
908 iChannelNumber == objId ) |
|
909 { |
|
910 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() PNS_PEP_CTRL_REQ for this PEP") ) ); |
|
911 result = PN_PIPE_NO_ERROR; |
|
912 TInt ret( KErrNone ); |
|
913 |
|
914 if( PEP_BCA_OK != data[KStatusIndex] ) |
|
915 { |
|
916 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() PNS_PEP_CTRL_REQ with error 0x%x"), data[KStatusIndex] ) ); |
|
917 ret = KErrGeneral; |
|
918 } |
|
919 |
|
920 if( PEP_CTRL_ID_LOAN == pepCtrlId ) |
|
921 { |
|
922 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() ctrl id PEP_CTRL_ID_LOAN") ) ); |
|
923 if( iClientOpenStatus ) |
|
924 { |
|
925 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() completing open") ) ); |
|
926 User::RequestComplete( iClientOpenStatus, ret ); |
|
927 iClientOpenStatus = NULL; |
|
928 } |
|
929 } |
|
930 else if( PEP_CTRL_ID_RETURNLOAN == pepCtrlId ) |
|
931 { |
|
932 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() ctrl id PEP_CTRL_ID_RETURNLOAN") ) ); |
|
933 if( iClientShutdownStatus ) |
|
934 { |
|
935 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() completing shutdown") ) ); |
|
936 User::RequestComplete(iClientShutdownStatus, ret); |
|
937 iClientShutdownStatus = NULL; |
|
938 } |
|
939 } |
|
940 } |
|
941 |
|
942 SendPepCtrlResp( |
|
943 trId, |
|
944 senderDevice, |
|
945 senderObject, |
|
946 pipeHandle, |
|
947 pepCtrlId, |
|
948 pepType, |
|
949 result ); |
|
950 |
|
951 C_TRACE( (_T("CBcaToIsc::HandlePepCtrlReq() <-") ) ); |
|
952 } |
|
953 |
|
954 |