68 #include <sys/types.h> 69 #include <sys/ioctl.h> 71 #include <sys/socket.h> 75 #include <arpa/inet.h> 79 #include <netpacket/packet.h> 106 #define RX_PRIM priMAC[1] 108 #define RX_SEC secMAC[1] 119 int r, rval, ifindex;
120 struct timeval timeout;
122 struct sockaddr_ll sll;
152 pthread_mutex_init(&(port->
tx_mutex) , NULL);
153 pthread_mutex_init(&(port->
rx_mutex) , NULL);
167 *psock = socket(PF_PACKET, SOCK_RAW, htons(
ETH_P_ECAT));
171 r = setsockopt(*psock, SOL_SOCKET, SO_RCVTIMEO, &timeout,
sizeof(timeout));
172 r = setsockopt(*psock, SOL_SOCKET, SO_SNDTIMEO, &timeout,
sizeof(timeout));
174 r = setsockopt(*psock, SOL_SOCKET, SO_DONTROUTE, &i,
sizeof(i));
176 strcpy(ifr.ifr_name, ifname);
177 r = ioctl(*psock, SIOCGIFINDEX, &ifr);
178 ifindex = ifr.ifr_ifindex;
179 strcpy(ifr.ifr_name, ifname);
182 r = ioctl(*psock, SIOCGIFFLAGS, &ifr);
184 ifr.ifr_flags = ifr.ifr_flags || IFF_PROMISC || IFF_BROADCAST;
185 r = ioctl(*psock, SIOCGIFFLAGS, &ifr);
187 sll.sll_family = AF_PACKET;
188 sll.sll_ifindex = ifindex;
190 r = bind(*psock, (
struct sockaddr *)&sll,
sizeof(sll));
198 if (r == 0) rval = 1;
226 bp->da0 = htons(0xffff);
227 bp->da1 = htons(0xffff);
228 bp->da2 = htons(0xffff);
229 bp->sa0 = htons(
priMAC[0]);
230 bp->sa1 = htons(
priMAC[1]);
231 bp->sa2 = htons(
priMAC[2]);
298 stack = &(port->
stack);
305 rval = send(*stack->
sock, (*stack->
txbuf)[idx], lp, 0);
324 ehp->sa1 = htons(
priMAC[1]);
329 pthread_mutex_lock( &(port->
tx_mutex) );
334 datagramP->index = idx;
336 ehp->sa1 = htons(
secMAC[1]);
339 pthread_mutex_unlock( &(port->
tx_mutex) );
358 stack = &(port->
stack);
365 bytesrx = recv(*stack->
sock, (*stack->
tempbuf), lp, 0);
368 return (bytesrx > 0);
399 stack = &(port->
stack);
406 rxbuf = &(*stack->
rxbuf)[idx];
410 l = (*rxbuf)[0] + ((
uint16)((*rxbuf)[1] & 0x0f) << 8);
412 rval = ((*rxbuf)[l] + ((
uint16)(*rxbuf)[l + 1] << 8));
418 pthread_mutex_lock(&(port->
rx_mutex));
428 l =
etohs(ecp->elength) & 0x0fff;
436 rval = ((*rxbuf)[l] + ((
uint16)((*rxbuf)[l + 1]) << 8));
440 (*stack->
rxsa)[idx] = ntohs(ehp->sa1);
447 rxbuf = &(*stack->
rxbuf)[idxf];
452 (*stack->
rxsa)[idxf] = ntohs(ehp->sa1);
461 pthread_mutex_unlock( &(port->
rx_mutex) );
525 if ( ((primrx == 0) && (secrx ==
RX_SEC)) ||
625 int ec_setupnic(
const char *ifname,
int secondary)
630 int ec_closenic(
void)
635 int ec_getindex(
void)
640 void ec_setbufstat(
int idx,
int bufstat)
645 int ec_outframe(
int idx,
int stacknumber)
650 int ec_outframe_red(
int idx)
655 int ec_inframe(
int idx,
int stacknumber)
660 int ec_waitinframe(
int idx,
int timeout)
665 int ec_srconfirm(
int idx,
int timeout)
int ecx_getindex(ecx_portt *port)
int txbuflength[EC_MAXBUF]
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
boolean osal_timer_is_expired(osal_timert *self)
ec_bufT(* rxbuf)[EC_MAXBUF]
ec_bufT(* txbuf)[EC_MAXBUF]
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)
void osal_timer_start(osal_timert *self, uint32 timeout_us)
static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer)
pthread_mutex_t getindex_mutex
uint8 ec_bufT[EC_BUFSIZE]
int ecx_closenic(ecx_portt *port)
int ecx_outframe_red(ecx_portt *port, int idx)
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)