aboutsummaryrefslogtreecommitdiff
path: root/rpc_client_daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'rpc_client_daemon.c')
-rw-r--r--rpc_client_daemon.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/rpc_client_daemon.c b/rpc_client_daemon.c
index dea352f..7ff3f21 100644
--- a/rpc_client_daemon.c
+++ b/rpc_client_daemon.c
@@ -45,17 +45,18 @@ static int sock = -1;
hal_error_t hal_rpc_client_transport_init(void)
{
+ const char *sockname = getenv("CRYPTECH_RPC_CLIENT_SOCKET_NAME");
struct sockaddr_un name;
- int ret;
- sock = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock == -1)
return perror("socket"), HAL_ERROR_RPC_TRANSPORT;
+ if (sockname == NULL)
+ sockname = HAL_CLIENT_DAEMON_DEFAULT_SOCKET_NAME;
memset(&name, 0, sizeof(struct sockaddr_un));
name.sun_family = AF_UNIX;
- strncpy(name.sun_path, HAL_CLIENT_DAEMON_DEFAULT_SOCKET_NAME, sizeof(name.sun_path) - 1);
- ret = connect(sock, (const struct sockaddr *) &name, sizeof(struct sockaddr_un));
- if (ret == -1)
+ strncpy(name.sun_path, sockname, sizeof(name.sun_path) - 1);
+ if (connect(sock, (const struct sockaddr *) &name, sizeof(struct sockaddr_un)) < 0)
return perror("connect"), HAL_ERROR_RPC_TRANSPORT;
return HAL_OK;
}
@@ -69,17 +70,35 @@ hal_error_t hal_rpc_client_transport_close(void)
return HAL_OK;
}
+
hal_error_t hal_rpc_send(const uint8_t * const buf, const size_t len)
{
- ssize_t ret = send(sock, (const void *)buf, len, 0);
- return (ret == -1) ? HAL_ERROR_RPC_TRANSPORT : HAL_OK;
+ return hal_slip_send(buf, len);
}
hal_error_t hal_rpc_recv(uint8_t * const buf, size_t * const len)
{
- ssize_t ret = recv(sock, (void *)buf, *len, 0);
- if (ret == -1)
- return HAL_ERROR_RPC_TRANSPORT;
- *len = (size_t)ret;
+ size_t maxlen = *len;
+ *len = 0;
+ hal_error_t err = hal_slip_recv(buf, len, maxlen);
+ return err;
+}
+
+/*
+ * These two are sort of mis-named, fix eventually, but this is what
+ * the code in slip.c expects.
+ */
+
+hal_error_t hal_serial_send_char(const uint8_t c)
+{
+ if (write(sock, &c, 1) != 1)
+ return perror("write"), HAL_ERROR_RPC_TRANSPORT;
+ return HAL_OK;
+}
+
+hal_error_t hal_serial_recv_char(uint8_t * const c)
+{
+ if (read(sock, c, 1) != 1)
+ return perror("read"), HAL_ERROR_RPC_TRANSPORT;
return HAL_OK;
}