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