|
1 // Copyright (c) 2000-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 #ifndef RFCOMMFRAME_H |
|
17 #define RFCOMMFRAME_H |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "rfcommsap.h" |
|
21 #include "rfcommconsts.h" |
|
22 #include "btsockettimer.h" |
|
23 |
|
24 /** |
|
25 Abstract base class for the different Rfcomm frame types |
|
26 |
|
27 All RFCOMM (TS07.10) frames have the following format: |
|
28 @verbatim |
|
29 Field | Address | Control | Length | Data | FCS | |
|
30 Length | 1 byte | 1 byte | 1 or 2 bytes | 0..* bytes | 1 byte | |
|
31 @endverbatim |
|
32 |
|
33 Classes derived from this one provide a typeId so that the |
|
34 appropriate matching can be done when working out which command a |
|
35 response is for, since this depends on the type of the frame. |
|
36 |
|
37 All frames have the notion of whether they need a response, and |
|
38 also have an associated response timer if necessary. |
|
39 |
|
40 **/ |
|
41 |
|
42 NONSHARABLE_CLASS(CRfcommFrame) : public CBase |
|
43 { |
|
44 friend class CRfcommMuxer; |
|
45 public: |
|
46 CRfcommFrame(CRfcommMuxer& aMux, CRfcommSAP* aSAP); |
|
47 CRfcommFrame(CRfcommMuxer& aMux); |
|
48 virtual ~CRfcommFrame(); |
|
49 void SetAddress(TUint8 aChan); |
|
50 TUint8 Address() const; |
|
51 void SetControl(TUint8 aCtrl); |
|
52 TUint8 Ctrl() const; |
|
53 virtual TUint8 Credit() const; |
|
54 virtual void SetCredit(TUint8 aCredit); |
|
55 virtual TUint16 DataLength() const; |
|
56 CRfcommSAP* SAP() const; |
|
57 |
|
58 virtual const TDesC8& Data() =0; |
|
59 virtual TInt Type() const =0; |
|
60 virtual TBool ResponseNeeded() =0; |
|
61 virtual void QueResponseTimer() =0; |
|
62 virtual void DequeTimer() =0; |
|
63 virtual TBool Priority() const =0; |
|
64 |
|
65 protected: |
|
66 TUint8 iAddr; |
|
67 TUint8 iCtrl; |
|
68 CRfcommMuxer& iMuxer; //< The muxer this frame belongs to |
|
69 CRfcommSAP* iSAP; //< The sap this frame belongs to, if any - could be NULL |
|
70 TDblQueLink iLink; |
|
71 }; |
|
72 |
|
73 /** |
|
74 Represents the non-data frames that exist in RFCOMM |
|
75 |
|
76 These types are as follows: |
|
77 |
|
78 SABM : Creates a channel |
|
79 UA : Acknowledgement |
|
80 DM : Disconnected mode - sent for a channel that is not on |
|
81 DISC : Disconnects a channel |
|
82 |
|
83 |
|
84 FCS is calculated using a polynomial CRC. |
|
85 |
|
86 All these frames have a length of 0 and no user data. |
|
87 |
|
88 SABM and DISC frames require a response, so objects of this class |
|
89 have associated timer entries |
|
90 **/ |
|
91 |
|
92 NONSHARABLE_CLASS(CRfcommCtrlFrame) : public CRfcommFrame |
|
93 { |
|
94 public: |
|
95 CRfcommCtrlFrame(CRfcommMuxer& aMux, CRfcommSAP* aSAP); |
|
96 CRfcommCtrlFrame(CRfcommMuxer& aMux); |
|
97 ~CRfcommCtrlFrame(); |
|
98 void SetResponseNeeded(TBool aNeed); |
|
99 |
|
100 virtual const TDesC8& Data(); |
|
101 virtual TInt Type() const; |
|
102 virtual TBool ResponseNeeded(); |
|
103 virtual void QueResponseTimer(); |
|
104 virtual void DequeTimer(); |
|
105 virtual TBool Priority() const; |
|
106 |
|
107 private: |
|
108 static TInt TimerExpired(TAny* aFrame); |
|
109 TBool iResponseNeeded; |
|
110 TDeltaTimerEntry iTimerEntry; |
|
111 TBool iTimerQueued; |
|
112 TBuf8<KRfcommCtrlFrameSize> iData; |
|
113 }; |
|
114 |
|
115 |
|
116 /** |
|
117 Represents a data frame in RFCOMM |
|
118 |
|
119 UIH frames carry both user data and mux commands between the |
|
120 endpoints. Thus this class is the base for mux ctrl frames. |
|
121 |
|
122 A simple, stream-like store API is defined so that subsequent |
|
123 writes occur further into the packet than earlier ones. |
|
124 |
|
125 // Note that with this implementation only single byte lengths are |
|
126 // supported, and a fixed sized buffer is used to contain the data. |
|
127 // Mel no longer true but we have to reorganise this to remove the dependency |
|
128 // of Ctrl frames on data frames |
|
129 **/ |
|
130 NONSHARABLE_CLASS(CRfcommUIHFrame) : public CRfcommFrame |
|
131 { |
|
132 public: |
|
133 |
|
134 static CRfcommUIHFrame* NewL(TInt aInformationLength, CRfcommMuxer& aMux, CRfcommSAP* aSAP=0); |
|
135 |
|
136 virtual ~CRfcommUIHFrame(); |
|
137 |
|
138 virtual void PutByte(TUint8 aByte); |
|
139 virtual void PutLittleEndian16(TUint16 aShort); |
|
140 virtual void PutLittleEndian32(TUint32 aLong); |
|
141 virtual void PutData(const TDesC8& aDes); |
|
142 |
|
143 virtual const TDesC8& Data(); |
|
144 virtual TInt Type() const; |
|
145 virtual TBool ResponseNeeded(); |
|
146 virtual void QueResponseTimer(); |
|
147 virtual void DequeTimer(); |
|
148 virtual TBool Priority() const; |
|
149 virtual TUint16 DataLength() const; |
|
150 |
|
151 protected: |
|
152 |
|
153 CRfcommUIHFrame(CRfcommMuxer& aMux, CRfcommSAP* aSAP); |
|
154 |
|
155 // Called as part of NewL |
|
156 virtual void ConstructDataBufferL(TInt aInformationLength); |
|
157 |
|
158 virtual void PrepareDataFrame(); |
|
159 void PutByteAt(TInt aOffset, TUint8 aByte); |
|
160 |
|
161 protected: |
|
162 |
|
163 HBufC8* iData; |
|
164 TPtrC8 iReturnedFrame; |
|
165 TBool iFramePrepared; |
|
166 }; |
|
167 |
|
168 /** |
|
169 Represents a UIH frame in RFCOMM which is used for carrying information |
|
170 **/ |
|
171 NONSHARABLE_CLASS(CRfcommDataFrame) : public CRfcommUIHFrame |
|
172 { |
|
173 public: |
|
174 |
|
175 static CRfcommDataFrame* NewL(TInt aInformationLength, CRfcommMuxer& aMux, CRfcommSAP* aSAP=0); |
|
176 |
|
177 virtual ~CRfcommDataFrame(); |
|
178 |
|
179 |
|
180 protected: |
|
181 |
|
182 CRfcommDataFrame(CRfcommMuxer& aMux, CRfcommSAP* aSAP); |
|
183 |
|
184 // Called as part of NewL |
|
185 virtual void ConstructDataBufferL(TInt aInformationLength); |
|
186 |
|
187 virtual void PrepareDataFrame(); |
|
188 |
|
189 }; |
|
190 |
|
191 /** |
|
192 Represents a data frame in RFCOMM which also carries a credit |
|
193 **/ |
|
194 NONSHARABLE_CLASS(CRfcommCreditDataFrame) : public CRfcommDataFrame |
|
195 { |
|
196 public: |
|
197 |
|
198 static CRfcommCreditDataFrame* NewL(TInt aInformationLength, CRfcommMuxer& aMux, CRfcommSAP* aSAP=0); |
|
199 |
|
200 virtual ~CRfcommCreditDataFrame(); |
|
201 |
|
202 virtual TInt Type() const; |
|
203 virtual TUint16 DataLength() const; |
|
204 virtual void SetCredit(TUint8 aCredit); |
|
205 virtual TUint8 Credit() const; |
|
206 |
|
207 protected: |
|
208 |
|
209 CRfcommCreditDataFrame(CRfcommMuxer& aMux, CRfcommSAP* aSAP); |
|
210 |
|
211 // Called as part of NewL |
|
212 virtual void ConstructDataBufferL(TInt aInformationLength); |
|
213 |
|
214 virtual void PrepareDataFrame(); |
|
215 |
|
216 private: |
|
217 |
|
218 TUint8 iCredit; // what we are doling out this frame |
|
219 }; |
|
220 |
|
221 /** |
|
222 Represents mux control channel commands and responses |
|
223 |
|
224 These are carried in UIH frames, but as commands require responses |
|
225 the infrastructure for these has been added. |
|
226 **/ |
|
227 NONSHARABLE_CLASS(CRfcommMuxCtrlFrame) : public CRfcommUIHFrame |
|
228 { |
|
229 friend class CRfcommMuxer; |
|
230 public: |
|
231 |
|
232 static CRfcommMuxCtrlFrame* NewL(TUint8 aCommandValuesLength, CRfcommMuxer& aMux, CRfcommSAP* aSAP=0); |
|
233 |
|
234 ~CRfcommMuxCtrlFrame(); |
|
235 void SetCommandType(TUint8 aType, TBool aCommand); |
|
236 TUint8 CommandType() const; |
|
237 void SetResponseNeeded(TBool aNeed); |
|
238 |
|
239 virtual TInt Type() const; |
|
240 virtual TBool ResponseNeeded(); |
|
241 virtual void QueResponseTimer(); |
|
242 virtual void DequeTimer(); |
|
243 virtual TBool Priority() const; |
|
244 |
|
245 // NB. MuxCtrlFrames are always sent on DLCI 0 (i.e. the Mux Control Channel). |
|
246 // The SetDLCI / DLCI members refer to the actual channel which is being addressed, |
|
247 // rather than the channel on which this frame is being sent. |
|
248 // |
|
249 void SetDLCI(TUint8 aDLCI); |
|
250 TUint8 DLCI() const; |
|
251 |
|
252 protected: |
|
253 |
|
254 // Called as part of NewL |
|
255 virtual void ConstructDataBufferL(TInt aCommandValuesLength); |
|
256 virtual void PrepareDataFrame(); |
|
257 |
|
258 private: |
|
259 CRfcommMuxCtrlFrame(TUint8 aCommandValuesLength, CRfcommMuxer& aMux, CRfcommSAP* aSAP); |
|
260 |
|
261 static TInt TimerExpired(TAny* aFrame); |
|
262 TBool iResponseNeeded; |
|
263 TUint8 iCommandType; |
|
264 TUint8 iCommandLength; |
|
265 TDeltaTimerEntry iTimerEntry; |
|
266 TBool iTimerQueued; |
|
267 TUint8 iDLCI; |
|
268 }; |
|
269 |
|
270 #include "rfcommframe.inl" |
|
271 #endif |