更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
api_shell.c 文件参考

浏览源代码.

结构体

struct  ping6_args
 
struct  ping6_stats
 
struct  ifconfig_option
 
struct  netstat_data
 
struct  if_cmd_data
 
struct  arp_option
 

类型定义

typedef struct ping6_args ping6_args_t
 
typedef struct ping6_stats ping6_stats_t
 

函数

int get_unused_socket_num (void)
 
LWIP_STATIC int print_netif (struct netif *netif, char *print_buf, unsigned int buf_len)
 
LWIP_STATIC void lwip_ifconfig_show_internal (void *arg)
 
LWIP_STATIC void lwip_ifconfig_internal (void *arg)
 
void lwip_printsize (size_t size)
 
LWIP_STATIC void lwip_ifconfig_usage (const char *cmd)
 
LWIP_STATIC void lwip_arp_show_internal (struct netif *netif, char *printf_buf, unsigned int buf_len)
 
LWIP_STATIC void lwip_arp_internal (void *arg)
 
LWIP_STATIC void lwip_arp_usage (const char *cmd)
 
void ifup_internal (void *arg)
 
void ifdown_internal (void *arg)
 
LWIP_STATIC unsigned int get_hostip (const char *hname)
 
LWIP_STATIC struct hostent * gethostnameinfo (const char *host)
 
LWIP_STATIC u32_t netdebug_memp (int argc, const char **argv)
 
LWIP_STATIC u32_t netdebug_sock (int argc, const char **argv)
 
u32_t osShellNetDebug (int argc, const char **argv)
 
u32_t osShellIpDebug (int argc, const char **argv)
 
LWIP_STATIC void update_ping6_stats (ping6_stats_t *ping6_stats, u32_t rtt, u32_t nreceived)
 
LWIP_STATIC int parse_args_ping6 (int argc, const char **argv, ping6_args_t *ping6_params)
 
u32_t osShellPing6 (int argc, const char **argv)
 
LWIP_STATIC int create_ping6_socket (u8_t type, const void *param)
 
LWIP_STATIC const char * convert_icmpv6_err_to_string (u8_t err_type)
 
u32_t osTcpserver (int argc, const char **argv)
 
void udpserver (int argc, const char **argv)
 
void tcp_access (int sockfd)
 
int netstat_get_udp_sendQLen6 (struct udp_pcb *udppcb, struct pbuf *udpbuf)
 
int netstat_udp_sendq6 (struct udp_pcb *upcb)
 
int netstat_get_udp_sendQLen (struct udp_pcb *udppcb, struct pbuf *udpbuf)
 
int netstat_tcp_sendq (struct tcp_pcb *tpcb)
 
int netstat_tcp_recvq (struct tcp_pcb *tpcb)
 
int netstat_netconn_recvq (const struct netconn *conn)
 
int netstat_udp_sendq (struct udp_pcb *upcb)
 
int netstat_netconn_sendq (struct netconn *conn)
 
u32_t lwip_ifconfig (int argc, const char **argv)
 
 SHELLCMD_ENTRY (ifconfig_shellcmd, CMD_TYPE_EX, "ifconfig", XARGS,(CmdCallBackFunc) lwip_ifconfig)
 
u32_t lwip_arp (int argc, const char **argv)
 
 SHELLCMD_ENTRY (arp_shellcmd, CMD_TYPE_EX, "arp", 1,(CmdCallBackFunc) lwip_arp)
 
static void lwip_ping_usage (void)
 
LWIP_STATIC int osPingFunc (u32_t destip, u32_t cnt, u32_t interval, u32_t data_len)
 
static void ping_cmd (unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3)
 
u32_t osShellPing (int argc, const char **argv)
 
 SHELLCMD_ENTRY (ping_shellcmd, CMD_TYPE_EX, "ping", XARGS,(CmdCallBackFunc) osShellPing)
 
 SHELLCMD_ENTRY (ping6_shellcmd, CMD_TYPE_EX, "ping6", XARGS,(CmdCallBackFunc) osShellPing6)
 
u32_t osShellNtpdate (int argc, const char **argv)
 
 SHELLCMD_ENTRY (ntpdate_shellcmd, CMD_TYPE_EX, "ntpdate", XARGS,(CmdCallBackFunc) osShellNtpdate)
 
u32_t osShellDns (int argc, const char **argv)
 
 SHELLCMD_ENTRY (dns_shellcmd, CMD_TYPE_EX, "dns", XARGS,(CmdCallBackFunc) osShellDns)
 

变量

sys_sem_t ip_conflict_detect
 
volatile int tcpip_init_finish
 
const char *const tcp_state_str []
 
static int ping_taskid = -1
 
static int ping_kill = 0
 
struct nd6_neighbor_cache_entry neighbor_cache [LWIP_ND6_NUM_NEIGHBORS]
 

类型定义说明

◆ ping6_args_t

typedef struct ping6_args ping6_args_t

◆ ping6_stats_t

typedef struct ping6_stats ping6_stats_t

函数说明

◆ convert_icmpv6_err_to_string()

LWIP_STATIC const char * convert_icmpv6_err_to_string ( u8_t  err_type)

在文件 api_shell.c2567 行定义.

2568{
2569 switch (err_type) {
2570 case ICMP6_TYPE_DUR:
2571 return "Destination Unreachable";
2572 case ICMP6_TYPE_PTB:
2573 return "Packet too big";
2574 case ICMP6_TYPE_TE:
2575 return "Time Exceeded";
2576 case ICMP6_TYPE_PP:
2577 return "Parameter Problem";
2578 default:
2579 break;
2580 }
2581 return "Unknown Error";
2582}
这是这个函数的调用关系图:

◆ create_ping6_socket()

LWIP_STATIC int create_ping6_socket ( u8_t  type,
const void param 
)

在文件 api_shell.c2340 行定义.

2341{
2342 int sfd;
2343 int ret;
2344 struct sockaddr_in6 stHostAddr6;
2345 struct icmp6_filter icmp6_sock_filter;
2346
2347 sfd = lwip_socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
2348 if (sfd == -1) {
2349 PRINTK("ping6 : Failed, socket creation failed\n");
2350 return -1;
2351 }
2352
2353 if (param != NULL) {
2354 if (type == LWIP_PING6_SOURCE_ADDRESS_ARG) {
2355 /* Binding socket to the provided source address */
2356 (void)memset_s(&stHostAddr6, sizeof(stHostAddr6), 0, sizeof(stHostAddr6));
2357 stHostAddr6.sin6_family = AF_INET6;
2358 inet6_addr_from_ip6addr(&stHostAddr6.sin6_addr, (ip6_addr_t *)param);
2359 stHostAddr6.sin6_port = htons(IPPROTO_ICMPV6);
2360 stHostAddr6.sin6_scope_id = 0;
2361
2362 ret = lwip_bind(sfd, (struct sockaddr *)&stHostAddr6, sizeof(stHostAddr6));
2363 if (ret == -1) {
2364 (void)lwip_close(sfd);
2365 PRINTK("ping6 : bind icmp socket: cannot assign requested address\n");
2366 return ret;
2367 }
2368 } else if (type == LWIP_PING6_INTERFACE_ARG) {
2369 /* Binding socket to the provided netif */
2370 ret = lwip_setsockopt(sfd, SOL_SOCKET, SO_BINDTODEVICE, (char *)(param), strlen((char *)(param)));
2371 if (ret == -1) {
2372 (void)lwip_close(sfd);
2373 PRINTK("ping6: unknownn iface %s\n", (char *)(param));
2374 return ret;
2375 }
2376 }
2377 }
2378
2379 /* Setting socket filter since we are interested only in ECHO REPLY and ERROR messages */
2380 ICMP6_FILTER_SETBLOCKALL (&icmp6_sock_filter);
2381 ICMP6_FILTER_SETPASS (ICMP6_TYPE_EREP, &icmp6_sock_filter);
2382 ICMP6_FILTER_SETPASS (ICMP6_TYPE_DUR, &icmp6_sock_filter);
2383 ICMP6_FILTER_SETPASS (ICMP6_TYPE_PTB, &icmp6_sock_filter);
2384 ICMP6_FILTER_SETPASS (ICMP6_TYPE_TE, &icmp6_sock_filter);
2385
2386 ret = lwip_setsockopt(sfd, IPPROTO_ICMPV6, ICMP6_FILTER, &icmp6_sock_filter, sizeof(struct icmp6_filter));
2387 if (ret == -1) {
2388 (void)lwip_close(sfd);
2389 PRINTK("ping6 : setsockopt: Invalid Argument\n");
2390 return -1;
2391 }
2392
2393 return sfd;
2394}
int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
Definition: sockets.c:77
int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
Definition: sockets.c:83
int lwip_socket(int domain, int type, int protocol)
Definition: sockets.c:71
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图:
这是这个函数的调用关系图:

◆ get_hostip()

LWIP_STATIC unsigned int get_hostip ( const char *  hname)

在文件 api_shell.c1543 行定义.

1544{
1545 unsigned int ip = 0;
1546 int ret;
1547
1548 struct hostent *pent = gethostnameinfo(hname);
1549 if (pent == NULL || pent->h_addr == NULL)
1550 return 0;
1551 ret = memcpy_s(&ip, sizeof(ip), pent->h_addr, 4);
1552 if (ret != 0) {
1553 return 0;
1554 }
1555 return ip;
1556}
LWIP_STATIC struct hostent * gethostnameinfo(const char *host)
Definition: api_shell.c:1527
函数调用图:
这是这个函数的调用关系图:

◆ get_unused_socket_num()

int get_unused_socket_num ( void  )

在文件 sockets.c343 行定义.

344{
345 int unused = 0;
346 SYS_ARCH_DECL_PROTECT(lev);
347
348 SYS_ARCH_PROTECT(lev);
349
350 for (int i = 0; i < NUM_SOCKETS; i++) {
351 if (sockets[i].conn == NULL) {
352#if LWIP_NETCONN_FULLDUPLEX
353 if (sockets[i].fd_used) {
354 continue;
355 }
356#endif
357 unused++;
358 }
359 }
360
361 SYS_ARCH_UNPROTECT(lev);
362
363 return unused;
364}
这是这个函数的调用关系图:

◆ gethostnameinfo()

LWIP_STATIC struct hostent * gethostnameinfo ( const char *  host)

在文件 api_shell.c1527 行定义.

1528{
1529 static struct hostent hostbuf;
1530 struct hostent *hp = NULL;
1531 const size_t hstbuflen = 1024;
1532 char tmphstbuf[1024];
1533 int res;
1534 int herr;
1535
1536 res = lwip_gethostbyname_r(host, &hostbuf, tmphstbuf, hstbuflen, &hp, &herr);
1537 /* Check for errors. */
1538 if (res || hp == NULL)
1539 return NULL;
1540 return hp;
1541}
这是这个函数的调用关系图:

◆ ifdown_internal()

void ifdown_internal ( void arg)

在文件 api_shell.c1503 行定义.

1504{
1505 struct netif *netif = NULL;
1506 struct if_cmd_data *ifcmd_data = NULL;
1507
1508 ifcmd_data = (struct if_cmd_data *)arg;
1509 if (ifcmd_data == NULL) {
1510 return;
1511 }
1512 netif = netif_find(ifcmd_data->if_name);
1513 if (netif == NULL) {
1514 ifcmd_data->err = ERR_VAL;
1515 } else {
1516 (void)netif_set_down(netif);
1517 ifcmd_data->err = ERR_OK;
1518 }
1519
1520 sys_sem_signal(&ifcmd_data->cb_completed);
1521}
sys_sem_t cb_completed
Definition: api_shell.c:263
char * if_name
Definition: api_shell.c:261
err_t err
Definition: api_shell.c:262
void sys_sem_signal(sys_sem_t *sem)
Definition: sys_arch.c:267
函数调用图:

◆ ifup_internal()

void ifup_internal ( void arg)

在文件 api_shell.c1483 行定义.

1484{
1485 struct netif *netif = NULL;
1486 struct if_cmd_data *ifcmd_data;
1487
1488 ifcmd_data = (struct if_cmd_data *)arg;
1489 if (ifcmd_data == NULL) {
1490 return;
1491 }
1492 netif = netif_find(ifcmd_data->if_name);
1493 if (netif == NULL) {
1494 ifcmd_data->err = ERR_VAL;
1495 } else {
1496 (void)netif_set_up(netif);
1497 ifcmd_data->err = ERR_OK;
1498 }
1499
1500 sys_sem_signal(&ifcmd_data->cb_completed);
1501}
函数调用图:

◆ lwip_arp()

u32_t lwip_arp ( int  argc,
const char **  argv 
)

在文件 api_shell.c1347 行定义.

1348{
1349 int i;
1350 struct arp_option arp_cmd;
1351 err_t ret;
1352 size_t interface_len = 0;
1353
1354 (void)memset_s(&arp_cmd, sizeof(struct arp_option), 0, sizeof(struct arp_option));
1355 if (!tcpip_init_finish) {
1356 PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
1357 return LOS_NOK;
1358 }
1359
1360 arp_cmd.iface[0] = 'd';
1361 arp_cmd.iface[1] = 'e';
1362 arp_cmd.iface[2] = '0';
1363 arp_cmd.option = ARP_OPTION_SHOW;
1364 arp_cmd.print_buf_len = 0;
1365 if (sys_sem_new(&arp_cmd.cb_completed, 0) != ERR_OK) {
1366 PRINTK("%s: sys_sem_new fail\n", __FUNCTION__);
1367 return 1;
1368 }
1369
1370 i = 0;
1371 while (argc > 0) {
1372 if (strcmp("-i", argv[i]) == 0 && (argc > 1)) {
1373 /* get the network interface's name */
1374 interface_len = strlen(argv[i + 1]);
1375 if (interface_len < IFNAMSIZ) {
1376 if (strncmp(argv[i + 1], "lo", (sizeof("lo") - 1)) == 0) {
1377 PRINTK("Illegal operation\n");
1378 goto arp_error;
1379 }
1380 if (strncpy_s(arp_cmd.iface, IFNAMSIZ, argv[i + 1], interface_len) != EOK) {
1381 PRINTK("strncpy_s error\n");
1382 goto arp_error;
1383 }
1384 arp_cmd.iface[interface_len] = '\0';
1385 } else {
1386 PRINTK("Iface name is big \n");
1387 goto arp_error;
1388 }
1389 i += 2;
1390 argc -= 2;
1391 } else if (strcmp("-d", argv[i]) == 0 && (argc > 1)) {
1392 /* arp delete */
1393 arp_cmd.option = ARP_OPTION_DEL;
1394 arp_cmd.ipaddr = inet_addr(argv[i + 1]);
1395
1396 if (arp_cmd.ipaddr == IPADDR_NONE) {
1397 PRINTK("IP address is not correct!\n");
1398 goto arp_error;
1399 }
1400
1401 i += 2;
1402 argc -= 2;
1403 } else if (strcmp("-s", argv[i]) == 0 && (argc > 2)) {
1404 /* arp add */
1405 char *digit = NULL;
1406 u32_t macaddrlen = strlen(argv[i + 2]) + 1;
1407 char tmpStr[MAX_MACADDR_STRING_LENGTH];
1408 char *tmpStr1 = NULL;
1409 char *saveptr1 = NULL;
1410 char *temp = NULL;
1411 int j;
1412
1413 arp_cmd.option = ARP_OPTION_ADD;
1414 arp_cmd.ipaddr = inet_addr(argv[i + 1]);
1415
1416 if (arp_cmd.ipaddr == IPADDR_NONE) {
1417 PRINTK("IP address is not correct!\n");
1418 goto arp_error;
1419 }
1420
1421 /*cannot add an arp entry of 127.*.*.* */
1422 if ((arp_cmd.ipaddr & (u32_t)0x0000007fUL) == (u32_t)0x0000007fUL) {
1423 PRINTK("IP address is not correct!\n");
1424 goto arp_error;
1425 }
1426
1427 if (macaddrlen != MAX_MACADDR_STRING_LENGTH) {
1428 PRINTK("Wrong MAC address length\n");
1429 goto arp_error;
1430 }
1431
1432 if (strncpy_s(tmpStr, MAX_MACADDR_STRING_LENGTH, argv[i + 2], macaddrlen - 1) != 0) {
1433 PRINTK("Wrong MAC address\n");
1434 goto arp_error;
1435 }
1436
1437 for (j = 0, tmpStr1 = tmpStr; j < 6; j++, tmpStr1 = NULL) {
1438 digit = strtok_r(tmpStr1, ":", &saveptr1);
1439 if ((digit == NULL) || (strlen(digit) > 2)) {
1440 PRINTK("MAC address is not correct\n");
1441 goto arp_error;
1442 }
1443
1444 for (temp = digit; *temp != '\0'; temp++) {
1445 if (!isxdigit(*temp)) {
1446 PRINTK("MAC address is not correct\n");
1447 goto arp_error;
1448 }
1449 }
1450
1451 CONVERT_STRING_TO_HEX(digit, arp_cmd.ethaddr[j]);
1452 }
1453
1454 i += 3;
1455 argc -= 3;
1456 } else {
1457 goto arp_error;
1458 }
1459 }
1460
1461 ret = tcpip_callback(lwip_arp_internal, &arp_cmd);
1462 if (ret != ERR_OK) {
1463 PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1464 sys_sem_free(&arp_cmd.cb_completed);
1465 return 1;
1466 }
1467 (void)sys_arch_sem_wait(&arp_cmd.cb_completed, 0);
1468 sys_sem_free(&arp_cmd.cb_completed);
1469 arp_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
1470 PRINTK("%s", arp_cmd.cb_print_buf);
1471 return 0;
1472
1473arp_error:
1474 lwip_arp_usage("arp");
1475 sys_sem_free(&arp_cmd.cb_completed);
1476 return 1;
1477}
LWIP_STATIC void lwip_arp_internal(void *arg)
Definition: api_shell.c:1249
volatile int tcpip_init_finish
Definition: fixme.c:403
LWIP_STATIC void lwip_arp_usage(const char *cmd)
Definition: api_shell.c:1338
in_addr_t inet_addr(const char *cp)
Definition: socket.c:334
void sys_sem_free(sys_sem_t *sem)
Definition: sys_arch.c:288
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeoutMs)
Definition: sys_arch.c:272
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
Definition: sys_arch.c:257
函数调用图:

◆ lwip_arp_internal()

LWIP_STATIC void lwip_arp_internal ( void arg)

在文件 api_shell.c1249 行定义.

1250{
1251#if LWIP_IPV4
1252 struct arp_option *arp_cmd = (struct arp_option *)arg;
1253 struct netif *netif = NULL;
1254 struct eth_addr ethaddr;
1255 ip4_addr_t ipaddr;
1256 err_t ret = 0;
1257 int type = 0;
1258
1259 if (arp_cmd->iface[0] == 'd' && arp_cmd->iface[1] == 'e') {
1260 netif = NULL;
1261 } else {
1262 /* find the specified netif by it's name */
1263 netif = netif_find(arp_cmd->iface);
1264 if (netif == NULL) {
1265 (void)snprintf_s(arp_cmd->cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1), "No such device\n");
1266 goto out;
1267 }
1268 }
1269
1270 type = arp_cmd->option;
1271 switch (type) {
1272 case ARP_OPTION_SHOW:
1273 if (netif != NULL) {
1274 lwip_arp_show_internal(netif, arp_cmd->cb_print_buf, PRINT_BUF_LEN);
1275 } else {
1276 lwip_arp_show_internal(NULL, arp_cmd->cb_print_buf, PRINT_BUF_LEN);
1277 }
1278 break;
1279
1280 case ARP_OPTION_ADD:
1281#if ETHARP_SUPPORT_STATIC_ENTRIES
1282 ipaddr.addr = arp_cmd->ipaddr;
1283 (void)memcpy_s(ethaddr.addr, sizeof(ethaddr.addr), arp_cmd->ethaddr, 6);
1284 if (netif != NULL) {
1285 if (ip4_addr_netcmp(&ipaddr, ip_2_ip4(&(netif->ip_addr)), ip_2_ip4(&(netif->netmask)))) {
1286 ret = etharp_update_arp_entry(netif, &ipaddr, &ethaddr,
1287 ETHARP_FLAG_TRY_HARD | ETHARP_FLAG_STATIC_ENTRY);
1288 } else {
1289 ret = ERR_RTE;
1290 }
1291 } else {
1292 ret = etharp_add_static_entry(&ipaddr, &ethaddr);
1293 }
1294#else
1295 ret = ERR_ARG;
1296#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
1297 break;
1298
1299 case ARP_OPTION_DEL:
1300 ipaddr.addr = arp_cmd->ipaddr;
1301 (void)memcpy_s(ethaddr.addr, sizeof(ethaddr.addr), arp_cmd->ethaddr, 6);
1302 if (netif != NULL) {
1303 ret = etharp_delete_arp_entry(netif, &ipaddr);
1304 } else {
1305 for (netif = netif_list; netif != NULL; netif = netif->next) {
1306 ret = etharp_delete_arp_entry(netif, &ipaddr);
1307 if (ret == ERR_OK) {
1308 /*only can del success one time*/
1309 break;
1310 }
1311 }
1312 }
1313 break;
1314
1315 default:
1316 (void)snprintf_s(arp_cmd->cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1), "Error\n");
1317 goto out;
1318 }
1319
1320out:
1321 if (type == ARP_OPTION_ADD || type == ARP_OPTION_DEL) {
1322 if (ret == ERR_MEM) {
1323 (void)snprintf_s(arp_cmd->cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1), "Out of memory error\n");
1324 } else if (ret == ERR_ARG) {
1325 (void)snprintf_s(arp_cmd->cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1), "Illegal argument\n");
1326 } else if (ret == ERR_RTE) {
1327 (void)snprintf_s(arp_cmd->cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1), "Network is unreachable\n");
1328 } else {
1329 (void)snprintf_s(arp_cmd->cb_print_buf, PRINT_BUF_LEN, (PRINT_BUF_LEN - 1), "Successed\n");
1330 }
1331 }
1332#endif
1333
1334 sys_sem_signal(&arp_cmd->cb_completed);
1335}
LWIP_STATIC void lwip_arp_show_internal(struct netif *netif, char *printf_buf, unsigned int buf_len)
Definition: api_shell.c:1172
err_t etharp_delete_arp_entry(struct netif *netif, ip4_addr_t *ipaddr)
Definition: fixme.c:337
err_t etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
Definition: fixme.c:328
unsigned char ethaddr[6]
Definition: api_shell.c:1160
unsigned int ipaddr
Definition: api_shell.c:1158
char iface[IFNAMSIZ]
Definition: api_shell.c:1156
sys_sem_t cb_completed
Definition: api_shell.c:1164
char cb_print_buf[PRINT_BUF_LEN]
Definition: api_shell.c:1165
函数调用图:
这是这个函数的调用关系图:

◆ lwip_arp_show_internal()

LWIP_STATIC void lwip_arp_show_internal ( struct netif *  netif,
char *  printf_buf,
unsigned int  buf_len 
)

在文件 api_shell.c1172 行定义.

1173{
1174 u8_t state, i;
1175 int ret;
1176 char *tmp = printf_buf;
1177 if (buf_len < 1) {
1178 return;
1179 }
1180 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%-24s%-24s%-12s%-12s\n", "Address", "HWaddress", "Iface", "Type");
1181 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
1182 return;
1183 tmp += ret;
1184 buf_len -= (unsigned int)ret;
1185
1186 if (netif != NULL) {
1187 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
1188 state = arp_table[i].state;
1189 if (((state == ETHARP_STATE_STABLE)
1190 #if ETHARP_SUPPORT_STATIC_ENTRIES
1191 || (state == ETHARP_STATE_STATIC)
1192#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
1193 ) && arp_table[i].netif) {
1194
1195 if (strcmp(netif_get_name(netif), netif_get_name(arp_table[i].netif)) != 0) {
1196 continue;
1197 }
1198
1199 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%-24s%02X:%02X:%02X:%02X:%02X:%02X %s %s\n",
1200 ip4addr_ntoa(&arp_table[i].ipaddr),
1201 arp_table[i].ethaddr.addr[0], arp_table[i].ethaddr.addr[1],
1202 arp_table[i].ethaddr.addr[2], arp_table[i].ethaddr.addr[3],
1203 arp_table[i].ethaddr.addr[4], arp_table[i].ethaddr.addr[5],
1204 netif_get_name(netif),
1205#if ETHARP_SUPPORT_STATIC_ENTRIES
1206 ((state == ETHARP_STATE_STATIC) ? "static" : "dynamic")
1207#else
1208 "dynamic"
1209#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
1210 );
1211 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
1212 return;
1213 tmp += ret;
1214 buf_len -= (unsigned int)ret;
1215 }
1216 }
1217 } else {
1218 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
1219 state = arp_table[i].state;
1220 if (((state == ETHARP_STATE_STABLE)
1221 #if ETHARP_SUPPORT_STATIC_ENTRIES
1222 || (state == ETHARP_STATE_STATIC)
1223#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
1224 ) && arp_table[i].netif) {
1225 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%-24s%02X:%02X:%02X:%02X:%02X:%02X %s %s\n",
1226 ip4addr_ntoa(&arp_table[i].ipaddr),
1227 arp_table[i].ethaddr.addr[0], arp_table[i].ethaddr.addr[1],
1228 arp_table[i].ethaddr.addr[2], arp_table[i].ethaddr.addr[3],
1229 arp_table[i].ethaddr.addr[4], arp_table[i].ethaddr.addr[5],
1230 netif_get_name(arp_table[i].netif),
1231#if ETHARP_SUPPORT_STATIC_ENTRIES
1232 ((state == ETHARP_STATE_STATIC) ? "static" : "dynamic")
1233#else
1234 "dynamic"
1235#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
1236 );
1237 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
1238 return;
1239 tmp += ret;
1240 buf_len -= (unsigned int)ret;
1241 }
1242 }
1243 }
1244}
ARG_NUM_3 int
这是这个函数的调用关系图:

◆ lwip_arp_usage()

LWIP_STATIC void lwip_arp_usage ( const char *  cmd)

在文件 api_shell.c1338 行定义.

1339{
1340 PRINTK("Usage:"
1341 "\n%s"
1342 "\n%s [-i IF] -s IPADDR HWADDR"
1343 "\n%s [-i IF] -d IPADDR\n",
1344 cmd, cmd, cmd);
1345}
这是这个函数的调用关系图:

◆ lwip_ifconfig()

u32_t lwip_ifconfig ( int  argc,
const char **  argv 
)

在文件 api_shell.c684 行定义.

685{
686 int i;
687 static struct ifconfig_option ifconfig_cmd;
688 err_t ret;
689
690#if LWIP_STATS
691 u32_t stat_err_cnt;
692 u32_t stat_drop_cnt;
693 u32_t stat_rx_or_tx_cnt;
694 u32_t stat_rx_or_tx_bytes;
695#endif
696
697#if LWIP_ARP
698 u32_t retval;
699 struct netif *netiftmp = NULL;
700#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
701 u32_t old_ip4addr;
702 err_t err;
704 extern u32_t is_ip_conflict_signal;
705#endif /* LWIP_ENABLE_IP_CONFLICT_SIGNAL */
706#endif /* LWIP_ARP */
707#if LWIP_IPV6
709 extern u32_t is_dup_detect_initialized;
710#endif
711 if (!tcpip_init_finish) {
712 PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
713 return 2;
714 }
715 /* To support "ifconfig -a" command
716 RX packets:XXXX errors:X dropped:X overruns:X bytes:XXXX (Human readable format)
717 TX packets:XXXX errors:X dropped:X overruns:X bytes:XXXX (Human readable format)
718
719 Below is assumed for 'overrun' stat.
720 Linux Kernel:
721 RX: FIFO overrun
722 Data structure: net_device->stats->rx_fifo_errors
723 Flag which is marked when FIFO overrun: ENRSR_FO
724
725 Function: ei_receive->ENRSR_FO
726
727 TX: A "FIFO underrun" occurred during transmit.
728 Data structure: net_device->stats->tx_fifo_errors
729 Flag which is marked when FIFO underrun: ENTSR_FU
730
731 Function: ei_tx_intr->ENTSR_FU
732
733 LWIP:
734 So in our case,
735 while receiving a packet RX case, if the buffer is full (trypost - it is sys_mbox_trypost)
736 the error will be returned, we can consider that an overflow has happened.
737 So this can be RX overrun.
738
739 But while transmitting a packet TX case, underrun cannot happen because it block on the
740 message Q if it is full (NOT trypost - it is sys_mbox_post). So TX overrun is always 0.
741 */
742 if (argc) {
743 if (strcmp("-a", argv[0]) == 0) {
744#if LWIP_STATS
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;
753
754 PRINTK("%18s:%u\t errors:%u\t ip dropped:%u\t link dropped:%u\t overrun:%d\t bytes:%u ",
755 "RX packets",
756 stat_rx_or_tx_cnt,
757 stat_err_cnt,
758 stat_drop_cnt,
759 lwip_stats.link.link_rx_drop,
760 lwip_stats.ip.link_rx_overrun,
761 stat_rx_or_tx_bytes);
762
763 /* Print in Human readable format of the incoming bytes */
764 lwip_printsize(lwip_stats.ip.ip_rx_bytes);
765#if IP6_STATS
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;
774
775 PRINTK("%18s:%u\t errors:%u\t dropped:%u\t overrun:%d\t bytes:%u ",
776 "RX packets(ip6)",
777 stat_rx_or_tx_cnt,
778 stat_err_cnt,
779 stat_drop_cnt,
780 lwip_stats.ip.link_rx_overrun,
781 stat_rx_or_tx_bytes);
782
783 /* Print in Human readable format of the incoming bytes */
784 lwip_printsize(lwip_stats.ip6.ip_rx_bytes);
785#endif
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);
788 /* IP layer drop stat param is not maintained, failure at IP is considered in 'errors' stat */
789 stat_drop_cnt = lwip_stats.link.link_tx_drop;
790 stat_rx_or_tx_bytes = lwip_stats.ip.ip_tx_bytes;
791
792 PRINTK("%18s:%u\t errors:%u\t link dropped:%u\t overrun:0\t bytes:%u",
793 "TX packets",
794 stat_rx_or_tx_cnt,
795 stat_err_cnt,
796 stat_drop_cnt,
797 stat_rx_or_tx_bytes);
798
799 /* Print in Human readable format of the outgoing bytes */
800 lwip_printsize(lwip_stats.ip.ip_tx_bytes);
801
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;
805
806 PRINTK("%18s:%u\t errors:%u\t overrun:0\t bytes:%u",
807 "TX packets(ip6)",
808 stat_rx_or_tx_cnt,
809 stat_err_cnt,
810 stat_rx_or_tx_bytes);
811
812 /* Print in Human readable format of the outgoing bytes */
813 lwip_printsize(lwip_stats.ip6.ip_tx_bytes);
814#endif /* LWIP_STATS */
815 return 0;
816 }
817 }
818
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__);
822 return 1;
823 }
824
825 i = 0;
826 /* Get the interface */
827 if (argc > 0) {
828 if (strlen(argv[i]) < IFNAMSIZ) {
829 if (strncpy_s(ifconfig_cmd.iface, IFNAMSIZ, argv[i], (strlen(argv[i]))) != EOK) {
830 sys_sem_free(&ifconfig_cmd.cb_completed);
831 PRINTK("ifconfig : strncpy_s error\n");
832 return 1;
833 }
834 ifconfig_cmd.iface[IFNAMSIZ - 1] = '\0';
835 } else {
836 sys_sem_free(&ifconfig_cmd.cb_completed);
837 PRINTK("ifconfig : interface name is too big\n");
838 return 1;
839 }
840 i++;
841 argc--;
842 if (argc == 0) {
843 /* no more arguments, show the interface state. */
844 ret = tcpip_callback(lwip_ifconfig_show_internal, &ifconfig_cmd);
845 if (ret != ERR_OK) {
846 sys_sem_free(&ifconfig_cmd.cb_completed);
847 PRINTK("ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
848 return 1;
849 }
850 (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
851 sys_sem_free(&ifconfig_cmd.cb_completed);
852 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
853 PRINTK("%s", ifconfig_cmd.cb_print_buf);
854 return 0;
855 }
856 } else {
857 /* no more arguments, show all the interface state. */
858 ret = tcpip_callback(lwip_ifconfig_show_internal, &ifconfig_cmd);
859 if (ret != ERR_OK) {
860 sys_sem_free(&ifconfig_cmd.cb_completed);
861 PRINTK("ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
862 return 1;
863 }
864 (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
865 sys_sem_free(&ifconfig_cmd.cb_completed);
866 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
867 PRINTK("%s", ifconfig_cmd.cb_print_buf);
868
869 return 0;
870 }
871
872 /* ifup/ifdown */
873 if (strcmp("up", argv[i]) == 0) {
874 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_UP;
875 /* setup the interface, other arguments is ignored. */
876 ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
877 if (ret != ERR_OK) {
878 sys_sem_free(&ifconfig_cmd.cb_completed);
879 PRINTK("ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
880 return 1;
881 }
882 (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
883 sys_sem_free(&ifconfig_cmd.cb_completed);
884 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
885 PRINTK("%s", ifconfig_cmd.cb_print_buf);
886 return 0;
887 } else if (strcmp("down", argv[i]) == 0) {
888 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_DOWN;
889 /* setdown the interface, other arguments is ignored. */
890 ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
891 if (ret != ERR_OK) {
892 sys_sem_free(&ifconfig_cmd.cb_completed);
893 PRINTK("ifconfig : internal error, l:%d err:%d\n", __LINE__, ret);
894 return 1;
895 }
896 (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
897 sys_sem_free(&ifconfig_cmd.cb_completed);
898 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
899 PRINTK("%s", ifconfig_cmd.cb_print_buf);
900 return 0;
901 }
902 /* check if set the ip address. */
903#if LWIP_ARP
904 netiftmp = netifapi_netif_find_by_name(ifconfig_cmd.iface);
905 if (netiftmp == NULL) {
906 sys_sem_free(&ifconfig_cmd.cb_completed);
907 PRINTK("ifconfig : Interface %s not found\n", ifconfig_cmd.iface);
908 return 1;
909 }
910#if LWIP_ENABLE_IP_CONFLICT_SIGNAL
911 old_ip4addr = ipaddr_addr(ipaddr_ntoa(&netiftmp->ip_addr));
912#endif /* LWIP_ENABLE_IP_CONFLICT_SIGNAL */
913#endif /* LWIP_ARP */
914 if (!strcmp(argv[i], "inet") || ip4addr_aton(argv[i], ip_2_ip4(&ifconfig_cmd.ip_addr))) {
915 if (!strcmp(argv[i], "inet")) {
916 if (argc <= 1) {
917 sys_sem_free(&ifconfig_cmd.cb_completed);
918 goto ifconfig_error;
919 }
920
921 if (!ip4addr_aton(argv[i + 1], ip_2_ip4(&ifconfig_cmd.ip_addr))) {
922 sys_sem_free(&ifconfig_cmd.cb_completed);
923 PRINTK("ifconfig : Invalid IPv4 Address\n");
924 return 1;
925 }
926 argc--;
927 i++;
928 }
929 IP_SET_TYPE_VAL((ifconfig_cmd.ip_addr), IPADDR_TYPE_V4);
930#if LWIP_ARP
931 if (!ip_addr_cmp(&ifconfig_cmd.ip_addr, &netiftmp->ip_addr)) {
932 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_IP;
933 }
934#else
935 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_IP;
936#endif /* LWIP_ARP */
937 argc--;
938 i++;
939 } else if (!strcmp(argv[i], "inet6")) {
940 if (argc < 3) {
941 sys_sem_free(&ifconfig_cmd.cb_completed);
942 goto ifconfig_error;
943 }
944 if (strcmp(argv[i + 1], "add") && strcmp(argv[i + 1], "del")) {
945 sys_sem_free(&ifconfig_cmd.cb_completed);
946 goto ifconfig_error;
947 }
948
949 if (!ip6addr_aton(argv[i + 2], ip_2_ip6(&ifconfig_cmd.ip_addr))) {
950 sys_sem_free(&ifconfig_cmd.cb_completed);
951 PRINTK("ifconfig : Invalid IPv6 Address\n");
952 return 1;
953 }
954
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);
957 argc -= 3;
958 i += 3;
959 }
960
961 if (ifconfig_cmd.option & IFCONFIG_OPTION_DEL_IP) {
962 if (argc != 0) {
963 sys_sem_free(&ifconfig_cmd.cb_completed);
964 goto ifconfig_error;
965 }
966 }
967
968 while (argc > 0) {
969 if (strcmp("netmask", argv[i]) == 0 && (argc > 1) && (ipaddr_addr(argv[i + 1]) != IPADDR_NONE)) {
970 /* if set netmask */
971 ip_addr_set_ip4_u32_val((ifconfig_cmd.netmask), ipaddr_addr(argv[i + 1]));
972 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_NETMASK;
973 i += 2;
974 argc -= 2;
975 } else if (strcmp("gateway", argv[i]) == 0 && (argc > 1) && (ipaddr_addr(argv[i + 1]) != IPADDR_NONE)) {
976 /* if set gateway */
977 ip_addr_set_ip4_u32_val((ifconfig_cmd.gw), ipaddr_addr(argv[i + 1]));
978 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_GW;
979 i += 2;
980 argc -= 2;
981 } else if (strcmp("hw", argv[i]) == 0 && argc > 2 && strcmp("ether", argv[i + 1]) == 0) {
982 /* if set HWaddr */
983 char *digit = NULL;
984 u32_t macaddrlen = strlen(argv[i + 2]) + 1;
985 char tmpStr[MAX_MACADDR_STRING_LENGTH];
986 char *tmpStr1 = NULL;
987 char *saveptr = NULL;
988 int j;
989
990 if (macaddrlen != MAX_MACADDR_STRING_LENGTH) {
991 sys_sem_free(&ifconfig_cmd.cb_completed);
992 PRINTK("ifconfig : wrong MAC address format\n");
993 return 1;
994 }
995
996 if (strncpy_s(tmpStr, MAX_MACADDR_STRING_LENGTH, argv[i + 2], macaddrlen - 1) != 0) {
997 sys_sem_free(&ifconfig_cmd.cb_completed);
998 PRINTK("ifconfig : wrong MAC address\n");
999 return 1;
1000 }
1001 for (j = 0, tmpStr1 = tmpStr; j < 6; j++, tmpStr1 = NULL) {
1002 digit = strtok_r(tmpStr1, ":", &saveptr);
1003 if ((digit == NULL) || (strlen(digit) > 2)) {
1004 sys_sem_free(&ifconfig_cmd.cb_completed);
1005 PRINTK("ifconfig : wrong MAC address format\n");
1006 return 1;
1007 }
1008 CONVERT_STRING_TO_HEX(digit, ifconfig_cmd.ethaddr[j]);
1009 }
1010 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_HW;
1011 i += 3;
1012 argc -= 3;
1013 } else if (!strcmp("mtu", argv[i]) && (argc > 1)) {
1014 /* if set mtu */
1015 if ((atoi(argv[i + 1]) < 0) || (atoi(argv[i + 1]) > 0xFFFF)) {
1016 sys_sem_free(&ifconfig_cmd.cb_completed);
1017 PRINTK("\nifconfig: Invalid argument for mtu\n");
1018 goto ifconfig_error;
1019 }
1020
1021 ifconfig_cmd.mtu = (u16_t)(atoi(argv[i + 1]));
1022 ifconfig_cmd.option |= IFCONFIG_OPTION_SET_MTU;
1023 i += 2;
1024 argc -= 2;
1025 } else {
1026 sys_sem_free(&ifconfig_cmd.cb_completed);
1027 goto ifconfig_error;
1028 }
1029 }
1030
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))) {
1033 /* Create the semaphore for ip conflict detection. */
1034 if (sys_sem_new(&ip_conflict_detect, 0) != ERR_OK) {
1035 sys_sem_free(&ifconfig_cmd.cb_completed);
1036 PRINTK("ifconfig: internal error\n");
1037 return 1;
1038 }
1040 }
1041#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
1042
1043#if LWIP_IPV6
1044 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL((ifconfig_cmd.ip_addr))) {
1045 /* Create the semaphore for duplicate address detection. */
1046 if (sys_sem_new(&dup_addr_detect, 0) != ERR_OK) {
1047 sys_sem_free(&ifconfig_cmd.cb_completed);
1048 PRINTK("ifconfig: internal error\n");
1049 return 1;
1050 }
1052 }
1053#endif /* LWIP_IPV6 */
1054
1055 ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
1056 if (ret != ERR_OK) {
1057 sys_sem_free(&ifconfig_cmd.cb_completed);
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))) {
1062 }
1063#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
1064
1065#if LWIP_IPV6
1066 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL((ifconfig_cmd.ip_addr))) {
1069 }
1070#endif /* LWIP_IPV6 */
1071
1072 PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1073 return 1;
1074 }
1075 (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
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
1079 /* Pend 2 seconds for waiting the arp reply if the ip is already in use.*/
1080 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V4_VAL((ifconfig_cmd.ip_addr))) {
1081 err = (err_t)sys_arch_sem_wait(&ip_conflict_detect, DUP_ARP_DETECT_TIME);
1084 if (err < 0) {
1085 /* The result neither conflict nor timeout. */
1086 PRINT_ERR("ifconfig: internal error\n");
1087 sys_sem_free(&ifconfig_cmd.cb_completed);
1088 return 1;
1089 } else if (err < DUP_ARP_DETECT_TIME) {
1090 /* Duplicate use of new ip, restore it to the old one. */
1091 PRINT_ERR("ifconfig: ip conflict!\n");
1092 ip_addr_set_ip4_u32_val(ifconfig_cmd.ip_addr, old_ip4addr);
1093 ret = tcpip_callback(lwip_ifconfig_internal, &ifconfig_cmd);
1094 if (ret != ERR_OK) {
1095 sys_sem_free(&ifconfig_cmd.cb_completed);
1096 PRINTK("%s : tcpip_callback failed in line %d : errnu %d", __FUNCTION__, __LINE__, ret);
1097 return 1;
1098 }
1099 (void)sys_arch_sem_wait(&ifconfig_cmd.cb_completed, 0);
1100 sys_sem_free(&ifconfig_cmd.cb_completed);
1101 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
1102 PRINTK("%s", ifconfig_cmd.cb_print_buf);
1103 return 1;
1104 }
1105 }
1106#endif /* LWIP_ARP && LWIP_ENABLE_IP_CONFLICT_SIGNAL */
1107#if LWIP_IPV6
1108 if ((ifconfig_cmd.option & IFCONFIG_OPTION_SET_IP) && IP_IS_V6_VAL(ifconfig_cmd.ip_addr)) {
1109 /* Pend 2 seconds for waiting the arp reply if the ip is already in use.*/
1110 retval = sys_arch_sem_wait(&dup_addr_detect, DUP_ARP_DETECT_TIME);
1113 if (retval == SYS_ARCH_ERROR) {
1114 sys_sem_free(&ifconfig_cmd.cb_completed);
1115 /* The result neither conflict nor timeout. */
1116 PRINT_ERR("ifconfig: internal error\n");
1117 return 1;
1118 } else if (retval < DUP_ARP_DETECT_TIME) {
1119 /* Duplicate use of new ip, restore it to the old one. */
1120 struct netif *netif = NULL;
1121 PRINT_ERR("ifconfig: IP conflict!\n");
1122 netif = netifapi_netif_find_by_name(ifconfig_cmd.iface);
1123 i = netif_get_ip6_addr_match(netif, &ifconfig_cmd.ip_addr.u_addr.ip6);
1124 if (i >= 0) {
1125 netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
1126 }
1127
1128 sys_sem_free(&ifconfig_cmd.cb_completed);
1129 ifconfig_cmd.cb_print_buf[PRINT_BUF_LEN - 1] = '\0';
1130 PRINTK("%s", ifconfig_cmd.cb_print_buf);
1131 return 1;
1132 }
1133 }
1134#endif /* LWIP_IPV6 */
1135 sys_sem_free(&ifconfig_cmd.cb_completed);
1136 return 0;
1137ifconfig_error:
1138 lwip_ifconfig_usage("ifconfig");
1139 return 1;
1140}
LWIP_STATIC void lwip_ifconfig_usage(const char *cmd)
Definition: api_shell.c:671
LWIP_STATIC void lwip_ifconfig_show_internal(void *arg)
Definition: api_shell.c:429
LWIP_STATIC void lwip_ifconfig_internal(void *arg)
Definition: api_shell.c:476
void lwip_printsize(size_t size)
Definition: api_shell.c:656
sys_sem_t ip_conflict_detect
Definition: fixme.c:369
int ip6addr_aton(const char *cp, ip6_addr_t *addr)
Definition: fixme.c:405
sys_sem_t dup_addr_detect
Definition: fixme.c:373
struct netif * netifapi_netif_find_by_name(const char *name)
Definition: fixme.c:241
u32_t is_ip_conflict_signal
Definition: fixme.c:368
u32_t is_dup_detect_initialized
Definition: fixme.c:372
uint32_t sys_sem_t
Definition: sys_arch.h:52
函数调用图:

◆ lwip_ifconfig_internal()

LWIP_STATIC void lwip_ifconfig_internal ( void arg)

在文件 api_shell.c476 行定义.

477{
478 struct ifconfig_option *ifconfig_cmd = NULL;
479 struct netif *netif = NULL;
480 ip_addr_t ip_addr;
481 ip_addr_t netmask;
482 ip_addr_t gw;
483 unsigned short mtu;
484 struct netif *loc_netif = NULL;
485 int ret;
486 s8_t idx;
487 err_t err;
488
489 ifconfig_cmd = (struct ifconfig_option *)arg;
490 netif = netif_find(ifconfig_cmd->iface);
491 if (netif == NULL) {
492 ERR_IFCONFIG_STRING_PUT(ret, "Device not found\n");
493 goto out;
494 }
495
496 if (ifconfig_cmd->option & IFCONFIG_OPTION_SET_UP) {
497 (void)netif_set_up(netif);
498 goto out;
499 } else if (ifconfig_cmd->option & IFCONFIG_OPTION_SET_DOWN) {
500 (void)netif_set_down(netif);
501 goto out;
502 }
503
504 if ((ifconfig_cmd->option & IFCONFIG_OPTION_SET_IP) ||
505 (ifconfig_cmd->option & IFCONFIG_OPTION_SET_NETMASK) ||
506 (ifconfig_cmd->option & IFCONFIG_OPTION_SET_HW)) {
507 (void)netif_set_down(netif);
508 }
509
510 if (ifconfig_cmd->option & IFCONFIG_OPTION_SET_IP) {
511 ip_addr_set_val(&ip_addr, &(ifconfig_cmd->ip_addr));
512 if (IP_IS_V4_VAL(ifconfig_cmd->ip_addr)) {
513 /* check the address is not multicast/broadcast/0/loopback */
514 if (ip_addr_ismulticast_val(&ip_addr) || ip_addr_isbroadcast_val(&ip_addr, netif) ||
515 ip_addr_isany(&ip_addr) || ip_addr_isloopback(&ip_addr)) {
516 ERR_IFCONFIG_STRING_PUT(ret, "Don't set ip as a multicast/broadcast/0/loopback address!\n");
517 goto out;
518 }
519
520 /* reset gateway if new and previous ipaddr not in same net */
521 if (!ip_addr_netcmp_val(&ip_addr, &netif->ip_addr, ip_2_ip4(&netif->netmask))) {
522 ip_addr_set_zero(&netif->gw);
523 if (netif == netif_default) {
524 (void)netif_set_default(NULL);
525 }
526 }
527
528 /* lwip disallow two netif sit in same net at the same time */
529 loc_netif = netif_list;
530 while (loc_netif != NULL) {
531 if (loc_netif == netif) {
532 loc_netif = loc_netif->next;
533 continue;
534 }
535 if (IP_IS_V4_VAL(ifconfig_cmd->ip_addr) && ip_addr_cmp(&netif->netmask, &loc_netif->netmask) &&
536 ip_addr_netcmp_val(&loc_netif->ip_addr, &ip_addr, ip_2_ip4(&netif->netmask))) {
537 ERR_IFCONFIG_STRING_PUT(ret, "Duplicate network!\n");
538 goto out;
539 }
540 loc_netif = loc_netif->next;
541 }
542
543#if LWIP_DHCP
544 if (netif_dhcp_data(netif) && netif_dhcp_data(netif)->state != DHCP_STATE_OFF) {
545 (void)netif_dhcp_off(netif);
546 }
547#endif
548 netif_set_ipaddr(netif, ip_2_ip4(&ip_addr));
549 } else if (IP_IS_V6_VAL(ifconfig_cmd->ip_addr)) {
550 idx = -1;
551 err = netif_add_ip6_address(netif, ip_2_ip6(&ip_addr), &idx);
552 if (err != ERR_OK || idx == -1) {
553 ERR_IFCONFIG_STRING_PUT(ret, "The IPv6 has reached the Global address limit, "
554 "you should delete one address before add!\n");
555 goto out;
556 }
557 }
558 }
559
560 if (ifconfig_cmd->option & IFCONFIG_OPTION_DEL_IP) {
561 (void)netif_do_rmv_ipv6_addr(netif, &ifconfig_cmd->ip_addr);
562 }
563
564 if (ifconfig_cmd->option & IFCONFIG_OPTION_SET_NETMASK) {
565 ip_addr_set_val(&netmask, &(ifconfig_cmd->netmask));
566 /* check data valid */
567 if (!ip_addr_netmask_valid(ip_2_ip4(&netmask))) {
568 ERR_IFCONFIG_STRING_PUT(ret, "ifconfig: netmask is invalid!\n");
569 goto out;
570 }
571
572#if LWIP_DHCP
573 if (netif_dhcp_data(netif) && netif_dhcp_data(netif)->state != DHCP_STATE_OFF) {
574 (void)netif_dhcp_off(netif);
575 }
576#endif
577 if (netif_ip4_netmask(netif)->addr != ip_2_ip4(&netmask)->addr) {
578 /* lwip disallow two netif sit in same net at the same time */
579 loc_netif = netif_list;
580 while (loc_netif != NULL) {
581 if (loc_netif == netif) {
582 loc_netif = loc_netif->next;
583 continue;
584 }
585 if (ip_addr_cmp(&loc_netif->netmask, &netmask) &&
586 ip_addr_netcmp(&loc_netif->ip_addr, &netif->ip_addr, ip_2_ip4(&netmask))) {
587 ERR_IFCONFIG_STRING_PUT(ret, "Duplicate network!\n");
588 goto out;
589 }
590 loc_netif = loc_netif->next;
591 }
592 netif_set_netmask(netif, ip_2_ip4(&netmask));
593 /* check if gateway still reachable */
594 if (!ip_addr_netcmp(&netif->gw, &netif->ip_addr, ip_2_ip4(&netmask))) {
595 ip_addr_set_zero(&(netif->gw));
596 if (netif == netif_default) {
597 (void)netif_set_default(NULL);
598 }
599 }
600 }
601 }
602
603 if ((ifconfig_cmd->option & IFCONFIG_OPTION_SET_HW) &&
604 netif_set_hwaddr(netif, ifconfig_cmd->ethaddr, NETIF_MAX_HWADDR_LEN) != ERR_OK) {
605 ERR_IFCONFIG_STRING_PUT(ret, "Failed to update the hwaddr of the device!\n");
606 (void)netif_set_up(netif);
607 goto out;
608 }
609
610 if ((ifconfig_cmd->option & IFCONFIG_OPTION_SET_IP) ||
611 (ifconfig_cmd->option & IFCONFIG_OPTION_SET_NETMASK) ||
612 (ifconfig_cmd->option & IFCONFIG_OPTION_SET_HW)) {
613 (void)netif_set_up(netif);
614 }
615
616 if (ifconfig_cmd->option & IFCONFIG_OPTION_SET_GW) {
617 ip_addr_set_val(&gw, &ifconfig_cmd->gw);
618
619 /* check the address multicast/0/loopback */
620 if (ip_addr_ismulticast_val(&gw) || ip_addr_isbroadcast_val(&gw, netif) ||
621 ip_addr_isany(&gw) || ip_addr_isloopback(&gw)) {
622 ERR_IFCONFIG_STRING_PUT(ret, "Don't set gateway as a multicast/broadcast/0/loopback address!\n");
623 goto out;
624 }
625
626 /* check if reachable */
627 if (!ip_addr_netcmp_val(&gw, &netif->ip_addr, ip_2_ip4(&netif->netmask))) {
628 ERR_IFCONFIG_STRING_PUT(ret, "The address is unreachable!\n");
629 goto out;
630 }
631
632 if (netif_default != netif) {
633 ip_addr_set_zero(&netif->gw);
634 (void)netif_set_default(netif);
635 }
636
637#if LWIP_DHCP
638 if (netif_dhcp_data(netif) && netif_dhcp_data(netif)->state != DHCP_STATE_OFF) {
639 (void)netif_dhcp_off(netif);
640 }
641#endif
642 netif_set_gw(netif, ip_2_ip4(&gw));
643 }
644
645 if (ifconfig_cmd->option & IFCONFIG_OPTION_SET_MTU) {
646 mtu = ifconfig_cmd->mtu;
647 if (netif_set_mtu(netif, mtu) != ERR_OK) {
648 ERR_IFCONFIG_STRING_PUT(ret, "Invalid MTU\n");
649 }
650 }
651out:
652 sys_sem_signal(&ifconfig_cmd->cb_completed);
653}
err_t netif_set_hwaddr(struct netif *netif, const unsigned char *hw_addr, int hw_len)
Definition: fixme.c:297
err_t netif_dhcp_off(struct netif *netif)
Definition: fixme.c:54
err_t netif_do_rmv_ipv6_addr(struct netif *netif, void *arguments)
Definition: fixme.c:165
err_t netif_set_mtu(struct netif *netif, u16_t netif_mtu)
Definition: fixme.c:270
char iface[IFNAMSIZ]
Definition: api_shell.c:238
ip_addr_t gw
Definition: api_shell.c:242
ip_addr_t netmask
Definition: api_shell.c:241
sys_sem_t cb_completed
Definition: api_shell.c:248
unsigned int option
Definition: api_shell.c:239
ip_addr_t ip_addr
Definition: api_shell.c:240
unsigned char ethaddr[6]
Definition: api_shell.c:243
函数调用图:
这是这个函数的调用关系图:

◆ lwip_ifconfig_show_internal()

LWIP_STATIC void lwip_ifconfig_show_internal ( void arg)

在文件 api_shell.c429 行定义.

430{
431 struct netif *netif = NULL;
432 struct ifconfig_option *ifconfig_cmd = (struct ifconfig_option *)arg;
433 int ret;
434
435 if (netif_list == NULL) {
436 ret = snprintf_s(ifconfig_cmd->cb_print_buf, PRINT_BUF_LEN - ifconfig_cmd->print_len,
437 ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), "Device not init\n");
438 if ((ret > 0) && ((unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) {
439 ifconfig_cmd->print_len += (unsigned int)ret;
440 }
441 sys_sem_signal(&ifconfig_cmd->cb_completed);
442 return;
443 }
444
445 if (ifconfig_cmd->iface[0] == '\0') {
446 /* display all netif */
447 for (netif = netif_list; netif != NULL; netif = netif->next) {
448 ret = print_netif(netif, ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len,
449 PRINT_BUF_LEN - ifconfig_cmd->print_len);
450 ifconfig_cmd->print_len += (unsigned int)ret;
451 }
452 } else {
453 netif = netif_find(ifconfig_cmd->iface);
454 if (netif == NULL) {
455 ret = snprintf_s(ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len,
456 (PRINT_BUF_LEN - ifconfig_cmd->print_len),
457 ((PRINT_BUF_LEN - ifconfig_cmd->print_len) - 1), "Device not found\n");
458 if ((ret > 0) && ((unsigned int)ret < (PRINT_BUF_LEN - ifconfig_cmd->print_len))) {
459 ifconfig_cmd->print_len += (unsigned int)ret;
460 }
461
462 sys_sem_signal(&ifconfig_cmd->cb_completed);
463 return;
464 }
465
466 ret = print_netif(netif, ifconfig_cmd->cb_print_buf + ifconfig_cmd->print_len,
467 PRINT_BUF_LEN - ifconfig_cmd->print_len);
468 ifconfig_cmd->print_len += (unsigned int)ret;
469 }
470 sys_sem_signal(&ifconfig_cmd->cb_completed);
471}
LWIP_STATIC int print_netif(struct netif *netif, char *print_buf, unsigned int buf_len)
Definition: api_shell.c:269
unsigned int print_len
Definition: api_shell.c:250
char cb_print_buf[PRINT_BUF_LEN]
Definition: api_shell.c:249
函数调用图:
这是这个函数的调用关系图:

◆ lwip_ifconfig_usage()

LWIP_STATIC void lwip_ifconfig_usage ( const char *  cmd)

在文件 api_shell.c671 行定义.

672{
673 PRINTK("Usage:"\
674 "\n%s [-a] "\
675 "\n[interface]"\
676 "\n[interface ipaddr] <netmask mask> <gateway gw>"\
677 "\n[interface inet6 add|del ipaddr]"\
678 "\n[interface hw ether MAC]"\
679 "\n[interface mtu NN]"\
680 "\n[interface up|down]\n",
681 cmd);
682}
这是这个函数的调用关系图:

◆ lwip_ping_usage()

static void lwip_ping_usage ( void  )
static

在文件 api_shell.c1563 行定义.

1564{
1565 PRINTK("Usage:"\
1566 "\n ping"
1567 "\n ping [-n cnt] [-w interval] [-l data_len] destination"
1568 "\n ping [-t] [-w interval] destination"
1569 "\n ping -k");
1570 PRINTK("\n -t means ping forever, user can use -k to stop the forever ping\n");
1571}
这是这个函数的调用关系图:

◆ lwip_printsize()

void lwip_printsize ( size_t  size)

在文件 api_shell.c656 行定义.

657{
658 static const char *SIZES[] = {"B", "KB", "MB", "GB"};
659 size_t divis = 0;
660 size_t rem = 0;
661
662 while ((size >= 1024) && (divis < ((sizeof(SIZES) / sizeof(char *)) - 1))) {
663 rem = (size % 1024);
664 divis++;
665 size /= 1024;
666 }
667
668 PRINTK("(%.1f %s) \r\n", (float)size + (float)rem / 1024.0, SIZES[divis]);
669}
这是这个函数的调用关系图:

◆ netdebug_memp()

LWIP_STATIC u32_t netdebug_memp ( int  argc,
const char **  argv 
)
这是这个函数的调用关系图:

◆ netdebug_sock()

LWIP_STATIC u32_t netdebug_sock ( int  argc,
const char **  argv 
)
这是这个函数的调用关系图:

◆ netstat_get_udp_sendQLen()

int netstat_get_udp_sendQLen ( struct udp_pcb *  udppcb,
struct pbuf *  udpbuf 
)

在文件 api_shell.c2802 行定义.

函数调用图:
这是这个函数的调用关系图:

◆ netstat_get_udp_sendQLen6()

int netstat_get_udp_sendQLen6 ( struct udp_pcb *  udppcb,
struct pbuf *  udpbuf 
)

在文件 api_shell.c2710 行定义.

2711{
2712 int sendLen = -1;
2713 u16_t offset = 0, len;
2714 struct ip6_hdr *iphdr = NULL;
2715 struct udp_hdr *udphdr = NULL;
2716 struct ip6_dest_hdr *dest_hdr = NULL;
2717 struct ip6_frag_hdr *frag_hdr = NULL;
2718 u8_t nexth;
2719 u16_t hlen = 0;
2720
2721 LWIP_ERROR("netstat_get_udp6_sendQLen: NULL pcb received\n", (udppcb != NULL), return -1);
2722 LWIP_ERROR("netstat_get_udp6_sendQLen: NULL pbuf received\n", (udpbuf != NULL), return -1);
2723
2724 iphdr = (struct ip6_hdr *)udpbuf->payload;
2725
2726 if (!(ip6_addr_cmp(&iphdr->dest, ip_2_ip6(&udppcb->remote_ip)) &&
2727 (ip_addr_isany(&udppcb->local_ip) ||
2728 ip6_addr_cmp(&iphdr->src, ip_2_ip6(&udppcb->local_ip))))) {
2729 goto FUNC_OUT;
2730 }
2731
2732 len = IP6_HLEN;
2733 if (pbuf_header(udpbuf, (s16_t)(-(s16_t)(len)))) {
2734 goto FUNC_OUT;
2735 }
2736
2737 offset = len;
2738
2739 nexth = IP6H_NEXTH(iphdr);
2740 while (offset < udpbuf->tot_len) {
2741 if (nexth == IP6_NEXTH_NONE || nexth == IP6_NEXTH_UDP || nexth == IP6_NEXTH_UDPLITE) {
2742 break;
2743 }
2744 switch (nexth) {
2745 case IP6_NEXTH_HOPBYHOP:
2746 case IP6_NEXTH_ROUTING:
2747 nexth = *((u8_t *)udpbuf->payload);
2748 hlen = (u16_t)(8 * (1 + *((u8_t *)udpbuf->payload + 1)));
2749 break;
2750 case IP6_NEXTH_DESTOPTS:
2751 nexth = *((u8_t *)udpbuf->payload);
2752 dest_hdr = (struct ip6_dest_hdr *)udpbuf->payload;
2753 hlen = (u16_t)(8 * (1 + dest_hdr->_hlen));
2754 break;
2755 case IP6_NEXTH_FRAGMENT:
2756 frag_hdr = (struct ip6_frag_hdr *)udpbuf->payload;
2757 nexth = frag_hdr->_nexth;
2758 hlen = IP6_FRAG_HLEN;
2759 break;
2760 default:
2761 /* Unknown next_header */
2762 goto FUNC_OUT;
2763 }
2764
2765 (void)pbuf_header(udpbuf, (s16_t)(-(s16_t)hlen));
2766 offset = (u16_t)(offset + hlen);
2767 }
2768
2769 /* If the while loop test condition failed , then revert the last offset change */
2770 if (offset >= udpbuf->tot_len) {
2771 offset = (u16_t)(offset - hlen);
2772 goto FUNC_OUT;
2773 }
2774
2775 LWIP_ERROR("Transport option should be UDP", (nexth == IP6_NEXTH_UDP || nexth == IP6_NEXTH_UDPLITE), goto FUNC_OUT);
2776
2777 if (offset > iphdr->_plen) {
2778 goto FUNC_OUT;
2779 }
2780
2781 /* check if there is enough space for atleast udp header available */
2782 if (udpbuf->tot_len < UDP_HLEN) {
2783 goto FUNC_OUT;
2784 }
2785
2786 udphdr = (struct udp_hdr *)udpbuf->payload;
2787 if ((ntohs(udphdr->dest) == udppcb->remote_port) && (ntohs(udphdr->src) == udppcb->local_port)) {
2788 if (ntohs(udphdr->len) > UDP_HLEN) {
2789 sendLen = ntohs(udphdr->len) - UDP_HLEN;
2790 } else {
2791 sendLen = udpbuf->tot_len - UDP_HLEN;
2792 }
2793 }
2794
2795FUNC_OUT:
2796 (void)pbuf_header(udpbuf, (s16_t)offset); // can not cross max limit of s16_t
2797 return sendLen;
2798}
if(tv==NULL)
Definition: time.c:430
函数调用图:
这是这个函数的调用关系图:

◆ netstat_netconn_recvq()

int netstat_netconn_recvq ( const struct netconn *  conn)
这是这个函数的调用关系图:

◆ netstat_netconn_sendq()

int netstat_netconn_sendq ( struct netconn *  conn)
这是这个函数的调用关系图:

◆ netstat_tcp_recvq()

int netstat_tcp_recvq ( struct tcp_pcb *  tpcb)
这是这个函数的调用关系图:

◆ netstat_tcp_sendq()

int netstat_tcp_sendq ( struct tcp_pcb *  tpcb)
这是这个函数的调用关系图:

◆ netstat_udp_sendq()

int netstat_udp_sendq ( struct udp_pcb *  upcb)
这是这个函数的调用关系图:

◆ netstat_udp_sendq6()

int netstat_udp_sendq6 ( struct udp_pcb *  upcb)
这是这个函数的调用关系图:

◆ osPingFunc()

LWIP_STATIC int osPingFunc ( u32_t  destip,
u32_t  cnt,
u32_t  interval,
u32_t  data_len 
)

在文件 api_shell.c1573 行定义.

1574{
1575 int sfd;
1576 struct sockaddr_in to;
1577 struct pbuf *pbuf_resp = NULL;
1578 struct icmp_echo_hdr *iecho = NULL;
1579 struct icmp_echo_hdr *iecho_resp = NULL;
1580 struct ip_hdr *iphdr_resp = NULL;
1581 u32_t iecho_len;
1582 s16_t ip_hlen;
1583 u32_t forever;
1584 u32_t i = 0;
1585 u32_t succ_cnt = 0;
1586 u32_t failed_cnt = 0;
1587 struct timespec start, end;
1588 long timout_ms = 0;
1589 struct pollfd pfd;
1590 long rtt;
1591 int ret = 0;
1592 u32_t intrvl = 0;
1593 char *data_buf = NULL;
1594 BOOL timeout_flag = false;
1595 char buf[50];
1596
1597 iecho_len = sizeof(struct icmp_echo_hdr) + data_len;
1598 sfd = lwip_socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
1599 if (sfd < 0) {
1600 perror("Ping socket");
1601 return -1;
1602 }
1603 pbuf_resp = pbuf_alloc(PBUF_RAW, IP_HLEN + sizeof(struct icmp_echo_hdr), PBUF_RAM);
1604 if (pbuf_resp == NULL) {
1605 PRINTK("Ping: pbuf_resp malloc failed\n");
1606 ret = -1;
1607 goto FAILURE;
1608 }
1609 iecho = (struct icmp_echo_hdr *)mem_malloc(iecho_len);
1610 if (iecho == NULL) {
1611 PRINTK("Ping: echo request malloc failed\n");
1612 ret = -1;
1613 goto FAILURE;
1614 }
1615
1616 to.sin_family = AF_INET;
1617 to.sin_addr.s_addr = destip; /* already in network order */
1618 to.sin_port = 0;
1619
1620 if (data_len > PING_ZERO_DATA_LEN) {
1621 (void)memset_s(iecho, sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN,
1622 0, sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN);
1623 data_buf = (char *)iecho + sizeof(struct icmp_echo_hdr) + PING_ZERO_DATA_LEN;
1624 for (i = 0; i < data_len - PING_ZERO_DATA_LEN; i++) {
1625 *(data_buf + i) = i + 0x10;
1626 }
1627 } else {
1628 (void)memset_s(iecho, sizeof(struct icmp_echo_hdr) + data_len, 0, sizeof(struct icmp_echo_hdr) + data_len);
1629 }
1630 iecho->id = htons((u16_t)LOS_CurTaskIDGet());
1631 ICMPH_TYPE_SET(iecho, (u8_t)ICMP_ECHO);
1632 forever = (cnt ? 0 : 1);
1633 i = 0;
1634 while (!ping_kill && (forever || (i < cnt))) {
1635 iecho->seqno = htons((u16_t)i);
1636 iecho->chksum = 0;
1637 iecho->chksum = inet_chksum((void *)iecho, iecho_len);
1638
1639 ret = sendto(sfd, iecho, iecho_len, 0, (struct sockaddr *)&to, (socklen_t)sizeof(to));
1640 if (ret < 0) {
1641 perror("Ping: sending ICMP echo request failed\n");
1642 goto FAILURE;
1643 }
1644
1645 /* capture the start time to calculate RTT */
1646 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &start);
1647
1648 /* poll for ICMP echo response msg */
1649 pfd.fd = sfd;
1650
1651 do {
1652 pfd.events = POLLIN;
1653 pfd.revents = 0;
1654 timeout_flag = false;
1655 ret = poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT);
1656 if (ret < 0) {
1657 perror("Ping: poll\n");
1658 goto FAILURE;
1659 } else if (ret == 0) {
1660 /* first type timeout event */
1661 timeout_flag = true;
1662 break;
1663 }
1664
1665 ret = recv(sfd, pbuf_resp->payload, pbuf_resp->len, MSG_DONTWAIT);
1666 if (ret < 0) {
1667 perror("Ping: recv echo reply failed\n");
1668 goto FAILURE;
1669 }
1670
1671 /* Accessing ip header and icmp header */
1672 iphdr_resp = pbuf_resp->payload;
1673
1674 ip_hlen = (IPH_HL(iphdr_resp) << 2);
1675 if (pbuf_header(pbuf_resp, -ip_hlen)) {
1676 /* this failure will never happen, but failure handle is written just to be in safe side */
1677 PRINTK("Ping : memory management failure\n");
1678 goto FAILURE;
1679 }
1680 iecho_resp = (struct icmp_echo_hdr *)pbuf_resp->payload;
1681 /* Reverting back pbuf to its original state */
1682 if (pbuf_header(pbuf_resp, ip_hlen)) {
1683 /* this failure will never happen, but failure handle is written just to be in safe side */
1684 PRINTK("ping : memory management failure\n");
1685 goto FAILURE;
1686 }
1687
1688 if ((iphdr_resp->src.addr != to.sin_addr.s_addr) ||
1689 ((ICMPH_TYPE(iecho_resp) == ICMP_ECHO) && (iphdr_resp->src.addr == to.sin_addr.s_addr))) {
1690 /* second type timeout event */
1691 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
1692 timout_ms = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
1693 timout_ms = LWIP_SHELL_CMD_PING_TIMEOUT - timout_ms;
1694 } else {
1695 timout_ms = 0;
1696 break;
1697 }
1698 } while (timout_ms >= 0);
1699
1700 /* all timeout events are true timeout */
1701 if ((timout_ms < 0) || (timeout_flag == true)) {
1702 failed_cnt++;
1703 i++;
1704 PRINTK("\nPing: destination unreachable ...");
1705 continue;
1706 }
1707 /* capture the end time to calculate round trip time */
1708 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
1709 rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
1710
1711 if (iphdr_resp->src.addr == to.sin_addr.s_addr) {
1712 switch (ICMPH_TYPE(iecho_resp)) {
1713 case ICMP_ER:
1714 PRINTK("\n[%u]Reply from %s: ", i, inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf)));
1715 if (rtt > 0) {
1716 PRINTK("time=%ims ", rtt);
1717 } else {
1718 PRINTK("time<1ms ");
1719 }
1720 PRINTK("TTL=%u", iphdr_resp->_ttl);
1721
1722 /* delay 1s for every successful ping */
1723 intrvl = interval;
1724 do {
1725 if (intrvl < 1000) {
1726 sys_msleep(intrvl);
1727 break;
1728 }
1729 intrvl -= 1000;
1730 sys_msleep(1000);
1731 if (ping_kill == 1)
1732 break;
1733 } while (intrvl > 0);
1734 succ_cnt++;
1735 break;
1736 case ICMP_DUR:
1737 PRINTK("\nPing: destination host unreachable ...");
1738 break;
1739 case ICMP_SQ:
1740 PRINTK("\nPing: source quench ...");
1741 break;
1742 case ICMP_RD:
1743 PRINTK("\nPing: redirect ...");
1744 break;
1745 case ICMP_TE:
1746 PRINTK("\nPing: time exceeded ...");
1747 break;
1748 case ICMP_PP:
1749 PRINTK("\nPing: parameter problem ...");
1750 break;
1751 default :
1752 PRINTK("\nPing: unknown error ...");
1753 break;
1754 }
1755 i++;
1756 }
1757 }
1758
1759 PRINTK("\n--- %s ping statistics ---\n", inet_ntop(AF_INET, &to.sin_addr, buf, sizeof(buf)));
1760 PRINTK("%u packets transmitted, %u received, %u loss\n", i, succ_cnt, failed_cnt);
1761
1762FAILURE:
1763 ping_kill = 0;
1764 (void)lwip_close(sfd);
1765 if (pbuf_resp != NULL) {
1766 (void)pbuf_free(pbuf_resp);
1767 }
1768 if (iecho != NULL) {
1769 mem_free(iecho);
1770 }
1771 return ret;
1772}
static int ping_kill
Definition: api_shell.c:1561
LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
Obtain current running task ID.
Definition: los_task.c:331
size_t BOOL
Definition: los_typedef.h:88
ssize_t recv(int s, void *mem, size_t len, int flags)
Definition: socket.c:234
ssize_t sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
区别是送达地址,意思是这些数据要发给哪个地址的
Definition: socket.c:268
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
Definition: socket.c:323
int clock_gettime(clockid_t clockID, struct timespec *tp)
当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截;
Definition: time.c:614
函数调用图:
这是这个函数的调用关系图:

◆ osShellDns()

u32_t osShellDns ( int  argc,
const char **  argv 
)

在文件 api_shell.c2635 行定义.

2636{
2637 ip_addr_t dns = {0};
2638 err_t err;
2639 int i;
2640 if (argc < 1 || argv == NULL) {
2641 goto usage;
2642 }
2643
2644 if (tcpip_init_finish == 0) {
2645 PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
2646 return LOS_NOK;
2647 }
2648
2649 if (argc == 1 && (strcmp(argv[0], "-a") == 0)) {
2650 for (i = 0; i < DNS_MAX_SERVERS; i++) {
2651 err = lwip_dns_getserver((u8_t)i, &dns);
2652 if (err == ERR_OK) {
2653 PRINTK("dns %d: %s\n", i + 1, ipaddr_ntoa_unsafe(&dns));
2654 } else {
2655 PRINTK("dns: failed\n");
2656 return LOS_NOK;
2657 }
2658 }
2659 return LOS_OK;
2660 } else if (argc == 2) {
2661 i = atoi(argv[0]);
2662 if ((i <= 0) || (i > DNS_MAX_SERVERS))
2663 goto usage;
2664#if LWIP_IPV6
2665 if (ip6addr_aton(argv[1], ((ip6_addr_t *)&dns))) {
2666#if LWIP_IPV4 && LWIP_IPV6
2667 dns.type = IPADDR_TYPE_V6;
2668#endif
2669 if (!ip6_addr_isglobal((ip6_addr_t *)&dns)) {
2670 PRINTK("ip address<%s> is wrong\n", argv[1]);
2671 return LOS_NOK;
2672 }
2673 } else
2674#endif
2675 {
2676#if LWIP_IPV4
2677 ((ip4_addr_t *)&dns)->addr = ipaddr_addr(argv[1]);
2678 if (((ip4_addr_t *)&dns)->addr == IPADDR_NONE) {
2679 PRINTK("ip address<%s> is wrong\n", argv[1]);
2680 return LOS_NOK;
2681 }
2682#if LWIP_IPV4 && LWIP_IPV6
2683 dns.type = IPADDR_TYPE_V4;
2684#endif
2685#endif
2686 }
2687
2688 err = lwip_dns_setserver((u8_t)(i - 1), &dns);
2689 if (err != ERR_OK) {
2690 PRINTK("dns : failed\n");
2691 return LOS_NOK;
2692 }
2693 return LOS_OK;
2694 }
2695usage:
2696 PRINTK("usage:\n");
2697 PRINTK("\tdns <1-%d> <IP>\n", DNS_MAX_SERVERS);
2698 PRINTK("\tdns -a\n");
2699 return LOS_NOK;
2700}
err_t lwip_dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
Definition: fixme.c:345
err_t lwip_dns_getserver(u8_t numdns, ip_addr_t *dnsserver)
Definition: fixme.c:352
函数调用图:

◆ osShellIpDebug()

u32_t osShellIpDebug ( int  argc,
const char **  argv 
)
这是这个函数的调用关系图:

◆ osShellNetDebug()

u32_t osShellNetDebug ( int  argc,
const char **  argv 
)
这是这个函数的调用关系图:

◆ osShellNtpdate()

u32_t osShellNtpdate ( int  argc,
const char **  argv 
)

在文件 api_shell.c2590 行定义.

2591{
2592 int server_num = 0;
2593 char *ret = NULL;
2594 struct timeval get_time;
2595 char buf[50];
2596
2597 (void)memset_s(&get_time, sizeof(struct timeval), 0, sizeof(struct timeval));
2598
2599 if (!tcpip_init_finish) {
2600 PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
2601 return LOS_NOK;
2602 }
2603
2604 if (argc < 1 || argv == NULL) {
2605 goto usage;
2606 }
2607
2608 server_num = lwip_sntp_start(argc, (char **)argv, &get_time);
2609 if (server_num >= 0 && server_num < argc) {
2610 ret = ctime_r((time_t *)&get_time.tv_sec, buf);
2611 if (ret != NULL) {
2612 PRINTK("time server %s: %s\n", argv[server_num], ret);
2613 } else {
2614 PRINTK("ctime return null error\n");
2615 }
2616 } else {
2617 PRINTK("no server suitable for synchronization found\n");
2618 }
2619
2620 return LOS_OK;
2621
2622usage:
2623 PRINTK("\nUsage:\n");
2624 PRINTK("ntpdate [SERVER_IP1] [SERVER_IP2] ...\n");
2625 return LOS_NOK;
2626}
int lwip_sntp_start(int server_num, char **sntp_server, struct timeval *time)
Definition: fixme.c:379
函数调用图:

◆ osShellPing()

u32_t osShellPing ( int  argc,
const char **  argv 
)

在文件 api_shell.c1790 行定义.

1791{
1792 int ret;
1793 u32_t i = 0;
1794 u32_t count = 0;
1795 int count_set = 0;
1796 u32_t interval = 1000; /* default ping interval */
1797 u32_t data_len = 48; /* default data length */
1798 ip4_addr_t dst_ipaddr;
1799 TSK_INIT_PARAM_S stPingTask;
1800
1801 if (!tcpip_init_finish) {
1802 PRINTK("Ping: tcpip_init have not been called\n");
1803 return LOS_NOK;
1804 }
1805
1806 if ((argc < 1) || (argv == NULL)) {
1807 PRINTK("Ping: require dest ipaddr at least\n");
1808 goto ping_error;
1809 }
1810
1811 /* could add more param support */
1812 while (argc > 0) {
1813 if (strcmp("-n", argv[i]) == 0 && (argc > 1)) {
1814 ret = atoi(argv[i + 1]);
1815 if (ret <= 0) {
1816 PRINTK("Ping count should be greater than 0 \n");
1817 goto ping_error;
1818 }
1819 count = ret;
1820 count_set = 1;
1821 i += 2;
1822 argc -= 2;
1823 } else if (strcmp("-t", argv[i]) == 0) {
1824 count = 0; /* ping forerver */
1825 count_set = 1;
1826 i++;
1827 argc--;
1828 } else if (strcmp("-w", argv[i]) == 0 && (argc > 1)) {
1829 ret = atoi(argv[i + 1]);
1830 if (ret <= 0) {
1831 PRINTK("Ping interval should be greater than 0 \n");
1832 goto ping_error;
1833 }
1834
1835 interval = ret;
1836 i += 2;
1837 argc -= 2;
1838 } else if (strcmp("-l", argv[i]) == 0 && (argc > 1)) {
1839 ret = atoi(argv[i + 1]);
1840 if (ret < 0 || ret > (int)(LWIP_MAX_UDP_RAW_SEND_SIZE - sizeof(struct icmp_echo_hdr))) {
1841 PRINTK("Ping data length error, should be in range of [0, %d] \n",
1842 LWIP_MAX_UDP_RAW_SEND_SIZE - sizeof(struct icmp_echo_hdr));
1843 goto ping_error;
1844 }
1845 data_len = ret;
1846 i += 2;
1847 argc -= 2;
1848 } else if (strcmp("-k", argv[i]) == 0) {
1849 if (ping_taskid > 0) {
1850 ping_kill = 1; /* stop the current ping task */
1851 return LOS_OK;
1852 } else {
1853 PRINTK("No ping task running...\n");
1854 return LOS_NOK;
1855 }
1856 } else {
1857 if (argc == 1) {
1858 break;
1859 } else {
1860 PRINTK("Invalid Ping param\n");
1861 goto ping_error;
1862 }
1863 }
1864 }
1865
1866 if (!count_set) {
1867 count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
1868 }
1869
1870 /* initialize dst IP address */
1871 if (argc <= 0) {
1872 goto ping_error;
1873 }
1874#if LWIP_DNS
1875 dst_ipaddr.addr = get_hostip(argv[i]);
1876#else /* LWIP_DNS */
1877 dst_ipaddr.addr = inet_addr(argv[i]);
1878#endif /* LWIP_DNS */
1879
1880 if (dst_ipaddr.addr == IPADDR_NONE || dst_ipaddr.addr == IPADDR_ANY) {
1881 PRINTK("Invalid dest ipaddr: NONE or ANY\n");
1882 return LOS_NOK;
1883 }
1884
1885 /* start one task if ping forever or ping count greater than 60 */
1886 if (count == 0 || count > LWIP_SHELL_CMD_PING_RETRY_TIMES) {
1887 if (ping_taskid > 0) {
1888 PRINTK("Ping task already running and only support one now\n");
1889 return LOS_NOK;
1890 }
1891 stPingTask.pfnTaskEntry = (TSK_ENTRY_FUNC)ping_cmd;
1892 stPingTask.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
1893 stPingTask.pcName = "ping_task";
1894 stPingTask.usTaskPrio = 8; /* higher than shell */
1895 stPingTask.uwResved = LOS_TASK_STATUS_DETACHED;
1896 stPingTask.auwArgs[0] = dst_ipaddr.addr; /* network order */
1897 stPingTask.auwArgs[1] = count;
1898 stPingTask.auwArgs[2] = interval;
1899 stPingTask.auwArgs[3] = data_len;
1900 ret = LOS_TaskCreate((UINT32 *)(&ping_taskid), &stPingTask);
1901 if (ret != LOS_OK) {
1902 PRINTK("ping_task create failed 0x%08x.\n", ret);
1903 count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
1904 } else {
1905 return LOS_OK;
1906 }
1907 }
1908
1909 /* two cases:
1910 1, ping cout less than LWIP_SHELL_CMD_PING_RETRY_TIMES;
1911 2, ping task create failed;
1912 */
1913 if (osPingFunc(dst_ipaddr.addr, count, interval, data_len) < 0) {
1914 PRINTK("Ping cmd failed due some errors\n");
1915 }
1916
1917 return LOS_OK;
1918ping_error:
1920 return LOS_NOK;
1921}
static void lwip_ping_usage(void)
Definition: api_shell.c:1563
static void ping_cmd(unsigned int p0, unsigned int p1, unsigned int p2, unsigned int p3)
Definition: api_shell.c:1774
static int ping_taskid
Definition: api_shell.c:1560
LWIP_STATIC int osPingFunc(u32_t destip, u32_t cnt, u32_t interval, u32_t data_len)
Definition: api_shell.c:1573
LWIP_STATIC unsigned int get_hostip(const char *hname)
Definition: api_shell.c:1543
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务
Definition: los_task.c:718
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
Definition: los_task.h:480
unsigned int UINT32
Definition: los_typedef.h:57
UINT16 usTaskPrio
Definition: los_task.h:505
UINTPTR auwArgs[4]
Definition: los_task.h:507
UINT32 uwStackSize
Definition: los_task.h:508
CHAR * pcName
Definition: los_task.h:509
TSK_ENTRY_FUNC pfnTaskEntry
Definition: los_task.h:504
UINT32 uwResved
Definition: los_task.h:513
函数调用图:

◆ osShellPing6()

u32_t osShellPing6 ( int  argc,
const char **  argv 
)

在文件 api_shell.c2082 行定义.

2083{
2084 u16_t icmpv6_id;
2085 u16_t icmpv6_seq;
2086 u32_t nsent;
2087 u32_t nrecieve;
2088 u32_t last_received;
2089 struct timespec start, end, start_in_reply;
2090 struct timespec first, last;
2091 long rtt;
2092 int ret;
2093 fd_set fdReadSet;
2094 void *param = NULL;
2095 ping6_args_t ping6_params;
2097 struct sockaddr_in6 to;
2098 struct icmp6_echo_hdr *iecho_resp = NULL;
2099 struct icmp6_echo_hdr *iecho = NULL;
2100 struct timeval stTimeVal;
2101 struct timeval deltaTimeVal;
2102 struct pbuf *pbuf_resp = NULL;
2103 struct pbuf *pbuf_req = NULL;
2104 int sfd = -1;
2105 u8_t type;
2106 u8_t select_on_socket = 0;
2107 char buf[INET6_ADDRSTRLEN];
2108
2109 if (!tcpip_init_finish) {
2110 PRINTK("%s: tcpip_init have not been called\n", __FUNCTION__);
2111 ret = -1;
2112 goto exit;
2113 }
2114
2115 if ((argc < 1) || (argc > LWIP_MAX_PING6_ARG_COUNT) || (argv == NULL)) {
2116 goto usage;
2117 }
2118
2119 ret = parse_args_ping6(argc, argv, &ping6_params);
2120 if (ret == -1) {
2121 goto exit;
2122 }
2123
2124 if (ping6_params.args_found & LWIP_PING6_SOURCE_ADDRESS_ARG) {
2125 type = LWIP_PING6_SOURCE_ADDRESS_ARG;
2126 param = (void *)(&ping6_params.src_addr);
2127 } else if (ping6_params.args_found & LWIP_PING6_INTERFACE_ARG) {
2128 type = LWIP_PING6_INTERFACE_ARG;
2129 param = (void *)(argv[ping6_params.interface_index]);
2130 } else {
2131 type = LWIP_PING6_DEFAULT_SOCKET;
2132 param = NULL;
2133 }
2134
2135 /* Create a socket for sending and receiving pings with appropriate bindings */
2136 sfd = create_ping6_socket(type, param);
2137 if (sfd == -1) {
2138 ret = -1;
2139 goto exit;
2140 }
2141
2142 pbuf_req = pbuf_alloc(PBUF_RAW, LWIP_PING6_STANDARD_PKT_SIZE, PBUF_RAM);
2143 pbuf_resp = pbuf_alloc(PBUF_RAW, LWIP_PING6_STANDARD_PKT_SIZE, PBUF_RAM);
2144 if ((pbuf_resp == NULL) || (pbuf_req == NULL)) {
2145 PRINTK("ping6 : Memory Allocation Failed\n");
2146 ret = -1;
2147 goto exit;
2148 }
2149
2150 to.sin6_family = AF_INET6;
2151 inet6_addr_from_ip6addr(&to.sin6_addr, &(ping6_params.dst_addr));
2152 to.sin6_port = htons(IPPROTO_ICMPV6);
2153
2154#if LWIP_DNS
2155 if (lwip_strnicmp(inet_ntop(AF_INET6, &to.sin6_addr, buf, sizeof(buf)), argv[ping6_params.host_index],
2156 sizeof(to.sin6_addr))) {
2157 /* If There Was A DNS Resolution */
2158 PRINTK("PING %s (%s) with %d bytes of data.\n",
2159 argv[ping6_params.host_index], buf, LWIP_PING6_STANDARD_PKT_SIZE);
2160 } else {
2161 PRINTK("PING %s with %d bytes of data.\n", buf, LWIP_PING6_STANDARD_PKT_SIZE);
2162 }
2163#else
2164 PRINTK("PING %s with %d bytes of data\n", inet_ntop(AF_INET6, &to.sin6_addr, buf, sizeof(buf)), LWIP_PING6_STANDARD_PKT_SIZE);
2165#endif /* LWIP_DNS */
2166
2167 nrecieve = 0;
2168 ping6_stats.flag = 0;
2169 ping6_stats.avg_rtt = 0;
2170 ping6_stats.max_rtt = 0;
2171 ping6_stats.min_rtt = 0;
2172 last_received = LWIP_PING6_STARTING_SEQ_NUM + LWIP_PING6_OUT_OF_ORDER_MAGNITUDE + 1;
2173 icmpv6_id = (u16_t)LWIP_RAND();
2174 icmpv6_seq = LWIP_PING6_STARTING_SEQ_NUM;
2175 /* Setting the start time of the entire ping task for statistics */
2176 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &first);
2177
2178 nsent = 0;
2179
2180 for (nsent = 0; nsent < ping6_params.pingcount; nsent++) {
2181 /* capture the start tick to calculate rtt */
2182 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &start);
2183 /* Initialize Memory To Prevent Unintialized Memory Read Write Issues */
2184 if (memset_s(pbuf_req->payload, pbuf_req->len, (int)(start.tv_nsec), pbuf_req->len) != 0) {
2185 goto exit;
2186 }
2187
2188 iecho = (struct icmp6_echo_hdr *)pbuf_req->payload;
2189 iecho->type = ICMP6_TYPE_EREQ;
2190 iecho->id = icmpv6_id;
2191 icmpv6_seq++;
2192 iecho->seqno = icmpv6_seq;
2193 iecho->code = 0;
2194
2195 /* Embedding the start_tick as data into the icmp_payload */
2196 (void)pbuf_header(pbuf_req, (s16_t)(-(s16_t)(sizeof(struct icmp6_echo_hdr))));
2197 if (memcpy_s(pbuf_req->payload, pbuf_req->len, (void *)&start, sizeof(start)) != 0) {
2198 goto exit;
2199 }
2200 (void)pbuf_header(pbuf_req, (s16_t)((s16_t)(sizeof(struct icmp6_echo_hdr))));
2201
2202 ret = lwip_sendto(sfd, iecho, pbuf_req->len, 0, (struct sockaddr *)&to, (socklen_t)sizeof(to));
2203 if (ret == -1) {
2204 PRINTK("ping6 : Sending ICMP Echo message failed\n");
2205 goto exit;
2206 }
2207
2208 /* Wait in select for ICMP response msg */
2209 FD_ZERO(&fdReadSet);
2210 FD_SET(sfd, &fdReadSet);
2211 stTimeVal.tv_sec = LWIP_MSECS_TO_SECS(LWIP_SHELL_CMD_PING_TIMEOUT);
2212 stTimeVal.tv_usec = 0;
2213 select_on_socket = 1;
2214
2215 while (select_on_socket) {
2216 select_on_socket = 0;
2217 ret = select(sfd + 1, &fdReadSet, 0, 0, &stTimeVal);
2218 if (ret < 0) {
2219 PRINTK("ping6 : select failure\n");
2220 goto exit;
2221 } else if (ret == 0) {
2222 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
2223 PRINTK("Request timed out\n");
2224 continue;
2225 }
2226
2227 /* capture the end time to calculate round trip time */
2228 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &end);
2229
2230 ret = lwip_recv(sfd, pbuf_resp->payload, pbuf_resp->len, 0);
2231 if (ret == -1) {
2232 PRINTK("ping6 : receiving ICMP echo response msg failed\n");
2233 goto exit;
2234 }
2235
2236 if ((u32_t)ret < sizeof(struct icmp6_echo_hdr *)) {
2237 /* Drop the packet if its too short [Doesnot contain even the header !!] */
2238 PRINTK("ping6 : received ICMP echo response too short\n");
2239 goto REDUCE_SELECT_TIME;
2240 }
2241
2242 /* Acceping the ICMPv6 payload. */
2243 /* Here, pbuf_resp->payload wont contain IPv6 Header since its an AF_INET6 RAW Socket */
2244 iecho_resp = (struct icmp6_echo_hdr *)pbuf_resp->payload;
2245
2246 if (iecho_resp->id == icmpv6_id) {
2247 if (iecho_resp->type == ICMP6_TYPE_EREP) {
2248 if (ret < LWIP_PING6_STANDARD_PKT_SIZE) {
2249 /* Drop the packet if its too short */
2250 PRINTK("ping6 : received ICMP echo response too short\n");
2251 goto REDUCE_SELECT_TIME;
2252 }
2253 /* Accept and process only those delayed EREP only if its sequence num is within out-of-order magnitude */
2254 if (nsent && iecho_resp->seqno != icmpv6_seq &&
2255 (iecho_resp->seqno<(u16_t)(last_received - LWIP_PING6_OUT_OF_ORDER_MAGNITUDE) ||
2256 iecho_resp->seqno>(u16_t)(
2257 last_received + LWIP_PING6_OUT_OF_ORDER_MAGNITUDE))) {
2258 /* Otherwise drop it and wait for more packets */
2259 goto REDUCE_SELECT_TIME;
2260 }
2261 ++nrecieve;
2262 last_received = iecho_resp->seqno;
2263 /* Retrieving the start_tick from the packet which was embedded when the request was transmitted */
2264 (void)pbuf_header(pbuf_resp, (s16_t)(-(s16_t)(sizeof(struct icmp6_echo_hdr))));
2265 if (memcpy_s((void *)&start_in_reply, sizeof(start_in_reply),
2266 pbuf_resp->payload, sizeof(start_in_reply)) != EOK) {
2267 goto REDUCE_SELECT_TIME;
2268 }
2269 (void)pbuf_header(pbuf_resp, (s16_t)((s16_t)(sizeof(struct icmp6_echo_hdr))));
2270
2271 rtt = ((end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000);
2272
2273 PRINTK("%d bytes from %s : icmp_seq=%d time", ret,
2274 inet_ntop(AF_INET6, &to.sin6_addr, buf, sizeof(buf)),
2275 ((iecho_resp->seqno) - LWIP_PING6_STARTING_SEQ_NUM));
2276 if (rtt < 1) {
2277 PRINTK("<1 ms\n");
2278 } else {
2279 PRINTK("=%i ms\n", rtt);
2280 }
2281
2282 update_ping6_stats(&ping6_stats, (u32_t)(rtt), nrecieve);
2283
2284 /* Checking if its a delayed packet */
2285 if ((iecho_resp->seqno != icmpv6_seq) && (nsent < ping6_params.pingcount)) {
2286 /* Incase of delayed packet wait on socket for other response before sending a new PING */
2287 /* We have to reduce the timeout value now when selecting on socket */
2288 goto REDUCE_SELECT_TIME;
2289 }
2290 } else {
2291 PRINTK("[%u]ping6 : %s\n", nsent, convert_icmpv6_err_to_string(iecho_resp->type));
2292 }
2293 } else {
2294 /* If incoming packet does not matches with icmp_id, it should be ignored */
2295 /* Reduce the timeout for select on socket */
2296REDUCE_SELECT_TIME:
2297 deltaTimeVal.tv_sec = (long)(end.tv_sec - start.tv_sec);
2298 deltaTimeVal.tv_usec = (long)((end.tv_nsec - start.tv_nsec) / 1000);
2299 /* Subtract deltaTime from stTime and store in stTime */
2300 /* This will reduce the select time on the socket */
2301 timersub(&stTimeVal, &deltaTimeVal, &stTimeVal);
2302 select_on_socket = 1;
2303 }
2304 }
2305 }
2306
2307 ret = ERR_OK;
2308
2309 (void)clock_gettime(CLOCK_MONOTONIC_RAW, &last);
2310 /* Display ping stats */
2311 PRINTK("--- %s ping statistics ---\n", argv[ping6_params.host_index]);
2312 PRINTK("%d packets transmitted, %d received, %.2f%% packet loss, time %dms\n",
2313 nsent, nrecieve, (float)(((float)(nsent - nrecieve)) * ((float)(100)) / ((float)(nsent))),
2314 ((last.tv_sec - first.tv_sec) * 1000 + (last.tv_nsec - first.tv_nsec) / 1000000));
2315 if (nrecieve) {
2316 /* Display rtt stats only if atleast one packet is recieved */
2317 PRINTK("rtt min/avg/max = %u/%.2f/%u ms\n", ping6_stats.min_rtt, ping6_stats.avg_rtt, ping6_stats.max_rtt);
2318 }
2319
2320exit:
2321 if (sfd != -1) {
2322 (void)lwip_close(sfd);
2323 }
2324
2325 if (pbuf_resp != NULL) {
2326 (void)pbuf_free(pbuf_resp);
2327 }
2328
2329 if (pbuf_req != NULL) {
2330 (void)pbuf_free(pbuf_req);
2331 }
2332 return (u32_t)((ret == (int)ERR_OK) ? LOS_OK : LOS_NOK);
2333
2334usage:
2335 PRINTK("Usage:\n");
2336 PRINTK("\tping6 [-c count] [-I interface/sourceAddress] destination\n");
2337 return LOS_NOK;
2338}
LWIP_STATIC const char * convert_icmpv6_err_to_string(u8_t err_type)
Definition: api_shell.c:2567
LWIP_STATIC void update_ping6_stats(ping6_stats_t *ping6_stats, u32_t rtt, u32_t nreceived)
Definition: api_shell.c:2552
LWIP_STATIC int create_ping6_socket(u8_t type, const void *param)
Definition: api_shell.c:2340
LWIP_STATIC int parse_args_ping6(int argc, const char **argv, ping6_args_t *ping6_params)
Definition: api_shell.c:2402
ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
Definition: sockets.c:90
void exit(int status)
Definition: stdlib.c:60
u8_t args_found
Definition: api_shell.c:154
ip6_addr_t src_addr
Definition: api_shell.c:159
u8_t host_index
Definition: api_shell.c:156
u32_t pingcount
Definition: api_shell.c:158
ip6_addr_t dst_addr
Definition: api_shell.c:160
u8_t interface_index
Definition: api_shell.c:155
float avg_rtt
Definition: api_shell.c:168
u32_t min_rtt
Definition: api_shell.c:166
u32_t flag
Definition: api_shell.c:165
u32_t max_rtt
Definition: api_shell.c:167
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
函数调用图:

◆ osTcpserver()

u32_t osTcpserver ( int  argc,
const char **  argv 
)
这是这个函数的调用关系图:

◆ parse_args_ping6()

LWIP_STATIC int parse_args_ping6 ( int  argc,
const char **  argv,
ping6_args_t ping6_params 
)

在文件 api_shell.c2402 行定义.

2403{
2404 int pingcount;
2405 int ret = -1;
2406#if LWIP_DNS
2407 struct addrinfo *res = NULL;
2408 struct addrinfo hints_structure;
2409#endif
2410 u8_t i = 0;
2411
2412 IP6_ADDR(&(ping6_params->dst_addr), 0, 0, 0, 0);
2413 IP6_ADDR(&(ping6_params->src_addr), 0, 0, 0, 0);
2414
2415 ping6_params->pingcount = LWIP_SHELL_CMD_PING_RETRY_TIMES;
2416 ping6_params->host_index = 0;
2417 ping6_params->args_found = 0;
2418
2419 while (i < argc) {
2420 if (strcmp("-c", argv[i]) == 0) {
2421 /* Handle number of ICMP packets to transmit :: -c [number_of_packets] */
2422 if (ping6_params->args_found & LWIP_PING6_COUNT_ARG) {
2423 PRINTK("ping6: -c option present multiple times \n");
2424 ret = -1;
2425 goto exit;
2426 }
2427
2428 if (i + 2 > argc) {
2429 PRINTK("ping6: ping count(-c) should require an argument \n");
2430 ret = -1;
2431 goto exit;
2432 }
2433
2434 pingcount = atoi(argv[i + 1]);
2435 if (pingcount <= 0) {
2436 PRINTK("ping6: bad number of packets to transmit \n");
2437 ret = -1;
2438 goto exit;
2439 }
2440
2441 ping6_params->args_found |= LWIP_PING6_COUNT_ARG;
2442 ping6_params->pingcount = (u32_t)pingcount;
2443 i = (u8_t)(i + 2);
2444 } else if (strcmp("-I", argv[i]) == 0) {
2445 /* Handle interface ID / sourceAddress using which the ICMP Packets has to be transmitted :: -I [interface_id/source_address] */
2446
2447 if ((ping6_params->args_found & LWIP_PING6_SOURCE_ADDRESS_ARG) ||
2448 (ping6_params->args_found & LWIP_PING6_INTERFACE_ARG)) {
2449 PRINTK("ping6: -I option present multiple times \n");
2450 ret = -1;
2451 goto exit;
2452 }
2453
2454 if (i + 2 > argc) {
2455 PRINTK("ping6: interface/source address(-I) should require an argument \n");
2456 ret = -1;
2457 goto exit;
2458 }
2459
2460 /* Check whether the given argument to -I is source address */
2461 if (ip6addr_aton(argv[i + 1], &(ping6_params->src_addr))) {
2462 ping6_params->args_found |= LWIP_PING6_SOURCE_ADDRESS_ARG;
2463 i = (u8_t)(i + 2);
2464 continue;
2465 }
2466
2467 /* Storing the index where interface name is found */
2468 /* If this name is not valid, then it will fail later in setsockopt(BIND_TO_DEVICE) */
2469 ping6_params->interface_index = (u8_t)(i + 1);
2470 ping6_params->args_found |= LWIP_PING6_INTERFACE_ARG;
2471
2472 i = (u8_t)(i + 2);
2473 } else {
2474 if (argv[i][0] == '-') {
2475 /* Check whether its a bad option */
2476 PRINTK("ping6: bad option %s\n", argv[i]);
2477 ret = -1;
2478 goto exit;
2479 } else if (ping6_params->args_found & LWIP_PING6_HOSTNAME_ARG) {
2480 /* Check whether hostname is already found and there are extra arguments */
2481 PRINTK("ping6: bad parameter %s\n", argv[i]);
2482 ret = -1;
2483 goto exit;
2484 }
2485
2486#if LWIP_DNS
2487 /* Resolve the given hostname */
2488 hints_structure.ai_family = AF_INET6;
2489 hints_structure.ai_flags = 0;
2490 ret = lwip_getaddrinfo(argv[i], NULL, &hints_structure, &res);
2491 if (ret != ERR_OK) {
2492 PRINTK("ping6 : Host : %s can't be resolved to IPv6 address\n", argv[i]);
2493 ret = -1;
2494 goto exit;
2495 }
2496
2497 inet6_addr_to_ip6addr(&(ping6_params->dst_addr),
2498 &(((const struct sockaddr_in6 *)(res->ai_addr))->sin6_addr));
2499#else
2500 /* Convert the string representation to network form */
2501 if (!ip6addr_aton(argv[i], &(ping6_params->dst_addr))) {
2502 PRINTK("ping6 : Invalid IPv6 Address : %s\n", argv[i]);
2503 ret = -1;
2504 goto exit;
2505 }
2506#endif /* LWIP_DNS */
2507 if (ip6_addr_isany(&(ping6_params->dst_addr)) || ip6_addr_isnone(&(ping6_params->dst_addr))) {
2508#if LWIP_DNS
2509 PRINTK("ping6 : IPv6 address of host : %s (%s) is invalid\n", argv[i],
2510 ip6addr_ntoa((const ip6_addr_t *)&(ping6_params->dst_addr)));
2511#else
2512 PRINTK("ping6 : Invalid IPv6 address : %s\n", argv[i]);
2513#endif /* LWIP_DNS */
2514 goto exit;
2515 }
2516 /* Setting host_index to the index of argv[] where the host/IP is present */
2517 ping6_params->args_found |= LWIP_PING6_HOSTNAME_ARG;
2518 ping6_params->host_index = (u8_t)(i);
2519 i = (u8_t)(i + 1);
2520 }
2521 }
2522
2523 if (!(ping6_params->args_found & LWIP_PING6_HOSTNAME_ARG)) {
2524 /* Hostname/IPv6 address not found */
2525 PRINTK("ping6 : Hostname/IPv6 address to ping is not specified\n");
2526 ret = -1;
2527 goto exit;
2528 }
2529
2530 if (ip6_addr_islinklocal(&(ping6_params->dst_addr)) &&
2531 !(ping6_params->args_found & (LWIP_PING6_INTERFACE_ARG | LWIP_PING6_SOURCE_ADDRESS_ARG))) {
2532 /* For link-local addresses, -I is mandatory */
2533 PRINTK("ping6 : Interface specification is mandatory for link-local addresses\n");
2534 ret = -1;
2535 goto exit;
2536 }
2537
2538 ret = ERR_OK;
2539
2540exit:
2541#if LWIP_DNS
2542 lwip_freeaddrinfo(res);
2543#endif /* LWIP_DNS */
2544
2545 return ret;
2546}
函数调用图:
这是这个函数的调用关系图:

◆ ping_cmd()

static void ping_cmd ( unsigned int  p0,
unsigned int  p1,
unsigned int  p2,
unsigned int  p3 
)
static

在文件 api_shell.c1774 行定义.

1775{
1776 u32_t destip = p0;
1777 u32_t count = p1;
1778 u32_t interval = p2;
1779 u32_t data_len = p3;
1780 int ret;
1781
1782 ret = osPingFunc(destip, count, interval, data_len);
1783 if (ret < 0) {
1784 PRINTK("Ping cmd failed due to some errors\n");
1785 }
1786
1787 ping_taskid = -1;
1788}
函数调用图:
这是这个函数的调用关系图:

◆ print_netif()

LWIP_STATIC int print_netif ( struct netif *  netif,
char *  print_buf,
unsigned int  buf_len 
)

在文件 api_shell.c269 行定义.

270{
271 int i, ret;
272 char *tmp = print_buf;
273#if LWIP_IPV6
274 char *addr = NULL;
275#endif
276
277 if (buf_len < 1) {
278 goto out;
279 }
280 if (netif->link_layer_type == LOOPBACK_IF) {
281 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%.2s\t", netif->name);
282 } else {
283 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%s\t", netif_get_name(netif));
284 }
285 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
286 goto out;
287 tmp += ret;
288 buf_len -= (unsigned int)ret;
289#if LWIP_IPV4
290 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "ip:%s ", ipaddr_ntoa(&netif->ip_addr));
291 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
292 goto out;
293 tmp += ret;
294 buf_len -= (unsigned int)ret;
295
296 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "netmask:%s ", ipaddr_ntoa(&netif->netmask));
297 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
298 goto out;
299 tmp += ret;
300 buf_len -= (unsigned int)ret;
301
302 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "gateway:%s\n", ipaddr_ntoa(&netif->gw));
303 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
304 goto out;
305 tmp += ret;
306 buf_len -= (unsigned int)ret;
307#endif
308
309#if LWIP_IPV6
310 for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
311 /* only PREFERRED addresses are displyaed */
312 if (!ip6_addr_isvalid(netif->ip6_addr_state[i])) {
313 continue;
314 }
315 addr = ip6addr_ntoa((const ip6_addr_t *)&netif->ip6_addr[i]);
316 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tip6: %s/64\n", addr ? addr : "::");
317 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
318 goto out;
319 tmp += ret;
320 buf_len -= (unsigned int)ret;
321 }
322#endif
323
324 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tHWaddr ");
325 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
326 goto out;
327 tmp += ret;
328 buf_len -= (unsigned int)ret;
329
330 for (i = 0; i < netif->hwaddr_len - 1; i++) {
331 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%02x:", netif->hwaddr[i]);
332 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
333 goto out;
334 tmp += ret;
335 buf_len -= (unsigned int)ret;
336 }
337
338 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "%02x", netif->hwaddr[i]);
339 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
340 goto out;
341 tmp += ret;
342 buf_len -= (unsigned int)ret;
343
344 ret = snprintf_s(tmp, buf_len, (buf_len - 1), " MTU:%d %s", netif->mtu,
345 netif->flags & NETIF_FLAG_UP ? "Running" : "Stop");
346 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
347 goto out;
348 tmp += ret;
349 buf_len -= (unsigned int)ret;
350
351 if (netif_default == netif && netif_is_up(netif)) {
352 ret = snprintf_s(tmp, buf_len, (buf_len - 1), " %s", "Default");
353 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
354 goto out;
355 tmp += ret;
356 buf_len -= (unsigned int)ret;
357 }
358
359 ret = snprintf_s(tmp, buf_len, (buf_len - 1), " %s\n", netif->flags & NETIF_FLAG_LINK_UP ? "Link UP" : "Link Down");
360 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
361 goto out;
362 tmp += ret;
363
364#if MIB2_STATS
365 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tRX packets:%u ",
366 netif->mib2_counters.ifinucastpkts + netif->mib2_counters.ifinnucastpkts);
367 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
368 goto out;
369 tmp += ret;
370 buf_len -= (unsigned int)ret;
371
372 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "errors:%u ", netif->mib2_counters.ifinerrors);
373 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
374 goto out;
375 tmp += ret;
376 buf_len -= (unsigned int)ret;
377
378 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "dropped:%u ", netif->mib2_counters.ifindiscards);
379 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
380 goto out;
381 tmp += ret;
382 buf_len -= (unsigned int)ret;
383
384 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "overruns:%u\n", netif->mib2_counters.ifinoverruns);
385 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
386 goto out;
387 tmp += ret;
388 buf_len -= (unsigned int)ret;
389
390 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tTX packets:%u ",
391 netif->mib2_counters.ifoutucastpkts + netif->mib2_counters.ifoutnucastpkts);
392 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
393 goto out;
394 tmp += ret;
395 buf_len -= (unsigned int)ret;
396
397 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "errors:%u ", netif->mib2_counters.ifouterrors);
398 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
399 goto out;
400 tmp += ret;
401 buf_len -= (unsigned int)ret;
402
403 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "dropped:%u\n", netif->mib2_counters.ifoutdiscards);
404 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
405 goto out;
406 tmp += ret;
407 buf_len -= (unsigned int)ret;
408
409 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "\tRX bytes:%u ", netif->mib2_counters.ifinoctets);
410 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
411 goto out;
412 tmp += ret;
413 buf_len -= (unsigned int)ret;
414
415 ret = snprintf_s(tmp, buf_len, (buf_len - 1), "TX bytes:%u\n", netif->mib2_counters.ifoutoctets);
416 if ((ret <= 0) || ((unsigned int)ret >= buf_len))
417 goto out;
418 tmp += ret;
419 buf_len -= (unsigned int)ret;
420#endif
421
422out:
423 return (int)(tmp - print_buf);
424}
这是这个函数的调用关系图:

◆ SHELLCMD_ENTRY() [1/6]

SHELLCMD_ENTRY ( arp_shellcmd  ,
CMD_TYPE_EX  ,
"arp"  ,
,
(CmdCallBackFunc lwip_arp 
)

◆ SHELLCMD_ENTRY() [2/6]

SHELLCMD_ENTRY ( dns_shellcmd  ,
CMD_TYPE_EX  ,
"dns"  ,
XARGS  ,
(CmdCallBackFunc osShellDns 
)

◆ SHELLCMD_ENTRY() [3/6]

SHELLCMD_ENTRY ( ifconfig_shellcmd  ,
CMD_TYPE_EX  ,
"ifconfig"  ,
XARGS  ,
(CmdCallBackFunc lwip_ifconfig 
)
这是这个函数的调用关系图:

◆ SHELLCMD_ENTRY() [4/6]

SHELLCMD_ENTRY ( ntpdate_shellcmd  ,
CMD_TYPE_EX  ,
"ntpdate"  ,
XARGS  ,
(CmdCallBackFunc osShellNtpdate 
)

◆ SHELLCMD_ENTRY() [5/6]

SHELLCMD_ENTRY ( ping6_shellcmd  ,
CMD_TYPE_EX  ,
"ping6"  ,
XARGS  ,
(CmdCallBackFunc osShellPing6 
)

◆ SHELLCMD_ENTRY() [6/6]

SHELLCMD_ENTRY ( ping_shellcmd  ,
CMD_TYPE_EX  ,
"ping"  ,
XARGS  ,
(CmdCallBackFunc osShellPing 
)

◆ tcp_access()

void tcp_access ( int  sockfd)
这是这个函数的调用关系图:

◆ udpserver()

void udpserver ( int  argc,
const char **  argv 
)
这是这个函数的调用关系图:

◆ update_ping6_stats()

LWIP_STATIC void update_ping6_stats ( ping6_stats_t ping6_stats,
u32_t  rtt,
u32_t  nreceived 
)

在文件 api_shell.c2552 行定义.

2553{
2554 if (rtt > ping6_stats->max_rtt) {
2555 ping6_stats->max_rtt = rtt;
2556 }
2557
2558 if (ping6_stats->flag == 0 || rtt < ping6_stats->min_rtt) {
2559 ping6_stats->min_rtt = rtt;
2560 ping6_stats->flag = 1;
2561 }
2562
2564 (float)((float)((float)rtt - ping6_stats->avg_rtt) / (float)(nreceived)));
2565}
这是这个函数的调用关系图:

变量说明

◆ ip_conflict_detect

sys_sem_t ip_conflict_detect
extern

在文件 fixme.c369 行定义.

◆ neighbor_cache

struct nd6_neighbor_cache_entry neighbor_cache[LWIP_ND6_NUM_NEIGHBORS]
extern

◆ ping_kill

int ping_kill = 0
static

在文件 api_shell.c1561 行定义.

◆ ping_taskid

int ping_taskid = -1
static

在文件 api_shell.c1560 行定义.

◆ tcp_state_str

const char* const tcp_state_str[]
extern

在文件 fixme.c389 行定义.

◆ tcpip_init_finish

volatile int tcpip_init_finish
extern

在文件 fixme.c403 行定义.