Merge branch 'linux-linaro-lsk-v4.4' into linux-linaro-lsk-v4.4-android
[firefly-linux-kernel-4.4.55.git] / drivers / usb / gadget / function / rndis.c
1 /*
2  * RNDIS MSG parser
3  *
4  * Authors:     Benedikt Spranger, Pengutronix
5  *              Robert Schwebel, Pengutronix
6  *
7  *              This program is free software; you can redistribute it and/or
8  *              modify it under the terms of the GNU General Public License
9  *              version 2, as published by the Free Software Foundation.
10  *
11  *              This software was originally developed in conformance with
12  *              Microsoft's Remote NDIS Specification License Agreement.
13  *
14  * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
15  *              Fixed message length bug in init_response
16  *
17  * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
18  *              Fixed rndis_rm_hdr length bug.
19  *
20  * Copyright (C) 2004 by David Brownell
21  *              updates to merge with Linux 2.6, better match RNDIS spec
22  */
23
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/idr.h>
29 #include <linux/list.h>
30 #include <linux/proc_fs.h>
31 #include <linux/slab.h>
32 #include <linux/seq_file.h>
33 #include <linux/netdevice.h>
34
35 #include <asm/io.h>
36 #include <asm/byteorder.h>
37 #include <asm/unaligned.h>
38
39 #include "u_rndis.h"
40
41 #undef  VERBOSE_DEBUG
42
43 #include "rndis.h"
44
45 int rndis_ul_max_pkt_per_xfer_rcvd;
46 module_param(rndis_ul_max_pkt_per_xfer_rcvd, int, S_IRUGO);
47 MODULE_PARM_DESC(rndis_ul_max_pkt_per_xfer_rcvd,
48                 "Max num of REMOTE_NDIS_PACKET_MSGs received in a single transfer");
49
50 int rndis_ul_max_xfer_size_rcvd;
51 module_param(rndis_ul_max_xfer_size_rcvd, int, S_IRUGO);
52 MODULE_PARM_DESC(rndis_ul_max_xfer_size_rcvd,
53                 "Max size of bus transfer received");
54
55
56 /* The driver for your USB chip needs to support ep0 OUT to work with
57  * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
58  *
59  * Windows hosts need an INF file like Documentation/usb/linux.inf
60  * and will be happier if you provide the host_addr module parameter.
61  */
62
63 #if 0
64 static int rndis_debug = 0;
65 module_param (rndis_debug, int, 0);
66 MODULE_PARM_DESC (rndis_debug, "enable debugging");
67 #else
68 #define rndis_debug             0
69 #endif
70
71 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
72
73 #define NAME_TEMPLATE "driver/rndis-%03d"
74
75 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
76
77 static DEFINE_IDA(rndis_ida);
78
79 /* Driver Version */
80 static const __le32 rndis_driver_version = cpu_to_le32(1);
81
82 /* Function Prototypes */
83 static rndis_resp_t *rndis_add_response(struct rndis_params *params,
84                                         u32 length);
85
86 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
87
88 static const struct file_operations rndis_proc_fops;
89
90 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
91
92 /* supported OIDs */
93 static const u32 oid_supported_list[] =
94 {
95         /* the general stuff */
96         RNDIS_OID_GEN_SUPPORTED_LIST,
97         RNDIS_OID_GEN_HARDWARE_STATUS,
98         RNDIS_OID_GEN_MEDIA_SUPPORTED,
99         RNDIS_OID_GEN_MEDIA_IN_USE,
100         RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE,
101         RNDIS_OID_GEN_LINK_SPEED,
102         RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE,
103         RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE,
104         RNDIS_OID_GEN_VENDOR_ID,
105         RNDIS_OID_GEN_VENDOR_DESCRIPTION,
106         RNDIS_OID_GEN_VENDOR_DRIVER_VERSION,
107         RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
108         RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE,
109         RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
110         RNDIS_OID_GEN_PHYSICAL_MEDIUM,
111
112         /* the statistical stuff */
113         RNDIS_OID_GEN_XMIT_OK,
114         RNDIS_OID_GEN_RCV_OK,
115         RNDIS_OID_GEN_XMIT_ERROR,
116         RNDIS_OID_GEN_RCV_ERROR,
117         RNDIS_OID_GEN_RCV_NO_BUFFER,
118 #ifdef  RNDIS_OPTIONAL_STATS
119         RNDIS_OID_GEN_DIRECTED_BYTES_XMIT,
120         RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT,
121         RNDIS_OID_GEN_MULTICAST_BYTES_XMIT,
122         RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT,
123         RNDIS_OID_GEN_BROADCAST_BYTES_XMIT,
124         RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT,
125         RNDIS_OID_GEN_DIRECTED_BYTES_RCV,
126         RNDIS_OID_GEN_DIRECTED_FRAMES_RCV,
127         RNDIS_OID_GEN_MULTICAST_BYTES_RCV,
128         RNDIS_OID_GEN_MULTICAST_FRAMES_RCV,
129         RNDIS_OID_GEN_BROADCAST_BYTES_RCV,
130         RNDIS_OID_GEN_BROADCAST_FRAMES_RCV,
131         RNDIS_OID_GEN_RCV_CRC_ERROR,
132         RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH,
133 #endif  /* RNDIS_OPTIONAL_STATS */
134
135         /* mandatory 802.3 */
136         /* the general stuff */
137         RNDIS_OID_802_3_PERMANENT_ADDRESS,
138         RNDIS_OID_802_3_CURRENT_ADDRESS,
139         RNDIS_OID_802_3_MULTICAST_LIST,
140         RNDIS_OID_802_3_MAC_OPTIONS,
141         RNDIS_OID_802_3_MAXIMUM_LIST_SIZE,
142
143         /* the statistical stuff */
144         RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT,
145         RNDIS_OID_802_3_XMIT_ONE_COLLISION,
146         RNDIS_OID_802_3_XMIT_MORE_COLLISIONS,
147 #ifdef  RNDIS_OPTIONAL_STATS
148         RNDIS_OID_802_3_XMIT_DEFERRED,
149         RNDIS_OID_802_3_XMIT_MAX_COLLISIONS,
150         RNDIS_OID_802_3_RCV_OVERRUN,
151         RNDIS_OID_802_3_XMIT_UNDERRUN,
152         RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE,
153         RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST,
154         RNDIS_OID_802_3_XMIT_LATE_COLLISIONS,
155 #endif  /* RNDIS_OPTIONAL_STATS */
156
157 #ifdef  RNDIS_PM
158         /* PM and wakeup are "mandatory" for USB, but the RNDIS specs
159          * don't say what they mean ... and the NDIS specs are often
160          * confusing and/or ambiguous in this context.  (That is, more
161          * so than their specs for the other OIDs.)
162          *
163          * FIXME someone who knows what these should do, please
164          * implement them!
165          */
166
167         /* power management */
168         OID_PNP_CAPABILITIES,
169         OID_PNP_QUERY_POWER,
170         OID_PNP_SET_POWER,
171
172 #ifdef  RNDIS_WAKEUP
173         /* wake up host */
174         OID_PNP_ENABLE_WAKE_UP,
175         OID_PNP_ADD_WAKE_UP_PATTERN,
176         OID_PNP_REMOVE_WAKE_UP_PATTERN,
177 #endif  /* RNDIS_WAKEUP */
178 #endif  /* RNDIS_PM */
179 };
180
181
182 /* NDIS Functions */
183 static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf,
184                                unsigned buf_len, rndis_resp_t *r)
185 {
186         int retval = -ENOTSUPP;
187         u32 length = 4; /* usually */
188         __le32 *outbuf;
189         int i, count;
190         rndis_query_cmplt_type *resp;
191         struct net_device *net;
192         struct rtnl_link_stats64 temp;
193         const struct rtnl_link_stats64 *stats;
194
195         if (!r) return -ENOMEM;
196         resp = (rndis_query_cmplt_type *)r->buf;
197
198         if (!resp) return -ENOMEM;
199
200         if (buf_len && rndis_debug > 1) {
201                 pr_debug("query OID %08x value, len %d:\n", OID, buf_len);
202                 for (i = 0; i < buf_len; i += 16) {
203                         pr_debug("%03d: %08x %08x %08x %08x\n", i,
204                                 get_unaligned_le32(&buf[i]),
205                                 get_unaligned_le32(&buf[i + 4]),
206                                 get_unaligned_le32(&buf[i + 8]),
207                                 get_unaligned_le32(&buf[i + 12]));
208                 }
209         }
210
211         /* response goes here, right after the header */
212         outbuf = (__le32 *)&resp[1];
213         resp->InformationBufferOffset = cpu_to_le32(16);
214
215         net = params->dev;
216         stats = dev_get_stats(net, &temp);
217
218         switch (OID) {
219
220         /* general oids (table 4-1) */
221
222         /* mandatory */
223         case RNDIS_OID_GEN_SUPPORTED_LIST:
224                 pr_debug("%s: RNDIS_OID_GEN_SUPPORTED_LIST\n", __func__);
225                 length = sizeof(oid_supported_list);
226                 count  = length / sizeof(u32);
227                 for (i = 0; i < count; i++)
228                         outbuf[i] = cpu_to_le32(oid_supported_list[i]);
229                 retval = 0;
230                 break;
231
232         /* mandatory */
233         case RNDIS_OID_GEN_HARDWARE_STATUS:
234                 pr_debug("%s: RNDIS_OID_GEN_HARDWARE_STATUS\n", __func__);
235                 /* Bogus question!
236                  * Hardware must be ready to receive high level protocols.
237                  * BTW:
238                  * reddite ergo quae sunt Caesaris Caesari
239                  * et quae sunt Dei Deo!
240                  */
241                 *outbuf = cpu_to_le32(0);
242                 retval = 0;
243                 break;
244
245         /* mandatory */
246         case RNDIS_OID_GEN_MEDIA_SUPPORTED:
247                 pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__);
248                 *outbuf = cpu_to_le32(params->medium);
249                 retval = 0;
250                 break;
251
252         /* mandatory */
253         case RNDIS_OID_GEN_MEDIA_IN_USE:
254                 pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__);
255                 /* one medium, one transport... (maybe you do it better) */
256                 *outbuf = cpu_to_le32(params->medium);
257                 retval = 0;
258                 break;
259
260         /* mandatory */
261         case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE:
262                 pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
263                 if (params->dev) {
264                         *outbuf = cpu_to_le32(params->dev->mtu);
265                         retval = 0;
266                 }
267                 break;
268
269         /* mandatory */
270         case RNDIS_OID_GEN_LINK_SPEED:
271                 if (rndis_debug > 1)
272                         pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__);
273                 if (params->media_state == RNDIS_MEDIA_STATE_DISCONNECTED)
274                         *outbuf = cpu_to_le32(0);
275                 else
276                         *outbuf = cpu_to_le32(params->speed);
277                 retval = 0;
278                 break;
279
280         /* mandatory */
281         case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE:
282                 pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
283                 if (params->dev) {
284                         *outbuf = cpu_to_le32(params->dev->mtu);
285                         retval = 0;
286                 }
287                 break;
288
289         /* mandatory */
290         case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE:
291                 pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
292                 if (params->dev) {
293                         *outbuf = cpu_to_le32(params->dev->mtu);
294                         retval = 0;
295                 }
296                 break;
297
298         /* mandatory */
299         case RNDIS_OID_GEN_VENDOR_ID:
300                 pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__);
301                 *outbuf = cpu_to_le32(params->vendorID);
302                 retval = 0;
303                 break;
304
305         /* mandatory */
306         case RNDIS_OID_GEN_VENDOR_DESCRIPTION:
307                 pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__);
308                 if (params->vendorDescr) {
309                         length = strlen(params->vendorDescr);
310                         memcpy(outbuf, params->vendorDescr, length);
311                 } else {
312                         outbuf[0] = 0;
313                 }
314                 retval = 0;
315                 break;
316
317         case RNDIS_OID_GEN_VENDOR_DRIVER_VERSION:
318                 pr_debug("%s: RNDIS_OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
319                 /* Created as LE */
320                 *outbuf = rndis_driver_version;
321                 retval = 0;
322                 break;
323
324         /* mandatory */
325         case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
326                 pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
327                 *outbuf = cpu_to_le32(*params->filter);
328                 retval = 0;
329                 break;
330
331         /* mandatory */
332         case RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE:
333                 pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
334                 *outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
335                 retval = 0;
336                 break;
337
338         /* mandatory */
339         case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS:
340                 if (rndis_debug > 1)
341                         pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
342                 *outbuf = cpu_to_le32(params->media_state);
343                 retval = 0;
344                 break;
345
346         case RNDIS_OID_GEN_PHYSICAL_MEDIUM:
347                 pr_debug("%s: RNDIS_OID_GEN_PHYSICAL_MEDIUM\n", __func__);
348                 *outbuf = cpu_to_le32(0);
349                 retval = 0;
350                 break;
351
352         /* The RNDIS specification is incomplete/wrong.   Some versions
353          * of MS-Windows expect OIDs that aren't specified there.  Other
354          * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
355          */
356         case RNDIS_OID_GEN_MAC_OPTIONS:         /* from WinME */
357                 pr_debug("%s: RNDIS_OID_GEN_MAC_OPTIONS\n", __func__);
358                 *outbuf = cpu_to_le32(
359                           RNDIS_MAC_OPTION_RECEIVE_SERIALIZED
360                         | RNDIS_MAC_OPTION_FULL_DUPLEX);
361                 retval = 0;
362                 break;
363
364         /* statistics OIDs (table 4-2) */
365
366         /* mandatory */
367         case RNDIS_OID_GEN_XMIT_OK:
368                 if (rndis_debug > 1)
369                         pr_debug("%s: RNDIS_OID_GEN_XMIT_OK\n", __func__);
370                 if (stats) {
371                         *outbuf = cpu_to_le32(stats->tx_packets
372                                 - stats->tx_errors - stats->tx_dropped);
373                         retval = 0;
374                 }
375                 break;
376
377         /* mandatory */
378         case RNDIS_OID_GEN_RCV_OK:
379                 if (rndis_debug > 1)
380                         pr_debug("%s: RNDIS_OID_GEN_RCV_OK\n", __func__);
381                 if (stats) {
382                         *outbuf = cpu_to_le32(stats->rx_packets
383                                 - stats->rx_errors - stats->rx_dropped);
384                         retval = 0;
385                 }
386                 break;
387
388         /* mandatory */
389         case RNDIS_OID_GEN_XMIT_ERROR:
390                 if (rndis_debug > 1)
391                         pr_debug("%s: RNDIS_OID_GEN_XMIT_ERROR\n", __func__);
392                 if (stats) {
393                         *outbuf = cpu_to_le32(stats->tx_errors);
394                         retval = 0;
395                 }
396                 break;
397
398         /* mandatory */
399         case RNDIS_OID_GEN_RCV_ERROR:
400                 if (rndis_debug > 1)
401                         pr_debug("%s: RNDIS_OID_GEN_RCV_ERROR\n", __func__);
402                 if (stats) {
403                         *outbuf = cpu_to_le32(stats->rx_errors);
404                         retval = 0;
405                 }
406                 break;
407
408         /* mandatory */
409         case RNDIS_OID_GEN_RCV_NO_BUFFER:
410                 pr_debug("%s: RNDIS_OID_GEN_RCV_NO_BUFFER\n", __func__);
411                 if (stats) {
412                         *outbuf = cpu_to_le32(stats->rx_dropped);
413                         retval = 0;
414                 }
415                 break;
416
417         /* ieee802.3 OIDs (table 4-3) */
418
419         /* mandatory */
420         case RNDIS_OID_802_3_PERMANENT_ADDRESS:
421                 pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__);
422                 if (params->dev) {
423                         length = ETH_ALEN;
424                         memcpy(outbuf, params->host_mac, length);
425                         retval = 0;
426                 }
427                 break;
428
429         /* mandatory */
430         case RNDIS_OID_802_3_CURRENT_ADDRESS:
431                 pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__);
432                 if (params->dev) {
433                         length = ETH_ALEN;
434                         memcpy(outbuf, params->host_mac, length);
435                         retval = 0;
436                 }
437                 break;
438
439         /* mandatory */
440         case RNDIS_OID_802_3_MULTICAST_LIST:
441                 pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
442                 /* Multicast base address only */
443                 *outbuf = cpu_to_le32(0xE0000000);
444                 retval = 0;
445                 break;
446
447         /* mandatory */
448         case RNDIS_OID_802_3_MAXIMUM_LIST_SIZE:
449                 pr_debug("%s: RNDIS_OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
450                 /* Multicast base address only */
451                 *outbuf = cpu_to_le32(1);
452                 retval = 0;
453                 break;
454
455         case RNDIS_OID_802_3_MAC_OPTIONS:
456                 pr_debug("%s: RNDIS_OID_802_3_MAC_OPTIONS\n", __func__);
457                 *outbuf = cpu_to_le32(0);
458                 retval = 0;
459                 break;
460
461         /* ieee802.3 statistics OIDs (table 4-4) */
462
463         /* mandatory */
464         case RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT:
465                 pr_debug("%s: RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
466                 if (stats) {
467                         *outbuf = cpu_to_le32(stats->rx_frame_errors);
468                         retval = 0;
469                 }
470                 break;
471
472         /* mandatory */
473         case RNDIS_OID_802_3_XMIT_ONE_COLLISION:
474                 pr_debug("%s: RNDIS_OID_802_3_XMIT_ONE_COLLISION\n", __func__);
475                 *outbuf = cpu_to_le32(0);
476                 retval = 0;
477                 break;
478
479         /* mandatory */
480         case RNDIS_OID_802_3_XMIT_MORE_COLLISIONS:
481                 pr_debug("%s: RNDIS_OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
482                 *outbuf = cpu_to_le32(0);
483                 retval = 0;
484                 break;
485
486         default:
487                 pr_warning("%s: query unknown OID 0x%08X\n",
488                          __func__, OID);
489         }
490         if (retval < 0)
491                 length = 0;
492
493         resp->InformationBufferLength = cpu_to_le32(length);
494         r->length = length + sizeof(*resp);
495         resp->MessageLength = cpu_to_le32(r->length);
496         return retval;
497 }
498
499 static int gen_ndis_set_resp(struct rndis_params *params, u32 OID,
500                              u8 *buf, u32 buf_len, rndis_resp_t *r)
501 {
502         rndis_set_cmplt_type *resp;
503         int i, retval = -ENOTSUPP;
504
505         if (!r)
506                 return -ENOMEM;
507         resp = (rndis_set_cmplt_type *)r->buf;
508         if (!resp)
509                 return -ENOMEM;
510
511         if (buf_len && rndis_debug > 1) {
512                 pr_debug("set OID %08x value, len %d:\n", OID, buf_len);
513                 for (i = 0; i < buf_len; i += 16) {
514                         pr_debug("%03d: %08x %08x %08x %08x\n", i,
515                                 get_unaligned_le32(&buf[i]),
516                                 get_unaligned_le32(&buf[i + 4]),
517                                 get_unaligned_le32(&buf[i + 8]),
518                                 get_unaligned_le32(&buf[i + 12]));
519                 }
520         }
521
522         switch (OID) {
523         case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
524
525                 /* these NDIS_PACKET_TYPE_* bitflags are shared with
526                  * cdc_filter; it's not RNDIS-specific
527                  * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
528                  *      PROMISCUOUS, DIRECTED,
529                  *      MULTICAST, ALL_MULTICAST, BROADCAST
530                  */
531                 *params->filter = (u16)get_unaligned_le32(buf);
532                 pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER %08x\n",
533                         __func__, *params->filter);
534
535                 /* this call has a significant side effect:  it's
536                  * what makes the packet flow start and stop, like
537                  * activating the CDC Ethernet altsetting.
538                  */
539                 retval = 0;
540                 if (*params->filter) {
541                         params->state = RNDIS_DATA_INITIALIZED;
542                         netif_carrier_on(params->dev);
543                         if (netif_running(params->dev))
544                                 netif_wake_queue(params->dev);
545                 } else {
546                         params->state = RNDIS_INITIALIZED;
547                         netif_carrier_off(params->dev);
548                         netif_stop_queue(params->dev);
549                 }
550                 break;
551
552         case RNDIS_OID_802_3_MULTICAST_LIST:
553                 /* I think we can ignore this */
554                 pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
555                 retval = 0;
556                 break;
557
558         default:
559                 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
560                          __func__, OID, buf_len);
561         }
562
563         return retval;
564 }
565
566 /*
567  * Response Functions
568  */
569
570 static int rndis_init_response(struct rndis_params *params,
571                                rndis_init_msg_type *buf)
572 {
573         rndis_init_cmplt_type *resp;
574         rndis_resp_t *r;
575
576         if (!params->dev)
577                 return -ENOTSUPP;
578
579         r = rndis_add_response(params, sizeof(rndis_init_cmplt_type));
580         if (!r)
581                 return -ENOMEM;
582         resp = (rndis_init_cmplt_type *)r->buf;
583
584         resp->MessageType = cpu_to_le32(RNDIS_MSG_INIT_C);
585         resp->MessageLength = cpu_to_le32(52);
586         resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
587         resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
588         resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
589         resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
590         resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
591         resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
592         resp->MaxPacketsPerTransfer = cpu_to_le32(params->max_pkt_per_xfer);
593         resp->MaxTransferSize = cpu_to_le32(params->max_pkt_per_xfer *
594                 (params->dev->mtu
595                 + sizeof(struct ethhdr)
596                 + sizeof(struct rndis_packet_msg_type)
597                 + 22));
598         resp->PacketAlignmentFactor = cpu_to_le32(0);
599         resp->AFListOffset = cpu_to_le32(0);
600         resp->AFListSize = cpu_to_le32(0);
601
602         params->resp_avail(params->v);
603         return 0;
604 }
605
606 static int rndis_query_response(struct rndis_params *params,
607                                 rndis_query_msg_type *buf)
608 {
609         rndis_query_cmplt_type *resp;
610         rndis_resp_t *r;
611
612         /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
613         if (!params->dev)
614                 return -ENOTSUPP;
615
616         /*
617          * we need more memory:
618          * gen_ndis_query_resp expects enough space for
619          * rndis_query_cmplt_type followed by data.
620          * oid_supported_list is the largest data reply
621          */
622         r = rndis_add_response(params,
623                 sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
624         if (!r)
625                 return -ENOMEM;
626         resp = (rndis_query_cmplt_type *)r->buf;
627
628         resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C);
629         resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
630
631         if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID),
632                         le32_to_cpu(buf->InformationBufferOffset)
633                                         + 8 + (u8 *)buf,
634                         le32_to_cpu(buf->InformationBufferLength),
635                         r)) {
636                 /* OID not supported */
637                 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
638                 resp->MessageLength = cpu_to_le32(sizeof *resp);
639                 resp->InformationBufferLength = cpu_to_le32(0);
640                 resp->InformationBufferOffset = cpu_to_le32(0);
641         } else
642                 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
643
644         params->resp_avail(params->v);
645         return 0;
646 }
647
648 static int rndis_set_response(struct rndis_params *params,
649                               rndis_set_msg_type *buf)
650 {
651         u32 BufLength, BufOffset;
652         rndis_set_cmplt_type *resp;
653         rndis_resp_t *r;
654
655         r = rndis_add_response(params, sizeof(rndis_set_cmplt_type));
656         if (!r)
657                 return -ENOMEM;
658         resp = (rndis_set_cmplt_type *)r->buf;
659
660         BufLength = le32_to_cpu(buf->InformationBufferLength);
661         BufOffset = le32_to_cpu(buf->InformationBufferOffset);
662
663 #ifdef  VERBOSE_DEBUG
664         pr_debug("%s: Length: %d\n", __func__, BufLength);
665         pr_debug("%s: Offset: %d\n", __func__, BufOffset);
666         pr_debug("%s: InfoBuffer: ", __func__);
667
668         for (i = 0; i < BufLength; i++) {
669                 pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
670         }
671
672         pr_debug("\n");
673 #endif
674
675         resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C);
676         resp->MessageLength = cpu_to_le32(16);
677         resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
678         if (gen_ndis_set_resp(params, le32_to_cpu(buf->OID),
679                         ((u8 *)buf) + 8 + BufOffset, BufLength, r))
680                 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
681         else
682                 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
683
684         params->resp_avail(params->v);
685         return 0;
686 }
687
688 static int rndis_reset_response(struct rndis_params *params,
689                                 rndis_reset_msg_type *buf)
690 {
691         rndis_reset_cmplt_type *resp;
692         rndis_resp_t *r;
693
694         u32 length;
695         u8 *xbuf;
696
697         /* drain the response queue */
698         while ((xbuf = rndis_get_next_response(params, &length)))
699                 rndis_free_response(params, xbuf);
700
701         r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type));
702         if (!r)
703                 return -ENOMEM;
704         resp = (rndis_reset_cmplt_type *)r->buf;
705
706         resp->MessageType = cpu_to_le32(RNDIS_MSG_RESET_C);
707         resp->MessageLength = cpu_to_le32(16);
708         resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
709         /* resent information */
710         resp->AddressingReset = cpu_to_le32(1);
711
712         params->resp_avail(params->v);
713         return 0;
714 }
715
716 static int rndis_keepalive_response(struct rndis_params *params,
717                                     rndis_keepalive_msg_type *buf)
718 {
719         rndis_keepalive_cmplt_type *resp;
720         rndis_resp_t *r;
721
722         /* host "should" check only in RNDIS_DATA_INITIALIZED state */
723
724         r = rndis_add_response(params, sizeof(rndis_keepalive_cmplt_type));
725         if (!r)
726                 return -ENOMEM;
727         resp = (rndis_keepalive_cmplt_type *)r->buf;
728
729         resp->MessageType = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C);
730         resp->MessageLength = cpu_to_le32(16);
731         resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
732         resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
733
734         params->resp_avail(params->v);
735         return 0;
736 }
737
738
739 /*
740  * Device to Host Comunication
741  */
742 static int rndis_indicate_status_msg(struct rndis_params *params, u32 status)
743 {
744         rndis_indicate_status_msg_type *resp;
745         rndis_resp_t *r;
746
747         if (params->state == RNDIS_UNINITIALIZED)
748                 return -ENOTSUPP;
749
750         r = rndis_add_response(params, sizeof(rndis_indicate_status_msg_type));
751         if (!r)
752                 return -ENOMEM;
753         resp = (rndis_indicate_status_msg_type *)r->buf;
754
755         resp->MessageType = cpu_to_le32(RNDIS_MSG_INDICATE);
756         resp->MessageLength = cpu_to_le32(20);
757         resp->Status = cpu_to_le32(status);
758         resp->StatusBufferLength = cpu_to_le32(0);
759         resp->StatusBufferOffset = cpu_to_le32(0);
760
761         params->resp_avail(params->v);
762         return 0;
763 }
764
765 int rndis_signal_connect(struct rndis_params *params)
766 {
767         params->media_state = RNDIS_MEDIA_STATE_CONNECTED;
768         return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_CONNECT);
769 }
770 EXPORT_SYMBOL_GPL(rndis_signal_connect);
771
772 int rndis_signal_disconnect(struct rndis_params *params)
773 {
774         params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
775         return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_DISCONNECT);
776 }
777 EXPORT_SYMBOL_GPL(rndis_signal_disconnect);
778
779 void rndis_uninit(struct rndis_params *params)
780 {
781         u8 *buf;
782         u32 length;
783
784         if (!params)
785                 return;
786         params->state = RNDIS_UNINITIALIZED;
787
788         /* drain the response queue */
789         while ((buf = rndis_get_next_response(params, &length)))
790                 rndis_free_response(params, buf);
791 }
792 EXPORT_SYMBOL_GPL(rndis_uninit);
793
794 void rndis_set_host_mac(struct rndis_params *params, const u8 *addr)
795 {
796         params->host_mac = addr;
797 }
798 EXPORT_SYMBOL_GPL(rndis_set_host_mac);
799
800 /*
801  * Message Parser
802  */
803 int rndis_msg_parser(struct rndis_params *params, u8 *buf)
804 {
805         u32 MsgType, MsgLength;
806         __le32 *tmp;
807
808         if (!buf)
809                 return -ENOMEM;
810
811         tmp = (__le32 *)buf;
812         MsgType   = get_unaligned_le32(tmp++);
813         MsgLength = get_unaligned_le32(tmp++);
814
815         if (!params)
816                 return -ENOTSUPP;
817
818         /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
819          * rx/tx statistics and link status, in addition to KEEPALIVE traffic
820          * and normal HC level polling to see if there's any IN traffic.
821          */
822
823         /* For USB: responses may take up to 10 seconds */
824         switch (MsgType) {
825         case RNDIS_MSG_INIT:
826                 pr_debug("%s: RNDIS_MSG_INIT\n",
827                         __func__);
828                 params->state = RNDIS_INITIALIZED;
829                 return rndis_init_response(params, (rndis_init_msg_type *)buf);
830
831         case RNDIS_MSG_HALT:
832                 pr_debug("%s: RNDIS_MSG_HALT\n",
833                         __func__);
834                 params->state = RNDIS_UNINITIALIZED;
835                 if (params->dev) {
836                         netif_carrier_off(params->dev);
837                         netif_stop_queue(params->dev);
838                 }
839                 return 0;
840
841         case RNDIS_MSG_QUERY:
842                 return rndis_query_response(params,
843                                         (rndis_query_msg_type *)buf);
844
845         case RNDIS_MSG_SET:
846                 return rndis_set_response(params, (rndis_set_msg_type *)buf);
847
848         case RNDIS_MSG_RESET:
849                 pr_debug("%s: RNDIS_MSG_RESET\n",
850                         __func__);
851                 return rndis_reset_response(params,
852                                         (rndis_reset_msg_type *)buf);
853
854         case RNDIS_MSG_KEEPALIVE:
855                 /* For USB: host does this every 5 seconds */
856                 if (rndis_debug > 1)
857                         pr_debug("%s: RNDIS_MSG_KEEPALIVE\n",
858                                 __func__);
859                 return rndis_keepalive_response(params,
860                                                  (rndis_keepalive_msg_type *)
861                                                  buf);
862
863         default:
864                 /* At least Windows XP emits some undefined RNDIS messages.
865                  * In one case those messages seemed to relate to the host
866                  * suspending itself.
867                  */
868                 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
869                         __func__, MsgType, MsgLength);
870                 print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
871                                      buf, MsgLength);
872                 break;
873         }
874
875         return -ENOTSUPP;
876 }
877 EXPORT_SYMBOL_GPL(rndis_msg_parser);
878
879 static inline int rndis_get_nr(void)
880 {
881         return ida_simple_get(&rndis_ida, 0, 0, GFP_KERNEL);
882 }
883
884 static inline void rndis_put_nr(int nr)
885 {
886         ida_simple_remove(&rndis_ida, nr);
887 }
888
889 struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v)
890 {
891         struct rndis_params *params;
892         int i;
893
894         if (!resp_avail)
895                 return ERR_PTR(-EINVAL);
896
897         i = rndis_get_nr();
898         if (i < 0) {
899                 pr_debug("failed\n");
900
901                 return ERR_PTR(-ENODEV);
902         }
903
904         params = kzalloc(sizeof(*params), GFP_KERNEL);
905         if (!params) {
906                 rndis_put_nr(i);
907
908                 return ERR_PTR(-ENOMEM);
909         }
910
911 #ifdef  CONFIG_USB_GADGET_DEBUG_FILES
912         {
913                 struct proc_dir_entry *proc_entry;
914                 char name[20];
915
916                 sprintf(name, NAME_TEMPLATE, i);
917                 proc_entry = proc_create_data(name, 0660, NULL,
918                                               &rndis_proc_fops, params);
919                 if (!proc_entry) {
920                         kfree(params);
921                         rndis_put_nr(i);
922
923                         return ERR_PTR(-EIO);
924                 }
925         }
926 #endif
927
928         params->confignr = i;
929         params->used = 1;
930         params->state = RNDIS_UNINITIALIZED;
931         params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
932         params->resp_avail = resp_avail;
933         params->v = v;
934         INIT_LIST_HEAD(&(params->resp_queue));
935         pr_debug("%s: configNr = %d\n", __func__, i);
936
937         return params;
938 }
939 EXPORT_SYMBOL_GPL(rndis_register);
940
941 void rndis_deregister(struct rndis_params *params)
942 {
943         int i;
944
945         pr_debug("%s:\n", __func__);
946
947         if (!params)
948                 return;
949
950         i = params->confignr;
951
952 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
953         {
954                 char name[20];
955
956                 sprintf(name, NAME_TEMPLATE, i);
957                 remove_proc_entry(name, NULL);
958         }
959 #endif
960
961         kfree(params);
962         rndis_put_nr(i);
963 }
964 EXPORT_SYMBOL_GPL(rndis_deregister);
965 int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev,
966                         u16 *cdc_filter)
967 {
968         pr_debug("%s:\n", __func__);
969         if (!dev)
970                 return -EINVAL;
971         if (!params)
972                 return -1;
973
974         params->dev = dev;
975         params->filter = cdc_filter;
976
977         rndis_ul_max_xfer_size_rcvd = 0;
978         rndis_ul_max_pkt_per_xfer_rcvd = 0;
979         return 0;
980 }
981 EXPORT_SYMBOL_GPL(rndis_set_param_dev);
982
983 int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID,
984                            const char *vendorDescr)
985 {
986         pr_debug("%s:\n", __func__);
987         if (!vendorDescr) return -1;
988         if (!params)
989                 return -1;
990
991         params->vendorID = vendorID;
992         params->vendorDescr = vendorDescr;
993
994         return 0;
995 }
996 EXPORT_SYMBOL_GPL(rndis_set_param_vendor);
997
998 int rndis_set_param_medium(struct rndis_params *params, u32 medium, u32 speed)
999 {
1000         pr_debug("%s: %u %u\n", __func__, medium, speed);
1001         if (!params)
1002                 return -1;
1003
1004         params->medium = medium;
1005         params->speed = speed;
1006
1007         return 0;
1008 }
1009 EXPORT_SYMBOL_GPL(rndis_set_param_medium);
1010
1011 void rndis_set_max_pkt_xfer(struct rndis_params *params, u8 max_pkt_per_xfer)
1012 {
1013         pr_debug("%s:\n", __func__);
1014
1015         params->max_pkt_per_xfer = max_pkt_per_xfer;
1016 }
1017
1018 void rndis_add_hdr(struct sk_buff *skb)
1019 {
1020         struct rndis_packet_msg_type *header;
1021
1022         if (!skb)
1023                 return;
1024         header = (void *)skb_push(skb, sizeof(*header));
1025         memset(header, 0, sizeof *header);
1026         header->MessageType = cpu_to_le32(RNDIS_MSG_PACKET);
1027         header->MessageLength = cpu_to_le32(skb->len);
1028         header->DataOffset = cpu_to_le32(36);
1029         header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
1030 }
1031 EXPORT_SYMBOL_GPL(rndis_add_hdr);
1032
1033 void rndis_free_response(struct rndis_params *params, u8 *buf)
1034 {
1035         rndis_resp_t *r;
1036         struct list_head *act, *tmp;
1037
1038         list_for_each_safe(act, tmp, &(params->resp_queue))
1039         {
1040                 r = list_entry(act, rndis_resp_t, list);
1041                 if (r && r->buf == buf) {
1042                         list_del(&r->list);
1043                         kfree(r);
1044                 }
1045         }
1046 }
1047 EXPORT_SYMBOL_GPL(rndis_free_response);
1048
1049 u8 *rndis_get_next_response(struct rndis_params *params, u32 *length)
1050 {
1051         rndis_resp_t *r;
1052         struct list_head *act, *tmp;
1053
1054         if (!length) return NULL;
1055
1056         list_for_each_safe(act, tmp, &(params->resp_queue))
1057         {
1058                 r = list_entry(act, rndis_resp_t, list);
1059                 if (!r->send) {
1060                         r->send = 1;
1061                         *length = r->length;
1062                         return r->buf;
1063                 }
1064         }
1065
1066         return NULL;
1067 }
1068 EXPORT_SYMBOL_GPL(rndis_get_next_response);
1069
1070 static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length)
1071 {
1072         rndis_resp_t *r;
1073
1074         /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1075         r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
1076         if (!r) return NULL;
1077
1078         r->buf = (u8 *)(r + 1);
1079         r->length = length;
1080         r->send = 0;
1081
1082         list_add_tail(&r->list, &(params->resp_queue));
1083         return r;
1084 }
1085
1086 int rndis_rm_hdr(struct gether *port,
1087                         struct sk_buff *skb,
1088                         struct sk_buff_head *list)
1089 {
1090         int num_pkts = 1;
1091
1092         if (skb->len > rndis_ul_max_xfer_size_rcvd)
1093                 rndis_ul_max_xfer_size_rcvd = skb->len;
1094
1095         while (skb->len) {
1096                 struct rndis_packet_msg_type *hdr;
1097                 struct sk_buff          *skb2;
1098                 u32             msg_len, data_offset, data_len;
1099
1100                 /* some rndis hosts send extra byte to avoid zlp, ignore it */
1101                 if (skb->len == 1) {
1102                         dev_kfree_skb_any(skb);
1103                         return 0;
1104                 }
1105
1106                 if (skb->len < sizeof *hdr) {
1107                         pr_err("invalid rndis pkt: skblen:%u hdr_len:%zu",
1108                                         skb->len, sizeof *hdr);
1109                         dev_kfree_skb_any(skb);
1110                         return -EINVAL;
1111                 }
1112
1113                 hdr = (void *)skb->data;
1114                 msg_len = le32_to_cpu(hdr->MessageLength);
1115                 data_offset = le32_to_cpu(hdr->DataOffset);
1116                 data_len = le32_to_cpu(hdr->DataLength);
1117
1118                 if (skb->len < msg_len ||
1119                                 ((data_offset + data_len + 8) > msg_len)) {
1120                         pr_err("invalid rndis message: %d/%d/%d/%d, len:%d\n",
1121                                         le32_to_cpu(hdr->MessageType),
1122                                         msg_len, data_offset, data_len, skb->len);
1123                         dev_kfree_skb_any(skb);
1124                         return -EOVERFLOW;
1125                 }
1126                 if (le32_to_cpu(hdr->MessageType) != RNDIS_MSG_PACKET) {
1127                         pr_err("invalid rndis message: %d/%d/%d/%d, len:%d\n",
1128                                         le32_to_cpu(hdr->MessageType),
1129                                         msg_len, data_offset, data_len, skb->len);
1130                         dev_kfree_skb_any(skb);
1131                         return -EINVAL;
1132                 }
1133
1134                 skb_pull(skb, data_offset + 8);
1135
1136                 if (msg_len == skb->len) {
1137                         skb_trim(skb, data_len);
1138                         break;
1139                 }
1140
1141                 skb2 = skb_clone(skb, GFP_ATOMIC);
1142                 if (!skb2) {
1143                         pr_err("%s:skb clone failed\n", __func__);
1144                         dev_kfree_skb_any(skb);
1145                         return -ENOMEM;
1146                 }
1147
1148                 skb_pull(skb, msg_len - sizeof *hdr);
1149                 skb_trim(skb2, data_len);
1150                 skb_queue_tail(list, skb2);
1151
1152                 num_pkts++;
1153         }
1154
1155         if (num_pkts > rndis_ul_max_pkt_per_xfer_rcvd)
1156                 rndis_ul_max_pkt_per_xfer_rcvd = num_pkts;
1157
1158         skb_queue_tail(list, skb);
1159         return 0;
1160 }
1161 EXPORT_SYMBOL_GPL(rndis_rm_hdr);
1162
1163 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1164
1165 static int rndis_proc_show(struct seq_file *m, void *v)
1166 {
1167         rndis_params *param = m->private;
1168
1169         seq_printf(m,
1170                          "Config Nr. %d\n"
1171                          "used      : %s\n"
1172                          "state     : %s\n"
1173                          "medium    : 0x%08X\n"
1174                          "speed     : %d\n"
1175                          "cable     : %s\n"
1176                          "vendor ID : 0x%08X\n"
1177                          "vendor    : %s\n",
1178                          param->confignr, (param->used) ? "y" : "n",
1179                          ({ char *s = "?";
1180                          switch (param->state) {
1181                          case RNDIS_UNINITIALIZED:
1182                                 s = "RNDIS_UNINITIALIZED"; break;
1183                          case RNDIS_INITIALIZED:
1184                                 s = "RNDIS_INITIALIZED"; break;
1185                          case RNDIS_DATA_INITIALIZED:
1186                                 s = "RNDIS_DATA_INITIALIZED"; break;
1187                         } s; }),
1188                          param->medium,
1189                          (param->media_state) ? 0 : param->speed*100,
1190                          (param->media_state) ? "disconnected" : "connected",
1191                          param->vendorID, param->vendorDescr);
1192         return 0;
1193 }
1194
1195 static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1196                                 size_t count, loff_t *ppos)
1197 {
1198         rndis_params *p = PDE_DATA(file_inode(file));
1199         u32 speed = 0;
1200         int i, fl_speed = 0;
1201
1202         for (i = 0; i < count; i++) {
1203                 char c;
1204                 if (get_user(c, buffer))
1205                         return -EFAULT;
1206                 switch (c) {
1207                 case '0':
1208                 case '1':
1209                 case '2':
1210                 case '3':
1211                 case '4':
1212                 case '5':
1213                 case '6':
1214                 case '7':
1215                 case '8':
1216                 case '9':
1217                         fl_speed = 1;
1218                         speed = speed * 10 + c - '0';
1219                         break;
1220                 case 'C':
1221                 case 'c':
1222                         rndis_signal_connect(p);
1223                         break;
1224                 case 'D':
1225                 case 'd':
1226                         rndis_signal_disconnect(p);
1227                         break;
1228                 default:
1229                         if (fl_speed) p->speed = speed;
1230                         else pr_debug("%c is not valid\n", c);
1231                         break;
1232                 }
1233
1234                 buffer++;
1235         }
1236
1237         return count;
1238 }
1239
1240 static int rndis_proc_open(struct inode *inode, struct file *file)
1241 {
1242         return single_open(file, rndis_proc_show, PDE_DATA(inode));
1243 }
1244
1245 static const struct file_operations rndis_proc_fops = {
1246         .owner          = THIS_MODULE,
1247         .open           = rndis_proc_open,
1248         .read           = seq_read,
1249         .llseek         = seq_lseek,
1250         .release        = single_release,
1251         .write          = rndis_proc_write,
1252 };
1253
1254 #define NAME_TEMPLATE "driver/rndis-%03d"
1255
1256 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */