|
1 // Copyright (c) 1997-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 <ir_sock.h> |
|
17 |
|
18 #include <irdaextensions.h> |
|
19 #include <e32base.h> |
|
20 #include <es_prot.h> |
|
21 #include <c32comm.h> |
|
22 #include "IR_CONST.H" |
|
23 |
|
24 EXPORT_C TIrdaSockAddr::TIrdaSockAddr() : TSockAddr() |
|
25 /** Default constructor. Sets the protocol family to the value of the constant |
|
26 KIrdaAddrFamily. */ |
|
27 { |
|
28 SetFamily(KIrdaAddrFamily); |
|
29 SetUserLen(sizeof(SIrdaAddr)); |
|
30 addrPtr()->iSpare = 0; |
|
31 } |
|
32 |
|
33 // |
|
34 // Copy constructor - takes a previously filled TSockAddr and |
|
35 // parses it for result fields. Useful for client code only. |
|
36 // |
|
37 EXPORT_C TIrdaSockAddr::TIrdaSockAddr(const TSockAddr &aAddr) |
|
38 /** Copy constructor. Assumes that the source address is an IrDA socket address. |
|
39 |
|
40 @param aAddr A socket address assumed to be valid IrDA socket address. */ |
|
41 { |
|
42 SetFamily(KIrdaAddrFamily); |
|
43 SetPort(aAddr.Port()); |
|
44 SetRemoteDevAddr(TIrdaSockAddr::Cast(aAddr).GetRemoteDevAddr()); |
|
45 SetHostDevAddr(TIrdaSockAddr::Cast(aAddr).GetHostDevAddr()); |
|
46 SetSniffStatus(TIrdaSockAddr::Cast(aAddr).GetSniffStatus()); |
|
47 SetSolicitedStatus(TIrdaSockAddr::Cast(aAddr).GetSolicitedStatus()); |
|
48 SetIrlapVersion(TIrdaSockAddr::Cast(aAddr).GetIrlapVersion()); |
|
49 SetCharacterSet(TIrdaSockAddr::Cast(aAddr).GetCharacterSet()); |
|
50 SetFirstServiceHintByte(TIrdaSockAddr::Cast(aAddr).GetFirstServiceHintByte()); |
|
51 SetSecondServiceHintByte(TIrdaSockAddr::Cast(aAddr).GetSecondServiceHintByte()); |
|
52 SetServiceHintByteCount(TIrdaSockAddr::Cast(aAddr).GetServiceHintByteCount()); |
|
53 SetHomePort(TIrdaSockAddr::Cast(aAddr).GetHomePort()); |
|
54 SetRemotePort(TIrdaSockAddr::Cast(aAddr).GetRemotePort()); |
|
55 |
|
56 SetUserLen(sizeof(SIrdaAddr)); |
|
57 } |
|
58 |
|
59 EXPORT_C TIrdaSockAddr &TIrdaSockAddr::Cast(const TSockAddr &aAddr) |
|
60 { |
|
61 return *((TIrdaSockAddr *)&aAddr); |
|
62 } |
|
63 |
|
64 EXPORT_C TIrdaSockAddr &TIrdaSockAddr::Cast(const TSockAddr *aAddr) |
|
65 { |
|
66 return *((TIrdaSockAddr *)aAddr); |
|
67 } |
|
68 |
|
69 EXPORT_C TUint TIrdaSockAddr::GetRemoteDevAddr() const |
|
70 { |
|
71 return addrPtr()->iRemoteDevAddr; |
|
72 } |
|
73 |
|
74 EXPORT_C void TIrdaSockAddr::SetRemoteDevAddr(const TUint aRemote) |
|
75 { |
|
76 addrPtr()->iRemoteDevAddr=aRemote; |
|
77 } |
|
78 |
|
79 EXPORT_C TUint TIrdaSockAddr::GetHostDevAddr() const |
|
80 { |
|
81 return addrPtr()->iHostDevAddr; |
|
82 } |
|
83 |
|
84 EXPORT_C void TIrdaSockAddr::SetHostDevAddr(const TUint aHost) |
|
85 { |
|
86 addrPtr()->iHostDevAddr=aHost; |
|
87 } |
|
88 |
|
89 EXPORT_C TBool TIrdaSockAddr::GetSniffStatus() const |
|
90 { |
|
91 return addrPtr()->iSniff; |
|
92 } |
|
93 |
|
94 EXPORT_C void TIrdaSockAddr::SetSniffStatus(const TBool aSniffStatus) |
|
95 { |
|
96 addrPtr()->iSniff=aSniffStatus; |
|
97 } |
|
98 |
|
99 EXPORT_C TBool TIrdaSockAddr::GetSolicitedStatus() const |
|
100 { |
|
101 return addrPtr()->iSolicited; |
|
102 } |
|
103 |
|
104 EXPORT_C void TIrdaSockAddr::SetSolicitedStatus(const TBool aSolicitedStatus) |
|
105 { |
|
106 addrPtr()->iSolicited=aSolicitedStatus; |
|
107 } |
|
108 |
|
109 EXPORT_C TUint8 TIrdaSockAddr::GetIrlapVersion() const |
|
110 { |
|
111 return addrPtr()->iIrlapVersion; |
|
112 } |
|
113 |
|
114 EXPORT_C void TIrdaSockAddr::SetIrlapVersion(const TUint8 aIrlapVersion) |
|
115 { |
|
116 addrPtr()->iIrlapVersion=aIrlapVersion; |
|
117 } |
|
118 |
|
119 EXPORT_C TUint8 TIrdaSockAddr::GetCharacterSet() const |
|
120 { |
|
121 return addrPtr()->iCharacterSet; |
|
122 } |
|
123 |
|
124 EXPORT_C void TIrdaSockAddr::SetCharacterSet(const TUint8 aCharacterSet) |
|
125 { |
|
126 addrPtr()->iCharacterSet=aCharacterSet; |
|
127 } |
|
128 |
|
129 EXPORT_C TUint8 TIrdaSockAddr::GetFirstServiceHintByte() const |
|
130 { |
|
131 return addrPtr()->iFirstServiceHintByte; |
|
132 } |
|
133 |
|
134 EXPORT_C void TIrdaSockAddr::SetFirstServiceHintByte(const TUint8 aFirstServiceHintByte) |
|
135 { |
|
136 addrPtr()->iFirstServiceHintByte=aFirstServiceHintByte; |
|
137 } |
|
138 |
|
139 EXPORT_C TUint8 TIrdaSockAddr::GetSecondServiceHintByte() const |
|
140 { |
|
141 return addrPtr()->iSecondServiceHintByte; |
|
142 } |
|
143 |
|
144 EXPORT_C void TIrdaSockAddr::SetSecondServiceHintByte(const TUint8 aSecondServiceHintByte) |
|
145 { |
|
146 addrPtr()->iSecondServiceHintByte=aSecondServiceHintByte; |
|
147 } |
|
148 |
|
149 EXPORT_C TUint8 TIrdaSockAddr::GetServiceHintByteCount() const |
|
150 { |
|
151 return addrPtr()->iServiceHintByteCount; |
|
152 } |
|
153 |
|
154 EXPORT_C void TIrdaSockAddr::SetServiceHintByteCount(const TUint8 aServiceHintByteCount) |
|
155 { |
|
156 addrPtr()->iServiceHintByteCount=aServiceHintByteCount; |
|
157 } |
|
158 |
|
159 EXPORT_C TUint8 TIrdaSockAddr::GetHomePort() const |
|
160 { |
|
161 return addrPtr()->iHomePort; |
|
162 } |
|
163 |
|
164 EXPORT_C void TIrdaSockAddr::SetHomePort(const TUint8 aHomePort) |
|
165 { |
|
166 addrPtr()->iHomePort=aHomePort; |
|
167 } |
|
168 |
|
169 EXPORT_C TUint8 TIrdaSockAddr::GetRemotePort() const |
|
170 { |
|
171 return addrPtr()->iRemotePort; |
|
172 } |
|
173 |
|
174 EXPORT_C void TIrdaSockAddr::SetRemotePort(const TUint8 aRemotePort) |
|
175 { |
|
176 addrPtr()->iRemotePort=aRemotePort; |
|
177 } |
|
178 |
|
179 TIrdaSockAddr::SIrdaAddr* TIrdaSockAddr::addrPtr() const |
|
180 { |
|
181 return (SIrdaAddr *)UserPtr(); |
|
182 } |
|
183 |
|
184 /** |
|
185 Stops the IrDA stack responding to discovery requests from |
|
186 another device. |
|
187 |
|
188 @return KErrNone, if successful. |
|
189 KErrPermissionDenied, if the method is called without the |
|
190 required capabilities. |
|
191 |
|
192 @capability WriteDeviceData |
|
193 @publishedAll |
|
194 @released |
|
195 */ |
|
196 EXPORT_C TInt RIrdaDiscoveryResponseSuppressor::Open() |
|
197 { |
|
198 return DefineAndSetKey(ETrue); |
|
199 } |
|
200 |
|
201 /** |
|
202 Stops the suppressor from blocking the sending of discovery responses |
|
203 to remote IrDA devices. |
|
204 |
|
205 @publishedAll |
|
206 @released |
|
207 */ |
|
208 EXPORT_C void RIrdaDiscoveryResponseSuppressor::Close() |
|
209 { |
|
210 (void) DefineAndSetKey(EFalse); |
|
211 } |
|
212 |
|
213 /** |
|
214 Private helper function that defines the IrDA discovery responses |
|
215 suppression P&S key and sets the specified suppression status. |
|
216 |
|
217 @param aSuppressDiscoveryResponses A boolean indicating if responses should be |
|
218 suppressed or allowed. |
|
219 |
|
220 @return KErrNone, if successful. |
|
221 KErrPermissionDenied, if the method is called without the |
|
222 required capabilities. |
|
223 |
|
224 @internalComponent |
|
225 @released |
|
226 */ |
|
227 TInt RIrdaDiscoveryResponseSuppressor::DefineAndSetKey(TBool aSuppressDiscoveryResponses) |
|
228 { |
|
229 // Define the discovery response suppression property. |
|
230 TSecurityPolicy policy = TSecurityPolicy(ECapabilityWriteDeviceData); |
|
231 TInt rerr = RProperty::Define(KIrdaPropertyCategory, |
|
232 KIrdaDiscoveryResponseSuppressor, |
|
233 RProperty::EInt, |
|
234 policy, |
|
235 policy); |
|
236 |
|
237 if(rerr == KErrAlreadyExists || rerr == KErrNone) |
|
238 { |
|
239 TDiscoveryResponseSuppressorStatus status = aSuppressDiscoveryResponses ? |
|
240 ESuppressDiscoveryResponses : |
|
241 EAllowDiscoveryResponses; |
|
242 |
|
243 rerr = RProperty::Set(KIrdaPropertyCategory, |
|
244 KIrdaDiscoveryResponseSuppressor, |
|
245 status); |
|
246 } |
|
247 |
|
248 // Forward the error if it is not KErrAlreadyExists. |
|
249 return rerr; |
|
250 } |
|
251 |
|
252 // EOF |