lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <sys/socket.h> |
| 4 | #include <arpa/inet.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <string.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <unistd.h> |
| 9 | #include <binder/Parcel.h> |
| 10 | #include <log/log.h> |
| 11 | #include "lynq_data.h" |
| 12 | #include <cutils/jstring.h> |
| 13 | #include <pthread.h> |
| 14 | #include "liblog/lynq_deflog.h" |
| 15 | #include <sys/time.h> |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 16 | #include <include/lynq_uci.h> |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 17 | #include <errno.h> |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 18 | #include <vector> |
| 19 | #include "lynq_data_urc.h" |
| 20 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 21 | #define LYNQ_SERVICE_PORT 8088 |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 22 | #define LYNQ_REC_BUF 8192 |
| 23 | #define LYNQ_REQUEST_PARAM_BUF 8192 |
| 24 | #define LYQN_SEDN_BUF 1024*8+sizeof(int)*3 |
| 25 | #define USER_LOG_TAG "LYNQ_DATA" |
| 26 | |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 27 | #define LYNQ_DATA_UCI_BUF 258 |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 28 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 29 | using ::android::Parcel; |
| 30 | typedef struct{ |
| 31 | int uToken; |
| 32 | int request; |
| 33 | int paramLen; |
| 34 | char param[LYNQ_REQUEST_PARAM_BUF]; |
| 35 | }lynq_client_t; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 36 | typedef enum{ |
| 37 | LYNQ_E_CARDSTATE_ERROR=8000, |
| 38 | /* The voice service state is out of service*/ |
| 39 | LYNQ_E_STATE_OUT_OF_SERVICE=8001, |
| 40 | /* The voice service state is EMERGENCY_ONLY*/ |
| 41 | LYNQ_E_STATE_EMERGENCY_ONLY=8002, |
| 42 | /* The radio power is power off*/ |
| 43 | LYNQ_E_STATE_POWER_OFF=8003, |
| 44 | LYNQ_E_TIME_OUT=8004, |
| 45 | /*create or open sms DB fail */ |
| 46 | LYNQ_E_SMS_DB_FAIL=8005, |
| 47 | /*Failed to execute sql statement*/ |
| 48 | LYNQ_E_SMS_SQL_FAIL = 8006, |
| 49 | LYNQ_E_SMS_NOT_FIND = 8007, |
| 50 | /* The logic conflict*/ |
| 51 | LYNQ_E_CONFLICT=9000, |
| 52 | /*Null anomaly*/ |
| 53 | LYNQ_E_NULL_ANONALY=9001 |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 54 | }LYNQ_E; |
| 55 | |
| 56 | int lynq_client_sockfd = 0; |
| 57 | int Global_uToken = 0; |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 58 | struct sockaddr_in lynq_data_socket_server_addr; |
| 59 | int lynq_data_socket_server_addr_len; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 60 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 61 | int lynq_data_call_change_id = -1; |
| 62 | pthread_t lynq_data_tid =-1; |
| 63 | static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 64 | static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 65 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 66 | static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 67 | static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 68 | static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 69 | static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER; |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 70 | /**g_lynq_data_sendto_mutex |
| 71 | * @brief mark data send request mutex |
| 72 | */ |
| 73 | static pthread_mutex_t g_lynq_data_sendto_mutex; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 74 | /*This value data the state of the wait*/ |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 75 | static int data_waiting_status = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 76 | /*The value indicates that 8085 error occurs in data*/ |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 77 | static int data_invaild_error = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 78 | /*This value ensure the data call timing is correct*/ |
| 79 | static int data_timelimit = 0; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 80 | |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 81 | /**g_lynq_data_init_flag |
| 82 | * @brief mark data initialization state |
| 83 | * 0:deinit status |
| 84 | * 1:init state |
| 85 | */ |
| 86 | static int g_lynq_data_init_flag = 0; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 87 | /**g_lynq_apn_result |
| 88 | * @brief temp of apn result info |
| 89 | */ |
| 90 | char g_lynq_apn_result[1024] = {}; |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 91 | |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 92 | static std::vector<int> s_data_urc_wait_list; |
| 93 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 94 | typedef struct |
| 95 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 96 | char apn[LYNQ_APN_MAX_LEN]; |
| 97 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
| 98 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
| 99 | int hasUsed; |
| 100 | int hasTimeout; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 101 | int status; |
| 102 | char statusApnType[LYNQ_APN_TYPE_MAX_LEN]; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 103 | }lynq_apn_t; |
| 104 | lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {}; |
| 105 | lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {}; |
| 106 | int lynq_data_call = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 107 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 108 | int getLynqApnID(char apnType[]) |
| 109 | { |
| 110 | int ret = 0; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 111 | int len = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 112 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 113 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 114 | len = strlen(apnType); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 115 | LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len); |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 116 | if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 117 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 118 | return ret; |
| 119 | } |
| 120 | } |
| 121 | return -1; |
| 122 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 123 | |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 124 | int getDeactApnID(char apnType[]) |
| 125 | { |
| 126 | int ret = 0; |
| 127 | int len = 0; |
| 128 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 129 | { |
| 130 | len = strlen(apnType); |
| 131 | LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len); |
| 132 | if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0) |
| 133 | { |
| 134 | return ret; |
| 135 | } |
| 136 | } |
| 137 | return -1; |
| 138 | } |
| 139 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 140 | void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[]) |
| 141 | { |
| 142 | LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName); |
| 143 | if(apn_table==NULL) |
| 144 | { |
| 145 | LYERRLOG("apn_table is null"); |
| 146 | return; |
| 147 | } |
| 148 | memcpy(apn_table->apn,apn,strlen(apn)+1); |
| 149 | memcpy(apn_table->apnType,apntype,strlen(apntype)+1); |
| 150 | memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1); |
| 151 | apn_table->hasTimeout = 0; |
| 152 | apn_table->hasUsed = 1; |
| 153 | return; |
| 154 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 155 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 156 | void cleanOnceApnTable(int apnId) |
| 157 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 158 | LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 159 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 160 | { |
| 161 | LYERRLOG("apn id is invalid!!!"); |
| 162 | return; |
| 163 | } |
| 164 | lynq_apn_table[apnId].hasTimeout = 0; |
| 165 | lynq_apn_table[apnId].hasUsed = 0; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 166 | memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType)); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 167 | bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 168 | bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 169 | bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 170 | lynq_apn_table[apnId].status = 32; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 171 | return; |
| 172 | } |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 173 | void cleanDeactApn(int apnId) |
| 174 | { |
| 175 | LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId); |
| 176 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 177 | { |
| 178 | LYERRLOG("apn id is invalid!!!"); |
| 179 | return; |
| 180 | } |
| 181 | lynq_apn_table[apnId].status = 0; |
| 182 | bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN); |
| 183 | } |
| 184 | |
| 185 | void updateDeactApn(int apnId,int pdnState) |
| 186 | { |
| 187 | LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId); |
| 188 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 189 | { |
| 190 | LYERRLOG("apn id is invalid!!!"); |
| 191 | return; |
| 192 | } |
| 193 | lynq_apn_table[apnId].status = pdnState; |
| 194 | } |
| 195 | |
| 196 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 197 | int getUnusedElement() |
| 198 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 199 | if (lynq_apn_table == NULL) |
| 200 | { |
| 201 | LYERRLOG("get UnusedElemnt apn_table is null"); |
| 202 | return -1; |
| 203 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 204 | for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++) |
| 205 | { |
| 206 | if(lynq_apn_table[i].hasUsed!=1) |
| 207 | { |
| 208 | return i; |
| 209 | } |
| 210 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 211 | LYERRLOG("None of get unused Element"); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 212 | return -1; |
| 213 | } |
| 214 | int updateApn(char apnType[]) |
| 215 | { |
| 216 | int ret = 0; |
| 217 | ret = getUnusedElement(); |
Hong_Liu | 5566871 | 2023-05-16 21:49:17 -0700 | [diff] [blame] | 218 | if(ret >= 0) |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 219 | { |
| 220 | memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1); |
| 221 | lynq_apn_table[ret].hasUsed = 1; |
| 222 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 223 | return ret; |
| 224 | } |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 225 | |
| 226 | int handleCheck(int handle) |
| 227 | { |
| 228 | if (lynq_apn_table[handle].hasUsed == 1) |
| 229 | { |
| 230 | return 0; |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | return -1; |
| 235 | } |
| 236 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 237 | int waitApnResult() |
| 238 | { |
| 239 | int ret = 0; |
| 240 | LYINFLOG("start wait apn result!!!"); |
| 241 | int sec = 0; |
| 242 | int usec = 0; |
| 243 | struct timeval now; |
| 244 | struct timespec timeout; |
| 245 | gettimeofday(&now, NULL); |
| 246 | sec = 20000 / 1000; |
| 247 | usec = 20000 % 1000; |
| 248 | timeout.tv_sec = now.tv_sec + sec; |
| 249 | timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000; |
| 250 | pthread_mutex_lock(&s_lynq_apn_change_mutex); |
| 251 | ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout); |
| 252 | pthread_mutex_unlock(&s_lynq_apn_change_mutex); |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | void sendSignalApnChange() |
| 257 | { |
| 258 | LYINFLOG("start send Signal Apn Change"); |
| 259 | pthread_mutex_lock(&s_lynq_apn_change_mutex); |
| 260 | pthread_cond_signal(&s_lynq_apn_change_cond); |
| 261 | pthread_mutex_unlock(&s_lynq_apn_change_mutex); |
| 262 | return; |
| 263 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 264 | |
| 265 | int waitPdnChange() |
| 266 | { |
| 267 | int ret = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 268 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 269 | ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex); |
| 270 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 271 | return ret; |
| 272 | } |
| 273 | int waitDataCallstateChange(int mtime) |
| 274 | { |
| 275 | int ret = 0; |
| 276 | int sec = 0; |
| 277 | int usec = 0; |
| 278 | struct timeval now; |
| 279 | struct timespec timeout; |
| 280 | gettimeofday(&now,NULL); |
| 281 | sec = mtime/1000; |
| 282 | usec = mtime%1000; |
| 283 | timeout.tv_sec = now.tv_sec+sec; |
| 284 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000; |
| 285 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 286 | ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout); |
| 287 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 288 | return ret; |
| 289 | } |
| 290 | void sendSignalDataCallStateChange() |
| 291 | { |
| 292 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 293 | pthread_cond_signal(&s_data_call_state_change_cond); |
| 294 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 295 | return; |
| 296 | } |
| 297 | void sendSignalPdnChange() |
| 298 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 299 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 300 | pthread_cond_signal(&s_lynq_urc_vector_cond); |
| 301 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | |
| 305 | int get_response(int sockfd,Parcel &p) |
| 306 | { |
| 307 | int len = 0; |
| 308 | char recvline[LYNQ_REC_BUF]; |
| 309 | bzero(recvline,LYNQ_REC_BUF); |
| 310 | /* receive data from server */ |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 311 | len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len); |
| 312 | //len = read(sockfd, recvline, LYNQ_REC_BUF); |
rjw | 0852868 | 2022-07-04 21:28:02 +0800 | [diff] [blame] | 313 | if(len == -1) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 314 | { |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 315 | LYERRLOG("get_response fail,errno:%d",errno); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 316 | return -1; |
| 317 | } |
| 318 | if (recvline != NULL) { |
| 319 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen); |
| 320 | p.setDataPosition(0); |
| 321 | } |
| 322 | return 0; |
| 323 | } |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 324 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 325 | { |
| 326 | if(p.dataAvail() > 0) |
| 327 | { |
| 328 | p.readInt32(resp_type); |
| 329 | p.readInt32(request); |
| 330 | p.readInt32(slot_id); |
| 331 | p.readInt32(error); |
| 332 | return 0; |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | return -1; |
| 337 | } |
| 338 | } |
| 339 | int send_request(int sockfd,lynq_client_t *client_tmp) |
| 340 | { |
| 341 | int ret=0; |
| 342 | ret = write(sockfd, client_tmp, LYQN_SEDN_BUF); |
| 343 | if(ret==-1) |
| 344 | { |
| 345 | perror("write error"); |
| 346 | return -1; |
| 347 | } |
| 348 | return 0; |
| 349 | } |
| 350 | static char *strdupReadString(Parcel &p) { |
| 351 | size_t stringlen; |
| 352 | const char16_t *s16; |
| 353 | s16 = p.readString16Inplace(&stringlen); |
| 354 | return strndup16to8(s16, stringlen); |
| 355 | } |
| 356 | static char *strdupReadString_p(Parcel *p) { |
| 357 | size_t stringlen; |
| 358 | const char16_t *s16; |
| 359 | s16 = p->readString16Inplace(&stringlen); |
| 360 | return strndup16to8(s16, stringlen); |
| 361 | } |
| 362 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 363 | /*Warren add for T800 platform 2021/11/19 start*/ |
| 364 | int lynq_socket_client_start() |
| 365 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 366 | /* init lynq_socket_server_addr */ |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 367 | bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr)); |
| 368 | lynq_data_socket_server_addr.sin_family = AF_INET; |
| 369 | lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT); |
jb.qi | ce04d00 | 2023-05-16 18:28:06 -0700 | [diff] [blame] | 370 | lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 371 | lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 372 | /* |
| 373 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0) |
| 374 | { |
| 375 | printf("[%s] is not a valid IPaddress\n", argv[1]); |
| 376 | exit(1); |
| 377 | } |
| 378 | */ |
| 379 | lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 380 | struct timeval timeOut; |
| 381 | |
rjw | a59bf31 | 2022-07-05 11:50:31 +0800 | [diff] [blame] | 382 | timeOut.tv_sec = 30; |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 383 | timeOut.tv_usec = 0; |
| 384 | |
| 385 | if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0) |
| 386 | { |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 387 | LYERRLOG("time out setting failed"); |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 388 | } |
| 389 | if(connect(lynq_client_sockfd, (struct sockaddr *)&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr)) == -1) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 390 | { |
| 391 | perror("connect error"); |
| 392 | return -1; |
| 393 | } |
| 394 | return 0; |
| 395 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 396 | |
| 397 | bool is_support_urc(int urc_id) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 398 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 399 | switch(urc_id) |
| 400 | { |
| 401 | case LYNQ_URC_DATA_CALL_STATUS_IND: |
| 402 | |
| 403 | case LYNQ_URC_MODIFY_APNDB: |
| 404 | case LYNQ_URC_RESET_APNDB: |
| 405 | return true; |
| 406 | default: |
| 407 | return false; |
| 408 | } |
| 409 | } |
| 410 | |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 411 | int printf_apn_table() |
| 412 | { |
| 413 | int ret = 0; |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 414 | if (lynq_apn_table == NULL) |
| 415 | { |
| 416 | LYERRLOG("apn table is null"); |
| 417 | return -1; |
| 418 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 419 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 420 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 421 | LYINFLOG("[%s][%d] apn=%s ;apntype=%s ;ifname=%s ;hasTimeout = %d ; hasUsed = %d,status = %d,statusDeactApn = %s",__FUNCTION__,ret, \ |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 422 | lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \ |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 423 | lynq_apn_table[ret].hasTimeout,lynq_apn_table[ret].hasUsed,lynq_apn_table[ret].status,lynq_apn_table[ret].statusApnType); |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 424 | } |
| 425 | return 0; |
| 426 | } |
| 427 | |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 428 | void printf_apn_table_debug(const char *fun,int line) |
| 429 | { |
| 430 | LYINFLOG("[%s][%d]apn_table msg",fun,line); |
| 431 | printf_apn_table(); |
| 432 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 433 | |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 434 | void urc_msg_process(Parcel *p) |
| 435 | { |
| 436 | int len; |
| 437 | int resp_type; |
| 438 | int urcid; |
| 439 | int slot_id; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 440 | int check_count = 0; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 441 | static int apnId=-1; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 442 | |
| 443 | int pdnState = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 444 | char apn[LYNQ_APN_MAX_LEN]; |
| 445 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 446 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 447 | char *urc_msg = NULL; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 448 | |
| 449 | int size = p->dataSize(); |
| 450 | p->readInt32(&resp_type); |
| 451 | p->readInt32(&urcid); |
| 452 | p->readInt32(&slot_id); |
| 453 | LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size); |
| 454 | switch(urcid) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 455 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 456 | case LYNQ_URC_DATA_CALL_STATUS_IND: |
| 457 | p->readInt32(&pdnState); |
| 458 | bzero(apn,LYNQ_APN_MAX_LEN); |
| 459 | bzero(apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 460 | bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
| 461 | if(pdnState!=4)//PDN_DISCONNECTED |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 462 | { |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 463 | urc_msg = strdupReadString_p(p); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 464 | int len = strlen(urc_msg); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 465 | if((len < LYNQ_APN_MAX_LEN-1) && (len > 0)) |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 466 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 467 | memcpy(apn,urc_msg,len+1); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 468 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 469 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 470 | urc_msg = strdupReadString_p(p); |
| 471 | len = strlen(urc_msg); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 472 | if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0)) |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 473 | { |
| 474 | memcpy(apnType,urc_msg,len+1); |
| 475 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 476 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 477 | urc_msg = strdupReadString_p(p); |
| 478 | len = strlen(urc_msg); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 479 | if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0)) |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 480 | { |
| 481 | memcpy(ifaceName,urc_msg,strlen(urc_msg)+1); |
| 482 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 483 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 484 | //sendSignalDataCallStateChange(); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 485 | apnId = getLynqApnID(apnType); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 486 | if(apnId >= 0) |
| 487 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 488 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 489 | if(lynq_apn_table[apnId].hasTimeout==1) |
| 490 | { |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 491 | /*whether timeout?,real or not,*/ |
| 492 | printf_apn_table(); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 493 | LYERRLOG("apn:%s has time out,deacive this apn",lynq_apn_table[apnId].apn); |
rjw | 3938f26 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 494 | if (NULL != lynq_apn_table[apnId].apn && NULL != lynq_apn_table[apnId].apnType && strlen(lynq_apn_table[apnId].apn)>0) |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 495 | { |
| 496 | LYERRLOG("deactive this time out APN"); |
| 497 | lynq_deactive_data_call(&apnId); |
| 498 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 499 | else |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 500 | { |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 501 | /*if apn lose,update apn and deactive all apn*/ |
| 502 | LYERRLOG("this table is invalid update APN table"); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 503 | } |
| 504 | break; |
| 505 | } |
rjw | acdb215 | 2023-02-07 14:12:49 +0800 | [diff] [blame] | 506 | updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 507 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 508 | } |
| 509 | /*To be completed*/ |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 510 | else |
| 511 | { |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 512 | data_invaild_error = 1; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 513 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
| 514 | apnId = getDeactApnID(apnType); |
| 515 | if(apnId < 0) |
| 516 | { |
| 517 | LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId); |
| 518 | break; |
| 519 | } |
| 520 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
| 521 | updateDeactApn(apnId,pdnState); |
| 522 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 523 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 524 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 525 | s_data_urc_wait_list.push_back(apnId); |
| 526 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
| 527 | lynq_data_call_change_id = apnId; |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 528 | sendSignalPdnChange(); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 529 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 530 | if(lynq_data_call==1) |
| 531 | { |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 532 | while (data_timelimit == 0) |
| 533 | { |
| 534 | LYINFLOG("client not ready to wait"); |
| 535 | for (check_count = 0;check_count < 500;check_count++) |
| 536 | { |
| 537 | /*wait 10ms*/ |
| 538 | usleep(10*1000); |
| 539 | } |
| 540 | LYERRLOG("client still without res"); |
| 541 | break; |
| 542 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 543 | sendSignalDataCallStateChange(); |
| 544 | lynq_data_call = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 545 | data_timelimit = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 546 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 547 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 548 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 549 | else |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 550 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 551 | urc_msg = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 552 | free(urc_msg); |
| 553 | urc_msg = strdupReadString_p(p); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 554 | len = strlen(urc_msg); |
| 555 | if(len < LYNQ_APN_TYPE_MAX_LEN-1) |
| 556 | { |
| 557 | memcpy(apnType,urc_msg,len+1); |
| 558 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 559 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 560 | LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 561 | apnId = getLynqApnID(apnType); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 562 | if(apnId >= 0) |
| 563 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 564 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
| 565 | lynq_data_call_change_id = apnId; |
| 566 | //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean |
| 567 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 568 | s_data_urc_wait_list.push_back(apnId); |
| 569 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
| 570 | sendSignalPdnChange(); |
| 571 | } |
| 572 | else |
| 573 | { |
| 574 | apnId = getDeactApnID(apnType); |
| 575 | if(apnId < 0) |
| 576 | { |
| 577 | LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId); |
| 578 | break; |
| 579 | } |
| 580 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
| 581 | cleanDeactApn(apnId); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 582 | lynq_data_call_change_id = apnId; |
| 583 | bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean |
rjw | 3938f26 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 584 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 585 | s_data_urc_wait_list.push_back(apnId); |
| 586 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 587 | sendSignalPdnChange(); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 588 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 589 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 590 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 591 | if(lynq_data_call==1) |
| 592 | { |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 593 | while (data_timelimit == 0) |
| 594 | { |
| 595 | LYINFLOG("client not ready to wait"); |
| 596 | for (check_count = 0;check_count < 500;check_count++) |
| 597 | { |
| 598 | /*wait 10ms*/ |
| 599 | usleep(10*1000); |
| 600 | } |
| 601 | LYERRLOG("client still without res"); |
| 602 | break; |
| 603 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 604 | sendSignalDataCallStateChange(); |
| 605 | lynq_data_call = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 606 | data_timelimit = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 607 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 608 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 609 | } |
| 610 | break; |
| 611 | case LYNQ_URC_MODIFY_APNDB: |
| 612 | urc_msg = strdupReadString_p(p); |
| 613 | if (NULL == urc_msg) |
| 614 | { |
| 615 | LYERRLOG("error apn msg"); |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | bzero(g_lynq_apn_result, 1024); |
| 620 | strcpy(g_lynq_apn_result, urc_msg); |
| 621 | sendSignalApnChange(); |
| 622 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 623 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 624 | break; |
| 625 | case LYNQ_URC_RESET_APNDB: |
| 626 | { |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 627 | urc_msg = strdupReadString_p(p); |
| 628 | if (NULL == urc_msg) |
| 629 | { |
| 630 | LYERRLOG("error apn msg"); |
| 631 | } |
| 632 | else |
| 633 | { |
| 634 | bzero(g_lynq_apn_result, 1024); |
| 635 | strcpy(g_lynq_apn_result, urc_msg); |
| 636 | sendSignalApnChange(); |
| 637 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 638 | free(urc_msg); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 639 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 640 | default: |
| 641 | break; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 642 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 643 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 644 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 645 | |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 646 | int create_urc_vector_signal_thread() |
| 647 | { |
| 648 | int ret; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 649 | pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 650 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 651 | s_data_urc_wait_list.clear(); |
| 652 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 653 | return 0; |
| 654 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 655 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 656 | int lynq_init_data(int uToken) |
| 657 | { |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 658 | if (g_lynq_data_init_flag == 1) |
| 659 | { |
| 660 | LYERRLOG("init twice is not allowed"); |
| 661 | return -1; |
| 662 | } |
| 663 | g_lynq_data_init_flag = 1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 664 | int result = 0; |
| 665 | Global_uToken = uToken; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 666 | LYLOGSET(LOG_INFO); |
| 667 | LYLOGEINIT(USER_LOG_TAG); |
| 668 | result = lynq_socket_client_start(); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 669 | pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 670 | if(result!=0) |
| 671 | { |
| 672 | LYERRLOG("init socket client fail!!!"); |
| 673 | return -1; |
| 674 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 675 | result = lynq_init_data_urc_thread(); |
| 676 | if(result!=0) |
| 677 | { |
| 678 | LYERRLOG("init socket urc fail!!!"); |
| 679 | return -1; |
| 680 | } |
| 681 | |
| 682 | result = create_urc_vector_signal_thread(); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 683 | if(result!=0) |
| 684 | { |
| 685 | LYERRLOG("init socket urc fail!!!"); |
| 686 | return -1; |
| 687 | } |
| 688 | memset(lynq_apn_table,0,sizeof(lynq_apn_table)); |
| 689 | LYDBGLOG("lynq init call success!!!"); |
| 690 | return 0; |
| 691 | |
| 692 | } |
| 693 | int lynq_deinit_data() |
| 694 | { |
| 695 | int ret = -1; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 696 | if (g_lynq_data_init_flag == 0) |
| 697 | { |
| 698 | LYERRLOG("deinit twice is not allowed"); |
| 699 | return ret; |
| 700 | } |
| 701 | g_lynq_data_init_flag = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 702 | for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++) |
| 703 | { |
| 704 | if(strlen(lynq_apn_table[i].apnType)!=0) |
| 705 | { |
| 706 | lynq_deactive_data_call(&i); |
| 707 | } |
| 708 | } |
| 709 | if(lynq_client_sockfd>0) |
| 710 | { |
| 711 | close(lynq_client_sockfd); |
| 712 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 713 | ret = lynq_deinit_data_urc_thread(); |
rjw | eb65a2f | 2023-02-01 16:43:23 +0800 | [diff] [blame] | 714 | if (ret != 0) |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 715 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 716 | LYERRLOG("lynq_deinit_data_urc_thread fail"); |
| 717 | return ret; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 718 | } |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 719 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 720 | s_data_urc_wait_list.clear(); |
| 721 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 722 | return 0; |
| 723 | } |
| 724 | int lynq_setup_data_call(int *handle) |
| 725 | { |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 726 | int error = -1; |
| 727 | #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman. |
| 728 | LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__); |
Hong_Liu | e987915 | 2023-04-25 20:40:26 -0700 | [diff] [blame] | 729 | error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 730 | #else |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 731 | Parcel p; |
| 732 | lynq_client_t client; |
| 733 | int resp_type = -1; |
| 734 | int request = -1; |
| 735 | int slot_id = -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 736 | int lynq_data_call_id = 0; |
| 737 | if(handle==NULL) |
| 738 | { |
| 739 | LYERRLOG("handle is null!!!"); |
| 740 | return LYNQ_E_NULL_ANONALY; |
| 741 | } |
| 742 | client.uToken = Global_uToken; |
| 743 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 744 | client.paramLen = 0; |
| 745 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 746 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 747 | lynq_data_call_id = updateApn("default"); |
| 748 | if (lynq_data_call_id < 0) |
| 749 | { |
| 750 | LYERRLOG("update apn table fail error id = %d",lynq_data_call_id); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 751 | return LYNQ_E_NULL_ANONALY+1; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 752 | } |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 753 | *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect. |
| 754 | //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate. |
rjw | 733b983 | 2023-04-03 10:20:08 +0800 | [diff] [blame] | 755 | lynq_data_call = 1; |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 756 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 757 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 758 | { |
| 759 | LYERRLOG("send request fail"); |
| 760 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 761 | return LYNQ_E_NULL_ANONALY+2; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 762 | } |
| 763 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 764 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 765 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 766 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 767 | if(error==0) |
| 768 | { |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 769 | data_timelimit = 1; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 770 | if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 771 | { |
| 772 | error = LYNQ_E_TIME_OUT; |
| 773 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 774 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 775 | if (data_invaild_error == 1) |
| 776 | { |
| 777 | data_invaild_error = 0; |
| 778 | LYERRLOG("urc apn info error!!!"); |
| 779 | return 8085; |
| 780 | } |
| 781 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 782 | return error; |
| 783 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 784 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 785 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 786 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 787 | return error; |
| 788 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 789 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 790 | int lynq_deactive_data_call(int *handle) |
| 791 | { |
| 792 | Parcel p; |
| 793 | lynq_client_t client; |
| 794 | int resp_type = -1; |
| 795 | int request = -1; |
| 796 | int slot_id = -1; |
| 797 | int error = -1; |
| 798 | int lynq_data_call_id = -1; |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 799 | int ret = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 800 | if(handle==NULL) |
| 801 | { |
| 802 | LYERRLOG("handle is null!!!"); |
| 803 | return -1; |
| 804 | } |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 805 | ret = handleCheck(*handle); |
| 806 | if (ret != 0) |
| 807 | { |
| 808 | LYERRLOG("incomming handle is invalid"); |
| 809 | return -1; |
| 810 | } |
| 811 | lynq_data_call_id = *handle; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 812 | client.uToken = Global_uToken; |
| 813 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
Hong_Liu | e3d3526 | 2023-05-04 00:20:12 -0700 | [diff] [blame] | 814 | client.paramLen = 0; |
| 815 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 816 | #ifdef GSW_RIL_CFG |
| 817 | client.paramLen = 1; |
| 818 | sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); |
| 819 | #else |
| 820 | if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 821 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 822 | client.paramLen = 1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 823 | sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); |
| 824 | } |
Hong_Liu | e3d3526 | 2023-05-04 00:20:12 -0700 | [diff] [blame] | 825 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 826 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 827 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 828 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 829 | { |
| 830 | LYERRLOG("send request fail"); |
| 831 | perror("[LYNQ_DATA] send request fail:"); |
| 832 | return -1; |
| 833 | } |
| 834 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 835 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 836 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 837 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 838 | cleanOnceApnTable(lynq_data_call_id); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 839 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 840 | return error; |
| 841 | } |
| 842 | int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol) |
| 843 | { |
| 844 | Parcel p; |
| 845 | lynq_client_t client; |
| 846 | int resp_type = -1; |
| 847 | int request = -1; |
| 848 | int slot_id = -1; |
| 849 | int error = -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 850 | int lynq_data_call_id = -1; |
| 851 | char *argv[10] = {}; |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 852 | #ifdef GSW_RIL_CFG |
| 853 | LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__); |
| 854 | if(handle==NULL||apnType==NULL) |
| 855 | { |
| 856 | LYERRLOG("handle or apntype is null!!!"); |
| 857 | return -1; |
| 858 | } |
| 859 | #else |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 860 | if(handle==NULL||apn==NULL||apnType==NULL) |
| 861 | { |
| 862 | LYERRLOG("handle ,apn or apntype is null!!!"); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 863 | return LYNQ_E_NULL_ANONALY; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 864 | } |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 865 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 866 | if(user==NULL) |
| 867 | { |
| 868 | argv[1] = "null"; |
| 869 | } |
| 870 | else |
| 871 | { |
| 872 | argv[1] = user; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 873 | } |
| 874 | if(password==NULL) |
| 875 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 876 | argv[2] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 877 | } |
| 878 | else |
| 879 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 880 | argv[2] = password; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 881 | } |
| 882 | if(authType==NULL) |
| 883 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 884 | argv[3] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 885 | } |
| 886 | else |
| 887 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 888 | argv[3] = authType; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 889 | } |
| 890 | if(normalProtocol==NULL) |
| 891 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 892 | argv[4] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 893 | } |
| 894 | else |
| 895 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 896 | argv[4] = normalProtocol; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 897 | } |
| 898 | if(roamingProtocol==NULL) |
| 899 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 900 | argv[5] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 901 | } |
| 902 | else |
| 903 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 904 | argv[5] = roamingProtocol; |
| 905 | } |
| 906 | client.uToken = Global_uToken; |
| 907 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 908 | client.paramLen = 7; |
| 909 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 910 | #ifdef GSW_RIL_CFG |
| 911 | if(NULL == apn) |
| 912 | { |
| 913 | sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
| 914 | } |
| 915 | else |
| 916 | { |
| 917 | sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
| 918 | } |
| 919 | #else |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 920 | sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 921 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 922 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 923 | lynq_data_call_id = updateApn(apnType); |
| 924 | if (lynq_data_call_id < 0) |
| 925 | { |
| 926 | LYERRLOG("update apn table fail error id = %d",lynq_data_call_id); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 927 | return LYNQ_E_NULL_ANONALY+1; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 928 | } |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 929 | *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) |
rjw | 733b983 | 2023-04-03 10:20:08 +0800 | [diff] [blame] | 930 | lynq_data_call = 1; |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 931 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 932 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 933 | { |
| 934 | LYERRLOG("send request fail"); |
| 935 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 936 | return LYNQ_E_NULL_ANONALY+2; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 937 | } |
| 938 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 939 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 940 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 941 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 942 | if(error==0) |
| 943 | { |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 944 | data_timelimit = 1; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 945 | if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 946 | { |
| 947 | error = LYNQ_E_TIME_OUT; |
| 948 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 949 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 950 | if (data_invaild_error == 1) |
| 951 | { |
| 952 | data_invaild_error = 0; |
| 953 | LYERRLOG("urc apn info error!!!"); |
| 954 | return 8085; |
| 955 | } |
| 956 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 957 | return error; |
| 958 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 959 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 960 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 961 | return error; |
| 962 | } |
| 963 | /* |
| 964 | int lynq_deactive_data_call_sp(int *handle,char *apnType) |
| 965 | { |
| 966 | Parcel p; |
| 967 | lynq_client_t client; |
| 968 | int resp_type = -1; |
| 969 | int request = -1; |
| 970 | int slot_id = -1; |
| 971 | int error = -1; |
| 972 | if(handle==NULL||apnType==NULL) |
| 973 | { |
| 974 | LYERRLOG("handle is null!!!"); |
| 975 | return -1; |
| 976 | } |
| 977 | client.uToken = Global_uToken; |
| 978 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
| 979 | client.paramLen = 1; |
| 980 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 981 | sprintf(client.param,"%s",apnType); |
| 982 | LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 983 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 984 | { |
| 985 | LYERRLOG("send request fail"); |
| 986 | perror("[LYNQ_DATA] send request fail:"); |
| 987 | return -1; |
| 988 | } |
| 989 | get_response(lynq_client_sockfd,p); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 990 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 991 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 992 | return error; |
| 993 | } |
| 994 | */ |
| 995 | int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum) |
| 996 | { |
| 997 | Parcel p; |
| 998 | lynq_client_t client; |
| 999 | int resp_type = -1; |
q.huang | 7de1d66 | 2022-09-13 14:19:24 +0800 | [diff] [blame] | 1000 | int token; |
| 1001 | int request = -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1002 | int slot_id = -1; |
| 1003 | int error = -1; |
| 1004 | int version =0; |
| 1005 | int num = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1006 | char *temp_char = NULL; |
| 1007 | if(dataCallList==NULL) |
| 1008 | { |
| 1009 | LYERRLOG("dataCallList is null!!!"); |
| 1010 | return -1; |
| 1011 | } |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1012 | Global_uToken++; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1013 | client.uToken = Global_uToken; |
| 1014 | client.request = 57;//RIL_REQUEST_DATA_CALL_LIST |
| 1015 | client.paramLen = 0; |
| 1016 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 1017 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1018 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1019 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1020 | { |
| 1021 | LYERRLOG("send request fail"); |
| 1022 | perror("[LYNQ_DATA] send request fail:"); |
| 1023 | return -1; |
| 1024 | } |
| 1025 | get_response(lynq_client_sockfd,p); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1026 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 1027 | if(p.dataAvail() > 0) |
| 1028 | { |
rjw | 0fb4ccb | 2022-09-16 19:12:35 +0800 | [diff] [blame] | 1029 | p.readInt32(&resp_type); |
| 1030 | p.readInt32(&token); |
| 1031 | p.readInt32(&request); |
| 1032 | p.readInt32(&slot_id); |
| 1033 | p.readInt32(&error); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 1034 | } |
| 1035 | else |
| 1036 | { |
| 1037 | return -1; |
| 1038 | } |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1039 | LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,token,request,slot_id,error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1040 | p.readInt32(&version); |
| 1041 | if(version==11) |
| 1042 | { |
| 1043 | p.readInt32(&num); |
| 1044 | *realNum = num; |
| 1045 | for (int i = 0; i < num; i++) |
| 1046 | { |
| 1047 | p.readInt32(&dataCallList[i].status); |
| 1048 | p.readInt32(&dataCallList[i].suggestedRetryTime); |
| 1049 | p.readInt32(&dataCallList[i].cid); |
| 1050 | p.readInt32(&dataCallList[i].active); |
| 1051 | temp_char = strdupReadString(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1052 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1053 | if(temp_char) |
| 1054 | { |
| 1055 | memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1); |
| 1056 | free(temp_char); |
| 1057 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1058 | temp_char = strdupReadString(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1059 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1060 | if(temp_char) |
| 1061 | { |
| 1062 | memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1); |
| 1063 | free(temp_char); |
| 1064 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1065 | temp_char = strdupReadString(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1066 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1067 | if(temp_char) |
| 1068 | { |
| 1069 | memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1); |
| 1070 | free(temp_char); |
| 1071 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1072 | temp_char = strdupReadString(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1073 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1074 | if(temp_char) |
| 1075 | { |
| 1076 | memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1); |
| 1077 | free(temp_char); |
| 1078 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1079 | temp_char = strdupReadString(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1080 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1081 | if(temp_char) |
| 1082 | { |
| 1083 | memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1); |
| 1084 | free(temp_char); |
| 1085 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1086 | temp_char = strdupReadString(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1087 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1088 | if(temp_char) |
| 1089 | { |
| 1090 | memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1); |
| 1091 | free(temp_char); |
| 1092 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1093 | p.readInt32(&dataCallList[i].mtu); |
| 1094 | } |
| 1095 | } |
| 1096 | return error; |
| 1097 | } |
| 1098 | int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList) |
| 1099 | { |
| 1100 | lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={}; |
| 1101 | int number = 0; |
| 1102 | int lynq_data_call_id = 0; |
| 1103 | int error = 0; |
| 1104 | lynq_data_call_id = *handle; |
| 1105 | if(handle==NULL) |
| 1106 | { |
| 1107 | LYERRLOG("handle is NULL"); |
| 1108 | return LYNQ_E_NULL_ANONALY; |
| 1109 | } |
rjw | 3938f26 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 1110 | if (*handle<0 && handle>8) |
| 1111 | { |
| 1112 | LYERRLOG("handle value error"); |
| 1113 | } |
| 1114 | LYINFLOG("incoming handle value: %d",*handle); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1115 | memset(interDataCallList,0,sizeof(interDataCallList)); |
| 1116 | error = getDataCallLists(interDataCallList,&number); |
| 1117 | if(error == 0) |
| 1118 | { |
| 1119 | for(int i = 0;i < number;i++) |
| 1120 | { |
| 1121 | if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0) |
| 1122 | { |
| 1123 | dataCallList->active = interDataCallList[i].active; |
| 1124 | dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime; |
| 1125 | dataCallList->cid = interDataCallList[i].cid; |
| 1126 | dataCallList->status = interDataCallList[i].status; |
| 1127 | dataCallList->mtu = interDataCallList[i].mtu; |
| 1128 | memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses)); |
| 1129 | memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname)); |
| 1130 | memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses)); |
| 1131 | memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type)); |
| 1132 | memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways)); |
| 1133 | memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf)); |
| 1134 | LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses); |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | return error; |
| 1139 | } |
| 1140 | int lynq_wait_data_call_state_change(int *handle) |
| 1141 | { |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 1142 | if (data_waiting_status == 1) |
| 1143 | { |
| 1144 | LYDBGLOG("some thread is waiting"); |
| 1145 | return -3; |
| 1146 | } |
| 1147 | LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty()); |
| 1148 | if (s_data_urc_wait_list.empty()) |
| 1149 | { |
| 1150 | LYDBGLOG("start wait"); |
| 1151 | data_waiting_status = 1; |
| 1152 | waitPdnChange(); |
| 1153 | } |
| 1154 | data_waiting_status = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 1155 | std::vector<int>::iterator iter; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 1156 | |
| 1157 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 1158 | iter = s_data_urc_wait_list.begin(); |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 1159 | if (iter != s_data_urc_wait_list.end()) |
| 1160 | { |
| 1161 | *handle = *iter; |
| 1162 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 1163 | s_data_urc_wait_list.erase(iter); |
| 1164 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
| 1165 | |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame^] | 1166 | LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1167 | return 0; |
| 1168 | } |
| 1169 | /*Warren add for T800 platform 2021/11/19 end*/ |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1170 | |
| 1171 | /*Typethree add for T800 platform 2022/04/21 start*/ |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1172 | |
| 1173 | int insert_apn_char(char *agc, char *id,char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier) |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1174 | { |
| 1175 | char strtmp[10][32]; |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1176 | if (id == NULL) |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1177 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1178 | sprintf(strtmp[0], "id=;"); |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1179 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1180 | else |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1181 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1182 | sprintf(strtmp[0], "id=%s;", id); |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1183 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1184 | if (mcc == NULL) |
| 1185 | { |
| 1186 | sprintf(strtmp[1], "mcc=;"); |
| 1187 | } |
| 1188 | else |
| 1189 | { |
| 1190 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1191 | } |
| 1192 | if (mnc == NULL) |
| 1193 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1194 | sprintf(strtmp[2], "mnc=;"); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1195 | } |
| 1196 | else |
| 1197 | { |
| 1198 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1199 | } |
| 1200 | if (apn == NULL) |
| 1201 | { |
| 1202 | sprintf(strtmp[3], "apn=;"); |
| 1203 | } |
| 1204 | else |
| 1205 | { |
| 1206 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1207 | } |
| 1208 | if (apntype == NULL) |
| 1209 | { |
| 1210 | sprintf(strtmp[4], "apntype=;"); |
| 1211 | } |
| 1212 | else |
| 1213 | { |
| 1214 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1215 | } |
| 1216 | if (user == NULL) |
| 1217 | { |
| 1218 | sprintf(strtmp[5], "user=;"); |
| 1219 | } |
| 1220 | else |
| 1221 | { |
| 1222 | sprintf(strtmp[5], "user=%s;", user); |
| 1223 | } |
| 1224 | if (password == NULL) |
| 1225 | { |
| 1226 | sprintf(strtmp[6], "password=;"); |
| 1227 | } |
| 1228 | else |
| 1229 | { |
| 1230 | sprintf(strtmp[6], "password=%s;", password); |
| 1231 | } |
| 1232 | if (normalprotocol == NULL) |
| 1233 | { |
| 1234 | sprintf(strtmp[7], "normalprotocol=;"); |
| 1235 | } |
| 1236 | else |
| 1237 | { |
| 1238 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1239 | } |
| 1240 | if (roamingprotocol == NULL) |
| 1241 | { |
| 1242 | sprintf(strtmp[8], "roamingprotocol=;"); |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1247 | } |
| 1248 | if (carrier == NULL) |
| 1249 | { |
| 1250 | sprintf(strtmp[9], "carrier=;"); |
| 1251 | } |
| 1252 | else |
| 1253 | { |
| 1254 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1255 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1256 | sprintf(agc, "%s%s%s%s%s%s%s%s%s%s",strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]); |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1257 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1258 | return 0; |
| 1259 | } |
| 1260 | |
| 1261 | int modify_apn_char(char *agc, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier) |
| 1262 | { |
| 1263 | char strtmp[10][32]; |
| 1264 | if (id == NULL) |
| 1265 | { |
| 1266 | sprintf(strtmp[0], "id=;"); |
| 1267 | } |
| 1268 | else |
| 1269 | { |
| 1270 | sprintf(strtmp[0], "id=%s;", id); |
| 1271 | } |
| 1272 | if (mcc == NULL) |
| 1273 | { |
| 1274 | sprintf(strtmp[1], "mcc=;"); |
| 1275 | } |
| 1276 | else |
| 1277 | { |
| 1278 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1279 | } |
| 1280 | if (mnc == NULL) |
| 1281 | { |
| 1282 | sprintf(strtmp[2], "mnc=;"); |
| 1283 | } |
| 1284 | else |
| 1285 | { |
| 1286 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1287 | } |
| 1288 | if (apn == NULL) |
| 1289 | { |
| 1290 | sprintf(strtmp[3], "apn=;"); |
| 1291 | } |
| 1292 | else |
| 1293 | { |
| 1294 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1295 | } |
| 1296 | if (apntype == NULL) |
| 1297 | { |
| 1298 | sprintf(strtmp[4], "apntype=;"); |
| 1299 | } |
| 1300 | else |
| 1301 | { |
| 1302 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1303 | } |
| 1304 | if (user == NULL) |
| 1305 | { |
| 1306 | sprintf(strtmp[5], "user=;"); |
| 1307 | } |
| 1308 | else |
| 1309 | { |
| 1310 | sprintf(strtmp[5], "user=%s;", user); |
| 1311 | } |
| 1312 | if (password == NULL) |
| 1313 | { |
| 1314 | sprintf(strtmp[6], "password=;"); |
| 1315 | } |
| 1316 | else |
| 1317 | { |
| 1318 | sprintf(strtmp[6], "password=%s;", password); |
| 1319 | } |
| 1320 | if (normalprotocol == NULL) |
| 1321 | { |
| 1322 | sprintf(strtmp[7], "normalprotocol=;"); |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1327 | } |
| 1328 | if (roamingprotocol == NULL) |
| 1329 | { |
| 1330 | sprintf(strtmp[8], "roamingprotocol=;"); |
| 1331 | } |
| 1332 | else |
| 1333 | { |
| 1334 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1335 | } |
| 1336 | if (carrier == NULL) |
| 1337 | { |
| 1338 | sprintf(strtmp[9], "carrier=;"); |
| 1339 | } |
| 1340 | else |
| 1341 | { |
| 1342 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1343 | } |
| 1344 | sprintf(agc, "%s%s%s%s%s%s%s%s%s%s", strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]); |
| 1345 | return 0; |
| 1346 | } |
| 1347 | |
rjw | af4b161 | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1348 | |
| 1349 | int query_apn_char(char *agc, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier) |
| 1350 | { |
| 1351 | char strtmp[10][32]; |
| 1352 | if (id == NULL) |
| 1353 | { |
| 1354 | sprintf(strtmp[0], ""); |
| 1355 | } |
| 1356 | else |
| 1357 | { |
| 1358 | sprintf(strtmp[0], "id=%s;", id); |
| 1359 | } |
| 1360 | if (mcc == NULL) |
| 1361 | { |
| 1362 | sprintf(strtmp[1], ""); |
| 1363 | } |
| 1364 | else |
| 1365 | { |
| 1366 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1367 | } |
| 1368 | if (mnc == NULL) |
| 1369 | { |
| 1370 | sprintf(strtmp[2], ""); |
| 1371 | } |
| 1372 | else |
| 1373 | { |
| 1374 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1375 | } |
| 1376 | if (apn == NULL) |
| 1377 | { |
| 1378 | sprintf(strtmp[3], ""); |
| 1379 | } |
| 1380 | else |
| 1381 | { |
| 1382 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1383 | } |
| 1384 | if (apntype == NULL) |
| 1385 | { |
| 1386 | sprintf(strtmp[4], ""); |
| 1387 | } |
| 1388 | else |
| 1389 | { |
| 1390 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1391 | } |
| 1392 | if (user == NULL) |
| 1393 | { |
| 1394 | sprintf(strtmp[5], ""); |
| 1395 | } |
| 1396 | else |
| 1397 | { |
| 1398 | sprintf(strtmp[5], "user=%s;", user); |
| 1399 | } |
| 1400 | if (password == NULL) |
| 1401 | { |
| 1402 | sprintf(strtmp[6], ""); |
| 1403 | } |
| 1404 | else |
| 1405 | { |
| 1406 | sprintf(strtmp[6], "password=%s;", password); |
| 1407 | } |
| 1408 | if (normalprotocol == NULL) |
| 1409 | { |
| 1410 | sprintf(strtmp[7], ""); |
| 1411 | } |
| 1412 | else |
| 1413 | { |
| 1414 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1415 | } |
| 1416 | if (roamingprotocol == NULL) |
| 1417 | { |
| 1418 | sprintf(strtmp[8], ""); |
| 1419 | } |
| 1420 | else |
| 1421 | { |
| 1422 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1423 | } |
| 1424 | if (carrier == NULL) |
| 1425 | { |
| 1426 | sprintf(strtmp[9], ""); |
| 1427 | } |
| 1428 | else |
| 1429 | { |
| 1430 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1431 | } |
| 1432 | sprintf(agc, "%s%s%s%s%s%s%s%s%s%s", strtmp[0], strtmp[1], strtmp[2], strtmp[3], strtmp[4], strtmp[5], strtmp[6], strtmp[7], strtmp[8], strtmp[9]); |
| 1433 | return 0; |
| 1434 | } |
| 1435 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1436 | static char *lynqStrdupReadString(Parcel &p) |
| 1437 | { |
| 1438 | size_t stringlen; |
| 1439 | const char16_t *s16; |
| 1440 | |
| 1441 | s16 = p.readString16Inplace(&stringlen); |
| 1442 | return strndup16to8(s16, stringlen); |
| 1443 | } |
| 1444 | |
| 1445 | int lynq_modify_apn_db(const int cmd, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier, char *out) |
| 1446 | { |
| 1447 | if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier) |
| 1448 | { |
| 1449 | LYERRLOG("There are no valid parameters"); |
| 1450 | return -1; |
| 1451 | } |
| 1452 | lynq_client_t client; |
| 1453 | char argc[512]; |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1454 | int res = 0; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1455 | Parcel p; |
| 1456 | if (cmd == 0) // insert apn db |
| 1457 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1458 | res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
| 1459 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1460 | client.uToken = Global_uToken; |
| 1461 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1462 | client.paramLen = 2; |
| 1463 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1464 | sprintf(client.param, "%d %s", cmd, argc); |
| 1465 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1466 | else if (cmd == 1) //delete apn db |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1467 | { |
| 1468 | if (NULL == id) |
| 1469 | { |
| 1470 | LYERRLOG("id is NULL!!!please input id: "); |
| 1471 | } |
| 1472 | sprintf(argc, "id=%s", id); |
| 1473 | client.uToken = Global_uToken; |
| 1474 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1475 | client.paramLen = 2; |
| 1476 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1477 | sprintf(client.param, "%d %s", cmd, argc); |
| 1478 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1479 | else if (cmd == 2) //query apn db |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1480 | { |
rjw | af4b161 | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1481 | query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1482 | client.uToken = Global_uToken; |
| 1483 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1484 | client.paramLen = 2; |
| 1485 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1486 | sprintf(client.param, "%d %s", cmd, argc); |
| 1487 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1488 | else if (cmd == 3) //modify apn db |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1489 | { |
| 1490 | modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
| 1491 | client.uToken = Global_uToken; |
| 1492 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1493 | client.paramLen = 2; |
| 1494 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1495 | sprintf(client.param, "%d %s", cmd, argc); |
| 1496 | } |
| 1497 | else |
| 1498 | { |
| 1499 | LYERRLOG("incoming command is invalid"); |
| 1500 | return -1; |
| 1501 | } |
| 1502 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1503 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1504 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1505 | { |
| 1506 | LYERRLOG("send request fail"); |
| 1507 | return -1; |
| 1508 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1509 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1510 | waitApnResult(); |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1511 | strcpy(out, g_lynq_apn_result); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1512 | LYINFLOG(">>>>>output info:%s",out); |
| 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | int lynq_reset_apn(char *result) |
| 1517 | { |
| 1518 | Parcel p; |
| 1519 | lynq_client_t client; |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1520 | if (NULL == result) |
| 1521 | { |
| 1522 | LYERRLOG("incoming paramters error"); |
| 1523 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1524 | client.uToken = Global_uToken; |
| 1525 | client.request = 2000 + 194; |
| 1526 | client.paramLen = 0; |
| 1527 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1528 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1529 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1530 | if (send_request(lynq_client_sockfd, &client) == -1) |
| 1531 | { |
| 1532 | LYERRLOG("send request fail"); |
| 1533 | return -1; |
| 1534 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1535 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1536 | waitApnResult(); |
| 1537 | strcpy(result, g_lynq_apn_result); |
| 1538 | LYINFLOG(">>>>>result:%s",result); |
| 1539 | return 0; |
| 1540 | } |
| 1541 | |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1542 | /*Typethree add for T800 platform 2022/04/21 end*/ |