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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
|
/*
* Copyright (c) 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
*/
#ifndef _F_GSI_H
#define _F_GSI_H
#include <linux/poll.h>
#include <linux/miscdevice.h>
#include <linux/ipa.h>
#include <uapi/linux/usb/cdc.h>
#include <linux/usb/ch9.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
#include <linux/usb/usb_ctrl_qti.h>
#include <linux/etherdevice.h>
#include <linux/debugfs.h>
#include <linux/ipa_usb.h>
#include <linux/usb/msm_hsusb.h>
#define GSI_RMNET_CTRL_NAME "rmnet_ctrl"
#define GSI_MBIM_CTRL_NAME "android_mbim"
#define GSI_DPL_CTRL_NAME "dpl_ctrl"
#define GSI_CTRL_NAME_LEN (sizeof(GSI_MBIM_CTRL_NAME)+2)
#define GSI_MAX_CTRL_PKT_SIZE 8192
#define GSI_CTRL_DTR (1 << 0)
#define GSI_NUM_IN_BUFFERS 15
#define GSI_IN_BUFF_SIZE 2048
#define GSI_NUM_OUT_BUFFERS 15
#define GSI_ECM_NUM_OUT_BUFFERS 31
#define GSI_OUT_AGGR_SIZE 24576
#define GSI_IN_RNDIS_AGGR_SIZE 9216
#define GSI_IN_MBIM_AGGR_SIZE 16384
#define GSI_IN_RMNET_AGGR_SIZE 16384
#define GSI_ECM_AGGR_SIZE 2048
#define GSI_OUT_MBIM_BUF_LEN 16384
#define GSI_OUT_RMNET_BUF_LEN 16384
#define GSI_OUT_ECM_BUF_LEN 2048
#define GSI_IPA_READY_TIMEOUT 5000
#define ETH_ADDR_STR_LEN 14
/* mbin and ecm */
#define GSI_CTRL_NOTIFY_BUFF_LEN 16
/* default max packets per tarnsfer value */
#define DEFAULT_MAX_PKT_PER_XFER 15
/* default pkt alignment factor */
#define DEFAULT_PKT_ALIGNMENT_FACTOR 4
#define GSI_MBIM_IOCTL_MAGIC 'o'
#define GSI_MBIM_GET_NTB_SIZE _IOR(GSI_MBIM_IOCTL_MAGIC, 2, u32)
#define GSI_MBIM_GET_DATAGRAM_COUNT _IOR(GSI_MBIM_IOCTL_MAGIC, 3, u16)
#define GSI_MBIM_EP_LOOKUP _IOR(GSI_MBIM_IOCTL_MAGIC, 4, struct ep_info)
#define GSI_MBIM_DATA_EP_TYPE_HSUSB 0x2
/* ID for Microsoft OS String */
#define GSI_MBIM_OS_STRING_ID 0xEE
#define EVT_NONE 0
#define EVT_UNINITIALIZED 1
#define EVT_INITIALIZED 2
#define EVT_CONNECT_IN_PROGRESS 3
#define EVT_CONNECTED 4
#define EVT_HOST_NRDY 5
#define EVT_HOST_READY 6
#define EVT_DISCONNECTED 7
#define EVT_SUSPEND 8
#define EVT_IPA_SUSPEND 9
#define EVT_RESUMED 10
enum connection_state {
STATE_UNINITIALIZED,
STATE_INITIALIZED,
STATE_CONNECT_IN_PROGRESS,
STATE_CONNECTED,
STATE_DISCONNECTED,
STATE_SUSPEND_IN_PROGRESS,
STATE_SUSPENDED
};
enum gsi_ctrl_notify_state {
GSI_CTRL_NOTIFY_NONE,
GSI_CTRL_NOTIFY_CONNECT,
GSI_CTRL_NOTIFY_SPEED,
GSI_CTRL_NOTIFY_OFFLINE,
GSI_CTRL_NOTIFY_RESPONSE_AVAILABLE,
};
#define MAXQUEUELEN 128
struct event_queue {
u8 event[MAXQUEUELEN];
u8 head, tail;
spinlock_t q_lock;
};
struct gsi_ntb_info {
u32 ntb_input_size;
u16 ntb_max_datagrams;
u16 reserved;
};
struct gsi_ctrl_pkt {
void *buf;
int len;
enum gsi_ctrl_notify_state type;
struct list_head list;
};
struct gsi_function_bind_info {
struct usb_string *string_defs;
int ctrl_str_idx;
int data_str_idx;
int iad_str_idx;
int mac_str_idx;
struct usb_interface_descriptor *ctrl_desc;
struct usb_interface_descriptor *data_desc;
struct usb_interface_assoc_descriptor *iad_desc;
struct usb_cdc_ether_desc *cdc_eth_desc;
struct usb_cdc_union_desc *union_desc;
struct usb_interface_descriptor *data_nop_desc;
struct usb_endpoint_descriptor *fs_in_desc;
struct usb_endpoint_descriptor *fs_out_desc;
struct usb_endpoint_descriptor *fs_notify_desc;
struct usb_endpoint_descriptor *hs_in_desc;
struct usb_endpoint_descriptor *hs_out_desc;
struct usb_endpoint_descriptor *hs_notify_desc;
struct usb_endpoint_descriptor *ss_in_desc;
struct usb_endpoint_descriptor *ss_out_desc;
struct usb_endpoint_descriptor *ss_notify_desc;
struct usb_descriptor_header **fs_desc_hdr;
struct usb_descriptor_header **hs_desc_hdr;
struct usb_descriptor_header **ss_desc_hdr;
const char *in_epname;
const char *out_epname;
u32 in_req_buf_len;
u32 in_req_num_buf;
u32 out_req_buf_len;
u32 out_req_num_buf;
u32 notify_buf_len;
};
struct gsi_ctrl_port {
char name[GSI_CTRL_NAME_LEN];
struct miscdevice ctrl_device;
struct usb_ep *notify;
struct usb_request *notify_req;
bool notify_req_queued;
atomic_t ctrl_online;
bool is_open;
wait_queue_head_t read_wq;
struct list_head cpkt_req_q;
struct list_head cpkt_resp_q;
unsigned long cpkts_len;
spinlock_t lock;
int ipa_cons_clnt_hdl;
int ipa_prod_clnt_hdl;
unsigned host_to_modem;
unsigned copied_to_modem;
unsigned copied_from_modem;
unsigned modem_to_host;
unsigned cpkt_drop_cnt;
unsigned get_encap_cnt;
};
struct gsi_data_port {
struct usb_ep *in_ep;
struct usb_ep *out_ep;
struct usb_gsi_request in_request;
struct usb_gsi_request out_request;
int (*ipa_usb_notify_cb)(enum ipa_usb_notify_event, void *driver_data);
struct ipa_usb_teth_params ipa_init_params;
int in_channel_handle;
int out_channel_handle;
u32 in_db_reg_phs_addr_lsb;
u32 in_db_reg_phs_addr_msb;
u32 out_db_reg_phs_addr_lsb;
u32 out_db_reg_phs_addr_msb;
u32 in_xfer_rsc_index;
u32 out_xfer_rsc_index;
u16 in_last_trb_addr;
u16 cdc_filter;
u32 in_aggr_size;
u32 out_aggr_size;
bool ipa_ready;
bool net_ready_trigger;
struct gsi_ntb_info ntb_info;
spinlock_t lock;
struct work_struct usb_ipa_w;
struct workqueue_struct *ipa_usb_wq;
enum connection_state sm_state;
struct event_queue evt_q;
wait_queue_head_t wait_for_ipa_ready;
/* Track these for debugfs */
struct ipa_usb_xdci_chan_params ipa_in_channel_params;
struct ipa_usb_xdci_chan_params ipa_out_channel_params;
struct ipa_usb_xdci_connect_params ipa_conn_pms;
};
struct f_gsi {
struct usb_function function;
struct usb_gadget *gadget;
enum ipa_usb_teth_prot prot_id;
int ctrl_id;
int data_id;
u32 vendorID;
u8 ethaddr[ETH_ADDR_STR_LEN];
const char *manufacturer;
struct rndis_params *params;
atomic_t connected;
bool data_interface_up;
bool rndis_use_wceis;
const struct usb_endpoint_descriptor *in_ep_desc_backup;
const struct usb_endpoint_descriptor *out_ep_desc_backup;
struct gsi_data_port d_port;
struct gsi_ctrl_port c_port;
};
static inline struct f_gsi *func_to_gsi(struct usb_function *f)
{
return container_of(f, struct f_gsi, function);
}
static inline struct f_gsi *d_port_to_gsi(struct gsi_data_port *d)
{
return container_of(d, struct f_gsi, d_port);
}
static inline struct f_gsi *c_port_to_gsi(struct gsi_ctrl_port *d)
{
return container_of(d, struct f_gsi, c_port);
}
/* for configfs support */
#define MAX_INST_NAME_LEN 40
struct gsi_opts {
struct usb_function_instance func_inst;
struct f_gsi *gsi;
};
static inline struct gsi_opts *to_gsi_opts(struct config_item *item)
{
return container_of(to_config_group(item), struct gsi_opts,
func_inst.group);
}
static enum ipa_usb_teth_prot name_to_prot_id(const char *name)
{
if (!name)
goto error;
if (!strncmp("rndis", name, MAX_INST_NAME_LEN))
return IPA_USB_RNDIS;
if (!strncmp("ecm", name, MAX_INST_NAME_LEN))
return IPA_USB_ECM;
if (!strncmp("rmnet", name, MAX_INST_NAME_LEN))
return IPA_USB_RMNET;
if (!strncasecmp("mbim", name, MAX_INST_NAME_LEN))
return IPA_USB_MBIM;
if (!strncasecmp("dpl", name, MAX_INST_NAME_LEN))
return IPA_USB_DIAG;
error:
return -EINVAL;
}
/* device descriptors */
#define LOG2_STATUS_INTERVAL_MSEC 5
#define MAX_NOTIFY_SIZE sizeof(struct usb_cdc_notification)
/* rmnet device descriptors */
static struct usb_interface_descriptor rmnet_gsi_interface_desc = {
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bNumEndpoints = 3,
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
.bInterfaceSubClass = USB_CLASS_VENDOR_SPEC,
.bInterfaceProtocol = USB_CLASS_VENDOR_SPEC,
/* .iInterface = DYNAMIC */
};
/* Full speed support */
static struct usb_endpoint_descriptor rmnet_gsi_fs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
};
static struct usb_endpoint_descriptor rmnet_gsi_fs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(64),
};
static struct usb_endpoint_descriptor rmnet_gsi_fs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(64),
};
static struct usb_descriptor_header *rmnet_gsi_fs_function[] = {
(struct usb_descriptor_header *) &rmnet_gsi_interface_desc,
(struct usb_descriptor_header *) &rmnet_gsi_fs_notify_desc,
(struct usb_descriptor_header *) &rmnet_gsi_fs_in_desc,
(struct usb_descriptor_header *) &rmnet_gsi_fs_out_desc,
NULL,
};
/* High speed support */
static struct usb_endpoint_descriptor rmnet_gsi_hs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_endpoint_descriptor rmnet_gsi_hs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_endpoint_descriptor rmnet_gsi_hs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_descriptor_header *rmnet_gsi_hs_function[] = {
(struct usb_descriptor_header *) &rmnet_gsi_interface_desc,
(struct usb_descriptor_header *) &rmnet_gsi_hs_notify_desc,
(struct usb_descriptor_header *) &rmnet_gsi_hs_in_desc,
(struct usb_descriptor_header *) &rmnet_gsi_hs_out_desc,
NULL,
};
/* Super speed support */
static struct usb_endpoint_descriptor rmnet_gsi_ss_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_ss_ep_comp_descriptor rmnet_gsi_ss_notify_comp_desc = {
.bLength = sizeof(rmnet_gsi_ss_notify_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 3 values can be tweaked if necessary */
/* .bMaxBurst = 0, */
/* .bmAttributes = 0, */
.wBytesPerInterval = cpu_to_le16(MAX_NOTIFY_SIZE),
};
static struct usb_endpoint_descriptor rmnet_gsi_ss_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor rmnet_gsi_ss_in_comp_desc = {
.bLength = sizeof(rmnet_gsi_ss_in_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_endpoint_descriptor rmnet_gsi_ss_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor rmnet_gsi_ss_out_comp_desc = {
.bLength = sizeof(rmnet_gsi_ss_out_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_descriptor_header *rmnet_gsi_ss_function[] = {
(struct usb_descriptor_header *) &rmnet_gsi_interface_desc,
(struct usb_descriptor_header *) &rmnet_gsi_ss_notify_desc,
(struct usb_descriptor_header *) &rmnet_gsi_ss_notify_comp_desc,
(struct usb_descriptor_header *) &rmnet_gsi_ss_in_desc,
(struct usb_descriptor_header *) &rmnet_gsi_ss_in_comp_desc,
(struct usb_descriptor_header *) &rmnet_gsi_ss_out_desc,
(struct usb_descriptor_header *) &rmnet_gsi_ss_out_comp_desc,
NULL,
};
/* String descriptors */
static struct usb_string rmnet_gsi_string_defs[] = {
[0].s = "RmNet",
{ } /* end of list */
};
static struct usb_gadget_strings rmnet_gsi_string_table = {
.language = 0x0409, /* en-us */
.strings = rmnet_gsi_string_defs,
};
static struct usb_gadget_strings *rmnet_gsi_strings[] = {
&rmnet_gsi_string_table,
NULL,
};
/* rndis device descriptors */
/* interface descriptor: Supports "Wireless" RNDIS; auto-detected by Windows*/
static struct usb_interface_descriptor rndis_gsi_control_intf = {
.bLength = sizeof(rndis_gsi_control_intf),
.bDescriptorType = USB_DT_INTERFACE,
/* .bInterfaceNumber = DYNAMIC */
/* status endpoint is optional; this could be patched later */
.bNumEndpoints = 1,
.bInterfaceClass = USB_CLASS_MISC,
.bInterfaceSubClass = 0x04,
.bInterfaceProtocol = 0x01, /* RNDIS over Ethernet */
/* .iInterface = DYNAMIC */
};
static struct usb_cdc_header_desc rndis_gsi_header_desc = {
.bLength = sizeof(rndis_gsi_header_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_HEADER_TYPE,
.bcdCDC = cpu_to_le16(0x0110),
};
static struct usb_cdc_call_mgmt_descriptor rndis_gsi_call_mgmt_descriptor = {
.bLength = sizeof(rndis_gsi_call_mgmt_descriptor),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
.bmCapabilities = 0x00,
.bDataInterface = 0x01,
};
static struct usb_cdc_acm_descriptor rndis_gsi_acm_descriptor = {
.bLength = sizeof(rndis_gsi_acm_descriptor),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_ACM_TYPE,
.bmCapabilities = 0x00,
};
static struct usb_cdc_union_desc rndis_gsi_union_desc = {
.bLength = sizeof(rndis_gsi_union_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_UNION_TYPE,
/* .bMasterInterface0 = DYNAMIC */
/* .bSlaveInterface0 = DYNAMIC */
};
/* the data interface has two bulk endpoints */
static struct usb_interface_descriptor rndis_gsi_data_intf = {
.bLength = sizeof(rndis_gsi_data_intf),
.bDescriptorType = USB_DT_INTERFACE,
/* .bInterfaceNumber = DYNAMIC */
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
/* .iInterface = DYNAMIC */
};
/* Supports "Wireless" RNDIS; auto-detected by Windows */
static struct usb_interface_assoc_descriptor
rndis_gsi_iad_descriptor = {
.bLength = sizeof(rndis_gsi_iad_descriptor),
.bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
.bFirstInterface = 0, /* XXX, hardcoded */
.bInterfaceCount = 2, /* control + data */
.bFunctionClass = USB_CLASS_MISC,
.bFunctionSubClass = 0x04,
.bFunctionProtocol = 0x01, /* RNDIS over Ethernet */
/* .iFunction = DYNAMIC */
};
/* full speed support: */
static struct usb_endpoint_descriptor rndis_gsi_fs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
};
static struct usb_endpoint_descriptor rndis_gsi_fs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_endpoint_descriptor rndis_gsi_fs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_descriptor_header *gsi_eth_fs_function[] = {
(struct usb_descriptor_header *) &rndis_gsi_iad_descriptor,
/* control interface matches ACM, not Ethernet */
(struct usb_descriptor_header *) &rndis_gsi_control_intf,
(struct usb_descriptor_header *) &rndis_gsi_header_desc,
(struct usb_descriptor_header *) &rndis_gsi_call_mgmt_descriptor,
(struct usb_descriptor_header *) &rndis_gsi_acm_descriptor,
(struct usb_descriptor_header *) &rndis_gsi_union_desc,
(struct usb_descriptor_header *) &rndis_gsi_fs_notify_desc,
/* data interface has no altsetting */
(struct usb_descriptor_header *) &rndis_gsi_data_intf,
(struct usb_descriptor_header *) &rndis_gsi_fs_in_desc,
(struct usb_descriptor_header *) &rndis_gsi_fs_out_desc,
NULL,
};
/* high speed support: */
static struct usb_endpoint_descriptor rndis_gsi_hs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_endpoint_descriptor rndis_gsi_hs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_endpoint_descriptor rndis_gsi_hs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_descriptor_header *gsi_eth_hs_function[] = {
(struct usb_descriptor_header *) &rndis_gsi_iad_descriptor,
/* control interface matches ACM, not Ethernet */
(struct usb_descriptor_header *) &rndis_gsi_control_intf,
(struct usb_descriptor_header *) &rndis_gsi_header_desc,
(struct usb_descriptor_header *) &rndis_gsi_call_mgmt_descriptor,
(struct usb_descriptor_header *) &rndis_gsi_acm_descriptor,
(struct usb_descriptor_header *) &rndis_gsi_union_desc,
(struct usb_descriptor_header *) &rndis_gsi_hs_notify_desc,
/* data interface has no altsetting */
(struct usb_descriptor_header *) &rndis_gsi_data_intf,
(struct usb_descriptor_header *) &rndis_gsi_hs_in_desc,
(struct usb_descriptor_header *) &rndis_gsi_hs_out_desc,
NULL,
};
/* super speed support: */
static struct usb_endpoint_descriptor rndis_gsi_ss_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_ss_ep_comp_descriptor rndis_gsi_ss_intr_comp_desc = {
.bLength = sizeof(rndis_gsi_ss_intr_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 3 values can be tweaked if necessary */
/* .bMaxBurst = 0, */
/* .bmAttributes = 0, */
.wBytesPerInterval = cpu_to_le16(MAX_NOTIFY_SIZE),
};
static struct usb_endpoint_descriptor rndis_gsi_ss_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_endpoint_descriptor rndis_gsi_ss_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor rndis_gsi_ss_bulk_comp_desc = {
.bLength = sizeof(rndis_gsi_ss_bulk_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_descriptor_header *gsi_eth_ss_function[] = {
(struct usb_descriptor_header *) &rndis_gsi_iad_descriptor,
/* control interface matches ACM, not Ethernet */
(struct usb_descriptor_header *) &rndis_gsi_control_intf,
(struct usb_descriptor_header *) &rndis_gsi_header_desc,
(struct usb_descriptor_header *) &rndis_gsi_call_mgmt_descriptor,
(struct usb_descriptor_header *) &rndis_gsi_acm_descriptor,
(struct usb_descriptor_header *) &rndis_gsi_union_desc,
(struct usb_descriptor_header *) &rndis_gsi_ss_notify_desc,
(struct usb_descriptor_header *) &rndis_gsi_ss_intr_comp_desc,
/* data interface has no altsetting */
(struct usb_descriptor_header *) &rndis_gsi_data_intf,
(struct usb_descriptor_header *) &rndis_gsi_ss_in_desc,
(struct usb_descriptor_header *) &rndis_gsi_ss_bulk_comp_desc,
(struct usb_descriptor_header *) &rndis_gsi_ss_out_desc,
(struct usb_descriptor_header *) &rndis_gsi_ss_bulk_comp_desc,
NULL,
};
/* string descriptors: */
static struct usb_string rndis_gsi_string_defs[] = {
[0].s = "RNDIS Communications Control",
[1].s = "RNDIS Ethernet Data",
[2].s = "RNDIS",
{ } /* end of list */
};
static struct usb_gadget_strings rndis_gsi_string_table = {
.language = 0x0409, /* en-us */
.strings = rndis_gsi_string_defs,
};
static struct usb_gadget_strings *rndis_gsi_strings[] = {
&rndis_gsi_string_table,
NULL,
};
/* mbim device descriptors */
#define MBIM_NTB_DEFAULT_IN_SIZE (0x4000)
static struct usb_cdc_ncm_ntb_parameters mbim_gsi_ntb_parameters = {
.wLength = sizeof(mbim_gsi_ntb_parameters),
.bmNtbFormatsSupported = cpu_to_le16(USB_CDC_NCM_NTB16_SUPPORTED),
.dwNtbInMaxSize = cpu_to_le32(MBIM_NTB_DEFAULT_IN_SIZE),
.wNdpInDivisor = cpu_to_le16(4),
.wNdpInPayloadRemainder = cpu_to_le16(0),
.wNdpInAlignment = cpu_to_le16(4),
.dwNtbOutMaxSize = cpu_to_le32(0x4000),
.wNdpOutDivisor = cpu_to_le16(4),
.wNdpOutPayloadRemainder = cpu_to_le16(0),
.wNdpOutAlignment = cpu_to_le16(4),
.wNtbOutMaxDatagrams = 16,
};
/*
* Use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one
* packet, to simplify cancellation;
*/
#define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
static struct usb_interface_assoc_descriptor mbim_gsi_iad_desc = {
.bLength = sizeof(mbim_gsi_iad_desc),
.bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
/* .bFirstInterface = DYNAMIC, */
.bInterfaceCount = 2, /* control + data */
.bFunctionClass = 2,
.bFunctionSubClass = 0x0e,
.bFunctionProtocol = 0,
/* .iFunction = DYNAMIC */
};
/* interface descriptor: */
static struct usb_interface_descriptor mbim_gsi_control_intf = {
.bLength = sizeof(mbim_gsi_control_intf),
.bDescriptorType = USB_DT_INTERFACE,
/* .bInterfaceNumber = DYNAMIC */
.bNumEndpoints = 1,
.bInterfaceClass = 0x02,
.bInterfaceSubClass = 0x0e,
.bInterfaceProtocol = 0,
/* .iInterface = DYNAMIC */
};
static struct usb_cdc_header_desc mbim_gsi_header_desc = {
.bLength = sizeof(mbim_gsi_header_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_HEADER_TYPE,
.bcdCDC = cpu_to_le16(0x0110),
};
static struct usb_cdc_union_desc mbim_gsi_union_desc = {
.bLength = sizeof(mbim_gsi_union_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_UNION_TYPE,
/* .bMasterInterface0 = DYNAMIC */
/* .bSlaveInterface0 = DYNAMIC */
};
static struct usb_cdc_mbim_desc mbim_gsi_desc = {
.bLength = sizeof(mbim_gsi_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_MBIM_TYPE,
.bcdMBIMVersion = cpu_to_le16(0x0100),
.wMaxControlMessage = cpu_to_le16(0x1000),
.bNumberFilters = 0x20,
.bMaxFilterSize = 0x80,
.wMaxSegmentSize = cpu_to_le16(0xfe0),
.bmNetworkCapabilities = 0x20,
};
static struct usb_cdc_mbim_extended_desc mbim_gsi_ext_mbb_desc = {
.bLength = sizeof(mbim_gsi_ext_mbb_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_MBIM_EXTENDED_TYPE,
.bcdMBIMExtendedVersion = cpu_to_le16(0x0100),
.bMaxOutstandingCommandMessages = 64,
.wMTU = cpu_to_le16(1500),
};
/* the default data interface has no endpoints ... */
static struct usb_interface_descriptor mbim_gsi_data_nop_intf = {
.bLength = sizeof(mbim_gsi_data_nop_intf),
.bDescriptorType = USB_DT_INTERFACE,
/* .bInterfaceNumber = DYNAMIC */
.bAlternateSetting = 0,
.bNumEndpoints = 0,
.bInterfaceClass = 0x0a,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0x02,
/* .iInterface = DYNAMIC */
};
/* ... but the "real" data interface has two bulk endpoints */
static struct usb_interface_descriptor mbim_gsi_data_intf = {
.bLength = sizeof(mbim_gsi_data_intf),
.bDescriptorType = USB_DT_INTERFACE,
/* .bInterfaceNumber = DYNAMIC */
.bAlternateSetting = 1,
.bNumEndpoints = 2,
.bInterfaceClass = 0x0a,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0x02,
/* .iInterface = DYNAMIC */
};
/* full speed support: */
static struct usb_endpoint_descriptor mbim_gsi_fs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = 4*cpu_to_le16(NCM_STATUS_BYTECOUNT),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
};
static struct usb_endpoint_descriptor mbim_gsi_fs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_endpoint_descriptor mbim_gsi_fs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_descriptor_header *mbim_gsi_fs_function[] = {
(struct usb_descriptor_header *) &mbim_gsi_iad_desc,
/* MBIM control descriptors */
(struct usb_descriptor_header *) &mbim_gsi_control_intf,
(struct usb_descriptor_header *) &mbim_gsi_header_desc,
(struct usb_descriptor_header *) &mbim_gsi_union_desc,
(struct usb_descriptor_header *) &mbim_gsi_desc,
(struct usb_descriptor_header *) &mbim_gsi_ext_mbb_desc,
(struct usb_descriptor_header *) &mbim_gsi_fs_notify_desc,
/* data interface, altsettings 0 and 1 */
(struct usb_descriptor_header *) &mbim_gsi_data_nop_intf,
(struct usb_descriptor_header *) &mbim_gsi_data_intf,
(struct usb_descriptor_header *) &mbim_gsi_fs_in_desc,
(struct usb_descriptor_header *) &mbim_gsi_fs_out_desc,
NULL,
};
/* high speed support: */
static struct usb_endpoint_descriptor mbim_gsi_hs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = 4*cpu_to_le16(NCM_STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_endpoint_descriptor mbim_gsi_hs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_endpoint_descriptor mbim_gsi_hs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_descriptor_header *mbim_gsi_hs_function[] = {
(struct usb_descriptor_header *) &mbim_gsi_iad_desc,
/* MBIM control descriptors */
(struct usb_descriptor_header *) &mbim_gsi_control_intf,
(struct usb_descriptor_header *) &mbim_gsi_header_desc,
(struct usb_descriptor_header *) &mbim_gsi_union_desc,
(struct usb_descriptor_header *) &mbim_gsi_desc,
(struct usb_descriptor_header *) &mbim_gsi_ext_mbb_desc,
(struct usb_descriptor_header *) &mbim_gsi_hs_notify_desc,
/* data interface, altsettings 0 and 1 */
(struct usb_descriptor_header *) &mbim_gsi_data_nop_intf,
(struct usb_descriptor_header *) &mbim_gsi_data_intf,
(struct usb_descriptor_header *) &mbim_gsi_hs_in_desc,
(struct usb_descriptor_header *) &mbim_gsi_hs_out_desc,
NULL,
};
/* Super Speed Support */
static struct usb_endpoint_descriptor mbim_gsi_ss_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = 4*cpu_to_le16(NCM_STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_ss_ep_comp_descriptor mbim_gsi_ss_notify_comp_desc = {
.bLength = sizeof(mbim_gsi_ss_notify_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 3 values can be tweaked if necessary */
/* .bMaxBurst = 0, */
/* .bmAttributes = 0, */
.wBytesPerInterval = 4*cpu_to_le16(NCM_STATUS_BYTECOUNT),
};
static struct usb_endpoint_descriptor mbim_gsi_ss_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor mbim_gsi_ss_in_comp_desc = {
.bLength = sizeof(mbim_gsi_ss_in_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_endpoint_descriptor mbim_gsi_ss_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor mbim_gsi_ss_out_comp_desc = {
.bLength = sizeof(mbim_gsi_ss_out_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_descriptor_header *mbim_gsi_ss_function[] = {
(struct usb_descriptor_header *) &mbim_gsi_iad_desc,
/* MBIM control descriptors */
(struct usb_descriptor_header *) &mbim_gsi_control_intf,
(struct usb_descriptor_header *) &mbim_gsi_header_desc,
(struct usb_descriptor_header *) &mbim_gsi_union_desc,
(struct usb_descriptor_header *) &mbim_gsi_desc,
(struct usb_descriptor_header *) &mbim_gsi_ext_mbb_desc,
(struct usb_descriptor_header *) &mbim_gsi_ss_notify_desc,
(struct usb_descriptor_header *) &mbim_gsi_ss_notify_comp_desc,
/* data interface, altsettings 0 and 1 */
(struct usb_descriptor_header *) &mbim_gsi_data_nop_intf,
(struct usb_descriptor_header *) &mbim_gsi_data_intf,
(struct usb_descriptor_header *) &mbim_gsi_ss_in_desc,
(struct usb_descriptor_header *) &mbim_gsi_ss_in_comp_desc,
(struct usb_descriptor_header *) &mbim_gsi_ss_out_desc,
(struct usb_descriptor_header *) &mbim_gsi_ss_out_comp_desc,
NULL,
};
/* string descriptors: */
static struct usb_string mbim_gsi_string_defs[] = {
[0].s = "MBIM Control",
[1].s = "MBIM Data",
{ } /* end of list */
};
static struct usb_gadget_strings mbim_gsi_string_table = {
.language = 0x0409, /* en-us */
.strings = mbim_gsi_string_defs,
};
static struct usb_gadget_strings *mbim_gsi_strings[] = {
&mbim_gsi_string_table,
NULL,
};
/* Microsoft OS Descriptors */
/*
* We specify our own bMS_VendorCode byte which Windows will use
* as the bRequest value in subsequent device get requests.
*/
#define MBIM_VENDOR_CODE 0xA5
/* Microsoft Extended Configuration Descriptor Header Section */
struct mbim_gsi_ext_config_desc_header {
__le32 dwLength;
__u16 bcdVersion;
__le16 wIndex;
__u8 bCount;
__u8 reserved[7];
};
/* Microsoft Extended Configuration Descriptor Function Section */
struct mbim_gsi_ext_config_desc_function {
__u8 bFirstInterfaceNumber;
__u8 bInterfaceCount;
__u8 compatibleID[8];
__u8 subCompatibleID[8];
__u8 reserved[6];
};
/* Microsoft Extended Configuration Descriptor */
static struct {
struct mbim_gsi_ext_config_desc_header header;
struct mbim_gsi_ext_config_desc_function function;
} mbim_gsi_ext_config_desc = {
.header = {
.dwLength = cpu_to_le32(sizeof(mbim_gsi_ext_config_desc)),
.bcdVersion = cpu_to_le16(0x0100),
.wIndex = cpu_to_le16(4),
.bCount = 1,
},
.function = {
.bFirstInterfaceNumber = 0,
.bInterfaceCount = 1,
.compatibleID = { 'A', 'L', 'T', 'R', 'C', 'F', 'G' },
/* .subCompatibleID = DYNAMIC */
},
};
/* ecm device descriptors */
#define ECM_QC_LOG2_STATUS_INTERVAL_MSEC 5
#define ECM_QC_STATUS_BYTECOUNT 16 /* 8 byte header + data */
/* interface descriptor: */
static struct usb_interface_descriptor ecm_gsi_control_intf = {
.bLength = sizeof(ecm_gsi_control_intf),
.bDescriptorType = USB_DT_INTERFACE,
/* .bInterfaceNumber = DYNAMIC */
/* status endpoint is optional; this could be patched later */
.bNumEndpoints = 1,
.bInterfaceClass = USB_CLASS_COMM,
.bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET,
.bInterfaceProtocol = USB_CDC_PROTO_NONE,
/* .iInterface = DYNAMIC */
};
static struct usb_cdc_header_desc ecm_gsi_header_desc = {
.bLength = sizeof(ecm_gsi_header_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_HEADER_TYPE,
.bcdCDC = cpu_to_le16(0x0110),
};
static struct usb_cdc_union_desc ecm_gsi_union_desc = {
.bLength = sizeof(ecm_gsi_union_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_UNION_TYPE,
/* .bMasterInterface0 = DYNAMIC */
/* .bSlaveInterface0 = DYNAMIC */
};
static struct usb_cdc_ether_desc ecm_gsi_desc = {
.bLength = sizeof(ecm_gsi_desc),
.bDescriptorType = USB_DT_CS_INTERFACE,
.bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
/* this descriptor actually adds value, surprise! */
/* .iMACAddress = DYNAMIC */
.bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
.wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
.wNumberMCFilters = cpu_to_le16(0),
.bNumberPowerFilters = 0,
};
/* the default data interface has no endpoints ... */
static struct usb_interface_descriptor ecm_gsi_data_nop_intf = {
.bLength = sizeof(ecm_gsi_data_nop_intf),
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 0,
.bInterfaceClass = USB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
/* .iInterface = DYNAMIC */
};
/* ... but the "real" data interface has two bulk endpoints */
static struct usb_interface_descriptor ecm_gsi_data_intf = {
.bLength = sizeof(ecm_gsi_data_intf),
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 1,
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
/* .iInterface = DYNAMIC */
};
/* full speed support: */
static struct usb_endpoint_descriptor ecm_gsi_fs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
};
static struct usb_endpoint_descriptor ecm_gsi_fs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_endpoint_descriptor ecm_gsi_fs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_descriptor_header *ecm_gsi_fs_function[] = {
/* CDC ECM control descriptors */
(struct usb_descriptor_header *) &ecm_gsi_control_intf,
(struct usb_descriptor_header *) &ecm_gsi_header_desc,
(struct usb_descriptor_header *) &ecm_gsi_union_desc,
(struct usb_descriptor_header *) &ecm_gsi_desc,
/* NOTE: status endpoint might need to be removed */
(struct usb_descriptor_header *) &ecm_gsi_fs_notify_desc,
/* data interface, altsettings 0 and 1 */
(struct usb_descriptor_header *) &ecm_gsi_data_nop_intf,
(struct usb_descriptor_header *) &ecm_gsi_data_intf,
(struct usb_descriptor_header *) &ecm_gsi_fs_in_desc,
(struct usb_descriptor_header *) &ecm_gsi_fs_out_desc,
NULL,
};
/* high speed support: */
static struct usb_endpoint_descriptor ecm_gsi_hs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_endpoint_descriptor ecm_gsi_hs_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_endpoint_descriptor ecm_gsi_hs_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_descriptor_header *ecm_gsi_hs_function[] = {
/* CDC ECM control descriptors */
(struct usb_descriptor_header *) &ecm_gsi_control_intf,
(struct usb_descriptor_header *) &ecm_gsi_header_desc,
(struct usb_descriptor_header *) &ecm_gsi_union_desc,
(struct usb_descriptor_header *) &ecm_gsi_desc,
/* NOTE: status endpoint might need to be removed */
(struct usb_descriptor_header *) &ecm_gsi_hs_notify_desc,
/* data interface, altsettings 0 and 1 */
(struct usb_descriptor_header *) &ecm_gsi_data_nop_intf,
(struct usb_descriptor_header *) &ecm_gsi_data_intf,
(struct usb_descriptor_header *) &ecm_gsi_hs_in_desc,
(struct usb_descriptor_header *) &ecm_gsi_hs_out_desc,
NULL,
};
static struct usb_endpoint_descriptor ecm_gsi_ss_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_INT,
.wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
.bInterval = ECM_QC_LOG2_STATUS_INTERVAL_MSEC + 4,
};
static struct usb_ss_ep_comp_descriptor ecm_gsi_ss_notify_comp_desc = {
.bLength = sizeof(ecm_gsi_ss_notify_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 3 values can be tweaked if necessary */
/* .bMaxBurst = 0, */
/* .bmAttributes = 0, */
.wBytesPerInterval = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
};
static struct usb_endpoint_descriptor ecm_gsi_ss_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor ecm_gsi_ss_in_comp_desc = {
.bLength = sizeof(ecm_gsi_ss_in_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_endpoint_descriptor ecm_gsi_ss_out_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor ecm_gsi_ss_out_comp_desc = {
.bLength = sizeof(ecm_gsi_ss_out_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
/* the following 2 values can be tweaked if necessary */
.bMaxBurst = 2,
/* .bmAttributes = 0, */
};
static struct usb_descriptor_header *ecm_gsi_ss_function[] = {
/* CDC ECM control descriptors */
(struct usb_descriptor_header *) &ecm_gsi_control_intf,
(struct usb_descriptor_header *) &ecm_gsi_header_desc,
(struct usb_descriptor_header *) &ecm_gsi_union_desc,
(struct usb_descriptor_header *) &ecm_gsi_desc,
/* NOTE: status endpoint might need to be removed */
(struct usb_descriptor_header *) &ecm_gsi_ss_notify_desc,
(struct usb_descriptor_header *) &ecm_gsi_ss_notify_comp_desc,
/* data interface, altsettings 0 and 1 */
(struct usb_descriptor_header *) &ecm_gsi_data_nop_intf,
(struct usb_descriptor_header *) &ecm_gsi_data_intf,
(struct usb_descriptor_header *) &ecm_gsi_ss_in_desc,
(struct usb_descriptor_header *) &ecm_gsi_ss_in_comp_desc,
(struct usb_descriptor_header *) &ecm_gsi_ss_out_desc,
(struct usb_descriptor_header *) &ecm_gsi_ss_out_comp_desc,
NULL,
};
/* string descriptors: */
static struct usb_string ecm_gsi_string_defs[] = {
[0].s = "CDC Ethernet Control Model (ECM)",
[1].s = NULL /* DYNAMIC */,
[2].s = "CDC Ethernet Data",
{ } /* end of list */
};
static struct usb_gadget_strings ecm_gsi_string_table = {
.language = 0x0409, /* en-us */
.strings = ecm_gsi_string_defs,
};
static struct usb_gadget_strings *ecm_gsi_strings[] = {
&ecm_gsi_string_table,
NULL,
};
/* qdss device descriptor */
static struct usb_interface_descriptor qdss_gsi_data_intf_desc = {
.bLength = sizeof(qdss_gsi_data_intf_desc),
.bDescriptorType = USB_DT_INTERFACE,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = 0xff,
.bInterfaceSubClass = 0xff,
.bInterfaceProtocol = 0xff,
};
static struct usb_endpoint_descriptor qdss_gsi_hs_data_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(512),
};
static struct usb_endpoint_descriptor qdss_gsi_ss_data_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = cpu_to_le16(1024),
};
static struct usb_ss_ep_comp_descriptor qdss_gsi_data_ep_comp_desc = {
.bLength = sizeof(qdss_gsi_data_ep_comp_desc),
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
.bMaxBurst = 1,
.bmAttributes = 0,
.wBytesPerInterval = 0,
};
static struct usb_descriptor_header *qdss_gsi_hs_data_only_desc[] = {
(struct usb_descriptor_header *) &qdss_gsi_data_intf_desc,
(struct usb_descriptor_header *) &qdss_gsi_hs_data_desc,
NULL,
};
static struct usb_descriptor_header *qdss_gsi_ss_data_only_desc[] = {
(struct usb_descriptor_header *) &qdss_gsi_data_intf_desc,
(struct usb_descriptor_header *) &qdss_gsi_ss_data_desc,
(struct usb_descriptor_header *) &qdss_gsi_data_ep_comp_desc,
NULL,
};
/* string descriptors: */
static struct usb_string qdss_gsi_string_defs[] = {
[0].s = "QDSS DATA",
{}, /* end of list */
};
static struct usb_gadget_strings qdss_gsi_string_table = {
.language = 0x0409,
.strings = qdss_gsi_string_defs,
};
static struct usb_gadget_strings *qdss_gsi_strings[] = {
&qdss_gsi_string_table,
NULL,
};
#endif
|