693 u32_t stat_rx_or_tx_cnt;
694 u32_t stat_rx_or_tx_bytes;
699 struct netif *netiftmp = NULL;
700#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
712 PRINTK(
"%s: tcpip_init have not been called\n", __FUNCTION__);
743 if (strcmp(
"-a", argv[0]) == 0) {
745 stat_rx_or_tx_cnt = lwip_stats.ip.recv;
746 stat_err_cnt = (u32_t)(lwip_stats.ip.ip_rx_err +
747 lwip_stats.ip.lenerr +
748 lwip_stats.ip.chkerr +
749 lwip_stats.ip.opterr +
750 lwip_stats.ip.proterr);
751 stat_drop_cnt = (u32_t)(lwip_stats.ip.drop + lwip_stats.link.link_rx_drop);
752 stat_rx_or_tx_bytes = lwip_stats.ip.ip_rx_bytes;
754 PRINTK(
"%18s:%u\t errors:%u\t ip dropped:%u\t link dropped:%u\t overrun:%d\t bytes:%u ",
759 lwip_stats.link.link_rx_drop,
760 lwip_stats.ip.link_rx_overrun,
761 stat_rx_or_tx_bytes);
766 stat_rx_or_tx_cnt = lwip_stats.ip6.recv;
767 stat_err_cnt = (u32_t)(lwip_stats.ip6.ip_rx_err +
768 lwip_stats.ip6.lenerr +
769 lwip_stats.ip6.chkerr +
770 lwip_stats.ip6.opterr +
771 lwip_stats.ip6.proterr);
772 stat_drop_cnt = lwip_stats.ip6.drop;
773 stat_rx_or_tx_bytes = lwip_stats.ip6.ip_rx_bytes;
775 PRINTK(
"%18s:%u\t errors:%u\t dropped:%u\t overrun:%d\t bytes:%u ",
780 lwip_stats.ip.link_rx_overrun,
781 stat_rx_or_tx_bytes);
786 stat_rx_or_tx_cnt = (u32_t)(lwip_stats.ip.fw + lwip_stats.ip.xmit);
787 stat_err_cnt = (u32_t)(lwip_stats.ip.rterr + lwip_stats.ip.ip_tx_err);
789 stat_drop_cnt = lwip_stats.link.link_tx_drop;
790 stat_rx_or_tx_bytes = lwip_stats.ip.ip_tx_bytes;
792 PRINTK(
"%18s:%u\t errors:%u\t link dropped:%u\t overrun:0\t bytes:%u",
797 stat_rx_or_tx_bytes);
802 stat_rx_or_tx_cnt = (u32_t)(lwip_stats.ip6.fw + lwip_stats.ip6.xmit);
803 stat_err_cnt = (u32_t)(lwip_stats.ip6.rterr + lwip_stats.ip6.ip_tx_err);
804 stat_rx_or_tx_bytes = lwip_stats.ip6.ip_tx_bytes;
806 PRINTK(
"%18s:%u\t errors:%u\t overrun:0\t bytes:%u",
810 stat_rx_or_tx_bytes);
819 (
void)memset_s(&ifconfig_cmd,
sizeof(ifconfig_cmd), 0,
sizeof(ifconfig_cmd));
820 if (
sys_sem_new(&ifconfig_cmd.cb_completed, 0) != ERR_OK) {
821 PRINTK(
"%s: sys_sem_new fail\n", __FUNCTION__);
828 if (strlen(argv[i]) < IFNAMSIZ) {
829 if (strncpy_s(ifconfig_cmd.iface, IFNAMSIZ, argv[i], (strlen(argv[i]))) != EOK) {
831 PRINTK(
"ifconfig : strncpy_s error\n");
834 ifconfig_cmd.iface[IFNAMSIZ - 1] =
'\0';
837 PRINTK(
"ifconfig : interface name is too big\n");
847 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
852 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
853 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
861 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
866 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
867 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
873 if (strcmp(
"up", argv[i]) == 0) {
874 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_UP;
879 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
884 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
885 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
887 }
else if (strcmp(
"down", argv[i]) == 0) {
888 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_DOWN;
893 PRINTK(
"ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
898 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
899 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
905 if (netiftmp == NULL) {
907 PRINTK(
"ifconfig : Interface %s not found\n", ifconfig_cmd.iface);
910#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
911 old_ip4addr = ipaddr_addr(ipaddr_ntoa(&netiftmp->ip_addr));
914 if (!strcmp(argv[i],
"inet") || ip4addr_aton(argv[i], ip_2_ip4(&ifconfig_cmd.ip_addr))) {
915 if (!strcmp(argv[i],
"inet")) {
921 if (!ip4addr_aton(argv[i + 1], ip_2_ip4(&ifconfig_cmd.ip_addr))) {
923 PRINTK(
"ifconfig : Invalid IPv4 Address\n");
929 IP_SET_TYPE_VAL((ifconfig_cmd.ip_addr), IPADDR_TYPE_V4);
931 if (!ip_addr_cmp(&ifconfig_cmd.ip_addr, &netiftmp->ip_addr)) {
932 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_IP;
935 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_IP;
939 }
else if (!strcmp(argv[i],
"inet6")) {
944 if (strcmp(argv[i + 1],
"add") && strcmp(argv[i + 1],
"del")) {
949 if (!
ip6addr_aton(argv[i + 2], ip_2_ip6(&ifconfig_cmd.ip_addr))) {
951 PRINTK(
"ifconfig : Invalid IPv6 Address\n");
955 IP_SET_TYPE_VAL((ifconfig_cmd.ip_addr), IPADDR_TYPE_V6);
956 ifconfig_cmd.option |= (!strcmp(argv[i + 1],
"add") ? IFCONFIG_OPTION_SET_IP : IFCONFIG_OPTION_DEL_IP);
961 if (ifconfig_cmd.option & IFCONFIG_OPTION_DEL_IP) {
969 if (strcmp(
"netmask", argv[i]) == 0 && (argc > 1) && (ipaddr_addr(argv[i + 1]) != IPADDR_NONE)) {
971 ip_addr_set_ip4_u32_val((ifconfig_cmd.netmask), ipaddr_addr(argv[i + 1]));
972 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_NETMASK;
975 }
else if (strcmp(
"gateway", argv[i]) == 0 && (argc > 1) && (ipaddr_addr(argv[i + 1]) != IPADDR_NONE)) {
977 ip_addr_set_ip4_u32_val((ifconfig_cmd.gw), ipaddr_addr(argv[i + 1]));
978 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_GW;
981 }
else if (strcmp(
"hw", argv[i]) == 0 && argc > 2 && strcmp(
"ether", argv[i + 1]) == 0) {
984 u32_t macaddrlen = strlen(argv[i + 2]) + 1;
985 char tmpStr[MAX_MACADDR_STRING_LENGTH];
986 char *tmpStr1 = NULL;
987 char *saveptr = NULL;
990 if (macaddrlen != MAX_MACADDR_STRING_LENGTH) {
992 PRINTK(
"ifconfig : wrong MAC address format\n");
996 if (strncpy_s(tmpStr, MAX_MACADDR_STRING_LENGTH, argv[i + 2], macaddrlen - 1) != 0) {
998 PRINTK(
"ifconfig : wrong MAC address\n");
1001 for (j = 0, tmpStr1 = tmpStr; j < 6; j++, tmpStr1 = NULL) {
1002 digit = strtok_r(tmpStr1,
":", &saveptr);
1003 if ((digit == NULL) || (strlen(digit) > 2)) {
1005 PRINTK(
"ifconfig : wrong MAC address format\n");
1008 CONVERT_STRING_TO_HEX(digit, ifconfig_cmd.ethaddr[j]);
1010 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_HW;
1013 }
else if (!strcmp(
"mtu", argv[i]) && (argc > 1)) {
1015 if ((atoi(argv[i + 1]) < 0) || (atoi(argv[i + 1]) > 0xFFFF)) {
1017 PRINTK(
"\nifconfig: Invalid argument for mtu\n");
1018 goto ifconfig_error;
1021 ifconfig_cmd.mtu = (u16_t)(atoi(argv[i + 1]));
1022 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_MTU;
1027 goto ifconfig_error;
1031#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
1032 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
1036 PRINTK(
"ifconfig: internal error\n");
1044 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL((ifconfig_cmd.ip_addr))) {
1048 PRINTK(
"ifconfig: internal error\n");
1056 if (ret != ERR_OK) {
1058#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
1059 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
1066 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL((ifconfig_cmd.ip_addr))) {
1072 PRINTK(
"%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1076 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
1077 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
1078#if LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL
1080 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
1086 PRINT_ERR(
"ifconfig: internal error\n");
1089 }
else if (err < DUP_ARP_DETECT_TIME) {
1091 PRINT_ERR(
"ifconfig: ip conflict!\n");
1092 ip_addr_set_ip4_u32_val(ifconfig_cmd.ip_addr, old_ip4addr);
1094 if (ret != ERR_OK) {
1096 PRINTK(
"%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1101 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
1102 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
1108 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL(ifconfig_cmd.ip_addr)) {
1113 if (retval == SYS_ARCH_ERROR) {
1116 PRINT_ERR(
"ifconfig: internal error\n");
1118 }
else if (retval < DUP_ARP_DETECT_TIME) {
1120 struct netif *netif = NULL;
1121 PRINT_ERR(
"ifconfig: IP conflict!\n");
1123 i = netif_get_ip6_addr_match(netif, &ifconfig_cmd.ip_addr.u_addr.ip6);
1125 netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
1129 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] =
'\0';
1130 PRINTK(
"%s", ifconfig_cmd.cb_print_buf);
LWIP_STATIC void lwip_ifconfig_usage(const char *cmd)
LWIP_STATIC void lwip_ifconfig_show_internal(void *arg)
LWIP_STATIC void lwip_ifconfig_internal(void *arg)
void lwip_printsize(size_t size)
sys_sem_t ip_conflict_detect
int ip6addr_aton(const char *cp, ip6_addr_t *addr)
sys_sem_t dup_addr_detect
struct netif * netifapi_netif_find_by_name(const char *name)
u32_t is_ip_conflict_signal
u32_t is_dup_detect_initialized