2014-01-22 00:21:45 +08:00
|
|
|
/****************************************************************************
|
2014-06-27 23:56:45 +08:00
|
|
|
* net/netdev/netdev_carrier.c
|
2014-01-22 00:21:45 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-01-22 00:21:45 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-01-22 00:21:45 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-01-22 00:21:45 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/ethernet.h>
|
2014-06-24 23:28:44 +08:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-01-22 00:21:45 +08:00
|
|
|
|
2023-01-09 20:47:11 +08:00
|
|
|
#include "ipfrag/ipfrag.h"
|
2014-06-27 23:56:45 +08:00
|
|
|
#include "netdev/netdev.h"
|
2020-04-13 21:36:14 +08:00
|
|
|
#include "netlink/netlink.h"
|
2021-11-18 13:29:25 +08:00
|
|
|
#include "arp/arp.h"
|
2014-01-22 00:21:45 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-20 06:02:56 +08:00
|
|
|
* Public Functions
|
2014-01-22 00:21:45 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 06:33:14 +08:00
|
|
|
* Name: netdev_carrier_on
|
2014-01-22 00:21:45 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2014-07-04 07:53:16 +08:00
|
|
|
* Notifies the networking layer about an available carrier.
|
2014-01-22 00:21:45 +08:00
|
|
|
* (e.g. a cable was plugged in)
|
|
|
|
*
|
2018-03-13 23:52:27 +08:00
|
|
|
* Input Parameters:
|
2014-01-22 00:21:45 +08:00
|
|
|
* dev - The device driver structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-12-08 14:43:38 +08:00
|
|
|
void netdev_carrier_on(FAR struct net_driver_s *dev)
|
2014-01-22 00:21:45 +08:00
|
|
|
{
|
2022-06-25 02:30:10 +08:00
|
|
|
if (dev && !IFF_IS_RUNNING(dev->d_flags))
|
2014-01-22 00:21:45 +08:00
|
|
|
{
|
|
|
|
dev->d_flags |= IFF_RUNNING;
|
2020-04-13 21:36:14 +08:00
|
|
|
netlink_device_notify(dev);
|
2014-01-22 00:21:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 06:33:14 +08:00
|
|
|
* Name: netdev_carrier_off
|
2014-01-22 00:21:45 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2014-07-04 07:53:16 +08:00
|
|
|
* Notifies the networking layer about an disappeared carrier.
|
2014-01-22 00:21:45 +08:00
|
|
|
* (e.g. a cable was unplugged)
|
|
|
|
*
|
2018-03-13 23:52:27 +08:00
|
|
|
* Input Parameters:
|
2014-01-22 00:21:45 +08:00
|
|
|
* dev - The device driver structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-12-08 14:43:38 +08:00
|
|
|
void netdev_carrier_off(FAR struct net_driver_s *dev)
|
2014-01-22 00:21:45 +08:00
|
|
|
{
|
2022-06-25 02:30:10 +08:00
|
|
|
if (dev && IFF_IS_RUNNING(dev->d_flags))
|
2014-01-22 00:21:45 +08:00
|
|
|
{
|
|
|
|
dev->d_flags &= ~IFF_RUNNING;
|
2020-04-13 21:36:14 +08:00
|
|
|
netlink_device_notify(dev);
|
2020-08-07 17:32:55 +08:00
|
|
|
|
2023-01-09 20:47:11 +08:00
|
|
|
#ifdef CONFIG_NET_IPFRAG
|
|
|
|
/* Clean up fragment data for this NIC (if any) */
|
|
|
|
|
|
|
|
ip_frag_stop(dev);
|
|
|
|
#endif
|
|
|
|
|
2020-08-07 17:32:55 +08:00
|
|
|
/* Notify clients that the network has been taken down */
|
|
|
|
|
2022-08-25 21:17:57 +08:00
|
|
|
devif_dev_event(dev, NETDEV_DOWN);
|
2021-11-18 13:29:25 +08:00
|
|
|
arp_cleanup(dev);
|
2014-01-22 00:21:45 +08:00
|
|
|
}
|
|
|
|
}
|