aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Delevoryas <pdel@fb.com>2022-05-13 19:56:45 -0700
committerPeter Delevoryas <pdel@fb.com>2022-05-18 21:11:04 -0700
commitda3afd3ccdde4f2317f3a73e31c879c0a2847a25 (patch)
tree559926d481fd2dffc7701af64996a2469a9f2263
parent2facdf288df59690b62037cb91df472b2215e975 (diff)
downloadslirp-da3afd3ccdde4f2317f3a73e31c879c0a2847a25.zip
slirp-da3afd3ccdde4f2317f3a73e31c879c0a2847a25.tar.gz
slirp-da3afd3ccdde4f2317f3a73e31c879c0a2847a25.tar.bz2
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 <pdel@fb.com>
-rw-r--r--src/ncsi.c18
1 files 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 {