-
Notifications
You must be signed in to change notification settings - Fork 34
/
fpc_imp_loire_tone.c
728 lines (600 loc) · 18.8 KB
/
fpc_imp_loire_tone.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
/*
* Copyright (C) 2016 Shane Francis / Jens Andersen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "QSEEComAPI.h"
#include "QSEEComFunc.h"
#include "fpc_imp.h"
#include "tz_api_loire_tone.h"
#include "common.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#define LOG_TAG "FPC IMP"
//#define LOG_NDEBUG 0
#if PLATFORM_SDK_VERSION < 28
#include <cutils/log.h>
#else
#include <log/log.h>
#endif
#include <limits.h>
typedef struct {
struct fpc_imp_data_t data;
struct QSEECom_handle *fpc_handle;
struct qsee_handle_t* qsee_handle;
struct qcom_km_ion_info_t ihandle;
uint64_t auth_id;
} fpc_data_t;
static const char *fpc_error_str(int err)
{
int realerror = err + 10;
switch(realerror)
{
case 0:
return "FPC_ERROR_CONFIG";
case 1:
return "FPC_ERROR_HARDWARE";
case 2:
return "FPC_ERROR_NOENTITY";
case 3:
return "FPC_ERROR_CANCELLED";
case 4:
return "FPC_ERROR_IO";
case 5:
return "FPC_ERROR_NOSPACE";
case 6:
return "FPC_ERROR_COMM";
case 7:
return "FPC_ERROR_ALLOC";
case 8:
return "FPC_ERROR_TIMEDOUT";
case 9:
return "FPC_ERROR_INPUT";
default:
return "FPC_ERROR_UNKNOWN";
}
}
err_t send_modified_command_to_tz(fpc_data_t *ldata, struct qcom_km_ion_info_t ihandle)
{
struct QSEECom_handle *handle = ldata->fpc_handle;
fpc_send_mod_cmd_t* send_cmd = (fpc_send_mod_cmd_t*) handle->ion_sbuffer;
void *rec_cmd = handle->ion_sbuffer + TZ_RESPONSE_OFFSET;
struct QSEECom_ion_fd_info ion_fd_info;
memset(&ion_fd_info, 0, sizeof(struct QSEECom_ion_fd_info));
ion_fd_info.data[0].fd = ihandle.ifd_data_fd;
ion_fd_info.data[0].cmd_buf_offset = 4;
send_cmd->v_addr = (intptr_t) ihandle.ion_sbuffer;
uint32_t length = (ihandle.sbuf_len + 4095) & (~4095);
send_cmd->length = length;
int result = ldata->qsee_handle->send_modified_cmd(handle,send_cmd,64,rec_cmd,64,&ion_fd_info);
if(result)
{
ALOGE("Error sending modified command: %d\n", result);
return -1;
}
if((result = *(int32_t*)rec_cmd) != 0)
{
ALOGE("Error in tz command (%d) : %s\n", result, fpc_error_str(result));
return -2;
}
return result;
}
err_t send_normal_command(fpc_data_t *ldata, int command)
{
fpc_send_std_cmd_t* send_cmd =
(fpc_send_std_cmd_t*) ldata->ihandle.ion_sbuffer;
send_cmd->group_id = 0x1;
send_cmd->cmd_id = command;
send_cmd->ret_val = 0x0;
int ret = send_modified_command_to_tz(ldata, ldata->ihandle);
if(!ret) {
ret = send_cmd->ret_val;
}
return ret;
}
err_t send_buffer_command(fpc_data_t *ldata, uint32_t group_id, uint32_t cmd_id, const uint8_t *buffer, uint32_t length)
{
struct qcom_km_ion_info_t ihandle;
if (ldata->qsee_handle->ion_alloc(&ihandle, length + sizeof(fpc_send_buffer_t)) <0) {
ALOGE("ION allocation failed");
return -1;
}
fpc_send_buffer_t *cmd_data = (fpc_send_buffer_t*)ihandle.ion_sbuffer;
memset(ihandle.ion_sbuffer, 0, length + sizeof(fpc_send_buffer_t));
cmd_data->group_id = group_id;
cmd_data->cmd_id = cmd_id;
cmd_data->length = length;
memcpy(&cmd_data->data, buffer, length);
if(send_modified_command_to_tz(ldata, ihandle) < 0) {
ALOGE("Error sending data to tz\n");
return -1;
}
int result = cmd_data->status;
ldata->qsee_handle->ion_free(&ihandle);
return result;
}
err_t send_command_result_buffer(fpc_data_t *ldata, uint32_t group_id, uint32_t cmd_id, uint8_t *buffer, uint32_t length)
{
struct qcom_km_ion_info_t ihandle;
if (ldata->qsee_handle->ion_alloc(&ihandle, length + sizeof(fpc_send_buffer_t)) <0) {
ALOGE("ION allocation failed");
return -1;
}
fpc_send_buffer_t *keydata_cmd = (fpc_send_buffer_t*)ihandle.ion_sbuffer;
memset(ihandle.ion_sbuffer, 0, length + sizeof(fpc_send_buffer_t));
keydata_cmd->group_id = group_id;
keydata_cmd->cmd_id = cmd_id;
keydata_cmd->length = length;
if(send_modified_command_to_tz(ldata, ihandle) < 0) {
ALOGE("Error sending data to tz\n");
return -1;
}
memcpy(buffer, &keydata_cmd->data[0], length);
int result = keydata_cmd->status;
ldata->qsee_handle->ion_free(&ihandle);
return result;
}
err_t send_custom_cmd(fpc_data_t *ldata, void *buffer, uint32_t len)
{
ALOGV(__func__);
struct qcom_km_ion_info_t ihandle;
if (ldata->qsee_handle->ion_alloc(&ihandle, len) <0) {
ALOGE("ION allocation failed");
return -1;
}
memcpy(ihandle.ion_sbuffer, buffer, len);
if(send_modified_command_to_tz(ldata, ihandle) < 0) {
ALOGE("Error sending data to tz\n");
return -1;
}
// Copy back result
memcpy(buffer, ihandle.ion_sbuffer, len);
ldata->qsee_handle->ion_free(&ihandle);
return 0;
};
err_t fpc_set_auth_challenge(fpc_imp_data_t *data, int64_t challenge)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_send_auth_cmd_t auth_cmd = {0};
auth_cmd.group_id = FPC_GROUP_FPCDATA;
auth_cmd.cmd_id = FPC_SET_AUTH_CHALLENGE;
auth_cmd.challenge = challenge;
if(send_custom_cmd(ldata, &auth_cmd, sizeof(auth_cmd)) < 0) {
ALOGE("Error sending data to tz\n");
return -1;
}
ALOGD("Status :%d\n", auth_cmd.status);
return auth_cmd.status;
}
int64_t fpc_load_auth_challenge(fpc_imp_data_t *data)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_load_auth_challenge_t cmd = {0};
cmd.group_id = FPC_GROUP_FPCDATA;
cmd.cmd_id = FPC_GET_AUTH_CHALLENGE;
if(send_custom_cmd(ldata, &cmd, sizeof(cmd)) < 0) {
ALOGE("Error sending data to tz\n");
return -1;
}
if(cmd.status != 0) {
ALOGE("Bad status getting auth challenge: %d\n", cmd.status);
return -2;
}
return cmd.challenge;
}
int64_t fpc_load_db_id(fpc_imp_data_t *data)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
// return cached auth_id value if available
if(ldata->auth_id) {
return ldata->auth_id;
}
fpc_get_db_id_cmd_t cmd = {0};
cmd.group_id = FPC_GROUP_NORMAL;
cmd.cmd_id = FPC_GET_TEMPLATE_ID;
if(send_custom_cmd(ldata, &cmd, sizeof(cmd)) < 0) {
ALOGE("Error sending data to TZ\n");
return -1;
}
// cache the auth_id value received from TZ
ldata->auth_id = cmd.auth_id;
return cmd.auth_id;
}
err_t fpc_get_hw_auth_obj(fpc_imp_data_t *data, void * buffer, uint32_t length)
{
ALOGV(__func__);
fpc_get_auth_result_t cmd = {0};
fpc_data_t *ldata = (fpc_data_t*)data;
cmd.group_id = FPC_GROUP_FPCDATA;
cmd.cmd_id = FPC_GET_AUTH_RESULT;
cmd.length = AUTH_RESULT_LENGTH;
if(send_custom_cmd(ldata, &cmd, sizeof(cmd)) < 0) {
ALOGE("Error sending data to tz\n");
return -1;
}
if(length != AUTH_RESULT_LENGTH)
{
ALOGE("Weird inconsistency between auth length!???\n");
}
if(cmd.result != 0)
{
ALOGE("Get hw_auth_obj failed: %d\n", cmd.result);
return cmd.result;
}
memcpy(buffer, cmd.auth_result, length);
return 0;
}
err_t fpc_verify_auth_challenge(fpc_imp_data_t *data, void* hat, uint32_t size)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
int ret = send_buffer_command(ldata, FPC_GROUP_FPCDATA, FPC_AUTHORIZE_ENROL, hat, size);
ALOGE("verify auth challenge: %d\n", ret);
return ret;
}
err_t fpc_del_print_id(fpc_imp_data_t *data, uint32_t id)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_fingerprint_delete_t cmd = {0};
cmd.group_id = FPC_GROUP_NORMAL;
cmd.cmd_id = FPC_DELETE_FINGERPRINT;
cmd.fingerprint_id = id;
int ret = send_custom_cmd(ldata, &cmd, sizeof(cmd));
if(ret < 0)
{
ALOGE("Error sending command: %d\n", ret);
return -1;
}
// remove the cached auth_id value upon deleting a fingerprint
ldata->auth_id = 0;
return cmd.status;
}
err_t fpc_wait_finger_lost(fpc_imp_data_t *data)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
int result;
result = send_normal_command(ldata, FPC_WAIT_FINGER_LOST);
if(result > 0)
return 0;
return -1;
}
err_t fpc_wait_finger_down(fpc_imp_data_t *data)
{
ALOGV(__func__);
int result=-1;
int i;
fpc_data_t *ldata = (fpc_data_t*)data;
// while(1)
{
result = send_normal_command(ldata, FPC_WAIT_FINGER_DOWN);
ALOGE_IF(result, "Wait finger down result: %d\n", result);
if(result)
return result;
if((result = fpc_poll_irq()) == -1) {
ALOGV("Error waiting for irq: %d\n", result);
return -1;
}
result = send_normal_command(ldata, FPC_GET_FINGER_STATUS);
if(result < 0)
{
ALOGE("Get finger status failed: %d\n", result);
return result;
}
ALOGD("Finger status: %d\n", result);
if(result)
return 0;
}
return -1;
}
// Attempt to capture image
err_t fpc_capture_image(fpc_imp_data_t *data)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
if (fpc_set_power(FPC_PWRON) < 0) {
ALOGE("Error starting device\n");
return -1;
}
int ret = fpc_wait_finger_lost(data);
if(!ret)
{
ALOGV("Finger lost as expected\n");
ret = fpc_wait_finger_down(data);
if(!ret)
{
ALOGE("Finger down, capturing image\n");
ret = send_normal_command(ldata, FPC_CAPTURE_IMAGE);
ALOGE("Image capture result :%d\n", ret);
} else
ret = 1001;
} else {
ret = 1000;
}
if (fpc_set_power(FPC_PWROFF) < 0) {
ALOGE("Error stopping device\n");
return -1;
}
send_normal_command(ldata, FPC_INIT);
return ret;
}
err_t fpc_enroll_step(fpc_imp_data_t *data, uint32_t *remaining_touches)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_enrol_step_t cmd = {0};
cmd.group_id = FPC_GROUP_NORMAL;
cmd.cmd_id = FPC_ENROL_STEP;
int ret = send_custom_cmd(ldata, &cmd, sizeof(cmd));
if(ret <0)
{
ALOGE("Error sending command: %d\n", ret);
return -1;
}
if(cmd.status < 0)
{
ALOGE("Error processing enroll step: %d\n", cmd.status);
return -1;
}
*remaining_touches = cmd.remaining_touches;
return cmd.status;
}
err_t fpc_enroll_start(fpc_imp_data_t * data, int __unused print_index)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
int ret = send_normal_command(ldata, FPC_BEGIN_ENROL);
if(ret < 0) {
ALOGE("Error beginning enrol: %d\n", ret);
return -1;
}
return ret;
}
err_t fpc_enroll_end(fpc_imp_data_t *data, uint32_t *print_id)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_end_enrol_t cmd = {0};
cmd.group_id = FPC_GROUP_NORMAL;
cmd.cmd_id = FPC_END_ENROL;
if(send_custom_cmd(ldata, &cmd, sizeof(cmd)) < 0) {
ALOGE("Error sending enrol command\n");
return -1;
}
if(cmd.status != 0) {
ALOGE("Error processing end enrol: %d\n", cmd.status);
return -2;
}
*print_id = cmd.print_id;
// remove the cached auth_id value upon enrolling a fingerprint
ldata->auth_id = 0;
return 0;
}
err_t fpc_auth_start(fpc_imp_data_t __unused *data)
{
ALOGV(__func__);
return 0;
}
err_t fpc_auth_step(fpc_imp_data_t *data, uint32_t *print_id)
{
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_send_identify_t identify_cmd = {0};
identify_cmd.commandgroup = FPC_GROUP_NORMAL;
identify_cmd.command = FPC_IDENTIFY;
int result = send_custom_cmd(ldata, &identify_cmd, sizeof(identify_cmd));
if(result)
{
ALOGE("Error identifying: %d || %d\n", result, identify_cmd.status);
return -1;
}
ALOGD("Print identified as %d\n", identify_cmd.id);
*print_id = identify_cmd.id;
return identify_cmd.status;
}
err_t fpc_auth_end(fpc_imp_data_t __unused *data)
{
ALOGV(__func__);
return 0;
}
err_t fpc_update_template(fpc_imp_data_t __unused *data)
{
// TODO: Implement for loire/tone
return 0;
}
err_t fpc_get_print_count(fpc_imp_data_t __unused *data)
{
ALOGV(__func__);
return 0;
}
fpc_fingerprint_index_t fpc_get_print_index(fpc_imp_data_t *data, uint32_t __unused count)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_fingerprint_index_t idx_data = {0};
fpc_fingerprint_list_t cmd = {0};
unsigned int i;
cmd.group_id = FPC_GROUP_NORMAL;
cmd.cmd_id = FPC_GET_FINGERPRINTS;
int ret = send_custom_cmd(ldata, &cmd, sizeof(cmd));
if(ret < 0 || cmd.status != 0)
{
ALOGE("Error retrieving fingerprints\n");
}
ALOGE("Found %d fingerprints\n", cmd.length);
for(i=0; i<cmd.length; i++)
{
idx_data.prints[i] = cmd.fingerprints[i];
}
return idx_data;
}
err_t fpc_get_user_db_length(fpc_imp_data_t __unused *data)
{
ALOGV(__func__);
return 0;
}
err_t fpc_load_empty_db(fpc_imp_data_t *data) {
err_t result;
fpc_data_t *ldata = (fpc_data_t*)data;
result = send_normal_command(ldata, FPC_LOAD_EMPTY_DB);
if(result)
{
ALOGE("Error creating new empty database: %d\n", result);
return result;
}
return 0;
}
err_t fpc_load_user_db(fpc_imp_data_t *data, char* path)
{
int result;
struct stat sb;
fpc_data_t *ldata = (fpc_data_t*)data;
ALOGD("Loading user db from %s\n", path);
result = send_buffer_command(ldata, FPC_GROUP_DB, FPC_LOAD_DB, (const uint8_t*)path, (uint32_t)strlen(path)+1);
return result;
}
err_t fpc_set_gid(fpc_imp_data_t *data, uint32_t gid)
{
int result;
fpc_data_t *ldata = (fpc_data_t*)data;
fpc_set_gid_t cmd = {0};
cmd.group_id = FPC_GROUP_NORMAL;
cmd.cmd_id = FPC_SET_GID;
cmd.gid = gid;
ALOGD("Setting GID to %d\n", gid);
result = send_custom_cmd(ldata, &cmd, sizeof(cmd));
if(!result)
result = cmd.status;
return result;
}
err_t fpc_store_user_db(fpc_imp_data_t *data, uint32_t __unused length, char* path)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
char temp_path[PATH_MAX];
snprintf(temp_path, PATH_MAX - 1, "%s.tmp", path);
int ret = send_buffer_command(ldata, FPC_GROUP_DB, FPC_STORE_DB, (const uint8_t*)temp_path, (uint32_t)strlen(temp_path)+1);
if(ret < 0)
{
ALOGE("storing database failed: %d\n", ret);
return ret;
}
if(rename(temp_path, path) != 0)
{
ALOGE("Renaming temporary db from %s to %s failed: %d\n", temp_path, path, errno);
return -2;
}
return ret;
}
err_t fpc_close(fpc_imp_data_t **data)
{
ALOGV(__func__);
fpc_data_t *ldata = (fpc_data_t*)data;
ldata->qsee_handle->shutdown_app(&ldata->fpc_handle);
if (fpc_set_power(FPC_PWROFF) < 0) {
ALOGE("Error stopping device\n");
return -1;
}
qsee_free_handle(&ldata->qsee_handle);
free(ldata);
*data = NULL;
return 1;
}
err_t fpc_init(fpc_imp_data_t **data)
{
int ret=0;
struct QSEECom_handle * mFPC_handle = NULL;
struct QSEECom_handle * mKeymasterHandle = NULL;
struct qsee_handle_t* qsee_handle = NULL;
ALOGE("INIT FPC TZ APP\n");
if(qsee_open_handle(&qsee_handle) != 0) {
ALOGE("Error loading QSEECom library");
goto err;
}
if (fpc_set_power(FPC_PWRON) < 0) {
ALOGE("Error starting device\n");
goto err_qsee;
}
fpc_data_t *fpc_data = (fpc_data_t*)malloc(sizeof(fpc_data_t));
fpc_data->auth_id = 0;
ALOGE("Starting app %s\n", KM_TZAPP_NAME);
if (qsee_handle->load_trustlet(qsee_handle, &mKeymasterHandle, KM_TZAPP_PATH, KM_TZAPP_NAME, 1024) < 0) {
if (qsee_handle->load_trustlet(qsee_handle, &mKeymasterHandle, KM_TZAPP_PATH, KM_TZAPP_ALT_NAME, 1024) < 0) {
ALOGE("Could not load app %s or %s\n", KM_TZAPP_NAME, KM_TZAPP_ALT_NAME);
goto err_alloc;
}
}
fpc_data->qsee_handle = qsee_handle;
ALOGE("Starting app %s\n", FP_TZAPP_NAME);
if (qsee_handle->load_trustlet(qsee_handle, &mFPC_handle, FP_TZAPP_PATH, FP_TZAPP_NAME, 128) < 0) {
ALOGE("Could not load app : %s\n", FP_TZAPP_NAME);
goto err_keymaster;
}
fpc_data->fpc_handle = mFPC_handle;
fpc_data->ihandle.ion_fd = 0;
if (fpc_data->qsee_handle->ion_alloc(&fpc_data->ihandle, 0x40) < 0) {
ALOGE("ION allocation failed");
goto err_keymaster;
}
if ((ret = send_normal_command(fpc_data, FPC_INIT)) != 0) {
ALOGE("Error sending FPC_INIT to tz: %d\n", ret);
return -1;
}
// Start creating one off command to get cert from keymaster
keymaster_cmd_t *req = (keymaster_cmd_t *) mKeymasterHandle->ion_sbuffer;
req->cmd_id = 0x205;
req->ret_val = 0x02;
uint8_t * send_buf = mKeymasterHandle->ion_sbuffer;
uint8_t * rec_buf = mKeymasterHandle->ion_sbuffer + 64;
//Send command to keymaster
if (qsee_handle->send_cmd(mKeymasterHandle, send_buf, 64, rec_buf, 1024-64) < 0) {
goto err_keymaster;
}
keymaster_return_t* ret_data = (keymaster_return_t*) rec_buf;
ALOGE("Keymaster Response Code : %u\n", ret_data->status);
ALOGE("Keymaster Response Length : %u\n", ret_data->length);
ALOGE("Keymaster Response Offset: %u\n", ret_data->offset);
void * data_buff = &rec_buf[ret_data->offset];
void *keydata = malloc(ret_data->length);
int keylength = ret_data->length;
memcpy(keydata, data_buff, keylength);
qsee_handle->shutdown_app(&mKeymasterHandle);
mKeymasterHandle = NULL;
int result = send_buffer_command(fpc_data, FPC_GROUP_FPCDATA, FPC_SET_KEY_DATA, keydata, keylength);
ALOGD("FPC_SET_KEY_DATA Result: %d\n", result);
if(result != 0)
return result;
if (fpc_set_power(FPC_PWROFF) < 0) {
ALOGE("Error stopping device\n");
goto err_alloc;
}
*data = (fpc_imp_data_t*)fpc_data;
return 1;
err_keymaster:
if(mKeymasterHandle != NULL)
qsee_handle->shutdown_app(&mKeymasterHandle);
err_alloc:
if(fpc_data != NULL) {
fpc_data->qsee_handle->ion_free(&fpc_data->ihandle);
free(fpc_data);
}
err_qsee:
qsee_free_handle(&qsee_handle);
err:
return -1;
}