Go to the documentation of this file.
35 #include <sys/types.h>
36 #include <sys/ioctl.h>
38 #include <sys/socket.h>
41 #include <arpa/inet.h>
72 #define RX_PRIM priMAC[1]
74 #define RX_SEC secMAC[1]
95 struct timeval timeout;
100 const int maxbpffile = 1000;
131 pthread_mutex_init(&(port->
tx_mutex) , NULL);
132 pthread_mutex_init(&(port->
rx_mutex) , NULL);
149 for(i = 0; *bpf == -1 && i < maxbpffile; ++i)
151 sprintf(fname,
"/dev/bpf%i", i);
152 *bpf = open(fname, O_RDWR);
158 perror(
"Could not open bpf\n");
164 uint buffer_len =
sizeof(
ec_bufT);
165 if (ioctl(*bpf, BIOCSBLEN, &buffer_len) == -1) {
169 if (buffer_len < 1518) {
170 printf(
"buffer_len %d < 1518\n", buffer_len);
175 strcpy(ifr.ifr_name, ifname);
176 if(ioctl(*bpf, BIOCSETIF, &ifr) == -1) {
184 if (ioctl(*bpf, BIOCIMMEDIATE, &true_val) == -1) {
185 perror(
"BIOCIMMEDIATE");
190 if (ioctl(*bpf, BIOCPROMISC, &true_val) == -1) {
191 perror(
"BIOCPROMISC");
196 if (ioctl(*bpf, BIOCSHDRCMPLT, &true_val) == -1) {
197 perror(
"BIOCSHDRCMPLT");
202 uint direction = BPF_D_IN;
203 if (ioctl(*bpf, BIOCSDIRECTION, &direction) == -1) {
204 perror(
"BIOCSDIRECTION");
210 timeout.tv_usec = 11000;
211 if (ioctl(*bpf, BIOCSRTIMEOUT, &timeout) == -1) {
212 perror(
"BIOCSRTIMEOUT");
250 bp->da0 = htons(0xffff);
251 bp->da1 = htons(0xffff);
252 bp->da2 = htons(0xffff);
253 bp->sa0 = htons(
priMAC[0]);
254 bp->sa1 = htons(
priMAC[1]);
255 bp->sa2 = htons(
priMAC[2]);
322 stack = &(port->
stack);
331 rval = write (*stack->
sock,(*stack->
txbuf)[idx], lp);
353 ehp->sa1 = htons(
priMAC[1]);
358 pthread_mutex_lock( &(port->
tx_mutex) );
363 datagramP->index = idx;
365 ehp->sa1 = htons(
secMAC[1]);
373 pthread_mutex_unlock( &(port->
tx_mutex) );
391 stack = &(port->
stack);
399 bytesrx = read(*stack->
sock, (*stack->
tempbuf), lp);
402 return (bytesrx > 0);
433 stack = &(port->
stack);
444 l = (*rxbuf)[0] + ((
uint16)((*
rxbuf)[1] & 0x0f) << 8);
446 rval = ((*rxbuf)[l] + ((
uint16)(*
rxbuf)[l + 1] << 8));
452 pthread_mutex_lock(&(port->
rx_mutex));
465 l =
etohs(ecp->elength) & 0x0fff;
473 rval = ((*rxbuf)[l] + ((
uint16)((*
rxbuf)[l + 1]) << 8));
477 (*stack->
rxsa)[idx] = ntohs(ehp->sa1);
489 (*stack->
rxsa)[idxf] = ntohs(ehp->sa1);
498 pthread_mutex_unlock( &(port->
rx_mutex) );
562 if ( ((primrx == 0) && (secrx ==
RX_SEC)) ||
682 int ec_inframe(
int idx,
int stacknumber)
uint8 ec_bufT[EC_BUFSIZE]
int ec_waitinframe(int idx, int timeout)
static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer)
int ecx_closenic(ecx_portt *port)
int ec_setupnic(const char *ifname, int secondary)
int txbuflength[EC_MAXBUF]
int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
void ec_setbufstat(int idx, int bufstat)
Headerfile for ethercatbase.c.
boolean osal_timer_is_expired(osal_timert *self)
int ec_outframe(int idx, int sock)
void ec_setupheader(void *p)
int ec_srconfirm(int idx, int timeout)
int ecx_waitinframe(ecx_portt *port, int idx, int timeout)
int ec_outframe_red(int idx)
PACKED_BEGIN struct PACKED ec_comt
int(* txbuflength)[EC_MAXBUF]
ec_bufT(* rxbuf)[EC_MAXBUF]
int ecx_srconfirm(ecx_portt *port, int idx, int timeout)
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
pthread_mutex_t getindex_mutex
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
int ecx_outframe_red(ecx_portt *port, int idx)
void ecx_setbufstat(ecx_portt *port, int idx, int bufstat)
ec_bufT(* txbuf)[EC_MAXBUF]
PACKED_BEGIN struct PACKED ec_etherheadert
static void ecx_clear_rxbufstat(int *rxbufstat)
int ecx_inframe(ecx_portt *port, int idx, int stacknumber)
int(* rxbufstat)[EC_MAXBUF]
static int ecx_recvpkt(ecx_portt *port, int stacknumber)
int ecx_getindex(ecx_portt *port)
soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Wed Mar 2 2022 01:01:49