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