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 <errno.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <sys/un.h> |
| 7 | #include <netinet/in.h> |
| 8 | #include <pthread.h> |
| 9 | #include <sys/epoll.h> |
| 10 | #include <string.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <signal.h> |
| 13 | |
| 14 | #include "mbtk_info_api.h" |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 15 | |
| 16 | #define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2")) |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 17 | |
| 18 | //#include "lynq_net_api.h" |
| 19 | |
| 20 | static mbtk_info_handle_t* info_handle = NULL; |
| 21 | |
| 22 | void net_state_change_cb(const void* data, int data_len) |
| 23 | { |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 24 | if(data && data_len > 0) { |
| 25 | const uint8 *ptr = (const uint8*)data; |
| 26 | if(*ptr == 0) { // CS |
| 27 | printf("CS:act=%d, mode=%d\n", *(ptr + 1), *(ptr + 2)); |
| 28 | } else { // PS |
| 29 | printf("PS[%s]:act=%d, mode=%d\n", *(ptr + 3) == 0 ? "GSM/WCDMA" : "LTE", *(ptr + 1), *(ptr + 2)); |
| 30 | } |
| 31 | } else |
| 32 | LOGD("NET_CB : NULL"); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void call_state_change_cb(const void* data, int data_len) |
| 36 | { |
| 37 | mbtk_call_info_t *reg = (mbtk_call_info_t *)data; |
| 38 | switch (reg->call_wait) |
| 39 | { |
| 40 | case MBTK_CLCC: |
| 41 | printf("\r\nRING : %d, %d, %d, %d, %d, %s, %d\r\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type); |
| 42 | break; |
| 43 | case MBTK_DISCONNECTED: |
| 44 | printf("\r\nRING : call dis connected!\r\n"); |
| 45 | break; |
| 46 | case MBTK_CPAS: |
| 47 | printf("\r\nCALL : Call state = %d\r\n", reg->pas); |
| 48 | /* |
| 49 | MBTK_CALL_RADY, //MT allows commands from TA/TE |
| 50 | MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE |
| 51 | MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions |
| 52 | MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active |
| 53 | MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress |
| 54 | MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state |
| 55 | MBTK_CALL_ACTIVE, |
| 56 | */ |
| 57 | switch (reg->pas) |
| 58 | { |
| 59 | case MBTK_CALL_RADY: |
| 60 | printf("CALL: call READY\r\n"); |
| 61 | break; |
| 62 | case MBTK_CALL_UNAVAILABLE: |
| 63 | printf("CALL: call unavaliable\r\n"); |
| 64 | break; |
| 65 | case MBTK_CALL_UNKNOWN: |
| 66 | printf("CALL: call unknown\r\n"); |
| 67 | break; |
| 68 | case MBTK_CALL_RINGING: |
| 69 | printf("CALL: call ringing\r\n"); |
| 70 | break; |
| 71 | case MBTK_CALL_PROGRESS: |
| 72 | printf("CALL: call progress\r\n"); |
| 73 | break; |
| 74 | case MBTK_CALL_ASLEEP: |
| 75 | printf("CALL: call asleep\r\n"); |
| 76 | break; |
| 77 | case MBTK_CALL_ACTIVE: |
| 78 | printf("CALL: call active\r\n"); |
| 79 | break; |
| 80 | default: |
| 81 | printf("\r\n"); |
| 82 | break; |
| 83 | } |
| 84 | break; |
| 85 | default: |
| 86 | printf("\r\nRING : None call_wait = %d\r\n", reg->call_wait); |
| 87 | break; |
| 88 | } |
| 89 | /* |
| 90 | if(reg->call_wait == ) //CLCC |
| 91 | { |
| 92 | printf("\r\nRING : %d, %d, %d, %d, %d, %s, %d\r\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type); |
| 93 | } |
| 94 | else if(reg->call_wait == 2) //Disconnected |
| 95 | { |
| 96 | printf("\r\nRING : call dis connected!\r\n"); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | printf("\r\nRING : None\r\n"); |
| 101 | } |
| 102 | */ |
| 103 | } |
| 104 | |
| 105 | void sms_state_change_cb(const void* data, int data_len) |
| 106 | { |
| 107 | LOGV("sms_state_change_cb()----------start\n"); |
| 108 | uint8 *ptr = (uint8*)data; |
| 109 | printf("3sms_state_change_cb() : %s\n", ptr); |
| 110 | |
| 111 | struct SMS_Struct s = PDUDecoding(ptr); |
| 112 | printf("服务中心地址: %s\n", s.SCA); |
| 113 | printf("发送方地址: %s\n", s.OA); |
| 114 | printf("服务中心时间戳: %s\n", s.SCTS); |
| 115 | printf("消息内容: %s\n", s.UD); |
| 116 | printf("数据编码方案: %s\n", DSC_to_msg(s.DCS)); |
| 117 | |
| 118 | } |
| 119 | |
| 120 | void radio_state_change_cb(const void* data, int data_len) |
| 121 | { |
| 122 | uint8 *ptr = (uint8*)data; |
| 123 | printf("Radio state : %d\n", *ptr); |
| 124 | } |
| 125 | |
| 126 | void sim_state_change_cb(const void* data, int data_len) |
| 127 | { |
| 128 | uint8 *ptr = (uint8*)data; |
| 129 | printf("SIM state : %d\n", *ptr); |
| 130 | } |
| 131 | |
| 132 | #include <netdb.h> |
| 133 | #include <sys/socket.h> |
| 134 | #include <netinet/in.h> |
| 135 | #include <arpa/inet.h> |
| 136 | |
| 137 | static void test2(int is_ipv6, char *ip) |
| 138 | { |
| 139 | char ipaddr[20] = {0}; |
| 140 | if(is_ipv6) { |
| 141 | struct in6_addr sin_addr; |
| 142 | if(inet_pton(AF_INET6, ip, &sin_addr) < 0) { |
| 143 | printf("inet_pton() fail.\n"); |
| 144 | } else { |
| 145 | log_hex("IPv6", &sin_addr, sizeof(struct in6_addr)); |
| 146 | } |
| 147 | } else { |
| 148 | struct in_addr sin_addr; |
| 149 | if(inet_pton(AF_INET, ip, &sin_addr) < 0) { |
| 150 | printf("inet_pton() fail.\n"); |
| 151 | } else { |
| 152 | log_hex("IPv4", &sin_addr, sizeof(struct in_addr)); |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | |
| 158 | static void help() |
| 159 | { |
| 160 | printf("version: Get version.\n"); |
| 161 | printf("imei: Get IMEI.\n"); |
| 162 | printf("sn: Get SN.\n"); |
| 163 | printf("meid: Get MEID.\n"); |
| 164 | printf("volte: Get VoLTE state.\n"); |
| 165 | printf("volte 0: Close VoLTE.\n"); |
| 166 | printf("volte 1: Open VoLTE.\n"); |
| 167 | printf("radio: Get radio state.\n"); |
| 168 | printf("radio 0: Close radio.\n"); |
| 169 | printf("radio 1: Open radio.\n"); |
| 170 | printf("sim: Get sim state.\n"); |
| 171 | printf("avail_net: Get available network.\n"); |
| 172 | printf("imsi: Get IMSI.\n"); |
| 173 | printf("iccid: Get ICCID.\n"); |
| 174 | printf("pn: Get Phone Number.\n"); |
| 175 | printf("sel_mode: Get network select mode.\n"); |
| 176 | printf("sel_mode <sel_mode> <net_type> <plmn>: Set network select mode.\n"); |
| 177 | printf("band: Get current bands.\n"); |
| 178 | printf("band support: Get support bands.\n"); |
| 179 | printf("band <net_pref> <gsm_band> <umts_band> <tdlte_band> <fddlte_band>: Set current bands.\n"); |
| 180 | printf("signal: Get network signal.\n"); |
| 181 | printf("reg: Get network registe information.\n"); |
| 182 | printf("cell: Get current cell information.\n"); |
| 183 | printf("shutdown <0,1,2>: reboot/poweroff/halt system.\n"); |
| 184 | printf("power_sim <0,1>: Power off/on sim.\n"); |
| 185 | printf("temp <0,1>: Get SOC/RF temperature.\n"); |
| 186 | printf("time <0,1,2> YYYY-MM-DD HH:MM:SS : Set system time as CELL/NTP/User.\n"); |
| 187 | printf("apn : Get current apns.\n"); |
| 188 | printf("apn <cid> <1/2/3/4> <apn> : Set apn.\n"); |
| 189 | printf("data_call <0/1/2> <cid> <timeout>: Stop/Start/State data call.\n"); |
| 190 | printf("call: Call the phone number.\n"); |
| 191 | printf("answer: Answer the phone call.\n"); |
| 192 | printf("hangup: Hang up all phone call. No id.\n"); |
| 193 | printf("hangup 0: Hang up waiting or background phone call.\n"); |
| 194 | printf("hangup 1: Hang up a phone call.\n"); |
| 195 | printf("hangup 2: Hang up a phone call.\n"); |
| 196 | printf("hangup 3: Hangup foreground resume background call.\n"); |
| 197 | printf("waitin: Returns the list of current calls.\n"); |
| 198 | printf("mute: Get mute state.\n"); |
| 199 | printf("mute 0: Close mute.\n"); |
| 200 | printf("mute 1: Open mute.\n"); |
| 201 | printf("dtmf : Set dtmf character[0, 1, 2, ..., A, B, C, D, *, #], duration [300-600].\n Such as: dtmf 0 300\n"); |
b.liu | d8043a3 | 2024-06-07 16:08:22 +0800 | [diff] [blame] | 202 | printf("ims_en 0/1 : Close/Open IMS(Restart takes effect).\n"); |
| 203 | printf("ims_state : Get IMS open or not?\n"); |
| 204 | printf("ims_reg: Get IMS register state.\n"); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void sig_process(int sig) |
| 208 | { |
| 209 | LOGI("I got signal %d\n", sig); |
| 210 | switch(sig) |
| 211 | { |
| 212 | case SIGINT: // Ctrl + C |
| 213 | { |
| 214 | LOGI("Exit by SIGINT.\n"); |
| 215 | mbtk_info_handle_free(&info_handle); |
| 216 | exit(0); |
| 217 | } |
| 218 | case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件) |
| 219 | { |
| 220 | LOGI("Exit by SIGQUIT.\n"); |
| 221 | mbtk_info_handle_free(&info_handle); |
| 222 | exit(0); |
| 223 | } |
| 224 | case SIGTERM:// 默认kill (同 SIGKILL ,但 SIGKILL 不可捕获) |
| 225 | { |
| 226 | LOGI("Exit by SIGTERM.\n"); |
| 227 | mbtk_info_handle_free(&info_handle); |
| 228 | exit(0); |
| 229 | } |
| 230 | case SIGTSTP:// Ctrl + Z (同 SIGSTOP ,但 SIGSTOP 不可捕获) |
| 231 | { |
| 232 | LOGI("Exit by SIGTSTP.\n"); |
| 233 | exit(0); |
| 234 | } |
| 235 | case SIGSEGV: // 如空指针 |
| 236 | { |
| 237 | LOGI("Exit by SIGSEGV.\n"); |
| 238 | exit(0); |
| 239 | } |
| 240 | default: |
| 241 | { |
| 242 | LOGI("Unknown sig:%d\n",sig); |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | int main(int argc, char *argv[]) |
| 249 | { |
| 250 | signal(SIGINT, sig_process); |
| 251 | signal(SIGQUIT, sig_process); |
| 252 | signal(SIGTERM, sig_process); |
| 253 | //signal(SIGTSTP, sig_process); |
| 254 | //signal(SIGSEGV, sig_process); |
| 255 | |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 256 | mbtk_log_init("radio","INFO_CLI"); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 257 | |
| 258 | //test2(0, "192.168.1.198"); |
| 259 | //test2(1, "2409:8162:140:cd3c:1:2:1494:72ba"); |
| 260 | //test2(1, "254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239"); |
| 261 | //test2(1, "2400:3200::1"); |
| 262 | |
| 263 | info_handle = mbtk_info_handle_get(); |
| 264 | if(!info_handle) |
| 265 | { |
| 266 | return -1; |
| 267 | } |
| 268 | |
| 269 | mbtk_net_state_change_cb_reg(info_handle, net_state_change_cb); |
| 270 | mbtk_call_state_change_cb_reg(info_handle, call_state_change_cb); |
| 271 | mbtk_sms_state_change_cb_reg(info_handle, sms_state_change_cb); |
| 272 | mbtk_radio_state_change_cb_reg(info_handle, radio_state_change_cb); |
| 273 | mbtk_sim_state_change_cb_reg(info_handle, sim_state_change_cb); |
| 274 | |
| 275 | printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n"); |
| 276 | char cmd[100]; |
| 277 | while(1) |
| 278 | { |
| 279 | memset(cmd, 0, 100); |
| 280 | int err; |
| 281 | if(fgets(cmd, 100, stdin)) |
| 282 | { |
| 283 | char *ptr = cmd + strlen(cmd) - 1; |
| 284 | while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n')) |
| 285 | { |
| 286 | *ptr-- = '\0'; |
| 287 | } |
| 288 | if(!strncasecmp(cmd, "version", 7)) |
| 289 | { |
| 290 | char version[50] = {0}; |
| 291 | err = mbtk_version_get(info_handle, version); |
| 292 | if(err) { |
| 293 | printf("Error : %d\n", err); |
| 294 | } else { |
| 295 | printf("Version : %s\n", version); |
| 296 | } |
| 297 | } else if(!strncasecmp(cmd, "imei", 4)){ |
| 298 | char imei[50] = {0}; |
| 299 | err = mbtk_imei_get(info_handle, imei); |
| 300 | if(err) { |
| 301 | printf("Error : %d\n", err); |
| 302 | } else { |
| 303 | printf("IMEI : %s\n", imei); |
| 304 | } |
| 305 | } else if(!strncasecmp(cmd, "sn", 2)){ |
| 306 | char sn[50] = {0}; |
| 307 | err = mbtk_sn_get(info_handle, sn); |
| 308 | if(err) { |
| 309 | printf("Error : %d\n", err); |
| 310 | } else { |
| 311 | printf("SN : %s\n", sn); |
| 312 | } |
| 313 | } else if(!strncasecmp(cmd, "meid", 4)){ |
| 314 | char meid[50] = {0}; |
| 315 | err = mbtk_meid_get(info_handle, meid); |
| 316 | if(err) { |
| 317 | printf("Error : %d\n", err); |
| 318 | } else { |
| 319 | printf("MEID : %s\n", meid); |
| 320 | } |
| 321 | } else if(!strncasecmp(cmd, "volte", 5)){ // "volte" or "volte 0" or "volte 1" |
| 322 | int volte; |
| 323 | if(!strcasecmp(cmd, "volte")) { // Get |
| 324 | err = mbtk_volte_state_get(info_handle, &volte); |
| 325 | if(err) { |
| 326 | printf("Error : %d\n", err); |
| 327 | } else { |
| 328 | printf("VoLTE : %d\n", volte); |
| 329 | } |
| 330 | } else { // Set |
| 331 | if(!strcasecmp(cmd, "volte 1")) { // Open VoLTE |
| 332 | volte = 1; |
| 333 | } else { // Close VoLTE |
| 334 | volte = 0; |
| 335 | } |
| 336 | err = mbtk_volte_state_set(info_handle, volte); |
| 337 | if(err) { |
| 338 | printf("Error : %d\n", err); |
| 339 | } else { |
| 340 | printf("VoLTE set success\n"); |
| 341 | } |
| 342 | } |
| 343 | } else if(!strncasecmp(cmd, "radio", 5)){ // "radio" or "radio 0" or "radio 1" |
| 344 | int radio; |
| 345 | if(!strcasecmp(cmd, "radio")) { // Get |
| 346 | err = mbtk_radio_state_get(info_handle, &radio); |
| 347 | if(err) { |
| 348 | printf("Error : %d\n", err); |
| 349 | } else { |
| 350 | printf("Radio : %d\n", radio); |
| 351 | } |
| 352 | } else { // Set |
| 353 | if(!strcasecmp(cmd, "radio 1")) { // Open radio |
| 354 | radio = 1; |
| 355 | } else { // Close radio |
| 356 | radio = 0; |
| 357 | } |
| 358 | err = mbtk_radio_state_set(info_handle, radio); |
| 359 | if(err) { |
| 360 | printf("Error : %d\n", err); |
| 361 | } else { |
| 362 | printf("Radio set success\n"); |
| 363 | } |
| 364 | } |
| 365 | } else if(!strncasecmp(cmd, "sim", 3)){ |
| 366 | mbtk_sim_state_enum sim; |
| 367 | err = mbtk_sim_state_get(info_handle, &sim); |
| 368 | if(err) { |
| 369 | printf("Error : %d\n", err); |
| 370 | } else { |
| 371 | printf("Sim : %d\n", sim); |
| 372 | } |
| 373 | } else if(!strncasecmp(cmd, "imsi", 4)){ |
| 374 | char imsi[50] = {0}; |
| 375 | err = mbtk_imsi_get(info_handle, imsi); |
| 376 | if(err) { |
| 377 | printf("Error : %d\n", err); |
| 378 | } else { |
| 379 | printf("IMSI : %s\n", imsi); |
| 380 | } |
| 381 | } else if(!strncasecmp(cmd, "iccid", 5)){ |
| 382 | char iccid[50] = {0}; |
| 383 | err = mbtk_iccid_get(info_handle, iccid); |
| 384 | if(err) { |
| 385 | printf("Error : %d\n", err); |
| 386 | } else { |
| 387 | printf("ICCID : %s\n", iccid); |
| 388 | } |
| 389 | } else if(!strncasecmp(cmd, "pn", 2)){ |
| 390 | char phone_number[50] = {0}; |
| 391 | err = mbtk_phone_number_get(info_handle, phone_number); |
| 392 | if(err) { |
| 393 | printf("Error : %d\n", err); |
| 394 | } else { |
| 395 | printf("Phone Number : %s\n", phone_number); |
| 396 | } |
| 397 | } else if(!strncasecmp(cmd, "avail_net", 9)){ |
| 398 | list_node_t* net_list = NULL; |
| 399 | err = mbtk_available_net_get(info_handle, &net_list); |
| 400 | if(err || net_list == NULL) { |
| 401 | printf("Error : %d\n", err); |
| 402 | } else { |
| 403 | mbtk_net_info_t* net = NULL; |
| 404 | list_first(net_list); |
| 405 | while ((net = (mbtk_net_info_t*) list_next(net_list))) |
| 406 | { |
| 407 | printf("Net : %d, %d, %d, %d\n", net->net_sel_mode, net->net_type, net->net_state, net->plmn); |
| 408 | } |
| 409 | } |
| 410 | list_free(net_list); |
| 411 | } else if(!strncasecmp(cmd, "cell", 4)){ |
| 412 | char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME |
| 413 | if(ptr == NULL) |
| 414 | { |
| 415 | printf("ptr == NULL\n"); |
| 416 | list_node_t* cell_list = NULL; |
| 417 | int type; |
| 418 | err = mbtk_cell_get(info_handle, &type, &cell_list); |
| 419 | if(err || cell_list == NULL) { |
| 420 | printf("Error : %d\n", err); |
| 421 | } else { |
| 422 | list_first(cell_list); |
| 423 | mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list); |
| 424 | if(cell) { // Current server cell. |
| 425 | switch(type) |
| 426 | { |
| 427 | case 0: |
| 428 | printf("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4); |
| 429 | break; |
| 430 | case 1: |
| 431 | printf("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3); |
| 432 | break; |
| 433 | case 2: |
| 434 | printf("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5); |
| 435 | break; |
| 436 | default: |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | while ((cell = (mbtk_cell_info_t*) list_next(cell_list))) |
| 441 | { |
| 442 | switch(type) |
| 443 | { |
| 444 | case 0: |
| 445 | printf("CELL : %d, %d, %d, %d, %d", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5); |
| 446 | break; |
| 447 | case 1: |
| 448 | printf("CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3); |
| 449 | break; |
| 450 | case 2: |
| 451 | printf("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell->value1, cell->value2, cell->value3, cell->value4); |
| 452 | break; |
| 453 | default: |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | list_free(cell_list); |
| 459 | } |
| 460 | else{ |
| 461 | char *ptr = strstr(cmd, ","); //cell,2,3,,40936,430 |
| 462 | char mem[50]={0}; |
| 463 | char resp[1024] = {0}; |
| 464 | if(ptr != NULL) |
| 465 | { |
| 466 | ptr++; |
| 467 | memset(mem, 0, sizeof(mem)); |
| 468 | memcpy(mem, ptr, strlen(ptr)); |
| 469 | printf("cell:%s\n", mem); |
| 470 | } |
| 471 | printf("cell_mem: %s \n", mem); |
| 472 | |
| 473 | memset(resp, 0, sizeof(resp)); |
| 474 | err = mbtk_cell_set(info_handle, mem, resp); |
| 475 | if(err) { |
| 476 | printf("Error : %d\n", err); |
| 477 | } else { |
| 478 | printf("cell set . resp:%s\n", resp); |
| 479 | } |
| 480 | |
| 481 | } |
| 482 | } else if(!strncasecmp(cmd, "sel_mode", 8)){ // "sel_mode" or "sel_mode 1 7 46000" |
| 483 | mbtk_net_info_t net; |
| 484 | memset(&net, 0, sizeof(mbtk_net_info_t)); |
| 485 | if(!strcasecmp(cmd, "sel_mode")) { // Get |
| 486 | err = mbtk_net_sel_mode_get(info_handle, &net); |
| 487 | if(err) { |
| 488 | printf("Error : %d\n", err); |
| 489 | } else { |
| 490 | printf("Net : %d, %d, %d, %d\n", net.net_sel_mode, net.net_type, net.net_state, net.plmn); |
| 491 | } |
| 492 | } else { // Set |
| 493 | char *ptr = strstr(cmd, " "); |
| 494 | if(ptr == NULL) |
| 495 | continue; |
| 496 | while(*ptr != '\0' && *ptr == ' ') |
| 497 | ptr++; |
| 498 | net.net_sel_mode = (uint8)atoi(ptr); |
| 499 | |
| 500 | ptr = strstr(ptr, " "); |
| 501 | if(ptr == NULL) |
| 502 | continue; |
| 503 | while(*ptr != '\0' && *ptr == ' ') |
| 504 | ptr++; |
| 505 | net.net_type = (uint8)atoi(ptr); |
| 506 | |
| 507 | ptr = strstr(ptr, " "); |
| 508 | if(ptr == NULL) |
| 509 | continue; |
| 510 | while(*ptr != '\0' && *ptr == ' ') |
| 511 | ptr++; |
| 512 | net.plmn = (uint32)atoi(ptr); |
| 513 | |
| 514 | err = mbtk_net_sel_mode_set(info_handle, &net); |
| 515 | if(err) { |
| 516 | printf("Error : %d\n", err); |
| 517 | } else { |
| 518 | printf("Net select mode set success\n"); |
| 519 | } |
| 520 | } |
| 521 | } else if(!strncasecmp(cmd, "band", 4)){ // "band" or "band support" or "band 0 79 147 482 524503" |
| 522 | mbtk_band_info_t band; |
b.liu | 288093c | 2024-05-09 17:02:57 +0800 | [diff] [blame] | 523 | memset(&band, 0x0, sizeof(mbtk_band_info_t)); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 524 | if(!strcasecmp(cmd, "band")) { // Get |
| 525 | err = mbtk_current_band_get(info_handle, &band); |
| 526 | if(err) { |
| 527 | printf("Error : %d\n", err); |
| 528 | } else { |
| 529 | printf("Band : %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band); |
| 530 | } |
| 531 | } else if(!strcasecmp(cmd, "band support")) { // Get |
| 532 | err = mbtk_support_band_get(info_handle, &band); |
| 533 | if(err) { |
| 534 | printf("Error : %d\n", err); |
| 535 | } else { |
| 536 | printf("Band : %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band); |
| 537 | } |
| 538 | } else { // "band 0 79 147 482 524503" |
| 539 | char *ptr = strstr(cmd, " "); |
| 540 | if(ptr == NULL) |
| 541 | continue; |
| 542 | while(*ptr != '\0' && *ptr == ' ') |
| 543 | ptr++; |
| 544 | band.net_pref = (uint8)atoi(ptr); |
| 545 | |
| 546 | ptr = strstr(ptr, " "); |
| 547 | if(ptr == NULL) |
| 548 | continue; |
| 549 | while(*ptr != '\0' && *ptr == ' ') |
| 550 | ptr++; |
| 551 | band.gsm_band = (uint16)atoi(ptr); |
| 552 | |
| 553 | ptr = strstr(ptr, " "); |
| 554 | if(ptr == NULL) |
| 555 | continue; |
| 556 | while(*ptr != '\0' && *ptr == ' ') |
| 557 | ptr++; |
| 558 | band.umts_band = (uint16)atoi(ptr); |
| 559 | |
| 560 | ptr = strstr(ptr, " "); |
| 561 | if(ptr == NULL) |
| 562 | continue; |
| 563 | while(*ptr != '\0' && *ptr == ' ') |
| 564 | ptr++; |
| 565 | band.tdlte_band = (uint32)atoi(ptr); |
| 566 | |
| 567 | ptr = strstr(ptr, " "); |
| 568 | if(ptr == NULL) |
| 569 | continue; |
| 570 | while(*ptr != '\0' && *ptr == ' ') |
| 571 | ptr++; |
| 572 | band.fddlte_band = (uint32)atoi(ptr); |
| 573 | |
| 574 | err = mbtk_current_band_set(info_handle, &band); |
| 575 | if(err) { |
| 576 | printf("Error : %d\n", err); |
| 577 | } else { |
| 578 | printf("Band set success\n"); |
| 579 | } |
| 580 | } |
| 581 | } else if(!strncasecmp(cmd, "signal", 6)){ |
| 582 | mbtk_signal_info_t signal; |
| 583 | err = mbtk_net_signal_get(info_handle, &signal); |
| 584 | if(err) { |
| 585 | printf("Error : %d\n", err); |
| 586 | } else { |
| 587 | printf("Signal : %d, %d, %d, %d, %d, %d, %d, %d\n", signal.type, signal.rssi, signal.rxlev, signal.ber, |
| 588 | signal.rscp, signal.ecno, signal.rsrq, signal.rsrp); |
| 589 | } |
| 590 | } else if(!strncasecmp(cmd, "reg", 3)){ |
| 591 | mbtk_net_reg_info_t reg; |
| 592 | err = mbtk_net_reg_get(info_handle, ®); |
| 593 | if(err) { |
| 594 | printf("Error : %d\n", err); |
| 595 | } else { |
| 596 | printf("REG : call_state=%d, data_state=%d, ims_state=%d, net_type=%d, %04x, %08x\n", reg.call_state, reg.data_state, reg.ims_state, reg.type, reg.lac, reg.ci); |
| 597 | } |
| 598 | } else if(!strncasecmp(cmd, "call", 4)){ |
| 599 | char phone_number[12]; |
| 600 | char *ptr = strstr(cmd, " "); |
| 601 | if(ptr == NULL) |
| 602 | continue; |
| 603 | while(*ptr != '\0' && *ptr == ' ') |
| 604 | ptr++; |
| 605 | memset(phone_number,0,strlen(phone_number)); |
| 606 | memcpy(phone_number,ptr,strlen(ptr)); |
| 607 | printf("phone number is: %s\n",phone_number); |
| 608 | err = mbtk_call_start(info_handle, phone_number); |
| 609 | if(err) { |
| 610 | printf("Error : %d\n", err); |
| 611 | } else { |
| 612 | printf("Call success.\n"); |
| 613 | } |
| 614 | } else if(!strncasecmp(cmd, "answer", 6)){ |
| 615 | err = mbtk_call_answer(info_handle); |
| 616 | if(err) { |
| 617 | printf("Error : %d\n", err); |
| 618 | } else { |
| 619 | printf("Call success.\n"); |
| 620 | } |
| 621 | } else if(!strncasecmp(cmd, "hangup", 6)){ |
| 622 | int phone_id; |
| 623 | if(!strcasecmp(cmd, "hangup")) { // hang up all |
| 624 | err = mbtk_call_hang(info_handle); |
| 625 | if(err) { |
| 626 | printf("Error : %d\n", err); |
| 627 | } else { |
| 628 | printf("Call hang up all.\n"); |
| 629 | } |
| 630 | } else if(!strcasecmp(cmd, "hangup 0")) { |
| 631 | err = mbtk_waiting_or_background_call_hang(info_handle); |
| 632 | if(err) { |
| 633 | printf("Error : %d\n", err); |
| 634 | } else { |
| 635 | printf("Call hang up waiting or background.\n"); |
| 636 | } |
| 637 | } else if(!strcasecmp(cmd, "hangup 3")) { |
| 638 | err = mbtk_foreground_resume_background_call_hang(info_handle); |
| 639 | if(err) { |
| 640 | printf("Error : %d\n", err); |
| 641 | } else { |
| 642 | printf("Call hang up foreground resume background.\n"); |
| 643 | } |
| 644 | } else { |
| 645 | if(!strcasecmp(cmd, "hangup 1")) { // hang up a call |
| 646 | phone_id = 1; |
| 647 | } else if(!strcasecmp(cmd, "hangup 2")) { |
| 648 | phone_id = 2; |
| 649 | } else { |
| 650 | printf("Error : Invalid input\n"); |
| 651 | } |
| 652 | err = mbtk_a_call_hang(info_handle, phone_id); |
| 653 | if(err) { |
| 654 | printf("Error : %d\n", err); |
| 655 | } else { |
| 656 | printf("A Call hang up.\n"); |
| 657 | } |
| 658 | } |
| 659 | } else if(!strncasecmp(cmd, "waitin", 6)){ |
| 660 | mbtk_call_info_t reg; |
| 661 | err = mbtk_call_reg_get(info_handle, ®); |
| 662 | if(err) { |
| 663 | printf("Error : %d\n", err); |
| 664 | } else { |
| 665 | if(reg.call_wait == 0) { |
| 666 | printf("No call ring\n"); |
| 667 | } |
| 668 | else { |
| 669 | printf("RING : %d, %d, %d, %d, %d, %s, %d\n", reg.dir1, reg.dir, reg.state, reg.mode, reg.mpty, reg.phone_number, reg.type); |
| 670 | } |
| 671 | } |
| 672 | } else if(!strncasecmp(cmd, "mute", 4)){ // "mute" or "mute 0" or "mute 1" |
| 673 | int mute; |
| 674 | if(!strcasecmp(cmd, "mute")) { // Get |
| 675 | err = mbtk_mute_state_get(info_handle, &mute); |
| 676 | if(err) { |
| 677 | printf("Error : %d\n", err); |
| 678 | } else { |
| 679 | printf("mute : %d\n", mute); |
| 680 | } |
| 681 | } else { // Set |
| 682 | if(!strcasecmp(cmd, "mute 1")) { // on mute |
| 683 | mute = 1; |
| 684 | } else { // off mute |
| 685 | mute = 0; |
| 686 | } |
| 687 | err = mbtk_mute_state_set(info_handle, mute); |
| 688 | if(err) { |
| 689 | printf("Error : %d\n", err); |
| 690 | } else { |
| 691 | printf("mute set success\n"); |
| 692 | } |
| 693 | } |
| 694 | } else if(!strncasecmp(cmd, "DTMF", 4)){ // valid character: (0, 1, ..., 9, A, B, C, D, *, #) |
| 695 | |
| 696 | mbtk_call_dtmf_info_t reg; |
| 697 | |
| 698 | char *ptr = strstr(cmd, " "); |
| 699 | if(ptr == NULL) |
| 700 | continue; |
| 701 | while(*ptr != '\0' && *ptr == ' ') |
| 702 | ptr++; |
| 703 | reg.character = *ptr; |
| 704 | |
| 705 | ptr = strstr(ptr, " "); |
| 706 | if(ptr == NULL) |
| 707 | continue; |
| 708 | while(*ptr != '\0' && *ptr == ' ') |
| 709 | ptr++; |
| 710 | reg.duration = (uint32)atoi(ptr); |
| 711 | printf("DTMF character is: %c,%d\n",reg.character, reg.duration); |
| 712 | err = mbtk_dtmf_send(info_handle, ®); |
| 713 | if(err) { |
| 714 | printf("Error : %d\n", err); |
| 715 | } else { |
| 716 | printf("DTMF success.\n"); |
| 717 | } |
| 718 | } else if(!strncasecmp(cmd, "shutdown", 8)){ |
| 719 | if(!strcasecmp(cmd, "shutdown 0")) { |
| 720 | err = mbtk_system_reboot(0); |
| 721 | if(err) { |
| 722 | printf("Error : %d\n", err); |
| 723 | } else { |
| 724 | printf("Success.\n"); |
| 725 | } |
| 726 | } else if(!strcasecmp(cmd, "shutdown 1")) { |
| 727 | err = mbtk_system_reboot(1); |
| 728 | if(err) { |
| 729 | printf("Error : %d\n", err); |
| 730 | } else { |
| 731 | printf("Success.\n"); |
| 732 | } |
| 733 | } else if(!strcasecmp(cmd, "shutdown 2")) { |
| 734 | err = mbtk_system_reboot(2); |
| 735 | if(err) { |
| 736 | printf("Error : %d\n", err); |
| 737 | } else { |
| 738 | printf("Success.\n"); |
| 739 | } |
| 740 | } else { |
| 741 | printf("Error."); |
| 742 | } |
| 743 | } else if(!strncasecmp(cmd, "power_sim", 9)){ |
| 744 | if(!strcasecmp(cmd, "power_sim 0")) { |
| 745 | err = mbtk_sim_power_set(0); |
| 746 | if(err) { |
| 747 | printf("Error : %d\n", err); |
| 748 | } else { |
| 749 | printf("Success.\n"); |
| 750 | } |
| 751 | } else if(!strcasecmp(cmd, "power_sim 1")) { |
| 752 | err = mbtk_sim_power_set(1); |
| 753 | if(err) { |
| 754 | printf("Error : %d\n", err); |
| 755 | } else { |
| 756 | printf("Success.\n"); |
| 757 | } |
| 758 | } else { |
| 759 | printf("Error."); |
| 760 | } |
| 761 | } else if(!strncasecmp(cmd, "temp", 4)){ |
r.xiao | 7958cfc | 2024-06-07 22:20:00 -0700 | [diff] [blame^] | 762 | mbtk_thermal_info_t temp; |
| 763 | memset(&temp, 0, sizeof(mbtk_thermal_info_t)); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 764 | if(!strcasecmp(cmd, "temp 0")) { |
| 765 | err = mbtk_temp_get(info_handle, 0, &temp); |
| 766 | if(err) { |
| 767 | printf("Error : %d\n", err); |
| 768 | } else { |
r.xiao | 7958cfc | 2024-06-07 22:20:00 -0700 | [diff] [blame^] | 769 | printf("SOC : %d\n", temp.ther); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 770 | } |
| 771 | } else if(!strcasecmp(cmd, "temp 1")) { |
| 772 | err = mbtk_temp_get(info_handle, 1, &temp); |
| 773 | if(err) { |
| 774 | printf("Error : %d\n", err); |
| 775 | } else { |
r.xiao | 7958cfc | 2024-06-07 22:20:00 -0700 | [diff] [blame^] | 776 | printf("RF : %d\n", temp.ther); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 777 | } |
| 778 | } else { |
| 779 | printf("Error."); |
| 780 | } |
| 781 | } else if(!strncasecmp(cmd, "time", 4)){ |
| 782 | if(!strcasecmp(cmd, "time 0")) { |
| 783 | err = mbtk_time_set(info_handle, 0, NULL); |
| 784 | if(err) { |
| 785 | printf("Error : %d\n", err); |
| 786 | } else { |
| 787 | printf("Success.\n"); |
| 788 | } |
| 789 | } else if(!strcasecmp(cmd, "time 1")) { |
| 790 | err = mbtk_time_set(info_handle, 1, NULL); |
| 791 | if(err) { |
| 792 | printf("Error : %d\n", err); |
| 793 | } else { |
| 794 | printf("Success.\n"); |
| 795 | } |
| 796 | } else if(!strncasecmp(cmd, "time 2 ", 7)) { |
| 797 | err = mbtk_time_set(info_handle, 2, cmd + 7); |
| 798 | if(err) { |
| 799 | printf("Error : %d\n", err); |
| 800 | } else { |
| 801 | printf("Success.\n"); |
| 802 | } |
| 803 | } else { // Get time type. |
| 804 | int time_type; |
| 805 | err = mbtk_time_get(info_handle, &time_type); |
| 806 | if(err) { |
| 807 | printf("Error : %d\n", err); |
| 808 | } else { |
| 809 | printf("Time type:%d.\n", time_type); |
| 810 | } |
| 811 | } |
| 812 | } else if(!strncasecmp(cmd, "apn", 3)){ |
| 813 | if(!strcasecmp(cmd, "apn")) { // Get apn |
| 814 | #define APN_MAX 10 |
| 815 | mbtk_apn_info_t apns[APN_MAX]; |
| 816 | int apn_num = APN_MAX; |
| 817 | err = mbtk_apn_get(info_handle, &apn_num, apns); |
| 818 | if(err) { |
| 819 | printf("Error : %d\n", err); |
| 820 | } else { |
| 821 | printf("APN Num:%d\n", apn_num); |
| 822 | int i = 0; |
| 823 | while(i < apn_num) { |
| 824 | printf("APN : %d, %s, %s\n", apns[i].cid, apn2str(apns[i].ip_type), apns[i].apn); |
| 825 | i++; |
| 826 | } |
| 827 | } |
| 828 | } else { // apn <cid> <0/1/2/3> <apn> |
| 829 | char *ptr = strstr(cmd, " "); |
| 830 | if(ptr == NULL) |
| 831 | continue; |
| 832 | while(*ptr != '\0' && *ptr == ' ') |
| 833 | ptr++; |
| 834 | int cid = atoi(ptr); |
| 835 | |
| 836 | ptr = strstr(ptr, " "); |
| 837 | if(ptr == NULL) |
| 838 | continue; |
| 839 | while(*ptr != '\0' && *ptr == ' ') |
| 840 | ptr++; |
| 841 | mbtk_ip_type_enum ip_type = (mbtk_ip_type_enum)atoi(ptr); |
| 842 | |
| 843 | ptr = strstr(ptr, " "); |
| 844 | if(ptr == NULL) |
| 845 | continue; |
| 846 | while(*ptr != '\0' && *ptr == ' ') |
| 847 | ptr++; |
| 848 | char *apn = ptr; |
| 849 | |
| 850 | err = mbtk_apn_set(info_handle, cid, ip_type, apn, NULL, NULL, NULL); |
| 851 | if(err) { |
| 852 | printf("Error : %d\n", err); |
| 853 | } else { |
| 854 | printf("APN set success\n"); |
| 855 | } |
| 856 | } |
| 857 | } else if(!strncasecmp(cmd, "data_call", 9)){ // data_call <0/1/2> <cid> <timeout> |
| 858 | // data_call <0/1/2> <cid> <timeout> |
| 859 | char *ptr = strstr(cmd, " "); |
| 860 | if(ptr == NULL) |
| 861 | continue; |
| 862 | while(*ptr != '\0' && *ptr == ' ') |
| 863 | ptr++; |
| 864 | mbtk_data_call_type_enum type = (mbtk_data_call_type_enum)atoi(ptr); |
| 865 | |
| 866 | ptr = strstr(ptr, " "); |
| 867 | if(ptr == NULL) |
| 868 | continue; |
| 869 | while(*ptr != '\0' && *ptr == ' ') |
| 870 | ptr++; |
| 871 | int cid = atoi(ptr); |
| 872 | |
| 873 | ptr = strstr(ptr, " "); |
| 874 | if(ptr == NULL) |
| 875 | continue; |
| 876 | while(*ptr != '\0' && *ptr == ' ') |
| 877 | ptr++; |
| 878 | int timeout = atoi(ptr); |
| 879 | |
| 880 | if(type == MBTK_DATA_CALL_START) { |
| 881 | err = mbtk_data_call_start(info_handle, cid, 0, FALSE, timeout); |
| 882 | } else if(type == MBTK_DATA_CALL_STOP) { |
| 883 | err = mbtk_data_call_stop(info_handle, cid, timeout); |
| 884 | } else { |
| 885 | mbtk_ipv4_info_t ipv4; |
| 886 | mbtk_ipv6_info_t ipv6; |
| 887 | err = mbtk_data_call_state_get(info_handle, cid, &ipv4, &ipv6); |
| 888 | if(!err) { |
| 889 | if(ipv4.valid) { |
| 890 | // log_hex("IPv4", &ipv4, sizeof(mbtk_ipv4_info_t)); |
| 891 | char ip_tmp[20]; |
| 892 | |
| 893 | memset(ip_tmp, 0, 20); |
| 894 | if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip_tmp, 20) == NULL) { |
| 895 | printf("IP error.\n"); |
| 896 | } else { |
| 897 | printf("IP : %s\n", ip_tmp); |
| 898 | } |
| 899 | |
| 900 | memset(ip_tmp, 0, 20); |
| 901 | if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), ip_tmp, 20) == NULL) { |
| 902 | printf("PrimaryDNS error.\n"); |
| 903 | } else { |
| 904 | printf("PrimaryDNS : %s\n", ip_tmp); |
| 905 | } |
| 906 | |
| 907 | memset(ip_tmp, 0, 20); |
| 908 | if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), ip_tmp, 20) == NULL) { |
| 909 | printf("SecondaryDNS error.\n"); |
| 910 | } else { |
| 911 | printf("SecondaryDNS : %s\n", ip_tmp); |
| 912 | } |
| 913 | |
| 914 | memset(ip_tmp, 0, 20); |
| 915 | if(inet_ntop(AF_INET, &(ipv4.GateWay), ip_tmp, 20) == NULL) { |
| 916 | printf("GateWay error.\n"); |
| 917 | } else { |
| 918 | printf("GateWay : %s\n", ip_tmp); |
| 919 | } |
| 920 | |
| 921 | memset(ip_tmp, 0, 20); |
| 922 | if(inet_ntop(AF_INET, &(ipv4.NetMask), ip_tmp, 20) == NULL) { |
| 923 | printf("NetMask error.\n"); |
| 924 | } else { |
| 925 | printf("NetMask : %s\n", ip_tmp); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | if(ipv6.valid) { |
| 930 | // log_hex("IPv6", &ipv6, sizeof(mbtk_ipv6_info_t)); |
| 931 | char ip_tmp[50]; |
| 932 | |
| 933 | memset(ip_tmp, 0, 50); |
| 934 | if(ipv6_2_str(&(ipv6.IPV6Addr), ip_tmp)) { |
| 935 | printf("IP error.\n"); |
| 936 | } else { |
| 937 | printf("IP : %s\n", ip_tmp); |
| 938 | } |
| 939 | |
| 940 | memset(ip_tmp, 0, 50); |
| 941 | if(ipv6_2_str(&(ipv6.PrimaryDNS), ip_tmp)) { |
| 942 | printf("PrimaryDNS error.\n"); |
| 943 | } else { |
| 944 | printf("PrimaryDNS : %s\n", ip_tmp); |
| 945 | } |
| 946 | |
| 947 | memset(ip_tmp, 0, 50); |
| 948 | if(ipv6_2_str(&(ipv6.SecondaryDNS), ip_tmp)) { |
| 949 | printf("SecondaryDNS error.\n"); |
| 950 | } else { |
| 951 | printf("SecondaryDNS : %s\n", ip_tmp); |
| 952 | } |
| 953 | |
| 954 | memset(ip_tmp, 0, 50); |
| 955 | if(ipv6_2_str(&(ipv6.GateWay), ip_tmp)) { |
| 956 | printf("GateWay error.\n"); |
| 957 | } else { |
| 958 | printf("GateWay : %s\n", ip_tmp); |
| 959 | } |
| 960 | |
| 961 | memset(ip_tmp, 0, 50); |
| 962 | if(ipv6_2_str(&(ipv6.NetMask), ip_tmp)) { |
| 963 | printf("NetMask error.\n"); |
| 964 | } else { |
| 965 | printf("NetMask : %s\n", ip_tmp); |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | } |
| 970 | if(err) { |
| 971 | printf("Error : %d\n", err); |
| 972 | } else { |
| 973 | printf("DATA_CALL success\n"); |
| 974 | } |
| 975 | }else if(!strncasecmp(cmd, "cmgf", 4)){ // set mode 0: pud, 1:text |
| 976 | int mode; |
| 977 | if(!strcasecmp(cmd, "cmgf")) { // Get |
| 978 | err = mbtk_sms_cmgf_get(info_handle, &mode); |
| 979 | if(err) { |
| 980 | printf("Error : %d\n", err); |
| 981 | } else { |
| 982 | printf("VoLTE : %d\n", mode); |
| 983 | } |
| 984 | } else { // Set |
| 985 | if(!strcasecmp(cmd, "cmgf 1")) { // cmgf 1 |
| 986 | mode = 1; |
| 987 | } else { // |
| 988 | mode = 0; |
| 989 | } |
| 990 | printf("mode:%d\n", mode); |
| 991 | sleep(2); |
| 992 | err = mbtk_sms_cmgf_set(info_handle, mode); |
| 993 | if(err) { |
| 994 | printf("Error : %d\n", err); |
| 995 | } else { |
| 996 | printf("VoLTE set success\n"); |
| 997 | } |
| 998 | } |
| 999 | }else if(!strncasecmp(cmd, "cpms", 4)){ // //CPMS=ME, ME, ME |
| 1000 | char mem[100] = {0}; |
| 1001 | char resp[100] = {0}; |
| 1002 | if(!strcasecmp(cmd, "cpms")) { // Get |
| 1003 | err = mbtk_sms_cpms_get(info_handle, &mem); |
| 1004 | if(err) { |
| 1005 | printf("Error : %d\n", err); |
| 1006 | } else { |
| 1007 | printf("cpms : %s\n", mem); |
| 1008 | } |
| 1009 | } else { // Set |
| 1010 | |
| 1011 | char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME |
| 1012 | if(ptr != NULL) |
| 1013 | { |
| 1014 | ptr++; |
| 1015 | memset(mem, 0, sizeof(mem)); |
| 1016 | memcpy(mem, ptr, strlen(ptr)); |
| 1017 | printf("cpms:%s\n", mem); |
| 1018 | } |
| 1019 | printf("cpms 0\n"); |
| 1020 | |
| 1021 | memset(resp, 0, sizeof(resp)); |
| 1022 | err = mbtk_sms_cpms_set(info_handle, mem, resp); |
| 1023 | if(err) { |
| 1024 | printf("Error : %d\n", err); |
| 1025 | } else { |
| 1026 | printf("cpms set success. resp:%s\n", resp); |
| 1027 | } |
| 1028 | } |
| 1029 | }else if(!strncasecmp(cmd, "cmgs", 4)){ // AT+CMGS="10086", CMGS TEST |
| 1030 | char cmgs[1024] = {0}; |
| 1031 | char resp[50] = {0}; |
| 1032 | if(!strcasecmp(cmd, "cmgs")) { // Get |
| 1033 | int mode; |
| 1034 | // err = mbtk_sms_cmgs_get(info_handle, &mode); |
| 1035 | if(err) { |
| 1036 | printf("Error : %d\n", err); |
| 1037 | } else { |
| 1038 | printf("VoLTE : %d\n", mode); |
| 1039 | } |
| 1040 | } else { // Set |
| 1041 | |
| 1042 | /* |
| 1043 | *AT+CMGS="10086", CMGS TEST // Send a SMS |
| 1044 | > CMGS TEST |
| 1045 | +CMGS: 17 |
| 1046 | OK |
| 1047 | */ |
| 1048 | |
| 1049 | char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf |
| 1050 | if(ptr != NULL) |
| 1051 | { |
| 1052 | ptr = strstr(cmd, ","); |
| 1053 | ptr++; |
| 1054 | memset(cmgs, 0, sizeof(cmgs)); |
| 1055 | memcpy(cmgs, ptr, strlen(ptr)); |
| 1056 | printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs)); |
| 1057 | } |
| 1058 | |
| 1059 | memset(resp, 0, sizeof(resp)); |
| 1060 | err = mbtk_sms_cmgs_set(info_handle, cmgs, resp); |
| 1061 | if(err) { |
| 1062 | printf("Error : %d\n", err); |
| 1063 | } else { |
| 1064 | printf("cmgs set success . resp:%s\n", resp); |
| 1065 | } |
| 1066 | } |
| 1067 | }else if(!strncasecmp(cmd, "cmss", 4)){ // +CMSS=<index>[,<da>[,<toda>]] |
| 1068 | char cmss[20] = {0}; |
| 1069 | char resp[20] = {0}; |
| 1070 | if(!strcasecmp(cmd, "cmgs")) { // Get |
| 1071 | printf("cmss : OK\n"); |
| 1072 | |
| 1073 | } else { |
| 1074 | char *ptr = strstr(cmd, "cmss,"); //CMSS=<index> |
| 1075 | if(ptr != NULL) |
| 1076 | { |
| 1077 | ptr = strstr(cmd, ","); |
| 1078 | ptr++; |
| 1079 | memset(cmss, 0, sizeof(cmss)); |
| 1080 | memcpy(cmss, ptr, strlen(ptr)); |
| 1081 | printf("1cmss:%s\n", cmss); |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | err = mbtk_sms_cmss_set(info_handle, cmss, resp); |
| 1086 | if(err) { |
| 1087 | printf("Error : %d\n", err); |
| 1088 | } else { |
| 1089 | printf("cmss set success. resp:%s\n", resp); |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | else if(!strncasecmp(cmd, "cmgr", 4)){ // +CMGR=<index |
| 1094 | int index = 0; |
| 1095 | char resp[1024] = {0}; |
| 1096 | if(!strcasecmp(cmd, "cmgr")) { // Get |
| 1097 | printf("cmgr : OK\n"); |
| 1098 | |
| 1099 | } else { |
| 1100 | char *ptr = strstr(cmd, "cmgr,"); //+CMGR <index> |
| 1101 | if(ptr != NULL) |
| 1102 | { |
| 1103 | ptr = strstr(cmd, ","); |
| 1104 | ptr++; |
| 1105 | index = atoi(ptr); |
| 1106 | } |
| 1107 | printf("1index:%d\n", index); |
| 1108 | |
| 1109 | memset(resp, 0, sizeof(resp)); |
| 1110 | err = mbtk_sms_cmgr_set(info_handle, index, resp); |
| 1111 | if(err) { |
| 1112 | printf("Error : %d\n", err); |
| 1113 | } else { |
| 1114 | printf("cmgr set success. rep:%s\n", resp); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | else if(!strncasecmp(cmd, "cmgw", 4)){ // +CMGW=<oa/da>[,<tooa/toda>[,<stat>]]<CR> |
| 1119 | //+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC> |
| 1120 | char cmgw[128] = {0}; |
| 1121 | char resp[50] = {0}; |
| 1122 | if(!strcasecmp(cmd, "cmgw")) { // Get |
| 1123 | printf("cmgw : OK\n"); |
| 1124 | |
| 1125 | } else { |
| 1126 | char *ptr = strstr(cmd, "cmgw,"); //+CMGW, <oa/da>, data |
| 1127 | if(ptr != NULL) |
| 1128 | { |
| 1129 | ptr = strstr(cmd, ","); |
| 1130 | ptr++; |
| 1131 | memset(cmgw, 0, sizeof(cmgw)); |
| 1132 | memcpy(cmgw, ptr, strlen(ptr)); |
| 1133 | printf("cmgw:%s\n", cmgw); |
| 1134 | } |
| 1135 | |
| 1136 | memset(resp, 0, sizeof(resp)); |
| 1137 | err = mbtk_sms_cmgw_set(info_handle, cmgw, resp); |
| 1138 | if(err) { |
| 1139 | printf("Error : %d\n", err); |
| 1140 | } else { |
| 1141 | printf("cmgw set success. resp:%s\n", resp); |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | else if(!strncasecmp(cmd, "cmgd", 4)){ // +CMGD=<index>[,<delflag> |
| 1146 | // |
| 1147 | char cmgd[128] = {0}; |
| 1148 | if(!strcasecmp(cmd, "cmgd")) { // Get |
| 1149 | printf("cmgd : OK\n"); |
| 1150 | |
| 1151 | } else { |
| 1152 | char *ptr = strstr(cmd, ","); //+CMGD=<index>[,<delflag> |
| 1153 | if(ptr != NULL) |
| 1154 | { |
| 1155 | ptr++; |
| 1156 | memset(cmgd, 0, sizeof(cmgd)); |
| 1157 | memcpy(cmgd, ptr, strlen(ptr)); |
| 1158 | printf("1cmgd:%s\n", cmgd); |
| 1159 | } |
| 1160 | |
| 1161 | |
| 1162 | err = mbtk_sms_cmgd_set(info_handle, cmgd); |
| 1163 | if(err) { |
| 1164 | printf("Error : %d\n", err); |
| 1165 | } else { |
| 1166 | printf("VoLTE set success\n"); |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | else if(!strncasecmp(cmd, "cmgl", 4)){ // AT+CMGL[=<stat>] |
| 1171 | // |
| 1172 | char cmgl[128] = {0}; |
| 1173 | char resp[5*1024] ={0}; |
| 1174 | if(!strcasecmp(cmd, "cmgl")) { // Get |
| 1175 | printf("cmgl : OK\n"); |
| 1176 | |
| 1177 | } else { |
| 1178 | char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>] |
| 1179 | if(ptr != NULL) |
| 1180 | { |
| 1181 | ptr = strstr(cmd, ","); |
| 1182 | ptr++; |
| 1183 | memset(cmgl, 0, sizeof(cmgl)); |
| 1184 | memcpy(cmgl, ptr, strlen(ptr)); |
| 1185 | printf("0cmgl:%s\n", cmgl); |
| 1186 | } |
| 1187 | |
| 1188 | memset(resp, 0, sizeof(resp)); |
| 1189 | err = mbtk_sms_cmgl_set(info_handle, cmgl, resp); |
| 1190 | if(err) { |
| 1191 | printf("Error : %d\n", err); |
| 1192 | } else { |
| 1193 | // printf("cmgl set success, reg:%s\n",resp); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | else if(!strncasecmp(cmd, "csca", 4)){ // AT+CSCA=<number> [,<type>] |
| 1198 | // |
| 1199 | char csca[128] = {0}; |
| 1200 | if(!strcasecmp(cmd, "csca")) { // Get |
| 1201 | err = mbtk_sms_csca_get(info_handle, csca); |
| 1202 | if(err) { |
| 1203 | printf("mbtk_sms_csca_get Error : %d\n", err); |
| 1204 | } else { |
| 1205 | printf("mbtk_sms_csca_get success\n"); |
| 1206 | } |
| 1207 | |
| 1208 | } else { |
| 1209 | char *ptr = strstr(cmd, ","); // AT+CSCA=<number> [,<type>] |
| 1210 | if(ptr != NULL) |
| 1211 | { |
| 1212 | ptr++; |
| 1213 | memset(csca, 0, sizeof(csca)); |
| 1214 | memcpy(csca, ptr, strlen(ptr)); |
| 1215 | printf("csca:%s\n", csca); |
| 1216 | } |
| 1217 | |
| 1218 | err = mbtk_sms_csca_set(info_handle, csca); |
| 1219 | if(err) { |
| 1220 | printf("Error : %d\n", err); |
| 1221 | } else { |
| 1222 | printf("VoLTE set success\n"); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | else if(!strncasecmp(cmd, "csmp", 4)){ // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]] |
| 1227 | // |
| 1228 | char csmp[128] = {0}; |
| 1229 | if(!strcasecmp(cmd, "csmp")) { // Get |
| 1230 | printf("cmgl : OK\n"); |
| 1231 | |
| 1232 | } else { |
| 1233 | char *ptr = strstr(cmd, ","); // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]] |
| 1234 | if(ptr != NULL) |
| 1235 | { |
| 1236 | ptr++; |
| 1237 | memset(csmp, 0, sizeof(csmp)); |
| 1238 | memcpy(csmp, ptr, strlen(ptr)); |
| 1239 | printf("csmp:%s\n", csmp); |
| 1240 | } |
| 1241 | |
| 1242 | err = mbtk_sms_csmp_set(info_handle, csmp); |
| 1243 | if(err) { |
| 1244 | printf("Error : %d\n", err); |
| 1245 | } else { |
| 1246 | printf("VoLTE set success\n"); |
| 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | else if(!strncasecmp(cmd, "cscb", 4)){ // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]> |
| 1251 | // |
| 1252 | char cscb[128] = {0}; |
| 1253 | if(!strcasecmp(cmd, "cscb")) { // Get |
| 1254 | printf("cmgl : OK\n"); |
| 1255 | |
| 1256 | } else { |
| 1257 | char *ptr = strstr(cmd, ","); // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]> |
| 1258 | if(ptr != NULL) |
| 1259 | { |
| 1260 | ptr++; |
| 1261 | memset(cscb, 0, sizeof(cscb)); |
| 1262 | memcpy(cscb, ptr, strlen(ptr)); |
| 1263 | printf("cscb:%s\n", cscb); |
| 1264 | } |
| 1265 | |
| 1266 | err = mbtk_sms_cscb_set(info_handle, cscb); |
| 1267 | if(err) { |
| 1268 | printf("Error : %d\n", err); |
| 1269 | } else { |
| 1270 | printf("VoLTE set success\n"); |
| 1271 | } |
| 1272 | } |
| 1273 | } |
b.liu | d8043a3 | 2024-06-07 16:08:22 +0800 | [diff] [blame] | 1274 | else if(!strncasecmp(cmd, "ims_en", 6)){ // ims_en 0/1 |
| 1275 | char enable[10] = {0}; |
| 1276 | if(1 == sscanf(cmd, "ims_en %s", enable)) { |
| 1277 | err = mbtk_net_ims_set(info_handle, atoi(enable) ? 1 : 0); |
| 1278 | if(err) { |
| 1279 | printf("Set IMS fail : %d\n", err); |
| 1280 | } else { |
| 1281 | printf("Set IMS success\n"); |
| 1282 | } |
| 1283 | } else { |
| 1284 | printf("ARG error\n"); |
| 1285 | } |
| 1286 | } |
| 1287 | else if(!strncasecmp(cmd, "ims_state", 9)){ // ims_state |
| 1288 | int enable = 0; |
| 1289 | err = mbtk_net_ims_get(info_handle, &enable); |
| 1290 | if(err) { |
| 1291 | printf("Get IMS state fail : %d\n", err); |
| 1292 | } else { |
| 1293 | printf("IMS state : %d\n", enable); |
| 1294 | } |
| 1295 | } |
| 1296 | else if(!strncasecmp(cmd, "ims_reg", 7)){ // ims_reg |
| 1297 | int reg = 0; |
| 1298 | err = mbtk_net_ims_reg_state_get(info_handle, ®); |
| 1299 | if(err) { |
| 1300 | printf("Get IMS register state fail : %d\n", err); |
| 1301 | } else { |
| 1302 | printf("IMS register state : %d\n", reg); |
| 1303 | } |
| 1304 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1305 | else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) { |
| 1306 | help(); |
| 1307 | } else if(!strcasecmp(cmd, "q")) { |
| 1308 | mbtk_info_handle_free(&info_handle); |
| 1309 | break; |
| 1310 | } else { |
| 1311 | printf("\n"); |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | LOG("Client exec complete."); |
| 1317 | #if 1 |
| 1318 | while(1) |
| 1319 | { |
| 1320 | sleep(1000 * 365 * 24 * 60 * 60); |
| 1321 | } |
| 1322 | #else |
| 1323 | sleep(1); |
| 1324 | #endif |
| 1325 | return 0; |
| 1326 | } |