• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2   @file:  loc_eng.cpp
3   @brief:
4 
5   DESCRIPTION
6     This file defines the implemenation for GPS hardware abstraction layer.
7 
8   INITIALIZATION AND SEQUENCING REQUIREMENTS
9 
10   -----------------------------------------------------------------------------
11 Copyright (c) 2009, QUALCOMM USA, INC.
12 
13 All rights reserved.
14 
15 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
16 
17 �         Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
18 
19 �         Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
20 
21 �         Neither the name of the QUALCOMM USA, INC.  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24   -----------------------------------------------------------------------------
25 
26 ******************************************************************************/
27 
28 /*=====================================================================
29 $Header: $
30 $DateTime: $
31 $Author: $
32 ======================================================================*/
33 #define LOG_NDDEBUG 0
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <ctype.h>
39 #include <errno.h>
40 #include <math.h>
41 #include <pthread.h>
42 
43 #include <rpc/rpc.h>
44 #include <loc_api_rpc_glue.h>
45 
46 #include <loc_eng.h>
47 
48 #define LOG_TAG "lib_locapi"
49 #include <utils/Log.h>
50 
51 // comment this out to enable logging
52 // #undef LOGD
53 // #define LOGD(...) {}
54 
55 #define LOC_XTRA_INJECT_DEFAULT_TIMEOUT (3100)
56 #define XTRA_BLOCK_SIZE                 (400)
57 
58 static int qct_loc_eng_xtra_init (GpsXtraCallbacks* callbacks);
59 static int qct_loc_eng_inject_xtra_data(char* data, int length);
60 
61 const GpsXtraInterface sLocEngXTRAInterface =
62 {
63     sizeof(GpsXtraInterface),
64     qct_loc_eng_xtra_init,
65     qct_loc_eng_inject_xtra_data,
66 };
67 
68 /*===========================================================================
69 FUNCTION    qct_loc_eng_xtra_init
70 
71 DESCRIPTION
72    Initialize XTRA module.
73 
74 DEPENDENCIES
75    N/A
76 
77 RETURN VALUE
78    0: success
79 
80 SIDE EFFECTS
81    N/A
82 
83 ===========================================================================*/
qct_loc_eng_xtra_init(GpsXtraCallbacks * callbacks)84 static int qct_loc_eng_xtra_init (GpsXtraCallbacks* callbacks)
85 {
86     rpc_loc_event_mask_type event;
87     loc_eng_xtra_data_s_type *xtra_module_data_ptr;
88 
89     xtra_module_data_ptr = &(loc_eng_data.xtra_module_data);
90     xtra_module_data_ptr->download_request_cb = callbacks->download_request_cb;
91 
92     return 0;
93 }
94 
95 /*===========================================================================
96 FUNCTION    qct_loc_eng_inject_xtra_data
97 
98 DESCRIPTION
99    Injects XTRA file into the engine.
100 
101 DEPENDENCIES
102    N/A
103 
104 RETURN VALUE
105    0: success
106    >0: failure
107 
108 SIDE EFFECTS
109    N/A
110 
111 ===========================================================================*/
qct_loc_eng_inject_xtra_data(char * data,int length)112 static int qct_loc_eng_inject_xtra_data(char* data, int length)
113 {
114     int     rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE;
115     boolean ret_val = 0;
116     int     total_parts;
117     uint8   part;
118     uint16  part_len;
119     uint16  len_injected;
120     rpc_loc_ioctl_data_u_type            ioctl_data;
121     rpc_loc_predicted_orbits_data_s_type *predicted_orbits_data_ptr;
122 
123     LOGV ("qct_loc_eng_inject_xtra_data, xtra size = %d, data ptr = 0x%x\n", length, (int) data);
124 
125     ioctl_data.disc = RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA;
126 
127     predicted_orbits_data_ptr = &(ioctl_data.rpc_loc_ioctl_data_u_type_u.predicted_orbits_data);
128     predicted_orbits_data_ptr->format_type = RPC_LOC_PREDICTED_ORBITS_XTRA;
129     predicted_orbits_data_ptr->total_size = length;
130     total_parts = (length / XTRA_BLOCK_SIZE);
131     if ((total_parts % XTRA_BLOCK_SIZE) != 0)
132     {
133         total_parts += 1;
134     }
135     predicted_orbits_data_ptr->total_parts = total_parts;
136 
137     len_injected = 0; // O bytes injected
138     // XTRA injection starts with part 1
139     for (part = 1; part <= total_parts; part++)
140     {
141         predicted_orbits_data_ptr->part = part;
142         predicted_orbits_data_ptr->part_len = XTRA_BLOCK_SIZE;
143         if (XTRA_BLOCK_SIZE > (length - len_injected))
144         {
145             predicted_orbits_data_ptr->part_len = length - len_injected;
146         }
147         predicted_orbits_data_ptr->data_ptr.data_ptr_len = predicted_orbits_data_ptr->part_len;
148         predicted_orbits_data_ptr->data_ptr.data_ptr_val = data + len_injected;
149 
150         LOGV ("qct_loc_eng_inject_xtra_data, inject part = %d, len = %d, len = %d\n", predicted_orbits_data_ptr->part, predicted_orbits_data_ptr->part_len, predicted_orbits_data_ptr->data_ptr.data_ptr_len);
151         LOGV ("qct_loc_eng_inject_xtra_data, total part = %d, len = %d \n", predicted_orbits_data_ptr->part, predicted_orbits_data_ptr->part_len);
152 
153         if (part < total_parts)
154         {
155             // No callback in this case
156             rpc_ret_val = loc_ioctl (loc_eng_data.client_handle,
157                                   RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA,
158                                   &ioctl_data);
159 
160             if (rpc_ret_val != RPC_LOC_API_SUCCESS)
161             {
162                 LOGE ("loc_ioctl for xtra returned %d \n", rpc_ret_val);
163                 ret_val = EINVAL; // return error
164                 break;
165             }
166         }
167         else // part == total_parts
168         {
169             // Last part injection, will need to wait for callback
170             ret_val = loc_eng_ioctl (loc_eng_data.client_handle,
171                                   RPC_LOC_IOCTL_INJECT_PREDICTED_ORBITS_DATA,
172                                   &ioctl_data,
173                                   LOC_XTRA_INJECT_DEFAULT_TIMEOUT,
174                                   NULL /* No output information is expected*/);
175             break; // done with injection
176         }
177 
178         len_injected += predicted_orbits_data_ptr->part_len;
179         LOGV ("loc_ioctl for xtra len injected %d \n", len_injected);
180     }
181 
182     return ret_val;
183 }
184