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);
392 rxbuf = &(*stack->
rxbuf)[idx];
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);
433 rxbuf = &(*stack->
rxbuf)[idxf];
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)
int ecx_getindex(ecx_portt *port)
int ec_outframe(int idx, int sock)
boolean osal_timer_is_expired(osal_timert *self)
int txbuflength[EC_MAXBUF]
int ec_setupnic(const char *ifname, int secondary)
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
static int ecx_recvpkt(ecx_portt *port, int stacknumber)
int ecx_inframe(ecx_portt *port, int idx, int stacknumber)
int(* txbuflength)[EC_MAXBUF]
PACKED_BEGIN struct PACKED ec_etherheadert
ec_bufT(* rxbuf)[EC_MAXBUF]
int ec_srconfirm(int idx, int timeout)
ec_bufT(* txbuf)[EC_MAXBUF]
void ec_setbufstat(int idx, int bufstat)
int ecx_waitinframe(ecx_portt *port, int idx, int timeout)
PACKED_BEGIN struct PACKED ec_comt
int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
Headerfile for ethercatbase.c.
static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer)
pthread_mutex_t getindex_mutex
int ec_outframe_red(int idx)
uint8 ec_bufT[EC_BUFSIZE]
static void ecx_clear_rxbufstat(int *rxbufstat)
int ecx_closenic(ecx_portt *port)
int ecx_outframe_red(ecx_portt *port, int idx)
int ec_waitinframe(int idx, int timeout)
void osal_timer_start(osal_timert *self, uint32 timeout_usec)
int(* rxbufstat)[EC_MAXBUF]
void ec_setupheader(void *p)
void ecx_setbufstat(ecx_portt *port, int idx, int bufstat)
int ecx_srconfirm(ecx_portt *port, int idx, int timeout)