1ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. 2ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * 3ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * Redistribution and use in source and binary forms, with or without 4ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * modification, are permitted provided that the following conditions are 5ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * met: 6ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * * Redistributions of source code must retain the above copyright 7ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * notice, this list of conditions and the following disclaimer. 8ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * * Redistributions in binary form must reproduce the above 9ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * copyright notice, this list of conditions and the following 10ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * disclaimer in the documentation and/or other materials provided 11ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * with the distribution. 12ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * * Neither the name of The Linux Foundation, nor the names of its 13ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * contributors may be used to endorse or promote products derived 14ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * from this software without specific prior written permission. 15ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * 16ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * 28ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo */ 29ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 30ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <stdio.h> 31ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <stdlib.h> 32ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <linux/stat.h> 33ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <fcntl.h> 34ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <linux/types.h> 35ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <unistd.h> 36ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <errno.h> 37ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <grp.h> 38ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <sys/stat.h> 39ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 40ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include "log_util.h" 41ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include "platform_lib_includes.h" 42ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include "loc_eng_dmn_conn_glue_msg.h" 43ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include "loc_eng_dmn_conn_handler.h" 44ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include "loc_eng_dmn_conn.h" 45ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include "loc_eng_msg.h" 46ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 47ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_api_server_msgqid; 48ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_api_resp_msgqid; 49ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int quipc_msgqid; 50ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int msapm_msgqid; 51ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int msapu_msgqid; 52ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 53ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic const char * global_loc_api_q_path = GPSONE_LOC_API_Q_PATH; 54ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic const char * global_loc_api_resp_q_path = GPSONE_LOC_API_RESP_Q_PATH; 55ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic const char * global_quipc_ctrl_q_path = QUIPC_CTRL_Q_PATH; 56ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic const char * global_msapm_ctrl_q_path = MSAPM_CTRL_Q_PATH; 57ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic const char * global_msapu_ctrl_q_path = MSAPU_CTRL_Q_PATH; 58ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 59ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_api_server_proc_init(void *context) 60ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 61ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_server_msgqid = loc_eng_dmn_conn_glue_msgget(global_loc_api_q_path, O_RDWR); 62ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo //change mode/group for the global_loc_api_q_path pipe 63ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo int result = chmod (global_loc_api_q_path, 0660); 64ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (result != 0) 65ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 66ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("failed to change mode for %s, error = %s\n", global_loc_api_q_path, strerror(errno)); 67ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 68ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 69ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct group * gps_group = getgrnam("gps"); 70ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (gps_group != NULL) 71ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 72ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo result = chown (global_loc_api_q_path, -1, gps_group->gr_gid); 73ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (result != 0) 74ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 75ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("chown for pipe failed, pipe %s, gid = %d, result = %d, error = %s\n", 76ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo global_loc_api_q_path, gps_group->gr_gid, result, strerror(errno)); 77ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 78ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 79ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo else 80ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 81ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("getgrnam for gps failed, error code = %d\n", errno); 82ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 83ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 84ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_resp_msgqid = loc_eng_dmn_conn_glue_msgget(global_loc_api_resp_q_path, O_RDWR); 85ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 86ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo //change mode/group for the global_loc_api_resp_q_path pipe 87ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo result = chmod (global_loc_api_resp_q_path, 0660); 88ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (result != 0) 89ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 90ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("failed to change mode for %s, error = %s\n", global_loc_api_resp_q_path, strerror(errno)); 91ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 92ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 93ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (gps_group != NULL) 94ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 95ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo result = chown (global_loc_api_resp_q_path, -1, gps_group->gr_gid); 96ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (result != 0) 97ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo { 98ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("chown for pipe failed, pipe %s, gid = %d, result = %d, error = %s\n", 99ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo global_loc_api_resp_q_path, 100ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo gps_group->gr_gid, result, strerror(errno)); 101ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 102ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 103ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 104ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo quipc_msgqid = loc_eng_dmn_conn_glue_msgget(global_quipc_ctrl_q_path, O_RDWR); 105ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo msapm_msgqid = loc_eng_dmn_conn_glue_msgget(global_msapm_ctrl_q_path , O_RDWR); 106ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo msapu_msgqid = loc_eng_dmn_conn_glue_msgget(global_msapu_ctrl_q_path , O_RDWR); 107ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 108ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] loc_api_server_msgqid = %d\n", __func__, __LINE__, loc_api_server_msgqid); 109ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 110ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 111ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 112ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_api_server_proc_pre(void *context) 113ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 114ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 115ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 116ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 117ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_api_server_proc(void *context) 118ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 119ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo int length, sz; 120ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo int result = 0; 121ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo static int cnt = 0; 122ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct ctrl_msgbuf * p_cmsgbuf; 123ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct ctrl_msgbuf cmsg_resp; 124ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 125ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo sz = sizeof(struct ctrl_msgbuf) + 256; 126ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo p_cmsgbuf = (struct ctrl_msgbuf *) malloc(sz); 127ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 128ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (!p_cmsgbuf) { 129ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("%s:%d] Out of memory\n", __func__, __LINE__); 130ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return -1; 131ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 132ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 133ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo cnt ++; 134ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] %d listening on %s...\n", __func__, __LINE__, cnt, (char *) context); 135ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo length = loc_eng_dmn_conn_glue_msgrcv(loc_api_server_msgqid, p_cmsgbuf, sz); 136ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (length <= 0) { 137ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo free(p_cmsgbuf); 138ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("%s:%d] fail receiving msg from gpsone_daemon, retry later\n", __func__, __LINE__); 139ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo usleep(1000); 140ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 141ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 142ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 143ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] received ctrl_type = %d\n", __func__, __LINE__, p_cmsgbuf->ctrl_type); 144ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo switch(p_cmsgbuf->ctrl_type) { 145ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case GPSONE_LOC_API_IF_REQUEST: 146ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo result = loc_eng_dmn_conn_loc_api_server_if_request_handler(p_cmsgbuf, length); 147ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 148ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 149ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case GPSONE_LOC_API_IF_RELEASE: 150ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo result = loc_eng_dmn_conn_loc_api_server_if_release_handler(p_cmsgbuf, length); 151ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 152ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 153ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case GPSONE_UNBLOCK: 154ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] GPSONE_UNBLOCK\n", __func__, __LINE__); 155ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 156ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 157ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo default: 158ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("%s:%d] unsupported ctrl_type = %d\n", 159ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo __func__, __LINE__, p_cmsgbuf->ctrl_type); 160ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 161ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 162ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 163ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo free(p_cmsgbuf); 164ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 165ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 166ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 167ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_api_server_proc_post(void *context) 168ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 169ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d]\n", __func__, __LINE__); 170ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_glue_msgremove( global_loc_api_q_path, loc_api_server_msgqid); 171ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_glue_msgremove( global_loc_api_resp_q_path, loc_api_resp_msgqid); 172ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_glue_msgremove( global_quipc_ctrl_q_path, quipc_msgqid); 173ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_glue_msgremove( global_msapm_ctrl_q_path, msapm_msgqid); 174ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_glue_msgremove( global_msapu_ctrl_q_path, msapu_msgqid); 175ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 176ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 177ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 178ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic int loc_eng_dmn_conn_unblock_proc(void) 179ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 180ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct ctrl_msgbuf cmsgbuf; 181ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo cmsgbuf.ctrl_type = GPSONE_UNBLOCK; 182ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d]\n", __func__, __LINE__); 183ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_glue_msgsnd(loc_api_server_msgqid, & cmsgbuf, sizeof(cmsgbuf)); 184ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 185ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 186ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 187ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russostatic struct loc_eng_dmn_conn_thelper thelper; 188ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 189ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russoint loc_eng_dmn_conn_loc_api_server_launch(thelper_create_thread create_thread_cb, 190ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo const char * loc_api_q_path, const char * resp_q_path, void *agps_handle) 191ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 192ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo int result; 193ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 194ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_handle = agps_handle; 195ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 196ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (loc_api_q_path) global_loc_api_q_path = loc_api_q_path; 197ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (resp_q_path) global_loc_api_resp_q_path = resp_q_path; 198ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 199ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo result = loc_eng_dmn_conn_launch_thelper( &thelper, 200ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_server_proc_init, 201ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_server_proc_pre, 202ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_server_proc, 203ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_api_server_proc_post, 204ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo create_thread_cb, 205ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo (char *) global_loc_api_q_path); 206ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (result != 0) { 207ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGE("%s:%d]\n", __func__, __LINE__); 208ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return -1; 209ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 210ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 211ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 212ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 213ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russoint loc_eng_dmn_conn_loc_api_server_unblock(void) 214ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 215ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_unblock_thelper(&thelper); 216ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_unblock_proc(); 217ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 218ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 219ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 220ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russoint loc_eng_dmn_conn_loc_api_server_join(void) 221ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ 222ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo loc_eng_dmn_conn_join_thelper(&thelper); 223ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 224ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 225ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 226ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russoint loc_eng_dmn_conn_loc_api_server_data_conn(int sender_id, int status) { 227ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct ctrl_msgbuf cmsgbuf; 228ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] quipc_msgqid = %d\n", __func__, __LINE__, quipc_msgqid); 229ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo cmsgbuf.ctrl_type = GPSONE_LOC_API_RESPONSE; 230ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo cmsgbuf.cmsg.cmsg_response.result = status; 231ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo switch (sender_id) { 232ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC: { 233ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC", __func__, __LINE__); 234ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (loc_eng_dmn_conn_glue_msgsnd(quipc_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { 235ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); 236ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return -1; 237ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 238ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 239ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 240ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM: { 241ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM", __func__, __LINE__); 242ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (loc_eng_dmn_conn_glue_msgsnd(msapm_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { 243ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); 244ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return -1; 245ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 246ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 247ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 248ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU: { 249ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU", __func__, __LINE__); 250ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (loc_eng_dmn_conn_glue_msgsnd(msapu_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { 251ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); 252ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return -1; 253ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 254ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 255ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 256ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo case LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON: { 257ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON", __func__, __LINE__); 258ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo if (loc_eng_dmn_conn_glue_msgsnd(loc_api_resp_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) { 259ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__); 260ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return -1; 261ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 262ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo break; 263ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 264ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo default: { 265ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo LOC_LOGD("%s:%d] invalid sender ID!", __func__, __LINE__); 266ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 267ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo } 268ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo return 0; 269ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 270ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 271