liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 | #include <stdlib.h>
|
| 3 | #include <unistd.h>
|
| 4 | #include <sys/socket.h>
|
| 5 | #include <errno.h>
|
| 6 | #include <fcntl.h>
|
| 7 | #include <string.h>
|
| 8 | #include <netinet/in.h>
|
| 9 | #include <arpa/inet.h>
|
| 10 | #include <linux/un.h>
|
| 11 | #include <linux/netlink.h>
|
| 12 | #include <cutils/properties.h>
|
| 13 | #include <time.h>
|
| 14 | #include <sys/time.h>
|
| 15 |
|
| 16 | //#include "cploader.h"
|
| 17 | #include "mbtk_log.h"
|
| 18 | #include "mbtk_ifc.h"
|
| 19 | #include "mbtk_type.h"
|
| 20 | #include "atchannel.h"
|
| 21 | #include "at_tok.h"
|
| 22 | #include "mbtk_utils.h"
|
| 23 | #include "mbtk_task.h"
|
| 24 | #include "mbtk_info.h"
|
| 25 | #include "mbtk_ntp.h"
|
| 26 | #include "mbtk_net_control.h"
|
| 27 | #include "info_data.h"
|
wangyouqiang | 38e5336 | 2024-01-23 10:53:48 +0800 | [diff] [blame] | 28 | #include "mbtk_led.h"
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 29 |
|
| 30 | #define TEMP_FAILURE_RETRY(exp) ({ \
|
| 31 | typeof (exp) _rc; \
|
| 32 | do { \
|
| 33 | _rc = (exp); \
|
| 34 | } while (_rc == -1 && errno == EINTR); \
|
| 35 | _rc; })
|
| 36 |
|
| 37 | #define BUFFER_SIZE 2048
|
| 38 | #define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"
|
| 39 | #define MBTK_BOOT_SERVER_READY "/etc/init.d/mbtk_boot_server_ready"
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 40 | #define MBTK_BOOT_NET_READY "/etc/init.d/mbtk_boot_net_ready"
|
| 41 | #define MBTK_RILD_PID_FILE "/var/run/mbtk_rild.pid"
|
| 42 | #define MBTK_RILD_TEMP_FILE "/tmp/mbtk_rild.count"
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 43 |
|
| 44 | struct cooling_device
|
| 45 | {
|
| 46 | const char *name;
|
| 47 | const char *action;
|
| 48 | const char *path;
|
| 49 | const char *event;
|
| 50 | const char *subsystem;
|
| 51 | };
|
| 52 | static pthread_t uevnet_task_id;
|
| 53 | extern net_info_t net_info;
|
| 54 | extern mbtK_cell_pack_info_t cell_info;
|
| 55 | extern info_cgact_wait_t cgact_wait;
|
| 56 | extern bool at_process;
|
yq.wang | d58f71e | 2024-08-21 23:45:31 -0700 | [diff] [blame] | 57 | extern bool at_cfun_command;
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 58 | static bool is_first_boot = FALSE;
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 59 |
|
| 60 | void setRadioPower(int isOn);
|
| 61 | int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
|
| 62 | int mbtk_signal_log(char *data);
|
| 63 |
|
| 64 | /* Called on command thread */
|
| 65 | static void onATTimeout()
|
| 66 | {
|
| 67 | LOGI("AT channel timeout; closing\n");
|
| 68 | at_close();
|
| 69 | }
|
| 70 |
|
| 71 | /* Called on command or reader thread */
|
| 72 | static void onATReaderClosed()
|
| 73 | {
|
| 74 | LOGI("AT channel closed\n");
|
| 75 | at_close();
|
| 76 | }
|
| 77 |
|
| 78 | //int req_time_set(int type, char *time, int *cme_err);
|
| 79 | static int metis_strptime(char *str_time)
|
| 80 | {
|
| 81 | struct tm stm;
|
| 82 | char dateTime[30];
|
| 83 | struct timeval tv;
|
| 84 | if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL)
|
| 85 | {
|
| 86 | time_t _t = mktime(&stm);
|
| 87 | tv.tv_sec = _t;
|
| 88 | if(settimeofday(&tv, NULL)) {
|
| 89 | LOG("Set time fail:%d", errno);
|
| 90 | return -1;
|
| 91 | } else {
|
| 92 | LOG("Set time to %s.", str_time);
|
| 93 | return 0;
|
| 94 | }
|
| 95 | } else {
|
| 96 | LOG("Set time fail.");
|
| 97 | return -1;
|
| 98 | }
|
| 99 | }
|
| 100 |
|
| 101 | static void* ntp_pthread_run(void* arg)
|
| 102 | {
|
| 103 | // Waitting for network connected.
|
| 104 | while(mbtk_net_state_get() == MBTK_NET_STATE_OFF) {
|
| 105 | sleep(1);
|
| 106 | }
|
| 107 | LOG("Network is connected.");
|
| 108 |
|
| 109 | char time_type[10];
|
| 110 | while(1){
|
| 111 | memset(time_type, 0, 10);
|
| 112 | property_get("persist.mbtk.time_type", time_type, "0");
|
| 113 | if(atoi(time_type) == MBTK_TIME_TYPE_NTP) // NTP time
|
| 114 | {
|
| 115 | char time_str[100] = {0};
|
| 116 | time_t time = 0;
|
| 117 | while((time = (time_t)mbtk_at_systime()) == 0) {
|
| 118 | usleep(100000);
|
| 119 | }
|
| 120 | struct tm *tm_t;
|
| 121 | tm_t = localtime(&time);
|
| 122 | strftime(time_str,128,"%F %T",tm_t);
|
| 123 |
|
| 124 | // NTP time
|
| 125 | metis_strptime(time_str);
|
| 126 | } else {
|
| 127 | break;
|
| 128 | }
|
| 129 |
|
| 130 | sleep(64); // Sleep 64s.
|
| 131 | }
|
| 132 | return NULL;
|
| 133 | }
|
| 134 |
|
| 135 | static void ntp_thread_start()
|
| 136 | {
|
| 137 | pthread_t ntp_pid;
|
| 138 | pthread_attr_t thread_attr;
|
| 139 | pthread_attr_init(&thread_attr);
|
| 140 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
|
| 141 | {
|
| 142 | LOG("pthread_attr_setdetachstate() fail.");
|
| 143 | return;
|
| 144 | }
|
| 145 |
|
| 146 | if(pthread_create(&ntp_pid, &thread_attr, ntp_pthread_run, NULL))
|
| 147 | {
|
| 148 | LOG("pthread_create() fail.");
|
| 149 | }
|
| 150 | }
|
| 151 |
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 152 | static void mbtk_net_ready()
|
| 153 | {
|
| 154 | // /etc/init.d/mbtk_boot_net_ready
|
| 155 | if(is_first_boot) {
|
| 156 | if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
|
| 157 | LOGD("Exec : %s", MBTK_BOOT_NET_READY);
|
| 158 | system(MBTK_BOOT_NET_READY);
|
| 159 | } else {
|
| 160 | LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
|
| 161 | }
|
| 162 | is_first_boot = FALSE; // Only one time.
|
| 163 | } else {
|
| 164 | LOGD("No exec : %s", MBTK_BOOT_NET_READY);
|
| 165 | }
|
| 166 | }
|
| 167 |
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 168 | bool sms_cmt = false;
|
| 169 | mbtk_sim_card_info sim_info_reg={0};
|
| 170 | static void onUnsolicited(const char *s, const char *sms_pdu)
|
| 171 | {
|
| 172 | LOGV("URC : %s", s);
|
| 173 | // MBTK_AT_READY
|
| 174 | if (strStartsWith(s, "MBTK_AT_READY")) // AT ready.
|
| 175 | {
|
| 176 |
|
| 177 | }
|
| 178 | #if 0
|
| 179 | else if(strStartsWith(s, "*SIMDETEC:")) // *SIMDETEC:1,SIM
|
| 180 | {
|
| 181 | const char* ptr = strstr(s, ",");
|
| 182 | if(ptr)
|
| 183 | {
|
| 184 | ptr++; // Jump ','
|
| 185 | if(memcmp(ptr, "SIM", 3) == 0)
|
| 186 | net_info.sim_state = MBTK_SIM_STATE_READY;
|
| 187 | else
|
| 188 | net_info.sim_state = MBTK_SIM_STATE_ABSENT;
|
| 189 | }
|
| 190 | }
|
| 191 | #endif
|
| 192 | else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
|
| 193 | {
|
| 194 | const char* ptr = s + strlen("*RADIOPOWER:");
|
| 195 | while(*ptr != '\0' && *ptr == ' ' )
|
| 196 | {
|
| 197 | ptr++;
|
| 198 | }
|
| 199 |
|
| 200 | uint8 state;
|
| 201 | if(*ptr == '1') {
|
| 202 | //net_info.radio_state = MBTK_RADIO_STATE_ON;
|
| 203 | // mbtk_radio_ready_cb();
|
| 204 | state = (uint8)1;
|
| 205 | } else {
|
| 206 | //net_info.radio_state = MBTK_RADIO_STATE_OFF;
|
| 207 | state = (uint8)0;
|
| 208 | }
|
| 209 | urc_msg_distribute(true, INFO_URC_MSG_RADIO_STATE, &state, sizeof(uint8));
|
| 210 | }
|
| 211 | // "CONNECT"
|
| 212 | else if(strStartsWith(s, "CONNECT"))
|
| 213 | {
|
| 214 | if(cgact_wait.waitting && cgact_wait.act) {
|
| 215 | cgact_wait.waitting = false;
|
| 216 | }
|
| 217 |
|
| 218 | uint8 data_pdp;
|
| 219 | data_pdp = 1; //
|
| 220 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 221 | }
|
| 222 | // +CGEV:
|
| 223 | // +CGEV: NW DEACT <cid>,<cid>
|
| 224 | // +CGEV: ME DEACT <cid>,<cid>
|
| 225 | // +CGEV: NW PDN DEACT <cid>
|
| 226 | // +CGEV: ME PDN DEACT <cid>
|
| 227 | // +CGEV: NW DETACH
|
| 228 | // +CGEV: ME DETACH
|
| 229 | //
|
| 230 | // +CGEV: NW ACT <cid>,<cid>
|
| 231 | // +CGEV: ME ACT <cid>,<cid>
|
| 232 | // +CGEV: EPS PDN ACT <cid>
|
| 233 | // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
|
| 234 | // +CGEV: ME PDN ACT <cid>,<reason>
|
| 235 | // +CGEV: NW PDN ACT <cid>
|
| 236 | // +CGEV: EPS ACT <cid>
|
| 237 | // +CGEV: NW MODIFY <cid>,<reason>
|
| 238 | // +CGEV: NW REATTACH
|
| 239 | else if(strStartsWith(s, "+CGEV:"))
|
| 240 | {
|
yq.wang | d58f71e | 2024-08-21 23:45:31 -0700 | [diff] [blame] | 241 | if(at_process && !at_cfun_command) {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 242 | if(cgact_wait.act) {
|
| 243 | if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
|
| 244 | if(cgact_wait.cid == atoi(s + 18)) {
|
| 245 | cgact_wait.waitting = false;
|
| 246 | }
|
| 247 |
|
| 248 | uint8 data_pdp;
|
| 249 | char* tmp_s = memdup(s + 18,strlen(s + 18));
|
| 250 | char* free_ptr = tmp_s;
|
| 251 | char *line = tmp_s;
|
| 252 | int tmp_int;
|
| 253 | if (at_tok_start(&line) < 0)
|
| 254 | {
|
| 255 | goto at_PDP_CREG_EXIT;
|
| 256 | }
|
| 257 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 258 | {
|
| 259 | goto at_PDP_CREG_EXIT;
|
| 260 | }
|
| 261 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 262 | {
|
| 263 | goto at_PDP_CREG_EXIT;
|
| 264 | }
|
| 265 | data_pdp = tmp_int;
|
| 266 | at_PDP_CREG_EXIT:
|
| 267 | free(free_ptr);
|
| 268 |
|
| 269 | //data_pdp = (uint8)atoi(s + 20); //reason
|
| 270 | if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
|
| 271 | {
|
| 272 | if(data_pdp == 0)
|
| 273 | {
|
| 274 | data_pdp = 25;
|
| 275 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 276 | //data_pdp = cgact_wait.cid + 200;
|
| 277 | }
|
| 278 | else if(data_pdp == 1)
|
| 279 | {
|
| 280 | data_pdp = 26;
|
| 281 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 282 | }
|
| 283 | else if(data_pdp == 2)
|
| 284 | {
|
| 285 | data_pdp = 27;
|
| 286 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 287 | }
|
| 288 | else if(data_pdp == 3)
|
| 289 | {
|
| 290 | data_pdp = 27;
|
| 291 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 292 | }
|
| 293 | else
|
| 294 | {
|
| 295 |
|
| 296 | }
|
| 297 | if(cgact_wait.cid != 0)
|
| 298 | {
|
| 299 | data_pdp = cgact_wait.cid + 200;
|
| 300 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 301 | }
|
| 302 | }
|
| 303 | } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
|
| 304 | if(cgact_wait.cid == atoi(s + 17)) {
|
| 305 | cgact_wait.waitting = false;
|
| 306 | }
|
| 307 | }
|
| 308 | } else {
|
| 309 | if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
|
| 310 | if(cgact_wait.cid == atoi(s + 20)) {
|
| 311 | cgact_wait.waitting = false;
|
| 312 | }
|
| 313 | uint8 data_pdp;
|
| 314 | data_pdp = 0; //
|
| 315 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 316 | if(cgact_wait.cid != 0)
|
| 317 | {
|
| 318 | data_pdp = cgact_wait.cid + 100;
|
| 319 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 320 | }
|
| 321 | }
|
| 322 | }
|
| 323 | } else {
|
| 324 | // apn_state_set
|
| 325 |
|
| 326 | // +CGEV: NW PDN DEACT <cid>
|
| 327 |
|
| 328 | // +CGEV: EPS PDN ACT 1
|
| 329 | // +CGEV: ME PDN ACT 8,1
|
| 330 |
|
| 331 | // +CGEV: ME PDN ACT 2,4
|
| 332 | uint8 data[2] = {0xFF};
|
| 333 | if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
|
| 334 | //apn_state_set(atoi(s + 20), false);
|
| 335 | data[0] = (uint8)0;
|
| 336 | data[1] = (uint8)atoi(s + 20);
|
| 337 |
|
| 338 | uint8 data_pdp;
|
| 339 | data_pdp = 0; //
|
| 340 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 341 | data_pdp = data[1] + 100;
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 342 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 343 | } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
|
| 344 | //apn_state_set(atoi(s + 19), true);
|
b.liu | f37bd33 | 2024-03-18 13:51:24 +0800 | [diff] [blame] | 345 | #if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
|
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 346 | //data[0] = (uint8)1;
|
| 347 | //data[1] = (uint8)atoi(s + 19);
|
| 348 | #else
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 349 | data[0] = (uint8)1;
|
| 350 | data[1] = (uint8)atoi(s + 19);
|
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 351 | #endif
|
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 352 | } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
|
| 353 | //apn_state_set(atoi(s + 19), true);
|
| 354 | data[0] = (uint8)0;
|
| 355 | data[1] = (uint8)atoi(s + 20);
|
| 356 |
|
| 357 | uint8 data_pdp;
|
| 358 | data_pdp = 0; //
|
| 359 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 360 | data_pdp = data[1] + 100;
|
| 361 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 362 | } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
|
| 363 | //apn_state_set(atoi(s + 18), true);
|
| 364 | data[0] = (uint8)1;
|
| 365 | data[1] = (uint8)atoi(s + 18);
|
| 366 |
|
| 367 | uint8 data_pdp;
|
| 368 | char* tmp_s = memdup(s + 18,strlen(s + 18));
|
| 369 | char* free_ptr = tmp_s;
|
| 370 | char *line = tmp_s;
|
| 371 | int tmp_int;
|
| 372 | if (at_tok_start(&line) < 0)
|
| 373 | {
|
| 374 | goto PDP_CREG_EXIT;
|
| 375 | }
|
| 376 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 377 | {
|
| 378 | goto PDP_CREG_EXIT;
|
| 379 | }
|
| 380 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 381 | {
|
| 382 | goto PDP_CREG_EXIT;
|
| 383 | }
|
| 384 | data_pdp = tmp_int;
|
| 385 | PDP_CREG_EXIT:
|
| 386 | free(free_ptr);
|
| 387 | //data_pdp = (uint8)atoi(s + 20); //reason
|
| 388 | if(data[1] >= 1 && data[1] < 8)
|
| 389 | {
|
| 390 | if(data_pdp == 0)
|
| 391 | {
|
| 392 | data_pdp = 25;
|
| 393 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 394 | }
|
| 395 | else if(data_pdp == 1)
|
| 396 | {
|
| 397 | data_pdp = 26;
|
| 398 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 399 | }
|
| 400 | else if(data_pdp == 2)
|
| 401 | {
|
| 402 | data_pdp = 27;
|
| 403 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 404 | }
|
| 405 | else if(data_pdp == 3)
|
| 406 | {
|
| 407 | data_pdp = 27;
|
| 408 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 409 | }
|
| 410 | else
|
| 411 | {
|
| 412 |
|
| 413 | }
|
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 414 |
|
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 415 | data_pdp = data[1] + 200;
|
| 416 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
wangyouqiang | 3947b30 | 2024-07-04 17:26:08 +0800 | [diff] [blame] | 417 | data[1] = 0;
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 418 | }
|
| 419 | } else {
|
| 420 | LOGI("No process : %s", s);
|
| 421 | }
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 422 |
|
wangyouqiang | 3947b30 | 2024-07-04 17:26:08 +0800 | [diff] [blame] | 423 | urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 424 | }
|
| 425 | }
|
| 426 | // +CREG: 1, "8010", "000060a5", 0, 2, 0
|
| 427 | // +CREG: 1, "8330", "06447347", 7, 2, 0
|
| 428 | // +CEREG: 1, "8330", "06447347", 7
|
| 429 | // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
|
| 430 | // $CREG: 1, "8010", "000060a7", 0,, 2, 0
|
| 431 | // +CGREG: 1
|
| 432 | else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
|
| 433 | || strStartsWith(s, "+CEREG:")) // LTE data registed.
|
| 434 | {
|
| 435 | char* tmp_s = s + 7;
|
liuyang | 67f4bac | 2024-06-26 17:06:13 +0800 | [diff] [blame] | 436 | static bool net_led_gms_wcdma = FALSE;
|
| 437 | static bool net_led_lte = FALSE;
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 438 | while(*tmp_s && *tmp_s == ' ')
|
| 439 | tmp_s++;
|
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 440 | uint8 data[2];
|
| 441 | data[0] = (uint8)atoi(tmp_s); // Reg State.
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 442 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 443 | if(strStartsWith(s, "+CGREG:"))
|
liuyang | 67f4bac | 2024-06-26 17:06:13 +0800 | [diff] [blame] | 444 | {
|
| 445 | data[1] = 0; // GMS/WCDMA
|
| 446 | if(data[0] == 1)
|
| 447 | {
|
| 448 | net_led_gms_wcdma = TRUE;
|
| 449 | }
|
| 450 | else
|
| 451 | {
|
| 452 | net_led_gms_wcdma = FALSE;
|
| 453 | }
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 454 |
|
| 455 | }
|
| 456 | else
|
liuyang | 67f4bac | 2024-06-26 17:06:13 +0800 | [diff] [blame] | 457 | {
|
| 458 | data[1] = 1; // LTE
|
| 459 | if(data[0] == 1)
|
| 460 | {
|
| 461 | net_led_lte = TRUE;
|
| 462 | }
|
| 463 | else
|
| 464 | {
|
| 465 | net_led_lte = FALSE;
|
| 466 | }
|
| 467 | }
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 468 |
|
liuyang | 67f4bac | 2024-06-26 17:06:13 +0800 | [diff] [blame] | 469 | if(FALSE == net_led_gms_wcdma && FALSE == net_led_lte)
|
| 470 | {
|
| 471 | mbtk_net_led_set(MBTK_NET_LED_SEARCH_NETWORK);
|
| 472 | }
|
| 473 | else
|
| 474 | {
|
| 475 | mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
|
| 476 | mbtk_net_ready();
|
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 477 | }
|
| 478 |
|
| 479 | urc_msg_distribute(true, INFO_URC_MSG_NET_PS_REG_STATE, data, sizeof(data));
|
liuyang | 37623a0 | 2024-06-20 15:21:39 +0800 | [diff] [blame] | 480 | urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 481 | }
|
| 482 | // +CREG: 1, "8010", "000060a5", 0, 2, 0
|
| 483 | // +CREG: 1, "8330", "06447347", 7, 2, 0
|
| 484 | // +CREG: 0
|
| 485 | else if(strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
|
| 486 | {
|
| 487 | uint8 data[3];
|
| 488 | data[0] = (uint8)MBTK_NET_CS_STATE;
|
| 489 | char* tmp_s = memdup(s,strlen(s));
|
| 490 | char* free_ptr = tmp_s;
|
| 491 | char *line = tmp_s;
|
| 492 | int tmp_int;
|
| 493 | char *tmp_str;
|
| 494 | if (at_tok_start(&line) < 0)
|
| 495 | {
|
| 496 | goto CREG_EXIT;
|
| 497 | }
|
| 498 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 499 | {
|
| 500 | goto CREG_EXIT;
|
| 501 | }
|
| 502 | data[1] = (uint8)tmp_int; // Reg State.
|
| 503 | if (data[1])
|
| 504 | {
|
| 505 | if (at_tok_nextstr(&line, &tmp_str) < 0)
|
| 506 | {
|
| 507 | goto CREG_EXIT;
|
| 508 | }
|
| 509 | if (at_tok_nextstr(&line, &tmp_str) < 0)
|
| 510 | {
|
| 511 | goto CREG_EXIT;
|
| 512 | }
|
| 513 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 514 | {
|
| 515 | goto CREG_EXIT;
|
| 516 | }
|
| 517 | data[2] = (uint8)tmp_int; // AcT
|
| 518 | } else {
|
| 519 | data[2] = (uint8)0xFF; // AcT
|
| 520 | }
|
| 521 | if(data[1] == 5)
|
| 522 | {
|
| 523 | uint8 data_pdp;
|
| 524 | data_pdp = 5; //
|
| 525 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 526 | }
|
| 527 | urc_msg_distribute(false, INFO_URC_MSG_NET_CS_REG_STATE, data, sizeof(data));
|
liuyang | 37623a0 | 2024-06-20 15:21:39 +0800 | [diff] [blame] | 528 | urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 529 | CREG_EXIT:
|
| 530 | free(free_ptr);
|
| 531 | }
|
| 532 | // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
|
| 533 | else if(strStartsWith(s, "+CLCC:"))
|
| 534 | {
|
| 535 | mbtk_call_info_t reg;
|
| 536 | reg.call_wait = MBTK_CLCC;
|
| 537 | char* tmp_s = memdup(s,strlen(s));
|
| 538 | char* free_ptr = tmp_s;
|
| 539 | char *line = tmp_s;
|
| 540 | int tmp_int;
|
| 541 | char *tmp_str;
|
| 542 | int err;
|
| 543 |
|
| 544 | err = at_tok_start(&line);
|
| 545 | if (err < 0)
|
| 546 | {
|
| 547 | goto CLCC_EXIT;
|
| 548 | }
|
| 549 | err = at_tok_nextint(&line, &tmp_int); // dir1
|
| 550 | if (err < 0)
|
| 551 | {
|
| 552 | goto CLCC_EXIT;
|
| 553 | }
|
| 554 | reg.dir1 = (uint8)tmp_int;
|
| 555 | err = at_tok_nextint(&line, &tmp_int);// dir
|
| 556 | if (err < 0)
|
| 557 | {
|
| 558 | goto CLCC_EXIT;
|
| 559 | }
|
| 560 | reg.dir = (uint8)tmp_int;
|
| 561 | err = at_tok_nextint(&line, &tmp_int);// state
|
| 562 | if (err < 0)
|
| 563 | {
|
| 564 | goto CLCC_EXIT;
|
| 565 | }
|
| 566 | reg.state = (uint8)tmp_int;
|
| 567 | err = at_tok_nextint(&line, &tmp_int);// mode
|
| 568 | if (err < 0)
|
| 569 | {
|
| 570 | goto CLCC_EXIT;
|
| 571 | }
|
| 572 | reg.mode = (uint8)tmp_int;
|
| 573 | err = at_tok_nextint(&line, &tmp_int);// mpty
|
| 574 | if (err < 0)
|
| 575 | {
|
| 576 | goto CLCC_EXIT;
|
| 577 | }
|
| 578 | reg.mpty = (uint8)tmp_int;
|
| 579 | err = at_tok_nextstr(&line, &tmp_str); // phone_number
|
| 580 | if (err < 0)
|
| 581 | {
|
| 582 | goto CLCC_EXIT;
|
| 583 | }
|
| 584 |
|
| 585 | memset(reg.phone_number,0,sizeof(reg.phone_number));
|
| 586 | memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
|
| 587 | err = at_tok_nextint(&line, &tmp_int);// tpye
|
| 588 | if (err < 0)
|
| 589 | {
|
| 590 | goto CLCC_EXIT;
|
| 591 | }
|
| 592 | reg.type = (uint8)tmp_int;
|
| 593 |
|
r.xiao | e1404b3 | 2024-05-23 22:43:39 -0700 | [diff] [blame] | 594 | if(reg.state == 2 || reg.state == 3 || reg.state == 0)
|
| 595 | {
|
| 596 | mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
|
| 597 | }
|
| 598 |
|
r.xiao | 195e252 | 2024-05-31 03:19:02 -0700 | [diff] [blame] | 599 | if(reg.state == 4 && reg.dir == 1)
|
| 600 | {
|
| 601 | mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
|
| 602 | }
|
| 603 |
|
| 604 |
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 605 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 606 | CLCC_EXIT:
|
| 607 | free(free_ptr);
|
| 608 | }
|
| 609 | // +CPAS: 4
|
| 610 | else if(strStartsWith(s, "+CPAS:"))
|
| 611 | {
|
| 612 | mbtk_call_info_t reg;
|
| 613 | reg.call_wait = 0;
|
| 614 | char* tmp_s = memdup(s,strlen(s));
|
| 615 | char* free_ptr = tmp_s;
|
| 616 | char *line = tmp_s;
|
| 617 | int tmp_int;
|
| 618 | int err;
|
| 619 |
|
| 620 | memset(®,0,sizeof(reg));
|
| 621 |
|
| 622 | err = at_tok_start(&line);
|
| 623 | if (err < 0)
|
| 624 | {
|
| 625 | goto CPAS_EXIT;
|
| 626 | }
|
| 627 | err = at_tok_nextint(&line, &tmp_int);
|
| 628 | if (err < 0)
|
| 629 | {
|
| 630 | goto CPAS_EXIT;
|
| 631 | }
|
| 632 | reg.pas = (uint8)tmp_int;
|
| 633 | reg.call_wait = MBTK_CPAS;
|
| 634 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 635 | CPAS_EXIT:
|
| 636 | free(free_ptr);
|
| 637 | }
|
| 638 | // +CALLDISCONNECT: 1
|
| 639 | else if(strStartsWith(s, "+CALLDISCONNECT:"))
|
| 640 | {
|
| 641 | mbtk_call_info_t reg;
|
| 642 | reg.call_wait = 0;
|
| 643 | char* tmp_s = memdup(s,strlen(s));
|
| 644 | char* free_ptr = tmp_s;
|
| 645 | char *line = tmp_s;
|
| 646 | int tmp_int;
|
| 647 | int err;
|
| 648 |
|
| 649 | memset(®,0,sizeof(reg));
|
| 650 |
|
| 651 | err = at_tok_start(&line);
|
| 652 | if (err < 0)
|
| 653 | {
|
| 654 | goto CALLDISCONNECTED_EXIT;
|
| 655 | }
|
| 656 | err = at_tok_nextint(&line, &tmp_int);
|
| 657 | if (err < 0)
|
| 658 | {
|
| 659 | goto CALLDISCONNECTED_EXIT;
|
| 660 | }
|
| 661 | reg.disconnected_id = tmp_int;
|
| 662 | reg.call_wait = MBTK_DISCONNECTED;
|
r.xiao | e1404b3 | 2024-05-23 22:43:39 -0700 | [diff] [blame] | 663 |
|
| 664 | if(reg.call_wait == MBTK_DISCONNECTED)
|
| 665 | {
|
| 666 | mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
|
| 667 | }
|
| 668 |
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 669 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 670 |
|
| 671 | CALLDISCONNECTED_EXIT:
|
| 672 | free(free_ptr);
|
| 673 | }
|
| 674 | // *SIMDETEC:1,SIM
|
| 675 | else if(strStartsWith(s, "*SIMDETEC:"))
|
| 676 | {
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 677 | if(strStartsWith(s, "*SIMDETEC:1,NOS"))
|
| 678 | {
|
| 679 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 680 | }
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 681 |
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 682 | sim_info_reg.sim = -1;
|
| 683 | if(strStartsWith(s, "*SIMDETEC:1,NOS"))
|
| 684 | sim_info_reg.sim = 0;
|
| 685 | else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
|
| 686 | sim_info_reg.sim = 1;
|
| 687 | if(sim_info_reg.sim == 0)
|
| 688 | {
|
| 689 | uint8 data_pdp;
|
| 690 | data_pdp = 11; //
|
| 691 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 692 | }
|
| 693 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 694 | }
|
| 695 | // *EUICC:1
|
| 696 | /*0: SIM
|
| 697 | 1: USIM
|
| 698 | 2: TEST SIM
|
| 699 | 3: TEST USIM
|
| 700 | 4: UNKNOWN
|
| 701 | Note: *EUICC:
|
| 702 | */
|
| 703 | else if(strStartsWith(s, "*EUICC:"))
|
| 704 | {
|
yq.wang | b184fc2 | 2024-08-19 00:54:30 -0700 | [diff] [blame] | 705 | sim_info_reg.sim = -1;
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 706 | sim_info_reg.sim_card_type = -1;
|
| 707 | if(strStartsWith(s, "*EUICC: 0"))
|
| 708 | sim_info_reg.sim_card_type = 1;
|
| 709 | else if(strStartsWith(s, "*EUICC: 1"))
|
| 710 | sim_info_reg.sim_card_type = 2;
|
| 711 | else if(strStartsWith(s, "*EUICC: 2"))
|
| 712 | sim_info_reg.sim_card_type = 1;
|
| 713 | else if(strStartsWith(s, "*EUICC: 3"))
|
| 714 | sim_info_reg.sim_card_type = 2;
|
| 715 | else if(strStartsWith(s, "*EUICC: 4"))
|
| 716 | sim_info_reg.sim_card_type = 0;
|
| 717 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 718 | }
|
| 719 | // +CPIN: SIM PIN
|
| 720 | else if(strStartsWith(s, "+CPIN:"))
|
| 721 | {
|
| 722 | sim_info_reg.sim = -1;
|
| 723 | if(strStartsWith(s, "+CPIN: READY"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 724 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 725 | sim_info_reg.sim = 1;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 726 | net_info.sim_state = MBTK_SIM_READY;
|
| 727 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 728 | else if(strStartsWith(s, "+CPIN: SIM PIN"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 729 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 730 | sim_info_reg.sim = 2;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 731 | net_info.sim_state = MBTK_SIM_PIN;
|
| 732 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 733 | else if(strStartsWith(s, "+CPIN: SIM PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 734 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 735 | sim_info_reg.sim = 3;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 736 | net_info.sim_state = MBTK_SIM_PUK;
|
| 737 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 738 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 739 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 740 | sim_info_reg.sim = 4;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 741 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 742 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 743 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 744 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 745 | sim_info_reg.sim = 5;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 746 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 747 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 748 | else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 749 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 750 | sim_info_reg.sim = 6;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 751 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 752 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 753 | else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 754 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 755 | sim_info_reg.sim = 7;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 756 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 757 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 758 | else if(strStartsWith(s, "+CPIN: SIM PIN2"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 759 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 760 | sim_info_reg.sim = 8;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 761 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 762 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 763 | else if(strStartsWith(s, "+CPIN: SIM PUK2"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 764 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 765 | sim_info_reg.sim = 9;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 766 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 767 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 768 | else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 769 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 770 | sim_info_reg.sim = 10;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 771 | net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
|
| 772 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 773 | else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 774 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 775 | sim_info_reg.sim = 11;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 776 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 777 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 778 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 779 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 780 | sim_info_reg.sim = 12;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 781 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 782 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 783 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 784 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 785 | sim_info_reg.sim = 13;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 786 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 787 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 788 | else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 789 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 790 | sim_info_reg.sim = 14;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 791 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 792 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 793 | else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 794 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 795 | sim_info_reg.sim = 15;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 796 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 797 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 798 | else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 799 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 800 | sim_info_reg.sim = 16;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 801 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 802 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 803 | else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 804 | {
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 805 | sim_info_reg.sim = 17;
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 806 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 807 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 808 | else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
|
liuyang | e22a25e | 2024-05-23 19:41:52 +0800 | [diff] [blame] | 809 | {
|
| 810 | sim_info_reg.sim = 18;
|
| 811 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 812 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 813 | else
|
| 814 | sim_info_reg.sim = 20;
|
| 815 |
|
| 816 | if(sim_info_reg.sim == 18)
|
| 817 | {
|
| 818 | uint8 data_pdp;
|
| 819 | data_pdp = 11; //
|
| 820 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 821 | }
|
| 822 |
|
| 823 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 824 | }
|
| 825 | // +CMT: ,23
|
| 826 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
| 827 | else if(strStartsWith(s, "+CMT:") || sms_cmt)
|
| 828 | {
|
| 829 | if(!sms_cmt){
|
| 830 | sms_cmt = true;
|
| 831 | }else{
|
| 832 | sms_cmt = false;
|
| 833 | }
|
| 834 | printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
|
| 835 | urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
|
| 836 | }
|
| 837 | #if 0
|
| 838 | // LTE data registed.
|
| 839 | // +CEREG: 1, "8330", "06447347", 7
|
| 840 | else if(strStartsWith(s, "+CEREG:"))
|
| 841 | {
|
| 842 | char* tmp_s = memdup(s,strlen(s));
|
| 843 | char* free_ptr = tmp_s;
|
| 844 | char *line = tmp_s;
|
| 845 | int tmp_int;
|
| 846 | char *tmp_str;
|
| 847 | if (at_tok_start(&line) < 0)
|
| 848 | {
|
| 849 | goto CREG_EXIT;
|
| 850 | }
|
| 851 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 852 | {
|
| 853 | goto CREG_EXIT;
|
| 854 | }
|
| 855 | uint8 data = (uint8)tmp_int; // Reg State.
|
| 856 |
|
| 857 | urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
|
| 858 | CREG_EXIT:
|
| 859 | free(free_ptr);
|
| 860 | }
|
| 861 | #endif
|
| 862 | /*
|
| 863 | // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
|
| 864 | // <rsrp>,<rsrq>, <sinr>,
|
| 865 | // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
|
| 866 | // cellId,subFrameAssignType,specialSubframePatterns,transMode
|
| 867 | // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
|
| 868 | // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
|
| 869 | // dlBer, ulBer,
|
| 870 | // diversitySinr, diversityRssi
|
| 871 | +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
|
| 872 | 0, 0, 0,
|
| 873 | 1, 10, 0, 1, 0, 1059, 78, 3959566565,
|
| 874 | 105149248, 2, 7, 7,
|
| 875 | 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
|
| 876 | 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 877 | 0, 0,
|
| 878 | 7, 44
|
| 879 | */
|
| 880 | else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
|
| 881 | {
|
| 882 | // tac, PCI, dlEuarfcn, ulEuarfcn, band
|
| 883 | if(cell_info.running) {
|
| 884 | int tmp_int;
|
| 885 | int i = 0;
|
| 886 | char* tmp_s = memdup(s,strlen(s));
|
| 887 | char* free_ptr = tmp_s;
|
| 888 | char *line = tmp_s;
|
| 889 | if (at_tok_start(&line) < 0)
|
| 890 | {
|
| 891 | goto EEMLTESVC_EXIT;
|
| 892 | }
|
| 893 |
|
| 894 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 895 | {
|
| 896 | goto EEMLTESVC_EXIT;
|
| 897 | }
|
| 898 | cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
|
| 899 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 900 | {
|
| 901 | goto EEMLTESVC_EXIT;
|
| 902 | }
|
| 903 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 904 | {
|
| 905 | goto EEMLTESVC_EXIT;
|
| 906 | }
|
| 907 | cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
|
| 908 | /*
|
| 909 | // Jump 2 integer.
|
| 910 | i = 0;
|
| 911 | while(i < 2) {
|
| 912 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 913 | {
|
| 914 | goto EEMLTESVC_EXIT;
|
| 915 | }
|
| 916 | i++;
|
| 917 | }
|
| 918 | */
|
| 919 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 920 | {
|
| 921 | goto EEMLTESVC_EXIT;
|
| 922 | }
|
| 923 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //tac
|
| 924 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 925 | {
|
| 926 | goto EEMLTESVC_EXIT;
|
| 927 | }
|
| 928 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //pci
|
| 929 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 930 | {
|
| 931 | goto EEMLTESVC_EXIT;
|
| 932 | }
|
| 933 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //dl arfcn
|
| 934 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 935 | {
|
| 936 | goto EEMLTESVC_EXIT;
|
| 937 | }
|
| 938 | cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //ul arfcn
|
| 939 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 940 | {
|
| 941 | goto EEMLTESVC_EXIT;
|
| 942 | }
|
| 943 | cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
|
| 944 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 945 | {
|
| 946 | goto EEMLTESVC_EXIT;
|
| 947 | }
|
| 948 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 949 | {
|
| 950 | goto EEMLTESVC_EXIT;
|
| 951 | }
|
| 952 | cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //cid
|
| 953 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 954 | {
|
| 955 | goto EEMLTESVC_EXIT;
|
| 956 | }
|
| 957 | cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrp
|
| 958 |
|
| 959 | for(i =0; i < 10; i++)
|
| 960 | {
|
| 961 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 962 | {
|
| 963 | goto EEMLTESVC_EXIT;
|
| 964 | }
|
| 965 | }
|
| 966 | cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
|
| 967 |
|
| 968 | cell_info.cell_num++;
|
| 969 |
|
| 970 | EEMLTESVC_EXIT:
|
| 971 | free(free_ptr);
|
| 972 | }
|
| 973 | }
|
| 974 | /*
|
| 975 | // index,phyCellId,euArfcn,rsrp,rsrq
|
| 976 | +EEMLTEINTER: 0, 65535, 38950, 0, 0
|
| 977 | */
|
| 978 | else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
|
| 979 | {
|
| 980 | // phyCellId,euArfcn,rsrp,rsrq
|
| 981 | if(cell_info.running) {
|
| 982 | int tmp_int;
|
| 983 | char* tmp_s = memdup(s,strlen(s));
|
| 984 | char* free_ptr = tmp_s;
|
| 985 | char *line = tmp_s;
|
| 986 | if (at_tok_start(&line) < 0)
|
| 987 | {
|
| 988 | goto EEMLTEINTER_EXIT;
|
| 989 | }
|
| 990 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 991 | {
|
| 992 | goto EEMLTEINTER_EXIT;
|
| 993 | }
|
| 994 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
|
| 995 | {
|
| 996 | goto EEMLTEINTER_EXIT;
|
| 997 | }
|
| 998 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
|
| 999 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1000 | {
|
| 1001 | goto EEMLTEINTER_EXIT;
|
| 1002 | }
|
| 1003 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
|
| 1004 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1005 | {
|
| 1006 | goto EEMLTEINTER_EXIT;
|
| 1007 | }
|
| 1008 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
|
| 1009 | LOG("cell line : %s", line);
|
| 1010 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1011 | {
|
| 1012 | goto EEMLTEINTER_EXIT;
|
| 1013 | }
|
| 1014 | cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
|
| 1015 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1016 | {
|
| 1017 | LOG("cell tmp_int : %d", tmp_int);
|
| 1018 | goto EEMLTEINTER_EXIT;
|
| 1019 | }
|
| 1020 | cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
|
| 1021 | LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
|
| 1022 | cell_info.cell_num++;
|
| 1023 | EEMLTEINTER_EXIT:
|
| 1024 | free(free_ptr);
|
| 1025 | }
|
| 1026 | }
|
| 1027 | // Do nothing
|
| 1028 | else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
|
| 1029 | {
|
| 1030 | if(cell_info.running) {
|
| 1031 |
|
| 1032 | }
|
| 1033 | }
|
| 1034 | // WCDMA
|
| 1035 | /*
|
| 1036 | // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
|
| 1037 |
|
| 1038 | // if sCMeasPresent == 1
|
| 1039 | // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
|
| 1040 | // endif
|
| 1041 |
|
| 1042 | // if sCParamPresent == 1
|
| 1043 | // rac, nom, mcc, mnc_len, mnc, lac, ci,
|
| 1044 | // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
|
| 1045 | // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
|
| 1046 | // endif
|
| 1047 |
|
| 1048 | // if ueOpStatusPresent == 1
|
| 1049 | // rrcState, numLinks, srncId, sRnti,
|
| 1050 | // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
|
| 1051 | // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
|
| 1052 | // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
|
| 1053 | // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
|
| 1054 | // endif
|
| 1055 | //
|
| 1056 | +EEMUMTSSVC: 3, 1, 1, 1,
|
| 1057 | -80, 27, -6, -18, -115, -32768,
|
| 1058 | 1, 1, 1120, 2, 1, 61697, 168432821,
|
| 1059 | 15, 24, 10763, 0, 0, 0, 0,
|
| 1060 | 128, 128, 65535, 0, 0,
|
| 1061 | 2, 255, 65535, 4294967295,
|
| 1062 | 0, 0, 0, 0, 0, 0,
|
| 1063 | 0, 0, 0, 0, 0, 0, 1, 1,
|
| 1064 | 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
|
| 1065 | 0, 0, 0, 0, 0, 0
|
| 1066 | */
|
| 1067 | else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
|
| 1068 | {
|
| 1069 | // lac, ci, arfcn
|
| 1070 | if(cell_info.running) {
|
| 1071 | int tmp_int;
|
| 1072 | int i = 0;
|
| 1073 | char* tmp_s = memdup(s,strlen(s));
|
| 1074 | char* free_ptr = tmp_s;
|
| 1075 | char *line = tmp_s;
|
| 1076 | if (at_tok_start(&line) < 0)
|
| 1077 | {
|
| 1078 | goto EEMUMTSSVC_EXIT;
|
| 1079 | }
|
| 1080 | // Jump 12 integer.
|
| 1081 | i = 0;
|
| 1082 | while(i < 12) {
|
| 1083 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1084 | {
|
| 1085 | goto EEMUMTSSVC_EXIT;
|
| 1086 | }
|
| 1087 | i++;
|
| 1088 | }
|
| 1089 | // mcc
|
| 1090 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1091 | {
|
| 1092 | goto EEMUMTSSVC_EXIT;
|
| 1093 | }
|
| 1094 | cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
|
| 1095 | // mnc
|
| 1096 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1097 | {
|
| 1098 | goto EEMUMTSSVC_EXIT;
|
| 1099 | }
|
| 1100 | cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
|
| 1101 | // lac
|
| 1102 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1103 | {
|
| 1104 | goto EEMUMTSSVC_EXIT;
|
| 1105 | }
|
| 1106 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
|
| 1107 | // ci
|
| 1108 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1109 | {
|
| 1110 | goto EEMUMTSSVC_EXIT;
|
| 1111 | }
|
| 1112 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
|
| 1113 |
|
| 1114 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1115 | {
|
| 1116 | goto EEMUMTSSVC_EXIT;
|
| 1117 | }
|
| 1118 | // cpi
|
| 1119 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1120 | {
|
| 1121 | goto EEMUMTSSVC_EXIT;
|
| 1122 | }
|
| 1123 | cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
|
| 1124 | /*
|
| 1125 | // Jump 2 integer.
|
| 1126 | i = 0;
|
| 1127 | while(i < 2) {
|
| 1128 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1129 | {
|
| 1130 | goto EEMUMTSSVC_EXIT;
|
| 1131 | }
|
| 1132 | i++;
|
| 1133 | }
|
| 1134 | */
|
| 1135 | // arfcn
|
| 1136 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1137 | {
|
| 1138 | goto EEMUMTSSVC_EXIT;
|
| 1139 | }
|
| 1140 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
|
| 1141 |
|
| 1142 | cell_info.cell_num++;
|
| 1143 | EEMUMTSSVC_EXIT:
|
| 1144 | free(free_ptr);
|
| 1145 | }
|
| 1146 | }
|
| 1147 | /*
|
| 1148 | // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
|
| 1149 | +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
|
| 1150 | */
|
| 1151 | else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
|
| 1152 | {
|
| 1153 | // lac, ci, arfcn
|
| 1154 | if(cell_info.running) {
|
| 1155 | int tmp_int;
|
| 1156 | int i = 0;
|
| 1157 | char* tmp_s = memdup(s,strlen(s));
|
| 1158 | char* free_ptr = tmp_s;
|
| 1159 | char *line = tmp_s;
|
| 1160 | if (at_tok_start(&line) < 0)
|
| 1161 | {
|
| 1162 | goto EEMUMTSINTRA_EXIT;
|
| 1163 | }
|
| 1164 | // Jump 8 integer.
|
| 1165 | i = 0;
|
| 1166 | while(i < 8) {
|
| 1167 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1168 | {
|
| 1169 | goto EEMUMTSINTRA_EXIT;
|
| 1170 | }
|
| 1171 | i++;
|
| 1172 | }
|
| 1173 |
|
| 1174 | // lac
|
| 1175 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1176 | {
|
| 1177 | goto EEMUMTSINTRA_EXIT;
|
| 1178 | }
|
| 1179 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
|
| 1180 |
|
| 1181 | // ci
|
| 1182 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1183 | {
|
| 1184 | goto EEMUMTSINTRA_EXIT;
|
| 1185 | }
|
| 1186 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
|
| 1187 |
|
| 1188 | // arfcn
|
| 1189 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1190 | {
|
| 1191 | goto EEMUMTSINTRA_EXIT;
|
| 1192 | }
|
| 1193 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
|
| 1194 |
|
| 1195 | cell_info.cell_num++;
|
| 1196 | EEMUMTSINTRA_EXIT:
|
| 1197 | free(free_ptr);
|
| 1198 | }
|
| 1199 | }
|
| 1200 | /*
|
| 1201 | // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
|
| 1202 | +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
|
| 1203 | */
|
| 1204 | else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
|
| 1205 | {
|
| 1206 | // lac, ci, arfcn
|
| 1207 | if(cell_info.running) {
|
| 1208 | int tmp_int;
|
| 1209 | int i = 0;
|
| 1210 | char* tmp_s = memdup(s,strlen(s));
|
| 1211 | char* free_ptr = tmp_s;
|
| 1212 | char *line = tmp_s;
|
| 1213 | if (at_tok_start(&line) < 0)
|
| 1214 | {
|
| 1215 | goto EEMUMTSINTERRAT_EXIT;
|
| 1216 | }
|
| 1217 | // Jump 7 integer.
|
| 1218 | i = 0;
|
| 1219 | while(i < 7) {
|
| 1220 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1221 | {
|
| 1222 | goto EEMUMTSINTERRAT_EXIT;
|
| 1223 | }
|
| 1224 | i++;
|
| 1225 | }
|
| 1226 |
|
| 1227 | // lac
|
| 1228 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1229 | {
|
| 1230 | goto EEMUMTSINTERRAT_EXIT;
|
| 1231 | }
|
| 1232 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
|
| 1233 |
|
| 1234 | // ci
|
| 1235 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1236 | {
|
| 1237 | goto EEMUMTSINTERRAT_EXIT;
|
| 1238 | }
|
| 1239 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
|
| 1240 |
|
| 1241 | // arfcn
|
| 1242 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1243 | {
|
| 1244 | goto EEMUMTSINTERRAT_EXIT;
|
| 1245 | }
|
| 1246 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
|
| 1247 |
|
| 1248 | cell_info.cell_num++;
|
| 1249 | EEMUMTSINTERRAT_EXIT:
|
| 1250 | free(free_ptr);
|
| 1251 | }
|
| 1252 | }
|
| 1253 | // GSM
|
| 1254 | // +EEMGINFOBASIC: 2
|
| 1255 | // Do nothing.
|
| 1256 | else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
|
| 1257 | // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
|
| 1258 | {
|
| 1259 | if(cell_info.running) {
|
| 1260 |
|
| 1261 | }
|
| 1262 | }
|
| 1263 | /*
|
| 1264 | // mcc, mnc_len, mnc, lac, ci, nom, nco,
|
| 1265 | // bsic, C1, C2, TA, TxPwr,
|
| 1266 | // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
|
| 1267 | // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
|
| 1268 | // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
|
| 1269 | // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
|
| 1270 | // gsmBand,channelMode
|
| 1271 | +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
|
| 1272 | 63, 36, 146, 1, 7,
|
| 1273 | 46, 42, 42, 7, 0,
|
| 1274 | 53, 0, 8, 0, 1, 6, 53,
|
| 1275 | 2, 0, 146, 42, 54, 0, 1,
|
| 1276 | 1, 32, 0, 0, 0, 0,
|
| 1277 | 0, 0
|
| 1278 | */
|
| 1279 | else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
|
| 1280 | {
|
| 1281 | // lac, ci, arfcn, bsic
|
| 1282 | LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
|
| 1283 | if(cell_info.running) {
|
| 1284 | int tmp_int;
|
| 1285 | int i = 0;
|
| 1286 | char* tmp_s = memdup(s,strlen(s));
|
| 1287 | char* free_ptr = tmp_s;
|
| 1288 | char *line = tmp_s;
|
| 1289 | if (at_tok_start(&line) < 0)
|
| 1290 | {
|
| 1291 | goto EEMGINFOSVC_EXIT;
|
| 1292 | }
|
| 1293 |
|
| 1294 | // mcc
|
| 1295 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1296 | {
|
| 1297 | goto EEMGINFOSVC_EXIT;
|
| 1298 | }
|
| 1299 | cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
|
| 1300 |
|
| 1301 | //mnc_len
|
| 1302 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1303 | {
|
| 1304 | goto EEMGINFOSVC_EXIT;
|
| 1305 | }
|
| 1306 | // mnc
|
| 1307 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1308 | {
|
| 1309 | goto EEMGINFOSVC_EXIT;
|
| 1310 | }
|
| 1311 | cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
|
| 1312 |
|
| 1313 | /*
|
| 1314 | // Jump 3 integer.
|
| 1315 | i = 0;
|
| 1316 | while(i < 3) {
|
| 1317 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1318 | {
|
| 1319 | goto EEMGINFOSVC_EXIT;
|
| 1320 | }
|
| 1321 | i++;
|
| 1322 | }
|
| 1323 | */
|
| 1324 | // lac
|
| 1325 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1326 | {
|
| 1327 | goto EEMGINFOSVC_EXIT;
|
| 1328 | }
|
| 1329 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
|
| 1330 |
|
| 1331 | // ci
|
| 1332 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1333 | {
|
| 1334 | goto EEMGINFOSVC_EXIT;
|
| 1335 | }
|
| 1336 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
|
| 1337 |
|
| 1338 | // Jump 2 integer.
|
| 1339 | i = 0;
|
| 1340 | while(i < 2) {
|
| 1341 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1342 | {
|
| 1343 | goto EEMGINFOSVC_EXIT;
|
| 1344 | }
|
| 1345 | i++;
|
| 1346 | }
|
| 1347 |
|
| 1348 | // bsic
|
| 1349 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1350 | {
|
| 1351 | goto EEMGINFOSVC_EXIT;
|
| 1352 | }
|
| 1353 | cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
|
| 1354 |
|
| 1355 | // Jump 15 integer.
|
| 1356 | i = 0;
|
| 1357 | while(i < 15) {
|
| 1358 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1359 | {
|
| 1360 | goto EEMGINFOSVC_EXIT;
|
| 1361 | }
|
| 1362 | i++;
|
| 1363 | }
|
| 1364 |
|
| 1365 | // arfcn
|
| 1366 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1367 | {
|
| 1368 | goto EEMGINFOSVC_EXIT;
|
| 1369 | }
|
| 1370 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
|
| 1371 |
|
| 1372 | cell_info.cell_num++;
|
| 1373 | EEMGINFOSVC_EXIT:
|
| 1374 | free(free_ptr);
|
| 1375 | }
|
| 1376 | }
|
| 1377 | /*
|
| 1378 | // PS_attached, attach_type, service_type, tx_power, c_value,
|
| 1379 | // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
|
| 1380 | // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
|
| 1381 | // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
|
| 1382 | +EEMGINFOPS: 1, 255, 0, 0, 0,
|
| 1383 | 0, 0, 268435501, 1, 0, 0,
|
| 1384 | 4, 0, 96, 0, 0, 0,
|
| 1385 | 0, 0, 0, 65535, 0, 13350
|
| 1386 | */
|
| 1387 | // Do nothing.
|
| 1388 | else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
|
| 1389 | {
|
| 1390 | if(cell_info.running) {
|
| 1391 |
|
| 1392 | }
|
| 1393 | }
|
| 1394 | else if(strStartsWith(s, "+EEMGINFONC:")) // cell
|
| 1395 | {
|
| 1396 | if(cell_info.running) {
|
| 1397 | int tmp_int;
|
| 1398 | int i = 0;
|
| 1399 | char* tmp_s = memdup(s,strlen(s));
|
| 1400 | char* free_ptr = tmp_s;
|
| 1401 | char *line = tmp_s;
|
| 1402 | if (at_tok_start(&line) < 0)
|
| 1403 | {
|
| 1404 | goto EEMGINFOPS_EXIT;
|
| 1405 | }
|
| 1406 |
|
| 1407 | // nc_num
|
| 1408 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1409 | {
|
| 1410 | LOG("cell_info.running 1= %d\n.",cell_info.running);
|
| 1411 | goto EEMGINFOPS_EXIT;
|
| 1412 | }
|
| 1413 | // mcc
|
| 1414 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1415 | {
|
| 1416 | LOG("cell_info.running 2= %d\n.",cell_info.running);
|
| 1417 | goto EEMGINFOPS_EXIT;
|
| 1418 | }
|
| 1419 | cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
|
| 1420 |
|
| 1421 | // mnc
|
| 1422 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1423 | {
|
| 1424 | LOG("cell_info.running 3= %d\n.",cell_info.running);
|
| 1425 | goto EEMGINFOPS_EXIT;
|
| 1426 | }
|
| 1427 | cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
|
| 1428 |
|
| 1429 | // lac
|
| 1430 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1431 | {
|
| 1432 | LOG("cell_info.running 4= %d\n.",cell_info.running);
|
| 1433 | goto EEMGINFOPS_EXIT;
|
| 1434 | }
|
| 1435 | cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
|
| 1436 |
|
| 1437 | // rac
|
| 1438 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1439 | {
|
| 1440 | LOG("cell_info.running 5= %d\n.",cell_info.running);
|
| 1441 | goto EEMGINFOPS_EXIT;
|
| 1442 | }
|
| 1443 |
|
| 1444 | // ci
|
| 1445 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1446 | {
|
| 1447 | LOG("cell_info.running 6= %d\n.",cell_info.running);
|
| 1448 | goto EEMGINFOPS_EXIT;
|
| 1449 | }
|
| 1450 | cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
|
| 1451 |
|
| 1452 | // rx_lv
|
| 1453 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1454 | {
|
| 1455 | LOG("cell_info.running 7= %d\n.",cell_info.running);
|
| 1456 | goto EEMGINFOPS_EXIT;
|
| 1457 | }
|
| 1458 |
|
| 1459 | // bsic
|
| 1460 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1461 | {
|
| 1462 | LOG("cell_info.running 8= %d\n.",cell_info.running);
|
| 1463 | goto EEMGINFOPS_EXIT;
|
| 1464 | }
|
| 1465 | cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
|
| 1466 |
|
| 1467 | // Jump 2 integer.
|
| 1468 | i = 0;
|
| 1469 | while(i < 2) {
|
| 1470 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1471 | {
|
| 1472 | LOG("cell_info.running 9= %d\n.",cell_info.running);
|
| 1473 | goto EEMGINFOPS_EXIT;
|
| 1474 | }
|
| 1475 | i++;
|
| 1476 | }
|
| 1477 |
|
| 1478 | // arfcn
|
| 1479 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1480 | {
|
| 1481 | LOG("cell_info.running 10 = %d\n.",cell_info.running);
|
| 1482 | goto EEMGINFOPS_EXIT;
|
| 1483 | }
|
| 1484 | cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
|
| 1485 |
|
| 1486 | cell_info.cell_num++;
|
| 1487 | EEMGINFOPS_EXIT:
|
| 1488 | free(free_ptr);
|
| 1489 | }
|
| 1490 | }
|
| 1491 | else if(strStartsWith(s, "+ZGIPDNS:")) // +ZGIPDNS: 1,"IPV4V6","10.156.239.245","10.156.239.246","223.87.253.100","223.87.253.253","fe80:0000:0000:0000:0001:0001:9b8c:7c0c","fe80::1:1:9b8c:7c0d","2409:8062:2000:2::1","2409:8062:2000:2::2"
|
| 1492 | {
|
| 1493 |
|
| 1494 | }
|
| 1495 | else
|
| 1496 | {
|
| 1497 | LOGV("Unknown URC : %s", s);
|
| 1498 | }
|
| 1499 | }
|
| 1500 |
|
| 1501 | static int openSocket(const char* sockname)
|
| 1502 | {
|
| 1503 | int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
| 1504 | if (sock < 0)
|
| 1505 | {
|
| 1506 | LOGE("Error create socket: %s\n", strerror(errno));
|
| 1507 | return -1;
|
| 1508 | }
|
| 1509 | struct sockaddr_un addr;
|
| 1510 | memset(&addr, 0, sizeof(addr));
|
| 1511 | addr.sun_family = AF_UNIX;
|
| 1512 | strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
|
| 1513 | while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
|
| 1514 | {
|
| 1515 | LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
|
| 1516 | sleep(1);
|
| 1517 | }
|
| 1518 |
|
| 1519 | #if 0
|
| 1520 | int sk_flags = fcntl(sock, F_GETFL, 0);
|
| 1521 | fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
|
| 1522 | #endif
|
| 1523 |
|
| 1524 | return sock;
|
| 1525 | }
|
| 1526 |
|
| 1527 | static void ril_get_cgpaddr_ip_process()
|
| 1528 | {
|
| 1529 | int err, skip;
|
| 1530 | ATResponse *p_response = NULL;
|
| 1531 | char *line;
|
| 1532 | char *ipv4 = NULL, *ipv6 = NULL;
|
| 1533 | err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
|
| 1534 | if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
|
| 1535 | {
|
| 1536 | LOGE("+CGPADDR exec error.");
|
| 1537 | goto error;
|
| 1538 | }
|
| 1539 |
|
| 1540 | // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
|
| 1541 | // +CGPADDR: 1, "10.124.139.131"
|
| 1542 | line = p_response->p_intermediates->line;
|
| 1543 | err = at_tok_start(&line);
|
| 1544 | if (err < 0)
|
| 1545 | {
|
| 1546 | goto error;
|
| 1547 | }
|
| 1548 |
|
| 1549 | err = at_tok_nextint(&line, &skip);
|
| 1550 | if (err < 0)
|
| 1551 | {
|
| 1552 | goto error;
|
| 1553 | }
|
| 1554 |
|
| 1555 | if (!at_tok_hasmore(&line))
|
| 1556 | {
|
| 1557 | goto error;
|
| 1558 | }
|
| 1559 |
|
| 1560 | err = at_tok_nextstr(&line, &ipv4);
|
| 1561 | if (err < 0)
|
| 1562 | {
|
| 1563 | LOGE("Get IPv4 fail.");
|
| 1564 | goto error;
|
| 1565 | }
|
| 1566 |
|
| 1567 | if (at_tok_hasmore(&line))
|
| 1568 | {
|
| 1569 | err = at_tok_nextstr(&line, &ipv6);
|
| 1570 | if (err < 0)
|
| 1571 | {
|
| 1572 | LOGE("Get IPv6 fail.");
|
| 1573 | goto error;
|
| 1574 | }
|
| 1575 | }
|
| 1576 | else
|
| 1577 | {
|
| 1578 | LOGD("No IPv6 Found.");
|
| 1579 | }
|
| 1580 |
|
| 1581 | if(ipv6)
|
| 1582 | {
|
| 1583 | LOGD("IPv6 : %s", ipv6);
|
| 1584 | }
|
| 1585 |
|
| 1586 | if(ipv4)
|
| 1587 | {
|
| 1588 | LOGD("IPv4 : %s", ipv4);
|
| 1589 |
|
| 1590 | // ril_net_dev_config("ccinet0", ipv4, NULL);
|
| 1591 | }
|
| 1592 | error:
|
| 1593 | at_response_free(p_response);
|
| 1594 | }
|
| 1595 |
|
| 1596 | static void sim_state_change(bool plug_in) {
|
| 1597 | if(plug_in) {
|
| 1598 | // If radio on,must off in the first.
|
| 1599 | if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
|
| 1600 | setRadioPower(0);
|
| 1601 | }
|
| 1602 | setRadioPower(1);
|
| 1603 | } else {
|
| 1604 | setRadioPower(0);
|
| 1605 | }
|
| 1606 | }
|
| 1607 |
|
| 1608 | static int open_uevent_socket()
|
| 1609 | {
|
| 1610 | struct sockaddr_nl addr;
|
| 1611 | int sz = 64*1024;
|
| 1612 | int s = 0;
|
| 1613 |
|
| 1614 | memset(&addr, 0, sizeof(addr));
|
| 1615 | addr.nl_family = AF_NETLINK;
|
| 1616 | addr.nl_pid = getpid();
|
| 1617 | addr.nl_groups = 0xffffffff;
|
| 1618 |
|
| 1619 | s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
|
| 1620 | if (s < 0)
|
| 1621 | {
|
| 1622 | LOGE("socket() fail.[%d]", errno);
|
| 1623 | return -1;
|
| 1624 | }
|
| 1625 |
|
| 1626 | setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
|
| 1627 |
|
| 1628 | if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
|
| 1629 | {
|
| 1630 | close(s);
|
| 1631 | return -1;
|
| 1632 | }
|
| 1633 |
|
| 1634 | return s;
|
| 1635 | }
|
| 1636 |
|
| 1637 | static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
|
| 1638 | {
|
| 1639 | // change@/devices/virtual/usim_event/usim0\0
|
| 1640 | // ACTION=change\0
|
| 1641 | // DEVPATH=/devices/virtual/usim_event/usim0\0
|
| 1642 | // SUBSYSTEM=usim_event\0
|
| 1643 | // USIM_NAME=usim0\0
|
| 1644 | // USIM_EVENT=plugout\0
|
| 1645 | // SEQNUM=704
|
| 1646 | int i = 0;
|
| 1647 | while (i < msg_len)
|
| 1648 | {
|
| 1649 | if(*(msg + i) == '\0')
|
| 1650 | {
|
| 1651 | i++;
|
| 1652 | continue;
|
| 1653 | }
|
| 1654 | if (!strncmp(msg + i, "USIM_NAME=", 10))
|
| 1655 | {
|
| 1656 | i += 10;
|
| 1657 | cdev->name = msg + i;
|
| 1658 | i += strlen(msg + i);
|
| 1659 | }
|
| 1660 | else if (!strncmp(msg + i, "ACTION=", 7))
|
| 1661 | {
|
| 1662 | i += 7;
|
| 1663 | cdev->action = msg + i;
|
| 1664 | i += strlen(msg + i);
|
| 1665 | }
|
| 1666 | else if (!strncmp(msg + i, "DEVPATH=", 8))
|
| 1667 | {
|
| 1668 | i += 8;
|
| 1669 | cdev->path = msg + i;
|
| 1670 | i += strlen(msg + i);
|
| 1671 | }
|
| 1672 | else if (!strncmp(msg + i, "USIM_EVENT=", 11))
|
| 1673 | {
|
| 1674 | i += 11;
|
| 1675 | cdev->event = msg + i;
|
| 1676 | i += strlen(msg + i);
|
| 1677 | }
|
| 1678 | else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
|
| 1679 | {
|
| 1680 | i += 10;
|
| 1681 | cdev->subsystem = msg + i;
|
| 1682 | i += strlen(msg + i);
|
| 1683 | }
|
| 1684 | else
|
| 1685 | {
|
| 1686 | i++;
|
| 1687 | }
|
| 1688 | }
|
| 1689 |
|
| 1690 | if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
|
| 1691 | && !strncmp(cdev->action, "change", 5))
|
| 1692 | {
|
| 1693 | LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
|
| 1694 | cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
|
| 1695 | if(!strcmp(cdev->event, "plugout"))
|
| 1696 | {
|
| 1697 | sim_state_change(FALSE);
|
| 1698 | }
|
| 1699 | else if(!strcmp(cdev->event, "plugin"))
|
| 1700 | {
|
| 1701 | sim_state_change(TRUE);
|
| 1702 | }
|
| 1703 | else
|
| 1704 | {
|
| 1705 | LOGE("usim evnet error!");
|
| 1706 | }
|
| 1707 | }
|
| 1708 | }
|
| 1709 |
|
| 1710 | static void* uevnet_run(void *payload)
|
| 1711 | {
|
| 1712 | int socket_fd = -1;
|
| 1713 | char msg[BUFFER_SIZE+2];
|
| 1714 | int n;
|
| 1715 |
|
| 1716 | socket_fd = open_uevent_socket();
|
| 1717 | if(socket_fd > 0)
|
| 1718 | {
|
| 1719 | while(1)
|
| 1720 | {
|
| 1721 | if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
|
| 1722 | {
|
| 1723 | struct cooling_device cdev;
|
| 1724 | memset(&cdev, 0x0, sizeof(cdev));
|
| 1725 |
|
| 1726 | if(n == BUFFER_SIZE)
|
| 1727 | continue;
|
| 1728 | msg[n] = '\0';
|
| 1729 | // change@/devices/virtual/usim_event/usim0\0ACTION=change\0DEVPATH=/devices/virtual/usim_event/usim0\0SUBSYSTEM=usim_event\0USIM_NAME=usim0\0USIM_EVENT=plugout\0SEQNUM=704
|
| 1730 | log_hex("UEVENT", msg, n);
|
| 1731 | parse_uevent(msg, n, &cdev);
|
| 1732 | }
|
| 1733 | else
|
| 1734 | {
|
| 1735 | LOGE("recv msg error.");
|
| 1736 | }
|
| 1737 | }
|
| 1738 | }
|
| 1739 |
|
| 1740 | LOGD("UEVENT Thread exit!!!");
|
| 1741 | return NULL;
|
| 1742 | }
|
| 1743 |
|
| 1744 | int uevent_main()
|
| 1745 | {
|
| 1746 | mbtk_task_info task;
|
| 1747 | task.task_id = &uevnet_task_id;
|
| 1748 | task.thread_run = uevnet_run;
|
| 1749 | task.args = NULL;
|
| 1750 | return mbtk_task_start(&task);
|
| 1751 | }
|
| 1752 |
|
| 1753 | /*
|
| 1754 | int ril_main()
|
| 1755 | {
|
| 1756 | return mbtk_task_queue_start(&ril_task, ril_main_run);
|
| 1757 | }
|
| 1758 | */
|
| 1759 |
|
| 1760 | int mbtk_info_server_start();
|
| 1761 | int InProduction_Mode(void);
|
| 1762 | void server_ready_set(void);
|
| 1763 |
|
| 1764 | |
| 1765 | /* |
| 1766 | *Get mtdblock which name is ASR_FLAG |
| 1767 | *return path if found, else return NULL |
| 1768 | */ |
| 1769 | static int asrFlagPathGet(char *asr_flag_path)
|
| 1770 | { |
| 1771 | char buf[128]; |
| 1772 | unsigned char find = 0; |
| 1773 | FILE *fd = fopen("/proc/mtd", "r");
|
| 1774 | if (fd == NULL) { |
| 1775 | LOGE("Open MTD failed!");
|
| 1776 | return -1;
|
| 1777 | } |
| 1778 | |
| 1779 | memset(buf, '\0', 128); |
| 1780 | while (fgets(buf, 128, fd) != NULL) { |
| 1781 | if(strstr(buf, "asr_flag")) { |
| 1782 | char *p = strstr(buf, "mtd"); |
| 1783 | if(p) |
| 1784 | { |
| 1785 | int bln; |
| 1786 | sscanf(p, "mtd%d", &bln); |
| 1787 | sprintf(asr_flag_path, "/dev/mtdblock%d", bln); |
| 1788 | find = 1; |
| 1789 | break; |
| 1790 | } |
| 1791 | } |
| 1792 | memset(buf, '\0', 128); |
| 1793 | } |
| 1794 | |
| 1795 | fclose(fd); |
| 1796 | return ((find == 1) ? 0 : -1);
|
| 1797 | } |
| 1798 | |
| 1799 | static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
|
| 1800 | { |
| 1801 | int ret, fd; |
| 1802 | if (!path) |
| 1803 | return -1; |
| 1804 | |
| 1805 | fd = open(path, O_RDONLY); |
| 1806 | if (fd < 0) { |
| 1807 | LOGE("readFromMTD open error,%d", errno);
|
| 1808 | return -1; |
| 1809 | } |
| 1810 | |
| 1811 | ret = lseek(fd, offset, SEEK_SET); |
| 1812 | if (ret < 0) { |
| 1813 | close(fd); |
| 1814 | LOGE("readFromMTD lseek error,%d", errno);
|
| 1815 | return -1; |
| 1816 | } |
| 1817 | ret = read(fd, buf, size); |
| 1818 | if (ret < 0) { |
| 1819 | close(fd); |
| 1820 | LOGE("readFromMTD read error,%d", errno);
|
| 1821 | return -1; |
| 1822 | } |
| 1823 | close(fd); |
| 1824 | return 0; |
| 1825 | } |
| 1826 | |
| 1827 | static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
|
| 1828 | { |
| 1829 | int ret, fd; |
| 1830 | |
| 1831 | if (!path) |
| 1832 | return -1; |
| 1833 | |
| 1834 | fd = open(path, O_RDWR | O_SYNC); |
| 1835 | if (fd < 0) |
| 1836 | return -1; |
| 1837 | |
| 1838 | ret = lseek(fd, offset, SEEK_SET); |
| 1839 | if (ret < 0) { |
| 1840 | close(fd); |
| 1841 | return -1; |
| 1842 | } |
| 1843 | ret = write(fd, buf, size); |
| 1844 | if (ret < 0) { |
| 1845 | LOGE("writetomtd:write error:%d", errno);
|
| 1846 | close(fd); |
| 1847 | return -1; |
| 1848 | } |
| 1849 | |
| 1850 | close(fd); |
| 1851 | return 0; |
| 1852 | }
|
| 1853 |
|
| 1854 | static void fota_result_check()
|
| 1855 | {
|
| 1856 | #if 0
|
| 1857 | ASR_flag tag;
|
| 1858 | char asr_flag_path[30] = {0};
|
| 1859 | if(asrFlagPathGet(asr_flag_path)) {
|
| 1860 | LOGE("getAsrFlagPath() fail.");
|
| 1861 | return;
|
| 1862 | }
|
| 1863 |
|
| 1864 | if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
|
| 1865 | {
|
| 1866 | LOGE("Get FOTA result fail.");
|
| 1867 | }
|
| 1868 | else
|
| 1869 | {
|
| 1870 | LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
|
| 1871 | tag.fota_result[0] = 0;
|
| 1872 | tag.fota_result[1] = 0;
|
| 1873 | if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
|
| 1874 | {
|
| 1875 | LOGE("FOTA result update fail.");
|
| 1876 | } else {
|
| 1877 | LOGD("FOTA result update success.");
|
| 1878 | }
|
| 1879 | }
|
| 1880 | #endif
|
| 1881 | }
|
| 1882 |
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1883 | static void mbtk_ril_ready()
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1884 | {
|
| 1885 | // /etc/init.d/mbtk_boot_server_ready
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1886 | if(is_first_boot) {
|
| 1887 | if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
|
| 1888 | LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
|
| 1889 | system(MBTK_BOOT_SERVER_READY);
|
| 1890 | } else {
|
| 1891 | LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
|
| 1892 | }
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1893 | } else {
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1894 | LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1895 | }
|
| 1896 | }
|
| 1897 |
|
| 1898 | #if 1
|
| 1899 | int main(int argc, char *argv[])
|
| 1900 | {
|
| 1901 | mbtk_log_init("radio", "MBTK_RIL");
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1902 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 1903 | MBTK_SOURCE_INFO_PRINT("mbtk_rild");
|
| 1904 |
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1905 | #ifdef MBTK_DUMP_SUPPORT
|
| 1906 | mbtk_debug_open(NULL, TRUE);
|
| 1907 | #endif
|
| 1908 |
|
| 1909 | // Using Killall,the file lock may be not release.
|
| 1910 | #if 0
|
| 1911 | if(app_already_running(MBTK_RILD_PID_FILE)) {
|
| 1912 | LOGW("daemon already running.");
|
| 1913 | exit(1);
|
| 1914 | }
|
| 1915 | #endif
|
| 1916 |
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1917 | LOGI("mbtk_ril start.");
|
| 1918 |
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1919 | int fd = open(MBTK_RILD_TEMP_FILE, O_CREAT | O_RDWR, 0644);
|
| 1920 | if(fd > 0) {
|
| 1921 | char buff[10] = {0};
|
| 1922 | int count = 0;
|
| 1923 | if(read(fd, buff, sizeof(buff)) > 0) {
|
| 1924 | count = atoi(buff);
|
| 1925 | } else {
|
| 1926 | count = 0;
|
| 1927 | }
|
| 1928 |
|
| 1929 | if(count <= 0) {
|
| 1930 | is_first_boot = TRUE;
|
| 1931 | count = 0;
|
| 1932 | } else {
|
| 1933 | is_first_boot = FALSE;
|
| 1934 | }
|
| 1935 |
|
| 1936 | count++;
|
| 1937 | memset(buff, 0, sizeof(buff));
|
| 1938 | snprintf(buff, sizeof(buff), "%d", count);
|
| 1939 | write(fd, buff, strlen(buff));
|
| 1940 | close(fd);
|
| 1941 | } else {
|
| 1942 | is_first_boot = FALSE;
|
| 1943 | LOGE("Open %s fail:%d", MBTK_RILD_TEMP_FILE, errno);
|
| 1944 | LOGW("Will not exec %s and %s.", MBTK_BOOT_SERVER_READY, MBTK_BOOT_NET_READY);
|
| 1945 | }
|
| 1946 |
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1947 | if(InProduction_Mode()) {
|
| 1948 | LOGI("Is Production Mode, will exit...");
|
| 1949 | exit(0);
|
| 1950 | }
|
| 1951 |
|
| 1952 | int at_sock = openSocket("/tmp/atcmd_at");
|
| 1953 | if(at_sock < 0)
|
| 1954 | {
|
| 1955 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 1956 | return -1;
|
| 1957 | }
|
| 1958 | int uart_sock = openSocket("/tmp/atcmd_urc");
|
| 1959 | if(uart_sock < 0)
|
| 1960 | {
|
| 1961 | LOGE("Open Uart Socket Fail[%d].", errno);
|
| 1962 | return -1;
|
| 1963 | }
|
| 1964 |
|
| 1965 | at_set_on_reader_closed(onATReaderClosed);
|
| 1966 | at_set_on_timeout(onATTimeout);
|
| 1967 |
|
| 1968 | if(at_open(at_sock, uart_sock, onUnsolicited))
|
| 1969 | {
|
| 1970 | LOGE("Start AT thread fail.");
|
| 1971 | return -1;
|
| 1972 | }
|
| 1973 |
|
| 1974 | #if 1
|
| 1975 | if(at_handshake())
|
| 1976 | {
|
| 1977 | LOGE("AT handshake fail.");
|
| 1978 | return -1;
|
| 1979 | }
|
| 1980 | #endif
|
| 1981 |
|
| 1982 | LOGD("AT OK.");
|
| 1983 |
|
| 1984 | if(mbtk_info_server_start())
|
| 1985 | {
|
| 1986 | LOGE("mbtk_info_server_start() fail.");
|
| 1987 | return -1;
|
| 1988 | }
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1989 |
|
wangyouqiang | 38e5336 | 2024-01-23 10:53:48 +0800 | [diff] [blame] | 1990 | #ifdef MBTK_PROJECT_T108
|
liuyang | 15f493d | 2024-09-12 17:45:41 +0800 | [diff] [blame^] | 1991 | char led_enable_str[10];
|
| 1992 | memset(led_enable_str, 0, 10);
|
| 1993 | property_get("persist.mbtk.led_enable", led_enable_str, "1");
|
| 1994 | if(atoi(led_enable_str) == 1) { // NTP time
|
| 1995 | LOG("Start LED thread.");
|
| 1996 | mbtk_led_init();
|
| 1997 | }
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 1998 | #endif
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1999 |
|
| 2000 | #if 0
|
| 2001 | if(uevent_main())
|
| 2002 | {
|
| 2003 | LOGE("Start uevent thread fail.");
|
| 2004 | return -1;
|
| 2005 | }
|
| 2006 | #endif
|
| 2007 |
|
| 2008 | char time_type[10];
|
| 2009 | memset(time_type, 0, 10);
|
| 2010 | property_get("persist.mbtk.time_type", time_type, "0");
|
| 2011 | if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
|
| 2012 | LOG("Start NTP thread.");
|
| 2013 | ntp_thread_start();
|
| 2014 | }
|
| 2015 |
|
| 2016 | fota_result_check();
|
| 2017 |
|
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 2018 | mbtk_ril_ready();
|
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 2019 |
|
| 2020 | server_ready_set();//Set the server readiness state
|
| 2021 | while(1)
|
| 2022 | {
|
| 2023 | sleep(24 * 60 * 60);
|
| 2024 | }
|
| 2025 |
|
| 2026 | LOGD("!!!mbtk_ril exit!!!");
|
| 2027 | return 0;
|
| 2028 | }
|
| 2029 |
|
| 2030 | #else
|
| 2031 | int main()
|
| 2032 | {
|
| 2033 | char buff[BUFFER_SIZE + 1] = {0};
|
| 2034 | if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
|
| 2035 | {
|
| 2036 | LOGD("+CFUN RSP:%s", buff);
|
| 2037 | while(1)
|
| 2038 | {
|
| 2039 | sleep(1);
|
| 2040 | memset(buff, 0x0, BUFFER_SIZE + 1);
|
| 2041 | if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
|
| 2042 | {
|
| 2043 | LOGD("+CGPADDR RSP:%s", buff);
|
| 2044 | if(strstr(buff, "+CGPADDR:"))
|
| 2045 | {
|
| 2046 | // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
|
| 2047 | //
|
| 2048 | // OK
|
| 2049 | char *ip_start = NULL;
|
| 2050 | char *ip_end = NULL;
|
| 2051 | char ipv4[50] = {0};
|
| 2052 | ip_start = strstr(buff,"\"");
|
| 2053 | if(ip_start)
|
| 2054 | ip_end = strstr(ip_start + 1, "\"");
|
| 2055 | if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
|
| 2056 | {
|
| 2057 | memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
|
| 2058 | LOGD("IP : %s", ipv4);
|
| 2059 | if(!mbtk_ifc_open())
|
| 2060 | {
|
| 2061 | in_addr_t addr;
|
| 2062 | inet_aton(ipv4,(struct in_addr *)&addr);
|
| 2063 | LOGD("IP : %s -> %x", ipv4, addr);
|
| 2064 | if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
|
| 2065 | {
|
| 2066 | mbtk_ifc_up("ccinet0");
|
| 2067 | }
|
| 2068 |
|
| 2069 | mbtk_ifc_close();
|
| 2070 | }
|
| 2071 |
|
| 2072 | system("route add default dev ccinet0");
|
| 2073 |
|
| 2074 | LOGD("Set IP success.");
|
| 2075 | }
|
| 2076 | else
|
| 2077 | {
|
| 2078 | LOGD("Get IP fail.");
|
| 2079 | }
|
| 2080 |
|
| 2081 | break;
|
| 2082 | }
|
| 2083 | }
|
| 2084 | }
|
| 2085 | }
|
| 2086 |
|
| 2087 | return 0;
|
| 2088 | }
|
| 2089 | #endif
|