|
1 // Copyright (c) 2008-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 @internalTechnology |
|
19 |
|
20 */ |
|
21 |
|
22 #include "RRLP-Messages.h" |
|
23 #include "ULP.h" |
|
24 |
|
25 #include "suplpos.h" |
|
26 #include "suplpospayload.h" |
|
27 #include "rrlpmeasureposrequest.h" |
|
28 #include "rrlpassistancedata.h" |
|
29 #include "rrlpprotocolerror.h" |
|
30 #include "suplasn1error.h" |
|
31 #include "supldevloggermacros.h" |
|
32 |
|
33 #include <lbssatellite.h> |
|
34 #include <lbs/lbsgpsmeasurement.h> |
|
35 |
|
36 /** |
|
37 Static factory constructor |
|
38 */ |
|
39 EXPORT_C CSuplPos* CSuplPos::NewL(TBool aIsOutgoingMessage) |
|
40 { |
|
41 SUPLLOG(ELogP1, "CSuplPos::NewL() Begin\n"); |
|
42 CSuplPos* self = CSuplPos::NewLC(aIsOutgoingMessage); |
|
43 SUPLLOG(ELogP1, "CSuplPos::NewL() End\n"); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 EXPORT_C CSuplPos* CSuplPos::NewLC(TBool aIsOutgoingMessage) |
|
49 { |
|
50 SUPLLOG(ELogP1, "CSuplPos::NewLC() Begin\n"); |
|
51 CSuplPos* self = new (ELeave) CSuplPos(aIsOutgoingMessage); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 SUPLLOG(ELogP1, "CSuplPos::NewLC() End\n"); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 /** |
|
60 Constructor |
|
61 */ |
|
62 CSuplPos::CSuplPos(TBool aIsOutgoingMessage) |
|
63 : CSuplMessageBase::CSuplMessageBase(ESuplPos, aIsOutgoingMessage) |
|
64 { |
|
65 } |
|
66 |
|
67 |
|
68 /** |
|
69 Second stage constructor |
|
70 */ |
|
71 void CSuplPos::ConstructL() |
|
72 { |
|
73 // call the base class ConstructL() to create common data structures |
|
74 CSuplMessageBase::ConstructL(); |
|
75 |
|
76 // message specific structures for outgoing messages. |
|
77 if (iIsOutgoingMessage) |
|
78 { |
|
79 // local reference to context object |
|
80 OSCTXT* pctxt = iControl->getCtxtPtr(); |
|
81 |
|
82 // create the SUPL POS specific data structures |
|
83 iData->message.t = T_UlpMessage_msSUPLPOS; |
|
84 iData->message.u.msSUPLPOS = (ASN1T_SUPLPOS*)rtxMemAllocZ(pctxt, sizeof(ASN1T_SUPLPOS)); |
|
85 LeaveIfAllocErrorL(); |
|
86 |
|
87 iData->message.u.msSUPLPOS->m.velocityPresent = 0; |
|
88 |
|
89 iData->message.u.msSUPLPOS->posPayLoad.t = T_PosPayLoad_rrlpPayload; |
|
90 iData->message.u.msSUPLPOS->posPayLoad.u.rrlpPayload = (ASN1T_PosPayLoad_rrlpPayload*)rtxMemAllocZ(pctxt, sizeof(ASN1T_PosPayLoad_rrlpPayload)); |
|
91 LeaveIfAllocErrorL(); |
|
92 } |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 Destructor |
|
98 */ |
|
99 CSuplPos::~CSuplPos() |
|
100 { |
|
101 SUPLLOG(ELogP1, "CSuplPos::~CSuplPos() Begin\n"); |
|
102 delete iPosPayload; |
|
103 delete iDecodeBuffer; |
|
104 delete iPayloadData; |
|
105 delete iPayloadPdu; |
|
106 SUPLLOG(ELogP1, "CSuplPos::~CSuplPos() End\n"); |
|
107 } |
|
108 |
|
109 |
|
110 /** |
|
111 SetVelocity() |
|
112 |
|
113 Set the velocity parameter. The parameter TPositionInfoBase must contain |
|
114 course information (eg be TPositionCourseInfo or derived) for the velocity |
|
115 parameter to be set. |
|
116 |
|
117 @param aPosInfo: contains current velocity estimate |
|
118 @return KErrNone normally |
|
119 KErrNotFound if no TCourse information present |
|
120 KErrNoMemory if failed to allocate memory to store the outgoing data |
|
121 */ |
|
122 EXPORT_C TInt CSuplPos::SetVelocity(const TPositionInfoBase& aPosInfo) |
|
123 { |
|
124 SUPLLOG(ELogP1, "CSuplPos::SetVelocity() Begin\n"); |
|
125 __ASSERT_DEBUG(iIsOutgoingMessage, User::Invariant()); |
|
126 __ASSERT_DEBUG(iData->message.u.msSUPLPOS != NULL, User::Invariant()); |
|
127 |
|
128 // handle velocity (TCourse) information |
|
129 if ((aPosInfo.PositionClassType() & EPositionCourseInfoClass) != 0) |
|
130 { |
|
131 TPositionCourseInfo courseInfo = reinterpret_cast <const TPositionCourseInfo&> (aPosInfo); |
|
132 TCourse course; |
|
133 courseInfo.GetCourse(course); |
|
134 |
|
135 // populate the velocity parameter |
|
136 iData->message.u.msSUPLPOS->m.velocityPresent = 1; |
|
137 TInt velErr = PopulateVelocity(course, iData->message.u.msSUPLPOS->velocity); |
|
138 if (velErr != KErrNone) |
|
139 { |
|
140 SUPLLOG(ELogP1, "CSuplPos::SetVelocity() End (error populating velocity)\n"); |
|
141 return velErr; |
|
142 } |
|
143 } |
|
144 else |
|
145 { |
|
146 // passed parameter does not contain course information. |
|
147 SUPLLOG(ELogP1, "CSuplPos::SetVelocity() End (Course Information Not Present)\n"); |
|
148 return KErrNotFound; |
|
149 } |
|
150 |
|
151 SUPLLOG(ELogP1, "CSuplPos::SetVelocity() End\n"); |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 |
|
156 /** |
|
157 VelocityPresent() |
|
158 |
|
159 @return ETrue if the optional velocity parameter is present |
|
160 */ |
|
161 EXPORT_C TBool CSuplPos::VelocityPresent() |
|
162 { |
|
163 SUPLLOG(ELogP1, "CSuplPos::VelocityPresent() Begin\n"); |
|
164 __ASSERT_DEBUG(!iIsOutgoingMessage, User::Invariant()); |
|
165 __ASSERT_DEBUG(iData->message.u.msSUPLPOS != NULL, User::Invariant()); |
|
166 |
|
167 if (iData->message.u.msSUPLPOS->m.velocityPresent != 0) |
|
168 { |
|
169 SUPLLOG(ELogP1, "CSuplPos::VelocityPresent(ETrue) End\n"); |
|
170 return ETrue; |
|
171 } |
|
172 |
|
173 SUPLLOG(ELogP1, "CSuplPos::VelocityPresent(EFalse) End\n"); |
|
174 return EFalse; |
|
175 } |
|
176 |
|
177 |
|
178 /** |
|
179 Velocity() |
|
180 |
|
181 Populates aPosInfo according to the velocity parameter |
|
182 The parameter TPositionInfoBase must be able to store course information |
|
183 (eg be TPositionCourseInfo or derived) for the velocity parameter to be set. |
|
184 |
|
185 Note that the LBS course API currently does not support vertical velocity, |
|
186 so vertical speed information is ignored. |
|
187 |
|
188 @param aPosInfo: on return, populated with velocity information. |
|
189 @return KErrNotFound if the velocity is not available in the received message |
|
190 KErrNotSupported if the TPositionInfoBase can not hold course information. |
|
191 KErrArgument if the received data is not in the expected format. |
|
192 KErrNone otherwise |
|
193 */ |
|
194 EXPORT_C TInt CSuplPos::GetVelocity(TPositionInfoBase& aPosInfo) |
|
195 { |
|
196 SUPLLOG(ELogP1, "CSuplPos::Velocity() Begin\n"); |
|
197 __ASSERT_DEBUG(!iIsOutgoingMessage, User::Invariant()); |
|
198 __ASSERT_DEBUG(iData->message.u.msSUPLPOS != NULL, User::Invariant()); |
|
199 |
|
200 // check the velocity was present in the received message |
|
201 if (iData->message.u.msSUPLPOS->m.velocityPresent == 0) |
|
202 { |
|
203 return KErrNotFound; |
|
204 } |
|
205 |
|
206 // check the TPositionInfoBase can receive course information. |
|
207 if ((aPosInfo.PositionClassType() & EPositionCourseInfoClass) == 0) |
|
208 { |
|
209 __ASSERT_DEBUG(0, User::Invariant()); |
|
210 return KErrNotSupported; |
|
211 } |
|
212 |
|
213 // source velocity reference |
|
214 ASN1T_Velocity& velocity = iData->message.u.msSUPLPOS->velocity; |
|
215 |
|
216 // target course reference |
|
217 TCourse course; |
|
218 |
|
219 // set the course information according to the received velocity type |
|
220 switch (velocity.t) |
|
221 { |
|
222 case T_Velocity_horvel: |
|
223 { |
|
224 TUint bearing = 0; |
|
225 bearing = velocity.u.horvel->bearing.data[0] << 1; |
|
226 bearing |= velocity.u.horvel->bearing.data[1] >> 7; |
|
227 |
|
228 TUint speed = 0; |
|
229 speed = velocity.u.horvel->horspeed.data[0] << 8; |
|
230 speed |= velocity.u.horvel->horspeed.data[1]; |
|
231 |
|
232 course.SetHeading((TReal32)bearing); |
|
233 course.SetSpeed(ConvertHorSpeedToMetersPerSecond(speed)); |
|
234 break; |
|
235 } |
|
236 case T_Velocity_horandvervel: |
|
237 { |
|
238 TUint bearing = 0; |
|
239 bearing = velocity.u.horandvervel->bearing.data[0] << 1; |
|
240 bearing |= velocity.u.horandvervel->bearing.data[1] >> 7; |
|
241 |
|
242 TUint speed = 0; |
|
243 speed = velocity.u.horandvervel->horspeed.data[0] << 8; |
|
244 speed |= velocity.u.horandvervel->horspeed.data[1]; |
|
245 |
|
246 course.SetHeading((TReal32)bearing); |
|
247 course.SetSpeed(ConvertHorSpeedToMetersPerSecond(speed)); |
|
248 break; |
|
249 } |
|
250 case T_Velocity_horveluncert: |
|
251 { |
|
252 TUint bearing = 0; |
|
253 bearing = velocity.u.horveluncert->bearing.data[0] << 1; |
|
254 bearing |= velocity.u.horveluncert->bearing.data[1] >> 7; |
|
255 |
|
256 TUint speed = 0; |
|
257 speed = velocity.u.horveluncert->horspeed.data[0] << 8; |
|
258 speed |= velocity.u.horveluncert->horspeed.data[1]; |
|
259 |
|
260 TUint speedAccuracy = velocity.u.horveluncert->uncertspeed.data[0]; |
|
261 |
|
262 course.SetHeading((TReal32)bearing); |
|
263 course.SetSpeed(ConvertHorSpeedToMetersPerSecond(speed)); |
|
264 course.SetSpeedAccuracy(ConvertHorSpeedAccuracyToMetersPerSecond(speedAccuracy)); |
|
265 break; |
|
266 } |
|
267 case T_Velocity_horandveruncert: |
|
268 { |
|
269 TUint bearing = 0; |
|
270 bearing = velocity.u.horandveruncert->bearing.data[0] << 1; |
|
271 bearing |= velocity.u.horandveruncert->bearing.data[1] >> 7; |
|
272 |
|
273 TUint speed = 0; |
|
274 speed = velocity.u.horandveruncert->horspeed.data[0] << 8; |
|
275 speed |= velocity.u.horandveruncert->horspeed.data[1]; |
|
276 |
|
277 TUint speedAccuracy = velocity.u.horandveruncert->horuncertspeed.data[0]; |
|
278 |
|
279 course.SetHeading((TReal32)bearing); |
|
280 course.SetSpeed(ConvertHorSpeedToMetersPerSecond(speed)); |
|
281 course.SetSpeedAccuracy(ConvertHorSpeedAccuracyToMetersPerSecond(speedAccuracy)); |
|
282 break; |
|
283 } |
|
284 default: |
|
285 { |
|
286 __ASSERT_DEBUG(0, User::Invariant()); |
|
287 return KErrArgument; |
|
288 } |
|
289 } |
|
290 |
|
291 // set the course information in the return parameter. |
|
292 TPositionCourseInfo posInfo = reinterpret_cast <const TPositionCourseInfo&> (aPosInfo); |
|
293 posInfo.SetCourse(course); |
|
294 |
|
295 SUPLLOG(ELogP1, "CSuplPos::Velocity() End\n"); |
|
296 return KErrNone; |
|
297 } |
|
298 |
|
299 |
|
300 /** |
|
301 SetPosPayload() |
|
302 |
|
303 Assigns the payload RRLP message for outgoing messages. |
|
304 CSuplPos instance takes immediate ownership of the CSuplPosPayload object. |
|
305 |
|
306 @param |
|
307 */ |
|
308 EXPORT_C void CSuplPos::SetPosPayload(CSuplPosPayload* aPayload) |
|
309 { |
|
310 SUPLLOG(ELogP1, "CSuplPos::SetPosPayload() Begin\n"); |
|
311 __ASSERT_DEBUG(iIsOutgoingMessage, User::Invariant()); |
|
312 __ASSERT_DEBUG(iPosPayload == NULL, User::Invariant()); |
|
313 iPosPayload = aPayload; |
|
314 SUPLLOG(ELogP1, "CSuplPos::SetPosPayload() End\n"); |
|
315 } |
|
316 |
|
317 |
|
318 /** |
|
319 DecodePosPayloadL() |
|
320 |
|
321 Decodes the content of received positioning payload. Must be called before content |
|
322 of the payload may be accessed |
|
323 |
|
324 @param aError, on return indicates if an error was encountered, |
|
325 eg KErrNotSupported for unsupported payload types. |
|
326 */ |
|
327 void CSuplPos::DecodePosPayloadL(TInt& aError) |
|
328 { |
|
329 SUPLLOG(ELogP1, "CSuplPos::DecodePosPayloadL() Begin\n"); |
|
330 __ASSERT_DEBUG(!iIsOutgoingMessage, User::Invariant()); |
|
331 __ASSERT_DEBUG(iPosPayload == NULL, User::Invariant()); |
|
332 __ASSERT_DEBUG(iData->message.u.msSUPLPOS != NULL, User::Invariant()); |
|
333 |
|
334 // check that the payload is RRLP |
|
335 if (iData->message.u.msSUPLPOS->posPayLoad.t != T_PosPayLoad_rrlpPayload) |
|
336 { |
|
337 aError = ESuplAsn1ErrUnsupportedPosProtocol; |
|
338 return; |
|
339 } |
|
340 |
|
341 // extract the RRLP payload and decode and compare... |
|
342 TInt payloadLength = iData->message.u.msSUPLPOS->posPayLoad.u.rrlpPayload->numocts; |
|
343 OSOCTET* payloadptr = &iData->message.u.msSUPLPOS->posPayLoad.u.rrlpPayload->data[0]; |
|
344 |
|
345 // Create the payload decode buffer |
|
346 ASN1Context* payloadContext = new (ELeave) ASN1Context; |
|
347 CleanupDeletePushL(payloadContext); |
|
348 iDecodeBuffer = new (ELeave) ASN1PERDecodeBuffer (payloadptr, payloadLength, FALSE, payloadContext); |
|
349 // construction of iDecodeBuffer successful, pop payloadContext off the cleanup stack |
|
350 CleanupStack::Pop(payloadContext); |
|
351 |
|
352 // Create data and control objects to manage the decode |
|
353 iPayloadData = new (ELeave) ASN1T_PDU(); |
|
354 iPayloadPdu = new (ELeave) ASN1C_PDU (*iDecodeBuffer, *iPayloadData); |
|
355 |
|
356 TInt stat = iPayloadPdu->Decode(); |
|
357 |
|
358 // return now if error encountered while decoding |
|
359 if (stat != KErrNone) |
|
360 { |
|
361 aError = ProcessAsn1Error(stat); |
|
362 return; |
|
363 } |
|
364 |
|
365 // build payload content wrapper. |
|
366 switch (iPayloadData->component.t) |
|
367 { |
|
368 case T_RRLP_Component_msrPositionReq: |
|
369 { |
|
370 iPosPayload = CRrlpMeasurePositionRequest::NewL(); |
|
371 break; |
|
372 } |
|
373 |
|
374 case T_RRLP_Component_assistanceData: |
|
375 { |
|
376 iPosPayload = CRrlpAssistanceData::NewL(); |
|
377 break; |
|
378 } |
|
379 |
|
380 case T_RRLP_Component_protocolError: |
|
381 { |
|
382 iPosPayload = CRrlpProtocolError::NewL(EFalse); |
|
383 break; |
|
384 } |
|
385 |
|
386 case T_RRLP_Component_msrPositionRsp: |
|
387 case T_RRLP_Component_assistanceDataAck: |
|
388 default: |
|
389 { |
|
390 // unsupported message type |
|
391 aError = ESuplAsn1ErrUnsupportedPosMessageType; |
|
392 return; |
|
393 } |
|
394 } |
|
395 |
|
396 // pass ownership of the decoded message content. |
|
397 CRrlpMessageBase* rrlpMessage = (CRrlpMessageBase*)iPosPayload; |
|
398 rrlpMessage->SetDecodedData(iPayloadData, iPayloadPdu); |
|
399 iPayloadData = NULL; |
|
400 iPayloadPdu = NULL; |
|
401 |
|
402 // no longer need the decode buffer object. |
|
403 delete iDecodeBuffer; |
|
404 iDecodeBuffer = NULL; |
|
405 SUPLLOG(ELogP1, "CSuplPos::DecodePosPayloadL() End\n"); |
|
406 } |
|
407 |
|
408 |
|
409 /** |
|
410 PosPayload() |
|
411 |
|
412 Returns the decoded positioning payload for received SUPL POS messages. |
|
413 Note that ownership of the position payload is returned - the calling entity |
|
414 becomes responsible for the destruction of the positioning payload. |
|
415 |
|
416 @return pointer to the positioning payload. |
|
417 */ |
|
418 EXPORT_C CSuplPosPayload* CSuplPos::PosPayload() |
|
419 { |
|
420 SUPLLOG(ELogP1, "CSuplPos::PosPayload() Begin\n"); |
|
421 __ASSERT_DEBUG(!iIsOutgoingMessage, User::Invariant()); |
|
422 __ASSERT_DEBUG(iPosPayload != NULL, User::Invariant()); |
|
423 __ASSERT_DEBUG(iData->message.u.msSUPLPOS != NULL, User::Invariant()); |
|
424 |
|
425 CSuplPosPayload* posPayload = iPosPayload; |
|
426 iPosPayload = NULL; |
|
427 |
|
428 SUPLLOG(ELogP1, "CSuplPos::PosPayload() End\n"); |
|
429 |
|
430 return posPayload; |
|
431 } |
|
432 |
|
433 |
|
434 /** |
|
435 EncodePosPayloadL() |
|
436 |
|
437 Encodes the positioning payload. |
|
438 |
|
439 @return error indication, KErrNone otherwise |
|
440 */ |
|
441 TInt CSuplPos::EncodePosPayloadL() |
|
442 { |
|
443 SUPLLOG(ELogP1, "CSuplPos::EncodePosPayloadL() Begin\n"); |
|
444 __ASSERT_DEBUG(iIsOutgoingMessage, User::Invariant()); |
|
445 __ASSERT_DEBUG(iPosPayload!=NULL, User::Invariant()); |
|
446 |
|
447 // encode the positioning payload. |
|
448 // Payload is encoded directly to the supl payload container. |
|
449 TPtr8 payloadPtr(iData->message.u.msSUPLPOS->posPayLoad.u.rrlpPayload->data, 8192); |
|
450 TInt err = iPosPayload->EncodeToL(payloadPtr); |
|
451 if (err!=KErrNone) |
|
452 { |
|
453 SUPLLOG(ELogP1, "CSuplPos::EncodePosPayloadL() Error\n"); |
|
454 return ProcessAsn1Error(err); |
|
455 } |
|
456 |
|
457 // set the SUPL payload length to the encoded payload. |
|
458 iData->message.u.msSUPLPOS->posPayLoad.u.rrlpPayload->numocts = payloadPtr.Length(); |
|
459 |
|
460 SUPLLOG(ELogP1, "CSuplPos::EncodePosPayloadL() End\n"); |
|
461 return KErrNone; |
|
462 } |
|
463 |
|
464 /** |
|
465 ConvertHorSpeedToMetersPerSecond() |
|
466 |
|
467 Converts received speed value N to meters per second, according to |
|
468 3GPP GAD: |
|
469 |
|
470 for N = 0 N <= h < N+0.5 |
|
471 for 0 < N < 2^16-1 N-0.5 <= h < N+0.5 |
|
472 for N=2^16-1 N-0.5 <= h |
|
473 |
|
474 where h = speed in km/hour |
|
475 |
|
476 @param aSpeed - the received, encoded speed N. |
|
477 @return the uncertainty speed in meters per second. |
|
478 */ |
|
479 TReal32 CSuplPos::ConvertHorSpeedToMetersPerSecond(TUint aSpeed) |
|
480 { |
|
481 SUPLLOG(ELogP1, "CSuplPos::ConvertHorSpeedToMetersPerSecond() Begin\n"); |
|
482 TReal32 kph; |
|
483 if (aSpeed == 0) |
|
484 { |
|
485 kph = 0; |
|
486 } |
|
487 else if (aSpeed < 65536) |
|
488 { |
|
489 kph = aSpeed - 0.5; |
|
490 } |
|
491 else |
|
492 { |
|
493 kph = 65535 - 0.5; |
|
494 } |
|
495 |
|
496 TReal32 metersPerSec = kph / 3.6; |
|
497 SUPLLOG(ELogP1, "CSuplPos::ConvertHorSpeedToMetersPerSecond() End\n"); |
|
498 return metersPerSec; |
|
499 } |
|
500 |
|
501 /** |
|
502 ConvertHorSpeedAccuracyToMetersPerSecond() |
|
503 |
|
504 Converts received speed uncertainty value N to meters per second, according to |
|
505 3GPP GAD: |
|
506 |
|
507 Uncertainty is encoded in increments of 1 kilometer per hour using an 8bit |
|
508 encoded number N. N is therefore the uncertainty speed in kmph, except for |
|
509 N=255 which indicates that the uncertainty is not specified |
|
510 |
|
511 @param aSpeedAccuracy - the received, encoded uncertainty speed N. |
|
512 @return the uncertainty speed in meters per second. |
|
513 */ |
|
514 TReal32 CSuplPos::ConvertHorSpeedAccuracyToMetersPerSecond(TUint aSpeedAccuracy) |
|
515 { |
|
516 SUPLLOG(ELogP1, "CSuplPos::ConvertHorSpeedAccuracyToMetersPerSecond() Begin\n"); |
|
517 TReal32 metersPerSec = aSpeedAccuracy / 3.6; |
|
518 SUPLLOG(ELogP1, "CSuplPos::ConvertHorSpeedAccuracyToMetersPerSecond() End\n"); |
|
519 return metersPerSec; |
|
520 } |
|
521 |
|
522 /** |
|
523 Prints the content payload data structure to the logger |
|
524 */ |
|
525 void CSuplPos::LogPayload() |
|
526 { |
|
527 if (iPosPayload) |
|
528 { |
|
529 iPosPayload->LogMessageContent(); |
|
530 } |
|
531 } |
|
532 |