-
Notifications
You must be signed in to change notification settings - Fork 22
/
QMIThread.c
2786 lines (2445 loc) · 112 KB
/
QMIThread.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
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
/******************************************************************************
@file QMIThread.c
@brief QMI WWAN connectivity manager.
DESCRIPTION
Connectivity Management Tool for USB network adapter of Quectel wireless cellular modules.
INITIALIZATION AND SEQUENCING REQUIREMENTS
None.
---------------------------------------------------------------------------
Copyright (c) 2016 - 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
Quectel Wireless Solution Proprietary and Confidential.
---------------------------------------------------------------------------
******************************************************************************/
#include "QMIThread.h"
#include <inttypes.h>
#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a): (b))
#endif
#define qmi_rsp_check_and_return() do { \
if (err < 0 || pResponse == NULL) { \
dbg_time("%s err = %d", __func__, err); \
return err; \
} \
pMUXMsg = &pResponse->MUXMsg; \
if (le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXResult) || le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXError)) { \
USHORT QMUXError = le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXError); \
dbg_time("%s QMUXResult = 0x%x, QMUXError = 0x%x", __func__, \
le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXResult), QMUXError); \
free(pResponse); \
return QMUXError; \
} \
} while(0)
#define qmi_rsp_check() do { \
if (err < 0 || pResponse == NULL) { \
dbg_time("%s err = %d", __func__, err); \
return err; \
} \
pMUXMsg = &pResponse->MUXMsg; \
if (le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXResult) || le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXError)) { \
USHORT QMUXError = le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXError); \
dbg_time("%s QMUXResult = 0x%x, QMUXError = 0x%x", __func__, \
le16_to_cpu(pMUXMsg->QMUXMsgHdrResp.QMUXResult), QMUXError); \
} \
} while(0)
static uint32_t WdsConnectionIPv4Handle = 0;
static uint32_t WdsConnectionIPv6Handle = 0;
static int s_is_cdma = 0;
static int s_5g_type = WWAN_DATA_CLASS_NONE;
static int s_hdr_personality = 0; // 0x01-HRPD, 0x02-eHRPD
static char *qstrcpy(char *to, const char *from) { //no __strcpy_chk
char *save = to;
for (; (*to = *from) != '\0'; ++from, ++to);
return(save);
}
static void uchar2char(char *dst_ptr, size_t dst_len, const UCHAR *src_ptr, size_t src_len) {
size_t copy = MIN(dst_len-1, src_len);
if (copy)
memcpy(dst_ptr, src_ptr, copy);
dst_ptr[copy] = 0;
}
static int s_9x07 = 1;
typedef USHORT (*CUSTOMQMUX)(PQMUX_MSG pMUXMsg, void *arg);
// To retrieve the ith (Index) TLV
PQMI_TLV_HDR GetTLV (PQCQMUX_MSG_HDR pQMUXMsgHdr, int TLVType) {
int TLVFind = 0;
USHORT Length = le16_to_cpu(pQMUXMsgHdr->Length);
PQMI_TLV_HDR pTLVHdr = (PQMI_TLV_HDR)(pQMUXMsgHdr + 1);
while (Length >= sizeof(QMI_TLV_HDR)) {
TLVFind++;
if (TLVType > 0x1000) {
if ((TLVFind + 0x1000) == TLVType)
return pTLVHdr;
} else if (pTLVHdr->TLVType == TLVType) {
return pTLVHdr;
}
Length -= (le16_to_cpu((pTLVHdr->TLVLength)) + sizeof(QMI_TLV_HDR));
pTLVHdr = (PQMI_TLV_HDR)(((UCHAR *)pTLVHdr) + le16_to_cpu(pTLVHdr->TLVLength) + sizeof(QMI_TLV_HDR));
}
return NULL;
}
static USHORT GetQMUXTransactionId(void) {
static int TransactionId = 0;
if (++TransactionId > 0xFFFF)
TransactionId = 1;
return TransactionId;
}
static PQCQMIMSG ComposeQMUXMsg(UCHAR QMIType, USHORT Type, CUSTOMQMUX customQmuxMsgFunction, void *arg) {
UCHAR QMIBuf[WDM_DEFAULT_BUFSIZE];
PQCQMIMSG pRequest = (PQCQMIMSG)QMIBuf;
int Length;
memset(QMIBuf, 0x00, sizeof(QMIBuf));
pRequest->QMIHdr.IFType = USB_CTL_MSG_TYPE_QMI;
pRequest->QMIHdr.CtlFlags = 0x00;
pRequest->QMIHdr.QMIType = QMIType;
pRequest->MUXMsg.QMUXHdr.CtlFlags = QMUX_CTL_FLAG_SINGLE_MSG | QMUX_CTL_FLAG_TYPE_CMD;
pRequest->MUXMsg.QMUXHdr.TransactionId = cpu_to_le16(GetQMUXTransactionId());
pRequest->MUXMsg.QMUXMsgHdr.Type = cpu_to_le16(Type);
if (customQmuxMsgFunction)
pRequest->MUXMsg.QMUXMsgHdr.Length = cpu_to_le16(customQmuxMsgFunction(&pRequest->MUXMsg, arg) - sizeof(QCQMUX_MSG_HDR));
else
pRequest->MUXMsg.QMUXMsgHdr.Length = cpu_to_le16(0x0000);
pRequest->QMIHdr.Length = cpu_to_le16(le16_to_cpu(pRequest->MUXMsg.QMUXMsgHdr.Length) + sizeof(QCQMUX_MSG_HDR) + sizeof(QCQMUX_HDR)
+ sizeof(QCQMI_HDR) - 1);
Length = le16_to_cpu(pRequest->QMIHdr.Length) + 1;
pRequest = (PQCQMIMSG)malloc(Length);
if (pRequest == NULL) {
dbg_time("%s fail to malloc", __func__);
} else {
memcpy(pRequest, QMIBuf, Length);
}
return pRequest;
}
#if 0
static USHORT NasSetEventReportReq(PQMUX_MSG pMUXMsg, void *arg) {
pMUXMsg->SetEventReportReq.TLVType = 0x10;
pMUXMsg->SetEventReportReq.TLVLength = 0x04;
pMUXMsg->SetEventReportReq.ReportSigStrength = 0x00;
pMUXMsg->SetEventReportReq.NumTresholds = 2;
pMUXMsg->SetEventReportReq.TresholdList[0] = -113;
pMUXMsg->SetEventReportReq.TresholdList[1] = -50;
return sizeof(QMINAS_SET_EVENT_REPORT_REQ_MSG);
}
static USHORT WdsSetEventReportReq(PQMUX_MSG pMUXMsg, void *arg) {
pMUXMsg->EventReportReq.TLVType = 0x10; // 0x10 -- current channel rate indicator
pMUXMsg->EventReportReq.TLVLength = 0x0001; // 1
pMUXMsg->EventReportReq.Mode = 0x00; // 0-do not report; 1-report when rate changes
pMUXMsg->EventReportReq.TLV2Type = 0x11; // 0x11
pMUXMsg->EventReportReq.TLV2Length = 0x0005; // 5
pMUXMsg->EventReportReq.StatsPeriod = 0x00; // seconds between reports; 0-do not report
pMUXMsg->EventReportReq.StatsMask = 0x000000ff; //
pMUXMsg->EventReportReq.TLV3Type = 0x12; // 0x12 -- current data bearer indicator
pMUXMsg->EventReportReq.TLV3Length = 0x0001; // 1
pMUXMsg->EventReportReq.Mode3 = 0x01; // 0-do not report; 1-report when changes
pMUXMsg->EventReportReq.TLV4Type = 0x13; // 0x13 -- dormancy status indicator
pMUXMsg->EventReportReq.TLV4Length = 0x0001; // 1
pMUXMsg->EventReportReq.DormancyStatus = 0x00; // 0-do not report; 1-report when changes
return sizeof(QMIWDS_SET_EVENT_REPORT_REQ_MSG);
}
static USHORT DmsSetEventReportReq(PQMUX_MSG pMUXMsg) {
PPIN_STATUS pPinState = (PPIN_STATUS)(&pMUXMsg->DmsSetEventReportReq + 1);
PUIM_STATE pUimState = (PUIM_STATE)(pPinState + 1);
// Pin State
pPinState->TLVType = 0x12;
pPinState->TLVLength = 0x01;
pPinState->ReportPinState = 0x01;
// UIM State
pUimState->TLVType = 0x15;
pUimState->TLVLength = 0x01;
pUimState->UIMState = 0x01;
return sizeof(QMIDMS_SET_EVENT_REPORT_REQ_MSG) + sizeof(PIN_STATUS) + sizeof(UIM_STATE);
}
#endif
static USHORT WdsStartNwInterfaceReq(PQMUX_MSG pMUXMsg, void *arg) {
PQMIWDS_TECHNOLOGY_PREFERECE pTechPref;
PQMIWDS_AUTH_PREFERENCE pAuthPref;
PQMIWDS_USERNAME pUserName;
PQMIWDS_PASSWD pPasswd;
PQMIWDS_APNNAME pApnName;
PQMIWDS_IP_FAMILY_TLV pIpFamily;
USHORT TLVLength = 0;
UCHAR *pTLV;
PROFILE_T *profile = (PROFILE_T *)arg;
const char *profile_user = profile->user;
const char *profile_password = profile->password;
int profile_auth = profile->auth;
if (s_is_cdma && (profile_user == NULL || profile_user[0] == '\0') && (profile_password == NULL || profile_password[0] == '\0')) {
profile_user = "[email protected]";
profile_password = "vnet.mobi";
profile_auth = 2; //chap
}
pTLV = (UCHAR *)(&pMUXMsg->StartNwInterfaceReq + 1);
pMUXMsg->StartNwInterfaceReq.Length = 0;
// Set technology Preferece
pTechPref = (PQMIWDS_TECHNOLOGY_PREFERECE)(pTLV + TLVLength);
pTechPref->TLVType = 0x30;
pTechPref->TLVLength = cpu_to_le16(0x01);
if (s_is_cdma == 0)
pTechPref->TechPreference = 0x01;
else
pTechPref->TechPreference = 0x02;
TLVLength +=(le16_to_cpu(pTechPref->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
// Set APN Name
if (profile->apn && !s_is_cdma) { //cdma no apn
pApnName = (PQMIWDS_APNNAME)(pTLV + TLVLength);
pApnName->TLVType = 0x14;
pApnName->TLVLength = cpu_to_le16(strlen(profile->apn));
qstrcpy((char *)&pApnName->ApnName, profile->apn);
TLVLength +=(le16_to_cpu(pApnName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Set User Name
if (profile_user) {
pUserName = (PQMIWDS_USERNAME)(pTLV + TLVLength);
pUserName->TLVType = 0x17;
pUserName->TLVLength = cpu_to_le16(strlen(profile_user));
qstrcpy((char *)&pUserName->UserName, profile_user);
TLVLength += (le16_to_cpu(pUserName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Set Password
if (profile_password) {
pPasswd = (PQMIWDS_PASSWD)(pTLV + TLVLength);
pPasswd->TLVType = 0x18;
pPasswd->TLVLength = cpu_to_le16(strlen(profile_password));
qstrcpy((char *)&pPasswd->Passwd, profile_password);
TLVLength += (le16_to_cpu(pPasswd->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Set Auth Protocol
if (profile_user && profile_password) {
pAuthPref = (PQMIWDS_AUTH_PREFERENCE)(pTLV + TLVLength);
pAuthPref->TLVType = 0x16;
pAuthPref->TLVLength = cpu_to_le16(0x01);
pAuthPref->AuthPreference = profile_auth; // 0 ~ None, 1 ~ Pap, 2 ~ Chap, 3 ~ MsChapV2
TLVLength += (le16_to_cpu(pAuthPref->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Add IP Family Preference
pIpFamily = (PQMIWDS_IP_FAMILY_TLV)(pTLV + TLVLength);
pIpFamily->TLVType = 0x19;
pIpFamily->TLVLength = cpu_to_le16(0x01);
pIpFamily->IpFamily = profile->curIpFamily;
TLVLength += (le16_to_cpu(pIpFamily->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
//Set Profile Index
if (profile->pdp && !s_is_cdma) { //cdma only support one pdp, so no need to set profile index
PQMIWDS_PROFILE_IDENTIFIER pProfileIndex = (PQMIWDS_PROFILE_IDENTIFIER)(pTLV + TLVLength);
pProfileIndex->TLVLength = cpu_to_le16(0x01);
pProfileIndex->TLVType = 0x31;
pProfileIndex->ProfileIndex = profile->pdp;
if (s_is_cdma && s_hdr_personality == 0x02) {
pProfileIndex->TLVType = 0x32; //profile_index_3gpp2
pProfileIndex->ProfileIndex = 101;
}
TLVLength += (le16_to_cpu(pProfileIndex->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
return sizeof(QMIWDS_START_NETWORK_INTERFACE_REQ_MSG) + TLVLength;
}
static USHORT WdsStopNwInterfaceReq(PQMUX_MSG pMUXMsg, void *arg) {
pMUXMsg->StopNwInterfaceReq.TLVType = 0x01;
pMUXMsg->StopNwInterfaceReq.TLVLength = cpu_to_le16(0x04);
if (*((int *)arg) == IpFamilyV4)
pMUXMsg->StopNwInterfaceReq.Handle = cpu_to_le32(WdsConnectionIPv4Handle);
else
pMUXMsg->StopNwInterfaceReq.Handle = cpu_to_le32(WdsConnectionIPv6Handle);
return sizeof(QMIWDS_STOP_NETWORK_INTERFACE_REQ_MSG);
}
static USHORT WdsSetClientIPFamilyPref(PQMUX_MSG pMUXMsg, void *arg) {
pMUXMsg->SetClientIpFamilyPrefReq.TLVType = 0x01;
pMUXMsg->SetClientIpFamilyPrefReq.TLVLength = cpu_to_le16(0x01);
pMUXMsg->SetClientIpFamilyPrefReq.IpPreference = *((UCHAR *)arg);
return sizeof(QMIWDS_SET_CLIENT_IP_FAMILY_PREF_REQ_MSG);
}
static USHORT WdsSetAutoConnect(PQMUX_MSG pMUXMsg, void *arg) {
pMUXMsg->SetAutoConnectReq.TLVType = 0x01;
pMUXMsg->SetAutoConnectReq.TLVLength = cpu_to_le16(0x01);
pMUXMsg->SetAutoConnectReq.autoconnect_setting = *((UCHAR *)arg);
return sizeof(QMIWDS_SET_AUTO_CONNECT_REQ_MSG);
}
enum peripheral_ep_type {
DATA_EP_TYPE_RESERVED = 0x0,
DATA_EP_TYPE_HSIC = 0x1,
DATA_EP_TYPE_HSUSB = 0x2,
DATA_EP_TYPE_PCIE = 0x3,
DATA_EP_TYPE_EMBEDDED = 0x4,
DATA_EP_TYPE_BAM_DMUX = 0x5,
};
static USHORT WdsSetQMUXBindMuxDataPort(PQMUX_MSG pMUXMsg, void *arg) {
QMAP_SETTING *qmap_settings = (QMAP_SETTING *)arg;
pMUXMsg->BindMuxDataPortReq.TLVType = 0x10;
pMUXMsg->BindMuxDataPortReq.TLVLength = cpu_to_le16(0x08);
pMUXMsg->BindMuxDataPortReq.ep_type = cpu_to_le32(qmap_settings->ep_type);
pMUXMsg->BindMuxDataPortReq.iface_id = cpu_to_le32(qmap_settings->iface_id);
pMUXMsg->BindMuxDataPortReq.TLV2Type = 0x11;
pMUXMsg->BindMuxDataPortReq.TLV2Length = cpu_to_le16(0x01);
pMUXMsg->BindMuxDataPortReq.MuxId = qmap_settings->MuxId;
pMUXMsg->BindMuxDataPortReq.TLV3Type = 0x13;
pMUXMsg->BindMuxDataPortReq.TLV3Length = cpu_to_le16(0x04);
pMUXMsg->BindMuxDataPortReq.client_type = cpu_to_le32(1); //WDS_CLIENT_TYPE_TETHERED
return sizeof(QMIWDS_BIND_MUX_DATA_PORT_REQ_MSG);
}
static int qmap_version = 0x05;
static USHORT WdaSetDataFormat(PQMUX_MSG pMUXMsg, void *arg) {
QMAP_SETTING *qmap_settings = (QMAP_SETTING *)arg;
if (qmap_settings->rx_urb_size == 0) {
PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV_QOS pWdsAdminQosTlv;
PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV linkProto;
PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV dlTlp;
pWdsAdminQosTlv = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV_QOS)(&pMUXMsg->QMUXMsgHdr + 1);
pWdsAdminQosTlv->TLVType = 0x10;
pWdsAdminQosTlv->TLVLength = cpu_to_le16(0x0001);
pWdsAdminQosTlv->QOSSetting = 0; /* no-QOS header */
linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)(pWdsAdminQosTlv + 1);
linkProto->TLVType = 0x11;
linkProto->TLVLength = cpu_to_le16(4);
linkProto->Value = cpu_to_le32(0x01); /* Set Ethernet mode */
dlTlp = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)(linkProto + 1);;
dlTlp->TLVType = 0x13;
dlTlp->TLVLength = cpu_to_le16(4);
dlTlp->Value = cpu_to_le32(0x00);
if (sizeof(*linkProto) != 7 )
dbg_time("%s sizeof(*linkProto) = %zu, is not 7!", __func__, sizeof(*linkProto) );
return sizeof(QCQMUX_MSG_HDR) + sizeof(*pWdsAdminQosTlv) + sizeof(*linkProto) + sizeof(*dlTlp);
}
else {
//Indicates whether the Quality of Service(QOS) data format is used by the client.
pMUXMsg->SetDataFormatReq.QosDataFormatTlv.TLVType = 0x10;
pMUXMsg->SetDataFormatReq.QosDataFormatTlv.TLVLength = cpu_to_le16(0x0001);
pMUXMsg->SetDataFormatReq.QosDataFormatTlv.QOSSetting = 0; /* no-QOS header */
//Underlying Link Layer Protocol
pMUXMsg->SetDataFormatReq.UnderlyingLinkLayerProtocolTlv.TLVType = 0x11;
pMUXMsg->SetDataFormatReq.UnderlyingLinkLayerProtocolTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.UnderlyingLinkLayerProtocolTlv.Value = cpu_to_le32(0x02); /* Set IP mode */
//Uplink (UL) data aggregation protocol to be used for uplink data transfer.
pMUXMsg->SetDataFormatReq.UplinkDataAggregationProtocolTlv.TLVType = 0x12;
pMUXMsg->SetDataFormatReq.UplinkDataAggregationProtocolTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.UplinkDataAggregationProtocolTlv.Value = cpu_to_le32(qmap_version); //UL QMAP is enabled
//Downlink (DL) data aggregation protocol to be used for downlink data transfer
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationProtocolTlv.TLVType = 0x13;
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationProtocolTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationProtocolTlv.Value = cpu_to_le32(qmap_version); //DL QMAP is enabled
//Maximum number of datagrams in a single aggregated packet on downlink
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxDatagramsTlv.TLVType = 0x15;
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxDatagramsTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxDatagramsTlv.Value = cpu_to_le32(qmap_settings->rx_urb_size/512);
//Maximum size in bytes of a single aggregated packet allowed on downlink
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxSizeTlv.TLVType = 0x16;
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxSizeTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.DownlinkDataAggregationMaxSizeTlv.Value = cpu_to_le32(qmap_settings->rx_urb_size);
//Peripheral End Point ID
pMUXMsg->SetDataFormatReq.epTlv.TLVType = 0x17;
pMUXMsg->SetDataFormatReq.epTlv.TLVLength = cpu_to_le16(8);
pMUXMsg->SetDataFormatReq.epTlv.ep_type = cpu_to_le32(qmap_settings->ep_type);
pMUXMsg->SetDataFormatReq.epTlv.iface_id = cpu_to_le32(qmap_settings->iface_id);
#ifdef QUECTEL_UL_DATA_AGG
if (!qmap_settings->ul_data_aggregation_max_datagrams) {
return ((size_t)&((QMIWDS_ADMIN_SET_DATA_FORMAT_REQ_MSG *)0)->DlMinimumPassingTlv);
}
//Maximum number of datagrams in a single aggregated packet on uplink
pMUXMsg->SetDataFormatReq.DlMinimumPassingTlv.TLVType = 0x19;
pMUXMsg->SetDataFormatReq.DlMinimumPassingTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.DlMinimumPassingTlv.Value = cpu_to_le32(qmap_settings->dl_minimum_padding);
//Maximum number of datagrams in a single aggregated packet on uplink
pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxDatagramsTlv.TLVType = 0x1B;
pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxDatagramsTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxDatagramsTlv.Value = cpu_to_le32(qmap_settings->ul_data_aggregation_max_datagrams);
//Maximum size in bytes of a single aggregated packet allowed on downlink
pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxSizeTlv.TLVType = 0x1C;
pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxSizeTlv.TLVLength = cpu_to_le16(4);
pMUXMsg->SetDataFormatReq.UplinkDataAggregationMaxSizeTlv.Value = cpu_to_le32(qmap_settings->ul_data_aggregation_max_size);
#endif
return sizeof(QMIWDS_ADMIN_SET_DATA_FORMAT_REQ_MSG);
}
}
#ifdef CONFIG_SIM
static USHORT DmsUIMVerifyPinReqSend(PQMUX_MSG pMUXMsg, void *arg) {
pMUXMsg->UIMVerifyPinReq.TLVType = 0x01;
pMUXMsg->UIMVerifyPinReq.PINID = 0x01; //Pin1, not Puk
pMUXMsg->UIMVerifyPinReq.PINLen = strlen((const char *)arg);
qstrcpy((char *)&pMUXMsg->UIMVerifyPinReq.PINValue, ((const char *)arg));
pMUXMsg->UIMVerifyPinReq.TLVLength = cpu_to_le16(2 + strlen((const char *)arg));
return sizeof(QMIDMS_UIM_VERIFY_PIN_REQ_MSG) + (strlen((const char *)arg) - 1);
}
static USHORT UimVerifyPinReqSend(PQMUX_MSG pMUXMsg, void *arg)
{
pMUXMsg->UIMUIMVerifyPinReq.TLVType = 0x01;
pMUXMsg->UIMUIMVerifyPinReq.TLVLength = cpu_to_le16(0x02);
pMUXMsg->UIMUIMVerifyPinReq.Session_Type = 0x00;
pMUXMsg->UIMUIMVerifyPinReq.Aid_Len = 0x00;
pMUXMsg->UIMUIMVerifyPinReq.TLV2Type = 0x02;
pMUXMsg->UIMUIMVerifyPinReq.TLV2Length = cpu_to_le16(2 + strlen((const char *)arg));
pMUXMsg->UIMUIMVerifyPinReq.PINID = 0x01; //Pin1, not Puk
pMUXMsg->UIMUIMVerifyPinReq.PINLen= strlen((const char *)arg);
qstrcpy((char *)&pMUXMsg->UIMUIMVerifyPinReq.PINValue, ((const char *)arg));
return sizeof(QMIUIM_VERIFY_PIN_REQ_MSG) + (strlen((const char *)arg) - 1);
}
#ifdef CONFIG_IMSI_ICCID
static USHORT UimReadTransparentIMSIReqSend(PQMUX_MSG pMUXMsg, void *arg) {
PREAD_TRANSPARENT_TLV pReadTransparent;
pMUXMsg->UIMUIMReadTransparentReq.TLVType = 0x01;
pMUXMsg->UIMUIMReadTransparentReq.TLVLength = cpu_to_le16(0x02);
if (!strcmp((char *)arg, "EF_ICCID")) {
pMUXMsg->UIMUIMReadTransparentReq.Session_Type = 0x06;
pMUXMsg->UIMUIMReadTransparentReq.Aid_Len = 0x00;
pMUXMsg->UIMUIMReadTransparentReq.TLV2Type = 0x02;
pMUXMsg->UIMUIMReadTransparentReq.file_id = cpu_to_le16(0x2FE2);
pMUXMsg->UIMUIMReadTransparentReq.path_len = 0x02;
pMUXMsg->UIMUIMReadTransparentReq.path[0] = 0x00;
pMUXMsg->UIMUIMReadTransparentReq.path[1] = 0x3F;
}
else if(!strcmp((char *)arg, "EF_IMSI")) {
pMUXMsg->UIMUIMReadTransparentReq.Session_Type = 0x00;
pMUXMsg->UIMUIMReadTransparentReq.Aid_Len = 0x00;
pMUXMsg->UIMUIMReadTransparentReq.TLV2Type = 0x02;
pMUXMsg->UIMUIMReadTransparentReq.file_id = cpu_to_le16(0x6F07);
pMUXMsg->UIMUIMReadTransparentReq.path_len = 0x04;
pMUXMsg->UIMUIMReadTransparentReq.path[0] = 0x00;
pMUXMsg->UIMUIMReadTransparentReq.path[1] = 0x3F;
pMUXMsg->UIMUIMReadTransparentReq.path[2] = 0xFF;
pMUXMsg->UIMUIMReadTransparentReq.path[3] = 0x7F;
}
pMUXMsg->UIMUIMReadTransparentReq.TLV2Length = cpu_to_le16(3 + pMUXMsg->UIMUIMReadTransparentReq.path_len);
pReadTransparent = (PREAD_TRANSPARENT_TLV)(&pMUXMsg->UIMUIMReadTransparentReq.path[pMUXMsg->UIMUIMReadTransparentReq.path_len]);
pReadTransparent->TLVType = 0x03;
pReadTransparent->TLVLength = cpu_to_le16(0x04);
pReadTransparent->Offset = cpu_to_le16(0x00);
pReadTransparent->Length = cpu_to_le16(0x00);
return (sizeof(QMIUIM_READ_TRANSPARENT_REQ_MSG) + pMUXMsg->UIMUIMReadTransparentReq.path_len + sizeof(READ_TRANSPARENT_TLV));
}
#endif
#endif
#ifdef CONFIG_APN
static USHORT WdsCreateProfileSettingsReqSend(PQMUX_MSG pMUXMsg, void *arg) {
PROFILE_T *profile = (PROFILE_T *)arg;
pMUXMsg->CreatetProfileSettingsReq.Length = cpu_to_le16(sizeof(QMIWDS_CREATE_PROFILE_SETTINGS_REQ_MSG) - 4);
pMUXMsg->CreatetProfileSettingsReq.TLVType = 0x01;
pMUXMsg->CreatetProfileSettingsReq.TLVLength = cpu_to_le16(0x01);
pMUXMsg->CreatetProfileSettingsReq.ProfileType = 0x00; // 0 ~ 3GPP, 1 ~ 3GPP2
pMUXMsg->CreatetProfileSettingsReq.TLV2Type = 0x25;
pMUXMsg->CreatetProfileSettingsReq.TLV2Length = cpu_to_le16(0x01);
pMUXMsg->CreatetProfileSettingsReq.pdp_context = profile->pdp; // 0 ~ 3GPP, 1 ~ 3GPP2
return sizeof(QMIWDS_CREATE_PROFILE_SETTINGS_REQ_MSG);
}
static USHORT WdsGetProfileSettingsReqSend(PQMUX_MSG pMUXMsg, void *arg) {
PROFILE_T *profile = (PROFILE_T *)arg;
pMUXMsg->GetProfileSettingsReq.Length = cpu_to_le16(sizeof(QMIWDS_GET_PROFILE_SETTINGS_REQ_MSG) - 4);
pMUXMsg->GetProfileSettingsReq.TLVType = 0x01;
pMUXMsg->GetProfileSettingsReq.TLVLength = cpu_to_le16(0x02);
pMUXMsg->GetProfileSettingsReq.ProfileType = 0x00; // 0 ~ 3GPP, 1 ~ 3GPP2
pMUXMsg->GetProfileSettingsReq.ProfileIndex = profile->pdp;
return sizeof(QMIWDS_GET_PROFILE_SETTINGS_REQ_MSG);
}
static USHORT WdsModifyProfileSettingsReq(PQMUX_MSG pMUXMsg, void *arg) {
USHORT TLVLength = 0;
UCHAR *pTLV;
PROFILE_T *profile = (PROFILE_T *)arg;
PQMIWDS_PDPTYPE pPdpType;
pMUXMsg->ModifyProfileSettingsReq.Length = cpu_to_le16(sizeof(QMIWDS_MODIFY_PROFILE_SETTINGS_REQ_MSG) - 4);
pMUXMsg->ModifyProfileSettingsReq.TLVType = 0x01;
pMUXMsg->ModifyProfileSettingsReq.TLVLength = cpu_to_le16(0x02);
pMUXMsg->ModifyProfileSettingsReq.ProfileType = 0x00; // 0 ~ 3GPP, 1 ~ 3GPP2
pMUXMsg->ModifyProfileSettingsReq.ProfileIndex = profile->pdp;
pTLV = (UCHAR *)(&pMUXMsg->ModifyProfileSettingsReq + 1);
pPdpType = (PQMIWDS_PDPTYPE)(pTLV + TLVLength);
pPdpType->TLVType = 0x11;
pPdpType->TLVLength = cpu_to_le16(0x01);
pPdpType->PdpType = profile->iptype;
TLVLength +=(le16_to_cpu(pPdpType->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
// Set APN Name
if (profile->apn) {
PQMIWDS_APNNAME pApnName = (PQMIWDS_APNNAME)(pTLV + TLVLength);
pApnName->TLVType = 0x14;
pApnName->TLVLength = cpu_to_le16(strlen(profile->apn));
qstrcpy((char *)&pApnName->ApnName, profile->apn);
TLVLength +=(le16_to_cpu(pApnName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Set User Name
if (profile->user) {
PQMIWDS_USERNAME pUserName = (PQMIWDS_USERNAME)(pTLV + TLVLength);
pUserName->TLVType = 0x1B;
pUserName->TLVLength = cpu_to_le16(strlen(profile->user));
qstrcpy((char *)&pUserName->UserName, profile->user);
TLVLength += (le16_to_cpu(pUserName->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Set Password
if (profile->password) {
PQMIWDS_PASSWD pPasswd = (PQMIWDS_PASSWD)(pTLV + TLVLength);
pPasswd->TLVType = 0x1C;
pPasswd->TLVLength = cpu_to_le16(strlen(profile->password));
qstrcpy((char *)&pPasswd->Passwd, profile->password);
TLVLength +=(le16_to_cpu(pPasswd->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
// Set Auth Protocol
if (profile->user && profile->password) {
PQMIWDS_AUTH_PREFERENCE pAuthPref = (PQMIWDS_AUTH_PREFERENCE)(pTLV + TLVLength);
pAuthPref->TLVType = 0x1D;
pAuthPref->TLVLength = cpu_to_le16(0x01);
pAuthPref->AuthPreference = profile->auth; // 0 ~ None, 1 ~ Pap, 2 ~ Chap, 3 ~ MsChapV2
TLVLength += (le16_to_cpu(pAuthPref->TLVLength) + sizeof(QCQMICTL_TLV_HDR));
}
return sizeof(QMIWDS_MODIFY_PROFILE_SETTINGS_REQ_MSG) + TLVLength;
}
#endif
static USHORT WdsGetRuntimeSettingReq(PQMUX_MSG pMUXMsg, void *arg)
{
(void)arg;
pMUXMsg->GetRuntimeSettingsReq.TLVType = 0x10;
pMUXMsg->GetRuntimeSettingsReq.TLVLength = cpu_to_le16(0x04);
// the following mask also applies to IPV6
pMUXMsg->GetRuntimeSettingsReq.Mask = cpu_to_le32(QMIWDS_GET_RUNTIME_SETTINGS_MASK_IPV4DNS_ADDR |
QMIWDS_GET_RUNTIME_SETTINGS_MASK_IPV4_ADDR |
QMIWDS_GET_RUNTIME_SETTINGS_MASK_MTU |
QMIWDS_GET_RUNTIME_SETTINGS_MASK_IPV4GATEWAY_ADDR) |
QMIWDS_GET_RUNTIME_SETTINGS_MASK_PCSCF_SV_ADDR |
QMIWDS_GET_RUNTIME_SETTINGS_MASK_PCSCF_DOM_NAME;
return sizeof(QMIWDS_GET_RUNTIME_SETTINGS_REQ_MSG);
}
static PQCQMIMSG s_pRequest;
static PQCQMIMSG s_pResponse;
static int is_response(const PQCQMIMSG pRequest, const PQCQMIMSG pResponse) {
if ((pRequest->QMIHdr.QMIType == pResponse->QMIHdr.QMIType)
&& (pRequest->QMIHdr.ClientId == pResponse->QMIHdr.ClientId)) {
USHORT requestTID, responseTID;
if (pRequest->QMIHdr.QMIType == QMUX_TYPE_CTL) {
requestTID = pRequest->CTLMsg.QMICTLMsgHdr.TransactionId;
responseTID = pResponse->CTLMsg.QMICTLMsgHdr.TransactionId;
} else {
requestTID = le16_to_cpu(pRequest->MUXMsg.QMUXHdr.TransactionId);
responseTID = le16_to_cpu(pResponse->MUXMsg.QMUXHdr.TransactionId);
}
return (requestTID == responseTID);
}
return 0;
}
int (*qmidev_send)(PQCQMIMSG pRequest);
int QmiThreadSendQMITimeout(PQCQMIMSG pRequest, PQCQMIMSG *ppResponse, unsigned msecs, const char *funcname) {
int ret;
if (!pRequest)
return -EINVAL;
pthread_mutex_lock(&cm_command_mutex);
if (ppResponse)
*ppResponse = NULL;
dump_qmi(pRequest, le16_to_cpu(pRequest->QMIHdr.Length) + 1);
s_pRequest = pRequest;
s_pResponse = NULL;
ret = qmidev_send(pRequest);
if (ret == 0) {
ret = pthread_cond_timeout_np(&cm_command_cond, &cm_command_mutex, msecs);
if (!ret) {
if (s_pResponse && ppResponse) {
*ppResponse = s_pResponse;
} else {
if (s_pResponse) {
free(s_pResponse);
s_pResponse = NULL;
}
}
} else {
dbg_time("%s message timeout", funcname);
}
}
pthread_mutex_unlock(&cm_command_mutex);
return ret;
}
void QmiThreadRecvQMI(PQCQMIMSG pResponse) {
pthread_mutex_lock(&cm_command_mutex);
if (pResponse == NULL) {
if (s_pRequest) {
free(s_pRequest);
s_pRequest = NULL;
s_pResponse = NULL;
pthread_cond_signal(&cm_command_cond);
}
pthread_mutex_unlock(&cm_command_mutex);
return;
}
dump_qmi(pResponse, le16_to_cpu(pResponse->QMIHdr.Length) + 1);
if (s_pRequest && is_response(s_pRequest, pResponse)) {
free(s_pRequest);
s_pRequest = NULL;
s_pResponse = malloc(le16_to_cpu(pResponse->QMIHdr.Length) + 1);
if (s_pResponse != NULL) {
memcpy(s_pResponse, pResponse, le16_to_cpu(pResponse->QMIHdr.Length) + 1);
}
pthread_cond_signal(&cm_command_cond);
} else if ((pResponse->QMIHdr.QMIType == QMUX_TYPE_CTL)
&& (le16_to_cpu(pResponse->CTLMsg.QMICTLMsgHdrRsp.QMICTLType == QMICTL_REVOKE_CLIENT_ID_IND))) {
qmidevice_send_event_to_main(MODEM_REPORT_RESET_EVENT);
} else if ((pResponse->QMIHdr.QMIType == QMUX_TYPE_NAS)
&& (le16_to_cpu(pResponse->MUXMsg.QMUXMsgHdrResp.Type) == QMINAS_SERVING_SYSTEM_IND)) {
qmidevice_send_event_to_main(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED);
} else if ((pResponse->QMIHdr.QMIType == QMUX_TYPE_WDS)
&& (le16_to_cpu(pResponse->MUXMsg.QMUXMsgHdrResp.Type) == QMIWDS_GET_PKT_SRVC_STATUS_IND)) {
qmidevice_send_event_to_main(RIL_UNSOL_DATA_CALL_LIST_CHANGED);
} else if ((pResponse->QMIHdr.QMIType == QMUX_TYPE_NAS)
&& (le16_to_cpu(pResponse->MUXMsg.QMUXMsgHdrResp.Type) == QMINAS_SYS_INFO_IND)) {
qmidevice_send_event_to_main(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED);
} else if ((pResponse->QMIHdr.QMIType == QMUX_TYPE_WDS_ADMIN)
&& (le16_to_cpu(pResponse->MUXMsg.QMUXMsgHdrResp.Type) == QMI_WDA_SET_LOOPBACK_CONFIG_IND)) {
qmidevice_send_event_to_main_ext(RIL_UNSOL_LOOPBACK_CONFIG_IND,
&pResponse->MUXMsg.SetLoopBackInd, sizeof(pResponse->MUXMsg.SetLoopBackInd));
} else {
if (debug_qmi)
dbg_time("nobody care this qmi msg!!");
}
pthread_mutex_unlock(&cm_command_mutex);
}
static int requestSetEthMode(PROFILE_T *profile) {
PQCQMIMSG pRequest;
PQCQMIMSG pResponse = NULL;
PQMUX_MSG pMUXMsg;
int err;
PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV linkProto;
UCHAR IpPreference;
UCHAR autoconnect_setting = 0;
QMAP_SETTING qmap_settings = {0};
qmap_settings.size = sizeof(qmap_settings);
if (profile->qmap_mode) {
profile->rawIP = 1;
s_9x07 = profile->rawIP;
qmap_settings.MuxId = profile->muxid;
if (profile->hardware_interface == HARDWARE_PCIE) { //SDX20_PCIE
qmap_settings.rx_urb_size = profile->qmap_size; //SDX24&SDX55 support 32KB
qmap_settings.ep_type = DATA_EP_TYPE_PCIE;
qmap_settings.iface_id = 0x04;
}
else { // for MDM9x07&MDM9x40&SDX20 USB
qmap_settings.rx_urb_size = profile->qmap_size; //SDX24&SDX55 support 32KB
qmap_settings.ep_type = DATA_EP_TYPE_HSUSB;
qmap_settings.iface_id = 0x04;
}
qmap_settings.ul_data_aggregation_max_datagrams = 11; //by test result, 11 can get best TPUT
qmap_settings.ul_data_aggregation_max_size = 8*1024;
qmap_settings.dl_minimum_padding = 0; //no effect when register to real netowrk
if(profile->qmap_version != 0x09)
profile->qmap_version = 0x05;
qmap_version = profile->qmap_version;
if (profile->rmnet_info.size) {
qmap_settings.rx_urb_size = profile->rmnet_info.rx_urb_size;
qmap_settings.ep_type = profile->rmnet_info.ep_type;
qmap_settings.iface_id = profile->rmnet_info.iface_id;
qmap_settings.dl_minimum_padding = profile->rmnet_info.dl_minimum_padding;
qmap_version = profile->rmnet_info.qmap_version;
}
if (!profile->wda_client) {
if (qmidev_is_gobinet(profile->qmichannel)) {
//when QMAP enabled, set data format in GobiNet driver
}
else if (profile->proxy[0]) {
/* the first running 'quectel-cm' had alloc wda client and set data format,
so we can ingore to set data format here. */
}
goto skip_WdaSetDataFormat;
}
}
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS_ADMIN, QMIWDS_ADMIN_SET_DATA_FORMAT_REQ, WdaSetDataFormat, (void *)&qmap_settings);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x11);
if (linkProto != NULL) {
profile->rawIP = (le32_to_cpu(linkProto->Value) == 2);
s_9x07 = profile->rawIP; //MDM90x7 only support RAW IP, do not support Eth
}
linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x16);
if (linkProto != NULL && profile->qmap_mode) {
qmap_settings.rx_urb_size = le32_to_cpu(linkProto->Value);
dbg_time("qmap_settings.rx_urb_size = %u", qmap_settings.rx_urb_size); //must same as rx_urb_size defined in GobiNet&qmi_wwan driver
}
#ifdef QUECTEL_UL_DATA_AGG
if (qmap_settings.ul_data_aggregation_max_datagrams)
{
linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x17);
if (linkProto != NULL) {
qmap_settings.ul_data_aggregation_max_datagrams = MIN(qmap_settings.ul_data_aggregation_max_datagrams, le32_to_cpu(linkProto->Value));
dbg_time("qmap_settings.ul_data_aggregation_max_datagrams = %u", qmap_settings.ul_data_aggregation_max_datagrams);
}
linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x18);
if (linkProto != NULL) {
qmap_settings.ul_data_aggregation_max_size = MIN(qmap_settings.ul_data_aggregation_max_size, le32_to_cpu(linkProto->Value));
dbg_time("qmap_settings.ul_data_aggregation_max_size = %u", qmap_settings.ul_data_aggregation_max_size);
}
linkProto = (PQMIWDS_ADMIN_SET_DATA_FORMAT_TLV)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x1A);
if (linkProto != NULL) {
qmap_settings.dl_minimum_padding = le32_to_cpu(linkProto->Value);
dbg_time("qmap_settings.dl_minimum_padding = %u", qmap_settings.dl_minimum_padding);
}
if (qmap_settings.ul_data_aggregation_max_datagrams > 1) {
ql_set_driver_qmap_setting(profile, &qmap_settings);
}
}
#endif
free(pResponse);
skip_WdaSetDataFormat:
if (profile->enable_ipv4) {
if (profile->qmapnet_adapter[0]) {
// bind wds mux data port
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_BIND_MUX_DATA_PORT_REQ , WdsSetQMUXBindMuxDataPort, (void *)&qmap_settings);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
if (pResponse) free(pResponse);
}
// set ipv4
IpPreference = IpFamilyV4;
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_SET_CLIENT_IP_FAMILY_PREF_REQ, WdsSetClientIPFamilyPref, (void *)&IpPreference);
err = QmiThreadSendQMI(pRequest, &pResponse);
if (pResponse) free(pResponse);
}
if (profile->enable_ipv6) {
if (profile->qmapnet_adapter[0]) {
// bind wds ipv6 mux data port
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS_IPV6, QMIWDS_BIND_MUX_DATA_PORT_REQ , WdsSetQMUXBindMuxDataPort, (void *)&qmap_settings);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
if (pResponse) free(pResponse);
}
// set ipv6
IpPreference = IpFamilyV6;
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS_IPV6, QMIWDS_SET_CLIENT_IP_FAMILY_PREF_REQ, WdsSetClientIPFamilyPref, (void *)&IpPreference);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
if (pResponse) free(pResponse);
}
pRequest = ComposeQMUXMsg(QMUX_TYPE_WDS, QMIWDS_SET_AUTO_CONNECT_REQ , WdsSetAutoConnect, (void *)&autoconnect_setting);
QmiThreadSendQMI(pRequest, &pResponse);
if (pResponse) free(pResponse);
return 0;
}
#ifdef CONFIG_SIM
static int requestGetPINStatus(SIM_Status *pSIMStatus) {
PQCQMIMSG pRequest;
PQCQMIMSG pResponse;
PQMUX_MSG pMUXMsg;
int err;
PQMIDMS_UIM_PIN_STATUS pPin1Status = NULL;
//PQMIDMS_UIM_PIN_STATUS pPin2Status = NULL;
if (s_9x07)
pRequest = ComposeQMUXMsg(QMUX_TYPE_UIM, QMIUIM_GET_CARD_STATUS_REQ, NULL, NULL);
else
pRequest = ComposeQMUXMsg(QMUX_TYPE_DMS, QMIDMS_UIM_GET_PIN_STATUS_REQ, NULL, NULL);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
pPin1Status = (PQMIDMS_UIM_PIN_STATUS)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x11);
//pPin2Status = (PQMIDMS_UIM_PIN_STATUS)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x12);
if (pPin1Status != NULL) {
if (pPin1Status->PINStatus == QMI_PIN_STATUS_NOT_VERIF) {
*pSIMStatus = SIM_PIN;
} else if (pPin1Status->PINStatus == QMI_PIN_STATUS_BLOCKED) {
*pSIMStatus = SIM_PUK;
} else if (pPin1Status->PINStatus == QMI_PIN_STATUS_PERM_BLOCKED) {
*pSIMStatus = SIM_BAD;
}
}
free(pResponse);
return 0;
}
static int requestGetSIMStatus(SIM_Status *pSIMStatus) { //RIL_REQUEST_GET_SIM_STATUS
PQCQMIMSG pRequest;
PQCQMIMSG pResponse;
PQMUX_MSG pMUXMsg;
int err;
const char * SIM_Status_String[] = {
"SIM_ABSENT",
"SIM_NOT_READY",
"SIM_READY", /* SIM_READY means the radio state is RADIO_STATE_SIM_READY */
"SIM_PIN",
"SIM_PUK",
"SIM_NETWORK_PERSONALIZATION"
};
if (s_9x07)
pRequest = ComposeQMUXMsg(QMUX_TYPE_UIM, QMIUIM_GET_CARD_STATUS_REQ, NULL, NULL);
else
pRequest = ComposeQMUXMsg(QMUX_TYPE_DMS, QMIDMS_UIM_GET_STATE_REQ, NULL, NULL);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
*pSIMStatus = SIM_ABSENT;
if (s_9x07)
{
PQMIUIM_CARD_STATUS pCardStatus = NULL;
PQMIUIM_PIN_STATE pPINState = NULL;
UCHAR CardState = 0x01;
UCHAR PIN1State = QMI_PIN_STATUS_NOT_VERIF;
//UCHAR PIN1Retries;
//UCHAR PUK1Retries;
//UCHAR PIN2State;
//UCHAR PIN2Retries;
//UCHAR PUK2Retries;
pCardStatus = (PQMIUIM_CARD_STATUS)GetTLV(&pResponse->MUXMsg.QMUXMsgHdr, 0x10);
if (pCardStatus != NULL)
{
pPINState = (PQMIUIM_PIN_STATE)((PUCHAR)pCardStatus + sizeof(QMIUIM_CARD_STATUS) + pCardStatus->AIDLength);
CardState = pCardStatus->CardState;
if (CardState == UIM_CARD_STATE_PRESENT) {
if (pPINState->UnivPIN == 1)
{
PIN1State = pCardStatus->UPINState;
//PIN1Retries = pCardStatus->UPINRetries;
//PUK1Retries = pCardStatus->UPUKRetries;
}
else
{
PIN1State = pPINState->PIN1State;
//PIN1Retries = pPINState->PIN1Retries;
//PUK1Retries = pPINState->PUK1Retries;
}
//PIN2State = pPINState->PIN2State;
//PIN2Retries = pPINState->PIN2Retries;
//PUK2Retries = pPINState->PUK2Retries;
}
}
*pSIMStatus = SIM_ABSENT;
if ((CardState == 0x01) && ((PIN1State == QMI_PIN_STATUS_VERIFIED)|| (PIN1State == QMI_PIN_STATUS_DISABLED)))
{
*pSIMStatus = SIM_READY;
}
else if (CardState == 0x01)
{
if (PIN1State == QMI_PIN_STATUS_NOT_VERIF)
{
*pSIMStatus = SIM_PIN;
}
if ( PIN1State == QMI_PIN_STATUS_BLOCKED)
{
*pSIMStatus = SIM_PUK;
}
else if (PIN1State == QMI_PIN_STATUS_PERM_BLOCKED)
{
*pSIMStatus = SIM_BAD;
}
else if (PIN1State == QMI_PIN_STATUS_NOT_INIT || PIN1State == QMI_PIN_STATUS_VERIFIED || PIN1State == QMI_PIN_STATUS_DISABLED)
{
*pSIMStatus = SIM_READY;
}
}
else if (CardState == 0x00 || CardState == 0x02)
{
}
else
{
}
}
else
{
//UIM state. Values:
// 0x00 UIM initialization completed
// 0x01 UIM is locked or the UIM failed
// 0x02 UIM is not present
// 0x03 Reserved
// 0xFF UIM state is currently
//unavailable
if (pResponse->MUXMsg.UIMGetStateResp.UIMState == 0x00) {
*pSIMStatus = SIM_READY;
} else if (pResponse->MUXMsg.UIMGetStateResp.UIMState == 0x01) {
*pSIMStatus = SIM_ABSENT;
err = requestGetPINStatus(pSIMStatus);
} else if ((pResponse->MUXMsg.UIMGetStateResp.UIMState == 0x02) || (pResponse->MUXMsg.UIMGetStateResp.UIMState == 0xFF)) {
*pSIMStatus = SIM_ABSENT;
} else {
*pSIMStatus = SIM_ABSENT;
}
}
dbg_time("%s SIMStatus: %s", __func__, SIM_Status_String[*pSIMStatus]);
free(pResponse);
return 0;
}
static int requestEnterSimPin(const char *pPinCode) {
PQCQMIMSG pRequest;
PQCQMIMSG pResponse;
PQMUX_MSG pMUXMsg;
int err;
if (s_9x07)
pRequest = ComposeQMUXMsg(QMUX_TYPE_UIM, QMIUIM_VERIFY_PIN_REQ, UimVerifyPinReqSend, (void *)pPinCode);
else
pRequest = ComposeQMUXMsg(QMUX_TYPE_DMS, QMIDMS_UIM_VERIFY_PIN_REQ, DmsUIMVerifyPinReqSend, (void *)pPinCode);
err = QmiThreadSendQMI(pRequest, &pResponse);
qmi_rsp_check_and_return();
free(pResponse);
return 0;
}
#endif
#ifdef CONFIG_IMSI_ICCID
static int requestGetICCID(void) { //RIL_REQUEST_GET_IMSI
PQCQMIMSG pRequest;
PQCQMIMSG pResponse;
PQMUX_MSG pMUXMsg;
PQMIUIM_CONTENT pUimContent;
int err;