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
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
|
/* Copyright (c) 2014-2015,2017 The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#define pr_fmt(fmt) "COMPAT-QSEECOM: %s: " fmt, __func__
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/qseecom.h>
#include <linux/compat.h>
#include "compat_qseecom.h"
static int compat_get_qseecom_register_listener_req(
struct compat_qseecom_register_listener_req __user *data32,
struct qseecom_register_listener_req __user *data)
{
int err;
compat_ulong_t listener_id;
compat_long_t ifd_data_fd;
compat_uptr_t virt_sb_base;
compat_ulong_t sb_size;
err = get_user(listener_id, &data32->listener_id);
err |= put_user(listener_id, &data->listener_id);
err |= get_user(ifd_data_fd, &data32->ifd_data_fd);
err |= put_user(ifd_data_fd, &data->ifd_data_fd);
err |= get_user(virt_sb_base, &data32->virt_sb_base);
/* upper bits won't get set, zero them */
err |= put_user(NULL, &data->virt_sb_base);
err |= put_user(virt_sb_base, (compat_uptr_t *)&data->virt_sb_base);
err |= get_user(sb_size, &data32->sb_size);
err |= put_user(sb_size, &data->sb_size);
return err;
}
static int compat_get_qseecom_load_img_req(
struct compat_qseecom_load_img_req __user *data32,
struct qseecom_load_img_req __user *data)
{
int err;
compat_ulong_t mdt_len;
compat_ulong_t img_len;
compat_long_t ifd_data_fd;
compat_ulong_t app_arch;
compat_uint_t app_id;
err = get_user(mdt_len, &data32->mdt_len);
err |= put_user(mdt_len, &data->mdt_len);
err |= get_user(img_len, &data32->img_len);
err |= put_user(img_len, &data->img_len);
err |= get_user(ifd_data_fd, &data32->ifd_data_fd);
err |= put_user(ifd_data_fd, &data->ifd_data_fd);
err |= copy_in_user(data->img_name, data32->img_name,
MAX_APP_NAME_SIZE);
err |= get_user(app_arch, &data32->app_arch);
err |= put_user(app_arch, &data->app_arch);
err |= get_user(app_id, &data32->app_id);
err |= put_user(app_id, &data->app_id);
return err;
}
static int compat_get_qseecom_send_cmd_req(
struct compat_qseecom_send_cmd_req __user *data32,
struct qseecom_send_cmd_req __user *data)
{
int err;
compat_uptr_t cmd_req_buf;
compat_uint_t cmd_req_len;
compat_uptr_t resp_buf;
compat_uint_t resp_len;
err = get_user(cmd_req_buf, &data32->cmd_req_buf);
err |= put_user(NULL, &data->cmd_req_buf);
err |= put_user(cmd_req_buf, (compat_uptr_t *)&data->cmd_req_buf);
err |= get_user(cmd_req_len, &data32->cmd_req_len);
err |= put_user(cmd_req_len, &data->cmd_req_len);
err |= get_user(resp_buf, &data32->resp_buf);
err |= put_user(NULL, &data->resp_buf);
err |= put_user(resp_buf, (compat_uptr_t *)&data->resp_buf);
err |= get_user(resp_len, &data32->resp_len);
err |= put_user(resp_len, &data->resp_len);
return err;
}
static int compat_get_qseecom_send_modfd_cmd_req(
struct compat_qseecom_send_modfd_cmd_req __user *data32,
struct qseecom_send_modfd_cmd_req __user *data)
{
int err;
unsigned int i;
compat_uptr_t cmd_req_buf;
compat_uint_t cmd_req_len;
compat_uptr_t resp_buf;
compat_uint_t resp_len;
compat_long_t fd;
compat_ulong_t cmd_buf_offset;
err = get_user(cmd_req_buf, &data32->cmd_req_buf);
err |= put_user(NULL, &data->cmd_req_buf);
err |= put_user(cmd_req_buf, (compat_uptr_t *)&data->cmd_req_buf);
err |= get_user(cmd_req_len, &data32->cmd_req_len);
err |= put_user(cmd_req_len, &data->cmd_req_len);
err |= get_user(resp_buf, &data32->resp_buf);
err |= put_user(NULL, &data->resp_buf);
err |= put_user(resp_buf, (compat_uptr_t *)&data->resp_buf);
err |= get_user(resp_len, &data32->resp_len);
err |= put_user(resp_len, &data->resp_len);
for (i = 0; i < MAX_ION_FD; i++) {
err |= get_user(fd, &data32->ifd_data[i].fd);
err |= put_user(fd, &data->ifd_data[i].fd);
err |= get_user(cmd_buf_offset,
&data32->ifd_data[i].cmd_buf_offset);
err |= put_user(cmd_buf_offset,
&data->ifd_data[i].cmd_buf_offset);
}
return err;
}
static int compat_get_qseecom_set_sb_mem_param_req(
struct compat_qseecom_set_sb_mem_param_req __user *data32,
struct qseecom_set_sb_mem_param_req __user *data)
{
int err;
compat_long_t ifd_data_fd;
compat_uptr_t virt_sb_base;
compat_ulong_t sb_len;
err = get_user(ifd_data_fd, &data32->ifd_data_fd);
err |= put_user(ifd_data_fd, &data->ifd_data_fd);
err |= get_user(virt_sb_base, &data32->virt_sb_base);
err |= put_user(NULL, &data->virt_sb_base);
err |= put_user(virt_sb_base, (compat_uptr_t *)&data->virt_sb_base);
err |= get_user(sb_len, &data32->sb_len);
err |= put_user(sb_len, &data->sb_len);
return err;
}
static int compat_get_qseecom_qseos_version_req(
struct compat_qseecom_qseos_version_req __user *data32,
struct qseecom_qseos_version_req __user *data)
{
int err;
compat_uint_t qseos_version;
err = get_user(qseos_version, &data32->qseos_version);
err |= put_user(qseos_version, &data->qseos_version);
return err;
}
static int compat_get_qseecom_qseos_app_load_query(
struct compat_qseecom_qseos_app_load_query __user *data32,
struct qseecom_qseos_app_load_query __user *data)
{
int err = 0;
unsigned int i;
compat_uint_t app_id;
char app_name;
compat_ulong_t app_arch;
for (i = 0; i < MAX_APP_NAME_SIZE; i++) {
err |= get_user(app_name, &(data32->app_name[i]));
err |= put_user(app_name, &(data->app_name[i]));
}
err |= get_user(app_id, &data32->app_id);
err |= put_user(app_id, &data->app_id);
err |= get_user(app_arch, &data32->app_arch);
err |= put_user(app_arch, &data->app_arch);
return err;
}
static int compat_get_qseecom_send_svc_cmd_req(
struct compat_qseecom_send_svc_cmd_req __user *data32,
struct qseecom_send_svc_cmd_req __user *data)
{
int err;
compat_ulong_t cmd_id;
compat_uptr_t cmd_req_buf;
compat_uint_t cmd_req_len;
compat_uptr_t resp_buf;
compat_uint_t resp_len;
err = get_user(cmd_id, &data32->cmd_id);
err |= put_user(cmd_id, &data->cmd_id);
err |= get_user(cmd_req_buf, &data32->cmd_req_buf);
err |= put_user(NULL, &data->cmd_req_buf);
err |= put_user(cmd_req_buf, (compat_uptr_t *)&data->cmd_req_buf);
err |= get_user(cmd_req_len, &data32->cmd_req_len);
err |= put_user(cmd_req_len, &data->cmd_req_len);
err |= get_user(resp_buf, &data32->resp_buf);
err |= put_user(NULL, &data->resp_buf);
err |= put_user(resp_buf, (compat_uptr_t *)&data->resp_buf);
err |= get_user(resp_len, &data32->resp_len);
err |= put_user(resp_len, &data->resp_len);
return err;
}
static int compat_get_qseecom_create_key_req(
struct compat_qseecom_create_key_req __user *data32,
struct qseecom_create_key_req __user *data)
{
int err;
compat_uint_t usage;
err = copy_in_user(data->hash32, data32->hash32, QSEECOM_HASH_SIZE);
err |= get_user(usage, &data32->usage);
err |= put_user(usage, &data->usage);
return err;
}
static int compat_get_qseecom_wipe_key_req(
struct compat_qseecom_wipe_key_req __user *data32,
struct qseecom_wipe_key_req __user *data)
{
int err;
compat_uint_t usage;
compat_int_t wipe_key_flag;
err = get_user(usage, &data32->usage);
err |= put_user(usage, &data->usage);
err |= get_user(wipe_key_flag, &data32->wipe_key_flag);
err |= put_user(wipe_key_flag, &data->wipe_key_flag);
return err;
}
static int compat_get_qseecom_update_key_userinfo_req(
struct compat_qseecom_update_key_userinfo_req __user *data32,
struct qseecom_update_key_userinfo_req __user *data)
{
int err = 0;
compat_uint_t usage;
err = copy_in_user(data->current_hash32, data32->current_hash32,
QSEECOM_HASH_SIZE);
err |= copy_in_user(data->new_hash32, data32->new_hash32,
QSEECOM_HASH_SIZE);
err |= get_user(usage, &data32->usage);
err |= put_user(usage, &data->usage);
return err;
}
static int compat_get_qseecom_save_partition_hash_req(
struct compat_qseecom_save_partition_hash_req __user *data32,
struct qseecom_save_partition_hash_req __user *data)
{
int err;
compat_int_t partition_id;
err = get_user(partition_id, &data32->partition_id);
err |= put_user(partition_id, &data->partition_id);
err |= copy_in_user(data->digest, data32->digest,
SHA256_DIGEST_LENGTH);
return err;
}
static int compat_get_qseecom_is_es_activated_req(
struct compat_qseecom_is_es_activated_req __user *data32,
struct qseecom_is_es_activated_req __user *data)
{
compat_int_t is_activated;
int err;
err = get_user(is_activated, &data32->is_activated);
err |= put_user(is_activated, &data->is_activated);
return err;
}
static int compat_get_qseecom_mdtp_cipher_dip_req(
struct compat_qseecom_mdtp_cipher_dip_req __user *data32,
struct qseecom_mdtp_cipher_dip_req __user *data)
{
int err;
compat_int_t in_buf_size;
compat_uptr_t in_buf;
compat_int_t out_buf_size;
compat_uptr_t out_buf;
compat_int_t direction;
err = get_user(in_buf_size, &data32->in_buf_size);
err |= put_user(in_buf_size, &data->in_buf_size);
err |= get_user(out_buf_size, &data32->out_buf_size);
err |= put_user(out_buf_size, &data->out_buf_size);
err |= get_user(direction, &data32->direction);
err |= put_user(direction, &data->direction);
err |= get_user(in_buf, &data32->in_buf);
err |= put_user(NULL, &data->in_buf);
err |= put_user(in_buf, (compat_uptr_t *)&data->in_buf);
err |= get_user(out_buf, &data32->out_buf);
err |= put_user(NULL, &data->out_buf);
err |= put_user(out_buf, (compat_uptr_t *)&data->out_buf);
return err;
}
static int compat_get_qseecom_send_modfd_listener_resp(
struct compat_qseecom_send_modfd_listener_resp __user *data32,
struct qseecom_send_modfd_listener_resp __user *data)
{
int err;
unsigned int i;
compat_uptr_t resp_buf_ptr;
compat_uint_t resp_len;
compat_long_t fd;
compat_ulong_t cmd_buf_offset;
err = get_user(resp_buf_ptr, &data32->resp_buf_ptr);
err |= put_user(NULL, &data->resp_buf_ptr);
err |= put_user(resp_buf_ptr, (compat_uptr_t *)&data->resp_buf_ptr);
err |= get_user(resp_len, &data32->resp_len);
err |= put_user(resp_len, &data->resp_len);
for (i = 0; i < MAX_ION_FD; i++) {
err |= get_user(fd, &data32->ifd_data[i].fd);
err |= put_user(fd, &data->ifd_data[i].fd);
err |= get_user(cmd_buf_offset,
&data32->ifd_data[i].cmd_buf_offset);
err |= put_user(cmd_buf_offset,
&data->ifd_data[i].cmd_buf_offset);
}
return err;
}
static int compat_get_qseecom_qteec_req(
struct compat_qseecom_qteec_req __user *data32,
struct qseecom_qteec_req __user *data)
{
compat_uptr_t req_ptr;
compat_ulong_t req_len;
compat_uptr_t resp_ptr;
compat_ulong_t resp_len;
int err;
err = get_user(req_ptr, &data32->req_ptr);
err |= put_user(NULL, &data->req_ptr);
err |= put_user(req_ptr, (compat_uptr_t *)&data->req_ptr);
err |= get_user(req_len, &data32->req_len);
err |= put_user(req_len, &data->req_len);
err |= get_user(resp_ptr, &data32->resp_ptr);
err |= put_user(NULL, &data->resp_ptr);
err |= put_user(resp_ptr, (compat_uptr_t *)&data->resp_ptr);
err |= get_user(resp_len, &data32->resp_len);
err |= put_user(resp_len, &data->resp_len);
return err;
}
static int compat_get_qseecom_qteec_modfd_req(
struct compat_qseecom_qteec_modfd_req __user *data32,
struct qseecom_qteec_modfd_req __user *data)
{
compat_uptr_t req_ptr;
compat_ulong_t req_len;
compat_uptr_t resp_ptr;
compat_ulong_t resp_len;
compat_long_t fd;
compat_ulong_t cmd_buf_offset;
int err, i;
err = get_user(req_ptr, &data32->req_ptr);
err |= put_user(NULL, &data->req_ptr);
err |= put_user(req_ptr, (compat_uptr_t *)&data->req_ptr);
err |= get_user(req_len, &data32->req_len);
err |= put_user(req_len, &data->req_len);
err |= get_user(resp_ptr, &data32->resp_ptr);
err |= put_user(NULL, &data->resp_ptr);
err |= put_user(resp_ptr, (compat_uptr_t *)&data->resp_ptr);
err |= get_user(resp_len, &data32->resp_len);
err |= put_user(resp_len, &data->resp_len);
for (i = 0; i < MAX_ION_FD; i++) {
err |= get_user(fd, &data32->ifd_data[i].fd);
err |= put_user(fd, &data->ifd_data[i].fd);
err |= get_user(cmd_buf_offset,
&data32->ifd_data[i].cmd_buf_offset);
err |= put_user(cmd_buf_offset,
&data->ifd_data[i].cmd_buf_offset);
}
return err;
}
static int compat_get_int(compat_int_t __user *data32,
int __user *data)
{
compat_int_t x;
int err;
err = get_user(x, data32);
err |= put_user(x, data);
return err;
}
static int compat_put_qseecom_load_img_req(
struct compat_qseecom_load_img_req __user *data32,
struct qseecom_load_img_req __user *data)
{
int err;
compat_ulong_t mdt_len;
compat_ulong_t img_len;
compat_long_t ifd_data_fd;
compat_ulong_t app_arch;
compat_int_t app_id;
err = get_user(mdt_len, &data->mdt_len);
err |= put_user(mdt_len, &data32->mdt_len);
err |= get_user(img_len, &data->img_len);
err |= put_user(img_len, &data32->img_len);
err |= get_user(ifd_data_fd, &data->ifd_data_fd);
err |= put_user(ifd_data_fd, &data32->ifd_data_fd);
err |= copy_in_user(data32->img_name, data->img_name,
MAX_APP_NAME_SIZE);
err |= get_user(app_arch, &data->app_arch);
err |= put_user(app_arch, &data32->app_arch);
err |= get_user(app_id, &data->app_id);
err |= put_user(app_id, &data32->app_id);
return err;
}
static int compat_put_qseecom_qseos_version_req(
struct compat_qseecom_qseos_version_req __user *data32,
struct qseecom_qseos_version_req __user *data)
{
compat_uint_t qseos_version;
int err;
err = get_user(qseos_version, &data->qseos_version);
err |= put_user(qseos_version, &data32->qseos_version);
return err;
}
static int compat_put_qseecom_qseos_app_load_query(
struct compat_qseecom_qseos_app_load_query __user *data32,
struct qseecom_qseos_app_load_query __user *data)
{
int err = 0;
unsigned int i;
compat_int_t app_id;
compat_ulong_t app_arch;
char app_name;
for (i = 0; i < MAX_APP_NAME_SIZE; i++) {
err |= get_user(app_name, &(data->app_name[i]));
err |= put_user(app_name, &(data32->app_name[i]));
}
err |= get_user(app_id, &data->app_id);
err |= put_user(app_id, &data32->app_id);
err |= get_user(app_arch, &data->app_arch);
err |= put_user(app_arch, &data32->app_arch);
return err;
}
static int compat_put_qseecom_is_es_activated_req(
struct compat_qseecom_is_es_activated_req __user *data32,
struct qseecom_is_es_activated_req __user *data)
{
compat_int_t is_activated;
int err;
err = get_user(is_activated, &data->is_activated);
err |= put_user(is_activated, &data32->is_activated);
return err;
}
static unsigned int convert_cmd(unsigned int cmd)
{
switch (cmd) {
case COMPAT_QSEECOM_IOCTL_REGISTER_LISTENER_REQ:
return QSEECOM_IOCTL_REGISTER_LISTENER_REQ;
case COMPAT_QSEECOM_IOCTL_UNREGISTER_LISTENER_REQ:
return QSEECOM_IOCTL_UNREGISTER_LISTENER_REQ;
case COMPAT_QSEECOM_IOCTL_LOAD_APP_REQ:
return QSEECOM_IOCTL_LOAD_APP_REQ;
case COMPAT_QSEECOM_IOCTL_RECEIVE_REQ:
return QSEECOM_IOCTL_RECEIVE_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_RESP_REQ:
return QSEECOM_IOCTL_SEND_RESP_REQ;
case COMPAT_QSEECOM_IOCTL_UNLOAD_APP_REQ:
return QSEECOM_IOCTL_UNLOAD_APP_REQ;
case COMPAT_QSEECOM_IOCTL_PERF_ENABLE_REQ:
return QSEECOM_IOCTL_PERF_ENABLE_REQ;
case COMPAT_QSEECOM_IOCTL_PERF_DISABLE_REQ:
return QSEECOM_IOCTL_PERF_DISABLE_REQ;
case COMPAT_QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ:
return QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ;
case COMPAT_QSEECOM_IOCTL_SET_BUS_SCALING_REQ:
return QSEECOM_IOCTL_SET_BUS_SCALING_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_CMD_REQ:
return QSEECOM_IOCTL_SEND_CMD_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_CMD_REQ:
return QSEECOM_IOCTL_SEND_MODFD_CMD_REQ;
case COMPAT_QSEECOM_IOCTL_SET_MEM_PARAM_REQ:
return QSEECOM_IOCTL_SET_MEM_PARAM_REQ;
case COMPAT_QSEECOM_IOCTL_GET_QSEOS_VERSION_REQ:
return QSEECOM_IOCTL_GET_QSEOS_VERSION_REQ;
case COMPAT_QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ:
return QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ;
case COMPAT_QSEECOM_IOCTL_APP_LOADED_QUERY_REQ:
return QSEECOM_IOCTL_APP_LOADED_QUERY_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_CMD_SERVICE_REQ:
return QSEECOM_IOCTL_SEND_CMD_SERVICE_REQ;
case COMPAT_QSEECOM_IOCTL_CREATE_KEY_REQ:
return QSEECOM_IOCTL_CREATE_KEY_REQ;
case COMPAT_QSEECOM_IOCTL_WIPE_KEY_REQ:
return QSEECOM_IOCTL_WIPE_KEY_REQ;
case COMPAT_QSEECOM_IOCTL_UPDATE_KEY_USER_INFO_REQ:
return QSEECOM_IOCTL_UPDATE_KEY_USER_INFO_REQ;
case COMPAT_QSEECOM_IOCTL_SAVE_PARTITION_HASH_REQ:
return QSEECOM_IOCTL_SAVE_PARTITION_HASH_REQ;
case COMPAT_QSEECOM_IOCTL_IS_ES_ACTIVATED_REQ:
return QSEECOM_IOCTL_IS_ES_ACTIVATED_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_RESP:
return QSEECOM_IOCTL_SEND_MODFD_RESP;
case COMPAT_QSEECOM_QTEEC_IOCTL_OPEN_SESSION_REQ:
return QSEECOM_QTEEC_IOCTL_OPEN_SESSION_REQ;
case COMPAT_QSEECOM_QTEEC_IOCTL_CLOSE_SESSION_REQ:
return QSEECOM_QTEEC_IOCTL_CLOSE_SESSION_REQ;
case COMPAT_QSEECOM_QTEEC_IOCTL_INVOKE_MODFD_CMD_REQ:
return QSEECOM_QTEEC_IOCTL_INVOKE_MODFD_CMD_REQ;
case COMPAT_QSEECOM_QTEEC_IOCTL_REQUEST_CANCELLATION_REQ:
return QSEECOM_QTEEC_IOCTL_REQUEST_CANCELLATION_REQ;
case COMPAT_QSEECOM_IOCTL_MDTP_CIPHER_DIP_REQ:
return QSEECOM_IOCTL_MDTP_CIPHER_DIP_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_CMD_64_REQ:
return QSEECOM_IOCTL_SEND_MODFD_CMD_64_REQ;
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_RESP_64:
return QSEECOM_IOCTL_SEND_MODFD_RESP_64;
default:
return cmd;
}
}
long compat_qseecom_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
long ret;
switch (cmd) {
case COMPAT_QSEECOM_IOCTL_UNREGISTER_LISTENER_REQ:
case COMPAT_QSEECOM_IOCTL_RECEIVE_REQ:
case COMPAT_QSEECOM_IOCTL_SEND_RESP_REQ:
case COMPAT_QSEECOM_IOCTL_UNLOAD_APP_REQ:
case COMPAT_QSEECOM_IOCTL_PERF_ENABLE_REQ:
case COMPAT_QSEECOM_IOCTL_PERF_DISABLE_REQ:
case COMPAT_QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ: {
return qseecom_ioctl(file, convert_cmd(cmd), 0);
}
break;
case COMPAT_QSEECOM_IOCTL_REGISTER_LISTENER_REQ: {
struct compat_qseecom_register_listener_req __user *data32;
struct qseecom_register_listener_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_register_listener_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_LOAD_APP_REQ: {
struct compat_qseecom_load_img_req __user *data32;
struct qseecom_load_img_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_load_img_req(data32, data);
if (err)
return err;
ret = qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
err = compat_put_qseecom_load_img_req(data32, data);
return ret ? ret : err;
}
break;
case COMPAT_QSEECOM_IOCTL_SEND_CMD_REQ: {
struct compat_qseecom_send_cmd_req __user *data32;
struct qseecom_send_cmd_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_send_cmd_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_CMD_REQ:
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_CMD_64_REQ: {
struct compat_qseecom_send_modfd_cmd_req __user *data32;
struct qseecom_send_modfd_cmd_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_send_modfd_cmd_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_SET_MEM_PARAM_REQ: {
struct compat_qseecom_set_sb_mem_param_req __user *data32;
struct qseecom_set_sb_mem_param_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_set_sb_mem_param_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_GET_QSEOS_VERSION_REQ: {
struct compat_qseecom_qseos_version_req __user *data32;
struct qseecom_qseos_version_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_qseos_version_req(data32, data);
if (err)
return err;
ret = qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
err = compat_put_qseecom_qseos_version_req(data32, data);
return ret ? ret : err;
}
break;
case COMPAT_QSEECOM_IOCTL_SET_BUS_SCALING_REQ: {
compat_int_t __user *data32;
int __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_int(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ: {
struct compat_qseecom_load_img_req __user *data32;
struct qseecom_load_img_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_load_img_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_APP_LOADED_QUERY_REQ: {
struct compat_qseecom_qseos_app_load_query __user *data32;
struct qseecom_qseos_app_load_query __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_qseos_app_load_query(data32, data);
if (err)
return err;
ret = qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
err = compat_put_qseecom_qseos_app_load_query(data32, data);
return ret ? ret : err;
}
break;
case COMPAT_QSEECOM_IOCTL_SEND_CMD_SERVICE_REQ: {
struct compat_qseecom_send_svc_cmd_req __user *data32;
struct qseecom_send_svc_cmd_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_send_svc_cmd_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_CREATE_KEY_REQ: {
struct compat_qseecom_create_key_req __user *data32;
struct qseecom_create_key_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_create_key_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_WIPE_KEY_REQ: {
struct compat_qseecom_wipe_key_req __user *data32;
struct qseecom_wipe_key_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_wipe_key_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_UPDATE_KEY_USER_INFO_REQ: {
struct compat_qseecom_update_key_userinfo_req __user *data32;
struct qseecom_update_key_userinfo_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_update_key_userinfo_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_SAVE_PARTITION_HASH_REQ: {
struct compat_qseecom_save_partition_hash_req __user *data32;
struct qseecom_save_partition_hash_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_save_partition_hash_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_IS_ES_ACTIVATED_REQ: {
struct compat_qseecom_is_es_activated_req __user *data32;
struct qseecom_is_es_activated_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_is_es_activated_req(data32, data);
if (err)
return err;
ret = qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
err = compat_put_qseecom_is_es_activated_req(data32, data);
return ret ? ret : err;
}
break;
case COMPAT_QSEECOM_IOCTL_MDTP_CIPHER_DIP_REQ: {
struct compat_qseecom_mdtp_cipher_dip_req __user *data32;
struct qseecom_mdtp_cipher_dip_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_mdtp_cipher_dip_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_RESP:
case COMPAT_QSEECOM_IOCTL_SEND_MODFD_RESP_64: {
struct compat_qseecom_send_modfd_listener_resp __user *data32;
struct qseecom_send_modfd_listener_resp __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_send_modfd_listener_resp(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_QTEEC_IOCTL_CLOSE_SESSION_REQ: {
struct compat_qseecom_qteec_req __user *data32;
struct qseecom_qteec_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_qteec_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
case COMPAT_QSEECOM_QTEEC_IOCTL_OPEN_SESSION_REQ:
case COMPAT_QSEECOM_QTEEC_IOCTL_INVOKE_MODFD_CMD_REQ:
case COMPAT_QSEECOM_QTEEC_IOCTL_REQUEST_CANCELLATION_REQ: {
struct compat_qseecom_qteec_modfd_req __user *data32;
struct qseecom_qteec_modfd_req __user *data;
int err;
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
if (data == NULL)
return -EFAULT;
err = compat_get_qseecom_qteec_modfd_req(data32, data);
if (err)
return err;
return qseecom_ioctl(file, convert_cmd(cmd),
(unsigned long)data);
}
break;
default:
return -ENOIOCTLCMD;
break;
}
return 0;
}
|