Change crypto clients to use rpc_caller_session

Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I6c370e8dc14f2262a2502995f655888a80d69c7b
diff --git a/components/service/crypto/client/cpp/crypto_client.cpp b/components/service/crypto/client/cpp/crypto_client.cpp
index 3537c8a..9d5609a 100644
--- a/components/service/crypto/client/cpp/crypto_client.cpp
+++ b/components/service/crypto/client/cpp/crypto_client.cpp
@@ -5,7 +5,6 @@
  */
 
 #include "crypto_client.h"
-#include <service/discovery/client/discovery_client.h>
 #include <protocols/rpc/common/packed-c/status.h>
 
 crypto_client::crypto_client() :
@@ -14,15 +13,10 @@
 	service_client_init(&m_client, NULL);
 }
 
-crypto_client::crypto_client(struct rpc_caller *caller) :
+crypto_client::crypto_client(struct rpc_caller_session *session) :
 	m_client()
 {
-	service_client_init(&m_client, caller);
-
-	if (caller) {
-
-		discovery_client_get_service_info(&m_client);
-	}
+	service_client_init(&m_client, session);
 }
 
 crypto_client::~crypto_client()
@@ -30,14 +24,9 @@
 	service_client_deinit(&m_client);
 }
 
-void crypto_client::set_caller(struct rpc_caller *caller)
+void crypto_client::set_caller(struct rpc_caller_session *session)
 {
-	m_client.caller = caller;
-
-	if (caller) {
-
-		discovery_client_get_service_info(&m_client);
-	}
+	m_client.session = session;
 }
 
 int crypto_client::err_rpc_status() const
diff --git a/components/service/crypto/client/cpp/crypto_client.h b/components/service/crypto/client/cpp/crypto_client.h
index ccb0714..eebe60e 100644
--- a/components/service/crypto/client/cpp/crypto_client.h
+++ b/components/service/crypto/client/cpp/crypto_client.h
@@ -237,8 +237,8 @@
 
 protected:
 	crypto_client();
-	crypto_client(struct rpc_caller *caller);
-	void set_caller(struct rpc_caller *caller);
+	crypto_client(struct rpc_caller_session *session);
+	void set_caller(struct rpc_caller_session *session);
 
 	struct service_client m_client;
 };
diff --git a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
index 4e10f9b..2465f05 100644
--- a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
@@ -15,8 +15,8 @@
 
 }
 
-packedc_crypto_client::packedc_crypto_client(struct rpc_caller *caller) :
-	crypto_client(caller)
+packedc_crypto_client::packedc_crypto_client(struct rpc_caller_session *session) :
+	crypto_client(session)
 {
 
 }
diff --git a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
index d74ba60..c0e8958 100644
--- a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
+++ b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
@@ -7,6 +7,7 @@
 #ifndef PACKEDC_CRYPTO_CLIENT_H
 #define PACKEDC_CRYPTO_CLIENT_H
 
+#include "rpc_caller_session.h"
 #include <service/crypto/client/cpp/crypto_client.h>
 #include <protocols/service/crypto/packed-c/key_attributes.h>
 
@@ -17,7 +18,7 @@
 {
 public:
 	packedc_crypto_client();
-	packedc_crypto_client(struct rpc_caller *caller);
+	packedc_crypto_client(struct rpc_caller_session *session);
 	virtual ~packedc_crypto_client();
 
 	/* Key lifecycle methods */
diff --git a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
index 337485f..c84c753 100644
--- a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
@@ -9,7 +9,6 @@
 #include "protobuf_crypto_client.h"
 #include <protocols/rpc/common/packed-c/status.h>
 #include <service/common/serializer/protobuf/pb_helper.h>
-#include <rpc_caller.h>
 #include <service/crypto/protobuf/opcodes.pb.h>
 #include <service/crypto/protobuf/generate_key.pb.h>
 #include <service/crypto/protobuf/destroy_key.pb.h>
@@ -30,8 +29,8 @@
 
 }
 
-protobuf_crypto_client::protobuf_crypto_client(struct rpc_caller *caller) :
-	crypto_client(caller)
+protobuf_crypto_client::protobuf_crypto_client(struct rpc_caller_session *session) :
+	crypto_client(session)
 {
 
 }
@@ -69,23 +68,25 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len, 0);
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_GenerateKeyIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-				ts_crypto_Opcode_GENERATE_KEY, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle,
+							  ts_crypto_Opcode_GENERATE_KEY,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -103,7 +104,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -123,23 +124,24 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len, 0);
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_DestroyKeyIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-				ts_crypto_Opcode_DESTROY_KEY, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle, ts_crypto_Opcode_DESTROY_KEY,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+			if (m_client.rpc_status == RPC_SUCCESS) psa_status = service_status;
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -164,23 +166,24 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len, 0);
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_ImportKeyIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-				ts_crypto_Opcode_IMPORT_KEY, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle, ts_crypto_Opcode_IMPORT_KEY,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -198,7 +201,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -254,23 +257,25 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len,
+						       PB_PACKET_LENGTH(data_size));
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_ExportKeyIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-				ts_crypto_Opcode_EXPORT_KEY, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle, ts_crypto_Opcode_EXPORT_KEY,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -308,7 +313,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -330,23 +335,26 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len,
+						       PB_PACKET_LENGTH(data_size));
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_ExportPublicKeyIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-				ts_crypto_Opcode_EXPORT_PUBLIC_KEY, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle,
+							  ts_crypto_Opcode_EXPORT_PUBLIC_KEY,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -385,7 +393,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -432,23 +440,25 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len,
+						       PB_PACKET_LENGTH(signature_size));
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_SignHashIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-						opcode, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle, opcode, &resp_buf, &resp_len,
+							  &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -481,7 +491,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -531,23 +541,24 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len, 0);
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_VerifyHashIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-						opcode, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle, opcode, &resp_buf, &resp_len,
+							  &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+			if (m_client.rpc_status == RPC_SUCCESS) psa_status = service_status;
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -586,23 +597,26 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len,
+						       PB_PACKET_LENGTH(output_size));
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus = PSA_ERROR_GENERIC_ERROR;
+			service_status_t service_status = PSA_ERROR_GENERIC_ERROR;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_AsymmetricEncryptIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-						ts_crypto_Opcode_ASYMMETRIC_ENCRYPT, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle,
+							  ts_crypto_Opcode_ASYMMETRIC_ENCRYPT,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -635,7 +649,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -674,23 +688,25 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len, 0);
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_AsymmetricDecryptIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-						ts_crypto_Opcode_ASYMMETRIC_DECRYPT, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle,
+							  ts_crypto_Opcode_ASYMMETRIC_DECRYPT,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -723,7 +739,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
@@ -746,23 +762,25 @@
 		rpc_call_handle call_handle;
 		uint8_t *req_buf;
 
-		call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
+		call_handle = rpc_caller_session_begin(m_client.session, &req_buf, req_len, output_size + 8);
 
 		if (call_handle) {
 
 			uint8_t *resp_buf;
 			size_t resp_len;
-			rpc_opstatus_t opstatus;
+			service_status_t service_status;
 
 			pb_ostream_t ostream = pb_ostream_from_buffer(req_buf, req_len);
 			pb_encode(&ostream, ts_crypto_GenerateRandomIn_fields, &req_msg);
 
-			m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
-					ts_crypto_Opcode_GENERATE_RANDOM, &opstatus, &resp_buf, &resp_len);
+			m_client.rpc_status =
+				rpc_caller_session_invoke(call_handle,
+							  ts_crypto_Opcode_GENERATE_RANDOM,
+							  &resp_buf, &resp_len, &service_status);
 
-			if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
+			if (m_client.rpc_status == RPC_SUCCESS) {
 
-				psa_status = opstatus;
+				psa_status = service_status;
 
 				if (psa_status == PSA_SUCCESS) {
 
@@ -792,7 +810,7 @@
 				}
 			}
 
-			rpc_caller_end(m_client.caller, call_handle);
+			rpc_caller_session_end(call_handle);
 		}
 	}
 
diff --git a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
index abe4439..8ce896f 100644
--- a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
+++ b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
@@ -9,6 +9,7 @@
 
 #include <service/crypto/client/cpp/crypto_client.h>
 #include <service/crypto/protobuf/key_attributes.pb.h>
+#include "rpc_caller_session.h"
 
 /*
  * A concrete crypto_client that uses the protobuf based crypto access protocol
@@ -17,7 +18,7 @@
 {
 public:
 	protobuf_crypto_client();
-	protobuf_crypto_client(struct rpc_caller *caller);
+	protobuf_crypto_client(struct rpc_caller_session *session);
 	virtual ~protobuf_crypto_client();
 
 	/* Key lifecycle methods */