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