|
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 "ULP.h" |
|
23 #include "suplresponse.h" |
|
24 #include "supldevloggermacros.h" |
|
25 |
|
26 /** |
|
27 Static factory constructor |
|
28 */ |
|
29 EXPORT_C CSuplResponse* CSuplResponse::NewL() |
|
30 { |
|
31 SUPLLOG(ELogP1, "CSuplResponse::NewL() Begin\n"); |
|
32 CSuplResponse* self = new (ELeave) CSuplResponse(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 SUPLLOG(ELogP1, "CSuplResponse::NewL() End\n"); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 /** |
|
41 Constructor |
|
42 */ |
|
43 CSuplResponse::CSuplResponse() |
|
44 : CSuplMessageBase::CSuplMessageBase(ESuplResponse, EFalse) |
|
45 { |
|
46 } |
|
47 |
|
48 /** |
|
49 Second stage constructor |
|
50 */ |
|
51 void CSuplResponse::ConstructL() |
|
52 { |
|
53 // call the base class ConstructL() to create common data structures |
|
54 CSuplMessageBase::ConstructL(); |
|
55 } |
|
56 |
|
57 |
|
58 /** |
|
59 Destructor |
|
60 */ |
|
61 CSuplResponse::~CSuplResponse() |
|
62 { |
|
63 SUPLLOG(ELogP1, "CSuplResponse::~CSuplResponse() Begin\n"); |
|
64 SUPLLOG(ELogP1, "CSuplResponse::~CSuplResponse() End\n"); |
|
65 } |
|
66 |
|
67 |
|
68 /** |
|
69 GetPosMethod() |
|
70 |
|
71 The Positioning Method parameter of the SUPL RESPONSE message is the method |
|
72 that SHALL be used for the SUPL POS session. |
|
73 |
|
74 @param aMethod on return, populated according to Pos Method parameter |
|
75 @return error indication, KErrNone otherwise |
|
76 */ |
|
77 EXPORT_C TInt CSuplResponse::GetPosMethod(TLbsNetPosRequestMethod& aMethod) |
|
78 { |
|
79 SUPLLOG(ELogP1, "CSuplResponse::GetPosMethod() Begin\n"); |
|
80 __ASSERT_DEBUG(iData->message.u.msSUPLRESPONSE != NULL, User::Invariant()); |
|
81 |
|
82 // pointer to message body |
|
83 ASN1T_SUPLRESPONSE* msgBody = iData->message.u.msSUPLRESPONSE; |
|
84 |
|
85 TLbsNetPosMethod posMethods[2]; |
|
86 TInt numMethods = 1; |
|
87 |
|
88 switch (msgBody->posMethod) |
|
89 { |
|
90 case PosMethod::agpsSETassisted: |
|
91 posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted); |
|
92 break; |
|
93 |
|
94 case PosMethod::agpsSETbased: |
|
95 posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted); |
|
96 break; |
|
97 |
|
98 case PosMethod::agpsSETassistedpref: |
|
99 posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted); |
|
100 posMethods[1].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted); |
|
101 ++numMethods; |
|
102 break; |
|
103 |
|
104 case PosMethod::PosMethod::agpsSETbasedpref: |
|
105 posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted); |
|
106 posMethods[1].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted); |
|
107 ++numMethods; |
|
108 break; |
|
109 |
|
110 case PosMethod::autonomousGPS: |
|
111 posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal); |
|
112 break; |
|
113 |
|
114 case PosMethod::aFLT: |
|
115 posMethods[0].SetPosMethod(KLbsPositioningMeansAflt, TPositionModuleInfo::ETechnologyTerminal); |
|
116 break; |
|
117 |
|
118 case PosMethod::eCID: |
|
119 posMethods[0].SetPosMethod(KLbsPositioningMeansCell, TPositionModuleInfo::ETechnologyTerminal); |
|
120 break; |
|
121 |
|
122 case PosMethod::PosMethod::eOTD: |
|
123 posMethods[0].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyTerminal); |
|
124 break; |
|
125 |
|
126 case PosMethod::oTDOA: |
|
127 posMethods[0].SetPosMethod(KLbsPositioningMeansOtdoa, TPositionModuleInfo::ETechnologyTerminal); |
|
128 break; |
|
129 |
|
130 case PosMethod::noPosition: |
|
131 posMethods[0].SetPosMethod(KLbsPositioningMeansNone, TPositionModuleInfo::ETechnologyTerminal); |
|
132 break; |
|
133 |
|
134 default: |
|
135 // error |
|
136 __ASSERT_DEBUG(EFalse, User::Invariant()); |
|
137 return KErrArgument; |
|
138 } |
|
139 |
|
140 // populate the return parameter |
|
141 TInt err = aMethod.SetPosMethods(posMethods, numMethods); |
|
142 |
|
143 SUPLLOG(ELogP1, "CSuplResponse::GetPosMethod() End\n"); |
|
144 return err; |
|
145 } |
|
146 |
|
147 |
|
148 /** |
|
149 SlpAddressPresent() |
|
150 |
|
151 The SLP Address is conditionally present - it is required if the SUPL Session |
|
152 is operating in non-Proxy mode, otherwise it is not required. |
|
153 |
|
154 @return ETrue if the SlpAddress parameter is present |
|
155 */ |
|
156 EXPORT_C TBool CSuplResponse::SlpAddressPresent() |
|
157 { |
|
158 SUPLLOG(ELogP1, "CSuplResponse::SlpAddressPresent() Begin\n"); |
|
159 __ASSERT_DEBUG(iData->message.u.msSUPLRESPONSE != NULL, User::Invariant()); |
|
160 |
|
161 if (iData->message.u.msSUPLRESPONSE->m.sLPAddressPresent == 0) |
|
162 { |
|
163 SUPLLOG(ELogP1, "CSuplResponse::SlpAddressPresent(EFalse) End\n"); |
|
164 return EFalse; |
|
165 } |
|
166 |
|
167 SUPLLOG(ELogP1, "CSuplResponse::SlpAddressPresent(ETrue) End\n"); |
|
168 return ETrue; |
|
169 } |
|
170 |
|
171 |
|
172 /** |
|
173 SlpAddress() |
|
174 |
|
175 @param aAddress, populated according to the SLP address parameter |
|
176 @return error indication, KErrNone otherwise |
|
177 */ |
|
178 EXPORT_C TInt CSuplResponse::GetSlpAddress(CSuplSlpAddress& aAddress) |
|
179 { |
|
180 SUPLLOG(ELogP1, "CSuplResponse::SlpAddress() Begin\n"); |
|
181 __ASSERT_DEBUG(iData->message.u.msSUPLRESPONSE != NULL, User::Invariant()); |
|
182 __ASSERT_DEBUG(iData->message.u.msSUPLRESPONSE->m.sLPAddressPresent != 0, User::Invariant()); |
|
183 |
|
184 // pointer to message body |
|
185 ASN1T_SUPLRESPONSE* msgBody = iData->message.u.msSUPLRESPONSE; |
|
186 |
|
187 if (msgBody->m.sLPAddressPresent == 0) |
|
188 { |
|
189 SUPLLOG(ELogP1, "CSuplResponse::SlpAddress() End (SLP Address element not present)\n"); |
|
190 return KErrNotFound; |
|
191 } |
|
192 |
|
193 if (msgBody->sLPAddress.t == T_SLPAddress_fQDN) |
|
194 { |
|
195 // FQDN is a NULL terminated string, length 1..255 |
|
196 aAddress.iSlpAddressType = ESuplSlpAddressTypeFqdn; |
|
197 |
|
198 // find the length of the FQDN (NULL terminated) |
|
199 const TUint8* tmp = (const TUint8*)msgBody->sLPAddress.u.fQDN; |
|
200 TPtrC8 source = TPtrC8(tmp, 256); |
|
201 _LIT8(KNull,"\0"); |
|
202 TInt fqdnLength = source.Find(KNull); |
|
203 source.Set(tmp, fqdnLength); |
|
204 |
|
205 // copy to the container |
|
206 TBuf8<256>& fqdn = aAddress.iFqdn->iFqdn; |
|
207 fqdn.Copy(source); |
|
208 fqdn.SetLength(fqdnLength); |
|
209 } |
|
210 |
|
211 else if (msgBody->sLPAddress.t == T_SLPAddress_iPAddress) |
|
212 { |
|
213 // SLP ID is an IP Address |
|
214 aAddress.iSlpAddressType = ESuplSlpAddressTypeIp; |
|
215 |
|
216 // Reference to the address data buffer |
|
217 TBuf8<16>& ipAddress = aAddress.iIpAddress->iIpAddress; |
|
218 |
|
219 // IPv4 or IPv6 address? |
|
220 if (msgBody->sLPAddress.u.iPAddress->t == T_IPAddress_ipv6Address) |
|
221 { |
|
222 aAddress.iIpAddress->iIpAddressType = ESuplIpAddressTypeV6; |
|
223 TInt len = msgBody->sLPAddress.u.iPAddress->u.ipv6Address->numocts; |
|
224 TUint8* data = msgBody->sLPAddress.u.iPAddress->u.ipv6Address->data; |
|
225 ipAddress.Copy(data, len); |
|
226 } |
|
227 else |
|
228 { |
|
229 aAddress.iIpAddress->iIpAddressType = ESuplIpAddressTypeV4; |
|
230 TInt len = msgBody->sLPAddress.u.iPAddress->u.ipv4Address->numocts; |
|
231 TUint8* data = msgBody->sLPAddress.u.iPAddress->u.ipv4Address->data; |
|
232 ipAddress.Copy(data, len); |
|
233 } |
|
234 } |
|
235 else |
|
236 { |
|
237 // error |
|
238 __ASSERT_DEBUG(0, User::Invariant()); |
|
239 return KErrArgument; |
|
240 } |
|
241 |
|
242 SUPLLOG(ELogP1, "CSuplResponse::SlpAddress() End\n"); |
|
243 return KErrNone; |
|
244 } |
|
245 |