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