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