From 2b5bde77420b5eac86ba9452c3910136d095e917 Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 26 Oct 2019 18:25:04 -0400 Subject: [PATCH] board: Naming convention change for "sg" bus --- board/sg-cmd.c | 56 ++++++++++++------------- board/sg-cmd.h | 10 ++--- board/sg-led-cmd.h | 16 ++++---- board/sg-led.c | 34 +++++++-------- board/sg-led.h | 2 +- board/sg-nfc-cmd.h | 36 ++++++++-------- board/sg-nfc.c | 100 ++++++++++++++++++++++----------------------- board/sg-nfc.h | 2 +- 8 files changed, 128 insertions(+), 128 deletions(-) diff --git a/board/sg-cmd.c b/board/sg-cmd.c index 166422b..0ed6f25 100644 --- a/board/sg-cmd.c +++ b/board/sg-cmd.c @@ -12,15 +12,15 @@ union sg_req_any { uint8_t bytes[256]; }; -union sg_resp_any { - struct sg_resp_header resp; +union sg_res_any { + struct sg_res_header res; uint8_t bytes[256]; }; static HRESULT sg_req_validate(const void *ptr, size_t nbytes); -static void sg_resp_error( - struct sg_resp_header *resp, +static void sg_res_error( + struct sg_res_header *res, const struct sg_req_header *req); static HRESULT sg_req_validate(const void *ptr, size_t nbytes) @@ -60,7 +60,7 @@ static HRESULT sg_req_validate(const void *ptr, size_t nbytes) } void sg_req_transact( - struct iobuf *resp_frame, + struct iobuf *res_frame, const uint8_t *req_bytes, size_t req_nbytes, sg_dispatch_fn_t dispatch, @@ -68,10 +68,10 @@ void sg_req_transact( { struct iobuf req_span; union sg_req_any req; - union sg_resp_any resp; + union sg_res_any res; HRESULT hr; - assert(resp_frame != NULL); + assert(res_frame != NULL); assert(req_bytes != NULL); assert(dispatch != NULL); @@ -91,44 +91,44 @@ void sg_req_transact( return; } - hr = dispatch(ctx, &req, &resp); + hr = dispatch(ctx, &req, &res); if (hr != S_FALSE) { if (FAILED(hr)) { - sg_resp_error(&resp.resp, &req.req); + sg_res_error(&res.res, &req.req); } - sg_frame_encode(resp_frame, resp.bytes, resp.resp.hdr.frame_len); + sg_frame_encode(res_frame, res.bytes, res.res.hdr.frame_len); } } -void sg_resp_init( - struct sg_resp_header *resp, +void sg_res_init( + struct sg_res_header *res, const struct sg_req_header *req, size_t payload_len) { - assert(resp != NULL); + assert(res != NULL); assert(req != NULL); - resp->hdr.frame_len = sizeof(*resp) + payload_len; - resp->hdr.addr = req->hdr.addr; - resp->hdr.seq_no = req->hdr.seq_no; - resp->hdr.cmd = req->hdr.cmd; - resp->status = 0; - resp->payload_len = payload_len; + res->hdr.frame_len = sizeof(*res) + payload_len; + res->hdr.addr = req->hdr.addr; + res->hdr.seq_no = req->hdr.seq_no; + res->hdr.cmd = req->hdr.cmd; + res->status = 0; + res->payload_len = payload_len; } -static void sg_resp_error( - struct sg_resp_header *resp, +static void sg_res_error( + struct sg_res_header *res, const struct sg_req_header *req) { - assert(resp != NULL); + assert(res != NULL); assert(req != NULL); - resp->hdr.frame_len = sizeof(*resp); - resp->hdr.addr = req->hdr.addr; - resp->hdr.seq_no = req->hdr.seq_no; - resp->hdr.cmd = req->hdr.cmd; - resp->status = 1; - resp->payload_len = 0; + res->hdr.frame_len = sizeof(*res); + res->hdr.addr = req->hdr.addr; + res->hdr.seq_no = req->hdr.seq_no; + res->hdr.cmd = req->hdr.cmd; + res->status = 1; + res->payload_len = 0; } diff --git a/board/sg-cmd.h b/board/sg-cmd.h index ea2ae07..685377f 100644 --- a/board/sg-cmd.h +++ b/board/sg-cmd.h @@ -19,7 +19,7 @@ struct sg_req_header { uint8_t payload_len; }; -struct sg_resp_header { +struct sg_res_header { struct sg_header hdr; uint8_t status; uint8_t payload_len; @@ -28,16 +28,16 @@ struct sg_resp_header { typedef HRESULT (*sg_dispatch_fn_t)( void *ctx, const void *req, - void *resp); + void *res); void sg_req_transact( - struct iobuf *resp_frame, + struct iobuf *res_frame, const uint8_t *req_bytes, size_t req_nbytes, sg_dispatch_fn_t dispatch, void *ctx); -void sg_resp_init( - struct sg_resp_header *resp, +void sg_res_init( + struct sg_res_header *res, const struct sg_req_header *req, size_t payload_len); diff --git a/board/sg-led-cmd.h b/board/sg-led-cmd.h index ac22c33..f74505b 100644 --- a/board/sg-led-cmd.h +++ b/board/sg-led-cmd.h @@ -10,13 +10,13 @@ enum { SG_RGB_CMD_GET_INFO = 0xF0, }; -struct sg_led_resp_reset { - struct sg_resp_header resp; +struct sg_led_res_reset { + struct sg_res_header res; uint8_t payload; }; -struct sg_led_resp_get_info { - struct sg_resp_header resp; +struct sg_led_res_get_info { + struct sg_res_header res; uint8_t payload[9]; }; @@ -31,9 +31,9 @@ union sg_led_req_any { struct sg_led_req_set_color set_color; }; -union sg_led_resp_any { +union sg_led_res_any { uint8_t bytes[256]; - struct sg_resp_header simple; - struct sg_led_resp_reset reset; - struct sg_led_resp_get_info get_info; + struct sg_res_header simple; + struct sg_led_res_reset reset; + struct sg_led_res_get_info get_info; }; diff --git a/board/sg-led.c b/board/sg-led.c index 128cf4a..855e36b 100644 --- a/board/sg-led.c +++ b/board/sg-led.c @@ -11,17 +11,17 @@ static HRESULT sg_led_dispatch( void *ctx, const void *v_req, - void *v_resp); + void *v_res); static HRESULT sg_led_cmd_reset( const struct sg_led *led, const struct sg_req_header *req, - struct sg_led_resp_reset *resp); + struct sg_led_res_reset *res); static HRESULT sg_led_cmd_get_info( const struct sg_led *led, const struct sg_req_header *req, - struct sg_led_resp_get_info *resp); + struct sg_led_res_get_info *res); static HRESULT sg_led_cmd_set_color( const struct sg_led *led, @@ -47,15 +47,15 @@ void sg_led_init( void sg_led_transact( struct sg_led *led, - struct iobuf *resp_frame, + struct iobuf *res_frame, const void *req_bytes, size_t req_nbytes) { assert(led != NULL); - assert(resp_frame != NULL); + assert(res_frame != NULL); assert(req_bytes != NULL); - sg_req_transact(resp_frame, req_bytes, req_nbytes, sg_led_dispatch, led); + sg_req_transact(res_frame, req_bytes, req_nbytes, sg_led_dispatch, led); } #ifdef NDEBUG @@ -87,15 +87,15 @@ static void sg_led_dprintf( static HRESULT sg_led_dispatch( void *ctx, const void *v_req, - void *v_resp) + void *v_res) { const struct sg_led *led; const union sg_led_req_any *req; - union sg_led_resp_any *resp; + union sg_led_res_any *res; led = ctx; req = v_req; - resp = v_resp; + res = v_res; if (req->simple.hdr.addr != led->addr) { /* Not addressed to us, don't send a response */ @@ -104,10 +104,10 @@ static HRESULT sg_led_dispatch( switch (req->simple.hdr.cmd) { case SG_RGB_CMD_RESET: - return sg_led_cmd_reset(led, &req->simple, &resp->reset); + return sg_led_cmd_reset(led, &req->simple, &res->reset); case SG_RGB_CMD_GET_INFO: - return sg_led_cmd_get_info(led, &req->simple, &resp->get_info); + return sg_led_cmd_get_info(led, &req->simple, &res->get_info); case SG_RGB_CMD_SET_COLOR: return sg_led_cmd_set_color(led, &req->set_color); @@ -122,13 +122,13 @@ static HRESULT sg_led_dispatch( static HRESULT sg_led_cmd_reset( const struct sg_led *led, const struct sg_req_header *req, - struct sg_led_resp_reset *resp) + struct sg_led_res_reset *res) { HRESULT hr; sg_led_dprintf(led, "Reset\n"); - sg_resp_init(&resp->resp, req, sizeof(resp->payload)); - resp->payload = 0; + sg_res_init(&res->res, req, sizeof(res->payload)); + res->payload = 0; if (led->ops->reset != NULL) { hr = led->ops->reset(led->ops_ctx); @@ -147,11 +147,11 @@ static HRESULT sg_led_cmd_reset( static HRESULT sg_led_cmd_get_info( const struct sg_led *led, const struct sg_req_header *req, - struct sg_led_resp_get_info *resp) + struct sg_led_res_get_info *res) { sg_led_dprintf(led, "Get info\n"); - sg_resp_init(&resp->resp, req, sizeof(resp->payload)); - memcpy(resp->payload, sg_led_info, sizeof(sg_led_info)); + sg_res_init(&res->res, req, sizeof(res->payload)); + memcpy(res->payload, sg_led_info, sizeof(sg_led_info)); return S_OK; } diff --git a/board/sg-led.h b/board/sg-led.h index 2d4ba01..de3caa6 100644 --- a/board/sg-led.h +++ b/board/sg-led.h @@ -25,6 +25,6 @@ void sg_led_init( void sg_led_transact( struct sg_led *led, - struct iobuf *resp_frame, + struct iobuf *res_frame, const void *req_bytes, size_t req_nbytes); diff --git a/board/sg-nfc-cmd.h b/board/sg-nfc-cmd.h index aeab127..b6754c2 100644 --- a/board/sg-nfc-cmd.h +++ b/board/sg-nfc-cmd.h @@ -19,13 +19,13 @@ enum { SG_NFC_CMD_FELICA_ENCAP = 0x71, }; -struct sg_nfc_resp_get_fw_version { - struct sg_resp_header resp; +struct sg_nfc_res_get_fw_version { + struct sg_res_header res; char version[23]; }; -struct sg_nfc_resp_get_hw_version { - struct sg_resp_header resp; +struct sg_nfc_res_get_hw_version { + struct sg_res_header res; char version[23]; }; @@ -57,14 +57,14 @@ struct sg_nfc_poll_felica { uint64_t PMm; }; -struct sg_nfc_resp_poll { - struct sg_resp_header resp; +struct sg_nfc_res_poll { + struct sg_res_header res; uint8_t count; uint8_t payload[250]; }; struct sg_nfc_req_mifare_select_tag { - struct sg_resp_header resp; + struct sg_res_header res; uint32_t uid; }; @@ -76,8 +76,8 @@ struct sg_nfc_req_mifare_read_block { } payload; }; -struct sg_nfc_resp_mifare_read_block { - struct sg_resp_header resp; +struct sg_nfc_res_mifare_read_block { + struct sg_res_header res; uint8_t block[16]; }; @@ -87,8 +87,8 @@ struct sg_nfc_req_felica_encap { uint8_t payload[243]; }; -struct sg_nfc_resp_felica_encap { - struct sg_resp_header resp; +struct sg_nfc_res_felica_encap { + struct sg_res_header res; uint8_t payload[250]; }; @@ -102,14 +102,14 @@ union sg_nfc_req_any { struct sg_nfc_req_felica_encap felica_encap; }; -union sg_nfc_resp_any { +union sg_nfc_res_any { uint8_t bytes[256]; - struct sg_resp_header simple; - struct sg_nfc_resp_get_fw_version get_fw_version; - struct sg_nfc_resp_get_hw_version get_hw_version; - struct sg_nfc_resp_poll poll; - struct sg_nfc_resp_mifare_read_block mifare_read_block; - struct sg_nfc_resp_felica_encap felica_encap; + struct sg_res_header simple; + struct sg_nfc_res_get_fw_version get_fw_version; + struct sg_nfc_res_get_hw_version get_hw_version; + struct sg_nfc_res_poll poll; + struct sg_nfc_res_mifare_read_block mifare_read_block; + struct sg_nfc_res_felica_encap felica_encap; }; #pragma pack(pop) diff --git a/board/sg-nfc.c b/board/sg-nfc.c index 2409b6d..2db684d 100644 --- a/board/sg-nfc.c +++ b/board/sg-nfc.c @@ -20,27 +20,27 @@ static HRESULT sg_nfc_dispatch( void *ctx, const void *v_req, - void *v_resp); + void *v_res); static HRESULT sg_nfc_cmd_reset( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_resp_header *resp); + struct sg_res_header *res); static HRESULT sg_nfc_cmd_get_fw_version( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_nfc_resp_get_fw_version *resp); + struct sg_nfc_res_get_fw_version *res); static HRESULT sg_nfc_cmd_get_hw_version( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_nfc_resp_get_hw_version *resp); + struct sg_nfc_res_get_hw_version *res); static HRESULT sg_nfc_cmd_poll( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_nfc_resp_poll *resp); + struct sg_nfc_res_poll *res); static HRESULT sg_nfc_poll_aime( struct sg_nfc *nfc, @@ -53,17 +53,17 @@ static HRESULT sg_nfc_poll_felica( static HRESULT sg_nfc_cmd_mifare_read_block( struct sg_nfc *nfc, const struct sg_nfc_req_mifare_read_block *req, - struct sg_nfc_resp_mifare_read_block *resp); + struct sg_nfc_res_mifare_read_block *res); static HRESULT sg_nfc_cmd_felica_encap( struct sg_nfc *nfc, const struct sg_nfc_req_felica_encap *req, - struct sg_nfc_resp_felica_encap *resp); + struct sg_nfc_res_felica_encap *res); static HRESULT sg_nfc_cmd_dummy( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_resp_header *resp); + struct sg_res_header *res); void sg_nfc_init( struct sg_nfc *nfc, @@ -107,29 +107,29 @@ static void sg_nfc_dprintf( void sg_nfc_transact( struct sg_nfc *nfc, - struct iobuf *resp_frame, + struct iobuf *res_frame, const void *req_bytes, size_t req_nbytes) { assert(nfc != NULL); - assert(resp_frame != NULL); + assert(res_frame != NULL); assert(req_bytes != NULL); - sg_req_transact(resp_frame, req_bytes, req_nbytes, sg_nfc_dispatch, nfc); + sg_req_transact(res_frame, req_bytes, req_nbytes, sg_nfc_dispatch, nfc); } static HRESULT sg_nfc_dispatch( void *ctx, const void *v_req, - void *v_resp) + void *v_res) { struct sg_nfc *nfc; const union sg_nfc_req_any *req; - union sg_nfc_resp_any *resp; + union sg_nfc_res_any *res; nfc = ctx; req = v_req; - resp = v_resp; + res = v_res; if (req->simple.hdr.addr != nfc->addr) { /* Not addressed to us, don't send a response */ @@ -138,37 +138,37 @@ static HRESULT sg_nfc_dispatch( switch (req->simple.hdr.cmd) { case SG_NFC_CMD_RESET: - return sg_nfc_cmd_reset(nfc, &req->simple, &resp->simple); + return sg_nfc_cmd_reset(nfc, &req->simple, &res->simple); case SG_NFC_CMD_GET_FW_VERSION: return sg_nfc_cmd_get_fw_version( nfc, &req->simple, - &resp->get_fw_version); + &res->get_fw_version); case SG_NFC_CMD_GET_HW_VERSION: return sg_nfc_cmd_get_hw_version( nfc, &req->simple, - &resp->get_hw_version); + &res->get_hw_version); case SG_NFC_CMD_POLL: return sg_nfc_cmd_poll( nfc, &req->simple, - &resp->poll); + &res->poll); case SG_NFC_CMD_MIFARE_READ_BLOCK: return sg_nfc_cmd_mifare_read_block( nfc, &req->mifare_read_block, - &resp->mifare_read_block); + &res->mifare_read_block); case SG_NFC_CMD_FELICA_ENCAP: return sg_nfc_cmd_felica_encap( nfc, &req->felica_encap, - &resp->felica_encap); + &res->felica_encap); case SG_NFC_CMD_MIFARE_AUTHENTICATE: case SG_NFC_CMD_MIFARE_SELECT_TAG: @@ -176,7 +176,7 @@ static HRESULT sg_nfc_dispatch( case SG_NFC_CMD_MIFARE_SET_KEY_BANA: case SG_NFC_CMD_RADIO_ON: case SG_NFC_CMD_RADIO_OFF: - return sg_nfc_cmd_dummy(nfc, &req->simple, &resp->simple); + return sg_nfc_cmd_dummy(nfc, &req->simple, &res->simple); default: sg_nfc_dprintf(nfc, "Unimpl command %02x\n", req->simple.hdr.cmd); @@ -188,11 +188,11 @@ static HRESULT sg_nfc_dispatch( static HRESULT sg_nfc_cmd_reset( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_resp_header *resp) + struct sg_res_header *res) { sg_nfc_dprintf(nfc, "Reset\n"); - sg_resp_init(resp, req, 0); - resp->status = 3; + sg_res_init(res, req, 0); + res->status = 3; return S_OK; } @@ -200,11 +200,11 @@ static HRESULT sg_nfc_cmd_reset( static HRESULT sg_nfc_cmd_get_fw_version( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_nfc_resp_get_fw_version *resp) + struct sg_nfc_res_get_fw_version *res) { /* Dest version is not NUL terminated, this is intentional */ - sg_resp_init(&resp->resp, req, sizeof(resp->version)); - memcpy(resp->version, "TN32MSEC003S F/W Ver1.2E", sizeof(resp->version)); + sg_res_init(&res->res, req, sizeof(res->version)); + memcpy(res->version, "TN32MSEC003S F/W Ver1.2E", sizeof(res->version)); return S_OK; } @@ -212,11 +212,11 @@ static HRESULT sg_nfc_cmd_get_fw_version( static HRESULT sg_nfc_cmd_get_hw_version( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_nfc_resp_get_hw_version *resp) + struct sg_nfc_res_get_hw_version *res) { /* Dest version is not NUL terminated, this is intentional */ - sg_resp_init(&resp->resp, req, sizeof(resp->version)); - memcpy(resp->version, "TN32MSEC003S H/W Ver3.0J", sizeof(resp->version)); + sg_res_init(&res->res, req, sizeof(res->version)); + memcpy(res->version, "TN32MSEC003S H/W Ver3.0J", sizeof(res->version)); return S_OK; } @@ -224,7 +224,7 @@ static HRESULT sg_nfc_cmd_get_hw_version( static HRESULT sg_nfc_cmd_poll( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_nfc_resp_poll *resp) + struct sg_nfc_res_poll *res) { struct sg_nfc_poll_mifare mifare; struct sg_nfc_poll_felica felica; @@ -239,9 +239,9 @@ static HRESULT sg_nfc_cmd_poll( hr = sg_nfc_poll_felica(nfc, &felica); if (SUCCEEDED(hr) && hr != S_FALSE) { - sg_resp_init(&resp->resp, req, 1 + sizeof(felica)); - memcpy(resp->payload, &felica, sizeof(felica)); - resp->count = 1; + sg_res_init(&res->res, req, 1 + sizeof(felica)); + memcpy(res->payload, &felica, sizeof(felica)); + res->count = 1; return S_OK; } @@ -249,15 +249,15 @@ static HRESULT sg_nfc_cmd_poll( hr = sg_nfc_poll_aime(nfc, &mifare); if (SUCCEEDED(hr) && hr != S_FALSE) { - sg_resp_init(&resp->resp, req, 1 + sizeof(mifare)); - memcpy(resp->payload, &mifare, sizeof(mifare)); - resp->count = 1; + sg_res_init(&res->res, req, 1 + sizeof(mifare)); + memcpy(res->payload, &mifare, sizeof(mifare)); + res->count = 1; return S_OK; } - sg_resp_init(&resp->resp, req, 1); - resp->count = 0; + sg_res_init(&res->res, req, 1); + res->count = 0; return S_OK; } @@ -340,7 +340,7 @@ static HRESULT sg_nfc_poll_felica( static HRESULT sg_nfc_cmd_mifare_read_block( struct sg_nfc *nfc, const struct sg_nfc_req_mifare_read_block *req, - struct sg_nfc_resp_mifare_read_block *resp) + struct sg_nfc_res_mifare_read_block *res) { uint32_t uid; @@ -360,11 +360,11 @@ static HRESULT sg_nfc_cmd_mifare_read_block( return E_FAIL; } - sg_resp_init(&resp->resp, &req->req, sizeof(resp->block)); + sg_res_init(&res->res, &req->req, sizeof(res->block)); - memcpy( resp->block, + memcpy( res->block, nfc->mifare.sectors[0].blocks[req->payload.block_no].bytes, - sizeof(resp->block)); + sizeof(res->block)); return S_OK; } @@ -372,7 +372,7 @@ static HRESULT sg_nfc_cmd_mifare_read_block( static HRESULT sg_nfc_cmd_felica_encap( struct sg_nfc *nfc, const struct sg_nfc_req_felica_encap *req, - struct sg_nfc_resp_felica_encap *resp) + struct sg_nfc_res_felica_encap *res) { struct const_iobuf f_req; struct iobuf f_res; @@ -397,8 +397,8 @@ static HRESULT sg_nfc_cmd_felica_encap( f_req.nbytes = req->payload[0]; f_req.pos = 1; - f_res.bytes = resp->payload; - f_res.nbytes = sizeof(resp->payload); + f_res.bytes = res->payload; + f_res.nbytes = sizeof(res->payload); f_res.pos = 1; #if 0 @@ -412,8 +412,8 @@ static HRESULT sg_nfc_cmd_felica_encap( return hr; } - sg_resp_init(&resp->resp, &req->req, f_res.pos); - resp->payload[0] = f_res.pos; + sg_res_init(&res->res, &req->req, f_res.pos); + res->payload[0] = f_res.pos; #if 0 dprintf("FELICA INBOUND:\n"); @@ -426,9 +426,9 @@ static HRESULT sg_nfc_cmd_felica_encap( static HRESULT sg_nfc_cmd_dummy( struct sg_nfc *nfc, const struct sg_req_header *req, - struct sg_resp_header *resp) + struct sg_res_header *res) { - sg_resp_init(resp, req, 0); + sg_res_init(res, req, 0); return S_OK; } diff --git a/board/sg-nfc.h b/board/sg-nfc.h index b88b222..5562b2b 100644 --- a/board/sg-nfc.h +++ b/board/sg-nfc.h @@ -34,6 +34,6 @@ void sg_nfc_init( void sg_nfc_transact( struct sg_nfc *nfc, - struct iobuf *resp_frame, + struct iobuf *res_frame, const void *req_bytes, size_t req_nbytes);