/* Comment ******************************************************************** * KNI 모듈의 APN을 설정하는 함수입니다. * 설정하는 APN type 정해지지 않으면, * at+sysinfo 명령을 통해 네트워크를 검색 후 default 값으로 설정하도록 합니다. * */ int set_kmkl200_apn (int type, char *apn_url) { enum { KNI_DUMMY_CMD= 0, KNI_APN_KT_CMD, KNI_APN_SKT_CMD }; char *pCmd[] = {"at", "AT+CGDCONT=1,\"IP\",\"privatelte.ktfwing.com\",\"0.0.0.0\",0,0", "AT+CGDCONT=1,\"IP\",\"lte-internet.sktelecom.com\",\"0.0.0.0\",0,0", NULL}; char buf[LTE_BUF_LENGTH+1] = {0}; char buf_temp[LTE_BUF_LENGTH+1] = {0}; char cmd_buf[LTE_BUF_LENGTH+1] = {0}; char *pbuf = buf; char *pbuf_temp = buf_temp; int read_bytes = 0; int value = 0; // dummy read memset(pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial(pCmd[KNI_DUMMY_CMD], pbuf); // dummy read memset(pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial(pCmd[KNI_DUMMY_CMD], pbuf); // disable echo memset(pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial("ate0", pbuf); // find network name (KT or SKT) if (type == APN_TYPE_DEFAULT) { memset (pbuf, 0x00, LTE_BUF_LENGTH); memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial ("at+sysinfo", pbuf); if (read_bytes > 0) { // sysinfo 의 8번째 값을 가지고 판단한다. lte_strtok(pbuf, read_bytes, 8, pbuf_temp); value = pal_atoi(pbuf_temp); if (value == 5) type = APN_TYPE_SKT; else if (value == 8) type = APN_TYPE_KT; else type = APN_TYPE_NONE; } } if (type == APN_TYPE_KT) { // APN command memset(pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial(pCmd[KNI_APN_KT_CMD], pbuf); DBG("%s \r\n", pbuf); if (read_bytes > 0) { if (lte_lookup_string_from_buf(pbuf, read_bytes, "OK") == LTE_ERROR) return LTE_ERROR; } } else if (type == APN_TYPE_SKT) { // APN command memset(pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial(pCmd[KNI_APN_SKT_CMD], pbuf); DBG("%s \r\n", pbuf); if (read_bytes > 0) { if (lte_lookup_string_from_buf(pbuf, read_bytes, "OK") == LTE_ERROR) return LTE_ERROR; } } else if (type == APN_TYPE_USER) { memset(pbuf, 0x00, LTE_BUF_LENGTH); memset(cmd_buf, 0x00, LTE_BUF_LENGTH); snprintf (cmd_buf, LTE_BUF_LENGTH, "AT+CGDCONT=1,\"IP\",\"%s\",\"0.0.0.0\",0,0", apn_url); read_bytes = lte_xmit_serial(cmd_buf, pbuf); DBG("apn_url : %s \r\n", apn_url); DBG("CMD : %s \r\n", cmd_buf); DBG("pbuf : %s \r\n", pbuf); if (read_bytes > 0) { if (lte_lookup_string_from_buf(pbuf, read_bytes, "OK") == LTE_ERROR) return LTE_ERROR; } } return LTE_OK; }
APP_RET_E app_parse_cmd_line( APP_CTXT_X *px_app_ctxt, int i_argc, char **ppuc_argv) { APP_RET_E e_main_ret = eAPP_RET_FAILURE; PAL_RET_E e_pal_ret = ePAL_RET_FAILURE; int32_t i_temp = 0; if ((NULL == px_app_ctxt) || (NULL == ppuc_argv) || (0 == i_argc)) { e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } if (i_argc < 7) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } if ((NULL == ppuc_argv [1]) || (NULL == ppuc_argv [2]) || (NULL == ppuc_argv [3]) || (NULL == ppuc_argv [4]) || (NULL == ppuc_argv [5]) || (NULL == ppuc_argv [6])) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } e_pal_ret = pal_atoi((uint8_t *) ppuc_argv[1], (int32_t *) &(px_app_ctxt->x_app_args.ui_no_nodes)); if (ePAL_RET_SUCCESS != e_pal_ret) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } e_pal_ret = pal_atoi((uint8_t *) ppuc_argv[2], (int32_t *) &(px_app_ctxt->x_app_args.ui_node_index)); if (ePAL_RET_SUCCESS != e_pal_ret) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } e_pal_ret = pal_atoi ((uint8_t *) ppuc_argv [3], &(i_temp)); if ((ePAL_RET_SUCCESS != e_pal_ret) || (i_temp > USHRT_MAX)) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } px_app_ctxt->x_app_args.us_listen_port_start_ho = (uint16_t) i_temp; (void) pal_strncpy (px_app_ctxt->x_app_args.uca_leader_hostname, (const uint8_t *) ppuc_argv [4], sizeof(px_app_ctxt->x_app_args.uca_leader_hostname)); e_pal_ret = pal_atoi ((uint8_t *) ppuc_argv [5], (int32_t *) &(px_app_ctxt->x_app_args.ui_unit_time_ms)); if (ePAL_RET_SUCCESS != e_pal_ret) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } e_pal_ret = pal_atoi ((uint8_t *) ppuc_argv [6], (int32_t *) &(px_app_ctxt->x_app_args.ui_enable_console_logging)); if (ePAL_RET_SUCCESS != e_pal_ret) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } if ((8 == i_argc) && (NULL != ppuc_argv[7])) { e_pal_ret = pal_atoi ((uint8_t *) ppuc_argv [7], &(i_temp)); if ((ePAL_RET_SUCCESS != e_pal_ret) || (i_temp > USHRT_MAX)) { app_print_usage (i_argc, ppuc_argv); e_main_ret = eAPP_RET_FAILURE; goto CLEAN_RETURN; } px_app_ctxt->x_app_args.us_app_internal_port_ho = (uint16_t) i_temp; } printf ("User Entered:\n" "\tTotal Nodes : %d\n" "\tThis Node Index : %d\n" "\tListen Port Range Start : %d\n" "\tLeader Host Name : %s\n" "\tUnit Time : %d\n" "\tEnable Console Logging : %d\n" "\tPort For Internal Use : %d\n", px_app_ctxt->x_app_args.ui_no_nodes, px_app_ctxt->x_app_args.ui_node_index, px_app_ctxt->x_app_args.us_listen_port_start_ho, px_app_ctxt->x_app_args.uca_leader_hostname, px_app_ctxt->x_app_args.ui_unit_time_ms, px_app_ctxt->x_app_args.ui_enable_console_logging, px_app_ctxt->x_app_args.us_app_internal_port_ho); printf ("\n\nEnter 1 to Quit Application\n\n"); e_main_ret = eAPP_RET_SUCCESS; CLEAN_RETURN: return e_main_ret; }
/* Comment ******************************************************************** * Kernel-I 모듈의 정보를 읽어옵니다. * */ void get_kmkl200_status(ZEBOS_LTE_MODULE_t *mod) { enum { KNI_DUMMY_CMD= 0, KNI_ATE0_CMD, KNI_SYSINFO_CMD, KNI_CGMR_CMD, KNI_CNUM_CMD, KNI_GSN_CMD }; char *pCmd[] = {"at", "ate0", "at+sysinfo", "at+cgmr", "at+cnum", "at+gsn", NULL}; enum { KNI_DUMMY= 0, KNI_SRV_STATUS, KNI_SYS_MODE, KNI_ROAM_STATUS, KNI_SIM_STATUS, KNI_VOICE_DOMAIN, KNI_SMS_DOMAIN, KNI_MCC, KNI_MNC, KNI_BAND, KNI_CHANNEL, KNI_RSSI, KNI_RSCP, KNI_BIT_ERR_RATE, KNI_ECIO, KNI_RSRP, KNI_RSRQ, KNI_LAC, KNI_LTE_TAC, KNI_LTE_RAC, KNI_CELL_ID, KNI_EMM_STATE, KNI_EMM_SUBSTATE, KNI_EMM_CONNECTION_STATE, KNI_REG_CAUSE, KNI_TIN, KNI_RRC_ACTIVE, }; int list_max = (sizeof(kni_state_list)/sizeof(LTE_STATE)); char buf[LTE_BUF_LENGTH+10] = {0}; char buf_copy[LTE_BUF_LENGTH+10] = {0}; char buf_temp[LTE_BUF_LENGTH+10] = {0}; char *pbuf = buf; char *pbuf_copy = buf_copy; char *pbuf_temp = buf_temp; int read_bytes = 0; int value = 0; int i = 0; // dummy read memset (pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial(pCmd[KNI_DUMMY_CMD], pbuf); // dummy read memset (pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial (pCmd[KNI_DUMMY_CMD], pbuf); // 모뎀으로 부터의 echo를 제거합니다. memset (pbuf, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial (pCmd[KNI_ATE0_CMD], pbuf); memset (pbuf, 0x00, LTE_BUF_LENGTH); memset (pbuf_copy, 0x00, LTE_BUF_LENGTH); memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial (pCmd[KNI_SYSINFO_CMD], pbuf); if (read_bytes > 0) { memcpy(pbuf_copy, pbuf, read_bytes); pbuf_copy[LTE_BUF_LENGTH-1] = '\0'; memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); lte_strtok(pbuf_copy, read_bytes, KNI_SRV_STATUS, pbuf_temp); mod->state = pal_atoi(pbuf_temp); for (i = 0; i < list_max; i++) { DBG ("@ %d / %d\n", mod->state , kni_state_list[i].state ); if (kni_state_list[i].state == mod->state) { snprintf(mod->state_name, sizeof(mod->state_name), "%s", kni_state_list[i].name); break; } } // netork type memcpy(pbuf_copy, pbuf, read_bytes); pbuf_copy[LTE_BUF_LENGTH-1] = '\0'; memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); lte_strtok(pbuf_copy, read_bytes, KNI_SYS_MODE, pbuf_temp); value = pal_atoi(pbuf_temp); if (value == 5) snprintf(mod->type, sizeof(mod->type), "%s", "WCDMA"); else if (value == 9) snprintf(mod->type, sizeof(mod->type), "%s", "LTE"); else snprintf(mod->type, sizeof(mod->type), "%s", "NONE"); // netork name memcpy(pbuf_copy, pbuf, read_bytes); pbuf_copy[LTE_BUF_LENGTH-1] = '\0'; memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); lte_strtok(pbuf_copy, read_bytes, KNI_MNC, pbuf_temp); value = pal_atoi(pbuf_temp); if (value == 5) snprintf(mod->name, sizeof(mod->name), "%s", "SKT"); else if (value == 8) snprintf(mod->name, sizeof(mod->name), "%s", "KT"); else snprintf(mod->name, sizeof(mod->name), "%s", "NONE"); // rssi memcpy(pbuf_copy, pbuf, read_bytes); pbuf_copy[LTE_BUF_LENGTH-1] = '\0'; memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); lte_strtok(pbuf_copy, read_bytes, KNI_RSSI, pbuf_temp); mod->rssi = pal_atoi(pbuf_temp); // rsrp memcpy(pbuf_copy, pbuf, read_bytes); pbuf_copy[LTE_BUF_LENGTH-1] = '\0'; memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); lte_strtok(pbuf_copy, read_bytes, KNI_RSRP, pbuf_temp); mod->rsrp = pal_atoi(pbuf_temp); // rsrq memcpy(pbuf_copy, pbuf, read_bytes); pbuf_copy[LTE_BUF_LENGTH-1] = '\0'; memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); lte_strtok(pbuf_copy, read_bytes, KNI_RSRQ, pbuf_temp); mod->rsrq = pal_atoi(pbuf_temp); // Ant level area // | -128 ~ -100 | -100 ~ -94 | -93 ~ -87 | -86 ~ 80 | -80 ~ | // | 0 | 1 | 2 | 3 | 4 | if (mod->rsrp < -100) mod->level = 0; else if (mod->rsrp < -94) mod->level = 25; else if (mod->rsrp < -87) mod->level = 50; else if (mod->rsrp < -80) mod->level = 75; else if (mod->rsrp >= -80) mod->level = 100; else mod->level = 0; } // module info memset (pbuf, 0x00, LTE_BUF_LENGTH); memset (pbuf_copy, 0x00, LTE_BUF_LENGTH); memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial (pCmd[KNI_CGMR_CMD], pbuf); if (read_bytes > 0) lte_strtok(pbuf, read_bytes, KNI_CGMR_INDEX, mod->info); // number memset (pbuf, 0x00, LTE_BUF_LENGTH); memset (pbuf_copy, 0x00, LTE_BUF_LENGTH); memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial (pCmd[KNI_CNUM_CMD], pbuf); if (read_bytes > 0) { // KT의 경우 전화번호 Index가 차이가 있습니다. if (strncmp(mod->name, "SKT", 3) ==0) lte_strtok(pbuf, read_bytes, KNI_CNUM_INDEX, mod->number); else if (strncmp(mod->name, "KT", 2) ==0) lte_strtok(pbuf, read_bytes, KNI_CNUM_INDEX + 2, mod->number); } // imei memset (pbuf, 0x00, LTE_BUF_LENGTH); memset (pbuf_copy, 0x00, LTE_BUF_LENGTH); memset (pbuf_temp, 0x00, LTE_BUF_LENGTH); read_bytes = lte_xmit_serial (pCmd[KNI_GSN_CMD], pbuf); if (read_bytes > 0) lte_strtok(pbuf, read_bytes, KNI_IMEI_INDEX, mod->imei); if (strncmp(mod->name, "KT", 2) == 0) { memset(mod->manufacturer, 0x00, sizeof(mod->manufacturer)); memcpy(mod->manufacturer, "Kernel-I", strlen("Kernel-I")); } }