Commit f2ec9766 authored by Aurelio Colosimo's avatar Aurelio Colosimo

state-listening partly completed. Still missing addForeign and issue msgs.

parent 14c4b984
......@@ -46,12 +46,12 @@ void posix_main_loop(struct pp_instance *ppi)
* the pending timeout
*/
i = posix_recv_packet(ppi, packet, sizeof(packet));
/* FIXME
if (i < sizeof(struct pp_packet)) {
if (i < PP_PACKET_SIZE) {
delay_ms = -1;
goto again;
}
*/
/* Warning: PP_PROTO_NR is endian-agnostic by design */
if ( ((struct ethhdr *)packet)->h_proto != htons(PP_PROTO_NR)) {
delay_ms = -1;
......
......@@ -40,10 +40,12 @@ int main(int argc, char **argv)
ppi->net_path = calloc(1, sizeof(*ppi->net_path));
ppi->buf_out = calloc(1, PP_PACKET_SIZE);
ppi->buf_in = calloc(1, PP_PACKET_SIZE);
ppi->frgn_master = calloc(1, sizeof(*ppi->frgn_master));;
if ((!ppi->defaultDS) || (!ppi->currentDS) || (!ppi->parentDS)
|| (!ppi->portDS) || (!ppi->timePropertiesDS) || (!ppi->sent_seq_id)
|| (!ppi->net_path) || (!ppi->buf_out) || (!ppi->buf_in)
|| (!ppi->frgn_master)
)
exit(__LINE__);
......
......@@ -79,7 +79,7 @@ extern int posix_timer_expired(struct pp_timer *tm)
int pp_timer_init(struct pp_instance *ppi)
__attribute__((alias("posix_timer_init")));
int pp_timer_start(struct pp_timer *tm)
int pp_timer_start(uint32_t interval, struct pp_timer *tm)
__attribute__((alias("posix_timer_start")));
int pp_timer_stop(struct pp_timer *tm)
......
......@@ -106,7 +106,7 @@ struct pp_net_path
*/
struct pp_instance {
int state;
int next_state, next_delay; /* set by state processing */
int next_state, next_delay, is_new_state; /* set by state processing */
void *arch_data; /* if arch needs it */
void *ext_data; /* if protocol ext needs it */
struct pp_runtime_opts *rt_opts;
......@@ -127,8 +127,9 @@ struct pp_instance {
Integer16 foreign_record_i;
Integer16 foreign_record_best;
Boolean record_update;
struct pp_frgn_master *frgn_master;
Octet *buf_out;
Octet *buf_in;
Octet *buf_in; /* FIXME really useful? Probably not*/
union {
MsgSync sync;
......@@ -177,11 +178,45 @@ extern UInteger16 pp_htons(UInteger16 hostshort);
/* Timers */
extern int pp_timer_init(struct pp_instance *ppi); /* initializes timer common
structure */
extern int pp_timer_start(struct pp_timer *tm);
extern int pp_timer_start(uint32_t interval, struct pp_timer *tm);
extern int pp_timer_stop(struct pp_timer *tm);
extern int pp_timer_expired(struct pp_timer *tm); /* returns 1 when expired */
/* bmc.c */
extern void m1(struct pp_instance *ppi);
extern void s1(MsgHeader *header, MsgAnnounce *ann, struct pp_instance *ppi);
extern UInteger8 bmc(struct pp_frgn_master *frgn_master,
struct pp_runtime_opts *rt_opts, struct pp_instance *ppi);
/* msg.c */
extern void msg_pack_header(void *buf, struct pp_instance *ppi);
extern void msg_unpack_header(void *buf, MsgHeader *hdr);
extern void msg_pack_sync(void *buf, Timestamp *orig_tstamp,
struct pp_instance *ppi);
extern void msg_unpack_sync(void *buf, MsgSync *sync);
extern void msg_pack_announce(void *buf, struct pp_instance *ppi);
extern void msg_unpack_announce(void *buf, MsgAnnounce *ann);
extern void msg_pack_follow_up(void *buf, Timestamp *prec_orig_tstamp,
struct pp_instance *ppi);
extern void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup);
extern void msg_pack_pdelay_req(void *buf, Timestamp *orig_tstamp,
struct pp_instance *ppi);
extern void msg_unpack_pdelay_req(void *buf, MsgPDelayReq *pdelay_req);
extern void msg_pack_delay_req(void *buf, Timestamp *orig_tstamp,
struct pp_instance *ppi);
extern void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req);
extern void msg_pack_delay_resp(void *buf, MsgHeader *hdr,
Timestamp *rcv_tstamp, struct pp_instance *ppi);
extern void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp);
extern void msg_pack_pdelay_resp(void *buf, MsgHeader *hdr,
Timestamp *req_rec_tstamp, struct pp_instance *ppi);
extern void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp *presp);
extern void msg_pack_pdelay_resp_followup(void *buf, MsgHeader *hdr,
Timestamp *resp_orig_tstamp, struct pp_instance* ppi);
extern void msg_unpack_pdelay_resp_followup(void *buf,
MsgPDelayRespFollowUp *presp_follow);
/* Get a timestamp */
extern void pp_get_stamp(uint32_t *sptr);
......
......@@ -62,7 +62,7 @@ void msg_pack_header(void *buf, struct pp_instance *ppi)
/* Pack Sync message into out buffer of ppi */
void msg_pack_sync(void *buf, Timestamp * orig_tstamp, struct pp_instance *ppi)
void msg_pack_sync(void *buf, Timestamp *orig_tstamp, struct pp_instance *ppi)
{
/* changes in header */
*(char *)(buf + 0) = *(char *)(buf + 0) & 0xF0;
......
......@@ -3,8 +3,80 @@
*/
#include <pproto/pproto.h>
static void restart_annrec_timer(struct pp_instance *ppi)
{
/* 0 <= logAnnounceInterval <= 4, see pag. 237 of spec */
/* FIXME: if (logAnnounceInterval < 0), error? Or handle a right
* shift?*/
pp_timer_start((DSPOR(ppi)->announceReceiptTimeout) <<
DSPOR(ppi)->logAnnounceInterval,
ppi->timers[PP_TIMER_ANNOUNCE_RECEIPT]);
}
int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
/* TODO */
if (ppi->is_new_state) {
restart_annrec_timer(ppi);
}
if (pp_timer_expired(ppi->timers[PP_TIMER_ANNOUNCE_RECEIPT])) {
/* FIXME diag
* DBGV("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n");
*/
ppi->number_foreign_records = 0;
ppi->foreign_record_i = 0;
if (!DSDEF(ppi)->slaveOnly &&
DSDEF(ppi)->clockQuality.clockClass != 255) {
m1(ppi);
ppi->next_state = PPS_MASTER;
}
else {
restart_annrec_timer(ppi);
}
}
if (ppi->rt_opts->e2e_mode) {
if (pp_timer_expired(ppi->timers[PP_TIMER_DELAYREQ_INTERVAL])) {
/* FIXME diag
* DBGV("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
*/
/* TODO issueDelayReq(rtOpts,ptpClock); */
}
} else {
if (pp_timer_expired(ppi->timers[PP_TIMER_PDELAYREQ_INTERVAL]))
{
/* FIXME diag
DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
*/
/* TODO issuePDelayReq(rtOpts,ptpClock); */
}
}
if (ppi->msg_tmp_header.messageType == PPM_ANNOUNCE) {
/* TODO check isFromSelf?
if (isFromSelf) {
DBGV("HandleAnnounce : Ignore message from self \n");
return;
}
*/
/* FIXME diag
* DBGV("Announce message from another foreign master");
*/
/* TODO addForeign(ptpClock->msgIbuf,header,ptpClock); */
ppi->record_update = TRUE;
if(ppi->record_update) {
/* FIXME diag DBGV("event STATE_DECISION_EVENT\n"); */
ppi->record_update = FALSE;
ppi->next_state = bmc(ppi->frgn_master,
ppi->rt_opts, ppi);
}
}
return 0;
}
......@@ -18,6 +18,10 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
struct pp_state_table_item *ip;
int state, err;
if (packet) {
msg_unpack_header(packet, &ppi->msg_tmp_header);
}
state = ppi->state;
/* a linear search is affordable up to a few dozen items */
......@@ -27,6 +31,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
/* found: handle this state */
ppi->next_state = state;
ppi->next_delay = 0;
ppi->is_new_state = 0;
pp_diag_fsm(ppi, 0 /* enter */, plen);
err = ip->f1(ppi, packet, plen);
if (!err && ip->f2)
......@@ -36,7 +41,10 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
pp_diag_fsm(ppi, 1 /* leave */, 0 /* unused */);
/* done: accept next state and delay */
ppi->state = ppi->next_state;
if (ppi->state != ppi->next_state) {
ppi->state = ppi->next_state;
ppi->is_new_state = 1;
}
return ppi->next_delay;
}
/* Unknwon state, can't happen */
......
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