Lely core libraries  2.3.4
can_ctrl.c File Reference
#include "io.h"
#include <lely/io2/linux/can.h>
#include <lely/util/util.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <net/if.h>
#include "can_attr.h"
#include "if.h"
#include "ifreq.h"
Include dependency graph for can_ctrl.c:

Go to the source code of this file.

Data Structures

struct  io_can_ctrl_impl
 

Macros

#define LELY_IO_CAN_TXLEN   128
 The default SocketCAN transmit queue length (in number of CAN frames).
 

Functions

io_can_ctrl_tio_can_ctrl_create_from_name (const char *name, size_t txlen)
 Creates a new CAN controller from an interface name. More...
 
io_can_ctrl_tio_can_ctrl_create_from_index (unsigned int index, size_t txlen)
 Creates a new CAN controller from an interface index. More...
 
void io_can_ctrl_destroy (io_can_ctrl_t *ctrl)
 Destroys a CAN controller. More...
 
const char * io_can_ctrl_get_name (const io_can_ctrl_t *ctrl)
 Returns the interface name of a CAN controller.
 
unsigned int io_can_ctrl_get_index (const io_can_ctrl_t *ctrl)
 Returns the interface index of a CAN controller.
 
int io_can_ctrl_get_flags (const io_can_ctrl_t *ctrl)
 Returns the flags specifying which CAN bus features are enabled. More...
 

Detailed Description

This file is part of the I/O library; it contains the CAN controller mplementation for Linux.

See also
lely/io2/linux/can.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

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.

Definition in file can_ctrl.c.

Function Documentation

◆ io_can_ctrl_create_from_name()

io_can_ctrl_t* io_can_ctrl_create_from_name ( const char *  name,
size_t  txlen 
)

Creates a new CAN controller from an interface name.

This function MAY need the CAP_NET_ADMIN capability to set the transmit queue length of the specified SocketCAN interface to at least txlen.

Parameters
namethe name of a SocketCAN network interface.
txlenthe transmission queue length (in number of frames) of the network interface. If txlen is 0, the default value LELY_IO_CAN_TXLEN is used.
Returns
a pointer to a new CAN controller, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
io_can_ctrl_create_from_index()

Definition at line 138 of file can_ctrl.c.

◆ io_can_ctrl_create_from_index()

io_can_ctrl_t* io_can_ctrl_create_from_index ( unsigned int  index,
size_t  txlen 
)

Creates a new CAN controller from an interface index.

This function MAY need the CAP_NET_ADMIN capability to set the transmit queue length of the specified SocketCAN interface to at least txlen.

Parameters
indexthe index of a SocketCAN network interface.
txlenthe transmission queue length (in number of frames) of the network interface. If txlen is 0, the default value LELY_IO_CAN_TXLEN is used.
Returns
a pointer to a new CAN controller, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
io_can_ctrl_create_from_name()

Definition at line 147 of file can_ctrl.c.

◆ io_can_ctrl_destroy()

void io_can_ctrl_destroy ( io_can_ctrl_t ctrl)

Destroys a CAN controller.

See also
io_can_ctrl_create_from_name(), io_can_ctrl_create_from_index()

Definition at line 174 of file can_ctrl.c.

◆ io_can_ctrl_get_flags()

int io_can_ctrl_get_flags ( const io_can_ctrl_t ctrl)

Returns the flags specifying which CAN bus features are enabled.

Returns
any combination of IO_CAN_BUS_FLAG_ERR, IO_CAN_BUS_FLAG_FDF and IO_CAN_BUS_FLAG_BRS.

Definition at line 199 of file can_ctrl.c.