#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 <vendor-ril/telephony/ril.h> | |
#include <vendor-ril/telephony/mtk_ril_sp.h> | |
#include "lynq_network.h" | |
#include "liblog/lynq_deflog.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 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; | |
//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; | |
} | |
int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error) | |
{ | |
LYINFLOG("jump header"); | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(resp_type); | |
p.readInt32(request); | |
p.readInt32(slot_id); | |
p.readInt32(error); | |
return 0; | |
} | |
else | |
{ | |
return -1; | |
} | |
} | |
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; | |
} | |
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(); | |
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 1002: //RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED | |
{ | |
network_wait_urc_id = urc_id; | |
LYINFLOG("slot_id = %d",network_urc_slot_id); | |
send_signal_changes(); | |
break; | |
} | |
case 1009: //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; | |
} | |
} | |
} | |
} | |
} | |
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; | |
} | |
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; | |
} | |
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); | |
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_Global_uToken = utoken; | |
LYLOGSET(LOG_INFO); | |
LYLOGEINIT(USER_LOG_TAG); | |
int ret = 0; | |
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); | |
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(¬hing); | |
// 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(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(&tmp_uint64); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
*cellinfo = (uint64_t)tmp_uint64; | |
tac = ¬hing; | |
earfcn = ¬hing; | |
break; | |
} | |
case RIL_CELL_INFO_TYPE_WCDMA: { | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(&tmp_uint64); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
*cellinfo = (uint64_t)tmp_uint64; | |
tac = ¬hing; | |
earfcn = ¬hing; | |
break; | |
} | |
case RIL_CELL_INFO_TYPE_CDMA: { | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
cellinfo = 0; | |
tac = ¬hing; | |
earfcn = ¬hing; | |
break; | |
} | |
case RIL_CELL_INFO_TYPE_LTE: { | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(&tmp_uint64); | |
p.readInt32(¬hing); | |
p.readInt32(tac); | |
p.readInt32(earfcn); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
*cellinfo = (uint64_t)tmp_uint64; | |
break; | |
} | |
case RIL_CELL_INFO_TYPE_TD_SCDMA: { | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(&tmp_uint64); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
*cellinfo = (uint64_t)tmp_uint64; | |
tac = ¬hing; | |
earfcn = ¬hing; | |
break; | |
} | |
case RIL_CELL_INFO_TYPE_NR: { | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readUint64(cellinfo); | |
p.readInt32(¬hing); | |
p.readInt32(tac); | |
p.readInt32(earfcn); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
p.readInt32(¬hing); | |
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; | |
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) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int num = 0; | |
lynq_client_t client_t; | |
char *resp[LYNQ_RESP_BUF]; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_OPERATOR; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
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]); | |
} | |
} | |
} | |
return response.error; | |
} | |
int lynq_query_network_selection_mode(int *netselMode) | |
{ | |
int ret = -1; | |
if(NULL == netselMode) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int readnum = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return -1; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,600); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
p.readInt32(&readnum); | |
p.readInt32(netselMode); | |
} | |
return response.error; | |
} | |
int lynq_set_network_selection_mode(const char *mode,const char* mccmnc) | |
{ | |
int ret = -1; | |
if(NULL == mode) | |
return ret; | |
if(strlen(mode) == 0) | |
{ | |
return ret; | |
} | |
int send_num = 0; | |
lynq_client_t client_t; | |
int recv_num = 0; | |
memset(&client_t,0,sizeof(client_t)); | |
if(!strcmp(mode,"Auto")) | |
{ | |
client_t.request = RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
}else if(!strcmp(mode,"Manual")){ | |
if(mccmnc == NULL) | |
{ | |
LYERRLOG("mccmnc is NULL!!!"); | |
return ret; | |
} | |
if(strlen(mccmnc) == 0) | |
{ | |
LYERRLOG("mccmnc strlen is 0!!!"); | |
return ret; | |
} | |
client_t.request = RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL; | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"%s",mccmnc); | |
}else{ | |
LYERRLOG("request error"); | |
return ret; | |
} | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
} | |
return response.error; | |
} | |
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) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
char *resp[128]; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_QUERY_AVAILABLE_NETWORKS; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,600); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
int num =p.readInt32(); | |
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]); | |
} | |
if(NULL != resp[3]) | |
{ | |
strcpy(NetStatus,resp[2]); | |
} | |
} | |
} | |
return response.error; | |
} | |
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) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int num = 0; | |
char str[LYNQ_TYPE_BUF]; | |
char *resp[LYNQ_RESP_BUF]; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
if(strlen(type)>LYNQ_TYPE_BUF) | |
{ | |
LYERRLOG("[%s]the parameter is inavaliable !",__FUNCTION__); | |
} | |
memcpy(str,type,strlen(type)+1); | |
strUpper(str); | |
if(!strcmp(str,"VOICE")) | |
{ | |
client_t.request = RIL_REQUEST_VOICE_REGISTRATION_STATE; | |
}else if(!strcmp(str,"DATA")){ | |
client_t.request = RIL_REQUEST_DATA_REGISTRATION_STATE; | |
}else if(!strcmp(str,"IMS")){ | |
client_t.request = RIL_REQUEST_IMS_REGISTRATION_STATE; | |
}else{ | |
LYERRLOG("request error"); | |
return ret; | |
} | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
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)); | |
} | |
}else if(!strcmp(str,"DATA")){ | |
p.readInt32(&num); | |
if(num == 11) | |
{ | |
*regState = atoi(lynqStrdupReadString(p)); | |
resp[0] = lynqStrdupReadString(p); | |
strcpy(LAC,resp[0]); | |
resp[1] = lynqStrdupReadString(p); | |
strcpy(CID,resp[1]); | |
*netType = atoi(lynqStrdupReadString(p)); | |
} | |
}else if(!strcmp(str,"IMS")){ | |
p.readInt32(&num); | |
if(num == 2) | |
{ | |
p.readInt32(imsRegState); | |
p.readInt32(radioTechFam); | |
} | |
}else{ | |
LYERRLOG("request error"); | |
return ret; | |
} | |
} | |
return response.error; | |
} | |
int lynq_query_prefferred_networktype(int *preNetType) | |
{ | |
int ret = -1; | |
int send_num = 0; | |
int recv_num = 0; | |
int num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
p.readInt32(&num); | |
p.readInt32(preNetType); | |
} | |
return response.error; | |
} | |
int lynq_set_prefferred_networktype(const int preffertype) | |
{ | |
int ret = -1; | |
if(preffertype < 0||preffertype >33) | |
return ret; | |
int send_num = 0; | |
lynq_client_t client_t; | |
int recv_num = 0; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE; | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"%d",preffertype); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
} | |
return response.error; | |
} | |
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) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_GET_CELL_INFO_LIST; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
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]); | |
} | |
} | |
return response.error; | |
} | |
int lynq_set_unsol_cell_info_listrate(const int rate) | |
{ | |
int ret = -1; | |
int send_num = 0; | |
int recv_num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE; | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"%d",rate); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
} | |
return response.error; | |
} | |
int lynq_set_band_mode(const int bandmode) | |
{ | |
int ret = -1; | |
int send_num = 0; | |
int recv_num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_SET_BAND_MODE; | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"%d",bandmode); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
} | |
return response.error; | |
} | |
int lynq_query_available_bandmode(int availBanMode[]) | |
{ | |
int ret = -1; | |
if(NULL == availBanMode) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int num = 0; | |
int res = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
for(int i = 0;i<10;i++) | |
{ | |
availBanMode[i]=0; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
p.readInt32(&num); | |
LYINFLOG("num = %d",num); | |
availBanMode[0] = num; | |
for(int i=1 ;i<=num;i++) | |
{ | |
p.readInt32(&res); | |
availBanMode[i]=res; | |
} | |
} | |
return response.error; | |
} | |
int lynq_radio_on(const int data) | |
{ | |
int ret = -1; | |
if(data < 0) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_RADIO_POWER; | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"%d",data); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
} | |
return response.error; | |
} | |
int lynq_query_radio_tech(int* radioTech) | |
{ | |
int ret = -1; | |
if(NULL == radioTech) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_VOICE_RADIO_TECH; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
p.readInt32(&num); | |
p.readInt32(radioTech); | |
} | |
return response.error; | |
} | |
int lynq_solicited_signal_strength(signalStrength_t *solSigStren) | |
{ | |
int ret = -1; | |
if(NULL == solSigStren) | |
return ret; | |
int send_num = 0; | |
int recv_num = 0; | |
int sum = 0; | |
int LTE_signalstrength = 0; | |
int WCDMA_signalstrength = 0; | |
int none = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_SIGNAL_STRENGTH; | |
client_t.paramLen = 0; | |
client_t.uToken = network_Global_uToken; | |
memset(client_t.param,0,sizeof(client_t.param)); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
//get data | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
if(response.error != 0) | |
{ | |
LYERRLOG("response return error"); | |
return response.error; | |
} | |
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(<E_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"); | |
} | |
} | |
return response.error; | |
} | |
int lynq_set_ims(const int ims_mode) | |
{ | |
int ret = -1; | |
if (ims_mode < 0 || ims_mode > 1) | |
{ | |
LYERRLOG("incoming ims_mode error"); | |
return ret; | |
} | |
int send_num = 0; | |
int recv_num = 0; | |
lynq_client_t client_t; | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_SET_IMS_ENABLE; | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"%d",ims_mode); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if (send_num<0) | |
{ | |
LYERRLOG("sendto error:"); | |
return ret; | |
} | |
Parcel p; | |
ret = get_response(p,30); | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
if (ret != 0) | |
{ | |
return ret; | |
} | |
if (p.dataAvail() > 0) | |
{ | |
p.readInt32(&response.resp_type); | |
p.readInt32(&response.request); | |
p.readInt32(&response.slot_id); | |
p.readInt32(&response.error); | |
} | |
return response.error; | |
} | |
/*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; | |
int send_num; | |
int recv_len; | |
Parcel p; | |
char res_data[LY_RECOVER_TIMER_INTERVAL] = {0}; | |
lynq_client_t client_t; | |
char response_interval[LY_RECOVER_TIMER_INTERVAL*2] = {0}; | |
ret = -1; | |
send_num = -1; | |
recv_len = -1; | |
LYINFLOG("lynq_oos_recover_timer_interval start"); | |
if((mode < 0) || (mode >1) || (NULL == interval) || (NULL == result)) | |
{ | |
LYERRLOG("lynq_oos_recover_timer_interval paramter fail!!!"); | |
return ret; | |
} | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_OEM_HOOK_RAW; //LYNQ_REQUEST_OOS_RECOVER_TIMER_INTERVAL | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
if(mode == 0) | |
{ | |
sprintf(client_t.param,"AT+ERSCFG=%s",interval); | |
} | |
else | |
{ | |
sprintf(client_t.param,"AT+ERSCFG?",interval); | |
} | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num < 0) | |
{ | |
LYERRLOG("sendto error:%s",strerror(errno)); | |
return ret; | |
} | |
ret = get_response(p,-1); //use defualt time (5s) | |
if(ret != 0) | |
{ | |
return ret; | |
} | |
JumpHeader(p, &response.resp_type, &response.request, &response.slot_id, &response.error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",response.resp_type, response.request, response.slot_id, response.error); | |
if(0 == response.error) | |
{ | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
LYINFLOG("get recover timer interval"); | |
p.readInt32(&recv_len); | |
if(recv_len == -1) | |
{ | |
LYINFLOG("no responset"); | |
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)); | |
} | |
} | |
LYINFLOG("ret:%d",ret); | |
return ret; | |
} | |
else | |
{ | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
return response.error; | |
} | |
} | |
int lynq_oos_deep_sleep_recover_timer_interval(int recovery_threshold,int fullband_timer,int sniffer_timer,int inactive_mode) | |
{ | |
int ret; | |
int send_num; | |
int recv_len; | |
Parcel p; | |
char res_data[LY_RECOVER_TIMER_INTERVAL] = {0}; | |
lynq_client_t client_t; | |
char response_interval[LY_RECOVER_TIMER_INTERVAL*2] = {0}; | |
ret = -1; | |
send_num = -1; | |
recv_len = -1; | |
LYINFLOG("lynq_oos_deep_sleep_recover_timer_interval start"); | |
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("lynq_oos_deep_sleep_recover_timer_interval paramter fail!!!"); | |
return ret; | |
} | |
memset(&client_t,0,sizeof(client_t)); | |
client_t.request = RIL_REQUEST_OEM_HOOK_RAW; //LYNQ_REQUEST_OOS_DEEP_SLEEP_RECOVER_TIMER_INTERVAL | |
client_t.paramLen = 1; | |
client_t.uToken = network_Global_uToken; | |
sprintf(client_t.param,"AT+ESRVREC=%d,%d,%d,%d",recovery_threshold,fullband_timer,sniffer_timer,inactive_mode); | |
pthread_mutex_lock(&g_lynq_network_sendto_mutex); | |
send_num = sendto(network_sock_fd,&client_t,sizeof(client_t),0,(struct sockaddr *)&network_addr_serv,network_len_addr_serv); | |
if(send_num<0) | |
{ | |
LYERRLOG("sendto error:%s",strerror(errno)); | |
return ret; | |
} | |
ret = get_response(p,-1); //use defualt time (5s) | |
if(ret != 0) | |
{ | |
return ret; | |
} | |
JumpHeader(p, &response.resp_type, &response.request, &response.slot_id, &response.error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",response.resp_type, response.request, response.slot_id, response.error); | |
if(0 == response.error) | |
{ | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
LYINFLOG("set deep sleep recover timer interval response"); | |
p.readInt32(&recv_len); | |
if(recv_len == -1) | |
{ | |
LYINFLOG("no responset"); | |
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); | |
return ret; | |
} | |
else | |
{ | |
pthread_mutex_unlock(&g_lynq_network_sendto_mutex); | |
return response.error; | |
} | |
} | |
#endif | |