@@ -1581,14 +1581,76 @@ int net_shell_cmd_http(int argc, char *argv[])
1581
1581
1582
1582
int net_shell_cmd_iface (int argc , char * argv [])
1583
1583
{
1584
- ARG_UNUSED (argc );
1585
- ARG_UNUSED (argv );
1584
+ int arg = 0 ;
1585
+ bool up = false;
1586
+ char * endptr = NULL ;
1587
+ struct net_if * iface ;
1588
+ int idx , ret ;
1589
+
1590
+ if (strcmp (argv [arg ], "iface" ) == 0 ) {
1591
+ arg ++ ;
1592
+ }
1586
1593
1594
+ if (!argv [arg ]) {
1587
1595
#if defined(CONFIG_NET_HOSTNAME_ENABLE )
1588
- printk ("Hostname: %s\n\n" , net_hostname_get ());
1596
+ printk ("Hostname: %s\n\n" , net_hostname_get ());
1589
1597
#endif
1598
+ net_if_foreach (iface_cb , NULL );
1599
+
1600
+ return 0 ;
1601
+ }
1602
+
1603
+ if (strcmp (argv [arg ], "up" ) == 0 ) {
1604
+ arg ++ ;
1605
+ up = true;
1606
+ } else if (strcmp (argv [arg ], "down" ) == 0 ) {
1607
+ arg ++ ;
1608
+ }
1609
+
1610
+ if (!argv [arg ]) {
1611
+ printk ("Usage: net iface [up|down] [index]\n" );
1612
+ return 0 ;
1613
+ }
1614
+
1615
+ idx = strtol (argv [arg ], & endptr , 10 );
1616
+ if (* endptr != '\0' ) {
1617
+ printk ("Invalid index %s\n" , argv [arg ]);
1618
+ return 0 ;
1619
+ }
1620
+
1621
+ if (idx < 0 || idx > 255 ) {
1622
+ printk ("Invalid index %d\n" , idx );
1623
+ return 0 ;
1624
+ }
1625
+
1626
+ iface = net_if_get_by_index (idx );
1627
+ if (!iface ) {
1628
+ printk ("No such interface in index %d\n" , idx );
1629
+ return 0 ;
1630
+ }
1590
1631
1591
- net_if_foreach (iface_cb , NULL );
1632
+ if (up ) {
1633
+ if (net_if_is_up (iface )) {
1634
+ printk ("Interface %d is already up.\n" , idx );
1635
+ return 0 ;
1636
+ }
1637
+
1638
+ ret = net_if_up (iface );
1639
+ if (ret ) {
1640
+ printk ("Cannot take interface %d up (%d)\n" ,
1641
+ idx , ret );
1642
+ } else {
1643
+ printk ("Interface %d is up\n" , idx );
1644
+ }
1645
+ } else {
1646
+ ret = net_if_down (iface );
1647
+ if (ret ) {
1648
+ printk ("Cannot take interface %d down (%d)\n" ,
1649
+ idx , ret );
1650
+ } else {
1651
+ printk ("Interface %d is down\n" , idx );
1652
+ }
1653
+ }
1592
1654
1593
1655
return 0 ;
1594
1656
}
@@ -2786,7 +2848,9 @@ static struct shell_cmd net_commands[] = {
2786
2848
"http monitor\n\tStart monitoring HTTP connections\n"
2787
2849
"http\n\tTurn off HTTP connection monitoring" },
2788
2850
{ "iface" , net_shell_cmd_iface ,
2789
- "\n\tPrint information about network interfaces" },
2851
+ "\n\tPrint information about network interfaces\n"
2852
+ "iface up [idx]\n\tTake network interface up\n"
2853
+ "iface down [idx]\n\tTake network interface down" },
2790
2854
{ "mem" , net_shell_cmd_mem ,
2791
2855
"\n\tPrint information about network interfaces" },
2792
2856
{ "nbr" , net_shell_cmd_nbr , "\n\tPrint neighbor information\n"
0 commit comments