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"); |
| 202 | } |
| 203 | |
| 204 | static void sig_process(int sig) |
| 205 | { |
| 206 | LOGI("I got signal %d\n", sig); |
| 207 | switch(sig) |
| 208 | { |
| 209 | case SIGINT: // Ctrl + C |
| 210 | { |
| 211 | LOGI("Exit by SIGINT.\n"); |
| 212 | mbtk_info_handle_free(&info_handle); |
| 213 | exit(0); |
| 214 | } |
| 215 | case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件) |
| 216 | { |
| 217 | LOGI("Exit by SIGQUIT.\n"); |
| 218 | mbtk_info_handle_free(&info_handle); |
| 219 | exit(0); |
| 220 | } |
| 221 | case SIGTERM:// 默认kill (同 SIGKILL ,但 SIGKILL 不可捕获) |
| 222 | { |
| 223 | LOGI("Exit by SIGTERM.\n"); |
| 224 | mbtk_info_handle_free(&info_handle); |
| 225 | exit(0); |
| 226 | } |
| 227 | case SIGTSTP:// Ctrl + Z (同 SIGSTOP ,但 SIGSTOP 不可捕获) |
| 228 | { |
| 229 | LOGI("Exit by SIGTSTP.\n"); |
| 230 | exit(0); |
| 231 | } |
| 232 | case SIGSEGV: // 如空指针 |
| 233 | { |
| 234 | LOGI("Exit by SIGSEGV.\n"); |
| 235 | exit(0); |
| 236 | } |
| 237 | default: |
| 238 | { |
| 239 | LOGI("Unknown sig:%d\n",sig); |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | int main(int argc, char *argv[]) |
| 246 | { |
| 247 | signal(SIGINT, sig_process); |
| 248 | signal(SIGQUIT, sig_process); |
| 249 | signal(SIGTERM, sig_process); |
| 250 | //signal(SIGTSTP, sig_process); |
| 251 | //signal(SIGSEGV, sig_process); |
| 252 | |
b.liu | fe32063 | 2024-01-17 20:38:08 +0800 | [diff] [blame] | 253 | mbtk_log_init("radio","INFO_CLI"); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 254 | |
| 255 | //test2(0, "192.168.1.198"); |
| 256 | //test2(1, "2409:8162:140:cd3c:1:2:1494:72ba"); |
| 257 | //test2(1, "254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239"); |
| 258 | //test2(1, "2400:3200::1"); |
| 259 | |
| 260 | info_handle = mbtk_info_handle_get(); |
| 261 | if(!info_handle) |
| 262 | { |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | mbtk_net_state_change_cb_reg(info_handle, net_state_change_cb); |
| 267 | mbtk_call_state_change_cb_reg(info_handle, call_state_change_cb); |
| 268 | mbtk_sms_state_change_cb_reg(info_handle, sms_state_change_cb); |
| 269 | mbtk_radio_state_change_cb_reg(info_handle, radio_state_change_cb); |
| 270 | mbtk_sim_state_change_cb_reg(info_handle, sim_state_change_cb); |
| 271 | |
| 272 | printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n"); |
| 273 | char cmd[100]; |
| 274 | while(1) |
| 275 | { |
| 276 | memset(cmd, 0, 100); |
| 277 | int err; |
| 278 | if(fgets(cmd, 100, stdin)) |
| 279 | { |
| 280 | char *ptr = cmd + strlen(cmd) - 1; |
| 281 | while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n')) |
| 282 | { |
| 283 | *ptr-- = '\0'; |
| 284 | } |
| 285 | if(!strncasecmp(cmd, "version", 7)) |
| 286 | { |
| 287 | char version[50] = {0}; |
| 288 | err = mbtk_version_get(info_handle, version); |
| 289 | if(err) { |
| 290 | printf("Error : %d\n", err); |
| 291 | } else { |
| 292 | printf("Version : %s\n", version); |
| 293 | } |
| 294 | } else if(!strncasecmp(cmd, "imei", 4)){ |
| 295 | char imei[50] = {0}; |
| 296 | err = mbtk_imei_get(info_handle, imei); |
| 297 | if(err) { |
| 298 | printf("Error : %d\n", err); |
| 299 | } else { |
| 300 | printf("IMEI : %s\n", imei); |
| 301 | } |
| 302 | } else if(!strncasecmp(cmd, "sn", 2)){ |
| 303 | char sn[50] = {0}; |
| 304 | err = mbtk_sn_get(info_handle, sn); |
| 305 | if(err) { |
| 306 | printf("Error : %d\n", err); |
| 307 | } else { |
| 308 | printf("SN : %s\n", sn); |
| 309 | } |
| 310 | } else if(!strncasecmp(cmd, "meid", 4)){ |
| 311 | char meid[50] = {0}; |
| 312 | err = mbtk_meid_get(info_handle, meid); |
| 313 | if(err) { |
| 314 | printf("Error : %d\n", err); |
| 315 | } else { |
| 316 | printf("MEID : %s\n", meid); |
| 317 | } |
| 318 | } else if(!strncasecmp(cmd, "volte", 5)){ // "volte" or "volte 0" or "volte 1" |
| 319 | int volte; |
| 320 | if(!strcasecmp(cmd, "volte")) { // Get |
| 321 | err = mbtk_volte_state_get(info_handle, &volte); |
| 322 | if(err) { |
| 323 | printf("Error : %d\n", err); |
| 324 | } else { |
| 325 | printf("VoLTE : %d\n", volte); |
| 326 | } |
| 327 | } else { // Set |
| 328 | if(!strcasecmp(cmd, "volte 1")) { // Open VoLTE |
| 329 | volte = 1; |
| 330 | } else { // Close VoLTE |
| 331 | volte = 0; |
| 332 | } |
| 333 | err = mbtk_volte_state_set(info_handle, volte); |
| 334 | if(err) { |
| 335 | printf("Error : %d\n", err); |
| 336 | } else { |
| 337 | printf("VoLTE set success\n"); |
| 338 | } |
| 339 | } |
| 340 | } else if(!strncasecmp(cmd, "radio", 5)){ // "radio" or "radio 0" or "radio 1" |
| 341 | int radio; |
| 342 | if(!strcasecmp(cmd, "radio")) { // Get |
| 343 | err = mbtk_radio_state_get(info_handle, &radio); |
| 344 | if(err) { |
| 345 | printf("Error : %d\n", err); |
| 346 | } else { |
| 347 | printf("Radio : %d\n", radio); |
| 348 | } |
| 349 | } else { // Set |
| 350 | if(!strcasecmp(cmd, "radio 1")) { // Open radio |
| 351 | radio = 1; |
| 352 | } else { // Close radio |
| 353 | radio = 0; |
| 354 | } |
| 355 | err = mbtk_radio_state_set(info_handle, radio); |
| 356 | if(err) { |
| 357 | printf("Error : %d\n", err); |
| 358 | } else { |
| 359 | printf("Radio set success\n"); |
| 360 | } |
| 361 | } |
| 362 | } else if(!strncasecmp(cmd, "sim", 3)){ |
| 363 | mbtk_sim_state_enum sim; |
| 364 | err = mbtk_sim_state_get(info_handle, &sim); |
| 365 | if(err) { |
| 366 | printf("Error : %d\n", err); |
| 367 | } else { |
| 368 | printf("Sim : %d\n", sim); |
| 369 | } |
| 370 | } else if(!strncasecmp(cmd, "imsi", 4)){ |
| 371 | char imsi[50] = {0}; |
| 372 | err = mbtk_imsi_get(info_handle, imsi); |
| 373 | if(err) { |
| 374 | printf("Error : %d\n", err); |
| 375 | } else { |
| 376 | printf("IMSI : %s\n", imsi); |
| 377 | } |
| 378 | } else if(!strncasecmp(cmd, "iccid", 5)){ |
| 379 | char iccid[50] = {0}; |
| 380 | err = mbtk_iccid_get(info_handle, iccid); |
| 381 | if(err) { |
| 382 | printf("Error : %d\n", err); |
| 383 | } else { |
| 384 | printf("ICCID : %s\n", iccid); |
| 385 | } |
| 386 | } else if(!strncasecmp(cmd, "pn", 2)){ |
| 387 | char phone_number[50] = {0}; |
| 388 | err = mbtk_phone_number_get(info_handle, phone_number); |
| 389 | if(err) { |
| 390 | printf("Error : %d\n", err); |
| 391 | } else { |
| 392 | printf("Phone Number : %s\n", phone_number); |
| 393 | } |
| 394 | } else if(!strncasecmp(cmd, "avail_net", 9)){ |
| 395 | list_node_t* net_list = NULL; |
| 396 | err = mbtk_available_net_get(info_handle, &net_list); |
| 397 | if(err || net_list == NULL) { |
| 398 | printf("Error : %d\n", err); |
| 399 | } else { |
| 400 | mbtk_net_info_t* net = NULL; |
| 401 | list_first(net_list); |
| 402 | while ((net = (mbtk_net_info_t*) list_next(net_list))) |
| 403 | { |
| 404 | printf("Net : %d, %d, %d, %d\n", net->net_sel_mode, net->net_type, net->net_state, net->plmn); |
| 405 | } |
| 406 | } |
| 407 | list_free(net_list); |
| 408 | } else if(!strncasecmp(cmd, "cell", 4)){ |
| 409 | char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME |
| 410 | if(ptr == NULL) |
| 411 | { |
| 412 | printf("ptr == NULL\n"); |
| 413 | list_node_t* cell_list = NULL; |
| 414 | int type; |
| 415 | err = mbtk_cell_get(info_handle, &type, &cell_list); |
| 416 | if(err || cell_list == NULL) { |
| 417 | printf("Error : %d\n", err); |
| 418 | } else { |
| 419 | list_first(cell_list); |
| 420 | mbtk_cell_info_t* cell = (mbtk_cell_info_t*) list_next(cell_list); |
| 421 | if(cell) { // Current server cell. |
| 422 | switch(type) |
| 423 | { |
| 424 | case 0: |
| 425 | printf("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell->value1, cell->value2, cell->value3, cell->value4); |
| 426 | break; |
| 427 | case 1: |
| 428 | printf("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3); |
| 429 | break; |
| 430 | case 2: |
| 431 | printf("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5); |
| 432 | break; |
| 433 | default: |
| 434 | break; |
| 435 | } |
| 436 | } |
| 437 | while ((cell = (mbtk_cell_info_t*) list_next(cell_list))) |
| 438 | { |
| 439 | switch(type) |
| 440 | { |
| 441 | case 0: |
| 442 | printf("CELL : %d, %d, %d, %d, %d", cell->value1, cell->value2, cell->value3, cell->value4, cell->value5); |
| 443 | break; |
| 444 | case 1: |
| 445 | printf("CELL : lac=%d, ci=%d, arfcn=%d\n", cell->value1, cell->value2, cell->value3); |
| 446 | break; |
| 447 | case 2: |
| 448 | printf("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell->value1, cell->value2, cell->value3, cell->value4); |
| 449 | break; |
| 450 | default: |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | list_free(cell_list); |
| 456 | } |
| 457 | else{ |
| 458 | char *ptr = strstr(cmd, ","); //cell,2,3,,40936,430 |
| 459 | char mem[50]={0}; |
| 460 | char resp[1024] = {0}; |
| 461 | if(ptr != NULL) |
| 462 | { |
| 463 | ptr++; |
| 464 | memset(mem, 0, sizeof(mem)); |
| 465 | memcpy(mem, ptr, strlen(ptr)); |
| 466 | printf("cell:%s\n", mem); |
| 467 | } |
| 468 | printf("cell_mem: %s \n", mem); |
| 469 | |
| 470 | memset(resp, 0, sizeof(resp)); |
| 471 | err = mbtk_cell_set(info_handle, mem, resp); |
| 472 | if(err) { |
| 473 | printf("Error : %d\n", err); |
| 474 | } else { |
| 475 | printf("cell set . resp:%s\n", resp); |
| 476 | } |
| 477 | |
| 478 | } |
| 479 | } else if(!strncasecmp(cmd, "sel_mode", 8)){ // "sel_mode" or "sel_mode 1 7 46000" |
| 480 | mbtk_net_info_t net; |
| 481 | memset(&net, 0, sizeof(mbtk_net_info_t)); |
| 482 | if(!strcasecmp(cmd, "sel_mode")) { // Get |
| 483 | err = mbtk_net_sel_mode_get(info_handle, &net); |
| 484 | if(err) { |
| 485 | printf("Error : %d\n", err); |
| 486 | } else { |
| 487 | printf("Net : %d, %d, %d, %d\n", net.net_sel_mode, net.net_type, net.net_state, net.plmn); |
| 488 | } |
| 489 | } else { // Set |
| 490 | char *ptr = strstr(cmd, " "); |
| 491 | if(ptr == NULL) |
| 492 | continue; |
| 493 | while(*ptr != '\0' && *ptr == ' ') |
| 494 | ptr++; |
| 495 | net.net_sel_mode = (uint8)atoi(ptr); |
| 496 | |
| 497 | ptr = strstr(ptr, " "); |
| 498 | if(ptr == NULL) |
| 499 | continue; |
| 500 | while(*ptr != '\0' && *ptr == ' ') |
| 501 | ptr++; |
| 502 | net.net_type = (uint8)atoi(ptr); |
| 503 | |
| 504 | ptr = strstr(ptr, " "); |
| 505 | if(ptr == NULL) |
| 506 | continue; |
| 507 | while(*ptr != '\0' && *ptr == ' ') |
| 508 | ptr++; |
| 509 | net.plmn = (uint32)atoi(ptr); |
| 510 | |
| 511 | err = mbtk_net_sel_mode_set(info_handle, &net); |
| 512 | if(err) { |
| 513 | printf("Error : %d\n", err); |
| 514 | } else { |
| 515 | printf("Net select mode set success\n"); |
| 516 | } |
| 517 | } |
| 518 | } else if(!strncasecmp(cmd, "band", 4)){ // "band" or "band support" or "band 0 79 147 482 524503" |
| 519 | mbtk_band_info_t band; |
b.liu | 288093c | 2024-05-09 17:02:57 +0800 | [diff] [blame^] | 520 | memset(&band, 0x0, sizeof(mbtk_band_info_t)); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 521 | if(!strcasecmp(cmd, "band")) { // Get |
| 522 | err = mbtk_current_band_get(info_handle, &band); |
| 523 | if(err) { |
| 524 | printf("Error : %d\n", err); |
| 525 | } else { |
| 526 | printf("Band : %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band); |
| 527 | } |
| 528 | } else if(!strcasecmp(cmd, "band support")) { // Get |
| 529 | err = mbtk_support_band_get(info_handle, &band); |
| 530 | if(err) { |
| 531 | printf("Error : %d\n", err); |
| 532 | } else { |
| 533 | printf("Band : %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band); |
| 534 | } |
| 535 | } else { // "band 0 79 147 482 524503" |
| 536 | char *ptr = strstr(cmd, " "); |
| 537 | if(ptr == NULL) |
| 538 | continue; |
| 539 | while(*ptr != '\0' && *ptr == ' ') |
| 540 | ptr++; |
| 541 | band.net_pref = (uint8)atoi(ptr); |
| 542 | |
| 543 | ptr = strstr(ptr, " "); |
| 544 | if(ptr == NULL) |
| 545 | continue; |
| 546 | while(*ptr != '\0' && *ptr == ' ') |
| 547 | ptr++; |
| 548 | band.gsm_band = (uint16)atoi(ptr); |
| 549 | |
| 550 | ptr = strstr(ptr, " "); |
| 551 | if(ptr == NULL) |
| 552 | continue; |
| 553 | while(*ptr != '\0' && *ptr == ' ') |
| 554 | ptr++; |
| 555 | band.umts_band = (uint16)atoi(ptr); |
| 556 | |
| 557 | ptr = strstr(ptr, " "); |
| 558 | if(ptr == NULL) |
| 559 | continue; |
| 560 | while(*ptr != '\0' && *ptr == ' ') |
| 561 | ptr++; |
| 562 | band.tdlte_band = (uint32)atoi(ptr); |
| 563 | |
| 564 | ptr = strstr(ptr, " "); |
| 565 | if(ptr == NULL) |
| 566 | continue; |
| 567 | while(*ptr != '\0' && *ptr == ' ') |
| 568 | ptr++; |
| 569 | band.fddlte_band = (uint32)atoi(ptr); |
| 570 | |
| 571 | err = mbtk_current_band_set(info_handle, &band); |
| 572 | if(err) { |
| 573 | printf("Error : %d\n", err); |
| 574 | } else { |
| 575 | printf("Band set success\n"); |
| 576 | } |
| 577 | } |
| 578 | } else if(!strncasecmp(cmd, "signal", 6)){ |
| 579 | mbtk_signal_info_t signal; |
| 580 | err = mbtk_net_signal_get(info_handle, &signal); |
| 581 | if(err) { |
| 582 | printf("Error : %d\n", err); |
| 583 | } else { |
| 584 | printf("Signal : %d, %d, %d, %d, %d, %d, %d, %d\n", signal.type, signal.rssi, signal.rxlev, signal.ber, |
| 585 | signal.rscp, signal.ecno, signal.rsrq, signal.rsrp); |
| 586 | } |
| 587 | } else if(!strncasecmp(cmd, "reg", 3)){ |
| 588 | mbtk_net_reg_info_t reg; |
| 589 | err = mbtk_net_reg_get(info_handle, ®); |
| 590 | if(err) { |
| 591 | printf("Error : %d\n", err); |
| 592 | } else { |
| 593 | 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); |
| 594 | } |
| 595 | } else if(!strncasecmp(cmd, "call", 4)){ |
| 596 | char phone_number[12]; |
| 597 | char *ptr = strstr(cmd, " "); |
| 598 | if(ptr == NULL) |
| 599 | continue; |
| 600 | while(*ptr != '\0' && *ptr == ' ') |
| 601 | ptr++; |
| 602 | memset(phone_number,0,strlen(phone_number)); |
| 603 | memcpy(phone_number,ptr,strlen(ptr)); |
| 604 | printf("phone number is: %s\n",phone_number); |
| 605 | err = mbtk_call_start(info_handle, phone_number); |
| 606 | if(err) { |
| 607 | printf("Error : %d\n", err); |
| 608 | } else { |
| 609 | printf("Call success.\n"); |
| 610 | } |
| 611 | } else if(!strncasecmp(cmd, "answer", 6)){ |
| 612 | err = mbtk_call_answer(info_handle); |
| 613 | if(err) { |
| 614 | printf("Error : %d\n", err); |
| 615 | } else { |
| 616 | printf("Call success.\n"); |
| 617 | } |
| 618 | } else if(!strncasecmp(cmd, "hangup", 6)){ |
| 619 | int phone_id; |
| 620 | if(!strcasecmp(cmd, "hangup")) { // hang up all |
| 621 | err = mbtk_call_hang(info_handle); |
| 622 | if(err) { |
| 623 | printf("Error : %d\n", err); |
| 624 | } else { |
| 625 | printf("Call hang up all.\n"); |
| 626 | } |
| 627 | } else if(!strcasecmp(cmd, "hangup 0")) { |
| 628 | err = mbtk_waiting_or_background_call_hang(info_handle); |
| 629 | if(err) { |
| 630 | printf("Error : %d\n", err); |
| 631 | } else { |
| 632 | printf("Call hang up waiting or background.\n"); |
| 633 | } |
| 634 | } else if(!strcasecmp(cmd, "hangup 3")) { |
| 635 | err = mbtk_foreground_resume_background_call_hang(info_handle); |
| 636 | if(err) { |
| 637 | printf("Error : %d\n", err); |
| 638 | } else { |
| 639 | printf("Call hang up foreground resume background.\n"); |
| 640 | } |
| 641 | } else { |
| 642 | if(!strcasecmp(cmd, "hangup 1")) { // hang up a call |
| 643 | phone_id = 1; |
| 644 | } else if(!strcasecmp(cmd, "hangup 2")) { |
| 645 | phone_id = 2; |
| 646 | } else { |
| 647 | printf("Error : Invalid input\n"); |
| 648 | } |
| 649 | err = mbtk_a_call_hang(info_handle, phone_id); |
| 650 | if(err) { |
| 651 | printf("Error : %d\n", err); |
| 652 | } else { |
| 653 | printf("A Call hang up.\n"); |
| 654 | } |
| 655 | } |
| 656 | } else if(!strncasecmp(cmd, "waitin", 6)){ |
| 657 | mbtk_call_info_t reg; |
| 658 | err = mbtk_call_reg_get(info_handle, ®); |
| 659 | if(err) { |
| 660 | printf("Error : %d\n", err); |
| 661 | } else { |
| 662 | if(reg.call_wait == 0) { |
| 663 | printf("No call ring\n"); |
| 664 | } |
| 665 | else { |
| 666 | 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); |
| 667 | } |
| 668 | } |
| 669 | } else if(!strncasecmp(cmd, "mute", 4)){ // "mute" or "mute 0" or "mute 1" |
| 670 | int mute; |
| 671 | if(!strcasecmp(cmd, "mute")) { // Get |
| 672 | err = mbtk_mute_state_get(info_handle, &mute); |
| 673 | if(err) { |
| 674 | printf("Error : %d\n", err); |
| 675 | } else { |
| 676 | printf("mute : %d\n", mute); |
| 677 | } |
| 678 | } else { // Set |
| 679 | if(!strcasecmp(cmd, "mute 1")) { // on mute |
| 680 | mute = 1; |
| 681 | } else { // off mute |
| 682 | mute = 0; |
| 683 | } |
| 684 | err = mbtk_mute_state_set(info_handle, mute); |
| 685 | if(err) { |
| 686 | printf("Error : %d\n", err); |
| 687 | } else { |
| 688 | printf("mute set success\n"); |
| 689 | } |
| 690 | } |
| 691 | } else if(!strncasecmp(cmd, "DTMF", 4)){ // valid character: (0, 1, ..., 9, A, B, C, D, *, #) |
| 692 | |
| 693 | mbtk_call_dtmf_info_t reg; |
| 694 | |
| 695 | char *ptr = strstr(cmd, " "); |
| 696 | if(ptr == NULL) |
| 697 | continue; |
| 698 | while(*ptr != '\0' && *ptr == ' ') |
| 699 | ptr++; |
| 700 | reg.character = *ptr; |
| 701 | |
| 702 | ptr = strstr(ptr, " "); |
| 703 | if(ptr == NULL) |
| 704 | continue; |
| 705 | while(*ptr != '\0' && *ptr == ' ') |
| 706 | ptr++; |
| 707 | reg.duration = (uint32)atoi(ptr); |
| 708 | printf("DTMF character is: %c,%d\n",reg.character, reg.duration); |
| 709 | err = mbtk_dtmf_send(info_handle, ®); |
| 710 | if(err) { |
| 711 | printf("Error : %d\n", err); |
| 712 | } else { |
| 713 | printf("DTMF success.\n"); |
| 714 | } |
| 715 | } else if(!strncasecmp(cmd, "shutdown", 8)){ |
| 716 | if(!strcasecmp(cmd, "shutdown 0")) { |
| 717 | err = mbtk_system_reboot(0); |
| 718 | if(err) { |
| 719 | printf("Error : %d\n", err); |
| 720 | } else { |
| 721 | printf("Success.\n"); |
| 722 | } |
| 723 | } else if(!strcasecmp(cmd, "shutdown 1")) { |
| 724 | err = mbtk_system_reboot(1); |
| 725 | if(err) { |
| 726 | printf("Error : %d\n", err); |
| 727 | } else { |
| 728 | printf("Success.\n"); |
| 729 | } |
| 730 | } else if(!strcasecmp(cmd, "shutdown 2")) { |
| 731 | err = mbtk_system_reboot(2); |
| 732 | if(err) { |
| 733 | printf("Error : %d\n", err); |
| 734 | } else { |
| 735 | printf("Success.\n"); |
| 736 | } |
| 737 | } else { |
| 738 | printf("Error."); |
| 739 | } |
| 740 | } else if(!strncasecmp(cmd, "power_sim", 9)){ |
| 741 | if(!strcasecmp(cmd, "power_sim 0")) { |
| 742 | err = mbtk_sim_power_set(0); |
| 743 | if(err) { |
| 744 | printf("Error : %d\n", err); |
| 745 | } else { |
| 746 | printf("Success.\n"); |
| 747 | } |
| 748 | } else if(!strcasecmp(cmd, "power_sim 1")) { |
| 749 | err = mbtk_sim_power_set(1); |
| 750 | if(err) { |
| 751 | printf("Error : %d\n", err); |
| 752 | } else { |
| 753 | printf("Success.\n"); |
| 754 | } |
| 755 | } else { |
| 756 | printf("Error."); |
| 757 | } |
| 758 | } else if(!strncasecmp(cmd, "temp", 4)){ |
| 759 | int temp; |
| 760 | if(!strcasecmp(cmd, "temp 0")) { |
| 761 | err = mbtk_temp_get(info_handle, 0, &temp); |
| 762 | if(err) { |
| 763 | printf("Error : %d\n", err); |
| 764 | } else { |
| 765 | printf("SOC : %d\n", temp); |
| 766 | } |
| 767 | } else if(!strcasecmp(cmd, "temp 1")) { |
| 768 | err = mbtk_temp_get(info_handle, 1, &temp); |
| 769 | if(err) { |
| 770 | printf("Error : %d\n", err); |
| 771 | } else { |
| 772 | printf("RF : %d\n", temp); |
| 773 | } |
| 774 | } else { |
| 775 | printf("Error."); |
| 776 | } |
| 777 | } else if(!strncasecmp(cmd, "time", 4)){ |
| 778 | if(!strcasecmp(cmd, "time 0")) { |
| 779 | err = mbtk_time_set(info_handle, 0, NULL); |
| 780 | if(err) { |
| 781 | printf("Error : %d\n", err); |
| 782 | } else { |
| 783 | printf("Success.\n"); |
| 784 | } |
| 785 | } else if(!strcasecmp(cmd, "time 1")) { |
| 786 | err = mbtk_time_set(info_handle, 1, NULL); |
| 787 | if(err) { |
| 788 | printf("Error : %d\n", err); |
| 789 | } else { |
| 790 | printf("Success.\n"); |
| 791 | } |
| 792 | } else if(!strncasecmp(cmd, "time 2 ", 7)) { |
| 793 | err = mbtk_time_set(info_handle, 2, cmd + 7); |
| 794 | if(err) { |
| 795 | printf("Error : %d\n", err); |
| 796 | } else { |
| 797 | printf("Success.\n"); |
| 798 | } |
| 799 | } else { // Get time type. |
| 800 | int time_type; |
| 801 | err = mbtk_time_get(info_handle, &time_type); |
| 802 | if(err) { |
| 803 | printf("Error : %d\n", err); |
| 804 | } else { |
| 805 | printf("Time type:%d.\n", time_type); |
| 806 | } |
| 807 | } |
| 808 | } else if(!strncasecmp(cmd, "apn", 3)){ |
| 809 | if(!strcasecmp(cmd, "apn")) { // Get apn |
| 810 | #define APN_MAX 10 |
| 811 | mbtk_apn_info_t apns[APN_MAX]; |
| 812 | int apn_num = APN_MAX; |
| 813 | err = mbtk_apn_get(info_handle, &apn_num, apns); |
| 814 | if(err) { |
| 815 | printf("Error : %d\n", err); |
| 816 | } else { |
| 817 | printf("APN Num:%d\n", apn_num); |
| 818 | int i = 0; |
| 819 | while(i < apn_num) { |
| 820 | printf("APN : %d, %s, %s\n", apns[i].cid, apn2str(apns[i].ip_type), apns[i].apn); |
| 821 | i++; |
| 822 | } |
| 823 | } |
| 824 | } else { // apn <cid> <0/1/2/3> <apn> |
| 825 | char *ptr = strstr(cmd, " "); |
| 826 | if(ptr == NULL) |
| 827 | continue; |
| 828 | while(*ptr != '\0' && *ptr == ' ') |
| 829 | ptr++; |
| 830 | int cid = atoi(ptr); |
| 831 | |
| 832 | ptr = strstr(ptr, " "); |
| 833 | if(ptr == NULL) |
| 834 | continue; |
| 835 | while(*ptr != '\0' && *ptr == ' ') |
| 836 | ptr++; |
| 837 | mbtk_ip_type_enum ip_type = (mbtk_ip_type_enum)atoi(ptr); |
| 838 | |
| 839 | ptr = strstr(ptr, " "); |
| 840 | if(ptr == NULL) |
| 841 | continue; |
| 842 | while(*ptr != '\0' && *ptr == ' ') |
| 843 | ptr++; |
| 844 | char *apn = ptr; |
| 845 | |
| 846 | err = mbtk_apn_set(info_handle, cid, ip_type, apn, NULL, NULL, NULL); |
| 847 | if(err) { |
| 848 | printf("Error : %d\n", err); |
| 849 | } else { |
| 850 | printf("APN set success\n"); |
| 851 | } |
| 852 | } |
| 853 | } else if(!strncasecmp(cmd, "data_call", 9)){ // data_call <0/1/2> <cid> <timeout> |
| 854 | // data_call <0/1/2> <cid> <timeout> |
| 855 | char *ptr = strstr(cmd, " "); |
| 856 | if(ptr == NULL) |
| 857 | continue; |
| 858 | while(*ptr != '\0' && *ptr == ' ') |
| 859 | ptr++; |
| 860 | mbtk_data_call_type_enum type = (mbtk_data_call_type_enum)atoi(ptr); |
| 861 | |
| 862 | ptr = strstr(ptr, " "); |
| 863 | if(ptr == NULL) |
| 864 | continue; |
| 865 | while(*ptr != '\0' && *ptr == ' ') |
| 866 | ptr++; |
| 867 | int cid = atoi(ptr); |
| 868 | |
| 869 | ptr = strstr(ptr, " "); |
| 870 | if(ptr == NULL) |
| 871 | continue; |
| 872 | while(*ptr != '\0' && *ptr == ' ') |
| 873 | ptr++; |
| 874 | int timeout = atoi(ptr); |
| 875 | |
| 876 | if(type == MBTK_DATA_CALL_START) { |
| 877 | err = mbtk_data_call_start(info_handle, cid, 0, FALSE, timeout); |
| 878 | } else if(type == MBTK_DATA_CALL_STOP) { |
| 879 | err = mbtk_data_call_stop(info_handle, cid, timeout); |
| 880 | } else { |
| 881 | mbtk_ipv4_info_t ipv4; |
| 882 | mbtk_ipv6_info_t ipv6; |
| 883 | err = mbtk_data_call_state_get(info_handle, cid, &ipv4, &ipv6); |
| 884 | if(!err) { |
| 885 | if(ipv4.valid) { |
| 886 | // log_hex("IPv4", &ipv4, sizeof(mbtk_ipv4_info_t)); |
| 887 | char ip_tmp[20]; |
| 888 | |
| 889 | memset(ip_tmp, 0, 20); |
| 890 | if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip_tmp, 20) == NULL) { |
| 891 | printf("IP error.\n"); |
| 892 | } else { |
| 893 | printf("IP : %s\n", ip_tmp); |
| 894 | } |
| 895 | |
| 896 | memset(ip_tmp, 0, 20); |
| 897 | if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), ip_tmp, 20) == NULL) { |
| 898 | printf("PrimaryDNS error.\n"); |
| 899 | } else { |
| 900 | printf("PrimaryDNS : %s\n", ip_tmp); |
| 901 | } |
| 902 | |
| 903 | memset(ip_tmp, 0, 20); |
| 904 | if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), ip_tmp, 20) == NULL) { |
| 905 | printf("SecondaryDNS error.\n"); |
| 906 | } else { |
| 907 | printf("SecondaryDNS : %s\n", ip_tmp); |
| 908 | } |
| 909 | |
| 910 | memset(ip_tmp, 0, 20); |
| 911 | if(inet_ntop(AF_INET, &(ipv4.GateWay), ip_tmp, 20) == NULL) { |
| 912 | printf("GateWay error.\n"); |
| 913 | } else { |
| 914 | printf("GateWay : %s\n", ip_tmp); |
| 915 | } |
| 916 | |
| 917 | memset(ip_tmp, 0, 20); |
| 918 | if(inet_ntop(AF_INET, &(ipv4.NetMask), ip_tmp, 20) == NULL) { |
| 919 | printf("NetMask error.\n"); |
| 920 | } else { |
| 921 | printf("NetMask : %s\n", ip_tmp); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | if(ipv6.valid) { |
| 926 | // log_hex("IPv6", &ipv6, sizeof(mbtk_ipv6_info_t)); |
| 927 | char ip_tmp[50]; |
| 928 | |
| 929 | memset(ip_tmp, 0, 50); |
| 930 | if(ipv6_2_str(&(ipv6.IPV6Addr), ip_tmp)) { |
| 931 | printf("IP error.\n"); |
| 932 | } else { |
| 933 | printf("IP : %s\n", ip_tmp); |
| 934 | } |
| 935 | |
| 936 | memset(ip_tmp, 0, 50); |
| 937 | if(ipv6_2_str(&(ipv6.PrimaryDNS), ip_tmp)) { |
| 938 | printf("PrimaryDNS error.\n"); |
| 939 | } else { |
| 940 | printf("PrimaryDNS : %s\n", ip_tmp); |
| 941 | } |
| 942 | |
| 943 | memset(ip_tmp, 0, 50); |
| 944 | if(ipv6_2_str(&(ipv6.SecondaryDNS), ip_tmp)) { |
| 945 | printf("SecondaryDNS error.\n"); |
| 946 | } else { |
| 947 | printf("SecondaryDNS : %s\n", ip_tmp); |
| 948 | } |
| 949 | |
| 950 | memset(ip_tmp, 0, 50); |
| 951 | if(ipv6_2_str(&(ipv6.GateWay), ip_tmp)) { |
| 952 | printf("GateWay error.\n"); |
| 953 | } else { |
| 954 | printf("GateWay : %s\n", ip_tmp); |
| 955 | } |
| 956 | |
| 957 | memset(ip_tmp, 0, 50); |
| 958 | if(ipv6_2_str(&(ipv6.NetMask), ip_tmp)) { |
| 959 | printf("NetMask error.\n"); |
| 960 | } else { |
| 961 | printf("NetMask : %s\n", ip_tmp); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | if(err) { |
| 967 | printf("Error : %d\n", err); |
| 968 | } else { |
| 969 | printf("DATA_CALL success\n"); |
| 970 | } |
| 971 | }else if(!strncasecmp(cmd, "cmgf", 4)){ // set mode 0: pud, 1:text |
| 972 | int mode; |
| 973 | if(!strcasecmp(cmd, "cmgf")) { // Get |
| 974 | err = mbtk_sms_cmgf_get(info_handle, &mode); |
| 975 | if(err) { |
| 976 | printf("Error : %d\n", err); |
| 977 | } else { |
| 978 | printf("VoLTE : %d\n", mode); |
| 979 | } |
| 980 | } else { // Set |
| 981 | if(!strcasecmp(cmd, "cmgf 1")) { // cmgf 1 |
| 982 | mode = 1; |
| 983 | } else { // |
| 984 | mode = 0; |
| 985 | } |
| 986 | printf("mode:%d\n", mode); |
| 987 | sleep(2); |
| 988 | err = mbtk_sms_cmgf_set(info_handle, mode); |
| 989 | if(err) { |
| 990 | printf("Error : %d\n", err); |
| 991 | } else { |
| 992 | printf("VoLTE set success\n"); |
| 993 | } |
| 994 | } |
| 995 | }else if(!strncasecmp(cmd, "cpms", 4)){ // //CPMS=ME, ME, ME |
| 996 | char mem[100] = {0}; |
| 997 | char resp[100] = {0}; |
| 998 | if(!strcasecmp(cmd, "cpms")) { // Get |
| 999 | err = mbtk_sms_cpms_get(info_handle, &mem); |
| 1000 | if(err) { |
| 1001 | printf("Error : %d\n", err); |
| 1002 | } else { |
| 1003 | printf("cpms : %s\n", mem); |
| 1004 | } |
| 1005 | } else { // Set |
| 1006 | |
| 1007 | char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME |
| 1008 | if(ptr != NULL) |
| 1009 | { |
| 1010 | ptr++; |
| 1011 | memset(mem, 0, sizeof(mem)); |
| 1012 | memcpy(mem, ptr, strlen(ptr)); |
| 1013 | printf("cpms:%s\n", mem); |
| 1014 | } |
| 1015 | printf("cpms 0\n"); |
| 1016 | |
| 1017 | memset(resp, 0, sizeof(resp)); |
| 1018 | err = mbtk_sms_cpms_set(info_handle, mem, resp); |
| 1019 | if(err) { |
| 1020 | printf("Error : %d\n", err); |
| 1021 | } else { |
| 1022 | printf("cpms set success. resp:%s\n", resp); |
| 1023 | } |
| 1024 | } |
| 1025 | }else if(!strncasecmp(cmd, "cmgs", 4)){ // AT+CMGS="10086", CMGS TEST |
| 1026 | char cmgs[1024] = {0}; |
| 1027 | char resp[50] = {0}; |
| 1028 | if(!strcasecmp(cmd, "cmgs")) { // Get |
| 1029 | int mode; |
| 1030 | // err = mbtk_sms_cmgs_get(info_handle, &mode); |
| 1031 | if(err) { |
| 1032 | printf("Error : %d\n", err); |
| 1033 | } else { |
| 1034 | printf("VoLTE : %d\n", mode); |
| 1035 | } |
| 1036 | } else { // Set |
| 1037 | |
| 1038 | /* |
| 1039 | *AT+CMGS="10086", CMGS TEST // Send a SMS |
| 1040 | > CMGS TEST |
| 1041 | +CMGS: 17 |
| 1042 | OK |
| 1043 | */ |
| 1044 | |
| 1045 | char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf |
| 1046 | if(ptr != NULL) |
| 1047 | { |
| 1048 | ptr = strstr(cmd, ","); |
| 1049 | ptr++; |
| 1050 | memset(cmgs, 0, sizeof(cmgs)); |
| 1051 | memcpy(cmgs, ptr, strlen(ptr)); |
| 1052 | printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs)); |
| 1053 | } |
| 1054 | |
| 1055 | memset(resp, 0, sizeof(resp)); |
| 1056 | err = mbtk_sms_cmgs_set(info_handle, cmgs, resp); |
| 1057 | if(err) { |
| 1058 | printf("Error : %d\n", err); |
| 1059 | } else { |
| 1060 | printf("cmgs set success . resp:%s\n", resp); |
| 1061 | } |
| 1062 | } |
| 1063 | }else if(!strncasecmp(cmd, "cmss", 4)){ // +CMSS=<index>[,<da>[,<toda>]] |
| 1064 | char cmss[20] = {0}; |
| 1065 | char resp[20] = {0}; |
| 1066 | if(!strcasecmp(cmd, "cmgs")) { // Get |
| 1067 | printf("cmss : OK\n"); |
| 1068 | |
| 1069 | } else { |
| 1070 | char *ptr = strstr(cmd, "cmss,"); //CMSS=<index> |
| 1071 | if(ptr != NULL) |
| 1072 | { |
| 1073 | ptr = strstr(cmd, ","); |
| 1074 | ptr++; |
| 1075 | memset(cmss, 0, sizeof(cmss)); |
| 1076 | memcpy(cmss, ptr, strlen(ptr)); |
| 1077 | printf("1cmss:%s\n", cmss); |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | err = mbtk_sms_cmss_set(info_handle, cmss, resp); |
| 1082 | if(err) { |
| 1083 | printf("Error : %d\n", err); |
| 1084 | } else { |
| 1085 | printf("cmss set success. resp:%s\n", resp); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | else if(!strncasecmp(cmd, "cmgr", 4)){ // +CMGR=<index |
| 1090 | int index = 0; |
| 1091 | char resp[1024] = {0}; |
| 1092 | if(!strcasecmp(cmd, "cmgr")) { // Get |
| 1093 | printf("cmgr : OK\n"); |
| 1094 | |
| 1095 | } else { |
| 1096 | char *ptr = strstr(cmd, "cmgr,"); //+CMGR <index> |
| 1097 | if(ptr != NULL) |
| 1098 | { |
| 1099 | ptr = strstr(cmd, ","); |
| 1100 | ptr++; |
| 1101 | index = atoi(ptr); |
| 1102 | } |
| 1103 | printf("1index:%d\n", index); |
| 1104 | |
| 1105 | memset(resp, 0, sizeof(resp)); |
| 1106 | err = mbtk_sms_cmgr_set(info_handle, index, resp); |
| 1107 | if(err) { |
| 1108 | printf("Error : %d\n", err); |
| 1109 | } else { |
| 1110 | printf("cmgr set success. rep:%s\n", resp); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | else if(!strncasecmp(cmd, "cmgw", 4)){ // +CMGW=<oa/da>[,<tooa/toda>[,<stat>]]<CR> |
| 1115 | //+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC> |
| 1116 | char cmgw[128] = {0}; |
| 1117 | char resp[50] = {0}; |
| 1118 | if(!strcasecmp(cmd, "cmgw")) { // Get |
| 1119 | printf("cmgw : OK\n"); |
| 1120 | |
| 1121 | } else { |
| 1122 | char *ptr = strstr(cmd, "cmgw,"); //+CMGW, <oa/da>, data |
| 1123 | if(ptr != NULL) |
| 1124 | { |
| 1125 | ptr = strstr(cmd, ","); |
| 1126 | ptr++; |
| 1127 | memset(cmgw, 0, sizeof(cmgw)); |
| 1128 | memcpy(cmgw, ptr, strlen(ptr)); |
| 1129 | printf("cmgw:%s\n", cmgw); |
| 1130 | } |
| 1131 | |
| 1132 | memset(resp, 0, sizeof(resp)); |
| 1133 | err = mbtk_sms_cmgw_set(info_handle, cmgw, resp); |
| 1134 | if(err) { |
| 1135 | printf("Error : %d\n", err); |
| 1136 | } else { |
| 1137 | printf("cmgw set success. resp:%s\n", resp); |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | else if(!strncasecmp(cmd, "cmgd", 4)){ // +CMGD=<index>[,<delflag> |
| 1142 | // |
| 1143 | char cmgd[128] = {0}; |
| 1144 | if(!strcasecmp(cmd, "cmgd")) { // Get |
| 1145 | printf("cmgd : OK\n"); |
| 1146 | |
| 1147 | } else { |
| 1148 | char *ptr = strstr(cmd, ","); //+CMGD=<index>[,<delflag> |
| 1149 | if(ptr != NULL) |
| 1150 | { |
| 1151 | ptr++; |
| 1152 | memset(cmgd, 0, sizeof(cmgd)); |
| 1153 | memcpy(cmgd, ptr, strlen(ptr)); |
| 1154 | printf("1cmgd:%s\n", cmgd); |
| 1155 | } |
| 1156 | |
| 1157 | |
| 1158 | err = mbtk_sms_cmgd_set(info_handle, cmgd); |
| 1159 | if(err) { |
| 1160 | printf("Error : %d\n", err); |
| 1161 | } else { |
| 1162 | printf("VoLTE set success\n"); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | else if(!strncasecmp(cmd, "cmgl", 4)){ // AT+CMGL[=<stat>] |
| 1167 | // |
| 1168 | char cmgl[128] = {0}; |
| 1169 | char resp[5*1024] ={0}; |
| 1170 | if(!strcasecmp(cmd, "cmgl")) { // Get |
| 1171 | printf("cmgl : OK\n"); |
| 1172 | |
| 1173 | } else { |
| 1174 | char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>] |
| 1175 | if(ptr != NULL) |
| 1176 | { |
| 1177 | ptr = strstr(cmd, ","); |
| 1178 | ptr++; |
| 1179 | memset(cmgl, 0, sizeof(cmgl)); |
| 1180 | memcpy(cmgl, ptr, strlen(ptr)); |
| 1181 | printf("0cmgl:%s\n", cmgl); |
| 1182 | } |
| 1183 | |
| 1184 | memset(resp, 0, sizeof(resp)); |
| 1185 | err = mbtk_sms_cmgl_set(info_handle, cmgl, resp); |
| 1186 | if(err) { |
| 1187 | printf("Error : %d\n", err); |
| 1188 | } else { |
| 1189 | // printf("cmgl set success, reg:%s\n",resp); |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | else if(!strncasecmp(cmd, "csca", 4)){ // AT+CSCA=<number> [,<type>] |
| 1194 | // |
| 1195 | char csca[128] = {0}; |
| 1196 | if(!strcasecmp(cmd, "csca")) { // Get |
| 1197 | err = mbtk_sms_csca_get(info_handle, csca); |
| 1198 | if(err) { |
| 1199 | printf("mbtk_sms_csca_get Error : %d\n", err); |
| 1200 | } else { |
| 1201 | printf("mbtk_sms_csca_get success\n"); |
| 1202 | } |
| 1203 | |
| 1204 | } else { |
| 1205 | char *ptr = strstr(cmd, ","); // AT+CSCA=<number> [,<type>] |
| 1206 | if(ptr != NULL) |
| 1207 | { |
| 1208 | ptr++; |
| 1209 | memset(csca, 0, sizeof(csca)); |
| 1210 | memcpy(csca, ptr, strlen(ptr)); |
| 1211 | printf("csca:%s\n", csca); |
| 1212 | } |
| 1213 | |
| 1214 | err = mbtk_sms_csca_set(info_handle, csca); |
| 1215 | if(err) { |
| 1216 | printf("Error : %d\n", err); |
| 1217 | } else { |
| 1218 | printf("VoLTE set success\n"); |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | else if(!strncasecmp(cmd, "csmp", 4)){ // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]] |
| 1223 | // |
| 1224 | char csmp[128] = {0}; |
| 1225 | if(!strcasecmp(cmd, "csmp")) { // Get |
| 1226 | printf("cmgl : OK\n"); |
| 1227 | |
| 1228 | } else { |
| 1229 | char *ptr = strstr(cmd, ","); // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]] |
| 1230 | if(ptr != NULL) |
| 1231 | { |
| 1232 | ptr++; |
| 1233 | memset(csmp, 0, sizeof(csmp)); |
| 1234 | memcpy(csmp, ptr, strlen(ptr)); |
| 1235 | printf("csmp:%s\n", csmp); |
| 1236 | } |
| 1237 | |
| 1238 | err = mbtk_sms_csmp_set(info_handle, csmp); |
| 1239 | if(err) { |
| 1240 | printf("Error : %d\n", err); |
| 1241 | } else { |
| 1242 | printf("VoLTE set success\n"); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | else if(!strncasecmp(cmd, "cscb", 4)){ // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]> |
| 1247 | // |
| 1248 | char cscb[128] = {0}; |
| 1249 | if(!strcasecmp(cmd, "cscb")) { // Get |
| 1250 | printf("cmgl : OK\n"); |
| 1251 | |
| 1252 | } else { |
| 1253 | char *ptr = strstr(cmd, ","); // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]> |
| 1254 | if(ptr != NULL) |
| 1255 | { |
| 1256 | ptr++; |
| 1257 | memset(cscb, 0, sizeof(cscb)); |
| 1258 | memcpy(cscb, ptr, strlen(ptr)); |
| 1259 | printf("cscb:%s\n", cscb); |
| 1260 | } |
| 1261 | |
| 1262 | err = mbtk_sms_cscb_set(info_handle, cscb); |
| 1263 | if(err) { |
| 1264 | printf("Error : %d\n", err); |
| 1265 | } else { |
| 1266 | printf("VoLTE set success\n"); |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) { |
| 1271 | help(); |
| 1272 | } else if(!strcasecmp(cmd, "q")) { |
| 1273 | mbtk_info_handle_free(&info_handle); |
| 1274 | break; |
| 1275 | } else { |
| 1276 | printf("\n"); |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | LOG("Client exec complete."); |
| 1282 | #if 1 |
| 1283 | while(1) |
| 1284 | { |
| 1285 | sleep(1000 * 365 * 24 * 60 * 60); |
| 1286 | } |
| 1287 | #else |
| 1288 | sleep(1); |
| 1289 | #endif |
| 1290 | return 0; |
| 1291 | } |