| lh | aa28307 | 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 | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 16 | #include <include/lynq_uci.h> | 
| rjw | 7d406a1 | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 17 | #include <errno.h> | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 18 | #include <vector> | 
 | 19 | #include "lynq_data_urc.h" | 
 | 20 |  | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 21 | #define LYNQ_SERVICE_PORT 8088 | 
| lh | aa28307 | 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 | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 27 | #define LYNQ_DATA_UCI_BUF 258 | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 28 |  | 
| lh | aa28307 | 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 | e912a14 | 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 | aa28307 | 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 | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 58 |  | 
| lh | aa28307 | 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 | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 63 |  | 
| rjw | d103738 | 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 | 3d6a50e | 2023-02-20 13:35:42 +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 | 9a46163 | 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 | 267d8ee | 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 | d103738 | 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 | 7d406a1 | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 86 |  | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 87 | static std::vector<int> s_data_urc_wait_list; | 
 | 88 |  | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 89 | typedef struct | 
 | 90 | { | 
| lh | aa28307 | 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 | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 100 |  | 
| lh | aa28307 | 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 | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 107 |         { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 108 |             return ret; | 
 | 109 |         } | 
 | 110 |     } | 
 | 111 |     return -1; | 
 | 112 | } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 113 |  | 
| lh | aa28307 | 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 | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 129 |  | 
| lh | aa28307 | 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 | 51dba88 | 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 | d103738 | 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 | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 203 |  | 
 | 204 | int waitPdnChange() | 
 | 205 | { | 
 | 206 |     int ret = 0; | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | aa28307 | 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 | 3d6a50e | 2023-02-20 13:35:42 +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 | aa28307 | 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 | 215d163 | 2022-07-04 21:28:02 +0800 | [diff] [blame] | 250 |     len = read(sockfd, recvline, LYNQ_REC_BUF); | 
 | 251 |     if(len == -1) | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 252 |     { | 
| rjw | 7d406a1 | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 253 |         LYERRLOG("read error"); | 
| lh | aa28307 | 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 | 9c52278 | 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 | aa28307 | 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 | aa28307 | 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 | 215d163 | 2022-07-04 21:28:02 +0800 | [diff] [blame] | 304 |     struct sockaddr_in lynq_data_socket_server_addr; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 305 |     /* init lynq_socket_server_addr */ | 
| rjw | 7d406a1 | 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 | aa28307 | 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 | 7d406a1 | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 318 |     struct timeval timeOut;  | 
 | 319 |  | 
| rjw | df20638 | 2022-07-05 11:50:31 +0800 | [diff] [blame] | 320 |     timeOut.tv_sec = 30; | 
| rjw | 7d406a1 | 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 | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 328 |     { | 
 | 329 |         perror("connect error"); | 
 | 330 |         return -1; | 
 | 331 |     } | 
 | 332 |     return 0; | 
 | 333 | } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 334 |  | 
 | 335 | bool is_support_urc(int urc_id) | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 336 | { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | aa28307 | 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 | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 359 |     char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 360 |     char *urc_msg = NULL; | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 368 |     { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 375 |             { | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 376 |                 urc_msg = strdupReadString_p(p); | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 377 |                 int len = strlen(urc_msg); | 
 | 378 |                 if(len < LYNQ_APN_MAX_LEN-1) | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 379 |                 { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 380 |                     memcpy(apn,urc_msg,len+1); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 381 |                 } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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); | 
| rjw | f98a5d8 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 401 |                         if (NULL != lynq_apn_table[apnId].apn && NULL != lynq_apn_table[apnId].apnType && strlen(lynq_apn_table[apnId].apn)>0) | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 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 |                     } | 
 | 412 |                     updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName); | 
 | 413 |                 } | 
 | 414 |                 /*To be completed*/ | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 415 |                 else | 
 | 416 |                 { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 417 |                     LYERRLOG("invalid apnId"); | 
 | 418 |                     break; | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 419 |                 } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 431 |             } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 432 |             else | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 433 |             { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | 
| rjw | f98a5d8 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 446 |                     pthread_mutex_lock(&s_lynq_urc_vector_mutex); | 
 | 447 |                     s_data_urc_wait_list.push_back(apnId); | 
 | 448 |                     pthread_mutex_unlock(&s_lynq_urc_vector_mutex); | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 449 |                 } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 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 | d103738 | 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 | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 486 |         default: | 
 | 487 |             break; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 488 |     } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 489 |      | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 490 | } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 491 |  | 
 | 492 | void cleanup_urc_vector_mutex(void *arg) | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 493 | { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +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 | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 501 |     { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 502 |         while (!s_data_urc_wait_list.empty()) | 
 | 503 |         { | 
 | 504 |             sendSignalPdnChange(); | 
 | 505 |             usleep(10); | 
 | 506 |         } | 
 | 507 |         usleep(1); | 
 | 508 |     } | 
 | 509 |     pthread_cleanup_pop(0); | 
 | 510 | } | 
 | 511 |  | 
 | 512 | void cancel_urc_vector_signal_thread() | 
 | 513 | { | 
 | 514 |     int ret; | 
 | 515 |      | 
 | 516 |     data_urc_vector_status = 0; | 
 | 517 |     pthread_mutex_lock(&s_lynq_urc_vector_mutex); | 
 | 518 |     if (data_list_urc_vector_tid != -1) | 
 | 519 |     { | 
 | 520 |         ret = pthread_cancel(data_list_urc_vector_tid); | 
 | 521 |         LYDBGLOG("pthread cancel ret = %d",ret); | 
 | 522 |     } | 
 | 523 |     pthread_mutex_unlock(&s_lynq_urc_vector_mutex); | 
 | 524 |  | 
 | 525 |     if (data_list_urc_vector_tid != -1) | 
 | 526 |     { | 
 | 527 |         ret = pthread_join(data_list_urc_vector_tid,NULL); | 
 | 528 |         LYDBGLOG("pthread join ret = %d",ret); | 
 | 529 |         data_list_urc_vector_tid = -1; | 
 | 530 |     } | 
 | 531 |     pthread_mutex_lock(&s_lynq_urc_vector_mutex); | 
 | 532 |     s_data_urc_wait_list.clear(); | 
 | 533 |     pthread_mutex_unlock(&s_lynq_urc_vector_mutex); | 
 | 534 | } | 
 | 535 |  | 
 | 536 | int create_urc_vector_signal_thread() | 
 | 537 | { | 
 | 538 |     int ret; | 
 | 539 |  | 
 | 540 |     data_urc_vector_status = 1; | 
 | 541 |     pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL); | 
 | 542 |     ret = pthread_create(&data_list_urc_vector_tid,NULL,thread_urc_vector,NULL); | 
 | 543 |     if (ret < 0) | 
 | 544 |     { | 
 | 545 |         LYERRLOG("urc vector signal pthread create error"); | 
 | 546 |         lynq_deinit_data_urc_thread(); | 
 | 547 |         data_urc_vector_status = 0; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 548 |         return -1; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 549 |     } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 550 |     pthread_mutex_lock(&s_lynq_urc_vector_mutex); | 
 | 551 |     s_data_urc_wait_list.clear(); | 
 | 552 |     pthread_mutex_unlock(&s_lynq_urc_vector_mutex); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 553 |     return 0; | 
 | 554 | } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 555 |  | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 556 | int lynq_init_data(int uToken) | 
 | 557 | { | 
| rjw | 267d8ee | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 558 |     if (g_lynq_data_init_flag == 1) | 
 | 559 |     { | 
 | 560 |         LYERRLOG("init twice is not allowed"); | 
 | 561 |         return -1; | 
 | 562 |     } | 
 | 563 |     g_lynq_data_init_flag = 1; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 564 |     int result = 0; | 
 | 565 |     Global_uToken = uToken; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 566 |     LYLOGSET(LOG_INFO); | 
 | 567 |     LYLOGEINIT(USER_LOG_TAG); | 
 | 568 |     result = lynq_socket_client_start(); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 569 |     pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 570 |     if(result!=0) | 
 | 571 |     { | 
 | 572 |         LYERRLOG("init socket client fail!!!"); | 
 | 573 |         return -1; | 
 | 574 |     } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 575 |     result = lynq_init_data_urc_thread(); | 
 | 576 |     if(result!=0) | 
 | 577 |     { | 
 | 578 |         LYERRLOG("init socket urc fail!!!"); | 
 | 579 |         return -1; | 
 | 580 |     } | 
 | 581 |  | 
 | 582 |     result = create_urc_vector_signal_thread(); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 583 |     if(result!=0) | 
 | 584 |     { | 
 | 585 |         LYERRLOG("init socket urc fail!!!"); | 
 | 586 |         return -1; | 
 | 587 |     } | 
 | 588 |     memset(lynq_apn_table,0,sizeof(lynq_apn_table)); | 
 | 589 |     LYDBGLOG("lynq init call success!!!"); | 
 | 590 |     return 0; | 
 | 591 |  | 
 | 592 | } | 
 | 593 | int lynq_deinit_data() | 
 | 594 | { | 
 | 595 |     int ret = -1; | 
| rjw | 267d8ee | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 596 |     if (g_lynq_data_init_flag == 0) | 
 | 597 |     { | 
 | 598 |         LYERRLOG("deinit twice is not allowed"); | 
 | 599 |         return ret; | 
 | 600 |     } | 
 | 601 |     g_lynq_data_init_flag = 0; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 602 |     for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++) | 
 | 603 |     { | 
 | 604 |         if(strlen(lynq_apn_table[i].apnType)!=0) | 
 | 605 |         { | 
 | 606 |             lynq_deactive_data_call(&i); | 
 | 607 |         } | 
 | 608 |     } | 
 | 609 |     if(lynq_client_sockfd>0) | 
 | 610 |     { | 
 | 611 |         close(lynq_client_sockfd); | 
 | 612 |     } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 613 |     ret = lynq_deinit_data_urc_thread(); | 
 | 614 |     if (ret != 0) | 
| rjw | 267d8ee | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 615 |     { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 616 |         LYERRLOG("lynq_deinit_data_urc_thread fail"); | 
 | 617 |         return ret; | 
| rjw | 267d8ee | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 618 |     } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 619 |     cancel_urc_vector_signal_thread(); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 620 |     return 0; | 
 | 621 | } | 
 | 622 | int lynq_setup_data_call(int *handle) | 
 | 623 | { | 
 | 624 |     Parcel p; | 
 | 625 |     lynq_client_t client; | 
 | 626 |     int resp_type = -1; | 
 | 627 |     int request = -1; | 
 | 628 |     int slot_id = -1; | 
 | 629 |     int error = -1; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 630 |     int lynq_data_call_id = 0; | 
 | 631 |     if(handle==NULL) | 
 | 632 |     { | 
 | 633 |         LYERRLOG("handle is null!!!"); | 
 | 634 |         return LYNQ_E_NULL_ANONALY; | 
 | 635 |     } | 
 | 636 |     client.uToken = Global_uToken; | 
 | 637 |     client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL | 
 | 638 |     client.paramLen = 0; | 
 | 639 |     bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | 
 | 640 |     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 641 |     pthread_mutex_lock(&g_lynq_data_sendto_mutex); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 642 |     if(send_request(lynq_client_sockfd,&client)==-1) | 
 | 643 |     { | 
 | 644 |         LYERRLOG("send request fail"); | 
 | 645 |         perror("[LYNQ_DATA] send request fail:"); | 
 | 646 |         return -1; | 
 | 647 |     } | 
 | 648 |     get_response(lynq_client_sockfd,p); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 649 |     pthread_mutex_unlock(&g_lynq_data_sendto_mutex); | 
| rjw | 9c52278 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 650 |     JumpHeader(p,&resp_type,&request,&slot_id,&error); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 651 |     LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | 
 | 652 |     lynq_data_call_id = updateApn("default"); | 
 | 653 |     lynq_data_call = 1; | 
 | 654 |     if(error==0) | 
 | 655 |     { | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 656 |         if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 657 |         { | 
 | 658 |             error = LYNQ_E_TIME_OUT; | 
 | 659 |             LYERRLOG("timeout:wait data Call state fail!!!"); | 
 | 660 |             lynq_apn_table[lynq_data_call_id].hasTimeout = 1; | 
 | 661 |             return error; | 
 | 662 |         } | 
 | 663 |         *handle = lynq_data_call_id; | 
 | 664 |     } | 
 | 665 |     return error; | 
 | 666 | } | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 667 |  | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 668 | int lynq_deactive_data_call(int *handle) | 
 | 669 | { | 
 | 670 |     Parcel p; | 
 | 671 |     lynq_client_t client; | 
 | 672 |     int resp_type = -1; | 
 | 673 |     int request = -1; | 
 | 674 |     int slot_id = -1; | 
 | 675 |     int error = -1; | 
 | 676 |     int lynq_data_call_id = -1; | 
| rjw | 51dba88 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 677 |     int ret = 0; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 678 |     if(handle==NULL) | 
 | 679 |     { | 
 | 680 |         LYERRLOG("handle is null!!!"); | 
 | 681 |         return -1; | 
 | 682 |     } | 
| rjw | 51dba88 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 683 |     ret = handleCheck(*handle); | 
 | 684 |     if (ret != 0) | 
 | 685 |     { | 
 | 686 |         LYERRLOG("incomming handle is invalid"); | 
 | 687 |         return -1; | 
 | 688 |     } | 
 | 689 |     lynq_data_call_id = *handle; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 690 |     client.uToken = Global_uToken; | 
 | 691 |     client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL | 
 | 692 |     if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")==0) | 
 | 693 |     { | 
 | 694 |         client.paramLen = 0; | 
 | 695 |         bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 696 |     } | 
 | 697 |     else | 
 | 698 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 699 |         client.paramLen = 1; | 
 | 700 |         bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | 
 | 701 |         sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); | 
 | 702 |     } | 
 | 703 |     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 704 |     pthread_mutex_lock(&g_lynq_data_sendto_mutex); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 705 |     if(send_request(lynq_client_sockfd,&client)==-1) | 
 | 706 |     { | 
 | 707 |         LYERRLOG("send request fail"); | 
 | 708 |         perror("[LYNQ_DATA] send request fail:"); | 
 | 709 |         return -1; | 
 | 710 |     } | 
 | 711 |     get_response(lynq_client_sockfd,p); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 712 |     pthread_mutex_unlock(&g_lynq_data_sendto_mutex); | 
| rjw | 9c52278 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 713 |     JumpHeader(p,&resp_type,&request,&slot_id,&error); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 714 |     LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | 
 | 715 |     cleanOnceApnTable(lynq_data_call_id); | 
 | 716 |     return error; | 
 | 717 | } | 
 | 718 | int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol) | 
 | 719 | { | 
 | 720 |     Parcel p; | 
 | 721 |     lynq_client_t client; | 
 | 722 |     int resp_type = -1; | 
 | 723 |     int request = -1; | 
 | 724 |     int slot_id = -1; | 
 | 725 |     int error = -1; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 726 |     int lynq_data_call_id = -1; | 
 | 727 |     char *argv[10] = {}; | 
 | 728 |     if(handle==NULL||apn==NULL||apnType==NULL) | 
 | 729 |     { | 
 | 730 |         LYERRLOG("handle ,apn or apntype is null!!!"); | 
 | 731 |         return -1; | 
 | 732 |     } | 
 | 733 |     if(user==NULL) | 
 | 734 |     { | 
 | 735 |         argv[1] = "null"; | 
 | 736 |     } | 
 | 737 |     else | 
 | 738 |     { | 
 | 739 |         argv[1] = user; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 740 |     } | 
 | 741 |     if(password==NULL) | 
 | 742 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 743 |         argv[2] = "null"; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 744 |     } | 
 | 745 |     else | 
 | 746 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 747 |         argv[2] = password; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 748 |     } | 
 | 749 |     if(authType==NULL) | 
 | 750 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 751 |         argv[3] = "null"; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 752 |     } | 
 | 753 |     else | 
 | 754 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 755 |         argv[3] = authType; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 756 |     } | 
 | 757 |     if(normalProtocol==NULL) | 
 | 758 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 759 |         argv[4] = "null"; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 760 |     } | 
 | 761 |     else | 
 | 762 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 763 |         argv[4] = normalProtocol; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 764 |     } | 
 | 765 |     if(roamingProtocol==NULL) | 
 | 766 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 767 |         argv[5] = "null"; | 
| lh | e912a14 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 768 |     } | 
 | 769 |     else | 
 | 770 |     { | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 771 |         argv[5] = roamingProtocol; | 
 | 772 |     } | 
 | 773 |     client.uToken = Global_uToken; | 
 | 774 |     client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL | 
 | 775 |     client.paramLen = 7; | 
 | 776 |     bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | 
 | 777 |     sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); | 
 | 778 |     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 779 |     pthread_mutex_lock(&g_lynq_data_sendto_mutex); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 780 |     if(send_request(lynq_client_sockfd,&client)==-1) | 
 | 781 |     { | 
 | 782 |         LYERRLOG("send request fail"); | 
 | 783 |         perror("[LYNQ_DATA] send request fail:"); | 
 | 784 |         return -1; | 
 | 785 |     } | 
 | 786 |     get_response(lynq_client_sockfd,p); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 787 |     pthread_mutex_unlock(&g_lynq_data_sendto_mutex); | 
| rjw | 9c52278 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 788 |     JumpHeader(p,&resp_type,&request,&slot_id,&error); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 789 |     LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | 
 | 790 |     lynq_data_call_id = updateApn(apnType); | 
 | 791 |     lynq_data_call = 1; | 
 | 792 |     if(error==0) | 
 | 793 |     { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 794 |         if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 795 |         { | 
 | 796 |             error = LYNQ_E_TIME_OUT; | 
 | 797 |             LYERRLOG("timeout:wait data Call state fail!!!"); | 
 | 798 |             lynq_apn_table[lynq_data_call_id].hasTimeout = 1; | 
 | 799 |             return error; | 
 | 800 |         } | 
 | 801 |         *handle = lynq_data_call_id; | 
 | 802 |     } | 
 | 803 |     return error; | 
 | 804 | } | 
 | 805 | /* | 
 | 806 | int lynq_deactive_data_call_sp(int *handle,char *apnType) | 
 | 807 | { | 
 | 808 |     Parcel p; | 
 | 809 |     lynq_client_t client; | 
 | 810 |     int resp_type = -1; | 
 | 811 |     int request = -1; | 
 | 812 |     int slot_id = -1; | 
 | 813 |     int error = -1; | 
 | 814 |     if(handle==NULL||apnType==NULL) | 
 | 815 |     { | 
 | 816 |         LYERRLOG("handle is null!!!"); | 
 | 817 |         return -1; | 
 | 818 |     } | 
 | 819 |     client.uToken = Global_uToken; | 
 | 820 |     client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL | 
 | 821 |     client.paramLen = 1; | 
 | 822 |     bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | 
 | 823 |     sprintf(client.param,"%s",apnType); | 
 | 824 |     LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | 
 | 825 |     if(send_request(lynq_client_sockfd,&client)==-1) | 
 | 826 |     { | 
 | 827 |         LYERRLOG("send request fail"); | 
 | 828 |         perror("[LYNQ_DATA] send request fail:"); | 
 | 829 |         return -1; | 
 | 830 |     } | 
 | 831 |     get_response(lynq_client_sockfd,p); | 
| rjw | 9c52278 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 832 |     JumpHeader(p,&resp_type,&request,&slot_id,&error); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 833 |     LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | 
 | 834 |     return error; | 
 | 835 | } | 
 | 836 | */ | 
 | 837 | int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum) | 
 | 838 | { | 
 | 839 |     Parcel p; | 
 | 840 |     lynq_client_t client; | 
 | 841 |     int resp_type = -1; | 
| q.huang | 2befc3a | 2022-09-13 14:19:24 +0800 | [diff] [blame] | 842 |     int token; | 
 | 843 |     int request = -1;     | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 844 |     int slot_id = -1; | 
 | 845 |     int error = -1; | 
 | 846 |     int version =0; | 
 | 847 |     int num = 0; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 848 |     char *temp_char = NULL; | 
 | 849 |     if(dataCallList==NULL) | 
 | 850 |     { | 
 | 851 |         LYERRLOG("dataCallList is null!!!"); | 
 | 852 |         return -1; | 
 | 853 |     } | 
 | 854 |     client.uToken = Global_uToken; | 
 | 855 |     client.request = 57;//RIL_REQUEST_DATA_CALL_LIST | 
 | 856 |     client.paramLen = 0; | 
 | 857 |     bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | 
 | 858 |     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 859 |     pthread_mutex_lock(&g_lynq_data_sendto_mutex); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 860 |     if(send_request(lynq_client_sockfd,&client)==-1) | 
 | 861 |     { | 
 | 862 |         LYERRLOG("send request fail"); | 
 | 863 |         perror("[LYNQ_DATA] send request fail:"); | 
 | 864 |         return -1; | 
 | 865 |     } | 
 | 866 |     get_response(lynq_client_sockfd,p); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 867 |     pthread_mutex_unlock(&g_lynq_data_sendto_mutex); | 
| rjw | 9c52278 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 868 |     if(p.dataAvail() > 0) | 
 | 869 |     { | 
| rjw | 8990b8e | 2022-09-16 19:12:35 +0800 | [diff] [blame] | 870 |         p.readInt32(&resp_type); | 
 | 871 |         p.readInt32(&token); | 
 | 872 |         p.readInt32(&request); | 
 | 873 |         p.readInt32(&slot_id); | 
 | 874 |         p.readInt32(&error); | 
| rjw | 9c52278 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 875 |     } | 
 | 876 |     else | 
 | 877 |     { | 
 | 878 |         return -1; | 
 | 879 |     } | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 880 |     LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | 
 | 881 |     p.readInt32(&version); | 
 | 882 |     if(version==11) | 
 | 883 |     { | 
 | 884 |         p.readInt32(&num); | 
 | 885 |         *realNum = num; | 
 | 886 |         for (int i = 0; i < num; i++) | 
 | 887 |         { | 
 | 888 |             p.readInt32(&dataCallList[i].status); | 
 | 889 |             p.readInt32(&dataCallList[i].suggestedRetryTime); | 
 | 890 |             p.readInt32(&dataCallList[i].cid); | 
 | 891 |             p.readInt32(&dataCallList[i].active); | 
 | 892 |             temp_char = strdupReadString(p); | 
 | 893 |             memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1); | 
 | 894 |             temp_char = strdupReadString(p); | 
 | 895 |             memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1); | 
 | 896 |             temp_char = strdupReadString(p); | 
 | 897 |             memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1); | 
 | 898 |             temp_char = strdupReadString(p); | 
 | 899 |             memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1); | 
 | 900 |             temp_char = strdupReadString(p); | 
 | 901 |             memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1); | 
 | 902 |             temp_char = strdupReadString(p); | 
 | 903 |             memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1); | 
 | 904 |             p.readInt32(&dataCallList[i].mtu); | 
 | 905 |         } | 
 | 906 |     } | 
 | 907 |     return error; | 
 | 908 | } | 
 | 909 | int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList) | 
 | 910 | { | 
 | 911 |     lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={}; | 
 | 912 |     int number = 0; | 
 | 913 |     int lynq_data_call_id = 0; | 
 | 914 |     int error = 0; | 
 | 915 |     lynq_data_call_id = *handle; | 
 | 916 |     if(handle==NULL) | 
 | 917 |     { | 
 | 918 |         LYERRLOG("handle is NULL"); | 
 | 919 |         return LYNQ_E_NULL_ANONALY; | 
 | 920 |     } | 
| rjw | f98a5d8 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 921 |     if (*handle<0 && handle>8) | 
 | 922 |     { | 
 | 923 |         LYERRLOG("handle value error"); | 
 | 924 |     } | 
 | 925 |     LYINFLOG("incoming handle value: %d",*handle); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 926 |     memset(interDataCallList,0,sizeof(interDataCallList)); | 
 | 927 |     error = getDataCallLists(interDataCallList,&number); | 
 | 928 |     if(error == 0) | 
 | 929 |     { | 
 | 930 |         for(int i = 0;i < number;i++) | 
 | 931 |         { | 
 | 932 |             if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0) | 
 | 933 |             { | 
 | 934 |                 dataCallList->active = interDataCallList[i].active; | 
 | 935 |                 dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime; | 
 | 936 |                 dataCallList->cid = interDataCallList[i].cid; | 
 | 937 |                 dataCallList->status = interDataCallList[i].status; | 
 | 938 |                 dataCallList->mtu = interDataCallList[i].mtu; | 
 | 939 |                 memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses)); | 
 | 940 |                 memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname)); | 
 | 941 |                 memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses)); | 
 | 942 |                 memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type)); | 
 | 943 |                 memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways)); | 
 | 944 |                 memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf)); | 
 | 945 |                 LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses); | 
 | 946 |             } | 
 | 947 |         } | 
 | 948 |     } | 
 | 949 |     return error; | 
 | 950 | } | 
 | 951 | int lynq_wait_data_call_state_change(int *handle) | 
 | 952 | { | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 953 |      | 
 | 954 |     std::vector<int>::iterator iter; | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 955 |     waitPdnChange(); | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 956 |  | 
 | 957 |     pthread_mutex_lock(&s_lynq_urc_vector_mutex); | 
 | 958 |     iter = s_data_urc_wait_list.begin(); | 
| rjw | f98a5d8 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 959 |     *handle = s_data_urc_wait_list.front(); | 
 | 960 |  | 
| rjw | 3d6a50e | 2023-02-20 13:35:42 +0800 | [diff] [blame] | 961 |     s_data_urc_wait_list.erase(iter); | 
 | 962 |     pthread_mutex_unlock(&s_lynq_urc_vector_mutex); | 
 | 963 |      | 
| rjw | f98a5d8 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 964 |     LYINFLOG("lynq data call id:%d",*handle); | 
| lh | aa28307 | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 965 |     return 0; | 
 | 966 | } | 
 | 967 | /*Warren add for T800 platform 2021/11/19 end*/ | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 968 |  | 
 | 969 | /*Typethree add for T800 platform 2022/04/21 start*/ | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 970 |  | 
 | 971 | 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 | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 972 | { | 
 | 973 |     char strtmp[10][32]; | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 974 |     if (id == NULL) | 
| rjw | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 975 |     { | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 976 |         sprintf(strtmp[0], "id=;"); | 
| rjw | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 977 |     } | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 978 |     else | 
| rjw | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 979 |     { | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 980 |         sprintf(strtmp[0], "id=%s;", id); | 
| rjw | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 981 |     } | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 982 |     if (mcc == NULL) | 
 | 983 |     { | 
 | 984 |         sprintf(strtmp[1], "mcc=;"); | 
 | 985 |     } | 
 | 986 |     else | 
 | 987 |     { | 
 | 988 |         sprintf(strtmp[1], "mcc=%s;", mcc); | 
 | 989 |     } | 
 | 990 |     if (mnc == NULL) | 
 | 991 |     { | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 992 |         sprintf(strtmp[2], "mnc=;"); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 993 |     } | 
 | 994 |     else | 
 | 995 |     { | 
 | 996 |         sprintf(strtmp[2], "mnc=%s;", mnc); | 
 | 997 |     } | 
 | 998 |     if (apn == NULL) | 
 | 999 |     { | 
 | 1000 |         sprintf(strtmp[3], "apn=;"); | 
 | 1001 |     } | 
 | 1002 |     else | 
 | 1003 |     { | 
 | 1004 |         sprintf(strtmp[3], "apn=%s;", apn); | 
 | 1005 |     } | 
 | 1006 |     if (apntype == NULL) | 
 | 1007 |     { | 
 | 1008 |         sprintf(strtmp[4], "apntype=;"); | 
 | 1009 |     } | 
 | 1010 |     else | 
 | 1011 |     { | 
 | 1012 |         sprintf(strtmp[4], "apntype=%s;", apntype); | 
 | 1013 |     } | 
 | 1014 |     if (user == NULL) | 
 | 1015 |     { | 
 | 1016 |         sprintf(strtmp[5], "user=;"); | 
 | 1017 |     } | 
 | 1018 |     else | 
 | 1019 |     { | 
 | 1020 |         sprintf(strtmp[5], "user=%s;", user); | 
 | 1021 |     } | 
 | 1022 |     if (password == NULL) | 
 | 1023 |     { | 
 | 1024 |         sprintf(strtmp[6], "password=;"); | 
 | 1025 |     } | 
 | 1026 |     else | 
 | 1027 |     { | 
 | 1028 |         sprintf(strtmp[6], "password=%s;", password); | 
 | 1029 |     } | 
 | 1030 |     if (normalprotocol == NULL) | 
 | 1031 |     { | 
 | 1032 |         sprintf(strtmp[7], "normalprotocol=;"); | 
 | 1033 |     } | 
 | 1034 |     else | 
 | 1035 |     { | 
 | 1036 |         sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); | 
 | 1037 |     } | 
 | 1038 |     if (roamingprotocol == NULL) | 
 | 1039 |     { | 
 | 1040 |         sprintf(strtmp[8], "roamingprotocol=;"); | 
 | 1041 |     } | 
 | 1042 |     else | 
 | 1043 |     { | 
 | 1044 |         sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); | 
 | 1045 |     } | 
 | 1046 |     if (carrier == NULL) | 
 | 1047 |     { | 
 | 1048 |         sprintf(strtmp[9], "carrier=;"); | 
 | 1049 |     } | 
 | 1050 |     else | 
 | 1051 |     { | 
 | 1052 |         sprintf(strtmp[9], "carrier=%s;", carrier); | 
 | 1053 |     } | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1054 |     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 | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1055 |  | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1056 |     return 0; | 
 | 1057 | } | 
 | 1058 |  | 
 | 1059 | 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) | 
 | 1060 | { | 
 | 1061 |     char strtmp[10][32]; | 
 | 1062 |     if (id == NULL) | 
 | 1063 |     { | 
 | 1064 |         sprintf(strtmp[0], "id=;"); | 
 | 1065 |     } | 
 | 1066 |     else | 
 | 1067 |     { | 
 | 1068 |         sprintf(strtmp[0], "id=%s;", id); | 
 | 1069 |     } | 
 | 1070 |     if (mcc == NULL) | 
 | 1071 |     { | 
 | 1072 |         sprintf(strtmp[1], "mcc=;"); | 
 | 1073 |     } | 
 | 1074 |     else | 
 | 1075 |     { | 
 | 1076 |         sprintf(strtmp[1], "mcc=%s;", mcc); | 
 | 1077 |     } | 
 | 1078 |     if (mnc == NULL) | 
 | 1079 |     { | 
 | 1080 |         sprintf(strtmp[2], "mnc=;"); | 
 | 1081 |     } | 
 | 1082 |     else | 
 | 1083 |     { | 
 | 1084 |         sprintf(strtmp[2], "mnc=%s;", mnc); | 
 | 1085 |     } | 
 | 1086 |     if (apn == NULL) | 
 | 1087 |     { | 
 | 1088 |         sprintf(strtmp[3], "apn=;"); | 
 | 1089 |     } | 
 | 1090 |     else | 
 | 1091 |     { | 
 | 1092 |         sprintf(strtmp[3], "apn=%s;", apn); | 
 | 1093 |     } | 
 | 1094 |     if (apntype == NULL) | 
 | 1095 |     { | 
 | 1096 |         sprintf(strtmp[4], "apntype=;"); | 
 | 1097 |     } | 
 | 1098 |     else | 
 | 1099 |     { | 
 | 1100 |         sprintf(strtmp[4], "apntype=%s;", apntype); | 
 | 1101 |     } | 
 | 1102 |     if (user == NULL) | 
 | 1103 |     { | 
 | 1104 |         sprintf(strtmp[5], "user=;"); | 
 | 1105 |     } | 
 | 1106 |     else | 
 | 1107 |     { | 
 | 1108 |         sprintf(strtmp[5], "user=%s;", user); | 
 | 1109 |     } | 
 | 1110 |     if (password == NULL) | 
 | 1111 |     { | 
 | 1112 |         sprintf(strtmp[6], "password=;"); | 
 | 1113 |     } | 
 | 1114 |     else | 
 | 1115 |     { | 
 | 1116 |         sprintf(strtmp[6], "password=%s;", password); | 
 | 1117 |     } | 
 | 1118 |     if (normalprotocol == NULL) | 
 | 1119 |     { | 
 | 1120 |         sprintf(strtmp[7], "normalprotocol=;"); | 
 | 1121 |     } | 
 | 1122 |     else | 
 | 1123 |     { | 
 | 1124 |         sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); | 
 | 1125 |     } | 
 | 1126 |     if (roamingprotocol == NULL) | 
 | 1127 |     { | 
 | 1128 |         sprintf(strtmp[8], "roamingprotocol=;"); | 
 | 1129 |     } | 
 | 1130 |     else | 
 | 1131 |     { | 
 | 1132 |         sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); | 
 | 1133 |     } | 
 | 1134 |     if (carrier == NULL) | 
 | 1135 |     { | 
 | 1136 |         sprintf(strtmp[9], "carrier=;"); | 
 | 1137 |     } | 
 | 1138 |     else | 
 | 1139 |     { | 
 | 1140 |         sprintf(strtmp[9], "carrier=%s;", carrier); | 
 | 1141 |     } | 
 | 1142 |     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]); | 
 | 1143 |     return 0; | 
 | 1144 | } | 
 | 1145 |  | 
| rjw | 6df787d | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1146 |  | 
 | 1147 | 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) | 
 | 1148 | { | 
 | 1149 |     char strtmp[10][32]; | 
 | 1150 |     if (id == NULL) | 
 | 1151 |     { | 
 | 1152 |         sprintf(strtmp[0], ""); | 
 | 1153 |     } | 
 | 1154 |     else | 
 | 1155 |     { | 
 | 1156 |         sprintf(strtmp[0], "id=%s;", id); | 
 | 1157 |     } | 
 | 1158 |     if (mcc == NULL) | 
 | 1159 |     { | 
 | 1160 |         sprintf(strtmp[1], ""); | 
 | 1161 |     } | 
 | 1162 |     else | 
 | 1163 |     { | 
 | 1164 |         sprintf(strtmp[1], "mcc=%s;", mcc); | 
 | 1165 |     } | 
 | 1166 |     if (mnc == NULL) | 
 | 1167 |     { | 
 | 1168 |         sprintf(strtmp[2], ""); | 
 | 1169 |     } | 
 | 1170 |     else | 
 | 1171 |     { | 
 | 1172 |         sprintf(strtmp[2], "mnc=%s;", mnc); | 
 | 1173 |     } | 
 | 1174 |     if (apn == NULL) | 
 | 1175 |     { | 
 | 1176 |         sprintf(strtmp[3], ""); | 
 | 1177 |     } | 
 | 1178 |     else | 
 | 1179 |     { | 
 | 1180 |         sprintf(strtmp[3], "apn=%s;", apn); | 
 | 1181 |     } | 
 | 1182 |     if (apntype == NULL) | 
 | 1183 |     { | 
 | 1184 |         sprintf(strtmp[4], ""); | 
 | 1185 |     } | 
 | 1186 |     else | 
 | 1187 |     { | 
 | 1188 |         sprintf(strtmp[4], "apntype=%s;", apntype); | 
 | 1189 |     } | 
 | 1190 |     if (user == NULL) | 
 | 1191 |     { | 
 | 1192 |         sprintf(strtmp[5], ""); | 
 | 1193 |     } | 
 | 1194 |     else | 
 | 1195 |     { | 
 | 1196 |         sprintf(strtmp[5], "user=%s;", user); | 
 | 1197 |     } | 
 | 1198 |     if (password == NULL) | 
 | 1199 |     { | 
 | 1200 |         sprintf(strtmp[6], ""); | 
 | 1201 |     } | 
 | 1202 |     else | 
 | 1203 |     { | 
 | 1204 |         sprintf(strtmp[6], "password=%s;", password); | 
 | 1205 |     } | 
 | 1206 |     if (normalprotocol == NULL) | 
 | 1207 |     { | 
 | 1208 |         sprintf(strtmp[7], ""); | 
 | 1209 |     } | 
 | 1210 |     else | 
 | 1211 |     { | 
 | 1212 |         sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); | 
 | 1213 |     } | 
 | 1214 |     if (roamingprotocol == NULL) | 
 | 1215 |     { | 
 | 1216 |         sprintf(strtmp[8], ""); | 
 | 1217 |     } | 
 | 1218 |     else | 
 | 1219 |     { | 
 | 1220 |         sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); | 
 | 1221 |     } | 
 | 1222 |     if (carrier == NULL) | 
 | 1223 |     { | 
 | 1224 |         sprintf(strtmp[9], ""); | 
 | 1225 |     } | 
 | 1226 |     else | 
 | 1227 |     { | 
 | 1228 |         sprintf(strtmp[9], "carrier=%s;", carrier); | 
 | 1229 |     } | 
 | 1230 |     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]); | 
 | 1231 |     return 0; | 
 | 1232 | } | 
 | 1233 |  | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1234 | static char *lynqStrdupReadString(Parcel &p) | 
 | 1235 | { | 
 | 1236 |     size_t stringlen; | 
 | 1237 |     const char16_t *s16; | 
 | 1238 |  | 
 | 1239 |     s16 = p.readString16Inplace(&stringlen); | 
 | 1240 |     return strndup16to8(s16, stringlen); | 
 | 1241 | } | 
 | 1242 |  | 
 | 1243 | 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) | 
 | 1244 | { | 
 | 1245 |     if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier) | 
 | 1246 |     { | 
 | 1247 |         LYERRLOG("There are no valid parameters"); | 
 | 1248 |         return -1; | 
 | 1249 |     } | 
 | 1250 |     lynq_client_t client; | 
 | 1251 |     char argc[512]; | 
| rjw | 6184a25 | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1252 |     int res = 0; | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1253 |     Parcel p; | 
 | 1254 |     if (cmd == 0) // insert apn db | 
 | 1255 |     { | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1256 |         res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); | 
 | 1257 |  | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1258 |         client.uToken = Global_uToken; | 
 | 1259 |         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN | 
 | 1260 |         client.paramLen = 2; | 
 | 1261 |         bzero(client.param, LYNQ_REQUEST_PARAM_BUF); | 
 | 1262 |         sprintf(client.param, "%d %s", cmd, argc); | 
 | 1263 |     } | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1264 |     else if (cmd == 1) //delete apn db | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1265 |     { | 
 | 1266 |         if (NULL == id) | 
 | 1267 |         { | 
 | 1268 |             LYERRLOG("id is NULL!!!please input id: "); | 
 | 1269 |         } | 
 | 1270 |         sprintf(argc, "id=%s", id); | 
 | 1271 |         client.uToken = Global_uToken; | 
 | 1272 |         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN | 
 | 1273 |         client.paramLen = 2; | 
 | 1274 |         bzero(client.param, LYNQ_REQUEST_PARAM_BUF); | 
 | 1275 |         sprintf(client.param, "%d %s", cmd, argc); | 
 | 1276 |     } | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1277 |     else if (cmd == 2) //query apn db | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1278 |     { | 
| rjw | 6df787d | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1279 |         query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1280 |         client.uToken = Global_uToken; | 
 | 1281 |         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN | 
 | 1282 |         client.paramLen = 2; | 
 | 1283 |         bzero(client.param, LYNQ_REQUEST_PARAM_BUF); | 
 | 1284 |         sprintf(client.param, "%d %s", cmd, argc); | 
 | 1285 |     } | 
| rjw | efd4861 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1286 |     else if (cmd == 3)  //modify apn db | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1287 |     { | 
 | 1288 |         modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); | 
 | 1289 |         client.uToken = Global_uToken; | 
 | 1290 |         client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN | 
 | 1291 |         client.paramLen = 2; | 
 | 1292 |         bzero(client.param, LYNQ_REQUEST_PARAM_BUF); | 
 | 1293 |         sprintf(client.param, "%d %s", cmd, argc); | 
 | 1294 |     } | 
 | 1295 |     else | 
 | 1296 |     { | 
 | 1297 |         LYERRLOG("incoming command is invalid"); | 
 | 1298 |         return -1; | 
 | 1299 |     } | 
 | 1300 |     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1301 |     pthread_mutex_lock(&g_lynq_data_sendto_mutex); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1302 |     if(send_request(lynq_client_sockfd,&client)==-1) | 
 | 1303 |     { | 
 | 1304 |         LYERRLOG("send request fail"); | 
 | 1305 |         return -1; | 
 | 1306 |     } | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1307 |     pthread_mutex_unlock(&g_lynq_data_sendto_mutex); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1308 |     waitApnResult(); | 
| rjw | 6f5380f | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1309 |     strcpy(out, g_lynq_apn_result); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1310 |     LYINFLOG(">>>>>output info:%s",out); | 
 | 1311 |     return 0; | 
 | 1312 | } | 
 | 1313 |  | 
 | 1314 | int lynq_reset_apn(char *result) | 
 | 1315 | { | 
 | 1316 |     Parcel p; | 
 | 1317 |     lynq_client_t client; | 
| rjw | 6f5380f | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1318 |     if (NULL == result) | 
 | 1319 |     { | 
 | 1320 |         LYERRLOG("incoming paramters error"); | 
 | 1321 |     } | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1322 |     client.uToken = Global_uToken; | 
 | 1323 |     client.request = 2000 + 194; | 
 | 1324 |     client.paramLen = 0; | 
 | 1325 |     bzero(client.param, LYNQ_REQUEST_PARAM_BUF); | 
 | 1326 |     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s", client.uToken, client.request, client.paramLen, client.param); | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1327 |     pthread_mutex_lock(&g_lynq_data_sendto_mutex); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1328 |     if (send_request(lynq_client_sockfd, &client) == -1) | 
 | 1329 |     { | 
 | 1330 |         LYERRLOG("send request fail"); | 
 | 1331 |         return -1; | 
 | 1332 |     } | 
| rjw | 9a46163 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1333 |     pthread_mutex_unlock(&g_lynq_data_sendto_mutex); | 
| rjw | d103738 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1334 |     waitApnResult(); | 
 | 1335 |     strcpy(result, g_lynq_apn_result); | 
 | 1336 |     LYINFLOG(">>>>>result:%s",result); | 
 | 1337 |     return 0; | 
 | 1338 | } | 
 | 1339 |  | 
| rjw | 6f5380f | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1340 | /*Typethree add for T800 platform 2022/04/21 end*/ |