1 // Copyright (c) 2005-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 // |
|
15 |
|
16 #include <obex/transport/obexconnector.h> |
|
17 #include "ObexListenerRfcommConnector.h" |
|
18 #include "connectobserver.h" |
|
19 #include "logger.h" |
|
20 #include "obexbtfaults.h" |
|
21 |
|
22 #ifdef __FLOG_ACTIVE |
|
23 _LIT8(KLogComponent, "RFCOMM"); |
|
24 #endif |
|
25 |
|
26 #ifdef _DEBUG |
|
27 _LIT(KPanicCat, "ListRfcomm"); |
|
28 #endif |
|
29 |
|
30 CObexListenerRfcommConnector::CObexListenerRfcommConnector(MConnectObserver& aParent, |
|
31 RSocketServ& aSocketServ, |
|
32 RSocket& aSocket, |
|
33 const TProtocolDesc& aProtocolDesc, |
|
34 TBTSockAddr& aAddr) |
|
35 : CActive(EPriorityStandard), |
|
36 iParent(aParent), |
|
37 iSocketServ(aSocketServ), |
|
38 iSocket(aSocket), |
|
39 iProtocolDesc(aProtocolDesc), |
|
40 iAddr(aAddr) |
|
41 { |
|
42 LOG_FUNC |
|
43 LOG(_L8("\taAddr:")); |
|
44 LOGHEXDESC(aAddr); |
|
45 |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 CObexListenerRfcommConnector::~CObexListenerRfcommConnector() |
|
50 { |
|
51 LOG_FUNC |
|
52 |
|
53 Cancel(); |
|
54 |
|
55 // iListeningSocket will only have been open if there was a request |
|
56 // outstanding, in which case it will have been closed in DoCancel, so no |
|
57 // need to do it here. |
|
58 __ASSERT_DEBUG(!iListeningSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
59 } |
|
60 |
|
61 void CObexListenerRfcommConnector::RunL() |
|
62 { |
|
63 LOG_LINE |
|
64 LOG_FUNC |
|
65 LOG1(_L8("\tiStatus = %d"), iStatus.Int()); |
|
66 |
|
67 // These exists purely as sanity-checks on our internal state. |
|
68 __ASSERT_DEBUG(iSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
69 __ASSERT_DEBUG(iListeningSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
70 |
|
71 TObexConnectionInfo sockinfo; |
|
72 if ( iStatus == KErrNone ) |
|
73 { |
|
74 sockinfo.iSocketType = TObexConnectionInfo::ESocketStream; |
|
75 |
|
76 TPckgBuf<TUint> optBuf(65535); //If all else fails we should get a max 64K buffer |
|
77 iSocket.GetOpt(KRFCOMMMaximumMTU, KSolBtRFCOMM, optBuf); |
|
78 |
|
79 // Set socket buffer sizes based on negotiated MTU |
|
80 iSocket.SetOpt(KSOSendBuf, KSOLSocket, optBuf); |
|
81 iSocket.SetOpt(KSORecvBuf, KSOLSocket, optBuf); |
|
82 } |
|
83 else |
|
84 { |
|
85 iSocket.Close(); |
|
86 } |
|
87 |
|
88 iListeningSocket.Close(); |
|
89 iParent.ConnectComplete(iStatus.Int(), sockinfo); |
|
90 } |
|
91 |
|
92 void CObexListenerRfcommConnector::DoCancel() |
|
93 { |
|
94 LOG_FUNC |
|
95 |
|
96 // These exist purely as sanity-checks on our internal state. |
|
97 __ASSERT_DEBUG(iSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
98 __ASSERT_DEBUG(iListeningSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
99 iListeningSocket.CancelAccept(); |
|
100 iListeningSocket.Close(); |
|
101 iSocket.Close(); |
|
102 } |
|
103 |
|
104 void CObexListenerRfcommConnector::AcceptL() |
|
105 { |
|
106 LOG_FUNC |
|
107 |
|
108 __ASSERT_DEBUG(!iSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
109 |
|
110 __ASSERT_DEBUG(!iListeningSocket.SubSessionHandle(), PANIC(KPanicCat, EListRfcommInternalError)); |
|
111 LEAVEIFERRORL(iListeningSocket.Open(iSocketServ, |
|
112 iProtocolDesc.iAddrFamily, |
|
113 iProtocolDesc.iSockType, |
|
114 iProtocolDesc.iProtocol)); |
|
115 CleanupClosePushL(iListeningSocket); |
|
116 |
|
117 LEAVEIFERRORL(iListeningSocket.Bind(iAddr)); |
|
118 if ( iAddr.Port() == KRfcommPassiveAutoBind ) |
|
119 { |
|
120 const TUint port = iListeningSocket.LocalPort(); |
|
121 LOG1(_L8("\tKRfcommPassiveAutoBind was specified- really using port %d"), port); |
|
122 // This updates the concrete transport controller's iTransportInfo member (by reference). |
|
123 iAddr.SetPort(port); |
|
124 } |
|
125 // We try to set the Object Transfer bit in our service class. If this fails we |
|
126 // ignore it, as it's better to carry on without it than to fail to start listening. |
|
127 (void)iListeningSocket.SetOpt(KBTRegisterCodService, KSolBtRFCOMM, EMajorServiceObjectTransfer); |
|
128 LEAVEIFERRORL(iListeningSocket.Listen(4)); // queue size of 4 |
|
129 |
|
130 // NB Client does SDP & Sec registration. |
|
131 |
|
132 LEAVEIFERRORL(iSocket.Open(iSocketServ)); |
|
133 |
|
134 CleanupStack::Pop(&iListeningSocket); |
|
135 |
|
136 iListeningSocket.Accept(iSocket, iStatus); |
|
137 SetActive(); |
|
138 } |
|