|
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 #include <bt_sock.h> |
|
17 |
|
18 #define FLOG(a) (a) |
|
19 |
|
20 // Remote Port Params class |
|
21 EXPORT_C void TRfcommRemotePortParams::UpdateFlowCtrlBit(TUint8 aFlowCtrl, |
|
22 TRPNFlowCtrlMask aFCMask) |
|
23 /** Constructor |
|
24 Set the flow control bit specified by aFCMask to |
|
25 the same value it has in aFlowCtrl |
|
26 @param aFlowCtrl Flow control specifier. |
|
27 @param aFCMask Flow control mask. |
|
28 */ |
|
29 { |
|
30 // Set flow control to all zeros if it's not valid already |
|
31 if(!(IsValid() & EVMFlowCtrl)) |
|
32 { |
|
33 const TUint8 KDefaultFlowControl = 0; |
|
34 SetFlowCtrl(KDefaultFlowControl); |
|
35 } |
|
36 |
|
37 // bitMask is guaranteed to have one and only one bit set as long as |
|
38 // the enums in TRPNFlowCtrlMask only have one bit set each |
|
39 TUint8 bitMask = TUint8(aFCMask); |
|
40 if(aFlowCtrl & bitMask) |
|
41 { |
|
42 // Bit is set in aFlowCtrl so set it here too |
|
43 SetFlowCtrl(iFlowCtrl |= bitMask); |
|
44 } |
|
45 else |
|
46 { |
|
47 // Bit is clear in aFlowCtrl so clear it here too |
|
48 SetFlowCtrl(iFlowCtrl &= ~bitMask); |
|
49 } |
|
50 } |
|
51 |
|
52 EXPORT_C void TRfcommRemotePortParams::UpdateWholeFlowCtrl(TUint16 aParamMask, |
|
53 TUint8 aFlowCtrl) |
|
54 /** Used to update flow control with relevant bits from aFlowCtrl |
|
55 (as specified by aParamsMask) |
|
56 @param aParamMask The parameter mask specifing what to change. |
|
57 @param aFlowCtrl Flow control information specifing new values. |
|
58 */ |
|
59 { |
|
60 if(aParamMask & EPMXOnOffInput) |
|
61 { |
|
62 // XON/off on input |
|
63 UpdateFlowCtrlBit(aFlowCtrl, EFCXOnOffInput); |
|
64 } |
|
65 |
|
66 if(aParamMask & EPMXOnOffOutput) |
|
67 { |
|
68 // XON/off on output |
|
69 UpdateFlowCtrlBit(aFlowCtrl, EFCXOnOffOutput); |
|
70 } |
|
71 |
|
72 if(aParamMask & EPMRTRInput) |
|
73 { |
|
74 // RTR on input |
|
75 UpdateFlowCtrlBit(aFlowCtrl, EFCRTRInput); |
|
76 } |
|
77 |
|
78 if(aParamMask & EPMRTROutput) |
|
79 { |
|
80 // RTR on output |
|
81 UpdateFlowCtrlBit(aFlowCtrl, EFCRTROutput); |
|
82 } |
|
83 |
|
84 if(aParamMask & EPMRTCInput) |
|
85 { |
|
86 // RTC on input |
|
87 UpdateFlowCtrlBit(aFlowCtrl, EFCRTCInput); |
|
88 } |
|
89 |
|
90 if(aParamMask & EPMRTCOutput) |
|
91 { |
|
92 // RTC on output |
|
93 UpdateFlowCtrlBit(aFlowCtrl, EFCRTCOutput); |
|
94 } |
|
95 } |
|
96 |
|
97 EXPORT_C void TRfcommRemotePortParams::UpdateFromRPNTransaction( |
|
98 const TRfcommRPNTransaction& aRPNTransaction) |
|
99 /** Update using a TRfcommRPNTransaction class. |
|
100 Update all parameters according to parameters and mask in aRPNTransaction |
|
101 @param aRPNTransaction The internal values are updated according to the values held in this attribute. |
|
102 @see TRfcommRPNTransaction |
|
103 */ |
|
104 { |
|
105 TUint16 paramMask = aRPNTransaction.iParamMask; |
|
106 TRfcommRemotePortParams portParams = aRPNTransaction.iPortParams; |
|
107 |
|
108 // Copy everything that is marked in the parameter mask if it is valid in the |
|
109 // source 'remote port params' structure |
|
110 if(paramMask & EPMBitRate) |
|
111 { |
|
112 TBps bitRate = EBps9600; // To stop compiler warnings |
|
113 if(portParams.GetBitRate(bitRate)) // Guarantees 'bitRate' set if returns True |
|
114 SetBitRate(bitRate); |
|
115 } |
|
116 |
|
117 if(paramMask & EPMDataBits) |
|
118 { |
|
119 TDataBits dataBits = EData5; // To stop compiler warnings |
|
120 if(portParams.GetDataBits(dataBits)) // Guarantees 'dataBits' set if returns True |
|
121 SetDataBits(dataBits); |
|
122 } |
|
123 |
|
124 if(paramMask & EPMStopBit) |
|
125 { |
|
126 TStopBits stopBit = EStop1; // To stop compiler warnings |
|
127 if(portParams.GetStopBit(stopBit)) // Guarantees 'stopBit' set if returns True |
|
128 SetStopBit(stopBit); |
|
129 } |
|
130 |
|
131 // Both indicate a change in the same thing in TRfcommRemotePortparams |
|
132 if(paramMask & EPMParity || paramMask & EPMParityType) |
|
133 { |
|
134 TParity parity = EParityNone; // To stop compiler warnings |
|
135 if(portParams.GetParity(parity)) // Guarantees 'parity' set if returns True |
|
136 SetParity(parity); |
|
137 } |
|
138 |
|
139 if(paramMask & EPMXOnChar) |
|
140 { |
|
141 TUint8 xOnChar = 0; // To stop compiler warnings |
|
142 if(portParams.GetXOnChar(xOnChar)) // Guarantees 'xOnChar' set if returns True |
|
143 SetXOnChar(xOnChar); |
|
144 } |
|
145 |
|
146 if(paramMask & EPMXOffChar) |
|
147 { |
|
148 TUint8 xOffChar = 0; // To stop compiler warnings |
|
149 if(portParams.GetXOffChar(xOffChar)) // Guarantees 'xOffChar' set if returns True |
|
150 SetXOffChar(xOffChar); |
|
151 } |
|
152 |
|
153 // Flow control is compound - do it separately |
|
154 TUint8 flowCtrl = 0; // To stop compiler warnings |
|
155 if(portParams.GetFlowCtrl(flowCtrl)) |
|
156 UpdateWholeFlowCtrl(paramMask, flowCtrl); |
|
157 } |
|
158 |
|
159 EXPORT_C TRfcommRemotePortParams::TRfcommRemotePortParams() |
|
160 : iFlowCtrl(0), |
|
161 iXOnChar(0), |
|
162 iXOffChar(0), |
|
163 iValidMask(0) |
|
164 { |
|
165 } |
|
166 |
|
167 EXPORT_C TUint8 TRfcommRemotePortParams::IsValid() const |
|
168 { |
|
169 return iValidMask; |
|
170 } |
|
171 |
|
172 EXPORT_C TBool TRfcommRemotePortParams::GetBitRate(TBps& aBitRate) const |
|
173 { |
|
174 if(IsValid() & EVMBitRate) |
|
175 { |
|
176 aBitRate = iBitRate; |
|
177 return ETrue; |
|
178 } |
|
179 else |
|
180 return EFalse; |
|
181 } |
|
182 |
|
183 EXPORT_C TInt TRfcommRemotePortParams::SetBitRate(TBps aBitRate) |
|
184 { |
|
185 switch(aBitRate) |
|
186 { |
|
187 case EBps2400: |
|
188 case EBps4800: |
|
189 case EBps7200: |
|
190 case EBps9600: |
|
191 case EBps19200: |
|
192 case EBps38400: |
|
193 case EBps57600: |
|
194 case EBps115200: |
|
195 case EBps230400: |
|
196 iValidMask|=EVMBitRate; |
|
197 iBitRate=aBitRate; |
|
198 return KErrNone; |
|
199 //break; |
|
200 default: |
|
201 return KErrArgument; |
|
202 //break; |
|
203 } |
|
204 } |
|
205 |
|
206 EXPORT_C TBool TRfcommRemotePortParams::GetDataBits(TDataBits& aDataBits) const |
|
207 // If Data Bits are valid, sets reference and returns True, |
|
208 // otherwise, returns False |
|
209 { |
|
210 if(IsValid() & EVMDataBits) |
|
211 { |
|
212 aDataBits = iDataBits; |
|
213 return ETrue; |
|
214 } |
|
215 else |
|
216 return EFalse; |
|
217 } |
|
218 |
|
219 EXPORT_C TInt TRfcommRemotePortParams::SetDataBits(TDataBits aDataBits) |
|
220 { |
|
221 iValidMask|=EVMDataBits; |
|
222 iDataBits=aDataBits; |
|
223 return KErrNone; |
|
224 } |
|
225 |
|
226 EXPORT_C TBool TRfcommRemotePortParams::GetStopBit(TStopBits& aStopBit) const |
|
227 // If Stop Bit is valid, sets reference and returns True, |
|
228 // otherwise, returns False |
|
229 { |
|
230 if(IsValid() & EVMStopBit) |
|
231 { |
|
232 aStopBit = iStopBit; |
|
233 return ETrue; |
|
234 } |
|
235 else |
|
236 return EFalse; |
|
237 } |
|
238 |
|
239 EXPORT_C TInt TRfcommRemotePortParams::SetStopBit(TStopBits aStopBit) |
|
240 { |
|
241 iValidMask|=EVMStopBit; |
|
242 iStopBit=aStopBit; |
|
243 return KErrNone; |
|
244 } |
|
245 |
|
246 EXPORT_C TBool TRfcommRemotePortParams::GetParity(TParity& aParity) const |
|
247 // If Parity is valid, sets reference and returns True, |
|
248 // otherwise, returns False |
|
249 { |
|
250 if(IsValid() & EVMParity) |
|
251 { |
|
252 aParity = iParity; |
|
253 return ETrue; |
|
254 } |
|
255 else |
|
256 return EFalse; |
|
257 } |
|
258 |
|
259 EXPORT_C TInt TRfcommRemotePortParams::SetParity(TParity aParity) |
|
260 { |
|
261 iValidMask|=EVMParity; |
|
262 iParity=aParity; |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 EXPORT_C TBool TRfcommRemotePortParams::GetFlowCtrl(TUint8& aFlowCtrl) const |
|
267 // If Flow Control is valid, sets reference and returns True, |
|
268 // otherwise, returns False |
|
269 { |
|
270 if(IsValid() & EVMFlowCtrl) |
|
271 { |
|
272 aFlowCtrl = iFlowCtrl; |
|
273 return ETrue; |
|
274 } |
|
275 else |
|
276 return EFalse; |
|
277 } |
|
278 |
|
279 EXPORT_C TInt TRfcommRemotePortParams::SetFlowCtrl(TUint8 aFlowCtrl) |
|
280 { |
|
281 iValidMask|=EVMFlowCtrl; |
|
282 iFlowCtrl=aFlowCtrl; |
|
283 return KErrNone; |
|
284 } |
|
285 |
|
286 EXPORT_C TBool TRfcommRemotePortParams::GetXOnChar(TUint8& aXOnChar) const |
|
287 // If XOn Char is valid, sets reference and returns True, |
|
288 // otherwise, returns False |
|
289 { |
|
290 if(IsValid() & EVMXOnChar) |
|
291 { |
|
292 aXOnChar = iXOnChar; |
|
293 return ETrue; |
|
294 } |
|
295 else |
|
296 return EFalse; |
|
297 } |
|
298 |
|
299 EXPORT_C TInt TRfcommRemotePortParams::SetXOnChar(TUint8 aXOnChar) |
|
300 { |
|
301 iValidMask|=EVMXOnChar; |
|
302 iXOnChar=aXOnChar; |
|
303 return KErrNone; |
|
304 } |
|
305 |
|
306 EXPORT_C TBool TRfcommRemotePortParams::GetXOffChar(TUint8& aXOffChar) const |
|
307 // If XOff Char is valid, sets reference and returns True, |
|
308 // otherwise, returns False |
|
309 { |
|
310 if(IsValid() & EVMXOffChar) |
|
311 { |
|
312 aXOffChar = iXOffChar; |
|
313 return ETrue; |
|
314 } |
|
315 else |
|
316 return EFalse; |
|
317 } |
|
318 |
|
319 EXPORT_C TInt TRfcommRemotePortParams::SetXOffChar(TUint8 aXOffChar) |
|
320 { |
|
321 iValidMask|=EVMXOffChar; |
|
322 iXOffChar=aXOffChar; |
|
323 return KErrNone; |
|
324 } |
|
325 |
|
326 // RPN Transaction class |
|
327 |
|
328 EXPORT_C TRfcommRPNTransaction::TRfcommRPNTransaction():iParamMask(0) |
|
329 { |
|
330 } |
|
331 |
|
332 // Socket Address class |
|
333 |
|
334 EXPORT_C TRfcommSockAddr::TRfcommSockAddr() |
|
335 /** Constructor |
|
336 */ |
|
337 { |
|
338 } |
|
339 |
|
340 EXPORT_C TRfcommSockAddr::TRfcommSockAddr(const TSockAddr &aAddr) |
|
341 : TBTSockAddr(aAddr) |
|
342 /** Constructor that takes a BT socket address. |
|
343 @param aAddr The BT socket address from which this instance is initialised. |
|
344 */ |
|
345 { |
|
346 } |
|
347 |
|
348 EXPORT_C TRfcommSockAddr& TRfcommSockAddr::Cast(const TSockAddr &aAddr) |
|
349 { |
|
350 return *((TRfcommSockAddr *)&aAddr); |
|
351 } |
|
352 |
|
353 // EOF |