blob: b735a255e0e0a657f00b8926f62b749c404feffd [file] [log] [blame]
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <binder/Parcel.h>
#include <log/log.h>
#include <cutils/jstring.h>
#include <pthread.h>
#include <list>
#include <vendor-ril/telephony/ril.h>
#include <vendor-ril/telephony/mtk_ril_sp.h>
#include "lynq_network.h"
#include "liblog/lynq_deflog.h"
#include "lynq_network_state_buffer.h"
#define LYNQ_SERVICE_PORT 8088
#define LYNQ_URC_SERVICE_PORT 8086
#define LYNQ_URC_ADDRESS "0.0.0.0"
#define LYNQ_ADDRESS "127.0.0.1"
#define LYNQ_REQUEST_PARAM_BUF 8192
#define LYNQ_REC_BUF 8192
#define LYNQ_RESP_BUF 128
#define LYNQ_TYPE_BUF 10
#define USER_LOG_TAG "LYNQ_NETWORK"
using ::android::Parcel;
typedef struct{
int uToken;
int request;
int paramLen;
char param[LYNQ_REQUEST_PARAM_BUF];
}lynq_client_t;
typedef struct{
int resp_type;
int token;
int request;
int slot_id;
int error;
}lynq_resp_t;
lynq_client_t client_t;
lynq_resp_t response;
int network_len_addr_serv;
int network_len_urc_addr_serv;
struct sockaddr_in network_addr_serv;
struct sockaddr_in network_urc_addr_serv;
static int network_sock_fd = 0;
int network_urc_sock_fd = 0;
int network_Global_uToken = 0;
int network_slot_id = -1;
int network_urc_slot_id = -1;
int network_urc_status = 1;
int network_wait_urc_id = 0;
signalStrength_t network_urc_solSigStren;
/**g_lynq_network_init_flag
* @brief mark network initialization state
* 0:deinit status
* 1:init state
*/
static int g_lynq_network_init_flag = 0;
static pthread_mutex_t signal_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t signal_state_change_cond = PTHREAD_COND_INITIALIZER;
/**g_lynq_network_sendto_mutex
* @brief mark network send request mutex
*/
static pthread_mutex_t g_lynq_network_sendto_mutex;
/*hq add for set waiting time 2022/09/13 begin*/
int network_rc_status = 1;
static pthread_mutex_t s_RecvMsgBlockMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t s_WaitRecvMsgCond = PTHREAD_COND_INITIALIZER;
#define BLOCK_RC_MSG_LOCK() pthread_mutex_lock(&s_RecvMsgBlockMutex)
#define BLOCK_RC_MSG_UNLOCK() pthread_mutex_unlock(&s_RecvMsgBlockMutex)
#define BLOCK_WAIT_RECV_MSG_TIME_OUT(a) pthread_cond_timedwait(&s_WaitRecvMsgCond, &s_RecvMsgBlockMutex,(a))
#define BLOCK_WAKEUP_RECV_MSG() pthread_cond_broadcast(&s_WaitRecvMsgCond)
std::list<Parcel*> g_recv_parcel_list;
const int waitResponse(int token,int time_out);
int g_inner_test=0;
/*hq add for set waiting time 2022/09/13 end*/
//static pthread_mutex_t g_lynq_network_recv_mutex;
typedef enum{
LYNQ_E_CARDSTATE_ERROR=8000,
/* The voice service state is out of service*/
LYNQ_E_STATE_OUT_OF_SERVICE=8001,
/* The voice service state is EMERGENCY_ONLY*/
LYNQ_E_STATE_EMERGENCY_ONLY=8002,
/* The radio power is power off*/
LYNQ_E_STATE_POWER_OFF=8003,
LYNQ_E_TIME_OUT=8004,
/*create or open sms DB fail */
LYNQ_E_SMS_DB_FAIL=8005,
/*Failed to execute sql statement*/
LYNQ_E_SMS_SQL_FAIL = 8006,
LYNQ_E_SMS_NOT_FIND = 8007,
/* The logic conflict*/
LYNQ_E_CONFLICT=9000,
/*Null anomaly*/
LYNQ_E_NULL_ANONALY=9001
}LYNQ_E;
/**@brief get response and write msg to parcel
* @param p [IN] <p>: the parcel
*
* @param time_out [IN] <time_out>: timeout.
* < 0:use defult timeout(5s)
* >=0:use this timeout
* @return
* 0:success
* other:failure
*/
int get_response(Parcel &p,int time_out)
{
int len = 0;
char recvline[LYNQ_REC_BUF];
bzero(recvline,LYNQ_REC_BUF);
LYINFLOG("get response");
/* receive data from server */
struct timeval timeOut;
timeOut.tv_sec = 30; //defualt 5s
timeOut.tv_usec = 0;
if(time_out >= 0)
{
LYINFLOG("use time out %d",time_out);
timeOut.tv_sec = time_out; //just set second
}
if(setsockopt(network_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
{
LYERRLOG("time out setting failed");
return -1;
}
len = recvfrom(network_sock_fd,recvline,sizeof(recvline),0,(struct sockaddr *)&network_addr_serv,(socklen_t *)&network_len_addr_serv);
if(len == -1 && errno == EAGAIN)
{
LYERRLOG("read error,maybe timeout: %s",strerror(errno));
return LYNQ_E_TIME_OUT;
}
if (recvline != NULL)
{
p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
p.setDataPosition(0);
}
return 0;
}
/**@brief wait response with expected token and write msg to parcel in some time
* @param p [IN]: pointer the parcel
* @param token [IN]: the expected token for the response msg
* @param time_out [IN]: timeout.
* @return
* 0:success
* other:failure
*/
const int waitResponse(Parcel*& p, int token,int time_out)
{
int waitToken = token;
int wakeup_token=-1;
int resp_type;
struct timeval now;
struct timespec timeout;
int ret;
std::list<Parcel*>::iterator iter;
int cnt=0;
gettimeofday(&now,NULL);
timeout.tv_sec = now.tv_sec+time_out; //timeout is 1min
timeout.tv_nsec = now.tv_usec*1000;
LYINFLOG("%s wait token is %d",__func__,waitToken);
BLOCK_RC_MSG_LOCK();
while(true) {
cnt++;
for(iter=g_recv_parcel_list.begin();iter!=g_recv_parcel_list.end();++iter)
{
(*iter)->setDataPosition(0);
(*iter)->readInt32(&resp_type);
(*iter)->readInt32(&wakeup_token);
if(wakeup_token==waitToken)
{
LYINFLOG("%s get waitToken",__func__);
p=(*iter);
p->setDataPosition(0);
g_recv_parcel_list.erase(iter);
goto waitResponse_end;
}
}
LYINFLOG("%s no wait Token in msg list, list size is %d",__func__,g_recv_parcel_list.size());
ret=BLOCK_WAIT_RECV_MSG_TIME_OUT(&timeout);
if(ret!=0)
{
LYERRLOG("%s no expected token after %d second",__func__,time_out);
break;
}
}
waitResponse_end:
LYINFLOG("%s wait token is %d wakeup_token is %d, cnt is %d",__func__,waitToken,wakeup_token,cnt);
BLOCK_RC_MSG_UNLOCK();
return wakeup_token==waitToken ? 0:LYNQ_E_TIME_OUT;
}
int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
{
LYINFLOG("jump header");
if(p.dataAvail() > 0)
{
p.readInt32(resp_type);
p.readInt32(token);
p.readInt32(request);
p.readInt32(slot_id);
p.readInt32(error);
LYINFLOG("resp_type=%d,token=%d,request=%d,slot_id=%d,error_code=%d",*resp_type,*token,*request,*slot_id,*error);
return 0;
}
else
{
return -1;
}
}
/**@brief print solicied response msg's head information
* @param head [IN]: head information
* @return none
*/
void PrintHeader(lynq_resp_t& head)
{
LYINFLOG("resp_type=%d,token=%d,request=%d,slot_id=%d,error_code=%d",head.resp_type,head.token,head.request,head.slot_id,head.error);
}
/**@brief get solicied response msg's head
* @param head [OUT]: head information
* @return
* 0:success
* other:failure
*/
int GetHeader(Parcel* &p, lynq_resp_t& head)
{
LYINFLOG("get header");
if(p->dataAvail() > 0)
{
p->readInt32(&(head.resp_type));
p->readInt32(&(head.token));
p->readInt32(&(head.request));
p->readInt32(&(head.slot_id));
p->readInt32(&(head.error));
PrintHeader(head);
return 0;
}
else
{
return -1;
}
}
/**@brief send msg to service and get response from service
* @param request_id [IN]: request id
* @param time_out [IN]: wait time uplimit
* @param p [IN]: point to response msg's parcel
* @param argc [IN]: how many parameters in parameter string
* @param format [IN]: parameter string's format
* @param ... [IN]: the specific parameter
* @return
* 0:success
* other:failure
*/
int lynq_get_common_request(int request_id, int time_out, Parcel*& p, int argc, const char* format,...)
{
lynq_client_t client;
int ret;
int send_num;
client.uToken = network_Global_uToken;
network_Global_uToken=(network_Global_uToken+1)%10000;/*0-10000*/
client.request = request_id;
client.paramLen = argc;
bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
if(argc!=0)
{
va_list args;
va_start(args, format);
vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
va_end(args);
}
LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
pthread_mutex_lock(&g_lynq_network_sendto_mutex);
if(g_inner_test==0)
{
send_num = sendto(network_sock_fd,&client,sizeof(client),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv);
}
else
{
send_num = 1;
g_inner_test = 0;
}
pthread_mutex_unlock(&g_lynq_network_sendto_mutex);
if(send_num <= 0)
{
LYERRLOG("send request fail, send num is %d", send_num);
return -1;
}
ret = waitResponse(p, client.uToken,time_out);
return ret;
}
int wait_signal_changes()
{
int ret = 0;
pthread_mutex_lock(&signal_state_change_mutex);
ret = pthread_cond_wait(&signal_state_change_cond,&signal_state_change_mutex);
pthread_mutex_unlock(&signal_state_change_mutex);
return 0;
}
void send_signal_changes()
{
pthread_mutex_lock(&signal_state_change_mutex);
pthread_cond_signal(&signal_state_change_cond);
pthread_mutex_unlock(&signal_state_change_mutex);
return;
}
/**@ a thread just for recv\buffer solicited msg's response and notice waiting thread
* @param p [IN]: no meaning
* @return
* always null
*/
void *thread_rc_recv(void *p)
{
Parcel* rc_p;
std::list<Parcel*>::iterator iter;
int resp_type = -1;
char rc_data[LYNQ_REC_BUF];
int rc_len;
int null_cnt=0;
int wakeup_token;
LYINFLOG("rc thread is running");
while(network_rc_status)
{
bzero(rc_data,LYNQ_REC_BUF);
while(true)
{
rc_len = recvfrom(network_sock_fd,rc_data,sizeof(rc_data),0,(struct sockaddr *)&network_addr_serv,(socklen_t *)&network_len_addr_serv);
if(rc_len<sizeof(int32_t)*2)
{
LYERRLOG("%s recv len %d less %d",__func__, rc_len,sizeof(int)*2);
continue;
}
rc_p= new Parcel;
if(rc_p==NULL)
{
null_cnt++;
LYERRLOG("%s rc_p is NULL, cnt is %d",__func__, null_cnt);
if(null_cnt>20)
{
goto rc_recv_end;
}
continue;
}
else
{
null_cnt=0;
}
rc_p->setData((uint8_t *)rc_data,rc_len); // p.setData((uint8_t *) buffer, buflen);
rc_p->setDataPosition(0);
if(rc_p->dataAvail()>0)
{
rc_p->readInt32(&resp_type);
rc_p->readInt32(&wakeup_token);
BLOCK_RC_MSG_LOCK();
g_recv_parcel_list.push_back(rc_p);
LYINFLOG("%s wakeup token is %d, list size is %d!",__func__,wakeup_token,g_recv_parcel_list.size());
if(g_recv_parcel_list.size()>20) //max 20
{
iter=g_recv_parcel_list.begin();
(*iter)->setDataPosition(0);
(*iter)->readInt32(&resp_type);
(*iter)->readInt32(&wakeup_token);
delete (*(g_recv_parcel_list.begin()));
LYERRLOG("%s wakeup token %d is deleted!",__func__,wakeup_token);
g_recv_parcel_list.erase(iter);
}
BLOCK_WAKEUP_RECV_MSG();
BLOCK_RC_MSG_UNLOCK();
break;
}
else
{
LYERRLOG("%s rc_p data Avail %d not greater than 0",__func__, rc_p->dataAvail());
delete rc_p;
}
}
}
rc_recv_end:
return NULL;
}
void *thread_urc_recv(void *p)
{
Parcel *urc_p =NULL;
char urc_data[LYNQ_REC_BUF];
int resp_type = -1;
int urc_id = -1;
int res = 0;
int none = 0;
int NR_sum = 0;
int urc_LTE_signalstrength = 0;
int urc_WCDMA_signalstrength = 0;
LYINFLOG("urc thread is running");
while(network_urc_status)
{
bzero(urc_data,LYNQ_REC_BUF);
res = recvfrom(network_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&network_urc_addr_serv,(socklen_t*)&network_len_urc_addr_serv);
if(res<=0)
{
LYERRLOG("thread_urc_recv step2 fail:");
break;
}
urc_p = new Parcel();
if(urc_p == NULL)
{
LYERRLOG("new parcel failure!!!");
break;
}
urc_p->setData((uint8_t *)urc_data,res); // p.setData((uint8_t *) buffer, buflen);
urc_p->setDataPosition(0);
if(urc_p->dataAvail()>0)
{
urc_p->readInt32(&resp_type);
urc_p->readInt32(&urc_id);
urc_p->readInt32(&network_urc_slot_id);
switch(urc_id)
{
case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
{
set_register_voice_buffer_valid(false);
network_wait_urc_id = urc_id;
LYINFLOG("slot_id = %d",network_urc_slot_id);
send_signal_changes();
break;
}
case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
{
set_register_data_buffer_valid(false);
network_wait_urc_id = urc_id;
LYINFLOG("slot_id = %d",network_urc_slot_id);
send_signal_changes();
break;
}
case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
{
set_register_ims_buffer_valid(false);
network_wait_urc_id = urc_id;
LYINFLOG("slot_id = %d",network_urc_slot_id);
send_signal_changes();
break;
}
case RIL_UNSOL_SIGNAL_STRENGTH:
{
urc_p->readInt32(&network_urc_solSigStren.rssi);
if((network_urc_solSigStren.rssi!=99)&&(network_urc_solSigStren.rssi!=0))
{
network_urc_solSigStren.gw_sig_valid = 1;
}else{
network_urc_solSigStren.gw_sig_valid = 0;
}
if(network_urc_solSigStren.gw_sig_valid == 1)
{
LYINFLOG("urc_GSM_signalstrength:%d",network_urc_solSigStren.rssi);
}
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&urc_LTE_signalstrength);
// p.readInt32(&solSigStren->signalStrength.LTE_SignalStrength.signalStrength);
urc_p->readInt32(&network_urc_solSigStren.rsrp);
urc_p->readInt32(&network_urc_solSigStren.rsrq);
urc_p->readInt32(&network_urc_solSigStren.rssnr);
if((urc_LTE_signalstrength!=99)&&(urc_LTE_signalstrength!=0))
{
network_urc_solSigStren.lte_sig_valid = 1;
}else{
network_urc_solSigStren.lte_sig_valid = 0;
}
if(network_urc_solSigStren.lte_sig_valid == 1)
{
LYINFLOG("urc_LTE_signalstrength:%d",urc_LTE_signalstrength);
}
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&none);
urc_p->readInt32(&urc_WCDMA_signalstrength);
urc_p->readInt32(&none);
urc_p->readInt32(&network_urc_solSigStren.rscp);
urc_p->readInt32(&network_urc_solSigStren.ecno);
if((urc_WCDMA_signalstrength!=99)&&(urc_WCDMA_signalstrength!=0))
{
network_urc_solSigStren.wcdma_sig_valid = 1;
}else{
network_urc_solSigStren.wcdma_sig_valid = 0;
}
if(network_urc_solSigStren.wcdma_sig_valid == 1)
{
LYINFLOG("urc_WCDMA_signalstrength:%d",urc_WCDMA_signalstrength);
}
urc_p->readInt32(&network_urc_solSigStren.ssRsrp);
urc_p->readInt32(&network_urc_solSigStren.ssRsrq);
urc_p->readInt32(&network_urc_solSigStren.ssSinr);
urc_p->readInt32(&network_urc_solSigStren.csiRsrp);
urc_p->readInt32(&network_urc_solSigStren.csiRsrq);
urc_p->readInt32(&network_urc_solSigStren.csiSinr);
NR_sum = (network_urc_solSigStren.ssRsrp) + (network_urc_solSigStren.ssRsrq) + (network_urc_solSigStren.ssSinr) + (network_urc_solSigStren.csiRsrp)+\
(network_urc_solSigStren.csiRsrq) + (network_urc_solSigStren.csiSinr);
if(NR_sum != 0)
{
network_urc_solSigStren.nr_sig_valid = 1;
}else{
network_urc_solSigStren.nr_sig_valid = 0;
}
if(network_urc_solSigStren.nr_sig_valid == 1)
{
LYINFLOG("[NR signal]ssRsrp is %d , ssRsrq is %d , ssSinr is %d , csiRsrp is %d , csiRsrq is %d , csiSinr is %d",\
network_urc_solSigStren.ssRsrp,network_urc_solSigStren.ssRsrq,network_urc_solSigStren.ssSinr, \
network_urc_solSigStren.csiRsrp,network_urc_solSigStren.csiRsrq,network_urc_solSigStren.csiSinr);
}
network_wait_urc_id = urc_id;
send_signal_changes();
break;
}
}
}
delete urc_p;
urc_p = NULL;
}
return NULL;
}
int lynq_server_socket_start()
{
// struct timeval timeOut;
network_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
if(-1 == network_sock_fd)
{
LYERRLOG("socket open error");
return -1;
}
# if 0
timeOut.tv_sec = 5;
timeOut.tv_usec = 0;
if (setsockopt(network_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
{
LYERRLOG("time out setting failed\n");
return -1;
}
#endif
LYINFLOG("network_sock_fd = %d",network_sock_fd);
memset(&network_addr_serv, 0, sizeof(network_addr_serv));
network_addr_serv.sin_family = AF_INET;
network_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_ADDRESS);
network_addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
network_len_addr_serv = sizeof(network_addr_serv);
BLOCK_RC_MSG_LOCK();
std::list<Parcel*>::iterator iter;
for(iter=g_recv_parcel_list.begin();iter!=g_recv_parcel_list.end();++iter)
{
delete (*iter);
}
g_recv_parcel_list.clear();
BLOCK_RC_MSG_UNLOCK();
pthread_t tid;
pthread_attr_t attr;
int ret;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ret = pthread_create(&tid,&attr,thread_rc_recv,NULL);
if(ret <0)
{
LYERRLOG("rc pthread create error");
return -1;
}
LYINFLOG("rc start success");
return 0;
}
int lynq_urc_socket_start()
{
pthread_t tid;
pthread_attr_t attr;
int on = 1;
network_urc_sock_fd = -1;
int ret = 0;
network_len_urc_addr_serv = sizeof(sockaddr_in);
network_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (network_urc_sock_fd <0){
LYERRLOG("urc socket error");
ret = -1;
}
network_urc_addr_serv.sin_family = AF_INET;
network_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);
network_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);
/* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
ret = setsockopt(network_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
if(ret <0)
{
LYERRLOG("urc socket set error");
return -1;
}
ret = bind(network_urc_sock_fd ,(struct sockaddr*)&network_urc_addr_serv, sizeof(network_urc_addr_serv));
if(ret <0)
{
LYERRLOG("urc socket bind error");
return -1;
}
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ret = pthread_create(&tid,&attr,thread_urc_recv,(void *)network_urc_sock_fd);
if(ret <0)
{
LYERRLOG("urc pthread create error");
return -1;
}
LYINFLOG("urc start success");
return 0;
}
int lynq_network_init(int utoken){
if(g_lynq_network_init_flag == 1)
{
LYERRLOG("init twice is not allowed");
return -1;
}
g_lynq_network_init_flag = 1;
if(utoken <0){
LYERRLOG("init err");
return -1;
}
network_urc_status = 1;
network_rc_status = 1;
network_Global_uToken = utoken;
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);
int ret = 0;
init_network_timer_all();
ret = lynq_server_socket_start();
if(ret !=0)
{
LYERRLOG("init socket client fail!!!");
return -1;
}
ret = lynq_urc_socket_start();
if(ret != 0)
{
LYERRLOG("init socket urc fail!!!");
return -1;
}
pthread_mutex_init(&g_lynq_network_sendto_mutex, NULL);
pthread_mutex_init(&s_RecvMsgBlockMutex, NULL);
return 0;
}
int strUpper(char * str)
{
int i=0;
while(1)
{
if(str[i]=='\0')
{
break;
}
if(str[i]>='a'&&str[i]<='z')
{
str[i]=str[i]-32;
}
i++;
}
return 0;
}
int copyCellInfoList(Parcel* &p,uint64_t *cellinfo,int *tac,int *earfcn)
{
int32_t v=0;
int64_t v6=0;
if(NULL == cellinfo)
{
LYERRLOG("*cellinfo error");
}
int nothing = 0;
int tmp_uint64 = 0;
p->readInt32(&v);
RIL_CellInfoType cellinfoType = RIL_CellInfoType(v);
p->readInt32(&nothing);
// cellinfo->cellinfo.cellInfoType = RIL_CellInfoType(v);
// p->readInt32(&cellinfo->cellinfo.registered);
p->readInt32(&v);
// cellinfo->cellinfo.timeStampType = RIL_TimeStampType(v);
p->readInt64(&v6);
// cellinfo->cellinfo.timeStamp = v6;
switch(cellinfoType) {
case RIL_CELL_INFO_TYPE_GSM: {
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&tmp_uint64);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
*cellinfo = (uint64_t)tmp_uint64;
tac = &nothing;
earfcn = &nothing;
break;
}
case RIL_CELL_INFO_TYPE_WCDMA: {
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&tmp_uint64);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
*cellinfo = (uint64_t)tmp_uint64;
tac = &nothing;
earfcn = &nothing;
break;
}
case RIL_CELL_INFO_TYPE_CDMA: {
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
cellinfo = 0;
tac = &nothing;
earfcn = &nothing;
break;
}
case RIL_CELL_INFO_TYPE_LTE: {
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&tmp_uint64);
p->readInt32(&nothing);
p->readInt32(tac);
p->readInt32(earfcn);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
*cellinfo = (uint64_t)tmp_uint64;
break;
}
case RIL_CELL_INFO_TYPE_TD_SCDMA: {
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&tmp_uint64);
p->readInt32(&nothing);
p->readInt32(&nothing);
*cellinfo = (uint64_t)tmp_uint64;
tac = &nothing;
earfcn = &nothing;
break;
}
case RIL_CELL_INFO_TYPE_NR: {
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readUint64(cellinfo);
p->readInt32(&nothing);
p->readInt32(tac);
p->readInt32(earfcn);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
p->readInt32(&nothing);
break;
}
}
LYINFLOG("CID in fUNC :%llu",*cellinfo);
LYINFLOG("tac in fUNC :%d",*tac);
LYINFLOG("earfcn in fUNC :%d",*earfcn);
return 0;
}
int lynq_network_deinit(void){
if (g_lynq_network_init_flag == 0)
{
LYERRLOG("deinit twice is not allowed");
return -1;
}
if (network_sock_fd > 0)
{
close(network_sock_fd);
}
g_lynq_network_init_flag = 0;
network_urc_status = 0;
network_rc_status = 0;
deinit_network_timer_all();
BLOCK_RC_MSG_LOCK();
std::list<Parcel*>::iterator iter;
for(iter=g_recv_parcel_list.begin();iter!=g_recv_parcel_list.end();++iter)
{
delete (*iter);
}
g_recv_parcel_list.clear();
BLOCK_RC_MSG_UNLOCK();
return 0;
}
static char * lynqStrdupReadString(Parcel* &p) {
size_t stringlen;
const char16_t *s16;
s16 = p->readString16Inplace(&stringlen);
return strndup16to8(s16, stringlen);
}
int lynq_query_operater(char *OperatorFN,char *OperatorSH,char *MccMnc)
{
int ret = -1;
if(NULL == OperatorFN||NULL == OperatorSH|| NULL == MccMnc)
{
LYERRLOG("%s some parameter OperatorFN OperatorSH MccMnc %s %s %s is NULL",__func__,OperatorFN,OperatorSH,MccMnc);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_OPERATOR,5,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num ;
char *resp[LYNQ_RESP_BUF];
p->readInt32(&num);
if(num == 0)
{
LYERRLOG("no paramters");
}else{
for(int i = 0; i<num;i++)
{
resp[i] = lynqStrdupReadString(p);
}
if(NULL != resp[0])
{
strcpy(OperatorFN,resp[0]);
}
if(NULL != resp[1])
{
strcpy(OperatorSH,resp[1]);
}
if(NULL != resp[2])
{
strcpy(MccMnc,resp[2]);
}
}
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_query_network_selection_mode(int *netselMode)
{
int ret = -1;
if(NULL == netselMode)
{
LYERRLOG("%s parameter is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE,600,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int readnum;
p->readInt32(&readnum);
p->readInt32(netselMode);
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
return ret;
}
int lynq_set_network_selection_mode(const char *mode,const char* mccmnc)
{
int ret = -1;
if(NULL == mode || (strlen(mode) == 0))
{
LYERRLOG("%s parameter mod %s is error",__func__,mode);
return -1;
}
if(!strcmp(mode,"Manual"))
{
if(mccmnc == NULL || strlen(mccmnc) == 0)
{
LYERRLOG("%s parameter mccmnc %s is error",__func__,mccmnc);
return -1;
}
}
lynq_resp_t head;
Parcel* p=NULL;
if(!strcmp(mode,"Auto"))
{
ret=lynq_get_common_request(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC,5,p,0,"");
}
else if(!strcmp(mode,"Manual"))
{
ret=lynq_get_common_request(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL,5,p,1,"%s",mccmnc);
}
else
{
LYERRLOG("%s parameter mode %s is NULL",__func__,mode);
return -1;
}
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
LYINFLOG("%s set mode %s mccmnc %s suc",__func__,mode,mccmnc);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_query_available_network(char *OperatorFN,char *OperatorSH,char *MccMnc,char * NetStatus)
{
int ret = -1;
if(NULL == OperatorFN||NULL == OperatorSH||NULL == MccMnc||NULL == NetStatus)
{
LYERRLOG("%s there is parameter is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS,600,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num =p->readInt32();
char *resp[128];
if(num == 0)
{
LYERRLOG("%s get num is 0",__func__);
delete p;
return -1;
}else{
for(int i = 0; i<num;i++)
{
resp[i] = lynqStrdupReadString(p);
}
if(NULL != resp[0])
{
strcpy(OperatorFN,resp[0]);
}
if(NULL != resp[1])
{
strcpy(OperatorSH,resp[1]);
}
if(NULL != resp[2])
{
strcpy(MccMnc,resp[2]);
}
if(NULL != resp[3])
{
strcpy(NetStatus,resp[2]);
}
}
delete p;
LYINFLOG("%s suc",__func__);
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_query_registration_state(const char *type,int* regState,int* imsRegState,char * LAC,char * CID,int *netType,int *radioTechFam,int *netRejected)
{
int ret = -1;
if(NULL == type || NULL ==regState ||NULL ==imsRegState ||NULL ==LAC ||NULL ==CID ||NULL ==netType ||NULL ==radioTechFam || NULL == netRejected)
{
LYERRLOG("%s there is parameter is NULL",__func__);
return ret;
}
if(strlen(type)>LYNQ_TYPE_BUF)
{
LYERRLOG("[%s]the parameter is inavaliable !",__FUNCTION__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
int request;
char str[LYNQ_TYPE_BUF];
memcpy(str,type,strlen(type)+1);
strUpper(str);
if(!strcmp(str,"VOICE"))
{
if(lynq_get_registration_state_to_buf_voice(regState,netType,netRejected)==0)
{
return 0;
}
request = RIL_REQUEST_VOICE_REGISTRATION_STATE;
}else if(!strcmp(str,"DATA")){
if(lynq_get_registration_state_to_buf_data(regState,LAC,CID,netType)==0)
{
return 0;
}
request = RIL_REQUEST_DATA_REGISTRATION_STATE;
}else if(!strcmp(str,"IMS")){
if(lynq_get_registration_state_to_buf_ims(imsRegState,radioTechFam)==0)
{
return 0;
}
request = RIL_REQUEST_IMS_REGISTRATION_STATE;
}else{
LYERRLOG("request error");
return ret;
}
ret=lynq_get_common_request(request,5,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num;
if(!strcmp(str,"VOICE"))
{
p->readInt32(&num);
if(num == 15)
{
*regState = atoi(lynqStrdupReadString(p));
lynqStrdupReadString(p);
lynqStrdupReadString(p);
*netType = atoi(lynqStrdupReadString(p));
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
lynqStrdupReadString(p);
*netRejected = atoi(lynqStrdupReadString(p));
lynq_set_registration_state_to_buf_voice(*regState,*netType,*netRejected);
}
else
{
LYERRLOG("%s type %s num %d error",__func__,str,num);
delete p;
return -1;
}
}
else if(!strcmp(str,"DATA")){
p->readInt32(&num);
if(num == 11)
{
char *resp[LYNQ_RESP_BUF];
*regState = atoi(lynqStrdupReadString(p));
resp[0] = lynqStrdupReadString(p);
strcpy(LAC,resp[0]);
resp[1] = lynqStrdupReadString(p);
strcpy(CID,resp[1]);
*netType = atoi(lynqStrdupReadString(p));
lynq_set_registration_state_to_buf_data(*regState,LAC,CID,*netType);
}
else
{
LYERRLOG("%s type %s num %d error",__func__,str,num);
delete p;
return -1;
}
}
else // "IMS"
{
p->readInt32(&num);
if(num == 2)
{
p->readInt32(imsRegState);
p->readInt32(radioTechFam);
lynq_set_registration_state_to_buf_ims(*imsRegState,*radioTechFam);
}
else
{
LYERRLOG("%s type %s num %d error",__func__,str,num);
delete p;
return -1;
}
}
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_query_prefferred_networktype(int *preNetType)
{
int ret = -1;
if(NULL == preNetType)
{
LYERRLOG("%s there is parameter is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE,5,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num;
p->readInt32(&num);
p->readInt32(preNetType);
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_set_prefferred_networktype(const int preffertype)
{
int ret = -1;
if(preffertype < 0||preffertype >33)
{
LYERRLOG("%s parameter %d error",__func__,preffertype);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE,5,p,1,"%d",preffertype);
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
LYINFLOG("%s set %d suc",__func__,preffertype);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_query_cell_info(uint64_t cellinfo[CELLINFO_MAX_NUM],int tac[CELLINFO_MAX_NUM],int earfcn[CELLINFO_MAX_NUM],int * realNum)
{
int ret = -1;
if(NULL == realNum)
{
LYERRLOG("%s there is parameter is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_GET_CELL_INFO_LIST,5,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num;
p->readInt32(&num);
LYINFLOG("cell info num:%d",num);
*realNum = num;
for(int i = 0;i<num;i++)
{
copyCellInfoList(p,&cellinfo[i],&tac[i],&earfcn[i]);
}
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_set_unsol_cell_info_listrate(const int rate)
{
int ret = -1;
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE,5,p,1,"%d",rate);
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
LYINFLOG("%s set %d suc",__func__,rate);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_set_band_mode(const int bandmode)
{
int ret = -1;
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_SET_BAND_MODE,5,p,1,"%d",bandmode);
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
LYINFLOG("%s set %d suc",__func__,bandmode);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
int lynq_query_available_bandmode(int availBanMode[])
{
int ret=-1;
if(NULL == availBanMode)
{
LYERRLOG("%s parameter is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE,5,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num = 0;
int res = 0;
int i;
p->readInt32(&num);
LYINFLOG("num = %d",num);
availBanMode[0] = num;
for(i=1 ;i<=num;i++)
{
p->readInt32(&res);
availBanMode[i]=res;
}
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
LYERRLOG("%s send request error %d",__func__,ret);
return ret;
}
int lynq_radio_on(const int data)
{
int ret = -1;
if (data < 0 || data > 1)
{
LYERRLOG("%s parameter %d error",__func__,data);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_RADIO_POWER,65,p,1,"%d",data);
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
LYINFLOG("%s set %d suc",__func__,data);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
const char * lynq_get_raw_data(Parcel* &p, int* data_len)
{
int32_t len;
int status;
char *data;
*data_len=0;
status = p->readInt32(&len);
if (status != 0) {
LYERRLOG("%s status is %d",__func__,status);
return NULL;
}
// The java code writes -1 for null arrays
if (((int)len) == -1 || ((int)len) == 0)
{
LYERRLOG("%s len is %d",__func__,len);
return NULL;
}
LYINFLOG("%s len is %d",__func__,len);
data = (char*) p->readInplace(len);
*data_len=len;
return data;
}
int lynq_query_radio_state(int *radio_state)
{
int ret=-1;
if(NULL == radio_state)
{
LYERRLOG("%s radio state is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_OEM_HOOK_RAW,5,p,1,"%s","AT+CFUN");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int bfind=false;
const char* data;
int data_len;
char* data_str;
char* start;
int length;
int i;
int num_start;
data = lynq_get_raw_data(p,&data_len);
if(data==NULL || data_len == 0)
{
LYERRLOG("%s lynq_get_raw_data NULL or data_len is 0",__func__);
delete p;
return -1;
}
data_str = (char*) calloc(1,data_len+1);
if (NULL == data_str)
{
LYERRLOG("%s alloc mem error, data_len is %d",__func__,data_len+1);
delete p;
return -1;
}
memmove(data_str, data, data_len);
data_str[data_len]='\0';
LYINFLOG("%s return string is %s",__func__,data_str);
start = strstr(data_str,"CFUN");
if(start!=NULL)
{
start=start+4;
length=strlen(start);
for(i=0; i<length;i++)
{
if((!bfind) && (start[i] >= '0') && (start[i] <= '9'))
{
bfind=true;
num_start=i;
}
else if(bfind && ((start[i] < '0') || (start[i] > '9')))
{
start[i]='\0';
break;
}
}
if(bfind)
{
(*radio_state) = atoi(start+num_start);
LYINFLOG("%s, radio state is %s %d",__func__,start+num_start,*radio_state);
free(data_str);
delete p;
return 0;
}
}
LYERRLOG("%s return string %s no cfun or no digit",__func__,data_str);
free(data_str);
delete p;
return -1;
}
LYERRLOG("%s send request error %d",__func__,ret);
return ret;
}
int lynq_query_radio_tech(int* radioTech)
{
int ret = -1;
if(NULL == radioTech)
{
LYERRLOG("%s radio tech is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_VOICE_RADIO_TECH,5,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int num;
p->readInt32(&num);
p->readInt32(radioTech);
LYINFLOG("%s suc",__func__);
delete p;
return head.error;
}
return ret;
}
int lynq_solicited_signal_strength(signalStrength_t *solSigStren)
{
int ret=-1;
if(NULL == solSigStren)
{
LYERRLOG("%s parameter is NULL",__func__);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_SIGNAL_STRENGTH,8,p,0,"");
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int sum = 0;
int LTE_signalstrength = 0;
int WCDMA_signalstrength = 0;
int none = 0;
p->readInt32(&solSigStren->rssi);
if((solSigStren->rssi!=99)&&(solSigStren->rssi!=0))
{
solSigStren->gw_sig_valid = 1;
}else{
solSigStren->gw_sig_valid = 0;
}
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&LTE_signalstrength);
// p->readInt32(&solSigStren->signalStrength.LTE_SignalStrength.signalStrength);
p->readInt32(&solSigStren->rsrp);
p->readInt32(&solSigStren->rsrq);
p->readInt32(&solSigStren->rssnr);
LYINFLOG("LTE_signalstrength:%d",LTE_signalstrength);
if((LTE_signalstrength!=99)&&(LTE_signalstrength!=0))
{
solSigStren->lte_sig_valid = 1;
}else{
solSigStren->lte_sig_valid = 0;
}
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&none);
p->readInt32(&WCDMA_signalstrength);
p->readInt32(&none);
p->readInt32(&solSigStren->rscp);
p->readInt32(&solSigStren->ecno);
LYINFLOG("WCDMA_signalstrength:%d",WCDMA_signalstrength);
if((WCDMA_signalstrength!=99)&&(WCDMA_signalstrength!=0))
{
solSigStren->wcdma_sig_valid = 1;
}else{
solSigStren->wcdma_sig_valid = 0;
}
/*bug fix*/
p->readInt32(&solSigStren->ssRsrp);
p->readInt32(&solSigStren->ssRsrq);
p->readInt32(&solSigStren->ssSinr);
p->readInt32(&solSigStren->csiRsrp);
p->readInt32(&solSigStren->csiRsrq);
p->readInt32(&solSigStren->csiSinr);
sum = (solSigStren->ssRsrp) + (solSigStren->ssRsrq) + (solSigStren->ssSinr) + (solSigStren->csiRsrp)+\
(solSigStren->csiRsrq) + (solSigStren->csiSinr);
if(sum != 0)
{
solSigStren->nr_sig_valid = 1;
}else{
LYERRLOG("None of NR signal info");
}
LYINFLOG("%s suc",__func__);
delete p;
return 0;
}
LYERRLOG("%s send request error %d",__func__,ret);
return ret;
}
int lynq_set_ims(const int ims_mode)
{
if(ims_mode == -1000)
{
g_inner_test = 1;
return 0;
}
int ret = -1;
if (ims_mode < 0 || ims_mode > 1)
{
LYERRLOG("%s parameter %d error",__func__,ims_mode);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_SET_IMS_ENABLE,65,p,1,"%d",ims_mode);
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error %d",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
LYINFLOG("%s set %d suc",__func__,ims_mode);
delete p;
return 0;
}
LYERRLOG("%s get response from modem failure, ret is %d",__func__,ret);
return ret;
}
/*Used to wait for an update signal*/
int lynq_wait_signalchanges(int *handle)
{
LYDBGLOG("start wait signalchanges info");
if(NULL == handle)
{
LYERRLOG("illegal input");
return -1;
}
wait_signal_changes();
LYDBGLOG("get signalchanges");
*handle = network_wait_urc_id;
return 0;
}
/*Used to get urc info*/
int lynq_get_urc_info(const int handle,signalStrength_t *solSigStren,int *slot_id)
{
LYDBGLOG("start get urc info");
if(handle != 1002&&handle != 1009)
{
LYINFLOG("invalid handle!!!");
return -1;
}
if(NULL == solSigStren && NULL == slot_id)
{
LYINFLOG("incoming solSigStren or slot_id is NULL!!!");
return -1;
}
switch(handle)
{
case 1002: //RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED
{
LYDBGLOG("get state update to VOICE");
*slot_id = network_urc_slot_id;
LYINFLOG("slot_id = %d",network_urc_slot_id);
break;
}
case 1009: //RIL_UNSOL_SIGNAL_STRENGTH
{
LYDBGLOG("get state update to signal info");
solSigStren->gw_sig_valid = network_urc_solSigStren.gw_sig_valid;
solSigStren->rssi = network_urc_solSigStren.rssi;
solSigStren->wcdma_sig_valid = network_urc_solSigStren.wcdma_sig_valid;
solSigStren->rscp = network_urc_solSigStren.rscp;
solSigStren->ecno = network_urc_solSigStren.ecno;
solSigStren->lte_sig_valid = network_urc_solSigStren.lte_sig_valid;
solSigStren->rsrp = network_urc_solSigStren.rsrp;
solSigStren->rsrq = network_urc_solSigStren.rsrq;
solSigStren->rssnr = network_urc_solSigStren.rssnr;
solSigStren->nr_sig_valid = network_urc_solSigStren.nr_sig_valid;
solSigStren->ssRsrp = network_urc_solSigStren.ssRsrp;
solSigStren->ssRsrq = network_urc_solSigStren.ssRsrq;
solSigStren->ssSinr = network_urc_solSigStren.ssSinr;
solSigStren->csiRsrp = network_urc_solSigStren.csiRsrp;
solSigStren->csiRsrq = network_urc_solSigStren.csiRsrq;
solSigStren->csiSinr = network_urc_solSigStren.csiSinr;
break;
}
}
return 0;
}
/**@brief parse at response,return error code,and the response
* @param response [IN] <response>:original at response,This parameter must be a character array.
* @param value [OUT] <value>: Used to receive the parsed value, if multiple values are separated by ";".
* field:
* eg:
* "+cnum: 123456\n+cnum: 456"
* value:12345;456;
* @param value_len [IN] <value_len>: The value length.
* @return:AT error code
*/
static int parse_at_result(char response[],char value[],int value_len)
{
if(response == NULL || value == NULL)
{
LYERRLOG("parameter invalid");
return -1;
}
if(strstr(response,"ERROR"))
{
int i;
for(i = 0;i < strlen(response);i++)
{
if(response[i]==':')
{
break;
}
}
if(i < strlen(response))
{
LYINFLOG("parse_result:%d\n",atoi(response+i+1));
return atoi(response+i+1);
}
else
{
LYINFLOG("%s parse_result:fail,this response invalid\n",response);
return 100; //unknown
}
}
else if(strstr(response,"OK"))
{
/** parse the at response value
* eg:
* --> at+cnum
* <-- +CNUM:"1243452"
* need parse the "1243452" to <value>
*@ To-Do
*/
int count;
int resp_addr[32] = {0};
char temp_buf[1024] = {0};
char *dest;
dest = NULL;
count = 0;
int res_len = strlen(response);
LYINFLOG("res_len:%d",res_len);
for(int i = 0; i < res_len; i++)
{
if(response[i]==':')
{
resp_addr[count] = i;
count++;
}
if(response[i] == '\n')
{
response[i] = '\0';
}
}
LYINFLOG("count:%d",count);
if(count > 0)
{
for(int i = 0; i < count; i++)
{
if((strlen(temp_buf) + strlen(response+resp_addr[i]+2)) >= 1023)
{
LYINFLOG("2 will be out of range\n");
break;
}
if(strlen(temp_buf) >= 1023)
{
LYINFLOG("1 will be out of range\n");
break;
}
strcat(temp_buf,response+resp_addr[i]+2);
if(strlen(temp_buf) >= 1023)
{
LYINFLOG("1 will be out of range\n");
break;
}
strcat(temp_buf,";");
printf("parse_result[%d]:%s,strcated:%s\n",i,response+resp_addr[i]+2,temp_buf);
}
LYINFLOG("parse_result:%s\n",temp_buf);
if(strlen(temp_buf) > value_len)
{
printf("result length over value:%ld,%d\n",strlen(temp_buf),value_len);
memcpy(value,temp_buf,value_len);
}
else
{
memcpy(value,temp_buf,strlen(temp_buf));
}
}
return 0;
}
else
{
LYINFLOG("%s this response invalid\n",response);
return -1;
}
}
#ifdef MODEM_GEN97
int lynq_oos_recover_timer_interval(int mode, char interval[LY_RECOVER_TIMER_INTERVAL],char result[LY_RECOVER_TIMER_INTERVAL])
{
int ret=-1;
if((mode < 0) || (mode >1) || (mode == 0 && NULL == interval) || (NULL == result))
{
LYERRLOG("%s mode %d interval %s result %s error",__func__,mode,interval,result);
return -1;
}
lynq_resp_t head;
Parcel* p=NULL;
if(mode == 0)
{
ret=lynq_get_common_request(RIL_REQUEST_OEM_HOOK_RAW,5,p,1,"AT+ERSCFG=%s",interval);
}
else
{
ret=lynq_get_common_request(RIL_REQUEST_OEM_HOOK_RAW,5,p,1,"AT+ERSCFG?");
}
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int recv_len;
char res_data[LY_RECOVER_TIMER_INTERVAL] = {0};
char response_interval[LY_RECOVER_TIMER_INTERVAL*2] = {0};
LYINFLOG("get recover timer interval");
p->readInt32(&recv_len);
if(recv_len == -1)
{
LYINFLOG("no responset");
delete p;
return -1;
}
else
{
LYINFLOG("recv_len:%d",recv_len);
p->read(response_interval,recv_len);
}
LYINFLOG("response_interval:%s",response_interval);
ret = parse_at_result(response_interval,res_data,LY_RECOVER_TIMER_INTERVAL);
if(mode == 1)
{
if(strlen(res_data) <= LY_RECOVER_TIMER_INTERVAL)
{
memcpy(result,res_data,strlen(res_data));
}
}
LYERRLOG("%s ret:%d",__func__,ret);
delete p;
return ret;
}
LYERRLOG("%s send request error %d",__func__,ret);
return ret;
}
int lynq_oos_deep_sleep_recover_timer_interval(int recovery_threshold,int fullband_timer,int sniffer_timer,int inactive_mode)
{
int ret=-1;
if(((recovery_threshold < 2) || (recovery_threshold > 10)) || ((fullband_timer < 90) || (fullband_timer > 360)) ||
((sniffer_timer < 10) || (sniffer_timer > 60)) || ((inactive_mode < 0) || (inactive_mode > 1)))
{
LYERRLOG("%s paramter recovery_threshold %d fullband_timer %d sniffer_timer %d inactive_mode %d fail!",recovery_threshold,fullband_timer,sniffer_timer,inactive_mode);
return ret;
}
lynq_resp_t head;
Parcel* p=NULL;
ret=lynq_get_common_request(RIL_REQUEST_OEM_HOOK_RAW,5,p,1,"AT+ESRVREC=%d,%d,%d,%d",recovery_threshold,fullband_timer,sniffer_timer,inactive_mode);
if(ret==0)
{
if(p==NULL)
{
LYERRLOG("%s get p error",__func__);
return -1;
}
ret=GetHeader(p,head);
if(ret!=0)
{
LYERRLOG("%s get head error",__func__,ret);
delete p;
return -1;
}
if(head.error!=0)
{
LYERRLOG("%s mdm return head error %d",__func__,head.error);
delete p;
return head.error;
}
int recv_len;
char res_data[LY_RECOVER_TIMER_INTERVAL] = {0};
char response_interval[LY_RECOVER_TIMER_INTERVAL*2] = {0};
p->readInt32(&recv_len);
if(recv_len == -1)
{
LYINFLOG("no responset");
delete p;
return -1;
}
else
{
LYINFLOG("recv_len:%d",recv_len);
p->read(response_interval,recv_len);
}
LYINFLOG("response_interval:%s",response_interval);
ret = parse_at_result(response_interval,res_data,LY_RECOVER_TIMER_INTERVAL);
LYERRLOG("%s ret:%d",__func__,ret);
delete p;
return ret;
}
LYERRLOG("%s send request error %d",__func__,ret);
return ret;
}
#endif