@@ -216,7 +216,7 @@ public TempMemoryReference(IntPtr buffer, uint size, TEFTempMemoryType type) :
216
216
/// This property represents the size of the buffer.
217
217
/// </summary>
218
218
/// <since_tizen> 3 </since_tizen>
219
- public uint Size { get ; }
219
+ public uint Size { get ; internal set ; }
220
220
} ;
221
221
222
222
/// <summary>
@@ -249,7 +249,7 @@ public RegisteredMemoryReference(SharedMemory parent, uint size, uint offset, TE
249
249
/// This property represents the size (in bytes) of the shared memory.
250
250
/// </summary>
251
251
/// <since_tizen> 3 </since_tizen>
252
- public uint Size { get ; }
252
+ public uint Size { get ; internal set ; }
253
253
/// <summary>
254
254
/// This property represents the offset (in bytes) from the start of the shared memory.
255
255
/// </summary>
@@ -281,12 +281,12 @@ public Value(uint a, uint b, TEFValueType type) :
281
281
/// This property represents an unsigned integer A.
282
282
/// </summary>
283
283
/// <since_tizen> 3 </since_tizen>
284
- public uint A { get ; }
284
+ public uint A { get ; internal set ; }
285
285
/// <summary>
286
286
/// This property represents an unsigned integer B.
287
287
/// </summary>
288
288
/// <since_tizen> 3 </since_tizen>
289
- public uint B { get ; }
289
+ public uint B { get ; internal set ; }
290
290
} ;
291
291
292
292
@@ -304,20 +304,90 @@ internal Session(Interop.TEEC_Context context) {
304
304
this . session = new Interop . TEEC_Session ( ) ;
305
305
}
306
306
307
+ /// <summary>
308
+ /// Destructor of the class.
309
+ /// </summary>
307
310
~ Session ( )
308
311
{
309
312
Close ( ) ;
310
313
}
311
314
315
+ internal UInt32 InitParam ( ref Interop . TEEC_Parameter dst , Parameter src )
316
+ {
317
+ switch ( src . NativeType ) {
318
+ case ( int ) TEFValueType . Input :
319
+ case ( int ) TEFValueType . Output :
320
+ case ( int ) TEFValueType . InOut :
321
+ dst . value . a = ( ( Value ) src ) . A ;
322
+ dst . value . b = ( ( Value ) src ) . B ;
323
+ break ;
324
+
325
+ case ( int ) TEFTempMemoryType . Input :
326
+ case ( int ) TEFTempMemoryType . Output :
327
+ case ( int ) TEFTempMemoryType . InOut :
328
+ dst . tmpref . buffer = ( ( TempMemoryReference ) src ) . Buffer ;
329
+ dst . tmpref . size = ( ( TempMemoryReference ) src ) . Size ;
330
+ break ;
331
+
332
+ case ( int ) TEFRegisteredMemoryType . Whole :
333
+ case ( int ) TEFRegisteredMemoryType . PartialInput :
334
+ case ( int ) TEFRegisteredMemoryType . PartialOutput :
335
+ case ( int ) TEFRegisteredMemoryType . PartialInOut :
336
+ dst . memref . parent = ( ( RegisteredMemoryReference ) src ) . Parent . shm ;
337
+ dst . memref . size = ( ( RegisteredMemoryReference ) src ) . Size ;
338
+ dst . memref . offset = ( ( RegisteredMemoryReference ) src ) . Offset ;
339
+ break ;
340
+
341
+ default : return 0 ;
342
+ }
343
+ return src . NativeType ;
344
+ }
345
+
346
+ internal void UpdateParam ( Interop . TEEC_Parameter src , ref Parameter dst )
347
+ {
348
+ switch ( dst . NativeType ) {
349
+ case ( int ) TEFValueType . Input :
350
+ case ( int ) TEFValueType . Output :
351
+ case ( int ) TEFValueType . InOut :
352
+ ( ( Value ) dst ) . A = src . value . a ;
353
+ ( ( Value ) dst ) . B = src . value . b ;
354
+ break ;
355
+
356
+ case ( int ) TEFTempMemoryType . Input :
357
+ case ( int ) TEFTempMemoryType . Output :
358
+ case ( int ) TEFTempMemoryType . InOut :
359
+ ( ( TempMemoryReference ) dst ) . Size = src . tmpref . size ;
360
+ break ;
361
+
362
+ case ( int ) TEFRegisteredMemoryType . Whole :
363
+ case ( int ) TEFRegisteredMemoryType . PartialInput :
364
+ case ( int ) TEFRegisteredMemoryType . PartialOutput :
365
+ case ( int ) TEFRegisteredMemoryType . PartialInOut :
366
+ ( ( RegisteredMemoryReference ) dst ) . Size = src . memref . size ;
367
+ break ;
368
+
369
+ default : break ;
370
+ }
371
+ }
372
+
312
373
internal void Open ( Guid destination , uint loginMethod , byte [ ] connectionData , Parameter [ ] paramlist )
313
374
{
314
375
Interop . TEEC_UUID uuid = Interop . TEEC_UUID . ToTeecUuid ( destination ) ;
315
376
Interop . TEEC_Operation op = new Interop . TEEC_Operation ( ) ;
316
- uint ro ;
317
377
378
+ op . started = 0 ;
379
+ op . paramTypes = 0 ;
380
+ for ( int i = 0 ; i < 4 && i < paramlist . Length ; ++ i ) {
381
+ op . paramTypes |= InitParam ( ref op . paramlist [ i ] , paramlist [ i ] ) << ( 4 * i ) ;
382
+ }
383
+
384
+ uint ro ;
318
385
int ret = Interop . Libteec . OpenSession ( ref context , ref session , ref uuid , loginMethod , connectionData , ref op , out ro ) ;
319
386
//MAYBE map origin of return code to specyfic Exception
320
387
Interop . CheckNThrowException ( ret , string . Format ( "OpenSession('{0}')" , destination ) ) ;
388
+ for ( int i = 0 ; i < 4 && i < paramlist . Length ; ++ i ) {
389
+ UpdateParam ( op . paramlist [ i ] , ref paramlist [ i ] ) ;
390
+ }
321
391
}
322
392
323
393
/// <summary>
@@ -358,16 +428,17 @@ public void InvokeCommand(uint commandID, Parameter[] paramlist)
358
428
Interop . TEEC_Operation op = new Interop . TEEC_Operation ( ) ;
359
429
op . started = 0 ;
360
430
op . paramTypes = 0 ;
361
-
362
- for ( int i = 0 ; i < 4 ; ++ i ) {
363
- Parameter p = paramlist [ i ] ;
364
- //TODO fill TEEC_Operation struct
431
+ for ( int i = 0 ; i < 4 && i < paramlist . Length ; ++ i ) {
432
+ op . paramTypes |= InitParam ( ref op . paramlist [ i ] , paramlist [ i ] ) << ( 4 * i ) ;
365
433
}
366
434
367
435
uint ro ;
368
436
int ret = Interop . Libteec . InvokeCommand ( ref session , commandID , ref op , out ro ) ;
369
437
//MAYBE map origin of return code to specific Exception
370
438
Interop . CheckNThrowException ( ret , string . Format ( "InvokeCommand({0})" , commandID ) ) ;
439
+ for ( int i = 0 ; i < 4 && i < paramlist . Length ; ++ i ) {
440
+ UpdateParam ( op . paramlist [ i ] , ref paramlist [ i ] ) ;
441
+ }
371
442
}
372
443
373
444
/// <summary>
@@ -417,10 +488,21 @@ public Context(string name)
417
488
context = new Interop . TEEC_Context ( ) ;
418
489
if ( name != null && name . Length == 0 )
419
490
name = null ;
420
- int ret = Interop . Libteec . InitializeContext ( name , ref context ) ;
421
- Interop . CheckNThrowException ( ret , string . Format ( "InititalizeContext('{0}')" , name ) ) ;
491
+ try {
492
+ int ret = Interop . Libteec . InitializeContext ( name , ref context ) ;
493
+ Interop . CheckNThrowException ( ret , string . Format ( "InititalizeContext('{0}')" , name ) ) ;
494
+ }
495
+ catch ( global ::System . DllNotFoundException e )
496
+ {
497
+ unchecked {
498
+ Interop . CheckNThrowException ( ( int ) Interop . LibteecError . NotImplemented , "Not found: " + e . Message ) ;
499
+ }
500
+ }
422
501
}
423
502
503
+ /// <summary>
504
+ /// Destructor of the class.
505
+ /// </summary>
424
506
~ Context ( )
425
507
{
426
508
Dispose ( ) ;
@@ -434,8 +516,10 @@ public Context(string name)
434
516
/// <privlevel>partner</privlevel>
435
517
/// <feature>http://tizen.org/feature/security.tee</feature>
436
518
public void Dispose ( ) {
437
- Interop . Libteec . FinalizeContext ( ref context ) ;
438
- //context.imp = null;
519
+ try {
520
+ Interop . Libteec . FinalizeContext ( ref context ) ;
521
+ }
522
+ catch ( global ::System . DllNotFoundException ) { }
439
523
}
440
524
441
525
/// <summary>
0 commit comments