/// </summary>
//TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session, const TEEC_UUID *destination, uint connectionMethod, const void *connectionData, TEEC_Operation *operation, uint *returnOrigin);
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_OpenSession", CallingConvention = CallingConvention.Cdecl)]
- static public extern int OpenSession(ref TEEC_Context context, ref TEEC_Session session, TEEC_UUID destination, uint connectionMethod, byte[] connectionData, ref TEEC_Operation operation, out uint returnOrigin);
+ static public extern int OpenSession(ref TEEC_Context context, ref TEEC_Session session, ref TEEC_UUID destination, uint connectionMethod, byte[] connectionData, ref TEEC_Operation operation, out uint returnOrigin);
/// <summary>
/// This function closes a session which has been opened with a trusted application.
using System;
+using System.IO;
+using System.Text;
using System.Runtime.InteropServices;
internal static partial class Interop
public UInt16 timeHiAndVersion;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] clockSeqAndNode;
+
+ internal static TEEC_UUID ToTeecUuid(Guid guid)
+ {
+ TEEC_UUID uuid = new TEEC_UUID();
+ byte[] bin = guid.ToByteArray();
+ uuid.timeLow = BitConverter.ToUInt32(bin, 0);
+ uuid.timeMid = BitConverter.ToUInt16(bin, 4);
+ uuid.timeHiAndVersion = BitConverter.ToUInt16(bin, 6);
+ uuid.clockSeqAndNode = new byte[8];
+ Array.Copy(bin, 8, uuid.clockSeqAndNode, 0, 8);
+ return uuid;
+ }
}
[StructLayout(LayoutKind.Sequential)]
using System;
using System.Collections.Generic;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
public void SetData(byte[] data, int dstOffs)
{
if ((shm.flags & (uint)SharedMemoryFlags.Output) == 0) throw new InvalidOperationException("No write access");
- //TODO copy data into shared memory starting at given offset
+ Marshal.Copy(data, 0, shm.buffer + dstOffs, data.Length);
}
/// <summary>
/// This function makes a copy and is designed for convenient operations on small buffers.
public void GetData(byte[] data, int srcOffs)
{
if ((shm.flags & (uint)SharedMemoryFlags.Input) == 0) throw new InvalidOperationException("No read access");
- //TODO copy data from shared memory starting at given offset
+ Marshal.Copy(shm.buffer + srcOffs, data, 0, data.Length);
}
};
internal void Open(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist)
{
- Interop.TEEC_UUID uuid = new Interop.TEEC_UUID();
+ Interop.TEEC_UUID uuid = Interop.TEEC_UUID.ToTeecUuid(destination);
Interop.TEEC_Operation op = new Interop.TEEC_Operation();
uint ro;
- int ret = Interop.Libteec.OpenSession(ref context, ref session, uuid, loginMethod, connectionData, ref op, out ro);
+ int ret = Interop.Libteec.OpenSession(ref context, ref session, ref uuid, loginMethod, connectionData, ref op, out ro);
//MAYBE map origin of return code to specyfic Exception
Interop.CheckNThrowException(ret, string.Format("OpenSession('{0}')", destination));
}
public Context(string name)
{
context = new Interop.TEEC_Context();
+ if (name != null && name.Length == 0)
+ name = null;
int ret = Interop.Libteec.InitializeContext(name, ref context);
Interop.CheckNThrowException(ret, string.Format("InititalizeContext('{0}')", name));
}