Code sync from tizen_2.4
[platform/core/telephony/tel-plugin-imc.git] / src / imc_gps.c
1 /*
2  * tel-plugin-imc
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: sharanayya mathapati <sharan.m@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <fcntl.h>
28 #include <glib.h>
29
30 #include <tcore.h>
31 #include <hal.h>
32 #include <core_object.h>
33 #include <plugin.h>
34 #include <queue.h>
35 #include <co_gps.h>
36 #include <user_request.h>
37 #include <util.h>
38 #include <server.h>
39 #include <at.h>
40 #include <libxml/xmlreader.h>
41 #include <libxml/parser.h>
42 #include <libxml/tree.h>
43
44 #include "imc_common.h"
45 #include "imc_gps.h"
46
47
48 #define FILE_NAME   "/opt/home/root/sample.xml"
49 #define POSITION_NODE   "pos"
50 #define POSITION_NODE_ATTR_XSI  "xsi:noNamespaceSchemaLocation"
51 #define POSITION_NODE_ATTR_VAL_XSI  "pos.xsd"
52 #define POSITION_NODE_ATTR_XMLNS    "xmlns:xsi"
53 #define POSITION_NODE_ATTR_VAL_XMLNS    "http://www.w3.org/2001/XMLSchema-instance"
54
55 #define MAX_NUM_OF_GPS_REF_TIME_ELEMENT 12 /* max number of gps satalite */
56 #define MAX_NUM_OF_GPS_NAV_ELEMENT  16 /* max num of navigation gps element. */
57 #define MAX_NUM_OF_GPS_ALMANC_ELEMENTS  64 /* Max num of almanc elements. */
58
59 #define NUM_OF_ELEMENTS(array)  (sizeof(array) / sizeof(*(array)))
60
61 #define NODE_SIZE 128
62
63 static char node_name[128]; /* max len of xml node */
64 static char node_value[128]; /* max len of xml node value. */
65
66 /* node type of gps assist data */
67 enum gps_assist_element_type {
68         REF_TIME = 1,
69         LOCATION_PARM,
70         DGPS_CORRECTION,
71         NAV_MODEL_ELEM,
72         IONOSPHERIC_MODEL,
73         UTC_MODEL,
74         ALMANAC,
75         ACQU_ASSIST,
76 };
77
78 /* Ref_time */
79         typedef struct {
80         unsigned char valid;
81         unsigned short bcchCarrier;
82         unsigned short bsic;
83         unsigned long int frameNumber;
84         unsigned short timeSlot;
85         unsigned short bitNumber;
86 } __attribute__((packed)) gps_gsm_time_t;
87
88 typedef struct {
89         unsigned char valid;
90         unsigned long int gpsTimeUncertainty;
91 } __attribute__((packed)) gps_utran_gps_unc_t;
92
93 typedef struct {
94         unsigned char valid;
95         signed long int driftRate;
96 } __attribute__((packed)) gps_drift_rate_t;
97
98 typedef struct {
99         unsigned char valid;
100         unsigned long int cellFrames;
101         unsigned char choice_mode;
102         unsigned long int UtranFdd; /* FDD Primary Scrambling Code */
103         unsigned long int UtranTdd; /* TDD Cell Parameter ID */
104         unsigned long int sfn; /* SFN */
105 } __attribute__((packed)) gps_utran_gps_ref_time_t;
106
107 typedef struct {
108         gps_utran_gps_ref_time_t UtranGpsRefTime;
109         gps_utran_gps_unc_t UtranGpsUncertainty;
110         unsigned char UtranSfnUncertainty;
111         gps_drift_rate_t UtranDriftRate;
112 } __attribute__((packed)) gps_utran_time_t;
113
114 typedef struct {
115         unsigned short satID;
116         unsigned short tlmWord;
117         unsigned char antiSpoofFlag;
118         unsigned char alertFlag;
119         unsigned char tmlReservedBits;
120 } __attribute__((packed)) gps_gps_tow_assist_t;
121
122 typedef struct {
123         unsigned long int gpsTow;
124         unsigned long int gpsWeek;
125         unsigned char nrOfSats;
126         union {                     /* Not supported. */
127                 gps_gsm_time_t gsm_time;
128                 gps_utran_time_t UtranTime;
129         } networkTimeInfo;
130         gps_gps_tow_assist_t GpsTowAssist[12];
131 } __attribute__((packed)) gps_ref_time_t;
132
133
134 /* Ref - Location. */
135 typedef struct {
136         unsigned char shapeType;
137         unsigned char hemisphere;
138         unsigned short altitude;
139         unsigned long int latitude;
140         signed long int longitude;
141         unsigned char directionOfAlt;
142         unsigned char semiMajorUncert;
143         unsigned char semiMinorUncert;
144         unsigned char majorAxis;
145         unsigned char altUncert;
146         unsigned char confidence;
147 } __attribute__((packed)) gps_ref_loc_t;
148
149 /* DGPS corrections */
150 typedef enum {
151         GPS_DGPS_INVALID,
152         GPS_DGPS_UDRE_SCALE_1_0,
153         GPS_DGPS_UDRE_SCALE_0_75,
154         GPS_DGPS_UDRE_SCALE_0_5,
155         GPS_DGPS_UDRE_SCALE_0_3,
156         GPS_DGPS_UDRE_SCALE_0_2,
157         GPS_DGPS_UDRE_SCALE_0_1,
158         GPS_DGPS_NO_DATA
159 } __attribute__((packed)) gps_dgps_status_e_type;
160
161 typedef struct {
162         unsigned char satId; /* Satellite ID */
163         unsigned short iode;
164         unsigned char udre;
165         signed short pseudoRangeCor;
166         signed short rangeRateCor;
167 } gps_dgps_sat_list_t;
168
169 typedef struct {
170         unsigned long int gpsTow;
171         gps_dgps_status_e_type status;
172         unsigned long int numberOfSat;
173         gps_dgps_sat_list_t seqOfSatElement[16];
174 } __attribute__((packed)) gps_dgps_correction_t;
175
176 /* Navi model */
177 typedef struct {
178         unsigned long int rsv1; /* 0~838860 */
179         unsigned long int rsv2; /* 0~16777215 */
180         unsigned long int rsv3; /* 0~16777215 */
181         unsigned long int rsv4; /* 0~65535 */
182 } __attribute__((packed)) gps_navi_subframe_rsv_t;
183
184 typedef struct {
185         unsigned char ephemCodeOnL2;                   /* 0~3 */
186         unsigned char ephemUra;                   /* 0~15 */
187         unsigned char ephemSvHealth;                   /* 0~63 */
188         unsigned short ephemIodc;              /* 0~1023 */
189         unsigned char ephemL2PFlag;                   /* 0~1 */
190         gps_navi_subframe_rsv_t NavigationSubFrameRsv;
191         signed char ephemTgd;                 /* -128~127 */
192         unsigned short ephemToc;              /* 0~37799 */
193         signed char ephemAf2;                 /* -128~12 */
194         signed short ephemAf1;                    /* -32768~32767 */
195         signed long int ephemAf0;                 /* -2097152~2097151 */
196         signed short ephemCrs;                    /* -32768~32767 */
197         signed short ephemDeltaN;                    /* -32768~32767 */
198         signed long int ephemM0;                 /* -2147483648~2147483647 */
199         signed short ephemCuc;                    /* -32768~32767 */
200         unsigned long int ephemE;               /* 0~4294967295 */
201         signed short ephemCus;                    /* -32768~32767 */
202         unsigned long int ephemAPowrHalf;               /* 0~4294967295 */
203         unsigned short ephemToe;              /* 0~37799 */
204         signed char ephemFitFlag;                 /* 0~1 */
205         unsigned char ephemAoda;                   /* 0~31 */
206         signed short ephemCic;                    /* -32768~32767 */
207         signed long int ephemOmegaA0;                 /* -2147483648~2147483647 */
208         signed short ephemCis;                    /* -32768~32767 */
209         signed long int ephemI0;                 /* -2147483648~2147483647 */
210         signed short ephemCrc;                    /* -32768~32767 */
211         signed long int ephemW;                 /* -2147483648~2147483647 */
212         signed long int ephemOmegaADot;                 /* -8388608~8388607 */
213         signed short ephemIDot;                    /* -8192~8191 */
214 } __attribute__((packed)) gps_navi_ephe_t;
215
216 typedef enum {
217         GPS_NAVIGATION_MODEL_NEW_SATELLITE_NEW_NAVIGATION,
218         GPS_NAVIGATION_MODEL_EXIST_SATELLITE_EXIST_NAVIGATION,
219         GPS_NAVIGATION_MODEL_EXIST_SATELLITE_NEW_NAVIGATION,
220         GPS_NAVIGATION_MODEL_RESERVED
221 } gps_navigation_sat_status_e_type;
222
223 typedef struct {
224         unsigned char satId;
225         gps_navigation_sat_status_e_type NavigationSatStatus;
226         gps_navi_ephe_t NavigationEphemeris;
227 } __attribute__((packed)) gps_navi_sat_info_t;
228
229 typedef struct {
230         unsigned long int numberOfSat;
231         gps_navi_sat_info_t NavigationSatInfo[16];
232 } __attribute__((packed)) gps_navi_model_t;
233
234 /* Iono_model */
235 typedef struct {
236         signed char alfa0; /* -128~127 */
237         signed char alfa1; /* -128~127 */
238         signed char alfa2; /* -128~127 */
239         signed char alfa3; /* -128~127 */
240         signed char beta0; /* -128~127 */
241         signed char beta1; /* -128~127 */
242         signed char beta2; /* -128~127 */
243         signed char beta3; /* -128~127 */
244 } __attribute__((packed)) gps_iono_model_t;
245
246 /* UTC_model */
247 typedef struct {
248         signed long int utcA1; /* -8388608~8388607 */
249         signed long int utcA0; /* -2147483648~2147483647 */
250         unsigned char utcTot; /* 0~255 */
251         unsigned char utcWNt; /* 0~255 */
252         signed char utcDeltaTls; /* -128~127 */
253         unsigned char utcWNlsf; /* 0~255 */
254         signed char utcDN; /* -128~127 */
255         signed char utcDeltaTlsf; /* -128~127 */
256 } __attribute__((packed)) gps_utc_model_t;
257
258 /* Almanac-model */
259 typedef struct {
260         signed char dataId; /* only for 3G, 0~3, if this value is -1, it means this value is invalid */
261         unsigned char satId;
262         unsigned short almanacE; /* 0~65536 */
263         unsigned char almanacToa;   /* 0~255 */
264         signed short almanacKsii;    /* -32768~3276 */
265         signed short almanacOmegaDot;    /* -32768~3276 */
266         unsigned char almanacSvHealth;   /* 0~255 */
267         unsigned long int almanacAPowerHalf; /* 0~16777215 */
268         signed long int almanacOmega0; /* -8388608~8388607 */
269         signed long int almanacW; /* -8388608~8388607 */
270         signed long int almanacM0; /* -8388608~8388607 */
271         signed short almanacAf0;    /* -1024~1023 */
272         signed short almanacAf1;    /* -1024~1023 */
273 } __attribute__((packed)) gps_almanac_sat_info_t;
274
275 typedef struct {
276         unsigned char almanacWNa; /* 0~255 */
277         unsigned long int numberOfSat;
278         gps_almanac_sat_info_t AlmanacSatInfo[64];
279 } __attribute__((packed)) gps_almanac_model_t;
280
281 /* acq_assist */
282 typedef struct {
283         unsigned char satId;
284         signed short doppler0; /* -2048~2047 (real value is from -5120 to 5117.5 by step of 2.5) */
285         unsigned char doppler1; /* 0~63 (real value is from -0.966 to 0.483 by step of 0.023) */
286         unsigned char dopplerUncertainty; /* 0~7 (12.5, 25, 50, 100, 200) */
287         unsigned short codePhase; /* 0~1022 */
288         unsigned char intCodePhase; /* 0~19 */
289         unsigned char gpsBitNumber; /* 0~3 */
290         unsigned char codePhaseSearchWindow; /* 0~15 (1023, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192) */
291         unsigned char azimuth; /* 0~31, 11.25 degree resolution */
292         unsigned char elevation; /* 0~7, 11.25 degree resolution */
293 } __attribute__((packed)) gps_acq_sat_info_t;
294
295 typedef struct {
296         gps_utran_gps_ref_time_t AcqUtranGpsRefTime;
297         gps_utran_gps_unc_t AcqUtranGpsUncertainty;
298 } __attribute__((packed)) gps_acq_utran_time_t;
299
300 typedef struct {
301         unsigned long int gpsTow;
302         union   {
303                 gps_gsm_time_t gsm_time;
304                 gps_acq_utran_time_t AcqUtranTime;
305         } acquisitionTimeInfo;                      /* --- not supported. */
306         unsigned long int numberOfSat;
307         gps_acq_sat_info_t lcsAcquisitionSatInfo[16];
308 } __attribute__((packed)) gps_acq_assist_t;
309
310 typedef struct {
311         unsigned char satId[16];
312         unsigned char numOfSat;
313 } __attribute__((packed)) gps_r_time_int_t;
314
315
316 /* Assist-data */
317 typedef struct {
318         unsigned long int flag;
319         gps_ref_time_t ref_time;
320         gps_ref_loc_t ref_loc;
321         gps_dgps_correction_t dgps_corrections;
322         gps_navi_model_t navi_model;
323         gps_iono_model_t iono_model;
324         gps_utc_model_t utc_model;
325         gps_almanac_model_t almanac;
326         gps_acq_assist_t acq_assist;
327         gps_r_time_int_t r_time_int; /* not supported */
328 } __attribute__((packed)) gps_assist_data_noti_t; /* APGPS -  GPS Assist Data Message - Notification */
329
330 typedef struct {
331         char *psat_status;
332         int stat_status;
333 } __attribute__((packed)) sat_status_info_t;
334
335 const sat_status_info_t sat_status_info_table[] = {
336         { "NS_NN-U", 0}, {"NS_NN", 0}, {"ES_NN-U", 1}, {"ES_SN", 2},
337         { "REVD", 3},
338 };
339
340 typedef struct {
341         char *pdoppler_status;
342         int doppler_status;
343 } __attribute__((packed)) doppler_status_info_t;
344
345 const doppler_status_info_t doppler_status_info_table[] = {
346         { "hz12-5", 12.5}, {"hz25", 25}, {"hz50", 50}, {"hz100", 100},
347         {"hz200", 200},
348 };
349
350 /* postion measurement data structure. */
351 /* gps_method_e_type */
352 typedef enum {
353         GPS_METHODTYPE_INVALID,
354         GPS_METHODTYPE_MS_ASSISTED,
355         GPS_METHODTYPE_MS_BASED,
356         GPS_METHODTYPE_MS_BASED_PREF,
357         GPS_METHODTYPE_MS_ASSISTED_PREF
358 } gps_method_e_type;
359
360 /* gps_accuracy_t */
361 typedef struct {
362         unsigned int flag;
363         unsigned char horizontalAccuracy;
364         unsigned char vertcalAccuracy;
365 } __attribute__((packed)) gps_accuracy_t;
366
367 /* gps_use_multi_sets_e_type */
368 typedef enum {
369         GPS_MULTIPLESETS_INVALID,
370         GPS_MULTIPLESETS_MULTIPLESETS,
371         GPS_MULTIPLESETS_ONESET
372 } gps_use_multi_sets_e_type;
373
374 /* gps_env_char_e_type */
375 typedef enum {
376         GPS_ENVIRONMENT_INVALID,
377         GPS_ENVIRONMENT_BAD_AREA,
378         GPS_ENVIRONMENT_NOT_BAD_AREA,
379         GPS_ENVIRONMENT_MIXED_AREA
380 } gps_env_char_e_type;
381
382 /* gps_cell_timing_wnt_e_type */
383 typedef enum {
384         GPS_CELLTIMING_INVALID,
385         GPS_CELLTIMING_WANTED,
386         GPS_CELLTIMING_NOT_WANTED
387 } gps_cell_timing_wnt_e_type;
388
389 /* gps_add_assit_req_e_type */
390 typedef enum {
391         GPS_ADDITIONAL_ASSISREQ_INVALID,
392         GPS_ADDITIONAL_ASSISREQ_REQ,
393         GPS_ADDITIONAL_ASSISREQ_NOT_REQ
394 } gps_add_assit_req_e_type;
395
396 /* gps measure position. */
397 typedef struct {
398         gps_method_e_type method_type;
399         gps_accuracy_t accuracy;
400         unsigned char rsp_time;
401         gps_use_multi_sets_e_type use_multi_sets;
402         gps_env_char_e_type environment_char;
403         gps_cell_timing_wnt_e_type cell_timing_wnt;
404         gps_add_assit_req_e_type add_assist_req;
405 } __attribute__((packed)) gps_measure_position_indi_t;
406
407
408 /* APGPS - Measure Position message - confirm */
409 typedef enum {
410         GPS_MSR_POS_RES_LOCATION,
411         GPS_MSR_POS_RES_GPS_MEASUREMENTS,
412         GPS_MSR_POS_RES_AID_REQ,
413         GPS_MSR_POS_RES_ERROR
414 } gps_msr_pos_res_e_type;
415
416 typedef struct {
417         unsigned char sat_id;
418         unsigned char iode;
419 } __attribute__((packed)) gps_sat_info_t;
420
421 typedef struct {
422         unsigned char beginWeek;
423         unsigned char endWeek;
424         unsigned char beginTow;
425         unsigned char endTow;
426 } __attribute__((packed)) gps_ext_ephe_chk_t;
427
428 typedef struct {
429         unsigned long int assistanceFlag;
430         unsigned short gpsWeek;
431         unsigned char gpsToe;
432         unsigned char nSat;
433         unsigned char toeLimit;
434         gps_sat_info_t satInfo[15];
435         unsigned char gpsExtendedEphemeris;
436         gps_ext_ephe_chk_t extEphemerisChk;
437 } __attribute__((packed)) gps_assistance_data_t;
438
439 /* Measure Position message */
440 typedef struct {
441         unsigned char satId; /* Satellite ID */
442         unsigned char cno; /* 0~63, unit of dB-Hz */
443         signed short doppler; /* -32768~32767, Hz and scale factor 0.2 */
444         unsigned short wholeChips; /* 0~1022 */
445         unsigned short fracChips; /* 0~1024 */
446         unsigned char lcsMultiPath;
447         unsigned char pseuRangeRmsErr; /* 0~63 */
448 } __attribute__((packed)) gps_measuremet_element_t;
449
450 typedef struct {
451         unsigned long int gpsTow; /* /< GPS time of week [msec] */
452         unsigned short gpsWeek; /* /< GPS week [0 .. 1023] */
453         unsigned char nrOfSats; /* /< number of satellites [1 .. 16] */
454         gps_measuremet_element_t GpsMeasure[16];
455 } __attribute__((packed)) gps_measure_t;
456
457 typedef struct {
458         signed long int latitude;
459         signed long int longitude;
460 } __attribute__((packed)) gps_ellipsoid_po_t;
461
462 typedef struct {
463         gps_ellipsoid_po_t point;
464         unsigned char uncertainRadius;
465 } __attribute__((packed)) gps_po_unc_circle_t;
466
467 typedef struct {
468         gps_ellipsoid_po_t point;
469         unsigned char semiMajorAxis;
470         unsigned char semiMinorAxis;
471         unsigned char orientationAngle;
472         unsigned char confidence;
473 } __attribute__((packed)) gps_po_unc_ellipse_t;
474
475 typedef struct {
476         gps_ellipsoid_po_t point;
477         signed short altitude;
478         unsigned char semiMajorAxis;
479         unsigned char semiMinorAxis;
480         unsigned char orientationAngle;
481         unsigned char uncertainAltitude;
482         unsigned char confidence;
483 } __attribute__((packed)) gps_po_alt_unc_ellipse_t;
484
485 typedef struct {
486         gps_ellipsoid_po_t point;
487         unsigned short innerRadius;
488         unsigned char uncertainRadius;
489         unsigned char offsetAngle;
490         unsigned char includedAngle;
491         unsigned char confidence;
492 } __attribute__((packed)) gps_ellipsoid_arc_t;
493
494 typedef struct {
495         gps_ellipsoid_po_t point;
496         signed short altitude;
497 } __attribute__((packed)) gps_ellipsoid_alt_t;
498
499 typedef struct {
500         unsigned char noOfPoints;
501         gps_ellipsoid_po_t points[15];
502 } __attribute__((packed)) gps_polygon_t;
503
504
505 typedef struct {
506         unsigned char shape_type;
507         gps_po_unc_circle_t p_unc_clrcle;
508         gps_po_unc_ellipse_t p_unc_ellipse;
509         gps_po_alt_unc_ellipse_t p_alt_unc_ellipse;
510         gps_ellipsoid_arc_t ellipsoid_arc;
511         gps_ellipsoid_po_t ellipsoid_po;
512         gps_ellipsoid_alt_t ellipsoid_alt;
513         gps_polygon_t polygon;
514 } __attribute__((packed)) gps_loc_info_t;
515
516
517 typedef struct {
518         unsigned long int gpsTow; /* /< GPS time of week [msec] */
519         unsigned short gpsWeek; /* /< GPS week [0 .. 1023] */
520         unsigned char fixType; /* /< Fix type. 2D(0x01) or 3D(0x02) */
521         gps_loc_info_t measured_loc_info;
522 } __attribute__((packed)) gps_measure_loc_info_t;
523
524 typedef struct {
525         unsigned char valid;
526         unsigned long int cellFrames;
527         unsigned char choice_mode;
528         unsigned long int UtranFdd; /* FDD Primary Scrambling Code */
529         unsigned long int UtranTdd; /* TDD Cell Parameter ID */
530         unsigned long int sfn; /* SFN */
531 } __attribute__((packed)) gps_utrangps_ref_time_t;
532
533 typedef struct {
534         unsigned char result; /* 0x00 : SUCCESS, 0x01 : Fail */
535         gps_msr_pos_res_e_type response_type; /* should be 4 byte */
536         gps_measure_t gps_measure;
537         gps_measure_loc_info_t loc_info;
538         gps_assistance_data_t measured_assit_data;
539         gps_utrangps_ref_time_t UtranGpsRefTime; /* only for 3G */
540 } __attribute__((packed)) gps_measure_position_confirm_t; /* APGPS - Measure Position message - confirm */
541
542 typedef struct {
543         char *name;
544         int type;
545 } t_element;
546
547 static t_element elements[] = {
548         {"ref_time", REF_TIME},
549         {"location_parameters", LOCATION_PARM},
550         {"DGPS_corrections", DGPS_CORRECTION},
551         {"nav_model_elem", NAV_MODEL_ELEM},
552         {"ionospheric_model", IONOSPHERIC_MODEL},
553         {"UTC_model", UTC_MODEL},
554         {"almanac", ALMANAC},
555         {"acqu_assist", ACQU_ASSIST},
556 };
557
558
559 /**************************************************************************
560 *               Local Function Prototypes
561 **************************************************************************/
562
563 static inline int _modem_sat_status_info_2_tel_sat_info(char *sat_info);
564
565 static inline int _modem_acqa_assit_doppler_2_tel_doppler(char *doppler_info);
566
567 static int _gps_element_compare(char *element[], char *element_str, int nelem);
568
569 static enum gps_assist_element_type _get_element_type(char *element_str);
570
571 static void _parse_ref_time_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean GPS_TOW_assist, int count);
572
573 static void _parse_location_parameters(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
574
575 static void _parse_dgps_correction_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
576
577 static void _parse_ionospheric_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
578
579 static void _parse_utc_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
580
581 static void _parse_almanc_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean alm_elem, int count);
582
583 static void _parse_acqu_assist_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist);
584
585 static void _parse_nav_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean ephem_and_clock, int element_count);
586
587 static void _set_coordinate(xmlNodePtr node, gps_ellipsoid_po_t *point, int isalt, int altitude);
588
589 static void _set_loc_info_ellipse_elements(xmlNodePtr node, void *elliplse, int is_unc_ellipse);
590
591 static xmlChar *_generate_confirm_measure_pos_xml_text(gps_measure_position_confirm_t *gps_measure_position_confirm);
592
593 static gboolean on_notification_gps_measure_position_from_modem(CoreObject *o, char *file_name, void *user_data);
594
595 /**************************************************************************
596 *               Local Function Definitions
597  **************************************************************************/
598
599 static inline int _modem_sat_status_info_2_tel_sat_info(char *sat_info)
600 {
601         int count;
602
603         for (count = 0; count < (int) (sizeof(sat_status_info_table) / sizeof(sat_status_info_t)); count++)
604                 if (strcmp(sat_status_info_table[count].psat_status, sat_info) == 0)
605                         return (sat_status_info_table[count].stat_status);
606
607         return (-1);
608 }
609
610 static inline int _modem_acqa_assit_doppler_2_tel_doppler(char *doppler_info)
611 {
612         int count;
613
614         for (count = 0; count < (int) (sizeof(doppler_status_info_table) / sizeof(doppler_status_info_t)); count++)
615                 if (strcmp(doppler_status_info_table[count].pdoppler_status, doppler_info) == 0)
616                         return (doppler_status_info_table[count].doppler_status);
617
618         return (-1);
619 }
620
621 static int _gps_element_compare(char *element[], char *element_str, int nelem)
622 {
623         int count;
624
625         for (count = 0; count < nelem; count++)
626                 if (strcmp(element[count], element_str) == 0)
627                         return count;
628
629         return -1;
630 }
631
632
633 static enum gps_assist_element_type _get_element_type(char *element_str)
634 {
635         unsigned int index;
636
637         for (index = 0; index < sizeof(elements) / sizeof(t_element); index++)
638                 if (strcmp(elements[index].name, element_str) == 0)
639                         return elements[index].type;
640
641         return -1;
642 }
643
644 static void _parse_ref_time_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist, gboolean GPS_TOW_assist, int count)
645 {
646         int node_count;
647         int nelem;
648         static char *element[] = {"GPS_TOW_msec", "GPS_week", "sat_id", "tlm_word", "anti_sp", "alert", "tlm_res"};
649
650         dbg("Enter");
651         if (count < 0 || count >= MAX_NUM_OF_GPS_REF_TIME_ELEMENT) {
652                 dbg("invalid count");
653                 return;
654         }
655         nelem = (int) NUM_OF_ELEMENTS(element);
656         node_count = _gps_element_compare(element, element_str, nelem);
657
658         if (node_count == 0) {
659                 gpsdata_assist->ref_time.gpsTow = atoi(element_value);
660                 dbg("gpsTow - %d\n", gpsdata_assist->ref_time.gpsTow);
661                 gpsdata_assist->dgps_corrections.gpsTow = gpsdata_assist->ref_time.gpsTow;
662                 return;
663         } else if (node_count == 1) {
664                 gpsdata_assist->ref_time.gpsWeek = atoi(element_value);
665                 dbg("gpsWeek - %d\n", gpsdata_assist->ref_time.gpsWeek);
666                 return;
667         }
668
669         if (GPS_TOW_assist) {
670                 switch (node_count) {
671                 case 2:
672                         gpsdata_assist->ref_time.GpsTowAssist[count].satID = atoi(element_value);
673                         dbg("GpsTowAssist[%d].satID  = %d\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].satID);
674                         gpsdata_assist->ref_time.nrOfSats = count + 1;
675                 break;
676
677                 case 3:
678                         gpsdata_assist->ref_time.GpsTowAssist[count].tlmWord = atoi(element_value);
679                         dbg("GpsTowAssist[%d]-tlmWord  = %d\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].tlmWord);
680                         gpsdata_assist->ref_time.nrOfSats = count + 1;
681                 break;
682
683                 case 4:
684                         gpsdata_assist->ref_time.GpsTowAssist[count].antiSpoofFlag = *element_value;
685                         dbg("GpsTowAssist[%d]-antiSpoofFlag  = 0x%X\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].antiSpoofFlag);
686                         gpsdata_assist->ref_time.nrOfSats = count + 1;
687                 break;
688
689                 case 5:
690                         gpsdata_assist->ref_time.GpsTowAssist[count].alertFlag = *element_value;
691                         dbg("GpsTowAssist[%d]-alertFlag  = 0x%X\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].alertFlag);
692                         gpsdata_assist->ref_time.nrOfSats = count + 1;
693                 break;
694
695                 case 6:
696                         gpsdata_assist->ref_time.GpsTowAssist[count].tmlReservedBits = *element_value;
697                         dbg("GpsTowAssist[%d]-tmlReservedBits  = 0x%X\n", count, gpsdata_assist->ref_time.GpsTowAssist[count].tmlReservedBits);
698                         gpsdata_assist->ref_time.nrOfSats = count + 1;
699                 break;
700
701                 default:
702                         dbg("Invalid  gps element");
703                 break;
704                 }
705         }
706 }
707
708 static void _parse_location_parameters(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
709 {
710         /* unsigned char shapeType;  and unsigned char hemisphere not supported. */
711
712         static char *element[] = {
713                 "north", "degrees", "height_above_surface", "height", "longitude", "uncert_semi_major", "uncert_semi_minor",
714                 "orient_major", "confidence", "uncert_alt"
715         };
716
717         int nelem = (int) NUM_OF_ELEMENTS(element);
718         int count;
719
720         count = _gps_element_compare(element, element_str, nelem);
721
722         dbg("Enter");
723
724         switch (count) {
725         case 0:
726                 /* gpsdata_assist.ref_loc.latitude_data.north = atoi(element_str_text); */
727                 /* dbg("gpsdata_assist.ref_loc.latitude_data.north  - %d\n",gpsdata_assist.ref_loc.latitude_data.north); */
728         break;
729
730         case 1:
731                 gpsdata_assist->ref_loc.latitude = atoi(element_value);
732                 dbg("latitude_data.degrees - %d\n", gpsdata_assist->ref_loc.latitude);
733         break;
734
735         case 2:
736                 /* gpsdata_assist.ref_loc.altitude_data.height_above_surface = atoi(element_str_text); */
737                 /* dbg("altitude_data.height_above_surface  - %d\n",gpsdata_assist.ref_loc.altitude_data.height_above_surface); */
738         break;
739
740         case 3:
741                 gpsdata_assist->ref_loc.altitude = atoi(element_value);      /* todo- need to confirm */
742                 dbg("altitude_data.height - %d\n", gpsdata_assist->ref_loc.altitude);
743         break;
744
745         case 4:
746                 gpsdata_assist->ref_loc.longitude = atoi(element_value);
747                 dbg("longitude  - %d\n", gpsdata_assist->ref_loc.longitude);
748         break;
749
750         case 5:
751                 gpsdata_assist->ref_loc.semiMajorUncert = *element_value;
752                 dbg("semiMajorUncert  - 0x%X\n", gpsdata_assist->ref_loc.semiMajorUncert);
753         break;
754
755         case 6:
756                 gpsdata_assist->ref_loc.semiMinorUncert = *element_value;
757                 dbg("uncert_semi_minor - 0x%X\n", gpsdata_assist->ref_loc.semiMinorUncert);
758         break;
759
760         case 7:
761                 gpsdata_assist->ref_loc.majorAxis = *element_value;
762                 dbg("orient_major - 0x%X\n", gpsdata_assist->ref_loc.majorAxis);
763         break;
764
765         case 8:
766                 gpsdata_assist->ref_loc.confidence = *element_value;
767                 dbg("confidence - 0x%X\n", gpsdata_assist->ref_loc.confidence);
768         break;
769
770         case 9:
771                 gpsdata_assist->ref_loc.altUncert = *element_value;
772                 dbg("altUncert - 0x%X\n", gpsdata_assist->ref_loc.altUncert);
773         break;
774
775         default:
776                 dbg("invalid element");
777         break;
778         }
779 }
780
781 static void _parse_dgps_correction_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
782 {
783         dbg("Enter");
784
785         if (strcmp(element_str, "sat_id") == 0) {
786                 gpsdata_assist->dgps_corrections.seqOfSatElement[0].satId = *element_value;
787                 dbg("seqOfSatElement[0].satId  - %d\n",
788                         gpsdata_assist->dgps_corrections.seqOfSatElement[0].satId);
789         } else if (strcmp(element_str, "IODE") == 0) {
790                 gpsdata_assist->dgps_corrections.seqOfSatElement[0].iode = atoi(element_value);
791                 dbg("seqOfSatElement[0].iode - %d\n",
792                         gpsdata_assist->dgps_corrections.seqOfSatElement[0].iode);
793         } else if (strcmp(element_str, "UDRE") == 0) {
794                 gpsdata_assist->dgps_corrections.seqOfSatElement[0].udre = *element_value;
795                 dbg("seqOfSatElement[0].udre- %d\n",
796                         gpsdata_assist->dgps_corrections.seqOfSatElement[0].udre);
797         } else if (strcmp(element_str, "PRC") == 0) {
798                 gpsdata_assist->dgps_corrections.seqOfSatElement[0].pseudoRangeCor = atoi(element_value);
799                 dbg("seqOfSatElement[0].pseudoRangeCor - %d\n",
800                         gpsdata_assist->dgps_corrections.seqOfSatElement[0].pseudoRangeCor);
801         } else if (strcmp(element_str, "RRC") == 0) {
802                 gpsdata_assist->dgps_corrections.seqOfSatElement[0].rangeRateCor = atoi(element_value);
803                 dbg("seqOfSatElement[0].rangeRateCor - %d\n",
804                         gpsdata_assist->dgps_corrections.seqOfSatElement[0].rangeRateCor);
805         }
806 }
807
808 static void _parse_ionospheric_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
809 {
810         static char *element[] = {"alfa0", "alfa1", "alfa2", "alfa3", "beta0", "beta1", "beta2", "beta3" };
811         int nelem = (int) NUM_OF_ELEMENTS(element);
812         int count;
813
814         count = _gps_element_compare(element, element_str, nelem);
815         dbg("enter");
816         switch (count) {
817         case 0:
818                 gpsdata_assist->iono_model.alfa0 = *element_value;
819                 dbg("alfa0  - 0x%X\n", gpsdata_assist->iono_model.alfa0);
820         break;
821
822         case 1:
823                 gpsdata_assist->iono_model.alfa1 = *element_value;
824                 dbg("alfa1 - 0x%X\n", gpsdata_assist->iono_model.alfa1);
825         break;
826
827         case 2:
828                 gpsdata_assist->iono_model.alfa2 = *element_value;
829                 dbg("alfa2  - 0x%X\n", gpsdata_assist->iono_model.alfa2);
830         break;
831
832         case 3:
833                 gpsdata_assist->iono_model.alfa3 = *element_value;
834                 dbg("alfa3  - 0x%X\n", gpsdata_assist->iono_model.alfa3);
835         break;
836
837         case 4:
838                 gpsdata_assist->iono_model.beta0 = *element_value;
839                 dbg("beta0  - 0x%X\n", gpsdata_assist->iono_model.beta0);
840         break;
841
842         case 5:
843                 gpsdata_assist->iono_model.beta1 = *element_value;
844                 dbg("beta1  -0x%X\n", gpsdata_assist->iono_model.beta1);
845         break;
846
847         case 6:
848                 gpsdata_assist->iono_model.beta2 = *element_value;
849                 dbg("beta2  - 0x%X\n", gpsdata_assist->iono_model.beta2);
850         break;
851
852         case 7:
853                 gpsdata_assist->iono_model.beta3 = *element_value;
854                 dbg("beta3  - 0x%X\n", gpsdata_assist->iono_model.beta3);
855         break;
856
857         default:
858                 dbg("invalid gps element");
859         break;
860         }
861 }
862
863 void _parse_utc_model_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
864 {
865         static char *element[] = {"a1", "a0", "tot", "wnt", "dtls", "wnlsf", "dn", "dtlsf"};
866         int nelem = (int) NUM_OF_ELEMENTS(element);
867         int count;
868
869         count = _gps_element_compare(element, element_str, nelem);
870         dbg("Enter");
871
872         switch (count) {
873         case 0:
874                 gpsdata_assist->utc_model.utcA1 = atoi(element_value);
875                 dbg("utcA1  - %d\n", gpsdata_assist->utc_model.utcA1);
876         break;
877
878         case 1:
879                 gpsdata_assist->utc_model.utcA0 = atoi(element_value);
880                 dbg("utcA0  - %d\n", gpsdata_assist->utc_model.utcA0);
881         break;
882
883         case 2:
884                 gpsdata_assist->utc_model.utcTot = *element_value;
885                 dbg("utcTot  - 0x%X\n", gpsdata_assist->utc_model.utcTot);
886         break;
887
888         case 3:
889                 gpsdata_assist->utc_model.utcWNt = *element_value;
890                 dbg("utcWNt  - 0x%X\n", gpsdata_assist->utc_model.utcWNt);
891         break;
892
893         case 4:
894                 gpsdata_assist->utc_model.utcDeltaTls = *element_value;
895                 dbg("utcDeltaTls  -0x%X\n", gpsdata_assist->utc_model.utcDeltaTls);
896         break;
897
898         case 5:
899                 gpsdata_assist->utc_model.utcWNlsf = *element_value;
900                 dbg("utcWNlsf  - 0x%X\n", gpsdata_assist->utc_model.utcWNlsf);
901         break;
902
903         case 6:
904                 gpsdata_assist->utc_model.utcDN = *element_value;
905                 dbg("utcDN  - 0x%X\n", gpsdata_assist->utc_model.utcDN);
906         break;
907
908         case 7:
909                 gpsdata_assist->utc_model.utcDeltaTlsf = *element_value;
910                 dbg("utcDeltaTlsf  - 0x%X\n", gpsdata_assist->utc_model.utcDeltaTlsf);
911         break;
912
913         default:
914                 dbg("invalid gps element");
915         break;
916         }
917 }
918
919 static void _parse_almanc_model_gps_elements(char *element_str,
920         char *element_value, gps_assist_data_noti_t *gpsdata_assist,
921         gboolean alm_elem, int count)
922 {
923         int nelem;
924         int node_count;
925         static char *element[] = {
926                 "wna", "data_id", "sat_id", "alm_ecc", "alm_toa", "alm_ksii", "alm_omega_dot", "alm_sv_health", "alm_power_half",
927                 "alm_omega0", "alm_omega", "alm_m0", "alm_af0", "alm_af1"
928         };
929
930         dbg("Enter");
931         if (count < 0 || count >= MAX_NUM_OF_GPS_ALMANC_ELEMENTS) {
932                 dbg("invalid count");
933                 return;
934         }
935         nelem = (int) NUM_OF_ELEMENTS(element);
936
937         node_count = _gps_element_compare(element, element_str, nelem);
938         if (node_count == 0) {
939                 gpsdata_assist->almanac.almanacWNa = *element_value;
940                 dbg("almanacWNa  - %d\n", gpsdata_assist->almanac.almanacWNa);
941                 return;
942         }
943
944         if (alm_elem) {
945                 switch (node_count) {
946                 case 1:
947                         gpsdata_assist->almanac.AlmanacSatInfo[count].dataId = *element_value;
948                         dbg("AlmanacSatInfo[%d].data_id  - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].dataId);
949                 break;
950
951                 case 2:
952                         gpsdata_assist->almanac.AlmanacSatInfo[count].satId = *element_value;
953                         dbg("AlmanacSatInfo[%d].sat_id  - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].satId);
954                 break;
955
956                 case 3:
957                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacE = atoi(element_value);
958                         dbg("AlmanacSatInfo[%d].almanacE  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacE);
959                 break;
960
961                 case 4:
962                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacToa = *element_value;
963                         dbg("AlmanacSatInfo[%d].almanacToa  - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacToa);
964                 break;
965
966                 case 5:
967                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacKsii = *element_value;
968                         dbg("AlmanacSatInfo[%d].almanacKsii  - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacKsii);
969                 break;
970
971                 case 6:
972                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmegaDot = *element_value;
973                         dbg("AlmanacSatInfo[%d].almanacOmegaDot  - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmegaDot);
974                 break;
975
976                 case 7:
977                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacSvHealth = *element_value;
978                         dbg("AlmanacSatInfo[%d].almanacSvHealth  - 0x%X\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacSvHealth);
979                 break;
980
981                 case 8:
982                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAPowerHalf = atoi(element_value);
983                         dbg("AlmanacSatInfo[%d].almanacAPowerHalf  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAPowerHalf);
984                 break;
985
986                 case 9:
987                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmega0 = atoi(element_value);
988                         dbg("AlmanacSatInfo[%d].almanacOmega0  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacOmega0);
989                 break;
990
991                 case 10:
992                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacW = atoi(element_value);
993                         dbg("AlmanacSatInfo[%d].almanacW  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacW);
994                 break;
995
996                 case 11:
997                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacM0 = atoi(element_value);
998                         dbg("AlmanacSatInfo[%d].almanacM0  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacM0);
999                 break;
1000
1001                 case 12:
1002                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf0 = atoi(element_value);
1003                         dbg("AlmanacSatInfo[%d].almanacAf0  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf0);
1004                 break;
1005
1006                 case 13:
1007                         gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf1 = atoi(element_value);
1008                         dbg("AlmanacSatInfo[%d].almanacAf1  - %d\n", count, gpsdata_assist->almanac.AlmanacSatInfo[count].almanacAf1);
1009                 break;
1010
1011                 default:
1012                         dbg("invalid gps element");
1013                 break;
1014                 }
1015         }
1016 }
1017
1018 static void _parse_acqu_assist_gps_elements(char *element_str, char *element_value, gps_assist_data_noti_t *gpsdata_assist)
1019 {
1020         static char *element[] = {"tow_msec", "sat_id", "dopl0", "dopl1", "code_ph", "code_ph_int", "GPS_bitno", "srch_w", "az", "elev"};
1021         int nelem = (int) NUM_OF_ELEMENTS(element);
1022         int count;
1023
1024         count = _gps_element_compare(element, element_str, nelem);
1025         dbg("Enter");
1026
1027         switch (count) {
1028         case 0:
1029                 gpsdata_assist->acq_assist.gpsTow = atoi(element_value);
1030                 dbg("acq_assist.gpsTow  - %d\n", gpsdata_assist->acq_assist.gpsTow);
1031         break;
1032
1033         case 1:
1034                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].satId = *element_value;
1035                 dbg("lcsAcquisitionSatInfo[0].satId  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].satId);
1036         break;
1037
1038         case 2:
1039                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler0 = atoi(element_value);
1040                 dbg("lcsAcquisitionSatInfo[0].dopl0  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler0);
1041         break;
1042
1043         case 3:
1044                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler1 = *element_value;
1045                 dbg("lcsAcquisitionSatInfo[0].doppler1  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].doppler1);
1046         break;
1047
1048         case 4:
1049                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhase = atoi(element_value);
1050                 dbg("lcsAcquisitionSatInfo[0].codePhase  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhase);
1051         break;
1052
1053         case 5:
1054                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].intCodePhase = *element_value;
1055                 dbg("lcsAcquisitionSatInfo[0].intCodePhase  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].intCodePhase);
1056         break;
1057
1058         case 6:
1059                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].gpsBitNumber = *element_value;
1060                 dbg("lcsAcquisitionSatInfo[0].GPS_bitno  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].gpsBitNumber);
1061         break;
1062
1063         case 7:
1064                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhaseSearchWindow = *element_value;
1065                 dbg("lcsAcquisitionSatInfo[0].codePhaseSearchWindow  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].codePhaseSearchWindow);
1066         break;
1067
1068         case 8:
1069                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].azimuth = *element_value;
1070                 dbg("lcsAcquisitionSatInfo[0].azimuth  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].azimuth);
1071         break;
1072
1073         case 9:
1074                 gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].elevation = *element_value;
1075                 dbg("lcsAcquisitionSatInfo[0].elevation  - 0x%X\n", gpsdata_assist->acq_assist.lcsAcquisitionSatInfo[0].elevation);
1076         break;
1077
1078         default:
1079                 dbg("invalid gps element");
1080         break;
1081         }
1082 }
1083
1084 static void _parse_nav_model_gps_elements(char *element_str, char *element_value,
1085         gps_assist_data_noti_t *gpsdata_assist, gboolean ephem_and_clock, int element_count)
1086 {
1087         static char *element[] = {
1088                 "sat_id", "l2_code", "ura", "sv_health", "iodc", "l2p_flag", "esr1", "esr2", "esr3", "esr4", "tgd", "toc", "af2", "af0",
1089                 "crs", "delta_n", "m0", "cuc", "ecc", "cus", "power_half", "toe", "fit_flag", "aoda", "cic", "omega0", "cis", "i0", "crc", "omega", "idot", "omega_dot"
1090         };
1091
1092         int nelem = (int) NUM_OF_ELEMENTS(element);
1093         int count;
1094
1095         if (element_count < 0 || element_count >= MAX_NUM_OF_GPS_NAV_ELEMENT) {
1096                 dbg("invalid count");
1097                 return;
1098         }
1099         count = _gps_element_compare(element, element_str, nelem);
1100
1101         dbg("Enter");
1102         if (count == 0) {
1103                 gpsdata_assist->navi_model.NavigationSatInfo[element_count].satId = *element_value;
1104                 dbg("NavigationSatInfo[%d].satId  - 0x%X\n", element_count, gpsdata_assist->navi_model.NavigationSatInfo[element_count].satId);
1105                 return;
1106         }
1107
1108         if (ephem_and_clock) {
1109                 switch (count) {
1110                 case 1:
1111                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCodeOnL2 = *element_value;
1112                 break;
1113
1114                 case 2:
1115                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemUra = *element_value;
1116                 break;
1117
1118                 case 3:
1119                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemSvHealth = *element_value;
1120                 break;
1121
1122                 case 4:
1123                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemIodc = atoi(element_value);
1124                 break;
1125
1126                 case 5:
1127                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemL2PFlag = *element_value;
1128                 break;
1129
1130                 case 6:
1131                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv1 = atoi(element_value);
1132                 break;
1133
1134                 case 7:
1135                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv2 = atoi(element_value);
1136                 break;
1137
1138                 case 8:
1139                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv3 = atoi(element_value);
1140                 break;
1141
1142                 case 9:
1143                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.NavigationSubFrameRsv.rsv4 = atoi(element_value);
1144                 break;
1145
1146                 case 10:
1147                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemTgd = *element_value;
1148                 break;
1149
1150                 case 11:
1151                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemToc = atoi(element_value);
1152                 break;
1153
1154                 case 12:
1155                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAf2 = *element_value;
1156                 break;
1157
1158                 case 13:
1159                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAf1 = atoi(element_value);
1160                 break;
1161
1162                 case 14:
1163                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAf0 = atoi(element_value);
1164                 break;
1165
1166                 case 15:
1167                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCrs = atoi(element_value);
1168                 break;
1169
1170                 case 16:
1171                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemDeltaN = atoi(element_value);
1172                 break;
1173
1174                 case 17:
1175                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemM0 = atoi(element_value);
1176                 break;
1177
1178                 case 18:
1179                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCuc = atoi(element_value);
1180                 break;
1181
1182                 case 19:
1183                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemE = atoi(element_value);
1184                 break;
1185
1186                 case 20:
1187                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCus = atoi(element_value);
1188                 break;
1189
1190                 case 21:
1191                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAPowrHalf = atoi(element_value);
1192                 break;
1193
1194                 case 22:
1195                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemToe = atoi(element_value);
1196                 break;
1197
1198                 case 23:
1199                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemFitFlag = *element_value;
1200                 break;
1201
1202                 case 24:
1203                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemAoda = *element_value;
1204                 break;
1205
1206                 case 25:
1207                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCic = atoi(element_value);
1208                 break;
1209
1210                 case 26:
1211                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemI0 = atoi(element_value);
1212                 break;
1213
1214                 case 27:
1215                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemCrc = atoi(element_value);
1216                 break;
1217
1218                 case 28:
1219                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemW = atoi(element_value);
1220                 break;
1221
1222                 case 29:
1223                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemIDot = atoi(element_value);
1224                 break;
1225
1226                 case 30:
1227                         gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemOmegaADot = atoi(element_value);
1228                         dbg("NavigationSatInfo[%d].NavigationEphemeris.ephemOmegaADot - 0x%X\n",
1229                                 element_count, gpsdata_assist->navi_model.NavigationSatInfo[element_count].NavigationEphemeris.ephemOmegaADot);
1230                 break;
1231
1232                 default:
1233                         dbg("invalid gps element");
1234                 break;
1235                 }
1236         }
1237 }
1238
1239
1240 /* Set coordinate elements  : <latitude> <longitude> <altitude> */
1241 static void _set_coordinate(xmlNodePtr node, gps_ellipsoid_po_t *point, int isalt, int altitude)
1242 {
1243         /* <parent_node> .. .. (xmlNodePtr node) */
1244         /* <coordinate>  <latitude>  <north>0</north>  <degrees>0</degrees> </latitude> <longitude>0</longitude> </coordinate> */
1245         /* <altitude>  <height_above_surface>0</height_above_surface>  <height>0</height> </altitude> */
1246         /* .. .. <\parent_node> */
1247
1248         xmlNodePtr coordinate_node = NULL, temp_node = NULL;
1249
1250         memset(node_name, 0x00, sizeof(node_name));
1251         memset(node_value, 0x00, sizeof(node_value));
1252
1253         snprintf(node_name, NODE_SIZE, "%s", "coordinate");
1254         coordinate_node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1255
1256         snprintf(node_name, NODE_SIZE, "%s", "latitude");
1257         temp_node = xmlNewChild(coordinate_node, NULL, BAD_CAST node_name, NULL);
1258
1259         snprintf(node_name, NODE_SIZE, "%s", "north");
1260         snprintf(node_value, NODE_SIZE, "%d", 0);
1261         xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1262
1263         snprintf(node_name, NODE_SIZE, "%s", "degrees");
1264         snprintf(node_value, NODE_SIZE, "%d", (int) point->latitude);
1265         xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1266
1267         snprintf(node_name, NODE_SIZE, "%s", "longitude");
1268         snprintf(node_value, NODE_SIZE, "%d", (int) point->longitude);
1269         xmlNewChild(coordinate_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1270
1271         if (isalt) {
1272                 snprintf(node_name, NODE_SIZE, "%s", "altitude");
1273                 temp_node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1274                 snprintf(node_name, NODE_SIZE, "%s", "height_above_surface");
1275                 snprintf(node_value, NODE_SIZE, "%d", 0);
1276                 xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1277                 snprintf(node_name, NODE_SIZE, "%s", "height");
1278                 snprintf(node_value, NODE_SIZE, "%d", altitude);
1279                 xmlNewChild(temp_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1280         }
1281         return;
1282 }
1283
1284 static void _set_loc_info_ellipse_elements(xmlNodePtr node, void *elliplse, int is_unc_ellipse)
1285 {
1286         gps_po_unc_ellipse_t *p_unc_ellipse;
1287         gps_po_alt_unc_ellipse_t *p_alt_unc_ellipse;
1288         unsigned char semiMajorAxis, semiMinorAxis, orientationAngle, confidence;
1289
1290         memset(node_name, 0x00, sizeof(node_name));
1291         memset(node_value, 0x00, sizeof(node_value));
1292
1293         if (is_unc_ellipse) {
1294                 p_unc_ellipse = (gps_po_unc_ellipse_t *) elliplse;
1295                 semiMajorAxis = p_unc_ellipse->semiMajorAxis;
1296                 semiMinorAxis = p_unc_ellipse->semiMinorAxis;
1297                 orientationAngle = p_unc_ellipse->orientationAngle;
1298                 confidence = p_unc_ellipse->confidence;
1299         } else {
1300                 p_alt_unc_ellipse = (gps_po_alt_unc_ellipse_t *) elliplse;
1301                 semiMajorAxis = p_alt_unc_ellipse->semiMajorAxis;
1302                 semiMinorAxis = p_alt_unc_ellipse->semiMinorAxis;
1303                 orientationAngle = p_alt_unc_ellipse->orientationAngle;
1304                 confidence = p_alt_unc_ellipse->confidence;
1305         }
1306
1307         snprintf(node_name, NODE_SIZE, "%s", "uncert_semi_major");
1308         snprintf(node_value, NODE_SIZE, "%d", semiMajorAxis);
1309         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1310
1311         snprintf(node_name, NODE_SIZE, "%s", "uncert_semi_minor");
1312         snprintf(node_value, NODE_SIZE, "%d", semiMinorAxis);
1313         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1314
1315         snprintf(node_name, NODE_SIZE, "%s", "orient_major");
1316         snprintf(node_value, NODE_SIZE, "%d", orientationAngle);
1317         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1318
1319         snprintf(node_name, NODE_SIZE, "%s", "confidence");
1320         snprintf(node_value, NODE_SIZE, "%d", confidence);
1321         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1322 }
1323
1324 static xmlChar *_generate_confirm_measure_pos_xml_text(gps_measure_position_confirm_t *gps_measure_position_confirm)
1325 {
1326         xmlDocPtr doc = NULL;
1327         xmlNodePtr root_node = NULL, node = NULL;
1328         xmlNodePtr gps_msr_node = NULL, shape_data_node = NULL, loc_child_node = NULL;
1329         xmlChar *xml = NULL;
1330         int count = 0, altitude, size;
1331
1332 /*
1333         Creates a new XML document
1334 ================================================================================================================================
1335 <?xml version="1.0"?>
1336 <pos xsi:noNamespaceSchemaLocation="pos.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1337         <GPS_meas>
1338                 <ref_time_only>
1339                         <tow_msec></tow_msec>
1340                 </ref_time_only>
1341                 <meas_params>
1342                         <sat_id></sat_id><carr2_noise></carr2_noise><dopl></dopl><whole_chips></whole_chips><fract_chips></fract_chips>
1343                         <multi_path literal="xx"></multi_path> <psr_rms_err></psr_rms_err>
1344                 </meas_params>
1345         </GPS_meas>
1346
1347         <location>
1348                 <time_of_fix></time_of_fix><
1349                 <location_parameters>
1350                         <shape_data>
1351
1352                         <ellipsoid_point>
1353                                 <coordinate>
1354                                         <latitude><north></north><degrees></degrees></latitude><longitude></longitude>
1355                                 </coordinate>
1356                         </ellipsoid_point>
1357
1358                         <ellipsoid_point_uncert_circle>
1359                                 <uncert_circle></uncert_circle>
1360                                 <coordinate>
1361                                         <latitude> <> <\> ...</latitude> <longitude></longitude>
1362                                 </coordinate>
1363                         </ellipsoid_point_uncert_circle>
1364
1365                         <ellipsoid_point_uncert_ellipse>
1366                                 <coordinate>
1367                                         <latitude><> <\>..<longitude></longitude>
1368                                 </coordinate>
1369                                 <uncert_ellipse><uncert_semi_major></uncert_semi_major><uncert_semi_minor></uncert_semi_minor>
1370                                 <orient_major></orient_major><confidence></confidence></uncert_ellipse>
1371                         </ellipsoid_point_uncert_ellipse>
1372
1373                         <polygon>
1374                                 <coordinate*>
1375                                         <latitude><> <\>...</latitude><longitude></longitude>
1376                                 </coordinate>
1377                         </polygon>
1378
1379                         <ellipsoid_point_alt>
1380                                 <coordinate>
1381                                         <latitude><> <\>..</latitude><longitude></longitude>
1382                                 </coordinate>
1383                                 <altitude>
1384                                         <height_above_surface></height_above_surface><height></height>
1385                                 </altitude>
1386                         </ellipsoid_point_alt>
1387
1388                         <ellipsoid_point_alt_uncertellipse>
1389                                 <coordinate>
1390                                         <latitude> <> <\>.. ..</latitude><longitude></longitude>
1391                                 </coordinate>
1392                                 <altitude>
1393                                         <height_above_surface></height_above_surface><height></height>
1394                                 </altitude>
1395                                 <uncert_semi_major></uncert_semi_major><uncert_semi_minor></uncert_semi_minor><orient_major></orient_major>
1396                                 <confidence></confidence><uncert_alt></uncert_alt>
1397                         </ellipsoid_point_alt_uncertellipse>
1398
1399                         <ellips_arc>
1400                                 <coordinate>
1401                                         <latitude><> <\> .. </latitude><longitude></longitude>
1402                                 </coordinate><
1403                                 <inner_rad></inner_rad>
1404                                 <uncert_rad></uncert_rad><offset_angle></offset_angle><included_angle></included_angle>
1405                                 <confidence></confidence>
1406                         </ellips_arc>
1407                         </shape_data>
1408                 </location_parameters>
1409         </location>
1410         <assist_data>
1411                 <msr_assist_data/>
1412         </assist_data>
1413 </pos>
1414  ================================================================================================================================
1415  */
1416
1417         doc = xmlNewDoc(BAD_CAST "1.0");
1418         dbg("Enter");
1419
1420         memset(node_name, 0x00, sizeof(node_name));
1421         memset(node_value, 0x00, sizeof(node_value));
1422         /* root element */
1423         snprintf(node_name, NODE_SIZE, "%s", POSITION_NODE);
1424         /* Creation of a new node element */
1425         root_node = xmlNewNode(NULL, BAD_CAST node_name);
1426         /* Set the root element of the document */
1427         xmlDocSetRootElement(doc, root_node);
1428         snprintf(node_name, NODE_SIZE, "%s", POSITION_NODE_ATTR_XSI);
1429         snprintf(node_value, NODE_SIZE, "%s", POSITION_NODE_ATTR_VAL_XSI);
1430         /* Create a new property carried by a node */
1431         xmlNewProp(root_node, BAD_CAST node_name, BAD_CAST node_value);
1432
1433         snprintf(node_name, NODE_SIZE, "%s", POSITION_NODE_ATTR_XMLNS);
1434         snprintf(node_value, NODE_SIZE, "%s", POSITION_NODE_ATTR_VAL_XMLNS);
1435         xmlNewProp(root_node, BAD_CAST node_name, BAD_CAST node_value);
1436
1437         /* 1.GPS measure. */
1438         /* Creation of a new child element, added at the end of @parent children list */
1439         snprintf(node_name, NODE_SIZE, "%s", "GPS_meas");
1440         gps_msr_node = xmlNewChild(root_node, NULL, BAD_CAST node_name, NULL);
1441
1442         snprintf(node_name, NODE_SIZE, "%s", "ref_time_only");
1443         node = xmlNewChild(gps_msr_node, NULL, BAD_CAST node_name, NULL);
1444
1445         snprintf(node_name, NODE_SIZE, "%s", "tow_msec");
1446         snprintf(node_value, NODE_SIZE, "%d", (int) gps_measure_position_confirm->gps_measure.gpsTow);
1447         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1448
1449         /* creatation of <meas_params> elements. */
1450         for (count = 0; count < gps_measure_position_confirm->gps_measure.nrOfSats; count++) {
1451                 xmlNodePtr multipath_node = NULL;
1452                 snprintf(node_name, NODE_SIZE, "%s", "meas_params");
1453                 node = xmlNewChild(gps_msr_node, NULL, BAD_CAST node_name, NULL);
1454
1455                 snprintf(node_name, NODE_SIZE, "%s", "sat_id");
1456                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].satId);
1457                 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1458
1459                 snprintf(node_name, NODE_SIZE, "%s", "carr2_noise");
1460                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].cno);
1461                 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1462
1463                 snprintf(node_name, NODE_SIZE, "%s", "dopl");
1464                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].doppler);
1465                 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1466
1467                 snprintf(node_name, NODE_SIZE, "%s", "whole_chips");
1468                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].wholeChips);
1469                 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1470
1471                 snprintf(node_name, NODE_SIZE, "%s", "fract_chips");
1472                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].fracChips);
1473                 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1474
1475                 snprintf(node_name, NODE_SIZE, "%s", "multi_path");
1476                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].lcsMultiPath);
1477                 multipath_node = xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1478                 xmlNewProp(multipath_node, BAD_CAST "literal", BAD_CAST "not_measured");
1479
1480                 snprintf(node_name, NODE_SIZE, "%s", "psr_rms_err");
1481                 snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->gps_measure.GpsMeasure[count].pseuRangeRmsErr);
1482                 xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1483         }
1484
1485         /* 2.Location. */
1486         snprintf(node_name, NODE_SIZE, "%s", "location");
1487         node = xmlNewChild(root_node, NULL, BAD_CAST node_name, NULL);
1488
1489         snprintf(node_name, NODE_SIZE, "%s", "time_of_fix");
1490         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.fixType);
1491         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1492
1493         /* location_parameters */
1494         snprintf(node_name, NODE_SIZE, "%s", "location_parameters");
1495         node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1496
1497         /* shape_data */
1498         snprintf(node_name, NODE_SIZE, "%s", "shape_data");
1499         shape_data_node = xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1500
1501         /* ellipsoid_point */
1502         snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point");
1503         node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1504         /* set coordinate. */
1505         _set_coordinate(node, &(gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_po), 0, 0);
1506
1507         /* ellipsoid_point_uncert_circle */
1508         snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_uncert_circle");
1509         node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1510         snprintf(node_name, NODE_SIZE, "%s", "uncert_circle");
1511         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_clrcle.uncertainRadius);
1512         xmlNewChild(node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1513         /* set coordinate parameters. */
1514         _set_coordinate(node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_clrcle.point), 0, 0);
1515
1516         /* ellipsoid_point_uncert_ellipse */
1517         snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_uncert_ellipse");
1518         loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1519         /* set coordinate parameters. */
1520         _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_clrcle.point), 0, 0);
1521
1522         snprintf(node_name, NODE_SIZE, "%s", "uncert_ellipse");
1523         node = xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, NULL);
1524         /* set location ellipse parametes. */
1525         _set_loc_info_ellipse_elements(node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_unc_ellipse), 1);
1526
1527         snprintf(node_name, NODE_SIZE, "%s", "polygon");
1528         loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1529         for (count = 0; count < gps_measure_position_confirm->loc_info.measured_loc_info.polygon.noOfPoints; count++) {
1530                 /* set coordinate parameters. */
1531                 _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.polygon.points[count]), 0, 0);
1532         }
1533
1534         /* ellipsoid_point_alt */
1535         snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_alt");
1536         loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1537         altitude = gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_alt.altitude;
1538         /* set coordinate parameters. */
1539         _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_alt.point), 1, altitude);
1540
1541         /* ellipsoid_point_alt_uncertellipse */
1542         snprintf(node_name, NODE_SIZE, "%s", "ellipsoid_point_alt_uncertellipse");
1543         loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1544         altitude = gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse.altitude;
1545         /* set coordinate parameters. */
1546         _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse.point), 1, altitude);
1547         /* set location ellipse parametes. */
1548         _set_loc_info_ellipse_elements(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse), 0);
1549
1550         snprintf(node_name, NODE_SIZE, "%s", "uncert_alt");
1551         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.p_alt_unc_ellipse.uncertainAltitude);
1552         xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1553
1554         /* ellipsoid_point_alt_uncertellipse */
1555         snprintf(node_name, NODE_SIZE, "%s", "ellips_arc");
1556         loc_child_node = xmlNewChild(shape_data_node, NULL, BAD_CAST node_name, NULL);
1557         _set_coordinate(loc_child_node, &(gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.point), 0, 0);
1558
1559         snprintf(node_name, NODE_SIZE, "%s", "inner_rad");
1560         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.innerRadius);
1561         xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1562
1563         snprintf(node_name, NODE_SIZE, "%s", "uncert_rad");
1564         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.uncertainRadius);
1565         xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1566
1567         snprintf(node_name, NODE_SIZE, "%s", "offset_angle");
1568         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.offsetAngle);
1569         xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1570
1571         snprintf(node_name, NODE_SIZE, "%s", "included_angle");
1572         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.includedAngle);
1573         xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1574
1575         snprintf(node_name, NODE_SIZE, "%s", "confidence");
1576         snprintf(node_value, NODE_SIZE, "%d", gps_measure_position_confirm->loc_info.measured_loc_info.ellipsoid_arc.confidence);
1577         xmlNewChild(loc_child_node, NULL, BAD_CAST node_name, BAD_CAST node_value);
1578
1579         /* 3. assist data /msr_assist_data */
1580         snprintf(node_name, NODE_SIZE, "%s", "assist_data");
1581         node = xmlNewChild(root_node, NULL, BAD_CAST node_name, NULL);
1582         snprintf(node_name, NODE_SIZE, "%s", "msr_assist_data");
1583         xmlNewChild(node, NULL, BAD_CAST node_name, NULL);
1584
1585         /* Dump an XML document in memory and return the #xmlChar * and it's size in bytes */
1586         xmlDocDumpMemory(doc, &xml, &size);
1587         dbg("xmlcontetnt:\n");
1588         dbg("%s", (char *) xml);
1589         /* Free up all the structures used by a document, tree included. */
1590         xmlFreeDoc(doc);
1591         xmlCleanupParser();
1592         return xml;
1593 }
1594
1595 static gboolean on_notification_gps_assist_data(CoreObject *o, const void *event_info, void *user_data)
1596 {
1597         int fd;
1598         gps_assist_data_noti_t gps_data_assist;
1599         char *node = NULL, *node_value = NULL;
1600         char *attribute = NULL, *attr_value = NULL;
1601         enum gps_assist_element_type node_type = -1, set_element_type = -1;
1602         int nav_model_node_count = 0;
1603         int alm_node_count = -1;
1604         int gps_tow_assist_count = -1;
1605         char *line = NULL, *pos = NULL;
1606         char *xml_line = NULL;
1607         gboolean ret;
1608         xmlTextReaderPtr reader;
1609         gboolean _gps_assist_data = FALSE, gps_tow_assist = FALSE;
1610         gboolean ephem_and_clock = FALSE, alm_elem = FALSE;
1611
1612         dbg("enter");
1613
1614 /*
1615         Example:GPS assist XML data will be in below format.
1616 ================================================================================================================================
1617         +CPOSR:<?xml version="1.0" encoding="UTF-8"?>
1618         <pos xsi:noNamespaceSchemaLocation="pos.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1619                 <assist_data>
1620                         <GPS_assist>
1621                                 <ref_time>
1622                                         <GPS_time> <> <\>..<\GPS_time> <GPS_TOW_assist*> <> <\> ..<\GPS_TOW_assist>
1623                                 </ref_time>
1624
1625                                 <location_parameters>
1626                                         <shape_data> <ellipsoid_point_alt_uncertellipse> </coordinate> <> <\>...</coordinate> <altitude> <\altitude>
1627                                         <uncert_semi_major> </uncert_semi_major> <uncert_semi_minor> </uncert_semi_minor> <orient_major> </orient_major> <confidence> </confidence>
1628                                         <uncert_alt> </uncert_alt>  </ellipsoid_point_alt_uncertellipse> </shape_data>
1629                                 </location_parameters>
1630
1631                                 <DGPS_corrections>
1632                                         <sat_id> </sat_id> <IODE> </IODE> <UDRE></UDRE> <PRC></PRC> <RRC></RRC>
1633                                 </DGPS_corrections>
1634
1635                                 <nav_model_elem*>
1636                                         <sat_id> </sat_id> <sat_status literal="xx"></sat_status>
1637                                         <ephem_and_clock?> <l2_code></l2_code> <> <\> .. ..  <\ephem_and_clock>
1638                                 </nav_model_elem>
1639
1640                                 <ionospheric_model> <alfa0> </alfa0> <alfa1> </alfa1> <alfa2> </alfa2>  <alfa3></alfa3>
1641                                         <beta0></beta0> <beta1></beta1> <beta2></beta2>  <beta3> </beta3>
1642                                 </ionospheric_model>
1643
1644                                 <UTC_model>
1645                                         <a1></a1><a0></a0><tot></tot><wnt></wnt> <dtls></dtls> <wnlsf></wnlsf> <dn></dn><dtlsf></dtlsf>
1646                                 </UTC_model>
1647                                 <almanac>
1648                                         <wna>0</wna> <alm_elem*> <> <\> ...<\alm_elem>
1649                                 </almanac>
1650
1651                                 <acqu_assist>
1652                                         <tow_msec></tow_msec>  <sat_info> <> <\> ...  <\sat_info>
1653                                 </acqu_assist>
1654
1655                         </GPS_assist>
1656                 </assist_data>
1657         </pos>
1658 ================================================================================================================================
1659 */
1660
1661         memset((void *) &gps_data_assist, 0x00, sizeof(gps_data_assist));
1662         xml_line = (char *) ((GSList *) event_info)->data;
1663
1664         if (g_str_has_prefix((char *) xml_line, "+CPOSR:")) {
1665                 dbg("notification line with prefix");
1666                 pos = (char *) xml_line + strlen("+CPOSR:");
1667         } else {
1668                 pos = (char *) xml_line;
1669         }
1670         line = g_strdup((char *) pos);
1671
1672         /* open file. */
1673         if ((fd = open(FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, S_IRWXU)) == -1) {
1674                 dbg("Cannot open file\n");
1675                 g_free(line);
1676                 return FALSE;
1677         }
1678
1679         /* write gps xml data into file. */
1680         if (write(fd, (const void *) line, strlen(line)) == -1) {
1681                 dbg("Cannot write into file\n");
1682                 close(fd);
1683                 g_free(line);
1684                 return FALSE;
1685         }
1686
1687         /* free the memory pointed to by line. */
1688         g_free(line);
1689
1690         dbg("read xml file");
1691         reader = xmlReaderForFile(FILE_NAME, NULL, 0);
1692
1693         while (xmlTextReaderRead(reader)) {
1694                 /* Get the node type of the current node */
1695                 switch (xmlTextReaderNodeType(reader)) {
1696                 case XML_READER_TYPE_ELEMENT: {
1697                         /* Read the qualified name of the node. */
1698                         node = (char *) xmlTextReaderConstName(reader);
1699                         dbg("Element: %s\n ", node);
1700                         if (node != NULL) {
1701                                 /* check type of sub element of <GPS_assist> */
1702                                 set_element_type = _get_element_type(node);
1703                                 if ((int) set_element_type != -1)     /* ignore negative value as excepted element type not set. */
1704                                         node_type = set_element_type;
1705
1706                                 dbg("xml node type  : %d", node_type);
1707
1708                                 /* Check for position measurement data. */
1709                                 if (strcmp(node, "pos_meas") == 0) {
1710                                         /* Deallocate all the resources associated to the reader */
1711                                         xmlFreeTextReader(reader);
1712                                         xmlCleanupParser();
1713                                         dbg("gps postion measurement notification ");
1714                                         /* GPS position measurement notification. */
1715                                         ret = on_notification_gps_measure_position_from_modem(o, FILE_NAME, user_data);
1716                                         /* remove file. */
1717                                         close(fd);
1718                                         if (access(FILE_NAME, F_OK) == 0) {
1719                                                 if (remove(FILE_NAME))
1720                                                         dbg("file removed");
1721                                         }
1722                                         return ret;
1723                                 }
1724
1725                                 /* Moves the position of the current instance to the next attribute associated with the current node. */
1726                                 while (xmlTextReaderMoveToNextAttribute(reader)) {
1727                                         /* Read the qualified name of the node */
1728                                         attribute = (char *) xmlTextReaderConstName(reader);
1729                                         dbg("attribute value - %s\n", attribute);
1730
1731                                         /* Provides the text value of the node if present. */
1732                                         attr_value = (char *) xmlTextReaderConstValue(reader);
1733                                         dbg("=\"%s\"\n", attr_value);
1734
1735                                         /* Read attribute value of <nav_model_elem> */
1736                                         if (node_type == NAV_MODEL_ELEM) {
1737                                                 if (strcmp(node, "sat_status") == 0 && strcmp(attribute, "literal") == 0) {
1738                                                         gps_data_assist.navi_model.NavigationSatInfo[nav_model_node_count].NavigationSatStatus = _modem_sat_status_info_2_tel_sat_info(attr_value);
1739                                                         dbg("navigation sat status of nav model element - %d\n", gps_data_assist.navi_model.NavigationSatInfo[nav_model_node_count].NavigationSatStatus);
1740                                                 }
1741                                         }
1742                                         /* Read attribute value of <acqu_assist> */
1743                                         else if (node_type == ACQU_ASSIST) {
1744                                                 if (strcmp(node, "dopl1_uncert") == 0 && strcmp(attribute, "literal") == 0) {
1745                                                         gps_data_assist.acq_assist.lcsAcquisitionSatInfo[0].dopplerUncertainty = _modem_acqa_assit_doppler_2_tel_doppler(attr_value);
1746                                                         dbg("doppler uncertainty of acqu assist data- %d", gps_data_assist.acq_assist.lcsAcquisitionSatInfo[0].dopplerUncertainty);
1747                                                 }
1748                                         }
1749                                 }        /* end of attribute check. */
1750
1751                                 /* check GPS data is having GPS_assist data. */
1752                                 if (strcmp(node, "GPS_assist") == 0)
1753                                         _gps_assist_data = TRUE;
1754
1755                                 if (_gps_assist_data == TRUE) {
1756                                         /* number of GPS_TOW_assist elements. */
1757                                         if (strcmp(node, "GPS_TOW_assist") == 0) {
1758                                                 gps_tow_assist_count++;
1759                                                 gps_tow_assist = TRUE;
1760                                         } else if (strcmp(node, "nav_model_elem") == 0) {
1761                                                 /* number of nav_model_elem. */
1762                                                 nav_model_node_count++;
1763                                         } else if (strcmp(node, "alm_elem") == 0) {
1764                                                 /* number of alm_elem elements. */
1765                                                 alm_node_count++;
1766                                                 dbg("alm_elem_count - %d", alm_node_count);
1767                                                 if (node_type == ALMANAC)
1768                                                         alm_elem = TRUE;
1769                                         } else if (strcmp(node, "ephem_and_clock") == 0 && node_type == NAV_MODEL_ELEM) {
1770                                                 ephem_and_clock = TRUE;
1771                                         }
1772                                 }
1773                         }
1774                         xmlTextReaderMoveToElement(reader);
1775                 }     /* end of reading node type. */
1776                 break;
1777
1778                 case XML_READER_TYPE_TEXT: {
1779                         /* Provides the text value of the node if present */
1780                         node_value = (char *) xmlTextReaderConstValue(reader);
1781                         dbg("node_value: %s\n", node_value);
1782
1783                         if (node_value != NULL) {
1784                                 switch (node_type) {
1785                                 case REF_TIME:
1786                                         _parse_ref_time_gps_elements(node, node_value, &gps_data_assist, gps_tow_assist, gps_tow_assist_count);
1787                                         break;
1788
1789                                 case LOCATION_PARM:
1790                                         _parse_location_parameters(node, node_value, &gps_data_assist);
1791                                         break;
1792
1793                                 case DGPS_CORRECTION:
1794                                         _parse_dgps_correction_gps_elements(node, node_value, &gps_data_assist);
1795                                         break;
1796
1797                                 case NAV_MODEL_ELEM:
1798                                         _parse_nav_model_gps_elements(node, node_value, &gps_data_assist, ephem_and_clock, nav_model_node_count);
1799                                         break;
1800
1801                                 case IONOSPHERIC_MODEL:
1802                                         _parse_ionospheric_model_gps_elements(node, node_value, &gps_data_assist);
1803                                         break;
1804
1805                                 case UTC_MODEL:
1806                                         _parse_utc_model_gps_elements(node, node_value, &gps_data_assist);
1807                                         break;
1808
1809                                 case ALMANAC:
1810                                         _parse_almanc_model_gps_elements(node, node_value, &gps_data_assist, alm_elem, alm_node_count);
1811                                         break;
1812
1813                                 case ACQU_ASSIST:
1814                                         _parse_acqu_assist_gps_elements(node, node_value, &gps_data_assist);
1815                                         break;
1816
1817                                 default:
1818                                         dbg("invalid element");
1819                                 }
1820                         }
1821                 }     /* end of reading node value. */
1822                 break;
1823                 }
1824         } /* end of parsing. */
1825
1826         /* Deallocate all the resources associated to the reader */
1827         xmlFreeTextReader(reader);
1828         xmlCleanupParser();
1829
1830         /* remove xml file. */
1831         close(fd);
1832         if (access(FILE_NAME, F_OK) == 0) {
1833                 if (remove(FILE_NAME))
1834                         dbg("file removed");
1835         }
1836
1837         tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)),
1838                 o,
1839                 TNOTI_GPS_ASSIST_DATA,
1840                 sizeof(gps_data_assist), &gps_data_assist);
1841         return TRUE;
1842 }
1843
1844 static gboolean on_notification_gps_measure_position_from_modem(CoreObject *o, char *file_name, void *user_data)
1845 {
1846         char *node = NULL, *node_value = NULL;
1847         char *attribute = NULL;
1848         char *attr_value = NULL;
1849         gps_measure_position_indi_t gps_measure_position_indi;
1850         gboolean rep_quant = FALSE;
1851         xmlTextReaderPtr reader;
1852
1853         memset(&gps_measure_position_indi, 0x00, sizeof(gps_measure_position_indi));
1854         reader = xmlReaderForFile(file_name, NULL, 0);
1855
1856         while (xmlTextReaderRead(reader)) {
1857                 switch (xmlTextReaderNodeType(reader)) {
1858                 case XML_READER_TYPE_ELEMENT: {
1859                         node = (char *) xmlTextReaderConstName(reader);
1860                         if (!node)
1861                                 return FALSE;
1862
1863                         dbg("Element: %s", node);
1864                         if (node != NULL) {
1865                                 /* Read attribute value. */
1866                                 while (xmlTextReaderMoveToNextAttribute(reader)) {
1867                                         attribute = (char *) xmlTextReaderConstName(reader);
1868                                         dbg("Attribute value - %s\n", attribute);
1869                                         attr_value = (char *) xmlTextReaderConstValue(reader);
1870                                         dbg("=\"%s\"\n", attr_value);
1871
1872                                         if (strcmp(node, "mult_sets") == 0) {
1873                                                 if (strcmp(attribute, "literal") == 0) {
1874                                                         if (strcmp(attr_value, "one") == 0)
1875                                                                 gps_measure_position_indi.use_multi_sets = GPS_MULTIPLESETS_ONESET;
1876                                                         else if (strcmp(attr_value, "multiple") == 0)
1877                                                                 gps_measure_position_indi.use_multi_sets = GPS_MULTIPLESETS_MULTIPLESETS;
1878                                                 }
1879                                                 dbg("gps_measure_position_indi.use_multi_sets - 0x%x\n", gps_measure_position_indi.use_multi_sets);
1880                                         } else if (strcmp(node, "rep_quant") == 0) {
1881                                                 rep_quant = TRUE;
1882                                                 if (strcmp(attribute, "addl_assist_data_req") == 0) {
1883                                                         if (strcmp(attr_value, "true") == 0)
1884                                                                 gps_measure_position_indi.add_assist_req = GPS_ADDITIONAL_ASSISREQ_REQ;
1885                                                         else
1886                                                                 gps_measure_position_indi.add_assist_req = GPS_ADDITIONAL_ASSISREQ_NOT_REQ;
1887                                                 } else if (strcmp(attribute, "gps_timing_of_cell_wanted") == 0) {
1888                                                         if (strcmp(attr_value, "true") == 0)
1889                                                                 gps_measure_position_indi.cell_timing_wnt = GPS_CELLTIMING_WANTED;
1890                                                         else
1891                                                                 gps_measure_position_indi.cell_timing_wnt = GPS_CELLTIMING_NOT_WANTED;
1892                                                 }
1893                                         }
1894                                 }        /* end of attribute check */
1895
1896                                 if (strcmp(node, "ms_assisted") == 0)
1897                                         gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_ASSISTED;
1898                                 else if (strcmp(node, "ms_assisted_no_accuracy") == 0)
1899                                         gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_ASSISTED;
1900                                 else if (strcmp(node, "ms_based") == 0)
1901                                         gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_BASED;
1902                                 else if (strcmp(node, "ms_based_pref") == 0)
1903                                         gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_BASED_PREF;
1904                                 else if (strcmp(node, "ms_assisted_pref") == 0)
1905                                         gps_measure_position_indi.method_type = GPS_METHODTYPE_MS_ASSISTED_PREF;
1906                         }
1907                         xmlTextReaderMoveToElement(reader);
1908                 }
1909                 break;
1910
1911                 case XML_READER_TYPE_TEXT: {
1912                         node_value = (char *) xmlTextReaderConstValue(reader);
1913                         dbg("element-value: %s", node_value);
1914                         if (node_value != NULL) {
1915                                 if (strcmp(node_value, "resp_time_seconds") == 0) {
1916                                         gps_measure_position_indi.rsp_time = *node_value;
1917                                         dbg("gps_measure_position_indi.rsp_time - 0x%x", gps_measure_position_indi.rsp_time);
1918                                 }
1919                                 if (rep_quant == TRUE) {
1920                                         if (strcmp(node_value, "hor_acc") == 0)
1921                                                 gps_measure_position_indi.accuracy.horizontalAccuracy = *node_value;
1922                                         else if (strcmp(node_value, "vert_acc") == 0)
1923                                                 gps_measure_position_indi.accuracy.vertcalAccuracy = *node_value;
1924                                 }
1925                         }
1926                 }
1927                 break;
1928                 }
1929         }
1930         xmlFreeTextReader(reader);
1931         xmlCleanupParser();
1932
1933         tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)),
1934                                                                    o, TNOTI_GPS_MEASURE_POSITION, sizeof(gps_measure_position_indi), &gps_measure_position_indi);
1935         return TRUE;
1936 }
1937
1938
1939 /* CONFIRMATION */
1940 static void on_confirmation_gps_message_send(TcorePending *p, gboolean result, void *user_data)
1941 {
1942         dbg("Entry");
1943
1944         if (result == FALSE) /* Fail */
1945                 dbg("SEND FAIL");
1946         else
1947                 dbg("SEND OK");
1948
1949         dbg("Exit");
1950 }
1951
1952 static gboolean on_notification_reset_assist_data(CoreObject *o, const void *event_info, void *user_data)
1953 {
1954         dbg("enter!\n");
1955         tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)),
1956                                                                    o, TNOTI_GPS_RESET_ASSIST_DATA, 0, NULL);
1957
1958         return TRUE;
1959 }
1960 static void on_confirmation_gps_measure_position(TcorePending *p, int data_len, const void *data, void *user_data)
1961 {
1962         /* GPS server does not except confirmation for GPS measure position request. */
1963         dbg("enter");
1964
1965         dbg("exit");
1966 }
1967
1968 static TReturn gps_confirm_measure_pos(CoreObject *o, UserRequest *ur)
1969 {
1970         char *raw_str = NULL;
1971         char *cmd_str = NULL;
1972         TcorePending *pending = NULL;
1973         TcoreATRequest *req = NULL;
1974         TcoreHal *hal = NULL;
1975         gboolean ret = FALSE;
1976         xmlChar *xml = NULL;
1977         unsigned char *data = NULL;
1978         unsigned int data_len;
1979         gps_measure_position_confirm_t gps_measure_pos_confirm;
1980
1981         dbg("enter!");
1982         if (!o || !ur)
1983                 return TCORE_RETURN_EINVAL;
1984
1985         data = (unsigned char *) tcore_user_request_ref_data(ur, &data_len);
1986         memcpy(&gps_measure_pos_confirm, data, data_len);
1987
1988         /* make confirm measure postion request in xml format. */
1989         xml = _generate_confirm_measure_pos_xml_text(&gps_measure_pos_confirm);
1990         if (!xml) {
1991                 err("xml text generation failed");
1992                 return TCORE_RETURN_EINVAL;
1993         }
1994
1995         /* AT+CPOS<cr>text is entered<ctrl-z/esc> */
1996         raw_str = g_strdup_printf("AT+CPOS%s", "\r");
1997         cmd_str = g_strdup_printf("%s%s\x1A", raw_str, xml);
1998
1999         dbg("command string : %s", cmd_str);
2000         pending = tcore_pending_new(o, 0);
2001         req = tcore_at_request_new(cmd_str, NULL, TCORE_AT_NO_RESULT);
2002         if (req == NULL) {
2003                 tcore_pending_free(pending);
2004                 g_free(cmd_str);
2005                 g_free(raw_str);
2006                 return TCORE_RETURN_EINVAL;
2007         }
2008         dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
2009         tcore_pending_set_request_data(pending, strlen(cmd_str), req);
2010         tcore_pending_set_priority(pending, TCORE_PENDING_PRIORITY_DEFAULT);
2011         tcore_pending_set_send_callback(pending, on_confirmation_gps_message_send, NULL);
2012         tcore_pending_set_response_callback(pending, on_confirmation_gps_measure_position, NULL);
2013         tcore_pending_link_user_request(pending, ur);
2014
2015         /* HAL */
2016         hal = tcore_object_get_hal(o);
2017         /* Send request to HAL */
2018         ret = tcore_hal_send_request(hal, pending);
2019         if (TCORE_RETURN_SUCCESS != ret) {
2020                 err("Request send failed");
2021                 ret = FALSE;
2022         }
2023
2024         dbg("exit");
2025         g_free(raw_str);
2026         g_free(cmd_str);
2027         xmlFree(xml);
2028         return ret;
2029 }
2030
2031 static struct tcore_gps_operations gps_ops = {
2032         .confirm_measure_pos = gps_confirm_measure_pos,
2033 };
2034
2035 gboolean imc_gps_init(TcorePlugin *cp, CoreObject *co_gps)
2036 {
2037         dbg("Enter");
2038
2039         /* Set operations */
2040         tcore_gps_set_ops(co_gps, &gps_ops, TCORE_OPS_TYPE_CP);
2041
2042         tcore_object_add_callback(co_gps, "+CPOSR", on_notification_gps_assist_data, NULL);
2043         tcore_object_add_callback(co_gps, "+XCPOSR", on_notification_reset_assist_data, NULL);
2044
2045         dbg("Exit");
2046
2047         return TRUE;
2048 }
2049
2050 void imc_gps_exit(TcorePlugin *cp, CoreObject *co_gps)
2051 {
2052         dbg("Exit");
2053 }