csock-raw (Can Socket Raw)

Header: udo/csock-raw.h

Table of contents (click to go)

Macros

Enums

Unions

Structs

  1. udo_csock_raw

  2. udo_csock_raw_create_info

Functions

  1. udo_csock_raw_create()

  2. udo_csock_raw_send_data()

  3. udo_csock_raw_recv_data()

  4. udo_csock_raw_get_fd()

  5. udo_csock_raw_get_iface()

  6. udo_csock_raw_destroy()

  7. udo_csock_raw_get_sizeof()

API Documentation

Kernel Modules

On Host Machine

sudo modprobe -a can can_raw vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set vcan0 up

udo_csock_raw (private)

Structure defining UDO CAN Socket Raw context.
struct udo_csock_raw
struct udo_log_error_struct err;
bool free;
int fd;
char iface[IFNAMSIZ];
err
Stores information about the error that occured
for the given context and may later be retrieved
by caller.
free
If structure allocated with calloc(3) member will be
set to true so that, we know to call free(3) when
destroying the context.
fd
File descriptor to the open CAN socket
iface
Textual CAN interface name in string format to bind(2) to.

udo_csock_raw_create_info

Structure passed to udo_csock_raw_create()
used to define how to create the CAN socket.
struct udo_csock_raw_create_info
const char *iface;
iface
Must pass textual CAN interface
name in string format.

udo_csock_raw_create

struct udo_csock_raw *udo_csock_raw_create(struct udo_csock_raw *csock, const void *csock_info);
Creates a socket that may be utilized
for sending & receiving CAN frames. On
a caller specified CAN interface.

Param

Decription

csock

May be NULL or a pointer to a struct udo_csock_raw.
If NULL memory will be allocated and return to
caller. If not NULL address passed will be used
to store the newly created struct udo_csock_raw
context.

csock_info

Implementation uses a pointer to a
Returns:
on success: Pointer to a struct udo_csock_raw
on failure: NULL

udo_csock_raw_send_data

ssize_t udo_csock_raw_send_data(struct udo_csock_raw *csock, const struct can_frame *frame, const void *csock_info);
Send CAN frame through socket bounded to CAN interface
specified by a call to udo_csock_raw_create().

Param

Decription

csock

Must pass a pointer to a struct udo_csock_raw.

frame

Pointer to frame buffer to send through socket.

csock_info

Reserved for future usage. For now used
to set the flag argument of send(2).
Returns:
on success: Size of CAN frame
on failure: # < 0

udo_csock_raw_recv_data

ssize_t udo_csock_raw_recv_data(struct udo_csock_raw *csock, struct can_frame *frame, const void *csock_info);
Receive CAN frame from socket bounded to CAN interface
specified by a call to udo_csock_raw_create().

Param

Decription

csock

Must pass a pointer to a struct udo_csock_raw.

frame

Pointer to buffer to store data received from a socket.

csock_info

Reserved for future usage. For now used
to set the flag argument of send(2).
Returns:
on success: Size of CAN frame
on failure: # < 0

udo_csock_raw_get_fd

int udo_csock_raw_get_fd(struct udo_csock_raw *csock);
Acquire socket file descriptor associated with
struct udo_csock_raw context.

Param

Decription

csock

Must pass a pointer to a struct udo_csock_raw.
Returns:
on success: RAW socket file descriptor
on failure: -1

udo_csock_raw_get_iface

const char *udo_csock_raw_get_iface(struct udo_csock_raw *csock);
Acquire textual CAN interface name in string format
associated with struct udo_csock_raw context.

Param

Decription

csock

Must pass a pointer to a struct udo_csock_raw.
Returns:
on success: Textual CAN interface name in string format
on failure: NULL

udo_csock_raw_destroy

void udo_csock_raw_destroy(struct udo_csock_raw *csock);
Frees any allocated memory and closes FD’s (if open)
created after udo_csock_raw_create() call.

Param

Decription

csock

Pointer to a valid struct udo_csock_raw.

udo_csock_raw_get_sizeof

int udo_csock_raw_get_sizeof(void);
Returns size of the internal structure. So,
if caller decides to allocate memory outside
of API interface they know the exact amount
of bytes.
Returns:
on success: sizeof(struct udo_csock_raw)
on failure: sizeof(struct udo_csock_raw)