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