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