|
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 // Define the AVCTP Service Access Point (SAP) class |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifndef AVCTPSAP_H |
|
24 #define AVCTPSAP_H |
|
25 |
|
26 #include <es_prot.h> |
|
27 #include <bt_sock.h> |
|
28 #include "avctpOutboundQ.h" |
|
29 #include "avctpconstants.h" |
|
30 #include "avctppacket.h" |
|
31 #include "BtSap.h" |
|
32 #include "secman.h" |
|
33 #include "avctpcommon.h" |
|
34 /** |
|
35 This class is used to queue an indication (in some circustances) so to serialize more indications |
|
36 to be served. It is also used in the particular case of an oustanding ioctl in order to be able |
|
37 to complete it with the right indication. |
|
38 The logic is that when an Ioctl with EPrimaryChannelAttachToTransport or ESecondaryChannelAttachToTransport name has been submitted it |
|
39 means that a connection request to a remote device has been submitted. So we queue an "indication" with |
|
40 the remote device address. If an Ioctl completed arrives we want to discriminate if it is the request's |
|
41 reply or an incoming connection from another device. If it isn't our request completion it will be queued |
|
42 So, we will serve first the request's completion and then the incoming connections. |
|
43 **/ |
|
44 NONSHARABLE_CLASS(HQueuedIndication) |
|
45 { |
|
46 public: |
|
47 static HQueuedIndication* New(const TControlIoctlMessage& aMessage); |
|
48 inline TControlIoctlMessage& Indication() const; |
|
49 ~HQueuedIndication(); |
|
50 public: |
|
51 TSglQueLink iLink; |
|
52 private: |
|
53 void ConstructL(const TControlIoctlMessage& aMessage); |
|
54 private: |
|
55 TControlIoctlMessage* iMessage; |
|
56 }; |
|
57 |
|
58 inline TControlIoctlMessage& HQueuedIndication::Indication() const |
|
59 { |
|
60 return *iMessage; |
|
61 } |
|
62 |
|
63 // Forward declarations |
|
64 class CAvctpProtocol; |
|
65 class CAvctpTransport; |
|
66 |
|
67 /** |
|
68 The SAP for an AVCTP socket. |
|
69 |
|
70 Note that this class doesn't currently support any ioctls or options, |
|
71 not even to forward them on to a lower protocol |
|
72 |
|
73 @internalAll |
|
74 @see CBluetoothSAP |
|
75 */ |
|
76 NONSHARABLE_CLASS(CAvctpSap) : public CBluetoothSAP, public MSocketNotify |
|
77 { |
|
78 friend class CAvctpProtocol; // needed for iQueLink access |
|
79 friend class CAvctpTransport; |
|
80 |
|
81 public: |
|
82 // Creation |
|
83 static CAvctpSap* NewL(CAvctpProtocol& aProtocol); |
|
84 ~CAvctpSap(); |
|
85 |
|
86 // Interface between the muxers and the saps via protocol |
|
87 TBool HasDataFor(const TBTDevAddr& aRemoteAddr); |
|
88 TBool NewData(HAvctpIncomingSdu* aSdu, TInt aChannel); |
|
89 |
|
90 inline SymbianAvctp::TPid Pid() const; |
|
91 inline TInt Channel() const; |
|
92 inline TBool IsInList() const; |
|
93 private: |
|
94 CAvctpSap(CAvctpProtocol& aProtocol); |
|
95 void ConstructL(); |
|
96 |
|
97 // virtuals from CServProviderBase |
|
98 // Made private so that only people accessing this class through the base base class |
|
99 // can get at them since these methods are public in there. |
|
100 void Start(); |
|
101 void LocalName(TSockAddr& aAddr) const; |
|
102 TInt SetLocalName(TSockAddr& aAddr); |
|
103 void RemName(TSockAddr& aAddr) const; |
|
104 TInt SetRemName(TSockAddr& aAddr); |
|
105 TInt GetOption(TUint aLevel,TUint aName,TDes8& aOption) const; |
|
106 void Ioctl(TUint aLevel,TUint aName,TDes8* aOption); |
|
107 void CancelIoctl(TUint aLevel,TUint aName); |
|
108 void ActiveOpen(); |
|
109 void ActiveOpen(const TDesC8& aConnectionData); |
|
110 TInt PassiveOpen(TUint aQueueSize); |
|
111 TInt PassiveOpen(TUint aQueueSize,const TDesC8& aConnectionData); |
|
112 void Shutdown(CServProviderBase::TCloseType aOption); |
|
113 void Shutdown(CServProviderBase::TCloseType aOption, const TDesC8& aDisconnectionData); |
|
114 void AutoBind(); |
|
115 TInt Write(RMBufChain& aData, TUint aOptions, TSockAddr* anAddr=NULL); |
|
116 TInt GetData(RMBufChain& aData, TUint aLength, TUint aOptions, TSockAddr* aAddr); |
|
117 TInt SecurityCheck(MProvdSecurityChecker* aSecurityChecker); |
|
118 |
|
119 // virtual from CBluetoothSAP |
|
120 // Made private so that only people accessing this class through the base base class |
|
121 // can get at them since these methods are public in there. |
|
122 TInt SAPSetOption(TUint aLevel,TUint aName,const TDesC8& aOption); |
|
123 |
|
124 // Callbacks |
|
125 void StartSendAsyncCallBack(); |
|
126 void CancelSendAsyncCallBack(); |
|
127 static TInt SendAsyncCallBack(TAny* aSap); |
|
128 |
|
129 // Utility functions |
|
130 TInt SetPid(SymbianAvctp::TPid aPid); |
|
131 MSocketNotify& Socket() const; |
|
132 void CheckForCanSend(); |
|
133 void CheckForCanClose(); |
|
134 TInt CheckPidAllowed(SymbianAvctp::TPid aPid); |
|
135 |
|
136 void MuxerDown(const TBTDevAddr& aRemoteAddr); |
|
137 |
|
138 private: |
|
139 // Pure virtuals From MSocketNotify |
|
140 // Made private so that only people accessing this class through the M- base class |
|
141 // can get at them since these methods are public in the M- class. |
|
142 void NewData(TUint aCount); // it's not used in favour of the public overloaded NewData() |
|
143 void CanSend(); |
|
144 void ConnectComplete(); |
|
145 void ConnectComplete(const TDesC8& aConnectData); |
|
146 void ConnectComplete(CServProviderBase& aSSP); |
|
147 void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData); |
|
148 void CanClose(TDelete aDelete=EDelete); |
|
149 void CanClose(const TDesC8& aDisconnectData,TDelete aDelete=EDelete); |
|
150 void Error(TInt aError, TUint aOperationMask=EErrorAllOperations); |
|
151 void Disconnect(void); |
|
152 void Disconnect(TDesC8& aDisconnectData); |
|
153 void IoctlComplete(TDesC8* aBuf); |
|
154 void NoBearer(const TDesC8& /*aConnectionInfo*/); |
|
155 void Bearer(const TDesC8& /*aConnectionInfo*/); |
|
156 |
|
157 private: // unowned |
|
158 |
|
159 /** The protocol object */ |
|
160 CAvctpProtocol& iProtocol; |
|
161 |
|
162 private: // owned |
|
163 |
|
164 /** The packets that the Sap has taken responsibility of sending */ |
|
165 TAvctpOutboundQ iOutgoingSdus; |
|
166 /** The packets that the Sap has taken responsibility of, and has notified to esock to pick up |
|
167 Packets should be added on the end as they come in and taken off the front as they go up to |
|
168 esock.*/ |
|
169 TDblQue<HAvctpIncomingSdu> iIncomingSdus; |
|
170 |
|
171 CAsyncCallBack* iSendAsyncCallBack; /** Asynchronous callback for processing */ |
|
172 SymbianAvctp::TPid iPid; /** The PID for this socket*/ |
|
173 /** A class provided by esock that will allow us to perform the PID security check*/ |
|
174 MProvdSecurityChecker* iSecurityChecker; |
|
175 |
|
176 TBool iSendBlocked; |
|
177 |
|
178 /** We need to store the address of any pending data we've been asked to send in case we need to error it |
|
179 if the associated muxer goes down for some reason. Note this member variable will only contain a |
|
180 valid address when iSendBlocked is ETrue */ |
|
181 TBTDevAddr iPendingSendAddress; |
|
182 TBool iIsClosing; |
|
183 TBool iClosed; |
|
184 |
|
185 TDblQueLink iQueLink; /** A link so that the protocol can queue Saps */ |
|
186 |
|
187 TInt iChannel; |
|
188 TBool iIsInList; |
|
189 }; |
|
190 |
|
191 |
|
192 // the SAPs are "sockets" so that the avctp transport can be very thin and "transient" so effectively forwards calls from L2CAP |
|
193 // perhaps with a bit of roundrobinning in the CanSend |
|
194 class CAvctpControlSAP : public CBluetoothSAP, public MSocketNotify |
|
195 { |
|
196 public: |
|
197 static CAvctpControlSAP* NewL(CAvctpProtocol& aProtocol); |
|
198 private: |
|
199 CAvctpControlSAP(CAvctpProtocol& aProtocol); |
|
200 private: |
|
201 void Start(); |
|
202 void LocalName(TSockAddr& aAddr) const; |
|
203 TInt SetLocalName(TSockAddr& aAddr); |
|
204 void RemName(TSockAddr& aAddr) const; |
|
205 TInt SetRemName(TSockAddr& aAddr); |
|
206 TInt GetOption(TUint aLevel,TUint aName,TDes8& aOption) const; |
|
207 TBool IsActiveRequest(TUint aName); |
|
208 void Ioctl(TUint aLevel,TUint aName,TDes8* aOption); |
|
209 void CancelIoctl(TUint aLevel,TUint aName); |
|
210 void ActiveOpen(); |
|
211 void ActiveOpen(const TDesC8& aConnectionData); |
|
212 TInt PassiveOpen(TUint aQueueSize); |
|
213 TInt PassiveOpen(TUint aQueueSize,const TDesC8& aConnectionData); |
|
214 void Shutdown(CServProviderBase::TCloseType aOption); |
|
215 void Shutdown(CServProviderBase::TCloseType aOption, const TDesC8& aDisconnectionData); |
|
216 void AutoBind(); |
|
217 TUint Write(const TDesC8& aDesc,TUint aOptions, TSockAddr* aAddr); |
|
218 TInt GetData(RMBufChain& aData, TUint aLength, TUint aOptions, TSockAddr* aAddr); |
|
219 TInt SecurityCheck(MProvdSecurityChecker* aSecurityChecker); |
|
220 |
|
221 // virtual from CBluetoothSAP |
|
222 // Made private so that only people accessing this class through the base base class |
|
223 // can get at them since these methods are public in there. |
|
224 TInt SAPSetOption(TUint aLevel,TUint aName,const TDesC8& aOption); |
|
225 void SetOutstandingIndication(const TControlIoctlMessage& aMessage); |
|
226 void QueueIncomingIndication(const TControlIoctlMessage& aMessage); |
|
227 void CompleteIoctlWithError(const TControlIoctlMessage& aMessage); |
|
228 void QueueErrorIoctlComplete(const TControlIoctlMessage& aMessage); |
|
229 void CompleteQueuedIoctlWithError(TInt aError); |
|
230 private: |
|
231 // Pure virtuals From MSocketNotify |
|
232 // Made private so that only people accessing this class through the M- base class |
|
233 // can get at them since these methods are public in the M- class. |
|
234 void NewData(TUint aCount); |
|
235 void CanSend(); |
|
236 void ConnectComplete(); |
|
237 void ConnectComplete(const TDesC8& aConnectData); |
|
238 void ConnectComplete(CServProviderBase& aSSP); |
|
239 void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData); |
|
240 void CanClose(TDelete aDelete=EDelete); |
|
241 void CanClose(const TDesC8& aDisconnectData,TDelete aDelete=EDelete); |
|
242 void Error(TInt aError, TUint aOperationMask=EErrorAllOperations); |
|
243 void Disconnect(void); |
|
244 void Disconnect(TDesC8& aDisconnectData); |
|
245 void IoctlComplete(TDesC8* aBuf); |
|
246 void NoBearer(const TDesC8& /*aConnectionInfo*/); |
|
247 void Bearer(const TDesC8& /*aConnectionInfo*/); |
|
248 |
|
249 void ProcessIoctlQueue(); |
|
250 inline void ClearIoctl(); |
|
251 |
|
252 private: |
|
253 CAvctpProtocol& iProtocol; |
|
254 TDblQueLink iQueLink; |
|
255 TSglQue<HQueuedIndication> iIndicationQueue; |
|
256 }; |
|
257 |
|
258 |
|
259 #include "avctpsap.inl" |
|
260 |
|
261 #endif // AVCTPSAP_H |
|
262 |