|
1 // Copyright (c) 2003-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 // Implements the avdtp local SEP |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <bluetooth/logger.h> |
|
24 #include "avdtpLocalSEP.h" |
|
25 #include "avdtpStream.h" |
|
26 #include "avdtp.h" |
|
27 #include "avdtputil.h" |
|
28 |
|
29 #ifdef __FLOG_ACTIVE |
|
30 _LIT8(KLogComponent, LOG_COMPONENT_AVDTP); |
|
31 #endif |
|
32 |
|
33 /* |
|
34 @param aSEPInfo is an in and out parameter |
|
35 inbound there is no SEID set, but this class on construction writes back the assigned SEID |
|
36 */ |
|
37 CLocalSEP* CLocalSEP::NewL(TAvdtpSEPInfo& aSEPInfo, TSEIDManager& aSEIDManager) |
|
38 { |
|
39 LOG_STATIC_FUNC |
|
40 CLocalSEP* sep = new (ELeave) CLocalSEP; |
|
41 CleanupStack::PushL(sep); |
|
42 sep->ConstructL(aSEPInfo, aSEIDManager); |
|
43 CleanupStack::Pop(sep); |
|
44 return sep; |
|
45 } |
|
46 |
|
47 CLocalSEP::CLocalSEP() : iPreConfigured(ETrue) |
|
48 { |
|
49 LOG_FUNC |
|
50 } |
|
51 |
|
52 void CLocalSEP::ConstructL(TAvdtpSEPInfo& aSEPInfo, TSEIDManager& aSEIDManager) |
|
53 { |
|
54 LOG_FUNC |
|
55 |
|
56 // store client's settings of sink-ness, codec type etc |
|
57 iInfo = aSEPInfo; |
|
58 // assign RSEID to us, and return for client knowledge |
|
59 User::LeaveIfError(aSEIDManager.GetSEID(iLocalSEID)); |
|
60 |
|
61 // store for remote-acquisition |
|
62 iInfo.SetSEID(iLocalSEID.SEID()); |
|
63 |
|
64 // update client with seid details |
|
65 aSEPInfo = iInfo; |
|
66 |
|
67 LOG1(_L("Assigned SEID %d"), aSEPInfo.SEID().SEID()); |
|
68 __ASSERT_DEBUG(iInfo.SEID().IsLocal(), Panic(EAvdtpSEIDHasWrongDomain)); |
|
69 } |
|
70 |
|
71 /* |
|
72 add or change a capability |
|
73 */ |
|
74 void CLocalSEP::AddCapability(const TAvdtpServiceCapability* aCapability) |
|
75 { |
|
76 LOG_FUNC |
|
77 // take heap copy to persist this blob of data |
|
78 __ASSERT_DEBUG(aCapability, Panic(EAvdtpBadLocalSEPUpdate)); |
|
79 |
|
80 TAvdtpServiceCategory c = aCapability->Category(); |
|
81 if (iCapabilities[c]) |
|
82 { |
|
83 delete iCapabilities[c]; |
|
84 } |
|
85 iCapabilities[c] = const_cast<TAvdtpServiceCapability*>(aCapability); |
|
86 iCapabilityCategories.SetCapability(c); |
|
87 } |
|
88 |
|
89 CLocalSEP::~CLocalSEP() |
|
90 { |
|
91 LOG_FUNC |
|
92 iLocalSEID.Close(); |
|
93 iCapabilities.DeleteAll(); |
|
94 iConfiguration.DeleteAll(); |
|
95 if (iStream) |
|
96 { |
|
97 iStream->LocalSEPDestroyed(*this); |
|
98 } |
|
99 iPendingConfigurationProtocolDomain.Close(); |
|
100 delete iSecurityControl; |
|
101 } |
|
102 |
|
103 /* |
|
104 Is the Local SEP in a state where it will accept pending configuration to be set. |
|
105 Returns KErrNone if a subsequent call to SetPendingConfiguration() will succeed |
|
106 otherwise an AVDTP error code. |
|
107 */ |
|
108 TInt CLocalSEP::CheckConfigurationState(TBool aIsReconfig) const |
|
109 { |
|
110 LOG_FUNC |
|
111 TInt ret = KErrNone; |
|
112 if (InUse() && !aIsReconfig) |
|
113 { |
|
114 ret = SymbianBluetoothAV::ConvertToSymbianError::AvdtpError(EAvdtpSEPInUse); |
|
115 } |
|
116 else if (!InUse() && aIsReconfig) |
|
117 { |
|
118 ret = SymbianBluetoothAV::ConvertToSymbianError::AvdtpError(EAvdtpSepNotInUse); |
|
119 } |
|
120 else |
|
121 { |
|
122 if (iPendingConfigurationProtocolDomain.Length()) |
|
123 { |
|
124 // remote sent us while already setting configuration |
|
125 ret = SymbianBluetoothAV::ConvertToSymbianError::AvdtpError(EAvdtpBadState); |
|
126 } |
|
127 } |
|
128 return ret; |
|
129 } |
|
130 |
|
131 /* |
|
132 The pending configuration is set for a period of time before the configuration |
|
133 is committed. |
|
134 |
|
135 For an incoming (re)configure, the pending configuration is set when AVDTP |
|
136 receives the (re)configure request and committed when GAVDP processes the |
|
137 resulting indication and sends the (re)configure response. |
|
138 |
|
139 For an outgoing (re)configure, the pending configuration is set when we send |
|
140 the (re)configure request and committed when we receive the (re)configure |
|
141 response. |
|
142 */ |
|
143 TInt CLocalSEP::SetPendingConfiguration(const RBuf8& aConfigProtocolDomain, TBool aIsReconfig) |
|
144 { |
|
145 LOG_FUNC |
|
146 TInt ret = CheckConfigurationState(aIsReconfig); |
|
147 |
|
148 if (ret == KErrNone) |
|
149 { |
|
150 // take ownership of config |
|
151 iPendingConfigurationProtocolDomain.Assign(aConfigProtocolDomain); |
|
152 } |
|
153 |
|
154 return ret; |
|
155 } |
|
156 |
|
157 |
|
158 void CLocalSEP::SetRemoteSEID(TSEID aINTSEID) |
|
159 { |
|
160 LOG_FUNC |
|
161 iRemoteSEID = aINTSEID; |
|
162 __ASSERT_DEBUG(!iRemoteSEID.IsLocal(), Panic(EAvdtpSEIDHasWrongDomain)); |
|
163 } |
|
164 |
|
165 |
|
166 void CLocalSEP::CommitPendingConfigurationL(TBool aSuccess, TBool aReconfig) |
|
167 { |
|
168 LOG_FUNC |
|
169 if (aSuccess) |
|
170 { |
|
171 TAvdtpServiceCategories cats; |
|
172 cats.SetCapability(EAllServiceCategories); |
|
173 CCapabilityParseVisitor* parser = new(ELeave) CCapabilityParseVisitor(cats); |
|
174 iConfiguration.DeleteAll(); |
|
175 parser->Process(iPendingConfigurationProtocolDomain); |
|
176 iConfiguration = parser->GetCapabilities(); |
|
177 delete parser; |
|
178 |
|
179 iPreConfigured = EFalse; |
|
180 } |
|
181 |
|
182 // if we're configuring we need to set in use if success |
|
183 // if we're reconfiguring we don't want to clear in use if fail |
|
184 if (aReconfig) |
|
185 { |
|
186 if (!InUse()) |
|
187 { |
|
188 // don't want to clear in use for failed reconfigurations |
|
189 SetInUse(aSuccess); |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 SetInUse(aSuccess); |
|
195 } |
|
196 // we were given ownership, close in either case |
|
197 iPendingConfigurationProtocolDomain.Close(); |
|
198 } |
|
199 |
|
200 void CLocalSEP::SetSecurityControl(const HBufC8* aSecurityControl) |
|
201 { |
|
202 LOG_FUNC |
|
203 delete iSecurityControl; |
|
204 iSecurityControl = aSecurityControl; |
|
205 } |
|
206 |
|
207 CAVStream& CLocalSEP::CreateStreamL(const TAvdtpSockAddr& aAddr, |
|
208 MAvdtpStreamNotify& aStreamNotify, |
|
209 CAvdtpProtocol& aProtocol) |
|
210 { |
|
211 LOG_FUNC |
|
212 if (!iStream) |
|
213 { |
|
214 iStream = CAVStream::NewL(aAddr, aStreamNotify, aProtocol, *this); |
|
215 aProtocol.StreamCreated(*iStream); |
|
216 } |
|
217 else |
|
218 { |
|
219 // client is trying to use same local sep for >1 stream. Wrong! |
|
220 User::Leave(KErrInUse); |
|
221 } |
|
222 return *Stream(); |
|
223 } |
|
224 |
|
225 void CLocalSEP::ExpectStreamL(const TBTDevAddr& aBTAddr, |
|
226 MAvdtpStreamNotify& aStreamNotify, |
|
227 CAvdtpProtocol& aProtocol) |
|
228 { |
|
229 LOG_FUNC |
|
230 TAvdtpSockAddr addr; |
|
231 addr.SetBTAddr(aBTAddr); |
|
232 addr.SetSEID(iRemoteSEID); |
|
233 CreateStreamL(addr, aStreamNotify, aProtocol).Configured(); |
|
234 } |
|
235 |
|
236 void CLocalSEP::SetInUse(TBool aInUse) |
|
237 { |
|
238 LOG_FUNC |
|
239 // clients must check that any bound stream will require erroring |
|
240 iInfo.SetInUse(aInUse); |
|
241 } |
|
242 |
|
243 TBool CLocalSEP::MultiplexingConfigured() const |
|
244 { |
|
245 return static_cast<TAvdtpMultiplexingCapability*>(Configuration()[EServiceCategoryMultiplexing]) ? |
|
246 ETrue : EFalse; |
|
247 } |