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