From da3afd3ccdde4f2317f3a73e31c879c0a2847a25 Mon Sep 17 00:00:00 2001 From: Peter Delevoryas Date: Fri, 13 May 2022 19:56:45 -0700 Subject: ncsi: Pass command header to response handlers This change passes the command header as an additional read-only parameter to each response handler so that they can make more response handling descisions based on the command header fields. This is especially useful for handling OEM NC-SI commands, or any protocol that's encapsulated in an NC-SI header. Signed-off-by: Peter Delevoryas --- src/ncsi.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ncsi.c b/src/ncsi.c index 5bf731b..bfe3088 100644 --- a/src/ncsi.c +++ b/src/ncsi.c @@ -56,7 +56,8 @@ static uint32_t ncsi_calculate_checksum(uint8_t *data, int len) } /* Get Version ID */ -static int ncsi_rsp_handler_gvi(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gvi(Slirp *slirp, const struct ncsi_pkt_hdr *nh, + struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gvi_pkt *rsp = (struct ncsi_rsp_gvi_pkt *)rnh; @@ -67,7 +68,8 @@ static int ncsi_rsp_handler_gvi(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) } /* Get Capabilities */ -static int ncsi_rsp_handler_gc(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gc(Slirp *slirp, const struct ncsi_pkt_hdr *nh, + struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gc_pkt *rsp = (struct ncsi_rsp_gc_pkt *)rnh; @@ -82,7 +84,8 @@ static int ncsi_rsp_handler_gc(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) } /* Get Link status */ -static int ncsi_rsp_handler_gls(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gls(Slirp *slirp, const struct ncsi_pkt_hdr *nh, + struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gls_pkt *rsp = (struct ncsi_rsp_gls_pkt *)rnh; @@ -91,7 +94,8 @@ static int ncsi_rsp_handler_gls(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) } /* Get Parameters */ -static int ncsi_rsp_handler_gp(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gp(Slirp *slirp, const struct ncsi_pkt_hdr *nh, + struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gp_pkt *rsp = (struct ncsi_rsp_gp_pkt *)rnh; @@ -107,7 +111,8 @@ static int ncsi_rsp_handler_gp(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) static const struct ncsi_rsp_handler { unsigned char type; int payload; - int (*handler)(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh); + int (*handler)(Slirp *slirp, const struct ncsi_pkt_hdr *nh, + struct ncsi_rsp_pkt_hdr *rnh); } ncsi_rsp_handlers[] = { { NCSI_PKT_RSP_CIS, 4, NULL }, { NCSI_PKT_RSP_SP, 4, NULL }, { NCSI_PKT_RSP_DP, 4, NULL }, @@ -188,8 +193,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) rnh->reason = htons(NCSI_PKT_RSP_R_NO_ERROR); if (handler->handler) { - /* TODO: handle errors */ - handler->handler(slirp, rnh); + handler->handler(slirp, nh, rnh); } ncsi_rsp_len += handler->payload; } else { -- cgit v1.1