Commit 2e755840 authored by Aurelio Colosimo's avatar Aurelio Colosimo

defined and used NP macro as ppi->net_path shortcut

parent 5ad45baf
......@@ -10,12 +10,12 @@
/* FIXME: which socket we receive and send with? */
int bare_recv_packet(struct pp_instance *ppi, void *pkt, int len)
{
return sys_recv(ppi->net_path->ch[PP_NP_GEN].fd, pkt, len, 0);
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
}
int bare_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
{
return sys_send(ppi->net_path->ch[chtype].fd, pkt, len, 0);
return sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
}
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
......@@ -53,9 +53,9 @@ int bare_open_ch(struct pp_instance *ppi, char *ifname)
pp_diag_error(ppi, bare_errno);
pp_diag_fatal(ppi, "ioctl(GIFHWADDR)", "");
}
memcpy(ppi->net_path->ch[PP_NP_GEN].addr,
memcpy(NP(ppi)->ch[PP_NP_GEN].addr,
ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
memcpy(ppi->net_path->ch[PP_NP_EVT].addr,
memcpy(NP(ppi)->ch[PP_NP_EVT].addr,
ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
/* bind and setsockopt */
......@@ -68,7 +68,7 @@ int bare_open_ch(struct pp_instance *ppi, char *ifname)
pp_diag_fatal(ppi, "bind", "");
}
ppi->net_path->ch[PP_NP_GEN].fd = sock;
ppi->net_path->ch[PP_NP_EVT].fd = sock;
NP(ppi)->ch[PP_NP_GEN].fd = sock;
NP(ppi)->ch[PP_NP_EVT].fd = sock;
return 0;
}
......@@ -46,11 +46,11 @@ void bare_main_loop(struct pp_instance *ppi)
again:
FD_ZERO(&set);
FD_SET(ppi->net_path->ch[PP_NP_GEN].fd, &set);
FD_SET(ppi->net_path->ch[PP_NP_EVT].fd, &set);
maxfd = ppi->net_path->ch[PP_NP_GEN].fd;
if (ppi->net_path->ch[PP_NP_EVT].fd > maxfd)
maxfd = ppi->net_path->ch[PP_NP_EVT].fd;
FD_SET(NP(ppi)->ch[PP_NP_GEN].fd, &set);
FD_SET(NP(ppi)->ch[PP_NP_EVT].fd, &set);
maxfd = NP(ppi)->ch[PP_NP_GEN].fd;
if (NP(ppi)->ch[PP_NP_EVT].fd > maxfd)
maxfd = NP(ppi)->ch[PP_NP_EVT].fd;
i = sys_select(maxfd + 1, &set, NULL, NULL, &tv);
if (i < 0 && bare_errno != 4 /* EINTR */)
......
......@@ -29,12 +29,12 @@ int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len)
/* TODO: rewrite it in a better way! */
switch (ch_check_stat) {
case 0:
ch1 = &(ppi->net_path->ch[PP_NP_EVT]);
ch2 = &(ppi->net_path->ch[PP_NP_GEN]);
ch1 = &(NP(ppi)->ch[PP_NP_EVT]);
ch2 = &(NP(ppi)->ch[PP_NP_GEN]);
break;
case 1:
ch1 = &(ppi->net_path->ch[PP_NP_GEN]);
ch2 = &(ppi->net_path->ch[PP_NP_EVT]);
ch1 = &(NP(ppi)->ch[PP_NP_GEN]);
ch2 = &(NP(ppi)->ch[PP_NP_EVT]);
break;
default:
/* Impossible! */
......@@ -53,7 +53,7 @@ int posix_recv_packet(struct pp_instance *ppi, void *pkt, int len)
int posix_send_packet(struct pp_instance *ppi, void *pkt, int len, int chtype)
{
return send(ppi->net_path->ch[chtype].fd, pkt, len, 0);
return send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
}
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
......@@ -99,8 +99,8 @@ int posix_open_ch(struct pp_instance *ppi, char *ifname)
return -1;
}
/* FIXME: what to do with hw address */
memcpy(ppi->net_path->ch[PP_NP_GEN].addr, ifr.ifr_hwaddr.sa_data, 6);
memcpy(ppi->net_path->ch[PP_NP_EVT].addr, ifr.ifr_hwaddr.sa_data, 6);
memcpy(NP(ppi)->ch[PP_NP_GEN].addr, ifr.ifr_hwaddr.sa_data, 6);
memcpy(NP(ppi)->ch[PP_NP_EVT].addr, ifr.ifr_hwaddr.sa_data, 6);
/* bind and setsockopt */
memset(&addr, 0, sizeof(addr));
......@@ -113,8 +113,8 @@ int posix_open_ch(struct pp_instance *ppi, char *ifname)
return -1;
}
/* FIXME: we are using the same socket for both channels by now */
ppi->net_path->ch[PP_NP_GEN].fd = sock;
ppi->net_path->ch[PP_NP_EVT].fd = sock;
NP(ppi)->ch[PP_NP_GEN].fd = sock;
NP(ppi)->ch[PP_NP_EVT].fd = sock;
return 0;
}
......@@ -164,14 +164,14 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
arch_data->tv.tv_usec = (delay_ms % 1000) * 1000;
}
ppi->net_path->ch[PP_NP_GEN].pkt_present = 0;
ppi->net_path->ch[PP_NP_EVT].pkt_present = 0;
NP(ppi)->ch[PP_NP_GEN].pkt_present = 0;
NP(ppi)->ch[PP_NP_EVT].pkt_present = 0;
maxfd = (ppi->net_path->ch[PP_NP_GEN].fd > ppi->net_path->ch[PP_NP_EVT].fd) ?
ppi->net_path->ch[PP_NP_GEN].fd : ppi->net_path->ch[PP_NP_EVT].fd;
maxfd = (NP(ppi)->ch[PP_NP_GEN].fd > NP(ppi)->ch[PP_NP_EVT].fd) ?
NP(ppi)->ch[PP_NP_GEN].fd : NP(ppi)->ch[PP_NP_EVT].fd;
FD_ZERO(&set);
FD_SET(ppi->net_path->ch[PP_NP_GEN].fd, &set);
FD_SET(ppi->net_path->ch[PP_NP_EVT].fd, &set);
FD_SET(NP(ppi)->ch[PP_NP_GEN].fd, &set);
FD_SET(NP(ppi)->ch[PP_NP_EVT].fd, &set);
i = select(maxfd + 1, &set, NULL, NULL, &arch_data->tv);
if (i < 0 && errno != EINTR)
......@@ -185,14 +185,14 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
if (i == 0)
goto _end;
if (FD_ISSET(ppi->net_path->ch[PP_NP_GEN].fd, &set)) {
if (FD_ISSET(NP(ppi)->ch[PP_NP_GEN].fd, &set)) {
ret++;
ppi->net_path->ch[PP_NP_GEN].pkt_present = 1;
NP(ppi)->ch[PP_NP_GEN].pkt_present = 1;
}
if (FD_ISSET(ppi->net_path->ch[PP_NP_EVT].fd, &set)) {
if (FD_ISSET(NP(ppi)->ch[PP_NP_EVT].fd, &set)) {
ret++;
ppi->net_path->ch[PP_NP_EVT].pkt_present = 1;
NP(ppi)->ch[PP_NP_EVT].pkt_present = 1;
}
_end:
......
......@@ -16,8 +16,8 @@ int spec_open_ch(struct pp_instance *ppi)
ep_enable(1, 1);
minic_init();
memcpy(ppi->net_path->ch[PP_NP_GEN].addr, fake_addr, 6);
memcpy(ppi->net_path->ch[PP_NP_EVT].addr, fake_addr, 6);
memcpy(NP(ppi)->ch[PP_NP_GEN].addr, fake_addr, 6);
memcpy(NP(ppi)->ch[PP_NP_EVT].addr, fake_addr, 6);
return 0;
}
......
......@@ -175,6 +175,7 @@ struct pp_instance {
#define DSPOR(x) ((x)->portDS)
#define DSPRO(x) ((x)->timePropertiesDS)
#define NP(x) ((x)->net_path)
/* The channel for an instance must be created and possibly destroyed. */
extern int pp_open_instance(struct pp_instance *ppi,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment