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