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