Commit 73cbbd9b authored by Alessandro Rubini's avatar Alessandro Rubini

fix frames offsets (now bare works)

This commits removes all the additions and subtractions of
the protocol offset. Now all recv and send functions, receive
the pointer to the actual data being sent, be it the ptp payload
or the transport header.

This simplification (though based on the two internal pointers within
ppsi -- se previous commit) fixed a long standing bug with bare
architectures, that didn't receive the frames due to some related
problem in offset calculation.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 06ef4b9b
......@@ -34,8 +34,6 @@ void posix_main_loop(struct pp_instance *ppi)
delay_ms = pp_state_machine(ppi, NULL, 0);
while (1) {
int i;
unsigned char packet[1500];
void *payload = packet + 16; /* aligned */
again:
......@@ -53,8 +51,9 @@ void posix_main_loop(struct pp_instance *ppi)
* We got a packet. If it's not ours, continue consuming
* the pending timeout
*/
i = ppi->n_ops->recv(ppi, payload, sizeof(packet) - 16,
&ppi->last_rcv_time);
i = ppi->n_ops->recv(ppi, ppi->rx_frame,
PP_MAX_FRAME_LENGTH - 4,
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
......@@ -66,6 +65,7 @@ void posix_main_loop(struct pp_instance *ppi)
goto again;
}
delay_ms = pp_state_machine(ppi, payload, i);
delay_ms = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
}
}
......@@ -95,17 +95,11 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t)
{
struct pp_channel *ch1 = NULL, *ch2 = NULL;
void *hdr;
int ret;
if (OPTS(ppi)->ethernet_mode) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
hdr = pp_get_header(ppi, pkt);
ret = posix_recv_msg(ppi, fd, hdr,
len + NP(ppi)->ptp_offset, t);
return ret <= 0 ? ret : ret - NP(ppi)->ptp_offset;
/* FIXME: check header */
return posix_recv_msg(ppi, fd, pkt, len, t);
}
/* else: UDP */
......@@ -132,11 +126,9 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
{
struct sockaddr_in addr;
struct ethhdr *hdr;
struct ethhdr *hdr = pkt;
if (OPTS(ppi)->ethernet_mode) {
hdr = pp_get_header(ppi, pkt);
hdr->h_proto = htons(ETH_P_1588);
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
......@@ -146,8 +138,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t)
ppi->t_ops->get(t);
return send(NP(ppi)->ch[PP_NP_GEN].fd, hdr,
len + NP(ppi)->ptp_offset, 0);
return send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0);
}
/* else: UDP */
......
......@@ -14,15 +14,14 @@ static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len,
if (t)
ppi->t_ops->get(t);
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd,
pkt - NP(ppi)->ptp_offset, len, 0);
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
}
static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t, int chtype, int use_pdelay_addr)
{
struct bare_ethhdr *hdr;
hdr = pp_get_header(ppi, pkt);
struct bare_ethhdr *hdr = pkt;
hdr->h_proto = htons(ETH_P_1588);
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, 6);
......@@ -33,8 +32,7 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t)
ppi->t_ops->get(t);
return sys_send(NP(ppi)->ch[chtype].fd, hdr,
len + NP(ppi)->ptp_offset, 0);
return sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
}
#define SHUT_RD 0
......
......@@ -34,8 +34,6 @@ void bare_main_loop(struct pp_instance *ppi)
struct bare_fd_set set;
int i, maxfd;
struct bare_timeval tv;
unsigned char packet[1500];
void *payload = packet + 16; /* aligned */
/* Wait for a packet or for the timeout */
tv.tv_sec = delay_ms / 1000;
......@@ -66,15 +64,17 @@ void bare_main_loop(struct pp_instance *ppi)
*
* FIXME: we don't know which socket to receive from
*/
i = ppi->n_ops->recv(ppi, payload, sizeof(packet) - 16,
&ppi->last_rcv_time);
i = ppi->n_ops->recv(ppi, ppi->rx_frame,
PP_MAX_FRAME_LENGTH - 4,
&ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
/* we passed payload but it filled the ether header too */
if (((struct bare_ethhdr *)(packet + 2))->h_proto
if (((struct bare_ethhdr *)(ppi->rx_frame))->h_proto
!= htons(PP_ETHERTYPE))
goto again;
delay_ms = pp_state_machine(ppi, packet, i);
delay_ms = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
}
}
......@@ -40,7 +40,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static inline int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype)
{
if (ppi->n_ops->send(ppi, ppi->tx_ptp, msglen,
if (ppi->n_ops->send(ppi, ppi->tx_frame, msglen + NP(ppi)->ptp_offset,
&ppi->last_snt_time, chtype, 0) < msglen) {
if (pp_verbose_frames)
PP_PRINTF("%s(%d) Message can't be sent\n",
......
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