|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <kernel.h> // For Kern |
|
20 #include "isinameservice.h" // For DISINameService |
|
21 #include "misiobjectrouterif.h" // For MISIObjectRouterIf |
|
22 #include "isinameservicetrace.h" // For C_TRACE, ASSERT_RESET.. and fault codes |
|
23 #include "memapi.h" // For MemApi |
|
24 #include <phonetisi.h> // For ISI_HEADER_SIZE |
|
25 #include <pn_const.h> // For PN_NAMESERVICE |
|
26 #include <nsisi.h> // For PN |
|
27 #include "misiobjectrouterif.h" // For MISIObjectRouterIf |
|
28 #include "iadhelpers.h" // For SET_RECEIVER_OBJ... |
|
29 #include "namerecords.h" // For DNameRecords |
|
30 #include <iscnokiadefinitions.h> // For THIS_DEVICE |
|
31 #include <commisi.h> // For SIZE_COMMON_MESSAGE_COMM_ISA_ENTITY_NOT_REACHABLE_RESP |
|
32 // Faults |
|
33 enum TISINameServiceFaults |
|
34 { |
|
35 EISINameServiceMemAllocFailure = 0x01, |
|
36 EISINameServiceNullPointer, |
|
37 EISINameServiceUnknownMessage, |
|
38 EISINameServiceMutexCreateFailed, |
|
39 EISINameServiceMutexWaitFailed, |
|
40 }; |
|
41 |
|
42 |
|
43 /* PUTB8 macro writes byte value to given address. |
|
44 * This macro is used mainly by other PUTBXX macros. |
|
45 */ |
|
46 #define PUTB8(p,v) \ |
|
47 {(*(TUint8 *)(p)) = ((TUint8)(v));} |
|
48 |
|
49 |
|
50 /* PUTB16 macro writes 16-bit value in Big Endian format |
|
51 * to given address. 16-bit value is written as two separate |
|
52 * bytes, and so this macro can write 16-bit value to whatever |
|
53 * address, regardless of the processor alignment restrictions |
|
54 */ |
|
55 #define PUTB16(p,v) \ |
|
56 {PUTB8((p),(TUint16)(v)>>8); PUTB8((TUint8*)(p)+1,v);} |
|
57 |
|
58 |
|
59 /* PUTB32 macro writes 32-bit value in Big Endian format |
|
60 * to given address. 32-bit value is written as four separate |
|
61 * bytes, and so this macro can write 32-bit value to whatever |
|
62 * address, regardless of the processor alignment restrictions |
|
63 */ |
|
64 #define PUTB32(p,v) \ |
|
65 {PUTB16((p),(TUint32)(v)>>16); PUTB16((TUint8*)(p)+2,(TUint32)(v));} |
|
66 |
|
67 |
|
68 /** |
|
69 * Big Endian to local endian type |
|
70 */ |
|
71 /* GETB8 macro returns byte value from given address. |
|
72 * This macro is used mainly by other GETBXX macros. |
|
73 */ |
|
74 #define GETB8(p) \ |
|
75 (*(TUint8 *)(p)) |
|
76 |
|
77 |
|
78 /* GETB16 macro reads 16-bit value in Big Endian format |
|
79 * from given address. 16-bit value is read as two separate |
|
80 * bytes, and so this macro can read 16-bit value from whatever |
|
81 * address, regardless of the processor alignment restrictions |
|
82 */ |
|
83 #define GETB16(p) \ |
|
84 (((TUint16) GETB8(p)<<8) | (TUint16) GETB8((TUint8 *)(p)+1)) |
|
85 |
|
86 |
|
87 /* GETB32 macro reads 32-bit value in Big Endian format |
|
88 * from given address. 32-bit value is read as four separate |
|
89 * bytes, and so this macro can read 32-bit value from whatever |
|
90 * address, regardless of the processor alignment restrictions |
|
91 */ |
|
92 #define GETB32(p) \ |
|
93 (((TUint32) GETB16(p)<<16) | (TUint32) GETB16((TUint8 *)(p)+2)) |
|
94 |
|
95 |
|
96 const TUint32 KNameServiceUID( 0x2002A5A1 ); |
|
97 const TUint8 KFiller( 0 ); |
|
98 |
|
99 DMutex* DISINameService::iNameServiceMutex = NULL; |
|
100 _LIT8( KNameServiceMutex, "KNameServiceMutex" ); |
|
101 |
|
102 |
|
103 DISINameService::DISINameService( |
|
104 // None |
|
105 ) |
|
106 : iObjId( 0x00 ) |
|
107 { |
|
108 C_TRACE( ( _T( "DISINameService::DISINameService 0x%x 0x%x>" ), iObjId, iRouter ) ); |
|
109 iRouter = MISIObjectRouterIf::Connect( KNameServiceUID, iObjId, this ); |
|
110 ASSERT_RESET_ALWAYS( iRouter, ( EISINameServiceNullPointer | EDISINameServiceTraceId << KClassIdentifierShift ) ); |
|
111 iNameRecords = new DNameRecords(); |
|
112 ASSERT_RESET_ALWAYS( iNameRecords, ( EISINameServiceMemAllocFailure | EDISINameServiceTraceId << KClassIdentifierShift ) ); |
|
113 TInt err( Kern::MutexCreate( iNameServiceMutex, KNameServiceMutex, KMutexOrdGeneral0 ) ); |
|
114 ASSERT_RESET_ALWAYS( ( KErrNone == err ), ( EISINameServiceMutexCreateFailed | EDISINameServiceTraceId << KClassIdentifierShift ) ); |
|
115 C_TRACE( ( _T( "DISINameService::DISINameService 0x%x 0x%x<" ), iObjId, iRouter ) ); |
|
116 } |
|
117 |
|
118 DISINameService::~DISINameService( |
|
119 // None |
|
120 ) |
|
121 { |
|
122 C_TRACE( ( _T( "DISINameService::~DISINameService>" ) ) ); |
|
123 if( iNameRecords ) |
|
124 { |
|
125 delete iNameRecords; |
|
126 iNameRecords = NULL; |
|
127 } |
|
128 |
|
129 C_TRACE( ( _T( "DISINameService::~DISINameService<" ) ) ); |
|
130 } |
|
131 |
|
132 |
|
133 void DISINameService::Receive( const TDesC8& aMessage ) |
|
134 { |
|
135 C_TRACE( ( _T( "DISINameService::Receive 0x%x>" ), &aMessage ) ); |
|
136 TInt err( Kern::MutexWait( *iNameServiceMutex ) ); |
|
137 ASSERT_RESET_ALWAYS( ( KErrNone == err ), ( EISINameServiceMutexWaitFailed | EDISINameServiceTraceId << KClassIdentifierShift ) ); |
|
138 TUint8* msgPtr( (TUint8*)aMessage.Ptr() ); |
|
139 |
|
140 TUint8 resource = msgPtr[ ISI_HEADER_OFFSET_RESOURCEID ]; |
|
141 if( resource == PN_NAMESERVICE ) |
|
142 { |
|
143 C_TRACE( ( _T( "DISINameService message to PN_NAMESERVICE" ) ) ); |
|
144 HandlePNSNameMessage( aMessage ); |
|
145 } |
|
146 else |
|
147 { |
|
148 //RouterByResource( aMessage ); |
|
149 |
|
150 C_TRACE( ( _T( "DISINameService message to RESOURCE : %d" ),resource ) ); |
|
151 //look for nametable by resource in message |
|
152 TUint16 phonetAddress = 0; |
|
153 TInt32 error = iNameRecords->LookupPhonetAddress(resource, &phonetAddress); |
|
154 |
|
155 if( KErrNone == error ) |
|
156 { |
|
157 //change phonet addr to current message from table entries |
|
158 |
|
159 |
|
160 msgPtr[ISI_HEADER_OFFSET_RECEIVERDEVICE] = (TUint8)( (phonetAddress & 0xFF00) >> 8); |
|
161 msgPtr[ISI_HEADER_OFFSET_RECEIVEROBJECT] = (TUint8) (phonetAddress & 0xFF); |
|
162 TDes8* messagePtr = reinterpret_cast<TDes8*>( const_cast<TDesC8*>(&aMessage) ); |
|
163 |
|
164 C_TRACE( ( _T( "<-DISINameService message to recDev: %d" ),msgPtr[ISI_HEADER_OFFSET_RECEIVERDEVICE] ) ); |
|
165 C_TRACE( ( _T( "<-DISINameService message to recObj: %d" ),msgPtr[ISI_HEADER_OFFSET_RECEIVEROBJECT] ) ); |
|
166 |
|
167 //send data to router for handling |
|
168 iRouter->Send( *messagePtr, iObjId); |
|
169 } |
|
170 else |
|
171 { |
|
172 //construct not reachable resp message |
|
173 C_TRACE( ( _T( "DISINameService::Receive **ELSE** !!" ) ) ); |
|
174 BuildAndSendCommIsaEntityNotReachableResp(aMessage); |
|
175 } |
|
176 } |
|
177 Kern::MutexSignal( *iNameServiceMutex ); |
|
178 C_TRACE( ( _T( "DISINameService::DISINameService<" ) ) ); |
|
179 } |
|
180 |
|
181 void DISINameService::HandleNameQueryResp( const TDesC8& aMessage, const TUint8* msgPtr ) |
|
182 { |
|
183 C_TRACE( ( _T( "DISINameService::HandleNameQueryResp>" ) ) ); |
|
184 TUint32 name = GETB32( &msgPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_NAME ] ); |
|
185 TUint32 mask = GETB32( &msgPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_REQ_OFFSET_BITMASK ] ); |
|
186 |
|
187 RArray <TNameTable*> nameTable; |
|
188 TInt32 count = iNameRecords->NameQuery( name, mask, &nameTable ); |
|
189 |
|
190 TUint16 msgLength = ( SIZE_PNS_NAME_QUERY_RESP + ( count * SIZE_PN_NAME_SRV_ITEM_STR ) ); |
|
191 TDes8& respMsg = MemApi::AllocBlock( msgLength ); |
|
192 respMsg.SetLength( msgLength ); |
|
193 TUint8* respPtr = const_cast<TUint8*>( respMsg.Ptr() ); |
|
194 |
|
195 respPtr[ ISI_HEADER_OFFSET_MEDIA ] = msgPtr[ ISI_HEADER_OFFSET_MEDIA ]; |
|
196 SET_RECEIVER_DEV( respPtr, msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] ); |
|
197 SET_SENDER_DEV( respPtr, PN_DEV_OWN ); |
|
198 respPtr[ ISI_HEADER_OFFSET_RESOURCEID ] = PN_NAMESERVICE; |
|
199 SET_LENGTH( respPtr, ( msgLength - PN_HEADER_SIZE ) ); |
|
200 SET_RECEIVER_OBJ( respPtr, msgPtr[ ISI_HEADER_OFFSET_SENDEROBJECT ] ); |
|
201 SET_SENDER_OBJ( respPtr, PN_OBJ_ROUTER ); |
|
202 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_UTID ] = msgPtr[ ISI_HEADER_OFFSET_TRANSID ]; |
|
203 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_SUBFUNCTION ]= PNS_NAME_QUERY_RESP; |
|
204 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_TOTALMATCHES ] = count >> 8; |
|
205 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_TOTALMATCHES + 1 ] = count; |
|
206 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_MATCHESINMSG ] = count >> 8; |
|
207 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_MATCHESINMSG + 1 ] = count; |
|
208 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_RESERVED1 ] = KFiller; |
|
209 respPtr[ ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_RESERVED2 ] = KFiller; |
|
210 |
|
211 TUint16 index = ISI_HEADER_SIZE + PNS_NAME_QUERY_RESP_OFFSET_NAMEENTRYTBL; |
|
212 for( int i = 0; i < count; i++) |
|
213 { |
|
214 //AddNameTable(); |
|
215 TNameTable* tmp = (nameTable)[ i ]; |
|
216 |
|
217 // Name |
|
218 respPtr[ index++ ] = (TUint8)(tmp->iName >> 24); |
|
219 respPtr[ index++ ] = (TUint8)(tmp->iName >> 16); |
|
220 respPtr[ index++ ] = (TUint8)(tmp->iName >> 8); |
|
221 respPtr[ index++ ] = (TUint8)(tmp->iName); |
|
222 // DevId |
|
223 respPtr[ index++ ] = (TUint8)(tmp->iPhonetAddress >> 8); |
|
224 // ObjId |
|
225 respPtr[ index++ ] = (TUint8)(tmp->iPhonetAddress); |
|
226 // Record flags |
|
227 respPtr[ index++ ] = tmp->iFlags; |
|
228 respPtr[ index++ ] = KFiller; // Reserved |
|
229 } |
|
230 |
|
231 iRouter->Send( respMsg, iObjId ); |
|
232 TDes8* block = reinterpret_cast<TDes8*>( const_cast<TDesC8*>(&aMessage) ); |
|
233 MemApi::DeallocBlock( *block ); |
|
234 C_TRACE( ( _T( "DISINameService::HandleNameQueryResp<" ) ) ); |
|
235 } |
|
236 |
|
237 void DISINameService::HandleNameRemoveResp( const TDesC8& aMessage, const TUint8* msgPtr ) |
|
238 { |
|
239 C_TRACE( ( _T( "DISINameService::HandleNameRemoveResp>" ) ) ); |
|
240 TUint32 name = GETB32( &msgPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_REQ_OFFSET_NAME ] ); |
|
241 |
|
242 TInt8 err = iNameRecords->RemoveName( name ); |
|
243 C_TRACE( ( _T( "DISINameService PNS_NAME_REMOVE_RESP 0x%x>" ), name ) ); |
|
244 |
|
245 TUint16 msgLength( ISI_HEADER_SIZE + SIZE_PNS_NAME_REMOVE_RESP ); |
|
246 TDes8& respMsg = MemApi::AllocBlock( msgLength ); |
|
247 respMsg.SetLength( msgLength ); |
|
248 TUint8* respPtr = const_cast<TUint8*>( respMsg.Ptr() ); |
|
249 |
|
250 respPtr[ ISI_HEADER_OFFSET_MEDIA ] = msgPtr[ ISI_HEADER_OFFSET_MEDIA ]; |
|
251 SET_RECEIVER_DEV( respPtr, msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] ); |
|
252 SET_SENDER_DEV( respPtr, PN_DEV_OWN ); |
|
253 respPtr[ ISI_HEADER_OFFSET_RESOURCEID ] = PN_NAMESERVICE; |
|
254 SET_LENGTH( respPtr, ( msgLength - PN_HEADER_SIZE ) ); |
|
255 SET_RECEIVER_OBJ( respPtr, msgPtr[ ISI_HEADER_OFFSET_SENDEROBJECT ] ); |
|
256 SET_SENDER_OBJ( respPtr, PN_OBJ_ROUTER ); |
|
257 respPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_RESP_OFFSET_UTID ] = msgPtr[ ISI_HEADER_OFFSET_TRANSID ]; |
|
258 respPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_RESP_OFFSET_SUBFUNCTION ] = PNS_NAME_REMOVE_RESP; |
|
259 if( msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] == PN_DEV_OWN ) |
|
260 { |
|
261 respPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_RESP_OFFSET_REASON ] = err; |
|
262 iRouter->Send( respMsg, iObjId ); |
|
263 |
|
264 if( PN_NAME_OK == err ) |
|
265 { |
|
266 C_TRACE( ( _T( "DISINameService PNS_NAME_REMOVE_IND>" ) ) ); |
|
267 msgLength = ( SIZE_PNS_NAME_REMOVE_IND + PNS_NAME_REMOVE_IND_OFFSET_NAMEENTRYTBL ); |
|
268 TDes8& indMsg = MemApi::AllocBlock( msgLength ); |
|
269 indMsg.SetLength( msgLength ); |
|
270 TUint8* indPtr = const_cast<TUint8*>( indMsg.Ptr() ); |
|
271 |
|
272 indPtr[ ISI_HEADER_OFFSET_MEDIA ] = PN_MEDIA_ROUTING_REQ; |
|
273 SET_RECEIVER_DEV( indPtr, msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] ); |
|
274 SET_SENDER_DEV( indPtr, PN_DEV_OWN ); |
|
275 indPtr[ ISI_HEADER_OFFSET_RESOURCEID ] = PN_NAMESERVICE; |
|
276 SET_LENGTH( indPtr, ( msgLength - PN_HEADER_SIZE ) ); |
|
277 SET_RECEIVER_OBJ( indPtr, PN_OBJ_EVENT_MULTICAST ); //communicationmanager |
|
278 SET_SENDER_OBJ( indPtr, PN_OBJ_ROUTER ); |
|
279 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_UTID ] = 0x00; |
|
280 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_SUBFUNCTION ]= PNS_NAME_REMOVE_IND; |
|
281 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_TOTALMATCHES ] = 0x00; |
|
282 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_TOTALMATCHES + 1 ] = 0x01; |
|
283 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_MATCHESINMSG ] = 0x00; |
|
284 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_MATCHESINMSG + 1 ] = 0x01; |
|
285 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_RESERVED1 ] = KFiller; |
|
286 indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_RESERVED2 ] = KFiller; |
|
287 PUTB32( &indPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_IND_OFFSET_NAMEENTRYTBL + PN_NAME_SRV_ITEM_STR_OFFSET_NAME ], name ); |
|
288 |
|
289 iRouter->Send( indMsg, iObjId ); |
|
290 TDes8* block = reinterpret_cast<TDes8*>( const_cast<TDesC8*>(&aMessage) ); |
|
291 MemApi::DeallocBlock( *block ); |
|
292 C_TRACE( ( _T( "DISINameService PNS_NAME_QUERY_IND<" ) ) ); |
|
293 } |
|
294 C_TRACE( ( _T( "DISINameService PNS_NAME_REMOVE_RESP<" ) ) ); |
|
295 } |
|
296 else |
|
297 { |
|
298 C_TRACE( ( _T( "DISINameService::HandlePNSNameMessage PNS_NAME_REMOVE_REQ from other device, PN_NAME_NOT_ALLOWED" ) ) ); |
|
299 respPtr[ ISI_HEADER_SIZE + PNS_NAME_REMOVE_RESP_OFFSET_REASON ] = PN_NAME_NOT_ALLOWED; |
|
300 iRouter->Send( respMsg, iObjId ); |
|
301 } |
|
302 C_TRACE( ( _T( "DISINameService::HandleNameRemoveResp<" ) ) ); |
|
303 } |
|
304 |
|
305 void DISINameService::HandlePNSNameMessage( const TDesC8& aMessage ) |
|
306 { |
|
307 C_TRACE( ( _T( "DISINameService::HandlePNSNameMessage 0x%x>" ), &aMessage ) ); |
|
308 const TUint8* msgPtr( aMessage.Ptr() ); |
|
309 TInt8 err( KErrArgument ); |
|
310 switch( msgPtr[ ISI_HEADER_OFFSET_MESSAGEID ] ) |
|
311 { |
|
312 case PNS_NAME_QUERY_REQ: |
|
313 { |
|
314 C_TRACE( ( _T( "DISINameService PNS_NAME_QUERY_REQ>" ) ) ); |
|
315 // if( msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] == THIS_DEVICE ) |
|
316 // { |
|
317 C_TRACE( ( _T( "DISINameService PNS_NAME_QUERY_RESP>" ) ) ); |
|
318 HandleNameQueryResp( aMessage, msgPtr ); |
|
319 // } |
|
320 // else |
|
321 // { |
|
322 // C_TRACE( ( _T( "DISINameService::HandlePNSNameMessage PNS_NAME_QUERY_REQ from other device, ignore" ) ) ); |
|
323 // } |
|
324 C_TRACE( ( _T( "DISINameService PNS_NAME_QUERY_REQ<" ) ) ); |
|
325 break; |
|
326 } |
|
327 case PNS_NAME_ADD_REQ: |
|
328 { |
|
329 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_REQ>" ) ) ); |
|
330 |
|
331 TUint16 msgLength( ISI_HEADER_SIZE + SIZE_PNS_NAME_ADD_RESP ); |
|
332 TDes8& respMsg = MemApi::AllocBlock( msgLength ); |
|
333 respMsg.SetLength( msgLength ); |
|
334 TUint8* respPtr = const_cast<TUint8*>( respMsg.Ptr() ); |
|
335 |
|
336 respPtr[ ISI_HEADER_OFFSET_MEDIA ] = msgPtr[ ISI_HEADER_OFFSET_MEDIA ]; |
|
337 SET_RECEIVER_DEV( respPtr, msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] ); |
|
338 SET_SENDER_DEV( respPtr, PN_DEV_OWN ); |
|
339 respPtr[ ISI_HEADER_OFFSET_RESOURCEID ] = PN_NAMESERVICE; |
|
340 SET_LENGTH( respPtr, ( msgLength - PN_HEADER_SIZE ) ); |
|
341 SET_RECEIVER_OBJ( respPtr, msgPtr[ ISI_HEADER_OFFSET_SENDEROBJECT ] ); |
|
342 SET_SENDER_OBJ( respPtr, PN_OBJ_ROUTER ); |
|
343 respPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_RESP_OFFSET_UTID ] = msgPtr[ ISI_HEADER_OFFSET_TRANSID ]; |
|
344 respPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_RESP_OFFSET_SUBFUNCTION ] = PNS_NAME_ADD_RESP; |
|
345 |
|
346 if( msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] == PN_DEV_OWN ) |
|
347 { |
|
348 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_REQ from this device" ) ) ); |
|
349 TUint32 name = GETB32( &msgPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_REQ_OFFSET_NAMEENTRY ] ); |
|
350 TUint16 phonetAddr = GETB16( &msgPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_REQ_OFFSET_NAMEENTRY + PN_NAME_SRV_ITEM_STR_OFFSET_DEV ] ); |
|
351 TUint8 flags = msgPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_REQ_OFFSET_NAMEENTRY + PN_NAME_SRV_ITEM_STR_OFFSET_FLAGS ]; |
|
352 err = iNameRecords->AddName( name, phonetAddr, flags ); |
|
353 respPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_RESP_OFFSET_REASON ] = err; |
|
354 for( TInt i( 0 ); i < respMsg.Length(); i++ ) |
|
355 { |
|
356 C_TRACE( ( _T( "PNS_NAME_ADD_RESP index[ %d ] data 0x%x"), i, respMsg.Ptr()[i] ) ); |
|
357 } |
|
358 iRouter->Send( respMsg, iObjId ); |
|
359 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_RESP from this device<" ) ) ); |
|
360 if( err == PN_NAME_OK ) |
|
361 { |
|
362 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_IND>" ) ) ); |
|
363 RArray <TNameTable*>* nameTable = NULL; |
|
364 nameTable = iNameRecords->GetNameTable(); |
|
365 msgLength = ( SIZE_PNS_NAME_ADD_IND + ( SIZE_PN_NAME_SRV_ITEM_STR * nameTable->Count() ) ); |
|
366 TDes8& indMsg = MemApi::AllocBlock( msgLength ); |
|
367 indMsg.SetLength( msgLength ); |
|
368 TUint8* indPtr = const_cast<TUint8*>( indMsg.Ptr() ); |
|
369 indPtr[ ISI_HEADER_OFFSET_MEDIA ] = PN_MEDIA_ROUTING_REQ; |
|
370 SET_RECEIVER_DEV( indPtr, msgPtr[ ISI_HEADER_OFFSET_SENDERDEVICE ] ); |
|
371 SET_SENDER_DEV( indPtr, PN_DEV_OWN ); |
|
372 indPtr[ ISI_HEADER_OFFSET_RESOURCEID ] = PN_NAMESERVICE; |
|
373 SET_LENGTH( indPtr, ( msgLength - PN_HEADER_SIZE ) ); |
|
374 SET_RECEIVER_OBJ( indPtr, PN_OBJ_EVENT_MULTICAST ); //communicationmanager |
|
375 SET_SENDER_OBJ( indPtr, PN_OBJ_ROUTER ); |
|
376 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_UTID ] = 0x00; |
|
377 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_SUBFUNCTION ]= PNS_NAME_ADD_IND; |
|
378 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_TOTALMATCHES ] = 0x00; |
|
379 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_TOTALMATCHES + 1 ] = 0x01; |
|
380 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_MATCHESINMSG ] = 0x00; |
|
381 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_MATCHESINMSG + 1 ] = 0x01; |
|
382 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_RESERVED1 ] = KFiller; |
|
383 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_RESERVED2 ] = KFiller; |
|
384 PUTB32( &indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_NAMEENTRYTBL + PN_NAME_SRV_ITEM_STR_OFFSET_NAME ], name ); |
|
385 PUTB16( &indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_NAMEENTRYTBL + PN_NAME_SRV_ITEM_STR_OFFSET_DEV ], phonetAddr ); |
|
386 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_NAMEENTRYTBL + PN_NAME_SRV_ITEM_STR_OFFSET_FLAGS ] = flags; |
|
387 indPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_IND_OFFSET_NAMEENTRYTBL + PN_NAME_SRV_ITEM_STR_OFFSET_RESERVED ] = KFiller; |
|
388 for( TInt i( 0 ); i < indMsg.Length(); i++ ) |
|
389 { |
|
390 C_TRACE( ( _T( "PNS_NAME_ADD_IND index[ %d ] data 0x%x"), i, indMsg.Ptr()[i] ) ); |
|
391 } |
|
392 iRouter->Send( indMsg, iObjId ); |
|
393 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_IND<" ) ) ); |
|
394 } |
|
395 } |
|
396 else |
|
397 { |
|
398 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_REQ from other device>" ) ) ); |
|
399 respPtr[ ISI_HEADER_SIZE + PNS_NAME_ADD_RESP_OFFSET_REASON ] = PN_NAME_NOT_ALLOWED; |
|
400 for( TInt i( 0 ); i < respMsg.Length(); i++ ) |
|
401 { |
|
402 C_TRACE( ( _T( "PNS_NAME_ADD_RESP index[ %d ] data 0x%x"), i, respMsg.Ptr()[i] ) ); |
|
403 } |
|
404 iRouter->Send( respMsg, iObjId ); |
|
405 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_RESP from other device<" ) ) ); |
|
406 } |
|
407 TDes8* block = reinterpret_cast<TDes8*>( const_cast<TDesC8*>(&aMessage) ); |
|
408 MemApi::DeallocBlock( *block ); |
|
409 C_TRACE( ( _T( "DISINameService PNS_NAME_ADD_REQ<" ) ) ); |
|
410 break; |
|
411 } |
|
412 case PNS_NAME_REMOVE_REQ: |
|
413 { |
|
414 C_TRACE( ( _T( "DISINameService PNS_NAME_REMOVE_REQ>" ) ) ); |
|
415 HandleNameRemoveResp( aMessage, msgPtr ); |
|
416 C_TRACE( ( _T( "DISINameService PNS_NAME_REMOVE_REQ<" ) ) ); |
|
417 break; |
|
418 } |
|
419 default: |
|
420 { |
|
421 ASSERT_RESET_ALWAYS( 0, ( EISINameServiceUnknownMessage | EDISINameServiceTraceId << KClassIdentifierShift ) ); |
|
422 C_TRACE( ( _T( "DISINameService::HandlePNSNameMessage unknown NAMESERVICE message" ) ) ); |
|
423 } |
|
424 } |
|
425 C_TRACE( ( _T( "DISINameService::HandlePNSNameMessage<" ) ) ); |
|
426 } |
|
427 |
|
428 |
|
429 EXPORT_C TBool DISINameService::IsValidResource( |
|
430 const TDesC8& aMessage |
|
431 ) |
|
432 { |
|
433 TInt err( Kern::MutexWait( *iNameServiceMutex ) ); |
|
434 ASSERT_RESET_ALWAYS( ( KErrNone == err ), ( EISINameServiceMutexWaitFailed | EDISINameServiceTraceId << KClassIdentifierShift ) ); |
|
435 C_TRACE( ( _T( "DISINameService::IsValidResource 0x%x>" ), &aMessage ) ); |
|
436 C_TRACE( ( _T( "DISINameService::IsValidResource 0x%x<" ), &aMessage ) ); |
|
437 Kern::MutexSignal( *iNameServiceMutex ); |
|
438 return ETrue; |
|
439 } |
|
440 |
|
441 |
|
442 DECLARE_STANDARD_EXTENSION() |
|
443 { |
|
444 Kern::Printf( "ISI Name Service extension>" ); |
|
445 // Create a container extension |
|
446 DISINameService* extension = new DISINameService(); |
|
447 TRACE_ASSERT( extension ); |
|
448 Kern::Printf( "ISI Name Service extension<" ); |
|
449 return extension ? KErrNone : KErrNoMemory; |
|
450 } |
|
451 |
|
452 void DISINameService::BuildAndSendCommIsaEntityNotReachableResp( |
|
453 const TDesC8& aMsg |
|
454 ) |
|
455 { |
|
456 C_TRACE( ( _T( "DISINameService::ConstructCommIsaEntityNotReachableResp 0x%x ->" ), &aMsg ) ); |
|
457 // Make channel opening request followinfg COMM specification: 000.026 |
|
458 // Length is sixteen bytes. |
|
459 TUint8 length( ISI_HEADER_SIZE + SIZE_COMMON_MESSAGE_COMM_ISA_ENTITY_NOT_REACHABLE_RESP ); |
|
460 TDes8& tempPtr = MemApi::AllocBlock( length ); |
|
461 ASSERT_RESET_ALWAYS( &tempPtr, EISINameServiceMemAllocFailure ); //lisää jotakin infoa jotta löytyy ilman tracea...pelkän luvun perusteella?? |
|
462 TUint8* ptr = const_cast<TUint8*>( tempPtr.Ptr() ); |
|
463 // We start to append from transaction id. |
|
464 tempPtr.SetLength( SIZE_COMMON_MESSAGE_COMM_ISA_ENTITY_NOT_REACHABLE_RESP ); |
|
465 // Get the header until messageid from prev. message. |
|
466 // Just turn receiver and sender device and object vice versa. |
|
467 const TUint8* msgTmpPtr( aMsg.Ptr() ); |
|
468 ptr[ ISI_HEADER_OFFSET_MEDIA ] = msgTmpPtr[ ISI_HEADER_OFFSET_MEDIA ]; |
|
469 SET_RECEIVER_DEV( ptr, GET_SENDER_DEV( aMsg ) ); |
|
470 SET_SENDER_DEV ( ptr, GET_RECEIVER_DEV( aMsg ) ); |
|
471 ptr[ ISI_HEADER_OFFSET_RESOURCEID ] = msgTmpPtr[ ISI_HEADER_OFFSET_RESOURCEID ]; |
|
472 SET_LENGTH( ptr, length - PN_HEADER_SIZE ); |
|
473 SET_RECEIVER_OBJ( ptr, GET_SENDER_OBJ( aMsg ) ); |
|
474 SET_SENDER_OBJ( ptr, GET_RECEIVER_OBJ( aMsg ) ); |
|
475 // Transactionid. Set to 0x01 since this is the first. |
|
476 tempPtr.Append( msgTmpPtr[ ISI_HEADER_OFFSET_TRANSID ] ); |
|
477 // Message ID |
|
478 tempPtr.Append( COMMON_MESSAGE ); // 0xF0 |
|
479 // Sub message ID. |
|
480 tempPtr.Append( COMM_ISA_ENTITY_NOT_REACHABLE_RESP ); // 0x14 |
|
481 // Not Delivered Message from original req. |
|
482 tempPtr.Append( msgTmpPtr[ ISI_HEADER_OFFSET_MESSAGEID ] ); |
|
483 // Status - COMM_ISA_ENTITY_NOT_EXISTING |
|
484 tempPtr.Append( COMM_ISA_ENTITY_NOT_EXISTING); //0x01 |
|
485 // Filler |
|
486 tempPtr.Append( 0x00 ); |
|
487 // Filler |
|
488 tempPtr.Append( 0x00 ); |
|
489 // Filler |
|
490 tempPtr.Append( 0x00 ); |
|
491 |
|
492 //send data to router for handling |
|
493 iRouter->Send( tempPtr, iObjId); |
|
494 |
|
495 TDes8* block = reinterpret_cast<TDes8*>( const_cast<TDesC8*>(&aMsg) ); |
|
496 MemApi::DeallocBlock( *block ); |
|
497 |
|
498 C_TRACE( ( _T( "DISINameService::SendCommIsaEntityNotReachableResp 0x%x <-" ), &aMsg ) ); |
|
499 } |
|
500 |
|
501 |