--- fwsync/driver/fwsync.c 2022/06/29 19:44:58 1.2 +++ fwsync/driver/fwsync.c 2022/07/05 21:50:36 1.4 @@ -8,12 +8,44 @@ static intptr_t fwsync_wchan; +static int +fwsync_add_state_4(const struct fws_proto *pkt) +{ + DTRACE(); + + return 0; +} + +static int +fwsync_add_state_6(const struct fws_proto *pkt) +{ + DTRACE(); + + return 0; +} + +static int +fwsync_add_state(const struct fws_proto *pkt) +{ + DTRACE(); + + if (pkt->fws_addrtype == 4) + fwsync_add_state_4(pkt); + else if (pkt->fws_addrtype == 6) + fwsync_add_state_6(pkt); + else + return EINVAL; + + return 0; +} + static void fwsync_edge_proc(void *arg) { - int e, rcvflg; + int e, rcvflg = 0; struct uio uio; struct mbuf *m = NULL; + struct fws_proto *pkt; DTRACE(); @@ -34,8 +66,27 @@ fwsync_edge_proc(void *arg) tsleep(&fwsync_wchan, 0, "edge_handler", hz); continue; } + pkt = mtod(m, struct fws_proto*); + if (m_length(m, NULL) != sizeof(struct fws_proto)) { + printf("FWSync packet length=%d isn't match expected %lu\n", + m_length(m, NULL), sizeof(struct fws_proto)); + continue; + } - printf("%u...-> %s\n", m->m_len, m->m_data); + switch (pkt->fws_version) { + case FWS_PKTVER_STATE: + fwsync_add_state(pkt); + break; + case FWS_PKTVER_ALIAS_OUT: + break; + case FWS_PKTVER_ALIAS_IN: + break; + default: + printf("FWSync packet was discarded due to wrong version\n"); + continue; + } + + printf("%u...-> %s version=%c\n", m->m_len, m->m_data, pkt->fws_version); } fws_ctx.config &= ~CTX_EDGE_ONLINE;