AM64x MCU+ SDK  10.00.00
Network functions binding

Introduction

Files

file  cb_ethernet.h
 Bindings to POSIX network functions.
 

Data Structures

struct  cb_rawsock_ovip_para_t
 parameters to open the over IP mode raw socket, the values are in host order More...
 
struct  cb_rawsock_paras_t
 raw socket parameters.to open or create raw socket this structure must be filled. More...
 

Functions

int cb_get_mac_bydev (CB_SOCKET_T sfd, const char *dev, ub_macaddr_t bmac)
 get mac address from device name like 'eth0' More...
 
int cb_get_ip_bydev (CB_SOCKET_T sfd, const char *dev, CB_IN_ADDR_T *inp)
 get ip address from device name like 'eth0' More...
 
int cb_get_brdip_bydev (CB_SOCKET_T sfd, const char *dev, CB_IN_ADDR_T *inp)
 get broadcast ip address from device name like 'eth0' More...
 
int cb_rawsock_open (cb_rawsock_paras_t *llrawp, CB_SOCKET_T *fd, CB_SOCKADDR_LL_T *addr, int *mtusize, ub_macaddr_t bmac)
 generic raw ethernet open More...
 
int cb_rawsock_close (CB_SOCKET_T fd)
 close the socket opened by cb_rawsock_open More...
 
int cb_sock_set_priority (CB_SOCKET_T fd, int priority)
 set socket priority More...
 
int cb_expand_mtusize (CB_SOCKET_T fd, const char *dev, int *mtusize)
 expand mtusize More...
 
int cb_set_promiscuous_mode (CB_SOCKET_T sfd, const char *dev, bool enable)
 set the promiscuous mode on the socket More...
 
int cb_reg_multicast_address (CB_SOCKET_T fd, const char *dev, const unsigned char *mcastmac, int del)
 register/deregister multicast address to receive More...
 
int cb_get_all_netdevs (int maxdevnum, netdevname_t *netdevs)
 get all network devices name availble in systems. More...
 
int cb_get_ethtool_linkstate (CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate)
 get ethtool link state from device name like 'eth0' More...
 
int cb_get_ethtool_info (CB_SOCKET_T cfd, const char *dev, uint32_t *speed, uint32_t *duplex)
 get ethtool info(speed and duplex) from device name like 'eth0' More...
 
int cb_get_netdev_from_ptpdev (char *ptpdev, char *netdev)
 find network device name from ptp device name More...
 
int cb_get_ptpdev_from_netdev (char *netdev, char *ptpdev)
 find ptp device name from network device name More...
 

Typedefs

typedef char ptpdevname_t[MAX_PTPDEV_NAME]
 ptpdevice name. More...
 
typedef char netdevname_t[CB_MAX_NETDEVNAME]
 network device name. More...
 

Enumerations

enum  cb_rawsock_rw_t { CB_RAWSOCK_RDWR = 0, CB_RAWSOCK_RDONLY, CB_RAWSOCK_WRONLY }
 this enumeration defines permission for raw socket. More...
 
enum  cb_sock_mode_t { CB_SOCK_MODE_OVIP = -1, CB_SOCK_MODE_NORMAL }
 

Macros

#define CB_MAX_NETDEVNAME   IFNAMSIZ
 
#define CB_SOCKET_T   int
 
#define CB_SOCKET_VALID(x)   ((x)>=0)
 
#define CB_SOCKET_INVALID_VALUE   -1
 
#define CB_ETHHDR_T   struct ethhdr
 
#define CB_SOCKLEN_T   socklen_t
 
#define CB_SOCKADDR_T   struct sockaddr
 
#define CB_SOCKADDR_LL_T   struct sockaddr_ll
 
#define CB_SOCKADDR_IN_T   struct sockaddr_in
 
#define CB_SOCKADDR_IN6_T   struct sockaddr_in6
 
#define CB_SOCKADDR_STORAGE_T   struct sockaddr_storage
 
#define CB_IN_ADDR_T   struct in_addr
 
#define CB_IN6_ADDR_T   struct in6_addr
 
#define CB_IFREQ_T   struct ifreq
 
#define CB_OPEN   open
 
#define CB_CLOSE   close
 
#define CB_WRITE   write
 
#define CB_SOCKET   socket
 
#define CB_IF_NAMETOINDEX   if_nametoindex
 
#define CB_SOCK_BIND   bind
 
#define CB_SOCK_IOCTL   ioctl
 
#define CB_SOCK_CLOSE   close
 
#define CB_SETSOCKOPT   setsockopt
 
#define CB_SOCK_SENDTO   sendto
 
#define CB_SELECT   select
 
#define CB_SOCK_RECVFROM   recvfrom
 
#define CB_SOCK_RECVMSG   recvmsg
 
#define CB_SOCK_WRITE   write
 
#define CB_SOCK_CONNECT   connect
 
#define CB_FCNTL   fcntl
 
#define CB_FD_SET_T   fd_set
 
#define CB_FDSET   FD_SET
 
#define CB_FDCLR   FD_CLR
 
#define CB_FDISSET   FD_ISSET
 
#define CB_FDZERO   FD_ZERO
 
#define CB_VIRTUAL_ETHDEV_PREFIX   "cbeth"
 prefix of virtual network device, which supports raw ethernet packet over udp More...
 
#define CB_VIRTUAL_PTPDEV_PREFIX   "cbptp"
 prefix of virtual ptp device. the suffix must be common with the virtual network device. More...
 
#define CB_VIRTUAL_ETHDEV_MACU32   {0x02,0x01,0x45,0x10}
 virtual MAC address of the virtual network device. the lower 2 bytes are calculated from the suffix More...
 
#define H_SOURCE   h_source
 
#define H_DEST   h_dest
 
#define H_PROTO   h_proto
 
#define PTP_HEAD_MSGTYPE(x)   ((*(uint8_t *) (&((uint8_t *)(x))[0])) & 0x0F)
 forms ptp header msgtype. More...
 
#define PTP_HEAD_SEQID(x)   ((((uint8_t *)(x))[30]<<8u)|(((uint8_t *)(x))[31]))
 macro which is used to form ptp header sequence id. More...
 
#define PTP_HEAD_DOMAIN_NUMBER(x)   (*(uint8_t *)(&((uint8_t *)(x))[4]))
 macro used to form ptp header domain number. More...
 
#define MAX_PTPDEV_NAME   32
 maximum character number of ptp device name More...
 

Macro Definition Documentation

◆ CB_MAX_NETDEVNAME

#define CB_MAX_NETDEVNAME   IFNAMSIZ

◆ CB_SOCKET_T

#define CB_SOCKET_T   int

◆ CB_SOCKET_VALID

#define CB_SOCKET_VALID (   x)    ((x)>=0)

◆ CB_SOCKET_INVALID_VALUE

#define CB_SOCKET_INVALID_VALUE   -1

◆ CB_ETHHDR_T

#define CB_ETHHDR_T   struct ethhdr

◆ CB_SOCKLEN_T

#define CB_SOCKLEN_T   socklen_t

◆ CB_SOCKADDR_T

#define CB_SOCKADDR_T   struct sockaddr

◆ CB_SOCKADDR_LL_T

#define CB_SOCKADDR_LL_T   struct sockaddr_ll

◆ CB_SOCKADDR_IN_T

#define CB_SOCKADDR_IN_T   struct sockaddr_in

◆ CB_SOCKADDR_IN6_T

#define CB_SOCKADDR_IN6_T   struct sockaddr_in6

◆ CB_SOCKADDR_STORAGE_T

#define CB_SOCKADDR_STORAGE_T   struct sockaddr_storage

◆ CB_IN_ADDR_T

#define CB_IN_ADDR_T   struct in_addr

◆ CB_IN6_ADDR_T

#define CB_IN6_ADDR_T   struct in6_addr

◆ CB_IFREQ_T

#define CB_IFREQ_T   struct ifreq

◆ CB_OPEN

#define CB_OPEN   open

◆ CB_CLOSE

#define CB_CLOSE   close

◆ CB_WRITE

#define CB_WRITE   write

◆ CB_SOCKET

#define CB_SOCKET   socket

◆ CB_IF_NAMETOINDEX

#define CB_IF_NAMETOINDEX   if_nametoindex

◆ CB_SOCK_BIND

#define CB_SOCK_BIND   bind

◆ CB_SOCK_IOCTL

#define CB_SOCK_IOCTL   ioctl

◆ CB_SOCK_CLOSE

#define CB_SOCK_CLOSE   close

◆ CB_SETSOCKOPT

#define CB_SETSOCKOPT   setsockopt

◆ CB_SOCK_SENDTO

#define CB_SOCK_SENDTO   sendto

◆ CB_SELECT

#define CB_SELECT   select

◆ CB_SOCK_RECVFROM

#define CB_SOCK_RECVFROM   recvfrom

◆ CB_SOCK_RECVMSG

#define CB_SOCK_RECVMSG   recvmsg

◆ CB_SOCK_WRITE

#define CB_SOCK_WRITE   write

◆ CB_SOCK_CONNECT

#define CB_SOCK_CONNECT   connect

◆ CB_FCNTL

#define CB_FCNTL   fcntl

◆ CB_FD_SET_T

#define CB_FD_SET_T   fd_set

◆ CB_FDSET

#define CB_FDSET   FD_SET

◆ CB_FDCLR

#define CB_FDCLR   FD_CLR

◆ CB_FDISSET

#define CB_FDISSET   FD_ISSET

◆ CB_FDZERO

#define CB_FDZERO   FD_ZERO

◆ CB_VIRTUAL_ETHDEV_PREFIX

#define CB_VIRTUAL_ETHDEV_PREFIX   "cbeth"

prefix of virtual network device, which supports raw ethernet packet over udp

◆ CB_VIRTUAL_PTPDEV_PREFIX

#define CB_VIRTUAL_PTPDEV_PREFIX   "cbptp"

prefix of virtual ptp device. the suffix must be common with the virtual network device.

◆ CB_VIRTUAL_ETHDEV_MACU32

#define CB_VIRTUAL_ETHDEV_MACU32   {0x02,0x01,0x45,0x10}

virtual MAC address of the virtual network device. the lower 2 bytes are calculated from the suffix

◆ H_SOURCE

#define H_SOURCE   h_source

◆ H_DEST

#define H_DEST   h_dest

◆ H_PROTO

#define H_PROTO   h_proto

◆ PTP_HEAD_MSGTYPE

#define PTP_HEAD_MSGTYPE (   x)    ((*(uint8_t *) (&((uint8_t *)(x))[0])) & 0x0F)

forms ptp header msgtype.

◆ PTP_HEAD_SEQID

#define PTP_HEAD_SEQID (   x)    ((((uint8_t *)(x))[30]<<8u)|(((uint8_t *)(x))[31]))

macro which is used to form ptp header sequence id.

◆ PTP_HEAD_DOMAIN_NUMBER

#define PTP_HEAD_DOMAIN_NUMBER (   x)    (*(uint8_t *)(&((uint8_t *)(x))[4]))

macro used to form ptp header domain number.

◆ MAX_PTPDEV_NAME

#define MAX_PTPDEV_NAME   32

maximum character number of ptp device name

Typedef Documentation

◆ ptpdevname_t

typedef char ptpdevname_t[MAX_PTPDEV_NAME]

ptpdevice name.

◆ netdevname_t

typedef char netdevname_t[CB_MAX_NETDEVNAME]

network device name.

Enumeration Type Documentation

◆ cb_rawsock_rw_t

this enumeration defines permission for raw socket.

for example 

CB_RAWSOCK_RDWR for read and write. CB_RAWSOCK_RDONLY for read only. CB_RAWSOCK_WRONLY for write only.

Enumerator
CB_RAWSOCK_RDWR 
CB_RAWSOCK_RDONLY 
CB_RAWSOCK_WRONLY 

◆ cb_sock_mode_t

Enumerator
CB_SOCK_MODE_OVIP 
CB_SOCK_MODE_NORMAL 

Function Documentation

◆ cb_get_mac_bydev()

int cb_get_mac_bydev ( CB_SOCKET_T  sfd,
const char *  dev,
ub_macaddr_t  bmac 
)

get mac address from device name like 'eth0'

Parameters
sfdif sfd!=-1, pre-opened socket is used to get the mac. if sfd==-1, a newly opened udp socket is used to get the mac Address.
devethernet device name like 'eth0'
bmacrefernce to buffer which is used to store mac address of ethernet device.
Returns
0 on success, -1 on error

◆ cb_get_ip_bydev()

int cb_get_ip_bydev ( CB_SOCKET_T  sfd,
const char *  dev,
CB_IN_ADDR_T inp 
)

get ip address from device name like 'eth0'

Parameters
sfdif sfd!=-1, pre-opened socket is used to get the mac. if sfd==-1, a newly opened udp socket is used to get the MAC Address.
devethenert device name like 'eth0'
inpreference to 'CB_IN_ADDR_T' where IP address is saved
Returns
0 on success, -1 on error

◆ cb_get_brdip_bydev()

int cb_get_brdip_bydev ( CB_SOCKET_T  sfd,
const char *  dev,
CB_IN_ADDR_T inp 
)

get broadcast ip address from device name like 'eth0'

Parameters
sfdif sfd!=-1, pre-opened socket is used to get the mac. if sfd==-1, a newly opened udp socket is used.
devethenert device name like 'eth0'
inpreference to 'CB_IN_ADDR_T' where IP address is saved
Returns
0 on success, -1 on error

◆ cb_rawsock_open()

int cb_rawsock_open ( cb_rawsock_paras_t llrawp,
CB_SOCKET_T fd,
CB_SOCKADDR_LL_T addr,
int *  mtusize,
ub_macaddr_t  bmac 
)

generic raw ethernet open

Parameters
llrawpcb_rawsock_paras_t -> raw socket open parameters, this parameter is passed as refernce to cb_rawsock_paras_t.
fdreturn a descriptor of opened socket
addrreturn sockaddr information which is used to open the socket
mtusizeMTU size including ETH header size. if *mtusize>default size, try to resize MTU size.
bmacthe mac address of 'dev' is returned in 'bmac'
Returns
0 on success, -1 on error
Note
for general this function support the both of 'avtp raw' and 'general raw', for 'nos'(no OS or primitive OS), this is for 'avtp raw' and nos_rawe_socket_open is for 'general raw'
before calling to this function, llrawp must be filled.
See also
cb_rawsock_paras_t

◆ cb_rawsock_close()

int cb_rawsock_close ( CB_SOCKET_T  fd)

close the socket opened by cb_rawsock_open

Parameters
fddescriptor of the opened socket
Returns
0 on success, -1 on error.

◆ cb_sock_set_priority()

int cb_sock_set_priority ( CB_SOCKET_T  fd,
int  priority 
)

set socket priority

Parameters
fddescriptor of the opened socket
prioritypriority number
Returns
0 on success, -1 on error.

◆ cb_expand_mtusize()

int cb_expand_mtusize ( CB_SOCKET_T  fd,
const char *  dev,
int *  mtusize 
)

expand mtusize

Parameters
fddescriptor of the opened socket
devethernet device name like eth0
mtusizenew mtusize, return a new mtu size in *mtusize
Returns
0 on success, -1 on error.

◆ cb_set_promiscuous_mode()

int cb_set_promiscuous_mode ( CB_SOCKET_T  sfd,
const char *  dev,
bool  enable 
)

set the promiscuous mode on the socket

Parameters
sfddescriptor of the socket
devethernet device name like eth0
enabletrue:enable, false:disable
Returns
0 on success, -1 on error.

◆ cb_reg_multicast_address()

int cb_reg_multicast_address ( CB_SOCKET_T  fd,
const char *  dev,
const unsigned char *  mcastmac,
int  del 
)

register/deregister multicast address to receive

Parameters
fddescriptor of the socket
devethernet device name like eth0
mcastmacmulticast address
del0:register 1:deregister
Returns
0 on success, -1 on error.

◆ cb_get_all_netdevs()

int cb_get_all_netdevs ( int  maxdevnum,
netdevname_t netdevs 
)

get all network devices name availble in systems.

Parameters
maxdevnumnumber of devices presents in systems.
netdevsreference to netdevname_t which stores net devices name.
Returns
index number of network devices presents on system.

◆ cb_get_ethtool_linkstate()

int cb_get_ethtool_linkstate ( CB_SOCKET_T  cfd,
const char *  dev,
uint32_t *  linkstate 
)

get ethtool link state from device name like 'eth0'

Parameters
cfdif cfd!=-1, pre-opened socket is used to get the ethtool info. if cfd==-1, a newly opened udp socket is used.
devethernet device name like 'eth0'
linkstateto store link state value (0:down, 1:up)
Returns
0 on success, -1 on error
Note
Linux platform supports this function. Other platform must suport in the outside of this layer. this function will be deprecated. read the status in uniconf DB which is managed by combase_link.h and low layer functinos.

◆ cb_get_ethtool_info()

int cb_get_ethtool_info ( CB_SOCKET_T  cfd,
const char *  dev,
uint32_t *  speed,
uint32_t *  duplex 
)

get ethtool info(speed and duplex) from device name like 'eth0'

Parameters
cfdif cfd!=-1, pre-opened socket is used to get the ethtool info. if cfd==-1, a newly opened udp socket is used.
devethenert device name like 'eth0'
speedto store speed value(0:unknow, 10:10Mbps, 100:100Mbps, 1000:1Gbps)
duplexto store duplex value(0:unknow, 1:Full, 2:Half)
Returns
0 on success, -1 on error
Note
Linux platform supports this function. Other platform must suport in the outside of this layer. this function will be deprecated. read the status in uniconf DB which is managed by combase_link.h and low layer functinos.

◆ cb_get_netdev_from_ptpdev()

int cb_get_netdev_from_ptpdev ( char *  ptpdev,
char *  netdev 
)

find network device name from ptp device name

Returns
0 on success, -1 on error
Parameters
ptpdevptpdevice name(either format of '/dev/ptp0' or 'ptp0')
netdevthe result of network device name, must have enough space
Note
Linux platform supports this function. Other platform must suport in the outside of this layer.

◆ cb_get_ptpdev_from_netdev()

int cb_get_ptpdev_from_netdev ( char *  netdev,
char *  ptpdev 
)

find ptp device name from network device name

Returns
0 on success, -1 on error
Parameters
netdevnetwork device name (like 'eth0')
ptpdevthe result of ptpdevice name(like 'ptp0', no preceding '/dev/'),
must have enough space.
Note
Linux platform supports this function. Other platform must suport in the outside of this layer.