Introduce common service client

In preparation for making common service access information
such as the maximum request length or supported serializations,
a common service client has been introduced that standardizes
common client state, including any available service access
info.  All clients refactored to use the common service client.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I31336901476f5647d2ed00294716940f475da08c
diff --git a/components/service/crypto/client/cpp/crypto_client.cpp b/components/service/crypto/client/cpp/crypto_client.cpp
index 602a6b5..33eb7d1 100644
--- a/components/service/crypto/client/cpp/crypto_client.cpp
+++ b/components/service/crypto/client/cpp/crypto_client.cpp
@@ -8,30 +8,28 @@
 #include <protocols/rpc/common/packed-c/status.h>
 
 crypto_client::crypto_client() :
-    m_caller(NULL),
-    m_err_rpc_status(TS_RPC_CALL_ACCEPTED)
+    m_client()
 {
-
+    service_client_init(&m_client, NULL);
 }
 
 crypto_client::crypto_client(struct rpc_caller *caller) :
-    m_caller(caller),
-    m_err_rpc_status(TS_RPC_CALL_ACCEPTED)
+    m_client()
 {
-
+    service_client_init(&m_client, caller);
 }
 
 crypto_client::~crypto_client()
 {
-
+    service_client_deinit(&m_client);
 }
 
 void crypto_client::set_caller(struct rpc_caller *caller)
 {
-    m_caller = caller;
+    m_client.caller = caller;
 }
 
 int crypto_client::err_rpc_status() const
 {
-    return m_err_rpc_status;
+    return m_client.rpc_status;
 }
diff --git a/components/service/crypto/client/cpp/crypto_client.h b/components/service/crypto/client/cpp/crypto_client.h
index 03cf4b3..d996380 100644
--- a/components/service/crypto/client/cpp/crypto_client.h
+++ b/components/service/crypto/client/cpp/crypto_client.h
@@ -9,8 +9,7 @@
 
 #include <cstdint>
 #include <psa/crypto.h>
-
-struct rpc_caller;
+#include <service/common/client/service_client.h>
 
 /*
  * Provides a client interface for accessing an instance of the Crypto service
@@ -72,8 +71,7 @@
     crypto_client(struct rpc_caller *caller);
     void set_caller(struct rpc_caller *caller);
 
-    struct rpc_caller *m_caller;
-    int m_err_rpc_status;
+    struct service_client m_client;
 };
 
 #endif /* CRYPTO_CLIENT_H */
diff --git a/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp b/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp
index a7618ba..43b2a66 100644
--- a/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp
@@ -42,7 +42,8 @@
 
 }
 
-psa_status_t packedc_crypto_client::generate_key(const psa_key_attributes_t *attributes, psa_key_id_t *id)
+psa_status_t packedc_crypto_client::generate_key(const psa_key_attributes_t *attributes,
+											psa_key_id_t *id)
 {
 	psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
 	struct ts_crypto_generate_key_in req_msg;
@@ -53,7 +54,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -63,10 +64,10 @@
 
 		memcpy(req_buf, &req_msg, req_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 			TS_CRYPTO_OPCODE_GENERATE_KEY, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -85,7 +86,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -102,7 +103,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -112,12 +113,12 @@
 
 		memcpy(req_buf, &req_msg, req_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 			TS_CRYPTO_OPCODE_DESTROY_KEY, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -141,7 +142,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -155,10 +156,10 @@
 		tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
 		tlv_encode(&req_iter, &key_record);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 			TS_CRYPTO_OPCODE_IMPORT_KEY, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -177,7 +178,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -198,7 +199,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -208,10 +209,10 @@
 
 		memcpy(req_buf, &req_msg, req_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 			TS_CRYPTO_OPCODE_EXPORT_KEY, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -241,7 +242,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -261,7 +262,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -271,10 +272,10 @@
 
 		memcpy(req_buf, &req_msg, req_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 			TS_CRYPTO_OPCODE_EXPORT_PUBLIC_KEY, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -304,7 +305,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -332,7 +333,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -346,10 +347,10 @@
 		tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
 		tlv_encode(&req_iter, &hash_record);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					TS_CRYPTO_OPCODE_SIGN_HASH, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -379,7 +380,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -412,7 +413,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -427,12 +428,12 @@
 		tlv_encode(&req_iter, &hash_record);
 		tlv_encode(&req_iter, &sig_record);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					TS_CRYPTO_OPCODE_VERIFY_HASH, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -470,7 +471,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -485,10 +486,10 @@
 		tlv_encode(&req_iter, &plaintext_record);
 		if (salt) tlv_encode(&req_iter, &salt_record);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					TS_CRYPTO_OPCODE_ASYMMETRIC_ENCRYPT, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -518,7 +519,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -556,7 +557,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -571,10 +572,10 @@
 		tlv_encode(&req_iter, &ciphertext_record);
 		if (salt) tlv_encode(&req_iter, &salt_record);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					TS_CRYPTO_OPCODE_ASYMMETRIC_DECRYPT, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -604,7 +605,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -621,7 +622,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -631,10 +632,10 @@
 
 		memcpy(req_buf, &req_msg, req_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 				TS_CRYPTO_OPCODE_GENERATE_RANDOM, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -663,7 +664,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -681,7 +682,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -691,10 +692,10 @@
 
 		memcpy(req_buf, &req_msg, req_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 			TS_CRYPTO_OPCODE_HASH_SETUP, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -713,7 +714,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -739,7 +740,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -753,12 +754,12 @@
 		tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
 		tlv_encode(&req_iter, &data_record);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					TS_CRYPTO_OPCODE_HASH_UPDATE, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
@@ -778,7 +779,7 @@
 	rpc_call_handle call_handle;
 	uint8_t *req_buf;
 
-	call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+	call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 	if (call_handle) {
 
@@ -788,10 +789,10 @@
 
 		memcpy(req_buf, &req_msg, req_fixed_len);
 
-		m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+		m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					TS_CRYPTO_OPCODE_HASH_FINISH, &opstatus, &resp_buf, &resp_len);
 
-		if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+		if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 			psa_status = opstatus;
 
@@ -821,7 +822,7 @@
 			}
 		}
 
-		rpc_caller_end(m_caller, call_handle);
+		rpc_caller_end(m_client.caller, call_handle);
 	}
 
 	return psa_status;
diff --git a/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp b/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp
index 32acd4c..1823a4a 100644
--- a/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp
@@ -56,7 +56,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -67,10 +67,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_GenerateKeyIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 				ts_crypto_Opcode_GENERATE_KEY, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -90,7 +90,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -110,7 +110,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -121,12 +121,12 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_DestroyKeyIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 				ts_crypto_Opcode_DESTROY_KEY, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -151,7 +151,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -162,10 +162,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_ImportKeyIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 				ts_crypto_Opcode_IMPORT_KEY, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -185,7 +185,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -210,7 +210,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -221,10 +221,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_ExportKeyIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 				ts_crypto_Opcode_EXPORT_KEY, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -264,7 +264,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -286,7 +286,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -297,10 +297,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_ExportPublicKeyIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 				ts_crypto_Opcode_EXPORT_PUBLIC_KEY, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -341,7 +341,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -369,7 +369,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -380,10 +380,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_SignHashIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 						ts_crypto_Opcode_SIGN_HASH, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -418,7 +418,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -450,7 +450,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -461,12 +461,12 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_VerifyHashIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 						ts_crypto_Opcode_VERIFY_HASH, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -501,7 +501,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -512,10 +512,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_AsymmetricEncryptIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 						ts_crypto_Opcode_ASYMMETRIC_ENCRYPT, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -550,7 +550,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -585,7 +585,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -596,10 +596,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_AsymmetricDecryptIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 						ts_crypto_Opcode_ASYMMETRIC_DECRYPT, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -622,19 +622,19 @@
 						}
 						else {
 							/* Provided buffer is too small */
-							m_err_rpc_status = PSA_ERROR_BUFFER_TOO_SMALL;
+							m_client.rpc_status = PSA_ERROR_BUFFER_TOO_SMALL;
 						}
 					}
 					else {
 						/* Failed to decode response message */
-						m_err_rpc_status = PSA_ERROR_GENERIC_ERROR;
+						m_client.rpc_status = PSA_ERROR_GENERIC_ERROR;
 					}
 
 					::free(plaintext_byte_array);
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}
 
@@ -657,7 +657,7 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_caller, &req_buf, req_len);
+		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
 
 		if (call_handle) {
 
@@ -668,10 +668,10 @@
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_GenerateRandomIn_fields, &req_msg);
 
-			m_err_rpc_status = rpc_caller_invoke(m_caller, call_handle,
+			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
 					ts_crypto_Opcode_GENERATE_RANDOM, &opstatus, &resp_buf, &resp_len);
 
-			if (m_err_rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
 
 				psa_status = opstatus;
 
@@ -703,7 +703,7 @@
 				}
 			}
 
-			rpc_caller_end(m_caller, call_handle);
+			rpc_caller_end(m_client.caller, call_handle);
 		}
 	}