2014-01-21 17:21:45 +01:00
|
|
|
/****************************************************************************
|
2014-06-27 17:56:45 +02:00
|
|
|
* net/netdev/netdev_carrier.c
|
2014-01-21 17:21:45 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01: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-21 17:21:45 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-01-21 17:21:45 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01: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-21 17:21:45 +01: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 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-01-21 17:21:45 +01:00
|
|
|
|
2014-06-27 17:56:45 +02:00
|
|
|
#include "netdev/netdev.h"
|
2020-04-13 15:36:14 +02:00
|
|
|
#include "netlink/netlink.h"
|
2021-11-18 06:29:25 +01:00
|
|
|
#include "arp/arp.h"
|
2014-01-21 17:21:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-19 23:02:56 +01:00
|
|
|
* Public Functions
|
2014-01-21 17:21:45 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_carrier_on
|
2014-01-21 17:21:45 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2014-07-04 01:53:16 +02:00
|
|
|
* Notifies the networking layer about an available carrier.
|
2014-01-21 17:21:45 +01:00
|
|
|
* (e.g. a cable was plugged in)
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2014-01-21 17:21:45 +01:00
|
|
|
* dev - The device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0:Success; negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
int netdev_carrier_on(FAR struct net_driver_s *dev)
|
2014-01-21 17:21:45 +01:00
|
|
|
{
|
2022-06-24 20:30:10 +02:00
|
|
|
if (dev && !IFF_IS_RUNNING(dev->d_flags))
|
2014-01-21 17:21:45 +01:00
|
|
|
{
|
|
|
|
dev->d_flags |= IFF_RUNNING;
|
2020-04-13 15:36:14 +02:00
|
|
|
netlink_device_notify(dev);
|
2014-01-21 17:21:45 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: netdev_carrier_off
|
2014-01-21 17:21:45 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2014-07-04 01:53:16 +02:00
|
|
|
* Notifies the networking layer about an disappeared carrier.
|
2014-01-21 17:21:45 +01:00
|
|
|
* (e.g. a cable was unplugged)
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2014-01-21 17:21:45 +01:00
|
|
|
* dev - The device driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0:Success; negated errno on failure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
int netdev_carrier_off(FAR struct net_driver_s *dev)
|
2014-01-21 17:21:45 +01:00
|
|
|
{
|
2022-06-24 20:30:10 +02:00
|
|
|
if (dev && IFF_IS_RUNNING(dev->d_flags))
|
2014-01-21 17:21:45 +01:00
|
|
|
{
|
|
|
|
dev->d_flags &= ~IFF_RUNNING;
|
2020-04-13 15:36:14 +02:00
|
|
|
netlink_device_notify(dev);
|
2020-08-07 11:32:55 +02:00
|
|
|
|
|
|
|
/* Notify clients that the network has been taken down */
|
|
|
|
|
|
|
|
devif_dev_event(dev, NULL, NETDEV_DOWN);
|
2021-11-18 06:29:25 +01:00
|
|
|
arp_cleanup(dev);
|
2020-08-07 11:32:55 +02:00
|
|
|
|
2014-01-21 17:21:45 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|