|
1 // Copyright (c) 2004-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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <bluetooth/logger.h> |
|
22 #include <es_sock.h> |
|
23 #include "BnepTypes.h" |
|
24 #include "RBnepFilterNetTypeSetRequestControl.h" |
|
25 |
|
26 #ifdef __FLOG_ACTIVE |
|
27 _LIT8(KLogComponent, LOG_COMPONENT_PAN_BNEP); |
|
28 #endif |
|
29 |
|
30 /** |
|
31 Obtain the length of the net protocol type list |
|
32 @internalComponent |
|
33 */ |
|
34 TInt RBnepFilterNetTypeSetRequestControl::NetworkProtocolTypeListLength (TUint16& aLength) const |
|
35 { |
|
36 TInt preamble = static_cast<TInt>(KSizeOfNetTypeFilterListLength + KSizeOfBnepControlType); |
|
37 if(Length() < preamble) |
|
38 { |
|
39 return KErrCorrupt; |
|
40 } |
|
41 TBuf8<KSizeOfNetTypeFilterListLength> buf; |
|
42 buf.SetMax(); |
|
43 CopyOut(buf, KNetworkProtocolTypeListLengthFieldOffset); |
|
44 aLength = BigEndian::Get16(&buf[0]); |
|
45 LOG2(_L8("RBnepFilterNetTypeSet[%x]: ...getting net type filter list length - length %d..."), this, aLength); |
|
46 return KErrNone; |
|
47 } |
|
48 |
|
49 /** |
|
50 Retrieve one value pair from a network packet type filter control |
|
51 @note This method should be called repeatedly until all the values are read out (ie. return value from the last pair is KErrEof) |
|
52 @param aStartValue The start value for the network filter range |
|
53 @param aEndValue The end value of the network filter range |
|
54 @param aIndex The index of the network protocol types, starting from zero. |
|
55 @return KErrNone if there a more addresses in the list, or KErrEof when there are no more addresses left |
|
56 @internalComponent |
|
57 */ |
|
58 TInt RBnepFilterNetTypeSetRequestControl::NetworkProtocolTypeRange (TUint16& aStartValue, TUint16& aEndValue, TUint aIndex) |
|
59 { |
|
60 LOG_FUNC |
|
61 TInt length = Length(); |
|
62 TUint16 tempLength; |
|
63 TInt err = NetworkProtocolTypeListLength(tempLength); |
|
64 if(err) |
|
65 { |
|
66 return err; |
|
67 } |
|
68 else |
|
69 { |
|
70 TInt netTypeListLength = static_cast<TInt>(tempLength); |
|
71 |
|
72 if(netTypeListLength <= 0) |
|
73 { |
|
74 return KErrNotFound; |
|
75 } |
|
76 |
|
77 TBuf8<KSizeOfNetType> buffer; |
|
78 buffer.SetMax(); |
|
79 TUint currentPair = (aIndex*(2*KSizeOfNetType) + KNetworkProtocolTypeFirstPairFieldOffset); |
|
80 if(length < currentPair+2*KSizeOfNetType) |
|
81 { |
|
82 return KErrCorrupt; |
|
83 } |
|
84 CopyOut(buffer,currentPair); |
|
85 aStartValue = BigEndian::Get16(&buffer[0]); |
|
86 CopyOut(buffer,currentPair + KSizeOfNetType); |
|
87 aEndValue = BigEndian::Get16(&buffer[0]); |
|
88 LOG2(_L8("RBnepFilterNetTypeSet[%x]: ...start protocol type: %x"), this, aStartValue); |
|
89 LOG2(_L8("RBnepFilterNetTypeSet[%x]: ...end protocol type: %x"), this, aEndValue); |
|
90 if(aStartValue > aEndValue) |
|
91 { |
|
92 LOG1(_L8("...error: start protocol type is greater than end protocol type"), this); |
|
93 return KErrArgument; |
|
94 } |
|
95 if(static_cast<TInt>((currentPair + (2*KSizeOfNetType))) > netTypeListLength) // check if this is the last pair |
|
96 { |
|
97 LOG1(_L8("...last item in list - returning KErrEof"), this); |
|
98 return KErrEof; |
|
99 } |
|
100 else |
|
101 { |
|
102 LOG1(_L8("...more items in list - returning KErrNone"), this); |
|
103 return KErrNone; |
|
104 } |
|
105 } |
|
106 } |