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