-
Notifications
You must be signed in to change notification settings - Fork 3
/
external_libsamsung-ipc.patch
2413 lines (2325 loc) · 69.5 KB
/
external_libsamsung-ipc.patch
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
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 2af14f9f70d5787afde143b1482c1ea0fbba9687 Mon Sep 17 00:00:00 2001
From: Jonathan Bakker <xc-racer2@live.ca>
Date: Fri, 24 Aug 2018 17:16:02 -0700
Subject: [PATCH 1/9] Fix includes for 4.4
I'm using the 6.0 branch as it has some fixes the 4.4 branch doesn't have
---
Android.mk | 1 +
1 file changed, 1 insertion(+)
diff --git a/Android.mk b/Android.mk
index 8944046..f1445fe 100644
--- a/Android.mk
+++ b/Android.mk
@@ -80,6 +80,7 @@ LOCAL_SRC_FILES := \
samsung-ipc/gen.c
LOCAL_C_INCLUDES := \
+ external/openssl/include \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/samsung-ipc \
$(LOCAL_PATH)/samsung-ipc/devices/xmm616/ \
--
2.11.0
From c0fbf987452804109de370fe3b19e15e77b38392 Mon Sep 17 00:00:00 2001
From: xc-racer99 <xc-racer2@live.ca>
Date: Sat, 21 Apr 2018 15:55:20 -0700
Subject: [PATCH 2/9] Add headers and defines for more RFS commands
Used in the Galaxy S 4G (SGH-T959P/SGH-T959V/SGH-T959W) series for copying files from EFS to the modem device
---
include/rfs.h | 113 ++++++++++++++++++++++++++++++++++++++++++++++++
include/samsung-ipc.h | 1 +
samsung-ipc/ipc.c | 8 ++++
samsung-ipc/ipc.h | 1 +
samsung-ipc/ipc_utils.c | 38 ++++++++++++++++
5 files changed, 161 insertions(+)
diff --git a/include/rfs.h b/include/rfs.h
index 7950f16..2f346ce 100644
--- a/include/rfs.h
+++ b/include/rfs.h
@@ -28,6 +28,25 @@
#define IPC_RFS_NV_READ_ITEM 0x4201
#define IPC_RFS_NV_WRITE_ITEM 0x4202
+#define IPC_RFS_READ_FILE 0x4203
+#define IPC_RFS_WRITE_FILE 0x4204
+#define IPC_RFS_LSEEK_FILE 0x4205
+#define IPC_RFS_CLOSE_FILE 0x4206
+#define IPC_RFS_PUT_FILE 0x4207
+#define IPC_RFS_GET_FILE 0x4208
+#define IPC_RFS_RENAME_FILE 0x4209
+#define IPC_RFS_GET_FILE_INFO 0x420a
+#define IPC_RFS_UNLINK_FILE 0x420b
+#define IPC_RFS_MAKE_DIR 0x420c
+#define IPC_RFS_REMOVE_DIR 0x420d
+#define IPC_RFS_OPEN_DIR 0x420e
+#define IPC_RFS_READ_DIR 0x420f
+#define IPC_RFS_CLOSE_DIR 0x4210
+#define IPC_RFS_OPEN_FILE 0x4211
+#define IPC_RFS_FTRUNCATE_FILE 0x4212
+#define IPC_RFS_GET_HANDLE_INFO 0x4213
+#define IPC_RFS_CREATE_FILE 0x4214
+#define IPC_RFS_NV_WRITE_ALL_ITEM 0x4215
/*
* Values
@@ -36,6 +55,9 @@
#define NV_DATA_SECRET "Samsung_Android_RIL"
#define NV_DATA_SIZE 0x200000
#define NV_DATA_CHUNK_SIZE 0x1000
+#define IPC_RFS_TYPE_UNKNOWN 0x0
+#define IPC_RFS_TYPE_DIRECTORY 0x1
+#define IPC_RFS_TYPE_FILE 0x2
/*
* Structures
@@ -63,6 +85,97 @@ struct ipc_rfs_nv_write_item_response_data {
unsigned int length;
} __attribute__((__packed__));
+struct ipc_rfs_generic_io_response_header {
+ int ret;
+ int err;
+} __attribute__((__packed__));
+
+struct ipc_rfs_read_dir_response_header {
+ int ret;
+ int len;
+ int err;
+} __attribute__((__packed__));
+
+struct ipc_rfs_file_info_response_data {
+ unsigned int ret;
+ unsigned short type;
+ unsigned int size;
+ unsigned char c_year;
+ unsigned char c_month;
+ unsigned char c_day;
+ unsigned char c_hour;
+ unsigned char c_min;
+ unsigned char c_sec;
+ unsigned char m_year;
+ unsigned char m_month;
+ unsigned char m_day;
+ unsigned char m_hour;
+ unsigned char m_min;
+ unsigned char m_sec;
+ unsigned int err;
+} __attribute__((__packed__));
+
+struct ipc_rfs_read_file_request_header {
+ int fd;
+ int len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_write_file_request_header {
+ int fd;
+ int len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_lseek_file_request_header {
+ int fd;
+ int offset;
+ int whence;
+} __attribute__((__packed__));
+
+struct ipc_rfs_close_file_request_header {
+ int fd;
+} __attribute__((__packed__));
+
+struct ipc_rfs_get_file_info_request_header {
+ int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_rename_file_request_header {
+ int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_unlink_file_request_header {
+ int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_make_dir_request_header {
+ int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_remove_dir_request_header {
+ int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_open_dir_request_header {
+ int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_read_dir_request_header {
+ unsigned int addr;
+} __attribute__((__packed__));
+
+struct ipc_rfs_close_dir_request_header {
+ unsigned int addr;
+} __attribute__((__packed__));
+
+struct ipc_rfs_open_file_request_header {
+ unsigned int flags; // | O_DSYNC
+ unsigned int path_len;
+} __attribute__((__packed__));
+
+struct ipc_rfs_get_handle_info_request_header {
+ int fd;
+} __attribute__((__packed__));
+
/*
* Helpers
*/
diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h
index 9d638ec..3bde3c0 100644
--- a/include/samsung-ipc.h
+++ b/include/samsung-ipc.h
@@ -105,6 +105,7 @@ char *ipc_client_gprs_get_iface(struct ipc_client *client, unsigned int cid);
int ipc_client_gprs_get_capabilities(struct ipc_client *client,
struct ipc_client_gprs_capabilities *capabilities);
+char *ipc_client_efs_root(struct ipc_client *client);
char *ipc_client_nv_data_path(struct ipc_client *client);
char *ipc_client_nv_data_md5_path(struct ipc_client *client);
char *ipc_client_nv_data_backup_path(struct ipc_client *client);
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index b3ee679..fcfd19c 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -431,6 +431,14 @@ int ipc_client_gprs_get_capabilities(struct ipc_client *client,
return client->gprs_specs->gprs_get_capabilities(capabilities);
}
+char *ipc_client_efs_root(struct ipc_client *client)
+{
+ if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->efs_root == NULL)
+ return NULL;
+
+ return client->nv_data_specs->efs_root;
+}
+
char *ipc_client_nv_data_path(struct ipc_client *client)
{
if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_path == NULL)
diff --git a/samsung-ipc/ipc.h b/samsung-ipc/ipc.h
index 60fca12..ed483f2 100644
--- a/samsung-ipc/ipc.h
+++ b/samsung-ipc/ipc.h
@@ -70,6 +70,7 @@ struct ipc_client_gprs_specs {
};
struct ipc_client_nv_data_specs {
+ char *efs_root;
char *nv_data_path;
char *nv_data_md5_path;
char *nv_data_backup_path;
diff --git a/samsung-ipc/ipc_utils.c b/samsung-ipc/ipc_utils.c
index 33860ce..4e145e9 100644
--- a/samsung-ipc/ipc_utils.c
+++ b/samsung-ipc/ipc_utils.c
@@ -345,6 +345,44 @@ const char *ipc_command_string(unsigned short command)
return "IPC_RFS_NV_READ_ITEM";
case IPC_RFS_NV_WRITE_ITEM:
return "IPC_RFS_NV_WRITE_ITEM";
+ case IPC_RFS_READ_FILE:
+ return "IPC_RFS_READ_FILE";
+ case IPC_RFS_WRITE_FILE:
+ return "IPC_RFS_WRITE_FILE";
+ case IPC_RFS_LSEEK_FILE:
+ return "IPC_RFS_LSEEK_FILE";
+ case IPC_RFS_CLOSE_FILE:
+ return "IPC_RFS_CLOSE_FILE";
+ case IPC_RFS_PUT_FILE:
+ return "IPC_RFS_PUT_FILE";
+ case IPC_RFS_GET_FILE:
+ return "IPC_RFS_GET_FILE";
+ case IPC_RFS_RENAME_FILE:
+ return "IPC_RFS_RENAME_FILE";
+ case IPC_RFS_GET_FILE_INFO:
+ return "IPC_RFS_GET_FILE_INFO";
+ case IPC_RFS_UNLINK_FILE:
+ return "IPC_RFS_UNLINK_FILE";
+ case IPC_RFS_MAKE_DIR:
+ return "IPC_RFS_MAKE_DIR";
+ case IPC_RFS_REMOVE_DIR:
+ return "IPC_RFS_REMOVE_DIR";
+ case IPC_RFS_OPEN_DIR:
+ return "IPC_RFS_OPEN_DIR";
+ case IPC_RFS_READ_DIR:
+ return "IPC_RFS_READ_DIR";
+ case IPC_RFS_CLOSE_DIR:
+ return "IPC_RFS_CLOSE_DIR";
+ case IPC_RFS_OPEN_FILE:
+ return "IPC_RFS_OPEN_FILE";
+ case IPC_RFS_FTRUNCATE_FILE:
+ return "IPC_RFS_FTRUNCATE_FILE";
+ case IPC_RFS_GET_HANDLE_INFO:
+ return "IPC_RFS_GET_HANDLE_INFO";
+ case IPC_RFS_CREATE_FILE:
+ return "IPC_RFS_CREATE_FILE";
+ case IPC_RFS_NV_WRITE_ALL_ITEM:
+ return "IPC_RFS_NV_WRITE_ALL_ITEM";
case IPC_GEN_PHONE_RES:
return "IPC_GEN_PHONE_RES";
default:
--
2.11.0
From cf894c5c30f403c85a990b0e80ce59fbd9def4e3 Mon Sep 17 00:00:00 2001
From: xc-racer99 <xc-racer2@live.ca>
Date: Mon, 23 Apr 2018 17:07:03 -0700
Subject: [PATCH 3/9] Fix struct ipc_net_serving_network_data definition
On some devices, the last entry is a char, not a short (and perhaps not lac?) Regardless, it is never used except for verification of minimum size of message
---
include/net.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net.h b/include/net.h
index 390541e..6d67e38 100644
--- a/include/net.h
+++ b/include/net.h
@@ -94,7 +94,7 @@ struct ipc_net_plmn_sel_request_data {
struct ipc_net_serving_network_data {
unsigned char unknown[3];
char plmn[6];
- unsigned short lac;
+ unsigned char lac; // This can be either a short or a char
} __attribute__((__packed__));
struct ipc_net_plmn_list_header {
--
2.11.0
From 4db4786b4ab6fcab41b3459b5a67f5a132ad744e Mon Sep 17 00:00:00 2001
From: xc-racer99 <xc-racer2@live.ca>
Date: Tue, 24 Apr 2018 14:19:30 -0700
Subject: [PATCH 4/9] Add more call type defines
We don't need to handle them for basic calling support, but they should defined in case they ever do appear in the wild
---
include/call.h | 3 +++
samsung-ipc/ipc_utils.c | 6 ++++++
2 files changed, 9 insertions(+)
diff --git a/include/call.h b/include/call.h
index 4f5d152..cc0988a 100644
--- a/include/call.h
+++ b/include/call.h
@@ -37,6 +37,9 @@
#define IPC_CALL_CONT_DTMF 0x0208
#define IPC_CALL_WAITING 0x0209
#define IPC_CALL_LINE_ID 0x020A
+#define IPC_CALL_SIGNAL 0x020B
+#define IPC_CALL_VOICE_PRIVACY 0x020C
+#define IPC_CALL_CALL_TIME_COUNT 0x020D
/*
* Values
diff --git a/samsung-ipc/ipc_utils.c b/samsung-ipc/ipc_utils.c
index 4e145e9..8c33e2e 100644
--- a/samsung-ipc/ipc_utils.c
+++ b/samsung-ipc/ipc_utils.c
@@ -117,6 +117,12 @@ const char *ipc_command_string(unsigned short command)
return "IPC_CALL_WAITING";
case IPC_CALL_LINE_ID:
return "IPC_CALL_LINE_ID";
+ case IPC_CALL_SIGNAL:
+ return "IPC_CALL_SIGNAL";
+ case IPC_CALL_VOICE_PRIVACY:
+ return "IPC_CALL_VOICE_PRIVACY";
+ case IPC_CALL_CALL_TIME_COUNT:
+ return "IPC_CALL_CALL_TIME_COUNT";
case IPC_SMS_SEND_MSG:
return "IPC_SMS_SEND_MSG";
case IPC_SMS_INCOMING_MSG:
--
2.11.0
From c14e65fba620130534cfaec3dbdd315336883843 Mon Sep 17 00:00:00 2001
From: xc-racer99 <xc-racer2@live.ca>
Date: Thu, 26 Apr 2018 11:42:20 -0700
Subject: [PATCH 5/9] Add a default call type
Used instead of voice with some devices
---
include/call.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/call.h b/include/call.h
index cc0988a..4c811c5 100644
--- a/include/call.h
+++ b/include/call.h
@@ -45,6 +45,7 @@
* Values
*/
+#define IPC_CALL_TYPE_DEFAULT 0x00
#define IPC_CALL_TYPE_VOICE 0x01
#define IPC_CALL_TYPE_DATA 0x03
--
2.11.0
From 42aaa1a0dfe7b8900ad5a3bdadcc9c526f4fad88 Mon Sep 17 00:00:00 2001
From: xc-racer99 <xc-racer2@live.ca>
Date: Sun, 15 Apr 2018 12:58:49 -0700
Subject: [PATCH 6/9] Add CRC CCITT calculation library
The XMODEM version is used by Galaxy S 4G devices in the serial communication with its STE M5730 modem
From https://github.com/lammertb/libcrc/tree/v2.0
---
Android.mk | 1 +
samsung-ipc/Makefile.am | 1 +
samsung-ipc/checksum.h | 81 ++++++++++++++++++++++
samsung-ipc/crc_ccitt.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 259 insertions(+)
create mode 100644 samsung-ipc/checksum.h
create mode 100644 samsung-ipc/crc_ccitt.c
diff --git a/Android.mk b/Android.mk
index f1445fe..3aa9dd0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -68,6 +68,7 @@ LOCAL_SRC_FILES := \
samsung-ipc/devices/i9300/i9300.c \
samsung-ipc/devices/n7100/n7100.c \
samsung-ipc/devices/n5100/n5100.c \
+ samsung-ipc/crc_ccitt.c \
samsung-ipc/utils.c \
samsung-ipc/call.c \
samsung-ipc/sms.c \
diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am
index ed65c29..1dda9c2 100644
--- a/samsung-ipc/Makefile.am
+++ b/samsung-ipc/Makefile.am
@@ -55,6 +55,7 @@ libsamsung_ipc_la_SOURCES = \
devices/n5100/n5100.c \
devices/n5100/n5100.h \
utils.c \
+ crc_ccitt.c \
call.c \
sms.c \
sec.c \
diff --git a/samsung-ipc/checksum.h b/samsung-ipc/checksum.h
new file mode 100644
index 0000000..0a3dee7
--- /dev/null
+++ b/samsung-ipc/checksum.h
@@ -0,0 +1,81 @@
+/*
+ * Library: libcrc
+ * File: include/checksum.h
+ * Author: Lammert Bies
+ *
+ * This file is licensed under the MIT License as stated below
+ *
+ * Copyright (c) 1999-2016 Lammert Bies
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Description
+ * -----------
+ * The headerfile include/checksum.h contains the definitions and prototypes
+ * for routines that can be used to calculate several kinds of checksums.
+ */
+
+#ifndef DEF_LIBCRC_CHECKSUM_H
+#define DEF_LIBCRC_CHECKSUM_H
+
+#include <stdint.h>
+
+/*
+ * #define CRC_POLY_xxxx
+ *
+ * The constants of the form CRC_POLY_xxxx define the polynomials for some well
+ * known CRC calculations.
+ */
+
+#define CRC_POLY_16 0xA001
+#define CRC_POLY_32 0xEDB88320L
+#define CRC_POLY_CCITT 0x1021
+#define CRC_POLY_DNP 0xA6BC
+#define CRC_POLY_KERMIT 0x8408
+#define CRC_POLY_SICK 0x8005
+
+/*
+ * #define CRC_START_xxxx
+ *
+ * The constants of the form CRC_START_xxxx define the values that are used for
+ * initialization of a CRC value for common used calculation methods.
+ */
+
+#define CRC_START_8 0x00
+#define CRC_START_16 0x0000
+#define CRC_START_MODBUS 0xFFFF
+#define CRC_START_XMODEM 0x0000
+#define CRC_START_CCITT_1D0F 0x1D0F
+#define CRC_START_CCITT_FFFF 0xFFFF
+#define CRC_START_KERMIT 0x0000
+#define CRC_START_SICK 0x0000
+#define CRC_START_DNP 0x0000
+#define CRC_START_32 0xFFFFFFFFL
+
+/*
+ * Prototype list of global functions
+ */
+
+uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes );
+uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes );
+uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes );
+uint16_t update_crc_ccitt( uint16_t crc, unsigned char c );
+
+#endif // DEF_LIBCRC_CHECKSUM_H
+
diff --git a/samsung-ipc/crc_ccitt.c b/samsung-ipc/crc_ccitt.c
new file mode 100644
index 0000000..7b3ddad
--- /dev/null
+++ b/samsung-ipc/crc_ccitt.c
@@ -0,0 +1,176 @@
+/*
+ * Library: libcrc
+ * File: src/crcccitt.c
+ * Author: Lammert Bies
+ *
+ * This file is licensed under the MIT License as stated below
+ *
+ * Copyright (c) 1999-2016 Lammert Bies
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Description
+ * -----------
+ * The module src/crcccitt.c contains routines which are used to calculate the
+ * CCITT CRC values of a string of bytes.
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include "checksum.h"
+
+static uint16_t crc_ccitt_generic( const unsigned char *input_str, size_t num_bytes, uint16_t start_value );
+static void init_crcccitt_tab( void );
+
+static bool crc_tabccitt_init = false;
+static uint16_t crc_tabccitt[256];
+
+/*
+ * uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes );
+ *
+ * The function crc_xmodem() performs a one-pass calculation of an X-Modem CRC
+ * for a byte string that has been passed as a parameter.
+ */
+
+uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes ) {
+
+ return crc_ccitt_generic( input_str, num_bytes, CRC_START_XMODEM );
+
+} /* crc_xmodem */
+
+/*
+ * uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes );
+ *
+ * The function crc_ccitt_1d0f() performs a one-pass calculation of the CCITT
+ * CRC for a byte string that has been passed as a parameter. The initial value
+ * 0x1d0f is used for the CRC.
+ */
+
+uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes ) {
+
+ return crc_ccitt_generic( input_str, num_bytes, CRC_START_CCITT_1D0F );
+
+} /* crc_ccitt_1d0f */
+
+/*
+ * uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes );
+ *
+ * The function crc_ccitt_ffff() performs a one-pass calculation of the CCITT
+ * CRC for a byte string that has been passed as a parameter. The initial value
+ * 0xffff is used for the CRC.
+ */
+
+uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes ) {
+
+ return crc_ccitt_generic( input_str, num_bytes, CRC_START_CCITT_FFFF );
+
+} /* crc_ccitt_ffff */
+
+/*
+ * static uint16_t crc_ccitt_generic( const unsigned char *input_str, size_t num_bytes, uint16_t start_value );
+ *
+ * The function crc_ccitt_generic() is a generic implementation of the CCITT
+ * algorithm for a one-pass calculation of the CRC for a byte string. The
+ * function accepts an initial start value for the crc.
+ */
+
+static uint16_t crc_ccitt_generic( const unsigned char *input_str, size_t num_bytes, uint16_t start_value ) {
+
+ uint16_t crc;
+ uint16_t tmp;
+ uint16_t short_c;
+ const unsigned char *ptr;
+ size_t a;
+
+ if ( ! crc_tabccitt_init ) init_crcccitt_tab();
+
+ crc = start_value;
+ ptr = input_str;
+
+ if ( ptr != NULL ) for (a=0; a<num_bytes; a++) {
+
+ short_c = 0x00ff & (unsigned short) *ptr;
+ tmp = (crc >> 8) ^ short_c;
+ crc = (crc << 8) ^ crc_tabccitt[tmp];
+
+ ptr++;
+ }
+
+ return crc;
+
+} /* crc_ccitt_generic */
+
+/*
+ * uint16_t update_crc_ccitt( uint16_t crc, unsigned char c );
+ *
+ * The function update_crc_ccitt() calculates a new CRC-CCITT value based on
+ * the previous value of the CRC and the next byte of the data to be checked.
+ */
+
+uint16_t update_crc_ccitt( uint16_t crc, unsigned char c ) {
+
+ int16_t tmp;
+ int16_t short_c;
+
+ short_c = 0x00ff & (uint16_t) c;
+
+ if ( ! crc_tabccitt_init ) init_crcccitt_tab();
+
+ tmp = (crc >> 8) ^ short_c;
+ crc = (crc << 8) ^ crc_tabccitt[tmp];
+
+ return crc;
+
+} /* update_crc_ccitt */
+
+/*
+ * static void init_crcccitt_tab( void );
+ *
+ * For optimal performance, the routine to calculate the CRC-CCITT uses a
+ * lookup table with pre-compiled values that can be directly applied in the
+ * XOR action. This table is created at the first call of the function by the
+ * init_crcccitt_tab() routine.
+ */
+
+static void init_crcccitt_tab( void ) {
+
+ uint16_t i;
+ uint16_t j;
+ uint16_t crc;
+ uint16_t c;
+
+ for (i=0; i<256; i++) {
+
+ crc = 0;
+ c = i << 8;
+
+ for (j=0; j<8; j++) {
+
+ if ( (crc ^ c) & 0x8000 ) crc = ( crc << 1 ) ^ CRC_POLY_CCITT;
+ else crc = crc << 1;
+
+ c = c << 1;
+ }
+
+ crc_tabccitt[i] = crc;
+ }
+
+ crc_tabccitt_init = true;
+
+} /* init_crcccitt_tab */
--
2.11.0
From 8d2a27bb01118517589ebf1e823160a0c803660c Mon Sep 17 00:00:00 2001
From: Jonathan Bakker <xc-racer2@live.ca>
Date: Thu, 3 Jan 2019 12:18:24 -0800
Subject: [PATCH 7/9] Add support for mainline kernel and STE M5730 modems to
Crespo driver
Some Galaxy S variants use an STE modem which has a different startup
Additionally, add some alternative paths for serial and modem image
devices as newer mainline kernels have some differences.
Also add a board name for S5PV210 mainline boards
---
Android.mk | 3 +-
samsung-ipc/Makefile.am | 2 +
samsung-ipc/devices/crespo/crespo.c | 43 +-
samsung-ipc/devices/crespo/crespo.h | 7 +-
samsung-ipc/devices/crespo/crespo_modem_ctl.h | 3 +
samsung-ipc/devices/crespo/crespo_ste_m5730.c | 543 ++++++++++++++++++++++++++
samsung-ipc/devices/crespo/ste_m5730.h | 36 ++
samsung-ipc/ipc_devices.c | 10 +
8 files changed, 641 insertions(+), 6 deletions(-)
create mode 100644 samsung-ipc/devices/crespo/crespo_ste_m5730.c
create mode 100644 samsung-ipc/devices/crespo/ste_m5730.h
diff --git a/Android.mk b/Android.mk
index 3aa9dd0..541c63a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -19,7 +19,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-ifneq (,$(filter crespo,$(TARGET_DEVICE)))
+ifneq (,$(filter crespo galaxys4gmtd fascinate4gmtd,$(TARGET_DEVICE)))
ipc_device_name := crespo
endif
@@ -61,6 +61,7 @@ LOCAL_SRC_FILES := \
samsung-ipc/devices/xmm626/xmm626_mipi.c \
samsung-ipc/devices/xmm626/xmm626_sec_modem.c \
samsung-ipc/devices/crespo/crespo.c \
+ samsung-ipc/devices/crespo/crespo_ste_m5730.c \
samsung-ipc/devices/aries/aries.c \
samsung-ipc/devices/galaxys2/galaxys2.c \
samsung-ipc/devices/maguro/maguro.c \
diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am
index 1dda9c2..7bdfd37 100644
--- a/samsung-ipc/Makefile.am
+++ b/samsung-ipc/Makefile.am
@@ -36,8 +36,10 @@ libsamsung_ipc_la_SOURCES = \
devices/xmm626/modem_link_device_hsic.h \
devices/xmm626/modem_prj.h \
devices/crespo/crespo.c \
+ devices/crespo/crespo_ste_m5730.c \
devices/crespo/crespo.h \
devices/crespo/crespo_modem_ctl.h \
+ devices/crespo/ste_m5730.h \
devices/aries/aries.c \
devices/aries/aries.h \
devices/aries/onedram.h \
diff --git a/samsung-ipc/devices/crespo/crespo.c b/samsung-ipc/devices/crespo/crespo.c
index c6837e5..40dca27 100644
--- a/samsung-ipc/devices/crespo/crespo.c
+++ b/samsung-ipc/devices/crespo/crespo.c
@@ -26,6 +26,7 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/select.h>
@@ -36,9 +37,10 @@
#include "crespo_modem_ctl.h"
#include "xmm616.h"
+#include "ste_m5730.h"
#include "crespo.h"
-int crespo_boot(struct ipc_client *client)
+int crespo_xmm_boot(struct ipc_client *client)
{
void *modem_image_data = NULL;
int modem_ctl_fd = -1;
@@ -51,7 +53,13 @@ int crespo_boot(struct ipc_client *client)
ipc_client_log(client, "Starting crespo modem boot");
- modem_image_data = file_data_read(CRESPO_MODEM_IMAGE_DEVICE, CRESPO_MODEM_IMAGE_SIZE, 0x1000, 0);
+ /* Try alternative modem image device first as the main one may exist
+ * even when it doesn't contain the modem
+ */
+ modem_image_data = file_data_read(CRESPO_ALT_MODEM_IMAGE_DEVICE, CRESPO_XMM_MODEM_IMAGE_SIZE, 0x1000, 0);
+ if (modem_image_data == NULL)
+ modem_image_data = file_data_read(CRESPO_MODEM_IMAGE_DEVICE, CRESPO_XMM_MODEM_IMAGE_SIZE, 0x1000, 0);
+
if (modem_image_data == NULL) {
ipc_client_log(client, "Reading modem image data failed");
goto error;
@@ -73,6 +81,9 @@ int crespo_boot(struct ipc_client *client)
ipc_client_log(client, "Reset modem");
serial_fd = open(CRESPO_MODEM_SERIAL_DEVICE, O_RDWR | O_NDELAY);
+ if (serial_fd < 0 && errno == ENOENT)
+ serial_fd = open(CRESPO_ALT_MODEM_SERIAL_DEVICE, O_RDWR | O_NDELAY);
+
if (serial_fd < 0) {
ipc_client_log(client, "Opening serial failed");
goto error;
@@ -94,7 +105,7 @@ int crespo_boot(struct ipc_client *client)
lseek(modem_ctl_fd, 0, SEEK_SET);
- rc = xmm616_firmware_send(client, modem_ctl_fd, NULL, (void *) p, CRESPO_MODEM_IMAGE_SIZE - CRESPO_PSI_SIZE);
+ rc = xmm616_firmware_send(client, modem_ctl_fd, NULL, (void *) p, CRESPO_XMM_MODEM_IMAGE_SIZE - CRESPO_PSI_SIZE);
if (rc < 0) {
ipc_client_log(client, "Sending XMM616 firmware failed");
goto error;
@@ -129,6 +140,21 @@ complete:
return rc;
}
+int crespo_boot(struct ipc_client *client)
+{
+ int rc;
+
+ if (crespo_is_ste()) {
+ ipc_client_log(client, "Detected an STE M5730 modem");
+ rc = crespo_ste_boot(client);
+ } else {
+ ipc_client_log(client, "Detected an XMM6160 modem");
+ rc = crespo_xmm_boot(client);
+ }
+
+ return rc;
+}
+
int crespo_fmt_send(struct ipc_client *client, struct ipc_message *message)
{
struct ipc_fmt_header header;
@@ -444,7 +470,7 @@ int crespo_poll(void *data, struct ipc_poll_fds *fds, struct timeval *timeout)
return rc;
}
-int crespo_power_on(void *data)
+int crespo_xmm_power_on(void *data)
{
int fd;
int rc;
@@ -463,6 +489,14 @@ int crespo_power_on(void *data)
return 0;
}
+int crespo_power_on(void *data)
+{
+ if (crespo_is_ste())
+ return crespo_ste_power_on(data);
+
+ return crespo_xmm_power_on(data);
+}
+
int crespo_power_off(void *data)
{
int fd;
@@ -594,6 +628,7 @@ struct ipc_client_gprs_specs crespo_gprs_specs = {
};
struct ipc_client_nv_data_specs crespo_nv_data_specs = {
+ .efs_root = CRESPO_EFS_ROOT,
.nv_data_path = XMM616_NV_DATA_PATH,
.nv_data_md5_path = XMM616_NV_DATA_MD5_PATH,
.nv_data_backup_path = XMM616_NV_DATA_BACKUP_PATH,
diff --git a/samsung-ipc/devices/crespo/crespo.h b/samsung-ipc/devices/crespo/crespo.h
index 97dff96..b02dd97 100644
--- a/samsung-ipc/devices/crespo/crespo.h
+++ b/samsung-ipc/devices/crespo/crespo.h
@@ -20,13 +20,16 @@
#ifndef __CRESPO_H__
#define __CRESPO_H__
-#define CRESPO_MODEM_IMAGE_SIZE 0xD80000
+#define CRESPO_XMM_MODEM_IMAGE_SIZE 0xD80000
+#define CRESPO_STE_MODEM_IMAGE_SIZE 0xE05000
#define CRESPO_PSI_SIZE 0x5000
#define CRESPO_MODEM_CTL_NV_DATA_OFFSET 0xD80000
#define CRESPO_BUFFER_LENGTH 0x50000
#define CRESPO_MODEM_IMAGE_DEVICE "/dev/mtd/mtd5ro"
+#define CRESPO_ALT_MODEM_IMAGE_DEVICE "/radio/modem.bin"
#define CRESPO_MODEM_SERIAL_DEVICE "/dev/s3c2410_serial3"
+#define CRESPO_ALT_MODEM_SERIAL_DEVICE "/dev/ttySAC3"
#define CRESPO_MODEM_CTL_DEVICE "/dev/modem_ctl"
#define CRESPO_MODEM_FMT_DEVICE "/dev/modem_fmt"
#define CRESPO_MODEM_RFS_DEVICE "/dev/modem_rfs"
@@ -34,6 +37,8 @@
#define CRESPO_GPRS_IFACE_PREFIX "rmnet"
#define CRESPO_GPRS_IFACE_COUNT 3
+#define CRESPO_EFS_ROOT "/efs/root"
+
struct crespo_transport_data {
int fd;
};
diff --git a/samsung-ipc/devices/crespo/crespo_modem_ctl.h b/samsung-ipc/devices/crespo/crespo_modem_ctl.h
index 7c23165..355b5ed 100644
--- a/samsung-ipc/devices/crespo/crespo_modem_ctl.h
+++ b/samsung-ipc/devices/crespo/crespo_modem_ctl.h
@@ -24,6 +24,9 @@
#define IOCTL_MODEM_SEND _IO('o', 0x23)
#define IOCTL_MODEM_RECV _IO('o', 0x24)
+#define IOCTL_MODEM_WAIT_FOR_SBL _IO('o', 0x25)
+#define IOCTL_MODEM_BINARY_LOAD _IO('o', 0x26)
+
struct modem_io {
uint32_t size;
uint32_t id;
diff --git a/samsung-ipc/devices/crespo/crespo_ste_m5730.c b/samsung-ipc/devices/crespo/crespo_ste_m5730.c
new file mode 100644
index 0000000..8baac4b
--- /dev/null
+++ b/samsung-ipc/devices/crespo/crespo_ste_m5730.c
@@ -0,0 +1,543 @@
+/*
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2011 Joerie de Gram <j.de.gram@gmail.com>
+ * Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
+ * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * libsamsung-ipc is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * libsamsung-ipc 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+
+#include <samsung-ipc.h>
+#include <checksum.h>
+#include <ipc.h>
+
+#include "crespo_modem_ctl.h"
+
+#include "xmm616.h"
+#include "ste_m5730.h"
+#include "crespo.h"
+
+const char* const send_protroms[] = {
+ "\x64",
+ "\x64\x88\x01",
+ "\x64\x88\x01\x04",
+ "\x04\x00",
+};
+
+int crespo_is_ste(void)
+{
+ char buf[10];
+ int fd, rc;
+
+ fd = open(CRESPO_MODEM_TYPE_SYSFS, O_RDONLY);
+ if (fd < 0)
+ return 0;
+
+ rc = read(fd, buf, 10);
+ if (strncmp(buf, "ste", 10))
+ rc = 1;
+ else
+ rc = 0;
+
+ close(fd);
+
+ return rc;
+}
+
+int m5730_write_baud_change(struct ipc_client *client, int serial_fd)
+{
+ struct timeval time;
+ fd_set fds;
+ unsigned char buf[8];
+ int rc;
+ int i;
+
+ usleep(110000);
+
+start_z_protocol:
+ /* Flush serial */
+ ioctl(serial_fd, TCFLSH, TCIOFLUSH);
+
+ /* Write b */
+ rc = write(serial_fd, "b", 1);
+ if (rc != 1) {
+ ipc_client_log(client, "Failed to write b");