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