33 #include <sys/types.h>
34 #include <sys/ioctl.h>
36 #include <sys/socket.h>
40 #include <arpa/inet.h>
44 #include <netpacket/packet.h>
71 #define RX_PRIM priMAC[1]
73 #define RX_SEC secMAC[1]
94 struct timeval timeout;
96 struct sockaddr_ll sll;
98 pthread_mutexattr_t mutexattr;
127 pthread_mutexattr_init(&mutexattr);
128 pthread_mutexattr_setprotocol(&mutexattr , PTHREAD_PRIO_INHERIT);
130 pthread_mutex_init(&(port->
tx_mutex) , &mutexattr);
131 pthread_mutex_init(&(port->
rx_mutex) , &mutexattr);
146 *psock = socket(PF_PACKET, SOCK_RAW, htons(
ETH_P_ECAT));
150 r = setsockopt(*psock, SOL_SOCKET, SO_RCVTIMEO, &timeout,
sizeof(timeout));
151 r = setsockopt(*psock, SOL_SOCKET, SO_SNDTIMEO, &timeout,
sizeof(timeout));
153 r = setsockopt(*psock, SOL_SOCKET, SO_DONTROUTE, &i,
sizeof(i));
155 strcpy(ifr.ifr_name, ifname);
156 r = ioctl(*psock, SIOCGIFINDEX, &ifr);
157 ifindex = ifr.ifr_ifindex;
158 strcpy(ifr.ifr_name, ifname);
161 r = ioctl(*psock, SIOCGIFFLAGS, &ifr);
163 ifr.ifr_flags = ifr.ifr_flags | IFF_PROMISC | IFF_BROADCAST;
164 r = ioctl(*psock, SIOCSIFFLAGS, &ifr);
166 sll.sll_family = AF_PACKET;
167 sll.sll_ifindex = ifindex;
169 r = bind(*psock, (
struct sockaddr *)&sll,
sizeof(sll));
177 if (r == 0) rval = 1;
205 bp->da0 = htons(0xffff);
206 bp->da1 = htons(0xffff);
207 bp->da2 = htons(0xffff);
208 bp->sa0 = htons(
priMAC[0]);
209 bp->sa1 = htons(
priMAC[1]);
210 bp->sa2 = htons(
priMAC[2]);
277 stack = &(port->
stack);
285 rval = send(*stack->
sock, (*stack->
txbuf)[idx], lp, 0);
307 ehp->sa1 = htons(
priMAC[1]);
312 pthread_mutex_lock( &(port->
tx_mutex) );
317 datagramP->index = idx;
319 ehp->sa1 = htons(
secMAC[1]);
326 pthread_mutex_unlock( &(port->
tx_mutex) );
344 stack = &(port->
stack);
351 bytesrx = recv(*stack->
sock, (*stack->
tempbuf), lp, 0);
354 return (bytesrx > 0);
385 stack = &(port->
stack);
396 l = (*rxbuf)[0] + ((
uint16)((*
rxbuf)[1] & 0x0f) << 8);
398 rval = ((*rxbuf)[l] + ((
uint16)(*
rxbuf)[l + 1] << 8));
404 pthread_mutex_lock(&(port->
rx_mutex));
414 l =
etohs(ecp->elength) & 0x0fff;
422 rval = ((*rxbuf)[l] + ((
uint16)((*
rxbuf)[l + 1]) << 8));
426 (*stack->
rxsa)[idx] = ntohs(ehp->sa1);
438 (*stack->
rxsa)[idxf] = ntohs(ehp->sa1);
447 pthread_mutex_unlock( &(port->
rx_mutex) );
511 if ( ((primrx == 0) && (secrx ==
RX_SEC)) ||
631 int ec_inframe(
int idx,
int stacknumber)