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