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 |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 28 | #define LYNQ_DATA_TIME_OUT 1000*120 |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 29 | |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 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, |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 52 | LYNQ_E_GET_RESP_FAIL = 8008, |
| 53 | LYNQ_E_NOT_THIS_APN = 8087, |
| 54 | LYNQ_E_NOT_ANY_APN = 8088, |
| 55 | LYNQ_E_MD_NOT_READY = 8089, |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 56 | /* The logic conflict*/ |
| 57 | LYNQ_E_CONFLICT=9000, |
| 58 | /*Null anomaly*/ |
| 59 | LYNQ_E_NULL_ANONALY=9001 |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 60 | }LYNQ_E; |
| 61 | |
| 62 | int lynq_client_sockfd = 0; |
| 63 | int Global_uToken = 0; |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 64 | struct sockaddr_in lynq_data_socket_server_addr; |
| 65 | int lynq_data_socket_server_addr_len; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 66 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 67 | int lynq_data_call_change_id = -1; |
| 68 | pthread_t lynq_data_tid =-1; |
| 69 | static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 70 | static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 71 | |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 72 | static pthread_mutex_t s_data_call_deactived_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 73 | static pthread_cond_t s_data_call_deactived_cond = PTHREAD_COND_INITIALIZER; |
| 74 | |
| 75 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 76 | static pthread_mutex_t s_lynq_apn_change_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 77 | static pthread_cond_t s_lynq_apn_change_cond = PTHREAD_COND_INITIALIZER; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 78 | static pthread_mutex_t s_lynq_urc_vector_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 79 | static pthread_cond_t s_lynq_urc_vector_cond = PTHREAD_COND_INITIALIZER; |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 80 | /**g_lynq_data_sendto_mutex |
| 81 | * @brief mark data send request mutex |
| 82 | */ |
| 83 | static pthread_mutex_t g_lynq_data_sendto_mutex; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 84 | /*This value data the state of the wait*/ |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 85 | static int data_waiting_status = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 86 | /*The value indicates that 8085 error occurs in data*/ |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 87 | static int data_invaild_error = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 88 | /*This value ensure the data call timing is correct*/ |
| 89 | static int data_timelimit = 0; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 90 | |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 91 | /**g_lynq_data_init_flag |
| 92 | * @brief mark data initialization state |
| 93 | * 0:deinit status |
| 94 | * 1:init state |
| 95 | */ |
| 96 | static int g_lynq_data_init_flag = 0; |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 97 | /**g_lynq_apn_result |
| 98 | * @brief temp of apn result info |
| 99 | */ |
| 100 | char g_lynq_apn_result[1024] = {}; |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 101 | |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 102 | static std::vector<int> s_data_urc_wait_list; |
| 103 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 104 | typedef struct |
| 105 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 106 | char apn[LYNQ_APN_MAX_LEN]; |
| 107 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
| 108 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
| 109 | int hasUsed; |
| 110 | int hasTimeout; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 111 | int status; |
| 112 | char statusApnType[LYNQ_APN_TYPE_MAX_LEN]; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 113 | }lynq_apn_t; |
| 114 | lynq_apn_t lynq_apn_table[LYNQ_APN_CHANNEL_MAX] = {}; |
| 115 | lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {}; |
| 116 | int lynq_data_call = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 117 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 118 | int getLynqApnID(char apnType[]) |
| 119 | { |
| 120 | int ret = 0; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 121 | int len = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 122 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 123 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 124 | len = strlen(apnType); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 125 | LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len); |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 126 | if(strncmp(lynq_apn_table[ret].apnType,apnType,len)==0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 127 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 128 | return ret; |
| 129 | } |
| 130 | } |
| 131 | return -1; |
| 132 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 133 | |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 134 | int getDeactApnID(char apnType[]) |
| 135 | { |
| 136 | int ret = 0; |
| 137 | int len = 0; |
| 138 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 139 | { |
| 140 | len = strlen(apnType); |
| 141 | LYINFLOG("apn_table[%d].apnType:%s,input apntype:%s,len:%d",ret,lynq_apn_table[ret].apnType,apnType,len); |
| 142 | if(strncmp(lynq_apn_table[ret].statusApnType,apnType,len)==0) |
| 143 | { |
| 144 | return ret; |
| 145 | } |
| 146 | } |
| 147 | return -1; |
| 148 | } |
| 149 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 150 | void updateApnTable(lynq_apn_t *apn_table,char apn[],char apntype[],char ifaceName[]) |
| 151 | { |
| 152 | LYDBGLOG("[updateApnTable] apn:%s,apntype:%s,ifaceName:%s",apn,apntype,ifaceName); |
| 153 | if(apn_table==NULL) |
| 154 | { |
| 155 | LYERRLOG("apn_table is null"); |
| 156 | return; |
| 157 | } |
| 158 | memcpy(apn_table->apn,apn,strlen(apn)+1); |
| 159 | memcpy(apn_table->apnType,apntype,strlen(apntype)+1); |
| 160 | memcpy(apn_table->ifaceName,ifaceName,strlen(ifaceName)+1); |
| 161 | apn_table->hasTimeout = 0; |
| 162 | apn_table->hasUsed = 1; |
| 163 | return; |
| 164 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 165 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 166 | void cleanOnceApnTable(int apnId) |
| 167 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 168 | LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 169 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 170 | { |
| 171 | LYERRLOG("apn id is invalid!!!"); |
| 172 | return; |
| 173 | } |
| 174 | lynq_apn_table[apnId].hasTimeout = 0; |
| 175 | lynq_apn_table[apnId].hasUsed = 0; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 176 | memcpy(lynq_apn_table[apnId].statusApnType,lynq_apn_table[apnId].apnType,strlen(lynq_apn_table[apnId].apnType)); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 177 | bzero(lynq_apn_table[apnId].apn,LYNQ_APN_MAX_LEN); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 178 | bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 179 | bzero(lynq_apn_table[apnId].ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 180 | lynq_apn_table[apnId].status = 32; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 181 | return; |
| 182 | } |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 183 | void cleanDeactApn(int apnId) |
| 184 | { |
| 185 | LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId); |
| 186 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 187 | { |
| 188 | LYERRLOG("apn id is invalid!!!"); |
| 189 | return; |
| 190 | } |
| 191 | lynq_apn_table[apnId].status = 0; |
| 192 | bzero(lynq_apn_table[apnId].statusApnType,LYNQ_APN_TYPE_MAX_LEN); |
| 193 | } |
| 194 | |
| 195 | void updateDeactApn(int apnId,int pdnState) |
| 196 | { |
| 197 | LYDBGLOG("%s:apn id:%d",__FUNCTION__,apnId); |
| 198 | if((apnId < 0) || (apnId > LYNQ_APN_CHANNEL_MAX-1)) |
| 199 | { |
| 200 | LYERRLOG("apn id is invalid!!!"); |
| 201 | return; |
| 202 | } |
| 203 | lynq_apn_table[apnId].status = pdnState; |
| 204 | } |
| 205 | |
| 206 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 207 | int getUnusedElement() |
| 208 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 209 | if (lynq_apn_table == NULL) |
| 210 | { |
| 211 | LYERRLOG("get UnusedElemnt apn_table is null"); |
| 212 | return -1; |
| 213 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 214 | for(int i=0;i < LYNQ_APN_CHANNEL_MAX; i++) |
| 215 | { |
| 216 | if(lynq_apn_table[i].hasUsed!=1) |
| 217 | { |
| 218 | return i; |
| 219 | } |
| 220 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 221 | LYERRLOG("None of get unused Element"); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 222 | return -1; |
| 223 | } |
| 224 | int updateApn(char apnType[]) |
| 225 | { |
| 226 | int ret = 0; |
| 227 | ret = getUnusedElement(); |
Hong_Liu | 5566871 | 2023-05-16 21:49:17 -0700 | [diff] [blame] | 228 | if(ret >= 0) |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 229 | { |
| 230 | memcpy(lynq_apn_table[ret].apnType,apnType,strlen(apnType)+1); |
| 231 | lynq_apn_table[ret].hasUsed = 1; |
| 232 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 233 | return ret; |
| 234 | } |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 235 | |
| 236 | int handleCheck(int handle) |
| 237 | { |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 238 | if ((handle >= 0) && (handle <= 6)) |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 239 | { |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 240 | if (lynq_apn_table[handle].hasUsed == 1) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 244 | return -1; |
| 245 | } |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 246 | return -1; |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 247 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 248 | int waitApnResult() |
| 249 | { |
| 250 | int ret = 0; |
| 251 | LYINFLOG("start wait apn result!!!"); |
| 252 | int sec = 0; |
| 253 | int usec = 0; |
| 254 | struct timeval now; |
| 255 | struct timespec timeout; |
| 256 | gettimeofday(&now, NULL); |
| 257 | sec = 20000 / 1000; |
| 258 | usec = 20000 % 1000; |
| 259 | timeout.tv_sec = now.tv_sec + sec; |
| 260 | timeout.tv_nsec = now.tv_usec * 1000 + usec * 1000000; |
| 261 | pthread_mutex_lock(&s_lynq_apn_change_mutex); |
| 262 | ret = pthread_cond_timedwait(&s_lynq_apn_change_cond, &s_lynq_apn_change_mutex, &timeout); |
| 263 | pthread_mutex_unlock(&s_lynq_apn_change_mutex); |
| 264 | return ret; |
| 265 | } |
| 266 | |
| 267 | void sendSignalApnChange() |
| 268 | { |
| 269 | LYINFLOG("start send Signal Apn Change"); |
| 270 | pthread_mutex_lock(&s_lynq_apn_change_mutex); |
| 271 | pthread_cond_signal(&s_lynq_apn_change_cond); |
| 272 | pthread_mutex_unlock(&s_lynq_apn_change_mutex); |
| 273 | return; |
| 274 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 275 | |
| 276 | int waitPdnChange() |
| 277 | { |
| 278 | int ret = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 279 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 280 | ret = pthread_cond_wait(&s_lynq_urc_vector_cond,&s_lynq_urc_vector_mutex); |
| 281 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 282 | return ret; |
| 283 | } |
| 284 | int waitDataCallstateChange(int mtime) |
| 285 | { |
| 286 | int ret = 0; |
| 287 | int sec = 0; |
| 288 | int usec = 0; |
| 289 | struct timeval now; |
| 290 | struct timespec timeout; |
| 291 | gettimeofday(&now,NULL); |
| 292 | sec = mtime/1000; |
| 293 | usec = mtime%1000; |
| 294 | timeout.tv_sec = now.tv_sec+sec; |
| 295 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000; |
| 296 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 297 | ret = pthread_cond_timedwait(&s_data_call_state_change_cond,&s_data_call_state_change_mutex,&timeout); |
| 298 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 299 | return ret; |
| 300 | } |
| 301 | void sendSignalDataCallStateChange() |
| 302 | { |
| 303 | pthread_mutex_lock(&s_data_call_state_change_mutex); |
| 304 | pthread_cond_signal(&s_data_call_state_change_cond); |
| 305 | pthread_mutex_unlock(&s_data_call_state_change_mutex); |
| 306 | return; |
| 307 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 308 | int waitDeactived(int mtime) |
| 309 | { |
| 310 | int ret = 0; |
| 311 | int sec = 0; |
| 312 | int usec = 0; |
| 313 | struct timeval now; |
| 314 | struct timespec timeout; |
| 315 | gettimeofday(&now,NULL); |
| 316 | sec = mtime/1000; |
| 317 | usec = mtime%1000; |
| 318 | timeout.tv_sec = now.tv_sec+sec; |
| 319 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000; |
| 320 | pthread_mutex_lock(&s_data_call_deactived_mutex); |
| 321 | ret = pthread_cond_timedwait(&s_data_call_deactived_cond,&s_data_call_deactived_mutex,&timeout); |
| 322 | pthread_mutex_unlock(&s_data_call_deactived_mutex); |
| 323 | return ret; |
| 324 | } |
| 325 | void sendSignalDeactvied() |
| 326 | { |
| 327 | pthread_mutex_lock(&s_data_call_deactived_mutex); |
| 328 | pthread_cond_signal(&s_data_call_deactived_cond); |
| 329 | pthread_mutex_unlock(&s_data_call_deactived_mutex); |
| 330 | return; |
| 331 | } |
| 332 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 333 | void sendSignalPdnChange() |
| 334 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 335 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 336 | pthread_cond_signal(&s_lynq_urc_vector_cond); |
| 337 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 338 | return; |
| 339 | } |
| 340 | |
| 341 | int get_response(int sockfd,Parcel &p) |
| 342 | { |
| 343 | int len = 0; |
| 344 | char recvline[LYNQ_REC_BUF]; |
| 345 | bzero(recvline,LYNQ_REC_BUF); |
| 346 | /* receive data from server */ |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 347 | len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len); |
| 348 | //len = read(sockfd, recvline, LYNQ_REC_BUF); |
rjw | 0852868 | 2022-07-04 21:28:02 +0800 | [diff] [blame] | 349 | if(len == -1) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 350 | { |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 351 | LYERRLOG("get_response fail,errno:%d",errno); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 352 | return -1; |
| 353 | } |
| 354 | if (recvline != NULL) { |
| 355 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen); |
| 356 | p.setDataPosition(0); |
| 357 | } |
| 358 | return 0; |
| 359 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 360 | /**@brief get utoken in range 0 to 10000 |
| 361 | * @return utoken |
| 362 | */ |
| 363 | int get_utoken() |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 364 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 365 | return (Global_uToken++)%10000;/*0-10000*/ |
| 366 | } |
| 367 | /**@brief wait response with expected token and write msg to parcel in some time |
| 368 | * @param fd [IN]: socket fd |
| 369 | * @param p [OUT]: quote the parcel,if return success need delete p. |
| 370 | * @param token [IN]: the expected token for the response msg |
| 371 | * @return |
| 372 | * 0:success |
| 373 | * other:failure |
| 374 | */ |
| 375 | int wait_response(int sockfd,Parcel *& p,int utoken) |
| 376 | { |
| 377 | int len = 0; |
| 378 | int flag = 1; |
| 379 | int count = 0; |
| 380 | int in_utoken = -1; |
| 381 | int resp_type = -1; |
| 382 | Parcel *temp = NULL; |
| 383 | char recvline[LYNQ_REC_BUF]; |
| 384 | //Sometimes the socket is abnormal, causing the socket buffer to store the response of the last request. |
| 385 | //Here it does not return until the response corresponding to the request is read. |
| 386 | while(flag && (count < 20))//why? |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 387 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 388 | bzero(recvline,LYNQ_REC_BUF); |
| 389 | count++; |
| 390 | LYINFLOG("wait_response,count:%d",count); |
| 391 | len = recvfrom(sockfd,recvline,LYNQ_REC_BUF,0,(struct sockaddr *)&lynq_data_socket_server_addr,(socklen_t *)&lynq_data_socket_server_addr_len); |
| 392 | if(len == -1) |
| 393 | { |
| 394 | LYERRLOG("wait_response fail,errno:%d",errno); |
| 395 | return LYNQ_E_GET_RESP_FAIL; |
| 396 | } |
| 397 | if (len != 0) |
| 398 | { |
| 399 | temp = new Parcel; |
| 400 | int i = 0; |
| 401 | while((NULL == temp) && (i < 100)) |
| 402 | { |
| 403 | usleep(1000); |
| 404 | temp = new Parcel; |
| 405 | i++; |
| 406 | } |
| 407 | if((i >= 100) || (NULL == temp)) |
| 408 | { |
| 409 | LYERRLOG("wait_response i:%d",i); |
| 410 | return LYNQ_E_GET_RESP_FAIL; |
| 411 | } |
| 412 | temp->setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen); |
| 413 | temp->setDataPosition(0); |
| 414 | temp->readInt32(&resp_type); |
| 415 | temp->readInt32(&in_utoken); |
| 416 | LYINFLOG("[%s]in_utoken:%d,utoken:%d",__FUNCTION__,in_utoken,utoken); |
| 417 | if (in_utoken != utoken) |
| 418 | { |
| 419 | delete temp; |
| 420 | temp = NULL; |
| 421 | in_utoken = 0; |
| 422 | continue; |
| 423 | } |
| 424 | temp->setDataPosition(0); |
| 425 | p = temp; |
| 426 | flag = 0; |
| 427 | return 0; |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | LYERRLOG("recvline is null,errno:%d",errno); |
| 432 | return LYNQ_E_GET_RESP_FAIL; |
| 433 | } |
| 434 | } |
| 435 | return LYNQ_E_GET_RESP_FAIL; |
| 436 | } |
| 437 | |
| 438 | int JumpHeader(Parcel *p,int *resp_type,int *utoken,int *request,int *slot_id,int *error) |
| 439 | { |
| 440 | if(NULL == p) |
| 441 | { |
| 442 | LYERRLOG("JumpHeader is null"); |
| 443 | return -1; |
| 444 | } |
| 445 | if(p->dataAvail() > 0) |
| 446 | { |
| 447 | p->readInt32(resp_type); |
| 448 | p->readInt32(utoken); |
| 449 | p->readInt32(request); |
| 450 | p->readInt32(slot_id); |
| 451 | p->readInt32(error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | return -1; |
| 457 | } |
| 458 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 459 | void free_parcel(Parcel *p) |
| 460 | { |
| 461 | if(p) |
| 462 | { |
| 463 | delete p; |
| 464 | p = NULL; |
| 465 | } |
| 466 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 467 | int send_request(int sockfd,lynq_client_t *client_tmp) |
| 468 | { |
| 469 | int ret=0; |
| 470 | ret = write(sockfd, client_tmp, LYQN_SEDN_BUF); |
| 471 | if(ret==-1) |
| 472 | { |
| 473 | perror("write error"); |
| 474 | return -1; |
| 475 | } |
| 476 | return 0; |
| 477 | } |
| 478 | static char *strdupReadString(Parcel &p) { |
| 479 | size_t stringlen; |
| 480 | const char16_t *s16; |
| 481 | s16 = p.readString16Inplace(&stringlen); |
| 482 | return strndup16to8(s16, stringlen); |
| 483 | } |
| 484 | static char *strdupReadString_p(Parcel *p) { |
| 485 | size_t stringlen; |
| 486 | const char16_t *s16; |
| 487 | s16 = p->readString16Inplace(&stringlen); |
| 488 | return strndup16to8(s16, stringlen); |
| 489 | } |
| 490 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 491 | /*Warren add for T800 platform 2021/11/19 start*/ |
| 492 | int lynq_socket_client_start() |
| 493 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 494 | /* init lynq_socket_server_addr */ |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 495 | bzero(&lynq_data_socket_server_addr, sizeof(lynq_data_socket_server_addr)); |
| 496 | lynq_data_socket_server_addr.sin_family = AF_INET; |
| 497 | lynq_data_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT); |
jb.qi | ce04d00 | 2023-05-16 18:28:06 -0700 | [diff] [blame] | 498 | lynq_data_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 499 | lynq_data_socket_server_addr_len = sizeof(lynq_data_socket_server_addr); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 500 | /* |
| 501 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0) |
| 502 | { |
| 503 | printf("[%s] is not a valid IPaddress\n", argv[1]); |
| 504 | exit(1); |
| 505 | } |
| 506 | */ |
| 507 | lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0); |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 508 | struct timeval timeOut; |
| 509 | |
rjw | a59bf31 | 2022-07-05 11:50:31 +0800 | [diff] [blame] | 510 | timeOut.tv_sec = 30; |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 511 | timeOut.tv_usec = 0; |
| 512 | |
| 513 | if (setsockopt(lynq_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0) |
| 514 | { |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 515 | LYERRLOG("time out setting failed"); |
rjw | 747deea | 2022-07-01 18:25:30 +0800 | [diff] [blame] | 516 | } |
| 517 | 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] | 518 | { |
| 519 | perror("connect error"); |
| 520 | return -1; |
| 521 | } |
| 522 | return 0; |
| 523 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 524 | |
| 525 | bool is_support_urc(int urc_id) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 526 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 527 | switch(urc_id) |
| 528 | { |
| 529 | case LYNQ_URC_DATA_CALL_STATUS_IND: |
| 530 | |
| 531 | case LYNQ_URC_MODIFY_APNDB: |
| 532 | case LYNQ_URC_RESET_APNDB: |
| 533 | return true; |
| 534 | default: |
| 535 | return false; |
| 536 | } |
| 537 | } |
| 538 | |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 539 | int printf_apn_table() |
| 540 | { |
| 541 | int ret = 0; |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 542 | if (lynq_apn_table == NULL) |
| 543 | { |
| 544 | LYERRLOG("apn table is null"); |
| 545 | return -1; |
| 546 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 547 | for(ret;ret<LYNQ_APN_CHANNEL_MAX;ret++) |
| 548 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 549 | LYINFLOG("[%s][%d] apn=%s ;apntype=%s ;ifname=%s ;hasTimeout = %d ; hasUsed = %d,status = %d,statusDeactApn = %s",__FUNCTION__,ret, \ |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 550 | lynq_apn_table[ret].apn,lynq_apn_table[ret].apnType,lynq_apn_table[ret].ifaceName, \ |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 551 | lynq_apn_table[ret].hasTimeout,lynq_apn_table[ret].hasUsed,lynq_apn_table[ret].status,lynq_apn_table[ret].statusApnType); |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 552 | } |
| 553 | return 0; |
| 554 | } |
| 555 | |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 556 | void printf_apn_table_debug(const char *fun,int line) |
| 557 | { |
| 558 | LYINFLOG("[%s][%d]apn_table msg",fun,line); |
| 559 | printf_apn_table(); |
| 560 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 561 | |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 562 | void urc_msg_process(Parcel *p) |
| 563 | { |
| 564 | int len; |
| 565 | int resp_type; |
| 566 | int urcid; |
| 567 | int slot_id; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 568 | int check_count = 0; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 569 | static int apnId=-1; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 570 | |
| 571 | int pdnState = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 572 | char apn[LYNQ_APN_MAX_LEN]; |
| 573 | char apnType[LYNQ_APN_TYPE_MAX_LEN]; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 574 | char ifaceName[LYNQ_IFACE_NAME_MAX_LEN]; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 575 | char *urc_msg = NULL; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 576 | |
| 577 | int size = p->dataSize(); |
| 578 | p->readInt32(&resp_type); |
| 579 | p->readInt32(&urcid); |
| 580 | p->readInt32(&slot_id); |
| 581 | LYINFLOG("data lib recv urc:resp_type=%d,urcid=%d,slot_id=%d,size=%d\n",resp_type,urcid,slot_id,size); |
| 582 | switch(urcid) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 583 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 584 | case LYNQ_URC_DATA_CALL_STATUS_IND: |
| 585 | p->readInt32(&pdnState); |
| 586 | bzero(apn,LYNQ_APN_MAX_LEN); |
| 587 | bzero(apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 588 | bzero(ifaceName,LYNQ_IFACE_NAME_MAX_LEN); |
| 589 | if(pdnState!=4)//PDN_DISCONNECTED |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 590 | { |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 591 | urc_msg = strdupReadString_p(p); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 592 | int len = strlen(urc_msg); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 593 | if((len < LYNQ_APN_MAX_LEN-1) && (len > 0)) |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 594 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 595 | memcpy(apn,urc_msg,len+1); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 596 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 597 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 598 | urc_msg = strdupReadString_p(p); |
| 599 | len = strlen(urc_msg); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 600 | if((len < LYNQ_APN_TYPE_MAX_LEN-1) && (len > 0)) |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 601 | { |
| 602 | memcpy(apnType,urc_msg,len+1); |
| 603 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 604 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 605 | urc_msg = strdupReadString_p(p); |
| 606 | len = strlen(urc_msg); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 607 | if((len < LYNQ_IFACE_NAME_MAX_LEN-1) && (len > 0)) |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 608 | { |
| 609 | memcpy(ifaceName,urc_msg,strlen(urc_msg)+1); |
| 610 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 611 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 612 | //sendSignalDataCallStateChange(); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 613 | apnId = getLynqApnID(apnType); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 614 | if(apnId >= 0) |
| 615 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 616 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 617 | if(lynq_apn_table[apnId].hasTimeout==1) |
| 618 | { |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 619 | /*whether timeout?,real or not,*/ |
| 620 | printf_apn_table(); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 621 | 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] | 622 | 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] | 623 | { |
| 624 | LYERRLOG("deactive this time out APN"); |
| 625 | lynq_deactive_data_call(&apnId); |
| 626 | } |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 627 | else |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 628 | { |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 629 | /*if apn lose,update apn and deactive all apn*/ |
| 630 | LYERRLOG("this table is invalid update APN table"); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 631 | } |
| 632 | break; |
| 633 | } |
rjw | acdb215 | 2023-02-07 14:12:49 +0800 | [diff] [blame] | 634 | updateApnTable(&lynq_apn_table[apnId],apn,apnType,ifaceName); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 635 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 636 | } |
| 637 | /*To be completed*/ |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 638 | else |
| 639 | { |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 640 | data_invaild_error = 1; |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 641 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
| 642 | apnId = getDeactApnID(apnType); |
| 643 | if(apnId < 0) |
| 644 | { |
| 645 | LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId); |
| 646 | break; |
| 647 | } |
| 648 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
| 649 | updateDeactApn(apnId,pdnState); |
| 650 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 651 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 652 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 653 | s_data_urc_wait_list.push_back(apnId); |
| 654 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
| 655 | lynq_data_call_change_id = apnId; |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 656 | sendSignalPdnChange(); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 657 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 658 | if(lynq_data_call==1) |
| 659 | { |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 660 | while (data_timelimit == 0) |
| 661 | { |
| 662 | LYINFLOG("client not ready to wait"); |
| 663 | for (check_count = 0;check_count < 500;check_count++) |
| 664 | { |
| 665 | /*wait 10ms*/ |
| 666 | usleep(10*1000); |
| 667 | } |
| 668 | LYERRLOG("client still without res"); |
| 669 | break; |
| 670 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 671 | sendSignalDataCallStateChange(); |
| 672 | lynq_data_call = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 673 | data_timelimit = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 674 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 675 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 676 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 677 | else |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 678 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 679 | urc_msg = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 680 | free(urc_msg); |
| 681 | urc_msg = strdupReadString_p(p); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 682 | len = strlen(urc_msg); |
| 683 | if(len < LYNQ_APN_TYPE_MAX_LEN-1) |
| 684 | { |
| 685 | memcpy(apnType,urc_msg,len+1); |
| 686 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 687 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 688 | LYDBGLOG("[data thread_urc_recv] apntype:%s",apnType); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 689 | apnId = getLynqApnID(apnType); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 690 | if(apnId >= 0) |
| 691 | { |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 692 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
| 693 | lynq_data_call_change_id = apnId; |
| 694 | //bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean |
| 695 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 696 | s_data_urc_wait_list.push_back(apnId); |
| 697 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
| 698 | sendSignalPdnChange(); |
| 699 | } |
| 700 | else |
| 701 | { |
| 702 | apnId = getDeactApnID(apnType); |
| 703 | if(apnId < 0) |
| 704 | { |
| 705 | LYERRLOG("[%d]invalid apnId:%d",__LINE__,apnId); |
| 706 | break; |
| 707 | } |
| 708 | LYINFLOG("URC apnType:%s,ifaceName:%s,apn:%s pdnState:%d,handle:%d",apnType,ifaceName,apn,pdnState,apnId); |
| 709 | cleanDeactApn(apnId); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 710 | lynq_data_call_change_id = apnId; |
| 711 | bzero(lynq_apn_table[apnId].apnType,LYNQ_APN_TYPE_MAX_LEN);//async clean |
rjw | 3938f26 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 712 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 713 | s_data_urc_wait_list.push_back(apnId); |
| 714 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 715 | sendSignalDeactvied(); |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 716 | sendSignalPdnChange(); |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 717 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 718 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 719 | LYDBGLOG("data call state:%d",lynq_data_call); |
| 720 | if(lynq_data_call==1) |
| 721 | { |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 722 | while (data_timelimit == 0) |
| 723 | { |
| 724 | LYINFLOG("client not ready to wait"); |
| 725 | for (check_count = 0;check_count < 500;check_count++) |
| 726 | { |
| 727 | /*wait 10ms*/ |
| 728 | usleep(10*1000); |
| 729 | } |
| 730 | LYERRLOG("client still without res"); |
| 731 | break; |
| 732 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 733 | sendSignalDataCallStateChange(); |
| 734 | lynq_data_call = 0; |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 735 | data_timelimit = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 736 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 737 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 738 | } |
| 739 | break; |
| 740 | case LYNQ_URC_MODIFY_APNDB: |
| 741 | urc_msg = strdupReadString_p(p); |
| 742 | if (NULL == urc_msg) |
| 743 | { |
| 744 | LYERRLOG("error apn msg"); |
| 745 | } |
| 746 | else |
| 747 | { |
| 748 | bzero(g_lynq_apn_result, 1024); |
| 749 | strcpy(g_lynq_apn_result, urc_msg); |
| 750 | sendSignalApnChange(); |
| 751 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 752 | free(urc_msg); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 753 | break; |
| 754 | case LYNQ_URC_RESET_APNDB: |
| 755 | { |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 756 | urc_msg = strdupReadString_p(p); |
| 757 | if (NULL == urc_msg) |
| 758 | { |
| 759 | LYERRLOG("error apn msg"); |
| 760 | } |
| 761 | else |
| 762 | { |
| 763 | bzero(g_lynq_apn_result, 1024); |
| 764 | strcpy(g_lynq_apn_result, urc_msg); |
| 765 | sendSignalApnChange(); |
| 766 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 767 | free(urc_msg); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 768 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 769 | default: |
| 770 | break; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 771 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 772 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 773 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 774 | |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 775 | int create_urc_vector_signal_thread() |
| 776 | { |
| 777 | int ret; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 778 | pthread_mutex_init(&s_lynq_urc_vector_mutex,NULL); |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 779 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 780 | s_data_urc_wait_list.clear(); |
| 781 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 782 | return 0; |
| 783 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 784 | int get_imsi(); |
Hong_Liu | 7d9ac8d | 2023-07-24 00:40:31 -0700 | [diff] [blame^] | 785 | int check_apn_status(); |
| 786 | int radio_switch(int status); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 787 | int lynq_init_data(int uToken) |
| 788 | { |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 789 | if (g_lynq_data_init_flag == 1) |
| 790 | { |
| 791 | LYERRLOG("init twice is not allowed"); |
| 792 | return -1; |
| 793 | } |
| 794 | g_lynq_data_init_flag = 1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 795 | int result = 0; |
| 796 | Global_uToken = uToken; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 797 | LYLOGSET(LOG_INFO); |
| 798 | LYLOGEINIT(USER_LOG_TAG); |
| 799 | result = lynq_socket_client_start(); |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 800 | pthread_mutex_init(&g_lynq_data_sendto_mutex, NULL); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 801 | if(result!=0) |
| 802 | { |
| 803 | LYERRLOG("init socket client fail!!!"); |
| 804 | return -1; |
| 805 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 806 | result = lynq_init_data_urc_thread(); |
| 807 | if(result!=0) |
| 808 | { |
| 809 | LYERRLOG("init socket urc fail!!!"); |
| 810 | return -1; |
| 811 | } |
| 812 | |
| 813 | result = create_urc_vector_signal_thread(); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 814 | if(result!=0) |
| 815 | { |
| 816 | LYERRLOG("init socket urc fail!!!"); |
| 817 | return -1; |
| 818 | } |
| 819 | memset(lynq_apn_table,0,sizeof(lynq_apn_table)); |
Hong_Liu | 7d9ac8d | 2023-07-24 00:40:31 -0700 | [diff] [blame^] | 820 | LYINFLOG("[%s] radio on/off solution 20230724",__FUNCTION__); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 821 | int count = 0; |
Hong_Liu | 7d9ac8d | 2023-07-24 00:40:31 -0700 | [diff] [blame^] | 822 | while(count < 2)//try recover the network within 10s. |
| 823 | { |
| 824 | result = check_apn_status(); |
| 825 | if(result==0) |
| 826 | { |
| 827 | break; |
| 828 | } |
| 829 | radio_switch(0); |
| 830 | sleep(1); |
| 831 | radio_switch(1); |
| 832 | sleep(3); |
| 833 | count++; |
| 834 | } |
| 835 | LYINFLOG("[%s] count is %d",__FUNCTION__,count); |
| 836 | if(result!=0) |
| 837 | { |
| 838 | LYDBGLOG("lynq init call fail!!!"); |
| 839 | return LYNQ_E_MD_NOT_READY;// |
| 840 | } |
| 841 | /* old |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 842 | while(count < 10) |
| 843 | { |
| 844 | result = get_imsi(); |
| 845 | if(result==0) |
| 846 | { |
| 847 | break; |
| 848 | } |
| 849 | sleep(1); |
| 850 | count++; |
| 851 | } |
| 852 | LYINFLOG("[%s] count is %d",__FUNCTION__,count); |
| 853 | if(result!=0) |
| 854 | { |
| 855 | LYDBGLOG("lynq init call fail!!!"); |
| 856 | return LYNQ_E_MD_NOT_READY;// |
| 857 | } |
Hong_Liu | 7d9ac8d | 2023-07-24 00:40:31 -0700 | [diff] [blame^] | 858 | */ |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 859 | LYDBGLOG("lynq init call success!!!"); |
| 860 | return 0; |
| 861 | |
| 862 | } |
| 863 | int lynq_deinit_data() |
| 864 | { |
| 865 | int ret = -1; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 866 | if (g_lynq_data_init_flag == 0) |
| 867 | { |
| 868 | LYERRLOG("deinit twice is not allowed"); |
| 869 | return ret; |
| 870 | } |
| 871 | g_lynq_data_init_flag = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 872 | for(int i =0;i<LYNQ_APN_CHANNEL_MAX;i++) |
| 873 | { |
| 874 | if(strlen(lynq_apn_table[i].apnType)!=0) |
| 875 | { |
| 876 | lynq_deactive_data_call(&i); |
| 877 | } |
| 878 | } |
| 879 | if(lynq_client_sockfd>0) |
| 880 | { |
| 881 | close(lynq_client_sockfd); |
| 882 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 883 | ret = lynq_deinit_data_urc_thread(); |
rjw | eb65a2f | 2023-02-01 16:43:23 +0800 | [diff] [blame] | 884 | if (ret != 0) |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 885 | { |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 886 | LYERRLOG("lynq_deinit_data_urc_thread fail"); |
| 887 | return ret; |
rjw | 22947c2 | 2022-03-15 09:21:29 +0800 | [diff] [blame] | 888 | } |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 889 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 890 | s_data_urc_wait_list.clear(); |
| 891 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | int lynq_setup_data_call(int *handle) |
| 895 | { |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 896 | int error = -1; |
| 897 | #ifdef GSW_RIL_CFG //becuase gsw not have connman,data can not be triggered by connman. |
| 898 | LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__); |
Hong_Liu | e987915 | 2023-04-25 20:40:26 -0700 | [diff] [blame] | 899 | error = lynq_setup_data_call_sp(handle,NULL,"default",NULL,NULL,NULL,NULL,NULL); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 900 | #else |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 901 | Parcel *p = NULL; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 902 | lynq_client_t client; |
| 903 | int resp_type = -1; |
| 904 | int request = -1; |
| 905 | int slot_id = -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 906 | int lynq_data_call_id = 0; |
| 907 | if(handle==NULL) |
| 908 | { |
| 909 | LYERRLOG("handle is null!!!"); |
| 910 | return LYNQ_E_NULL_ANONALY; |
| 911 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 912 | client.uToken = get_utoken(); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 913 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 914 | client.paramLen = 0; |
| 915 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 916 | 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] | 917 | lynq_data_call_id = updateApn("default"); |
| 918 | if (lynq_data_call_id < 0) |
| 919 | { |
| 920 | LYERRLOG("update apn table fail error id = %d",lynq_data_call_id); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 921 | return LYNQ_E_NULL_ANONALY+1; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 922 | } |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 923 | *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) why? If it times out, the client application will also try to reconnect. |
| 924 | //Reconnection needs to be deactivated first, and deactivation needs to know which apn to activate. |
rjw | 733b983 | 2023-04-03 10:20:08 +0800 | [diff] [blame] | 925 | lynq_data_call = 1; |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 926 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 927 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 928 | { |
| 929 | LYERRLOG("send request fail"); |
| 930 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 931 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 932 | return LYNQ_E_NULL_ANONALY+2; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 933 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 934 | //get_response(lynq_client_sockfd,p); |
| 935 | error = wait_response(lynq_client_sockfd,p,client.uToken); |
| 936 | if(error!=0) |
| 937 | { |
| 938 | LYERRLOG("wait_response fail,ret:%d",error); |
| 939 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
| 940 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 941 | return error; |
| 942 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 943 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | aa7f4b3 | 2023-07-19 07:51:25 -0700 | [diff] [blame] | 944 | JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 945 | free_parcel(p); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 946 | 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] | 947 | if(error==0) |
| 948 | { |
rjw | f9ec383 | 2023-04-12 10:59:15 +0800 | [diff] [blame] | 949 | data_timelimit = 1; |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 950 | if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 951 | { |
| 952 | error = LYNQ_E_TIME_OUT; |
| 953 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 954 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 955 | if (data_invaild_error == 1) |
| 956 | { |
| 957 | data_invaild_error = 0; |
| 958 | LYERRLOG("urc apn info error!!!"); |
| 959 | return 8085; |
| 960 | } |
| 961 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 962 | return error; |
| 963 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 964 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 965 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 966 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 967 | return error; |
| 968 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 969 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 970 | int lynq_deactive_data_call(int *handle) |
| 971 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 972 | Parcel *p = NULL; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 973 | lynq_client_t client; |
| 974 | int resp_type = -1; |
| 975 | int request = -1; |
| 976 | int slot_id = -1; |
| 977 | int error = -1; |
| 978 | int lynq_data_call_id = -1; |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 979 | int ret = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 980 | if(handle==NULL) |
| 981 | { |
| 982 | LYERRLOG("handle is null!!!"); |
| 983 | return -1; |
| 984 | } |
rjw | 1309e23 | 2022-07-22 09:54:06 +0800 | [diff] [blame] | 985 | ret = handleCheck(*handle); |
| 986 | if (ret != 0) |
| 987 | { |
| 988 | LYERRLOG("incomming handle is invalid"); |
| 989 | return -1; |
| 990 | } |
| 991 | lynq_data_call_id = *handle; |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 992 | client.uToken = get_utoken(); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 993 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
Hong_Liu | e3d3526 | 2023-05-04 00:20:12 -0700 | [diff] [blame] | 994 | client.paramLen = 0; |
| 995 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 996 | #ifdef GSW_RIL_CFG |
| 997 | client.paramLen = 1; |
| 998 | sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); |
| 999 | #else |
| 1000 | if(strcmp(lynq_apn_table[lynq_data_call_id].apnType,"default")!=0) |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1001 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1002 | client.paramLen = 1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1003 | sprintf(client.param,"%s",lynq_apn_table[lynq_data_call_id].apnType); |
| 1004 | } |
Hong_Liu | e3d3526 | 2023-05-04 00:20:12 -0700 | [diff] [blame] | 1005 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1006 | 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] | 1007 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1008 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1009 | { |
| 1010 | LYERRLOG("send request fail"); |
| 1011 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1012 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1013 | return -1; |
| 1014 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1015 | //get_response(lynq_client_sockfd,p); |
| 1016 | error = wait_response(lynq_client_sockfd,p,client.uToken); |
| 1017 | if(error!=0) |
| 1018 | { |
| 1019 | LYERRLOG("wait_response fail,ret:%d",error); |
| 1020 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
| 1021 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1022 | return error; |
| 1023 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1024 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1025 | JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error); |
| 1026 | LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1027 | cleanOnceApnTable(lynq_data_call_id); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1028 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1029 | if(error==0) |
| 1030 | { |
| 1031 | if(waitDeactived(20000)==ETIMEDOUT) |
| 1032 | { |
| 1033 | error = LYNQ_E_TIME_OUT; |
| 1034 | LYERRLOG("[lynq_deactive_data_call] timeout:wait data Call state fail!!!"); |
| 1035 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
| 1036 | } |
| 1037 | } |
| 1038 | free_parcel(p); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1039 | return error; |
| 1040 | } |
| 1041 | int lynq_setup_data_call_sp(int *handle,char *apn,char *apnType,char *user,char *password,char *authType,char *normalProtocol,char *roamingProtocol) |
| 1042 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1043 | Parcel *p = NULL; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1044 | lynq_client_t client; |
| 1045 | int resp_type = -1; |
| 1046 | int request = -1; |
| 1047 | int slot_id = -1; |
| 1048 | int error = -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1049 | int lynq_data_call_id = -1; |
| 1050 | char *argv[10] = {}; |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 1051 | #ifdef GSW_RIL_CFG |
| 1052 | LYINFLOG("[%s][%d]",__FUNCTION__,__LINE__); |
| 1053 | if(handle==NULL||apnType==NULL) |
| 1054 | { |
| 1055 | LYERRLOG("handle or apntype is null!!!"); |
| 1056 | return -1; |
| 1057 | } |
| 1058 | #else |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1059 | if(handle==NULL||apn==NULL||apnType==NULL) |
| 1060 | { |
| 1061 | LYERRLOG("handle ,apn or apntype is null!!!"); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1062 | return LYNQ_E_NULL_ANONALY; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1063 | } |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 1064 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1065 | if(user==NULL) |
| 1066 | { |
| 1067 | argv[1] = "null"; |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 1071 | argv[1] = user; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1072 | } |
| 1073 | if(password==NULL) |
| 1074 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1075 | argv[2] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1076 | } |
| 1077 | else |
| 1078 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1079 | argv[2] = password; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1080 | } |
| 1081 | if(authType==NULL) |
| 1082 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1083 | argv[3] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1084 | } |
| 1085 | else |
| 1086 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1087 | argv[3] = authType; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1088 | } |
| 1089 | if(normalProtocol==NULL) |
| 1090 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1091 | argv[4] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1092 | } |
| 1093 | else |
| 1094 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1095 | argv[4] = normalProtocol; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1096 | } |
| 1097 | if(roamingProtocol==NULL) |
| 1098 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1099 | argv[5] = "null"; |
lh | 1358661 | 2022-01-11 21:58:58 -0800 | [diff] [blame] | 1100 | } |
| 1101 | else |
| 1102 | { |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1103 | argv[5] = roamingProtocol; |
| 1104 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1105 | client.uToken = get_utoken(); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1106 | client.request = 27;//RIL_REQUEST_SETUP_DATA_CALL |
| 1107 | client.paramLen = 7; |
| 1108 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
Hong_Liu | e54db8c | 2023-04-21 02:37:23 -0700 | [diff] [blame] | 1109 | #ifdef GSW_RIL_CFG |
| 1110 | if(NULL == apn) |
| 1111 | { |
| 1112 | sprintf(client.param,"null %s %s %s %s %s %s",apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
| 1113 | } |
| 1114 | else |
| 1115 | { |
| 1116 | sprintf(client.param,"%s %s %s %s %s %s %s",apn,apnType,argv[1],argv[2],argv[3],argv[4],argv[5]); |
| 1117 | } |
| 1118 | #else |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1119 | 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] | 1120 | #endif //GSW_RIL_CFG |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1121 | 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] | 1122 | lynq_data_call_id = updateApn(apnType); |
| 1123 | if (lynq_data_call_id < 0) |
| 1124 | { |
| 1125 | LYERRLOG("update apn table fail error id = %d",lynq_data_call_id); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1126 | return LYNQ_E_NULL_ANONALY+1; |
rjw | c63abb4 | 2023-03-31 18:22:42 +0800 | [diff] [blame] | 1127 | } |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1128 | *handle = lynq_data_call_id;//T8TSK-211 (2023/5/16) |
rjw | 733b983 | 2023-04-03 10:20:08 +0800 | [diff] [blame] | 1129 | lynq_data_call = 1; |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1130 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1131 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1132 | { |
| 1133 | LYERRLOG("send request fail"); |
| 1134 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1135 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1136 | return LYNQ_E_NULL_ANONALY+2; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1137 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1138 | //get_response(lynq_client_sockfd,p); |
| 1139 | error = wait_response(lynq_client_sockfd,p,client.uToken); |
| 1140 | if(error!=0) |
| 1141 | { |
| 1142 | LYERRLOG("wait_response fail,ret:%d",error); |
| 1143 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
| 1144 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1145 | return error; |
| 1146 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1147 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1148 | JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error); |
| 1149 | LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error); |
| 1150 | free_parcel(p); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1151 | if(error==0) |
| 1152 | { |
Hong_Liu | 7e1b85e | 2023-05-16 05:51:57 -0700 | [diff] [blame] | 1153 | data_timelimit = 1; |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1154 | if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1155 | { |
| 1156 | error = LYNQ_E_TIME_OUT; |
| 1157 | LYERRLOG("timeout:wait data Call state fail!!!"); |
| 1158 | lynq_apn_table[lynq_data_call_id].hasTimeout = 1; |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1159 | if (data_invaild_error == 1) |
| 1160 | { |
| 1161 | data_invaild_error = 0; |
| 1162 | LYERRLOG("urc apn info error!!!"); |
| 1163 | return 8085; |
| 1164 | } |
| 1165 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1166 | return error; |
| 1167 | } |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1168 | } |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1169 | printf_apn_table_debug(__FUNCTION__,__LINE__); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1170 | return error; |
| 1171 | } |
| 1172 | /* |
| 1173 | int lynq_deactive_data_call_sp(int *handle,char *apnType) |
| 1174 | { |
| 1175 | Parcel p; |
| 1176 | lynq_client_t client; |
| 1177 | int resp_type = -1; |
| 1178 | int request = -1; |
| 1179 | int slot_id = -1; |
| 1180 | int error = -1; |
| 1181 | if(handle==NULL||apnType==NULL) |
| 1182 | { |
| 1183 | LYERRLOG("handle is null!!!"); |
| 1184 | return -1; |
| 1185 | } |
| 1186 | client.uToken = Global_uToken; |
| 1187 | client.request = 41;//RIL_REQUEST_DEACTIVATE_DATA_CALL |
| 1188 | client.paramLen = 1; |
| 1189 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 1190 | sprintf(client.param,"%s",apnType); |
| 1191 | LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 1192 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1193 | { |
| 1194 | LYERRLOG("send request fail"); |
| 1195 | perror("[LYNQ_DATA] send request fail:"); |
| 1196 | return -1; |
| 1197 | } |
| 1198 | get_response(lynq_client_sockfd,p); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 1199 | JumpHeader(p,&resp_type,&request,&slot_id,&error); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1200 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); |
| 1201 | return error; |
| 1202 | } |
| 1203 | */ |
| 1204 | int getDataCallLists(lynq_data_call_response_v11_t dataCallList[LYNQ_APN_CHANNEL_MAX],int *realNum) |
| 1205 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1206 | Parcel *p = NULL; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1207 | lynq_client_t client; |
| 1208 | int resp_type = -1; |
q.huang | 7de1d66 | 2022-09-13 14:19:24 +0800 | [diff] [blame] | 1209 | int token; |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1210 | int request = -1; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1211 | int slot_id = -1; |
| 1212 | int error = -1; |
| 1213 | int version =0; |
| 1214 | int num = 0; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1215 | char *temp_char = NULL; |
| 1216 | if(dataCallList==NULL) |
| 1217 | { |
| 1218 | LYERRLOG("dataCallList is null!!!"); |
| 1219 | return -1; |
| 1220 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1221 | client.uToken = get_utoken();; |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1222 | client.request = 57;//RIL_REQUEST_DATA_CALL_LIST |
| 1223 | client.paramLen = 0; |
| 1224 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 1225 | 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] | 1226 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1227 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1228 | { |
| 1229 | LYERRLOG("send request fail"); |
| 1230 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1231 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1232 | return -1; |
| 1233 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1234 | //get_response(lynq_client_sockfd,p); |
| 1235 | error = wait_response(lynq_client_sockfd,p,client.uToken); |
| 1236 | if(error!=0) |
| 1237 | { |
| 1238 | LYERRLOG("wait_response fail,ret:%d",error); |
| 1239 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1240 | return error; |
| 1241 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1242 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1243 | if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0) |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 1244 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1245 | LYERRLOG("JumpHeader fail"); |
rjw | fa53297 | 2022-09-16 13:39:41 +0800 | [diff] [blame] | 1246 | return -1; |
| 1247 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1248 | LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error); |
| 1249 | p->readInt32(&version); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1250 | if(version==11) |
| 1251 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1252 | p->readInt32(&num); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1253 | *realNum = num; |
| 1254 | for (int i = 0; i < num; i++) |
| 1255 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1256 | p->readInt32(&dataCallList[i].status); |
| 1257 | p->readInt32(&dataCallList[i].suggestedRetryTime); |
| 1258 | p->readInt32(&dataCallList[i].cid); |
| 1259 | p->readInt32(&dataCallList[i].active); |
| 1260 | temp_char = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1261 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1262 | if(temp_char) |
| 1263 | { |
| 1264 | memcpy(dataCallList[i].type,temp_char,strlen(temp_char)+1); |
| 1265 | free(temp_char); |
| 1266 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1267 | temp_char = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1268 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1269 | if(temp_char) |
| 1270 | { |
| 1271 | memcpy(dataCallList[i].ifname,temp_char,strlen(temp_char)+1); |
| 1272 | free(temp_char); |
| 1273 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1274 | temp_char = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1275 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1276 | if(temp_char) |
| 1277 | { |
| 1278 | memcpy(dataCallList[i].addresses,temp_char,strlen(temp_char)+1); |
| 1279 | free(temp_char); |
| 1280 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1281 | temp_char = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1282 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1283 | if(temp_char) |
| 1284 | { |
| 1285 | memcpy(dataCallList[i].dnses,temp_char,strlen(temp_char)+1); |
| 1286 | free(temp_char); |
| 1287 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1288 | temp_char = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1289 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1290 | if(temp_char) |
| 1291 | { |
| 1292 | memcpy(dataCallList[i].gateways,temp_char,strlen(temp_char)+1); |
| 1293 | free(temp_char); |
| 1294 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1295 | temp_char = strdupReadString_p(p); |
Hong_Liu | 6149f18 | 2023-05-12 02:15:14 -0700 | [diff] [blame] | 1296 | LYINFLOG("[%s][%d]%s",__FUNCTION__,__LINE__,temp_char); |
| 1297 | if(temp_char) |
| 1298 | { |
| 1299 | memcpy(dataCallList[i].pcscf,temp_char,strlen(temp_char)+1); |
| 1300 | free(temp_char); |
| 1301 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1302 | p->readInt32(&dataCallList[i].mtu); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1303 | } |
| 1304 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1305 | free_parcel(p); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1306 | return error; |
| 1307 | } |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1308 | |
| 1309 | int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg) |
| 1310 | { |
| 1311 | LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle); |
| 1312 | if((handle < 0) || (handle > 6) || (NULL == apn_msg)) |
| 1313 | { |
| 1314 | LYERRLOG("handle value error,or apn_msg is null"); |
| 1315 | return LYNQ_E_NULL_ANONALY; |
| 1316 | } |
| 1317 | apn_msg->handle = handle; |
| 1318 | if(apn_msg->apn!=NULL) |
| 1319 | { |
| 1320 | memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN); |
| 1321 | } |
| 1322 | if(apn_msg->apnType!=NULL) |
| 1323 | { |
| 1324 | memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN); |
| 1325 | } |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1329 | int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList) |
| 1330 | { |
| 1331 | lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={}; |
| 1332 | int number = 0; |
| 1333 | int lynq_data_call_id = 0; |
| 1334 | int error = 0; |
| 1335 | lynq_data_call_id = *handle; |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1336 | if((handle==NULL) || (dataCallList==NULL)) |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1337 | { |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1338 | LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL"); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1339 | return LYNQ_E_NULL_ANONALY; |
| 1340 | } |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1341 | if ((*handle < 0) || (*handle > 6)) |
rjw | 3938f26 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 1342 | { |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1343 | LYERRLOG("[lynq_get_data_call_list] handle value error"); |
| 1344 | return LYNQ_E_NULL_ANONALY; |
rjw | 3938f26 | 2023-03-08 16:09:28 +0800 | [diff] [blame] | 1345 | } |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1346 | LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1347 | memset(interDataCallList,0,sizeof(interDataCallList)); |
| 1348 | error = getDataCallLists(interDataCallList,&number); |
| 1349 | if(error == 0) |
| 1350 | { |
| 1351 | for(int i = 0;i < number;i++) |
| 1352 | { |
| 1353 | if(strcmp(interDataCallList[i].ifname,lynq_apn_table[lynq_data_call_id].ifaceName)==0) |
| 1354 | { |
| 1355 | dataCallList->active = interDataCallList[i].active; |
| 1356 | dataCallList->suggestedRetryTime = interDataCallList[i].suggestedRetryTime; |
| 1357 | dataCallList->cid = interDataCallList[i].cid; |
| 1358 | dataCallList->status = interDataCallList[i].status; |
| 1359 | dataCallList->mtu = interDataCallList[i].mtu; |
| 1360 | memcpy(dataCallList->addresses,interDataCallList[i].addresses,sizeof(interDataCallList[i].addresses)); |
| 1361 | memcpy(dataCallList->ifname,interDataCallList[i].ifname,sizeof(interDataCallList[i].ifname)); |
| 1362 | memcpy(dataCallList->dnses,interDataCallList[i].dnses,sizeof(interDataCallList[i].dnses)); |
| 1363 | memcpy(dataCallList->type,interDataCallList[i].type,sizeof(interDataCallList[i].type)); |
| 1364 | memcpy(dataCallList->gateways,interDataCallList[i].gateways,sizeof(interDataCallList[i].gateways)); |
| 1365 | memcpy(dataCallList->pcscf,interDataCallList[i].pcscf,sizeof(interDataCallList[i].pcscf)); |
| 1366 | LYDBGLOG("ifname:%s,addr:%s",dataCallList->ifname,dataCallList->addresses); |
| 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | return error; |
| 1371 | } |
| 1372 | int lynq_wait_data_call_state_change(int *handle) |
| 1373 | { |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 1374 | if (data_waiting_status == 1) |
| 1375 | { |
| 1376 | LYDBGLOG("some thread is waiting"); |
| 1377 | return -3; |
| 1378 | } |
| 1379 | LYDBGLOG("is empty :%d",s_data_urc_wait_list.empty()); |
| 1380 | if (s_data_urc_wait_list.empty()) |
| 1381 | { |
| 1382 | LYDBGLOG("start wait"); |
| 1383 | data_waiting_status = 1; |
| 1384 | waitPdnChange(); |
| 1385 | } |
| 1386 | data_waiting_status = 0; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 1387 | std::vector<int>::iterator iter; |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 1388 | |
| 1389 | pthread_mutex_lock(&s_lynq_urc_vector_mutex); |
| 1390 | iter = s_data_urc_wait_list.begin(); |
rjw | c3d6e58 | 2023-03-28 17:19:11 +0800 | [diff] [blame] | 1391 | if (iter != s_data_urc_wait_list.end()) |
| 1392 | { |
| 1393 | *handle = *iter; |
| 1394 | } |
rjw | 7ee7bb4 | 2023-01-18 11:34:28 +0800 | [diff] [blame] | 1395 | s_data_urc_wait_list.erase(iter); |
| 1396 | pthread_mutex_unlock(&s_lynq_urc_vector_mutex); |
| 1397 | |
Hong_Liu | dc46d41 | 2023-05-18 13:36:26 -0700 | [diff] [blame] | 1398 | LYINFLOG("lynq_wait_data_call_state_change handle:%d",*handle); |
lh | f81a46f | 2022-02-13 23:57:37 -0800 | [diff] [blame] | 1399 | return 0; |
| 1400 | } |
| 1401 | /*Warren add for T800 platform 2021/11/19 end*/ |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1402 | |
| 1403 | /*Typethree add for T800 platform 2022/04/21 start*/ |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1404 | |
| 1405 | 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] | 1406 | { |
| 1407 | char strtmp[10][32]; |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1408 | if (id == NULL) |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1409 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1410 | sprintf(strtmp[0], "id=;"); |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1411 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1412 | else |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1413 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1414 | sprintf(strtmp[0], "id=%s;", id); |
rjw | 0cdacbc | 2022-06-22 10:51:07 +0800 | [diff] [blame] | 1415 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1416 | if (mcc == NULL) |
| 1417 | { |
| 1418 | sprintf(strtmp[1], "mcc=;"); |
| 1419 | } |
| 1420 | else |
| 1421 | { |
| 1422 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1423 | } |
| 1424 | if (mnc == NULL) |
| 1425 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1426 | sprintf(strtmp[2], "mnc=;"); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1427 | } |
| 1428 | else |
| 1429 | { |
| 1430 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1431 | } |
| 1432 | if (apn == NULL) |
| 1433 | { |
| 1434 | sprintf(strtmp[3], "apn=;"); |
| 1435 | } |
| 1436 | else |
| 1437 | { |
| 1438 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1439 | } |
| 1440 | if (apntype == NULL) |
| 1441 | { |
| 1442 | sprintf(strtmp[4], "apntype=;"); |
| 1443 | } |
| 1444 | else |
| 1445 | { |
| 1446 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1447 | } |
| 1448 | if (user == NULL) |
| 1449 | { |
| 1450 | sprintf(strtmp[5], "user=;"); |
| 1451 | } |
| 1452 | else |
| 1453 | { |
| 1454 | sprintf(strtmp[5], "user=%s;", user); |
| 1455 | } |
| 1456 | if (password == NULL) |
| 1457 | { |
| 1458 | sprintf(strtmp[6], "password=;"); |
| 1459 | } |
| 1460 | else |
| 1461 | { |
| 1462 | sprintf(strtmp[6], "password=%s;", password); |
| 1463 | } |
| 1464 | if (normalprotocol == NULL) |
| 1465 | { |
| 1466 | sprintf(strtmp[7], "normalprotocol=;"); |
| 1467 | } |
| 1468 | else |
| 1469 | { |
| 1470 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1471 | } |
| 1472 | if (roamingprotocol == NULL) |
| 1473 | { |
| 1474 | sprintf(strtmp[8], "roamingprotocol=;"); |
| 1475 | } |
| 1476 | else |
| 1477 | { |
| 1478 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1479 | } |
| 1480 | if (carrier == NULL) |
| 1481 | { |
| 1482 | sprintf(strtmp[9], "carrier=;"); |
| 1483 | } |
| 1484 | else |
| 1485 | { |
| 1486 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1487 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1488 | 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] | 1489 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1490 | return 0; |
| 1491 | } |
| 1492 | |
| 1493 | 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) |
| 1494 | { |
| 1495 | char strtmp[10][32]; |
| 1496 | if (id == NULL) |
| 1497 | { |
| 1498 | sprintf(strtmp[0], "id=;"); |
| 1499 | } |
| 1500 | else |
| 1501 | { |
| 1502 | sprintf(strtmp[0], "id=%s;", id); |
| 1503 | } |
| 1504 | if (mcc == NULL) |
| 1505 | { |
| 1506 | sprintf(strtmp[1], "mcc=;"); |
| 1507 | } |
| 1508 | else |
| 1509 | { |
| 1510 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1511 | } |
| 1512 | if (mnc == NULL) |
| 1513 | { |
| 1514 | sprintf(strtmp[2], "mnc=;"); |
| 1515 | } |
| 1516 | else |
| 1517 | { |
| 1518 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1519 | } |
| 1520 | if (apn == NULL) |
| 1521 | { |
| 1522 | sprintf(strtmp[3], "apn=;"); |
| 1523 | } |
| 1524 | else |
| 1525 | { |
| 1526 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1527 | } |
| 1528 | if (apntype == NULL) |
| 1529 | { |
| 1530 | sprintf(strtmp[4], "apntype=;"); |
| 1531 | } |
| 1532 | else |
| 1533 | { |
| 1534 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1535 | } |
| 1536 | if (user == NULL) |
| 1537 | { |
| 1538 | sprintf(strtmp[5], "user=;"); |
| 1539 | } |
| 1540 | else |
| 1541 | { |
| 1542 | sprintf(strtmp[5], "user=%s;", user); |
| 1543 | } |
| 1544 | if (password == NULL) |
| 1545 | { |
| 1546 | sprintf(strtmp[6], "password=;"); |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | sprintf(strtmp[6], "password=%s;", password); |
| 1551 | } |
| 1552 | if (normalprotocol == NULL) |
| 1553 | { |
| 1554 | sprintf(strtmp[7], "normalprotocol=;"); |
| 1555 | } |
| 1556 | else |
| 1557 | { |
| 1558 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1559 | } |
| 1560 | if (roamingprotocol == NULL) |
| 1561 | { |
| 1562 | sprintf(strtmp[8], "roamingprotocol=;"); |
| 1563 | } |
| 1564 | else |
| 1565 | { |
| 1566 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1567 | } |
| 1568 | if (carrier == NULL) |
| 1569 | { |
| 1570 | sprintf(strtmp[9], "carrier=;"); |
| 1571 | } |
| 1572 | else |
| 1573 | { |
| 1574 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1575 | } |
| 1576 | 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]); |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
rjw | af4b161 | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1580 | |
| 1581 | 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) |
| 1582 | { |
| 1583 | char strtmp[10][32]; |
| 1584 | if (id == NULL) |
| 1585 | { |
| 1586 | sprintf(strtmp[0], ""); |
| 1587 | } |
| 1588 | else |
| 1589 | { |
| 1590 | sprintf(strtmp[0], "id=%s;", id); |
| 1591 | } |
| 1592 | if (mcc == NULL) |
| 1593 | { |
| 1594 | sprintf(strtmp[1], ""); |
| 1595 | } |
| 1596 | else |
| 1597 | { |
| 1598 | sprintf(strtmp[1], "mcc=%s;", mcc); |
| 1599 | } |
| 1600 | if (mnc == NULL) |
| 1601 | { |
| 1602 | sprintf(strtmp[2], ""); |
| 1603 | } |
| 1604 | else |
| 1605 | { |
| 1606 | sprintf(strtmp[2], "mnc=%s;", mnc); |
| 1607 | } |
| 1608 | if (apn == NULL) |
| 1609 | { |
| 1610 | sprintf(strtmp[3], ""); |
| 1611 | } |
| 1612 | else |
| 1613 | { |
| 1614 | sprintf(strtmp[3], "apn=%s;", apn); |
| 1615 | } |
| 1616 | if (apntype == NULL) |
| 1617 | { |
| 1618 | sprintf(strtmp[4], ""); |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | sprintf(strtmp[4], "apntype=%s;", apntype); |
| 1623 | } |
| 1624 | if (user == NULL) |
| 1625 | { |
| 1626 | sprintf(strtmp[5], ""); |
| 1627 | } |
| 1628 | else |
| 1629 | { |
| 1630 | sprintf(strtmp[5], "user=%s;", user); |
| 1631 | } |
| 1632 | if (password == NULL) |
| 1633 | { |
| 1634 | sprintf(strtmp[6], ""); |
| 1635 | } |
| 1636 | else |
| 1637 | { |
| 1638 | sprintf(strtmp[6], "password=%s;", password); |
| 1639 | } |
| 1640 | if (normalprotocol == NULL) |
| 1641 | { |
| 1642 | sprintf(strtmp[7], ""); |
| 1643 | } |
| 1644 | else |
| 1645 | { |
| 1646 | sprintf(strtmp[7], "normalprotocol=%s;", normalprotocol); |
| 1647 | } |
| 1648 | if (roamingprotocol == NULL) |
| 1649 | { |
| 1650 | sprintf(strtmp[8], ""); |
| 1651 | } |
| 1652 | else |
| 1653 | { |
| 1654 | sprintf(strtmp[8], "roamingprotocol=%s;", roamingprotocol); |
| 1655 | } |
| 1656 | if (carrier == NULL) |
| 1657 | { |
| 1658 | sprintf(strtmp[9], ""); |
| 1659 | } |
| 1660 | else |
| 1661 | { |
| 1662 | sprintf(strtmp[9], "carrier=%s;", carrier); |
| 1663 | } |
| 1664 | 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]); |
| 1665 | return 0; |
| 1666 | } |
| 1667 | |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1668 | static char *lynqStrdupReadString(Parcel &p) |
| 1669 | { |
| 1670 | size_t stringlen; |
| 1671 | const char16_t *s16; |
| 1672 | |
| 1673 | s16 = p.readString16Inplace(&stringlen); |
| 1674 | return strndup16to8(s16, stringlen); |
| 1675 | } |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1676 | int get_imsi() |
| 1677 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1678 | Parcel *p =NULL; |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1679 | lynq_client_t client; |
| 1680 | int resp_type = -1; |
| 1681 | int token; |
| 1682 | int request = -1; |
| 1683 | int slot_id = -1; |
| 1684 | int error = -1; |
| 1685 | int version =0; |
| 1686 | int num = 0; |
| 1687 | char *temp_char = NULL; |
| 1688 | char mccmnc[32] = {0}; |
| 1689 | char mccmnckey[64] = {0}; |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1690 | client.uToken = get_utoken(); |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1691 | client.request = 11;//RIL_REQUEST_GET_IMSI 11 |
| 1692 | client.paramLen = 0; |
| 1693 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 1694 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 1695 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
| 1696 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1697 | { |
| 1698 | LYERRLOG("send request fail"); |
| 1699 | perror("[LYNQ_DATA] send request fail:"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1700 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1701 | return -1; |
| 1702 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1703 | //get_response(lynq_client_sockfd,p); |
| 1704 | error = wait_response(lynq_client_sockfd,p,client.uToken); |
| 1705 | if(error!=0) |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1706 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1707 | LYERRLOG("wait_response fail,ret:%d",error); |
| 1708 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1709 | return error; |
| 1710 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1711 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1712 | if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0) |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1713 | { |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1714 | LYERRLOG("JumpHeader fail"); |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1715 | return -1; |
| 1716 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1717 | LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error); |
| 1718 | if(error == 0) |
| 1719 | { |
| 1720 | char * test = strdupReadString_p(p); |
| 1721 | memcpy(mccmnc, test,5); |
| 1722 | mccmnc[5]='\0'; |
| 1723 | free(test); |
| 1724 | sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc); |
| 1725 | system(mccmnckey); |
| 1726 | system("uci commit"); |
| 1727 | } |
| 1728 | free_parcel(p); |
| 1729 | return error; |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1730 | } |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1731 | 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) |
| 1732 | { |
| 1733 | if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier) |
| 1734 | { |
| 1735 | LYERRLOG("There are no valid parameters"); |
| 1736 | return -1; |
| 1737 | } |
| 1738 | lynq_client_t client; |
| 1739 | char argc[512]; |
Hong_Liu | 7163bbe | 2023-06-04 03:03:44 -0700 | [diff] [blame] | 1740 | int res = -1; |
| 1741 | int count = 0; |
| 1742 | while(count < 10) |
| 1743 | { |
| 1744 | res = get_imsi(); |
| 1745 | if(res==0) |
| 1746 | { |
| 1747 | break; |
| 1748 | } |
| 1749 | sleep(1); |
| 1750 | count++; |
| 1751 | } |
| 1752 | LYINFLOG("[%s] count is %d",__FUNCTION__,count); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1753 | if (cmd == 0) // insert apn db |
| 1754 | { |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1755 | res = insert_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1756 | client.uToken = get_utoken(); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1757 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1758 | client.paramLen = 2; |
| 1759 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1760 | sprintf(client.param, "%d %s", cmd, argc); |
| 1761 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1762 | else if (cmd == 1) //delete apn db |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1763 | { |
| 1764 | if (NULL == id) |
| 1765 | { |
| 1766 | LYERRLOG("id is NULL!!!please input id: "); |
| 1767 | } |
| 1768 | sprintf(argc, "id=%s", id); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1769 | client.uToken = get_utoken(); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1770 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1771 | client.paramLen = 2; |
| 1772 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1773 | sprintf(client.param, "%d %s", cmd, argc); |
| 1774 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1775 | else if (cmd == 2) //query apn db |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1776 | { |
rjw | af4b161 | 2022-06-13 17:26:01 +0800 | [diff] [blame] | 1777 | query_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1778 | client.uToken = get_utoken(); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1779 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1780 | client.paramLen = 2; |
| 1781 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1782 | sprintf(client.param, "%d %s", cmd, argc); |
| 1783 | } |
rjw | 61fcae3 | 2022-08-18 14:03:39 +0800 | [diff] [blame] | 1784 | else if (cmd == 3) //modify apn db |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1785 | { |
| 1786 | modify_apn_char(argc, id, mcc, mnc, apn, apntype, user, password, normalprotocol, roamingprotocol, carrier); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1787 | client.uToken = get_utoken(); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1788 | client.request = 2000 + 193; // RIL_REQUEST_MODIFY_APN |
| 1789 | client.paramLen = 2; |
| 1790 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1791 | sprintf(client.param, "%d %s", cmd, argc); |
| 1792 | } |
| 1793 | else |
| 1794 | { |
| 1795 | LYERRLOG("incoming command is invalid"); |
| 1796 | return -1; |
| 1797 | } |
| 1798 | 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] | 1799 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1800 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1801 | { |
| 1802 | LYERRLOG("send request fail"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1803 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1804 | return -1; |
| 1805 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1806 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1807 | waitApnResult(); |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1808 | strcpy(out, g_lynq_apn_result); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1809 | LYINFLOG(">>>>>output info:%s",out); |
| 1810 | return 0; |
| 1811 | } |
| 1812 | |
| 1813 | int lynq_reset_apn(char *result) |
| 1814 | { |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1815 | lynq_client_t client; |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1816 | if (NULL == result) |
| 1817 | { |
| 1818 | LYERRLOG("incoming paramters error"); |
| 1819 | } |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1820 | client.uToken = get_utoken(); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1821 | client.request = 2000 + 194; |
| 1822 | client.paramLen = 0; |
| 1823 | bzero(client.param, LYNQ_REQUEST_PARAM_BUF); |
| 1824 | 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] | 1825 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1826 | if (send_request(lynq_client_sockfd, &client) == -1) |
| 1827 | { |
| 1828 | LYERRLOG("send request fail"); |
Hong_Liu | 25edfe7 | 2023-06-16 01:13:42 -0700 | [diff] [blame] | 1829 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1830 | return -1; |
| 1831 | } |
rjw | ed00d04 | 2022-05-25 09:18:16 +0800 | [diff] [blame] | 1832 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
rjw | 20006d1 | 2022-04-21 16:29:04 +0800 | [diff] [blame] | 1833 | waitApnResult(); |
| 1834 | strcpy(result, g_lynq_apn_result); |
| 1835 | LYINFLOG(">>>>>result:%s",result); |
| 1836 | return 0; |
| 1837 | } |
| 1838 | |
rjw | 3bcbbf1 | 2022-04-22 16:47:18 +0800 | [diff] [blame] | 1839 | /*Typethree add for T800 platform 2022/04/21 end*/ |
Hong_Liu | 7d9ac8d | 2023-07-24 00:40:31 -0700 | [diff] [blame^] | 1840 | static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len) { |
| 1841 | FILE *fp; |
| 1842 | //printf("to exec cmd:%s\n", str_cmd); |
| 1843 | if((fp=popen(str_cmd,"r"))==NULL) |
| 1844 | { |
| 1845 | perror("popen error!"); |
| 1846 | return -1; |
| 1847 | } |
| 1848 | if((fread(str_cmd_ret,max_len,1,fp))<0) |
| 1849 | { |
| 1850 | perror("fread fail!"); |
| 1851 | fclose(fp); |
| 1852 | return -1; |
| 1853 | } |
| 1854 | fclose(fp); |
| 1855 | return 0; |
| 1856 | } |
| 1857 | int check_apn_status() |
| 1858 | { |
| 1859 | LYINFLOG("check_apn_status enter"); |
| 1860 | int ret = -1; |
| 1861 | char cmd_ret[8] ={0};//get mccmnc |
| 1862 | const char *cmd = "uci get radio_property.property.vendor_ril_data_gsm_mcc_mnc0"; |
| 1863 | const char *empty_str = ":empty"; |
| 1864 | ret = exec_cmd(cmd,cmd_ret,8); |
| 1865 | if(ret==0) |
| 1866 | { |
| 1867 | if(strlen(cmd_ret)==0) |
| 1868 | { |
| 1869 | LYERRLOG("not have mccmnc config in uci ram"); |
| 1870 | return 1; |
| 1871 | } |
| 1872 | if(strncmp(cmd_ret,empty_str,strlen(empty_str))==0) |
| 1873 | { |
| 1874 | LYERRLOG("mccmnc is empty"); |
| 1875 | return 2; |
| 1876 | } |
| 1877 | LYINFLOG("mccmnc is %s",cmd_ret); |
| 1878 | return 0; |
| 1879 | } |
| 1880 | else |
| 1881 | { |
| 1882 | LYERRLOG("exec cmd fail"); |
| 1883 | return -1; |
| 1884 | } |
| 1885 | return 0; |
| 1886 | } |
| 1887 | int radio_switch(int status) |
| 1888 | { |
| 1889 | Parcel *p =NULL; |
| 1890 | lynq_client_t client; |
| 1891 | int resp_type = -1; |
| 1892 | int token; |
| 1893 | int request = -1; |
| 1894 | int slot_id = -1; |
| 1895 | int error = -1; |
| 1896 | int version =0; |
| 1897 | int num = 0; |
| 1898 | char *temp_char = NULL; |
| 1899 | char mccmnc[32] = {0}; |
| 1900 | char mccmnckey[64] = {0}; |
| 1901 | client.uToken = get_utoken(); |
| 1902 | client.request = 59;//RIL_REQUEST_OEM_HOOK_RAW 59 |
| 1903 | client.paramLen = 1; |
| 1904 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF); |
| 1905 | sprintf(client.param,"AT+CFUN=%d",status); |
| 1906 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); |
| 1907 | pthread_mutex_lock(&g_lynq_data_sendto_mutex); |
| 1908 | if(send_request(lynq_client_sockfd,&client)==-1) |
| 1909 | { |
| 1910 | LYERRLOG("send request fail"); |
| 1911 | perror("[LYNQ_DATA] send request fail:"); |
| 1912 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1913 | return -1; |
| 1914 | } |
| 1915 | //get_response(lynq_client_sockfd,p); |
| 1916 | error = wait_response(lynq_client_sockfd,p,client.uToken); |
| 1917 | if(error!=0) |
| 1918 | { |
| 1919 | LYERRLOG("wait_response fail,ret:%d",error); |
| 1920 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1921 | return error; |
| 1922 | } |
| 1923 | pthread_mutex_unlock(&g_lynq_data_sendto_mutex); |
| 1924 | if(JumpHeader(p,&resp_type,&client.uToken,&request,&slot_id,&error)!=0) |
| 1925 | { |
| 1926 | LYERRLOG("JumpHeader fail"); |
| 1927 | return -1; |
| 1928 | } |
| 1929 | LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,client.uToken,request,slot_id,error); |
| 1930 | free_parcel(p); |
| 1931 | return error; |
| 1932 | } |