|
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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <bluetooth/logger.h> |
|
22 #include <bluetoothav.h> |
|
23 |
|
24 #include "avctppacketstatics.h" |
|
25 |
|
26 #ifdef __FLOG_ACTIVE |
|
27 _LIT8(KLogComponent, LOG_COMPONENT_AVLIB); |
|
28 #endif |
|
29 |
|
30 #ifdef _DEBUG |
|
31 PANICCATEGORY("pktstats"); |
|
32 #endif |
|
33 |
|
34 namespace SymbianAvctp |
|
35 { |
|
36 enum TAvctpLibPanic |
|
37 { |
|
38 /** Unknown Packet Type */ |
|
39 EAvctpLibUnknownPacketType = 0, |
|
40 /** Incorrect Packet Type */ |
|
41 EAvctpLibIncorrectPacketType = 1, |
|
42 /** Invalid Transaction label */ |
|
43 EAvctpLibInvalidTransactionLabel = 2, |
|
44 }; |
|
45 |
|
46 void Panic(TAvctpLibPanic aPanic) |
|
47 { |
|
48 _LIT(KAvctpLibPanicName, "BtAvAvctpPanic"); |
|
49 User::Panic(KAvctpLibPanicName, aPanic); |
|
50 } |
|
51 |
|
52 EXPORT_C TPduHeaderLength ConvertPacketTypeToHeaderLength(TPacketType aPktType) |
|
53 { |
|
54 TPduHeaderLength ret = ENormalHeaderLength; |
|
55 switch (aPktType) { |
|
56 case ENormalPkt: |
|
57 // leave ret as ENormalHeaderLength; |
|
58 break; |
|
59 case EStartFrag: |
|
60 ret = EStartFragHeaderLength; |
|
61 break; |
|
62 case EContinueFrag: |
|
63 case EEndFrag: |
|
64 ret = EOtherFragHeaderLength; |
|
65 break; |
|
66 default: |
|
67 Panic(EAvctpLibUnknownPacketType); |
|
68 break; |
|
69 } |
|
70 return ret; |
|
71 } |
|
72 |
|
73 /** |
|
74 Provides a method to assert that AVCTP transaction Labels |
|
75 are valid |
|
76 |
|
77 @internalTechnology |
|
78 @param aLabel the label to check |
|
79 */ |
|
80 EXPORT_C void AssertValidTransactionLabel(TTransactionLabel aLabel) |
|
81 { |
|
82 __ASSERT_ALWAYS (IsValidTransactionLabel(aLabel), |
|
83 Panic(EAvctpLibInvalidTransactionLabel)); |
|
84 } |
|
85 |
|
86 |
|
87 /** |
|
88 Provides a method to validate AVCTP transaction Labels |
|
89 |
|
90 @internalTechnology |
|
91 @param aLabel the label to check |
|
92 @return ETrue if the label is valid, EFalse otherwise |
|
93 */ |
|
94 EXPORT_C TBool IsValidTransactionLabel(TTransactionLabel aLabel) |
|
95 { |
|
96 return (aLabel < KMaxTransactionLabel); |
|
97 } |
|
98 |
|
99 /** |
|
100 The AVCTP transaction label |
|
101 |
|
102 @internalComponent |
|
103 @return The transaction label |
|
104 */ |
|
105 EXPORT_C TTransactionLabel TransactionLabel(const TDesC8& aData) |
|
106 { |
|
107 ASSERT_DEBUG(aData.Length() >= EOtherFragHeaderLength); // since EStartFragHeaderLength & ENormalHeaderLength are > EOtherFragHeaderLength |
|
108 |
|
109 return static_cast<TTransactionLabel>((*const_cast<TUint8*>(aData.Ptr()) & KTransactionMask) >> 4); |
|
110 } |
|
111 |
|
112 |
|
113 /** |
|
114 The AVCTP message type |
|
115 |
|
116 @internalComponent |
|
117 @return The message type |
|
118 */ |
|
119 EXPORT_C TMessageType MessageType(const TDesC8& aData) |
|
120 { |
|
121 ASSERT_DEBUG(aData.Length() >= EOtherFragHeaderLength); // since EStartFragHeaderLength & ENormalHeaderLength are > EOtherFragHeaderLength |
|
122 |
|
123 return static_cast<TMessageType>(((*const_cast<TUint8*>(aData.Ptr()) & KMessageTypeMask) >> 1) + 1); |
|
124 } |
|
125 |
|
126 |
|
127 /** |
|
128 The AVCTP packet type |
|
129 |
|
130 @internalComponent |
|
131 @return The packet type |
|
132 */ |
|
133 EXPORT_C TPacketType PacketType(const TDesC8& aData) |
|
134 { |
|
135 ASSERT_DEBUG(aData.Length() >= EOtherFragHeaderLength); // since EStartFragHeaderLength & ENormalHeaderLength are > EOtherFragHeaderLength |
|
136 |
|
137 return static_cast<TPacketType>((*const_cast<TUint8*>(aData.Ptr()) & KPacketTypeMask) >> 2); |
|
138 } |
|
139 |
|
140 /** |
|
141 The AVCTP PID |
|
142 |
|
143 @internalComponent |
|
144 @return The packet's PID |
|
145 */ |
|
146 EXPORT_C TPid Pid(const TDesC8& aData) |
|
147 { |
|
148 ASSERT_DEBUG(aData.Length() >= ENormalHeaderLength); // since EStartFragHeaderLength is > ENormalHeaderLength |
|
149 |
|
150 TPacketType pkt = PacketType(aData); |
|
151 TPid pid = 0; |
|
152 |
|
153 switch (pkt) |
|
154 { |
|
155 case ENormalPkt: |
|
156 { |
|
157 pid = TPid(BigEndian::Get16(const_cast<TUint8*>(aData.Ptr()) + 1)); |
|
158 break; |
|
159 } |
|
160 case EStartFrag: |
|
161 { |
|
162 pid = TPid(BigEndian::Get16(const_cast<TUint8*>(aData.Ptr()) + 2)); |
|
163 break; |
|
164 } |
|
165 default: |
|
166 { |
|
167 Panic(EAvctpLibIncorrectPacketType); |
|
168 } |
|
169 } |
|
170 return pid; |
|
171 } |
|
172 |
|
173 |
|
174 /** |
|
175 Check that the invalid PID bit is not set. |
|
176 |
|
177 @internalComponent |
|
178 @return ETrue if the bit is not set, EFalse otherwise |
|
179 */ |
|
180 EXPORT_C TBool IsValidPid(const TDesC8& aData) |
|
181 { |
|
182 ASSERT_DEBUG(aData.Length() >= EOtherFragHeaderLength); // since EStartFragHeaderLength & ENormalHeaderLength are > EOtherFragHeaderLength |
|
183 __ASSERT_DEBUG(PacketType(aData) == ENormalPkt || |
|
184 PacketType(aData) == EStartFrag, |
|
185 Panic(EAvctpLibIncorrectPacketType)); |
|
186 |
|
187 return ((*const_cast<TUint8*>(aData.Ptr()) & KIsValidPidMask) == 0); |
|
188 } |
|
189 |
|
190 |
|
191 EXPORT_C TUint8 FragmentsInSdu(const TDesC8& aData) |
|
192 { |
|
193 ASSERT_DEBUG(aData.Length() >= EStartFragHeaderLength); |
|
194 __ASSERT_DEBUG(PacketType(aData) == EStartFrag, Panic(EAvctpLibIncorrectPacketType)); |
|
195 |
|
196 return *(const_cast<TUint8*>(aData.Ptr()) + 1); |
|
197 } |
|
198 |
|
199 } // end of namespace SymbianAvctp |
|
200 |
|
201 // EOF |
|
202 |