aboutsummaryrefslogtreecommitdiff
path: root/daemon.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2016-06-30 21:52:59 -0400
committerPaul Selkirk <paul@psgd.org>2016-06-30 21:52:59 -0400
commit3ba7ca4155c7be439108b174a3b49a508923d378 (patch)
treec066815bbb29ad52fd309c6b5103cbd1bb9716c3 /daemon.c
parent709a71c0030225ba08cddf5227a1c67c2dbb4176 (diff)
RPC wire format now includes client handle in all requests, and opcode and
client handle in all responses. This simplies the daemon a little, and means that the directly-connected serial client uses the same wire format as the daemon. The expense is some redundant code in rpc_client and rpc_server to process (and throw away) this extra stuff.
Diffstat (limited to 'daemon.c')
-rw-r--r--daemon.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/daemon.c b/daemon.c
index 00a55f6..7991710 100644
--- a/daemon.c
+++ b/daemon.c
@@ -262,13 +262,13 @@ int main(int argc, char *argv[])
hexdump(ibuf.buf, ibuf.len);
#endif
/* We've got a complete rpc response packet. */
- const uint8_t *bufptr = ibuf.buf;
+ const uint8_t *bufptr = ibuf.buf + 4;
const uint8_t * const limit = ibuf.buf + ibuf.len;
uint32_t sock;
- /* First word of the response is the client ID. */
+ /* Second word of the response is the client ID. */
hal_xdr_decode_int(&bufptr, limit, &sock);
/* Pass response on to the client that requested it. */
- send(sock, bufptr, ibuf.len - 4, 0);
+ send(sock, ibuf.buf, ibuf.len, 0);
/* Reinitialize the receive buffer. */
memset(&ibuf, 0, sizeof(ibuf));
}
@@ -290,43 +290,25 @@ int main(int argc, char *argv[])
/* client data socket */
else {
- uint8_t *bufptr = obuf.buf;
const uint8_t * const limit = obuf.buf + MAX_PKT_SIZE;
- /* First word of the request is the client ID. */
- hal_xdr_encode_int(&bufptr, limit, pollfds[i].fd);
/* Get the client's rpc request packet. */
- obuf.len = recv(pollfds[i].fd, bufptr, MAX_PKT_SIZE - 4, 0);
+ obuf.len = recv(pollfds[i].fd, obuf.buf, MAX_PKT_SIZE, 0);
#ifdef DEBUG
printf("data socket %d received request:\n", pollfds[i].fd);
- hexdump(obuf.buf, obuf.len + 4);
+ hexdump(obuf.buf, obuf.len);
#endif
- /* Fill in the client handle arg as needed. */
- uint32_t opcode;
- hal_xdr_decode_int((const uint8_t ** const)&bufptr, limit, &opcode);
- switch (opcode) {
- case RPC_FUNC_SET_PIN:
- case RPC_FUNC_LOGIN:
- case RPC_FUNC_LOGOUT:
- case RPC_FUNC_IS_LOGGED_IN:
- case RPC_FUNC_HASH_INITIALIZE:
- case RPC_FUNC_PKEY_LOAD:
- case RPC_FUNC_PKEY_FIND:
- case RPC_FUNC_PKEY_GENERATE_RSA:
- case RPC_FUNC_PKEY_GENERATE_EC:
- /* first argument is client handle */
- hal_xdr_encode_int(&bufptr, limit, pollfds[i].fd);
- break;
- default:
- break;
- }
+ /* Fill in the client handle arg - first field after opcode. */
+ uint8_t *bufptr = obuf.buf + 4;
+ hal_xdr_encode_int(&bufptr, limit, pollfds[i].fd);
if (obuf.len > 0) {
#ifdef DEBUG
- printf("passing to serial port\n");
+ printf("passing to serial port:\n");
+ hexdump(obuf.buf, obuf.len);
#endif
/* Pass it on to the serial port. */
- hal_slip_send(obuf.buf, obuf.len + 4);
+ hal_slip_send(obuf.buf, obuf.len);
}
else {
#ifdef DEBUG