|
1 /* |
|
2 * Copyright (c) 2005-2006 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: The connect state definition |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "btengdiscovery.h" |
|
21 #include "btengconstants.h" |
|
22 #include "btmsconnect.h" |
|
23 #include "btmslisten.h" |
|
24 #include "btmsrfcomm.h" |
|
25 #include "btmsctrl.h" |
|
26 #include "btmsopenaudio.h" |
|
27 #include "btmrfcommsock.h" |
|
28 #include "btmactive.h" |
|
29 #include "debug.h" |
|
30 |
|
31 const TInt KSearchHandsfreeChannel = 1; |
|
32 const TInt KSearchHeadsetChannel = 2; |
|
33 const TInt KSearchCompleted = 3; |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 CBtmsConnect* CBtmsConnect::NewL(CBtmMan& aParent, TRequestStatus* aRequest, |
|
38 const TBTDevAddr& aAddr, TRequestCategory aRequestCat) |
|
39 { |
|
40 CBtmsConnect* self = new( ELeave ) CBtmsConnect(aParent, aRequest, aAddr, aRequestCat); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop(self); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CBtmsConnect::~CBtmsConnect() |
|
48 { |
|
49 TRACE_FUNC_ENTRY |
|
50 delete iBteng; |
|
51 delete iRfcomm; |
|
52 delete iDevice; |
|
53 TRACE_FUNC_EXIT |
|
54 } |
|
55 |
|
56 void CBtmsConnect::EnterL() |
|
57 { |
|
58 TRACE_STATE(_L("[BTMAC State] Connect")) |
|
59 *StateRequest() = KRequestPending; |
|
60 iSearchState = KSearchHandsfreeChannel; |
|
61 TInt err = iBteng->RemoteProtocolChannelQuery(iSockAddr.BTAddr(), EBTProfileHFP); |
|
62 if(err) |
|
63 { |
|
64 CompleteStateRequest(err); |
|
65 } |
|
66 } |
|
67 |
|
68 void CBtmsConnect::CancelConnectL() |
|
69 { |
|
70 TRACE_FUNC |
|
71 if (iRequestCat == ERequestConnect) |
|
72 { |
|
73 if (iRfcomm) |
|
74 { |
|
75 iRfcomm->CancelConnect(); |
|
76 } |
|
77 if (iBteng) |
|
78 { |
|
79 iBteng->CancelRemoteSdpQuery(); |
|
80 } |
|
81 CompleteStateRequest(KErrCancel); |
|
82 Parent().ChangeStateL(CBtmsListen::NewL(Parent())); |
|
83 } |
|
84 } |
|
85 |
|
86 void CBtmsConnect::CancelOpenAudioLinkL(const TBTDevAddr& aAddr) |
|
87 { |
|
88 TRACE_FUNC |
|
89 if (aAddr == iSockAddr.BTAddr() && iRequestCat == ERequestOpenAudio) |
|
90 { |
|
91 CompleteStateRequest(KErrCancel); |
|
92 iRequestCat = ERequestNone; |
|
93 } |
|
94 } |
|
95 |
|
96 CBtmRfcommSock* SwapRfcommSock(CBtmRfcommSock*& aSock) |
|
97 { |
|
98 CBtmRfcommSock* sock = aSock; |
|
99 aSock = NULL; |
|
100 return sock; |
|
101 } |
|
102 |
|
103 void CBtmsConnect::RfcommConnectCompletedL(TInt aErr) |
|
104 { |
|
105 TRACE_FUNC |
|
106 if (aErr) |
|
107 { |
|
108 CompleteStateRequest(aErr); |
|
109 Parent().ChangeStateL(CBtmsListen::NewL(Parent())); |
|
110 } |
|
111 else |
|
112 { |
|
113 if (iRfcomm->Service() == EBTProfileHFP) |
|
114 { |
|
115 Parent().ChangeStateL(CBtmsRfcomm::NewL(Parent(),SwapStateRequest(), SwapRfcommSock(iRfcomm), iRequestCat)); |
|
116 } |
|
117 else |
|
118 { |
|
119 if (iRequestCat == ERequestConnect) |
|
120 { |
|
121 CompleteStateRequest(aErr); |
|
122 Parent().ChangeStateL(CBtmsCtrl::NewL(Parent(), SwapRfcommSock(iRfcomm), NULL)); |
|
123 } |
|
124 else if (iRequestCat == ERequestConnect) |
|
125 { |
|
126 Parent().ChangeStateL(CBtmsOpenAudio::NewL(Parent(),SwapStateRequest(), SwapRfcommSock(iRfcomm), NULL)); |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 void CBtmsConnect::AttributeSearchComplete( TSdpServRecordHandle /*aHandle*/, const RSdpResultArray &aAttr, TInt aErr ) |
|
133 { |
|
134 TRACE_FUNC |
|
135 if (iSearchState == KSearchHandsfreeChannel) |
|
136 { |
|
137 if (aErr == KErrNone || (aErr == KErrEof && aAttr.Count()>0)) |
|
138 { |
|
139 RSdpResultArray attr(aAttr); |
|
140 CBTEngDiscovery::ParseRfcommChannel(attr, iRemoteChannel); |
|
141 TRACE_INFO((_L("HFP channel %d"), iRemoteChannel)) |
|
142 TRAP_IGNORE(DoSockConnectL(EBTProfileHFP)); |
|
143 iSearchState = KSearchCompleted; |
|
144 } |
|
145 else if (aErr == KErrEof && aAttr.Count()== 0) |
|
146 { |
|
147 iSearchState = KSearchHeadsetChannel; |
|
148 iBteng->RemoteProtocolChannelQuery(iSockAddr.BTAddr(), EBTProfileHSP); |
|
149 } |
|
150 else |
|
151 { |
|
152 CompleteStateRequest(aErr); |
|
153 TRAP_IGNORE(Parent().ChangeStateL(CBtmsListen::NewL(Parent()))); |
|
154 } |
|
155 } |
|
156 else if (iSearchState == KSearchHeadsetChannel) |
|
157 { |
|
158 if (aErr == KErrNone || (aErr == KErrEof && aAttr.Count()>0)) |
|
159 { |
|
160 RSdpResultArray attr(aAttr); |
|
161 CBTEngDiscovery::ParseRfcommChannel(attr, iRemoteChannel); |
|
162 TRACE_INFO((_L("HSP channel %d"), iRemoteChannel)) |
|
163 TRAP_IGNORE(DoSockConnectL(EBTProfileHSP)); |
|
164 iSearchState = KSearchCompleted; |
|
165 } |
|
166 else |
|
167 { |
|
168 CompleteStateRequest(aErr); |
|
169 TRAP_IGNORE(Parent().ChangeStateL(CBtmsListen::NewL(Parent()))); |
|
170 } |
|
171 } |
|
172 } |
|
173 |
|
174 |
|
175 CBtmsConnect::CBtmsConnect(CBtmMan& aParent, TRequestStatus* aRequest, |
|
176 const TBTDevAddr& aAddr, TRequestCategory aRequestCat) |
|
177 : CBtmState(aParent, aRequest), iRequestCat(aRequestCat) |
|
178 { |
|
179 iSockAddr.SetBTAddr(aAddr); |
|
180 } |
|
181 |
|
182 void CBtmsConnect::ConstructL() |
|
183 { |
|
184 TRACE_FUNC |
|
185 iBteng = CBTEngDiscovery::NewL(this); |
|
186 iRfcomm = CBtmRfcommSock::NewL(*this, Parent().SockServ()); |
|
187 } |
|
188 |
|
189 void CBtmsConnect::DoSockConnectL(TUint aService) |
|
190 { |
|
191 TRACE_FUNC |
|
192 iSockAddr.SetBTAddr(iSockAddr.BTAddr()); |
|
193 TBTServiceSecurity sec; |
|
194 sec.SetAuthentication(ETrue); |
|
195 sec.SetEncryption(ETrue); |
|
196 iSockAddr.SetSecurity(sec); |
|
197 iSockAddr.SetPort(iRemoteChannel); |
|
198 iRfcomm->ConnectL(iSockAddr, aService); |
|
199 } |
|
200 void CBtmsConnect::ServiceSearchComplete( const RSdpRecHandleArray& /*aResult*/, TUint /*aTotalRecordsCount*/, TInt /*aErr*/) {} |
|
201 |
|
202 void CBtmsConnect::DeviceSearchComplete( CBTDevice* /*aDevice*/, TInt /*aErr*/ ) {} |
|
203 |
|
204 void CBtmsConnect::ServiceAttributeSearchComplete( TSdpServRecordHandle aHandle, const RSdpResultArray& aAttr, TInt aErr ) |
|
205 { |
|
206 AttributeSearchComplete(aHandle, aAttr, aErr); |
|
207 } |
|
208 |