xref: /linux/drivers/usb/gadget/function/rndis.c (revision 83210e59ee1527f229af6aef78c95b747bdcf9c4)
100a2430fSAndrzej Pietrasiewicz /*
200a2430fSAndrzej Pietrasiewicz  * RNDIS MSG parser
300a2430fSAndrzej Pietrasiewicz  *
400a2430fSAndrzej Pietrasiewicz  * Authors:	Benedikt Spranger, Pengutronix
500a2430fSAndrzej Pietrasiewicz  *		Robert Schwebel, Pengutronix
600a2430fSAndrzej Pietrasiewicz  *
700a2430fSAndrzej Pietrasiewicz  *              This program is free software; you can redistribute it and/or
800a2430fSAndrzej Pietrasiewicz  *              modify it under the terms of the GNU General Public License
900a2430fSAndrzej Pietrasiewicz  *              version 2, as published by the Free Software Foundation.
1000a2430fSAndrzej Pietrasiewicz  *
1100a2430fSAndrzej Pietrasiewicz  *		This software was originally developed in conformance with
1200a2430fSAndrzej Pietrasiewicz  *		Microsoft's Remote NDIS Specification License Agreement.
1300a2430fSAndrzej Pietrasiewicz  *
1400a2430fSAndrzej Pietrasiewicz  * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
1500a2430fSAndrzej Pietrasiewicz  *		Fixed message length bug in init_response
1600a2430fSAndrzej Pietrasiewicz  *
1700a2430fSAndrzej Pietrasiewicz  * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
1800a2430fSAndrzej Pietrasiewicz  *		Fixed rndis_rm_hdr length bug.
1900a2430fSAndrzej Pietrasiewicz  *
2000a2430fSAndrzej Pietrasiewicz  * Copyright (C) 2004 by David Brownell
2100a2430fSAndrzej Pietrasiewicz  *		updates to merge with Linux 2.6, better match RNDIS spec
2200a2430fSAndrzej Pietrasiewicz  */
2300a2430fSAndrzej Pietrasiewicz 
2400a2430fSAndrzej Pietrasiewicz #include <linux/module.h>
2500a2430fSAndrzej Pietrasiewicz #include <linux/moduleparam.h>
2600a2430fSAndrzej Pietrasiewicz #include <linux/kernel.h>
2700a2430fSAndrzej Pietrasiewicz #include <linux/errno.h>
2800a2430fSAndrzej Pietrasiewicz #include <linux/list.h>
2900a2430fSAndrzej Pietrasiewicz #include <linux/proc_fs.h>
3000a2430fSAndrzej Pietrasiewicz #include <linux/slab.h>
3100a2430fSAndrzej Pietrasiewicz #include <linux/seq_file.h>
3200a2430fSAndrzej Pietrasiewicz #include <linux/netdevice.h>
3300a2430fSAndrzej Pietrasiewicz 
3400a2430fSAndrzej Pietrasiewicz #include <asm/io.h>
3500a2430fSAndrzej Pietrasiewicz #include <asm/byteorder.h>
3600a2430fSAndrzej Pietrasiewicz #include <asm/unaligned.h>
3700a2430fSAndrzej Pietrasiewicz 
3800a2430fSAndrzej Pietrasiewicz #include "u_rndis.h"
3900a2430fSAndrzej Pietrasiewicz 
4000a2430fSAndrzej Pietrasiewicz #undef	VERBOSE_DEBUG
4100a2430fSAndrzej Pietrasiewicz 
4200a2430fSAndrzej Pietrasiewicz #include "rndis.h"
4300a2430fSAndrzej Pietrasiewicz 
4400a2430fSAndrzej Pietrasiewicz 
4500a2430fSAndrzej Pietrasiewicz /* The driver for your USB chip needs to support ep0 OUT to work with
4600a2430fSAndrzej Pietrasiewicz  * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
4700a2430fSAndrzej Pietrasiewicz  *
4800a2430fSAndrzej Pietrasiewicz  * Windows hosts need an INF file like Documentation/usb/linux.inf
4900a2430fSAndrzej Pietrasiewicz  * and will be happier if you provide the host_addr module parameter.
5000a2430fSAndrzej Pietrasiewicz  */
5100a2430fSAndrzej Pietrasiewicz 
5200a2430fSAndrzej Pietrasiewicz #if 0
5300a2430fSAndrzej Pietrasiewicz static int rndis_debug = 0;
5400a2430fSAndrzej Pietrasiewicz module_param (rndis_debug, int, 0);
5500a2430fSAndrzej Pietrasiewicz MODULE_PARM_DESC (rndis_debug, "enable debugging");
5600a2430fSAndrzej Pietrasiewicz #else
5700a2430fSAndrzej Pietrasiewicz #define rndis_debug		0
5800a2430fSAndrzej Pietrasiewicz #endif
5900a2430fSAndrzej Pietrasiewicz 
6000a2430fSAndrzej Pietrasiewicz #define RNDIS_MAX_CONFIGS	1
6100a2430fSAndrzej Pietrasiewicz 
6200a2430fSAndrzej Pietrasiewicz 
6300a2430fSAndrzej Pietrasiewicz static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS];
6400a2430fSAndrzej Pietrasiewicz 
6500a2430fSAndrzej Pietrasiewicz /* Driver Version */
6600a2430fSAndrzej Pietrasiewicz static const __le32 rndis_driver_version = cpu_to_le32(1);
6700a2430fSAndrzej Pietrasiewicz 
6800a2430fSAndrzej Pietrasiewicz /* Function Prototypes */
69*83210e59SAndrzej Pietrasiewicz static rndis_resp_t *rndis_add_response(struct rndis_params *params,
70*83210e59SAndrzej Pietrasiewicz 					u32 length);
7100a2430fSAndrzej Pietrasiewicz 
7200a2430fSAndrzej Pietrasiewicz 
7300a2430fSAndrzej Pietrasiewicz /* supported OIDs */
7400a2430fSAndrzej Pietrasiewicz static const u32 oid_supported_list[] =
7500a2430fSAndrzej Pietrasiewicz {
7600a2430fSAndrzej Pietrasiewicz 	/* the general stuff */
7700a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_SUPPORTED_LIST,
7800a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_HARDWARE_STATUS,
7900a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MEDIA_SUPPORTED,
8000a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MEDIA_IN_USE,
8100a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE,
8200a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_LINK_SPEED,
8300a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE,
8400a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE,
8500a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_VENDOR_ID,
8600a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_VENDOR_DESCRIPTION,
8700a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_VENDOR_DRIVER_VERSION,
8800a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
8900a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE,
9000a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
9100a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_PHYSICAL_MEDIUM,
9200a2430fSAndrzej Pietrasiewicz 
9300a2430fSAndrzej Pietrasiewicz 	/* the statistical stuff */
9400a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_XMIT_OK,
9500a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_RCV_OK,
9600a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_XMIT_ERROR,
9700a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_RCV_ERROR,
9800a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_RCV_NO_BUFFER,
9900a2430fSAndrzej Pietrasiewicz #ifdef	RNDIS_OPTIONAL_STATS
10000a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_DIRECTED_BYTES_XMIT,
10100a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT,
10200a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MULTICAST_BYTES_XMIT,
10300a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT,
10400a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_BROADCAST_BYTES_XMIT,
10500a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT,
10600a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_DIRECTED_BYTES_RCV,
10700a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_DIRECTED_FRAMES_RCV,
10800a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MULTICAST_BYTES_RCV,
10900a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_MULTICAST_FRAMES_RCV,
11000a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_BROADCAST_BYTES_RCV,
11100a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_BROADCAST_FRAMES_RCV,
11200a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_RCV_CRC_ERROR,
11300a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH,
11400a2430fSAndrzej Pietrasiewicz #endif	/* RNDIS_OPTIONAL_STATS */
11500a2430fSAndrzej Pietrasiewicz 
11600a2430fSAndrzej Pietrasiewicz 	/* mandatory 802.3 */
11700a2430fSAndrzej Pietrasiewicz 	/* the general stuff */
11800a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_PERMANENT_ADDRESS,
11900a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_CURRENT_ADDRESS,
12000a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_MULTICAST_LIST,
12100a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_MAC_OPTIONS,
12200a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_MAXIMUM_LIST_SIZE,
12300a2430fSAndrzej Pietrasiewicz 
12400a2430fSAndrzej Pietrasiewicz 	/* the statistical stuff */
12500a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT,
12600a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_ONE_COLLISION,
12700a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_MORE_COLLISIONS,
12800a2430fSAndrzej Pietrasiewicz #ifdef	RNDIS_OPTIONAL_STATS
12900a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_DEFERRED,
13000a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_MAX_COLLISIONS,
13100a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_RCV_OVERRUN,
13200a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_UNDERRUN,
13300a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE,
13400a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST,
13500a2430fSAndrzej Pietrasiewicz 	RNDIS_OID_802_3_XMIT_LATE_COLLISIONS,
13600a2430fSAndrzej Pietrasiewicz #endif	/* RNDIS_OPTIONAL_STATS */
13700a2430fSAndrzej Pietrasiewicz 
13800a2430fSAndrzej Pietrasiewicz #ifdef	RNDIS_PM
13900a2430fSAndrzej Pietrasiewicz 	/* PM and wakeup are "mandatory" for USB, but the RNDIS specs
14000a2430fSAndrzej Pietrasiewicz 	 * don't say what they mean ... and the NDIS specs are often
14100a2430fSAndrzej Pietrasiewicz 	 * confusing and/or ambiguous in this context.  (That is, more
14200a2430fSAndrzej Pietrasiewicz 	 * so than their specs for the other OIDs.)
14300a2430fSAndrzej Pietrasiewicz 	 *
14400a2430fSAndrzej Pietrasiewicz 	 * FIXME someone who knows what these should do, please
14500a2430fSAndrzej Pietrasiewicz 	 * implement them!
14600a2430fSAndrzej Pietrasiewicz 	 */
14700a2430fSAndrzej Pietrasiewicz 
14800a2430fSAndrzej Pietrasiewicz 	/* power management */
14900a2430fSAndrzej Pietrasiewicz 	OID_PNP_CAPABILITIES,
15000a2430fSAndrzej Pietrasiewicz 	OID_PNP_QUERY_POWER,
15100a2430fSAndrzej Pietrasiewicz 	OID_PNP_SET_POWER,
15200a2430fSAndrzej Pietrasiewicz 
15300a2430fSAndrzej Pietrasiewicz #ifdef	RNDIS_WAKEUP
15400a2430fSAndrzej Pietrasiewicz 	/* wake up host */
15500a2430fSAndrzej Pietrasiewicz 	OID_PNP_ENABLE_WAKE_UP,
15600a2430fSAndrzej Pietrasiewicz 	OID_PNP_ADD_WAKE_UP_PATTERN,
15700a2430fSAndrzej Pietrasiewicz 	OID_PNP_REMOVE_WAKE_UP_PATTERN,
15800a2430fSAndrzej Pietrasiewicz #endif	/* RNDIS_WAKEUP */
15900a2430fSAndrzej Pietrasiewicz #endif	/* RNDIS_PM */
16000a2430fSAndrzej Pietrasiewicz };
16100a2430fSAndrzej Pietrasiewicz 
16200a2430fSAndrzej Pietrasiewicz 
16300a2430fSAndrzej Pietrasiewicz /* NDIS Functions */
164*83210e59SAndrzej Pietrasiewicz static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf,
16500a2430fSAndrzej Pietrasiewicz 			       unsigned buf_len, rndis_resp_t *r)
16600a2430fSAndrzej Pietrasiewicz {
16700a2430fSAndrzej Pietrasiewicz 	int retval = -ENOTSUPP;
16800a2430fSAndrzej Pietrasiewicz 	u32 length = 4;	/* usually */
16900a2430fSAndrzej Pietrasiewicz 	__le32 *outbuf;
17000a2430fSAndrzej Pietrasiewicz 	int i, count;
17100a2430fSAndrzej Pietrasiewicz 	rndis_query_cmplt_type *resp;
17200a2430fSAndrzej Pietrasiewicz 	struct net_device *net;
17300a2430fSAndrzej Pietrasiewicz 	struct rtnl_link_stats64 temp;
17400a2430fSAndrzej Pietrasiewicz 	const struct rtnl_link_stats64 *stats;
17500a2430fSAndrzej Pietrasiewicz 
17600a2430fSAndrzej Pietrasiewicz 	if (!r) return -ENOMEM;
17700a2430fSAndrzej Pietrasiewicz 	resp = (rndis_query_cmplt_type *)r->buf;
17800a2430fSAndrzej Pietrasiewicz 
17900a2430fSAndrzej Pietrasiewicz 	if (!resp) return -ENOMEM;
18000a2430fSAndrzej Pietrasiewicz 
18100a2430fSAndrzej Pietrasiewicz 	if (buf_len && rndis_debug > 1) {
18200a2430fSAndrzej Pietrasiewicz 		pr_debug("query OID %08x value, len %d:\n", OID, buf_len);
18300a2430fSAndrzej Pietrasiewicz 		for (i = 0; i < buf_len; i += 16) {
18400a2430fSAndrzej Pietrasiewicz 			pr_debug("%03d: %08x %08x %08x %08x\n", i,
18500a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i]),
18600a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i + 4]),
18700a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i + 8]),
18800a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i + 12]));
18900a2430fSAndrzej Pietrasiewicz 		}
19000a2430fSAndrzej Pietrasiewicz 	}
19100a2430fSAndrzej Pietrasiewicz 
19200a2430fSAndrzej Pietrasiewicz 	/* response goes here, right after the header */
19300a2430fSAndrzej Pietrasiewicz 	outbuf = (__le32 *)&resp[1];
19400a2430fSAndrzej Pietrasiewicz 	resp->InformationBufferOffset = cpu_to_le32(16);
19500a2430fSAndrzej Pietrasiewicz 
196*83210e59SAndrzej Pietrasiewicz 	net = params->dev;
19700a2430fSAndrzej Pietrasiewicz 	stats = dev_get_stats(net, &temp);
19800a2430fSAndrzej Pietrasiewicz 
19900a2430fSAndrzej Pietrasiewicz 	switch (OID) {
20000a2430fSAndrzej Pietrasiewicz 
20100a2430fSAndrzej Pietrasiewicz 	/* general oids (table 4-1) */
20200a2430fSAndrzej Pietrasiewicz 
20300a2430fSAndrzej Pietrasiewicz 	/* mandatory */
20400a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_SUPPORTED_LIST:
20500a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_SUPPORTED_LIST\n", __func__);
20600a2430fSAndrzej Pietrasiewicz 		length = sizeof(oid_supported_list);
20700a2430fSAndrzej Pietrasiewicz 		count  = length / sizeof(u32);
20800a2430fSAndrzej Pietrasiewicz 		for (i = 0; i < count; i++)
20900a2430fSAndrzej Pietrasiewicz 			outbuf[i] = cpu_to_le32(oid_supported_list[i]);
21000a2430fSAndrzej Pietrasiewicz 		retval = 0;
21100a2430fSAndrzej Pietrasiewicz 		break;
21200a2430fSAndrzej Pietrasiewicz 
21300a2430fSAndrzej Pietrasiewicz 	/* mandatory */
21400a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_HARDWARE_STATUS:
21500a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_HARDWARE_STATUS\n", __func__);
21600a2430fSAndrzej Pietrasiewicz 		/* Bogus question!
21700a2430fSAndrzej Pietrasiewicz 		 * Hardware must be ready to receive high level protocols.
21800a2430fSAndrzej Pietrasiewicz 		 * BTW:
21900a2430fSAndrzej Pietrasiewicz 		 * reddite ergo quae sunt Caesaris Caesari
22000a2430fSAndrzej Pietrasiewicz 		 * et quae sunt Dei Deo!
22100a2430fSAndrzej Pietrasiewicz 		 */
22200a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(0);
22300a2430fSAndrzej Pietrasiewicz 		retval = 0;
22400a2430fSAndrzej Pietrasiewicz 		break;
22500a2430fSAndrzej Pietrasiewicz 
22600a2430fSAndrzej Pietrasiewicz 	/* mandatory */
22700a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_MEDIA_SUPPORTED:
22800a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__);
229*83210e59SAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(params->medium);
23000a2430fSAndrzej Pietrasiewicz 		retval = 0;
23100a2430fSAndrzej Pietrasiewicz 		break;
23200a2430fSAndrzej Pietrasiewicz 
23300a2430fSAndrzej Pietrasiewicz 	/* mandatory */
23400a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_MEDIA_IN_USE:
23500a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__);
23600a2430fSAndrzej Pietrasiewicz 		/* one medium, one transport... (maybe you do it better) */
237*83210e59SAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(params->medium);
23800a2430fSAndrzej Pietrasiewicz 		retval = 0;
23900a2430fSAndrzej Pietrasiewicz 		break;
24000a2430fSAndrzej Pietrasiewicz 
24100a2430fSAndrzej Pietrasiewicz 	/* mandatory */
24200a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE:
24300a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
244*83210e59SAndrzej Pietrasiewicz 		if (params->dev) {
245*83210e59SAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(params->dev->mtu);
24600a2430fSAndrzej Pietrasiewicz 			retval = 0;
24700a2430fSAndrzej Pietrasiewicz 		}
24800a2430fSAndrzej Pietrasiewicz 		break;
24900a2430fSAndrzej Pietrasiewicz 
25000a2430fSAndrzej Pietrasiewicz 	/* mandatory */
25100a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_LINK_SPEED:
25200a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
25300a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__);
254*83210e59SAndrzej Pietrasiewicz 		if (params->media_state == RNDIS_MEDIA_STATE_DISCONNECTED)
25500a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(0);
25600a2430fSAndrzej Pietrasiewicz 		else
257*83210e59SAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(params->speed);
25800a2430fSAndrzej Pietrasiewicz 		retval = 0;
25900a2430fSAndrzej Pietrasiewicz 		break;
26000a2430fSAndrzej Pietrasiewicz 
26100a2430fSAndrzej Pietrasiewicz 	/* mandatory */
26200a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE:
26300a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
264*83210e59SAndrzej Pietrasiewicz 		if (params->dev) {
265*83210e59SAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(params->dev->mtu);
26600a2430fSAndrzej Pietrasiewicz 			retval = 0;
26700a2430fSAndrzej Pietrasiewicz 		}
26800a2430fSAndrzej Pietrasiewicz 		break;
26900a2430fSAndrzej Pietrasiewicz 
27000a2430fSAndrzej Pietrasiewicz 	/* mandatory */
27100a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE:
27200a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
273*83210e59SAndrzej Pietrasiewicz 		if (params->dev) {
274*83210e59SAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(params->dev->mtu);
27500a2430fSAndrzej Pietrasiewicz 			retval = 0;
27600a2430fSAndrzej Pietrasiewicz 		}
27700a2430fSAndrzej Pietrasiewicz 		break;
27800a2430fSAndrzej Pietrasiewicz 
27900a2430fSAndrzej Pietrasiewicz 	/* mandatory */
28000a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_VENDOR_ID:
28100a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__);
282*83210e59SAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(params->vendorID);
28300a2430fSAndrzej Pietrasiewicz 		retval = 0;
28400a2430fSAndrzej Pietrasiewicz 		break;
28500a2430fSAndrzej Pietrasiewicz 
28600a2430fSAndrzej Pietrasiewicz 	/* mandatory */
28700a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_VENDOR_DESCRIPTION:
28800a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__);
289*83210e59SAndrzej Pietrasiewicz 		if (params->vendorDescr) {
290*83210e59SAndrzej Pietrasiewicz 			length = strlen(params->vendorDescr);
291*83210e59SAndrzej Pietrasiewicz 			memcpy(outbuf, params->vendorDescr, length);
29200a2430fSAndrzej Pietrasiewicz 		} else {
29300a2430fSAndrzej Pietrasiewicz 			outbuf[0] = 0;
29400a2430fSAndrzej Pietrasiewicz 		}
29500a2430fSAndrzej Pietrasiewicz 		retval = 0;
29600a2430fSAndrzej Pietrasiewicz 		break;
29700a2430fSAndrzej Pietrasiewicz 
29800a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_VENDOR_DRIVER_VERSION:
29900a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
30000a2430fSAndrzej Pietrasiewicz 		/* Created as LE */
30100a2430fSAndrzej Pietrasiewicz 		*outbuf = rndis_driver_version;
30200a2430fSAndrzej Pietrasiewicz 		retval = 0;
30300a2430fSAndrzej Pietrasiewicz 		break;
30400a2430fSAndrzej Pietrasiewicz 
30500a2430fSAndrzej Pietrasiewicz 	/* mandatory */
30600a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
30700a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
308*83210e59SAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(*params->filter);
30900a2430fSAndrzej Pietrasiewicz 		retval = 0;
31000a2430fSAndrzej Pietrasiewicz 		break;
31100a2430fSAndrzej Pietrasiewicz 
31200a2430fSAndrzej Pietrasiewicz 	/* mandatory */
31300a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE:
31400a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
31500a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
31600a2430fSAndrzej Pietrasiewicz 		retval = 0;
31700a2430fSAndrzej Pietrasiewicz 		break;
31800a2430fSAndrzej Pietrasiewicz 
31900a2430fSAndrzej Pietrasiewicz 	/* mandatory */
32000a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS:
32100a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
32200a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
323*83210e59SAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(params->media_state);
32400a2430fSAndrzej Pietrasiewicz 		retval = 0;
32500a2430fSAndrzej Pietrasiewicz 		break;
32600a2430fSAndrzej Pietrasiewicz 
32700a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_PHYSICAL_MEDIUM:
32800a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_PHYSICAL_MEDIUM\n", __func__);
32900a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(0);
33000a2430fSAndrzej Pietrasiewicz 		retval = 0;
33100a2430fSAndrzej Pietrasiewicz 		break;
33200a2430fSAndrzej Pietrasiewicz 
33300a2430fSAndrzej Pietrasiewicz 	/* The RNDIS specification is incomplete/wrong.   Some versions
33400a2430fSAndrzej Pietrasiewicz 	 * of MS-Windows expect OIDs that aren't specified there.  Other
33500a2430fSAndrzej Pietrasiewicz 	 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
33600a2430fSAndrzej Pietrasiewicz 	 */
33700a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_MAC_OPTIONS:		/* from WinME */
33800a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_MAC_OPTIONS\n", __func__);
33900a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(
34000a2430fSAndrzej Pietrasiewicz 			  RNDIS_MAC_OPTION_RECEIVE_SERIALIZED
34100a2430fSAndrzej Pietrasiewicz 			| RNDIS_MAC_OPTION_FULL_DUPLEX);
34200a2430fSAndrzej Pietrasiewicz 		retval = 0;
34300a2430fSAndrzej Pietrasiewicz 		break;
34400a2430fSAndrzej Pietrasiewicz 
34500a2430fSAndrzej Pietrasiewicz 	/* statistics OIDs (table 4-2) */
34600a2430fSAndrzej Pietrasiewicz 
34700a2430fSAndrzej Pietrasiewicz 	/* mandatory */
34800a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_XMIT_OK:
34900a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
35000a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_OID_GEN_XMIT_OK\n", __func__);
35100a2430fSAndrzej Pietrasiewicz 		if (stats) {
35200a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(stats->tx_packets
35300a2430fSAndrzej Pietrasiewicz 				- stats->tx_errors - stats->tx_dropped);
35400a2430fSAndrzej Pietrasiewicz 			retval = 0;
35500a2430fSAndrzej Pietrasiewicz 		}
35600a2430fSAndrzej Pietrasiewicz 		break;
35700a2430fSAndrzej Pietrasiewicz 
35800a2430fSAndrzej Pietrasiewicz 	/* mandatory */
35900a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_RCV_OK:
36000a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
36100a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_OID_GEN_RCV_OK\n", __func__);
36200a2430fSAndrzej Pietrasiewicz 		if (stats) {
36300a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(stats->rx_packets
36400a2430fSAndrzej Pietrasiewicz 				- stats->rx_errors - stats->rx_dropped);
36500a2430fSAndrzej Pietrasiewicz 			retval = 0;
36600a2430fSAndrzej Pietrasiewicz 		}
36700a2430fSAndrzej Pietrasiewicz 		break;
36800a2430fSAndrzej Pietrasiewicz 
36900a2430fSAndrzej Pietrasiewicz 	/* mandatory */
37000a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_XMIT_ERROR:
37100a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
37200a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_OID_GEN_XMIT_ERROR\n", __func__);
37300a2430fSAndrzej Pietrasiewicz 		if (stats) {
37400a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(stats->tx_errors);
37500a2430fSAndrzej Pietrasiewicz 			retval = 0;
37600a2430fSAndrzej Pietrasiewicz 		}
37700a2430fSAndrzej Pietrasiewicz 		break;
37800a2430fSAndrzej Pietrasiewicz 
37900a2430fSAndrzej Pietrasiewicz 	/* mandatory */
38000a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_RCV_ERROR:
38100a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
38200a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_OID_GEN_RCV_ERROR\n", __func__);
38300a2430fSAndrzej Pietrasiewicz 		if (stats) {
38400a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(stats->rx_errors);
38500a2430fSAndrzej Pietrasiewicz 			retval = 0;
38600a2430fSAndrzej Pietrasiewicz 		}
38700a2430fSAndrzej Pietrasiewicz 		break;
38800a2430fSAndrzej Pietrasiewicz 
38900a2430fSAndrzej Pietrasiewicz 	/* mandatory */
39000a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_RCV_NO_BUFFER:
39100a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_RCV_NO_BUFFER\n", __func__);
39200a2430fSAndrzej Pietrasiewicz 		if (stats) {
39300a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(stats->rx_dropped);
39400a2430fSAndrzej Pietrasiewicz 			retval = 0;
39500a2430fSAndrzej Pietrasiewicz 		}
39600a2430fSAndrzej Pietrasiewicz 		break;
39700a2430fSAndrzej Pietrasiewicz 
39800a2430fSAndrzej Pietrasiewicz 	/* ieee802.3 OIDs (table 4-3) */
39900a2430fSAndrzej Pietrasiewicz 
40000a2430fSAndrzej Pietrasiewicz 	/* mandatory */
40100a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_PERMANENT_ADDRESS:
40200a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__);
403*83210e59SAndrzej Pietrasiewicz 		if (params->dev) {
40400a2430fSAndrzej Pietrasiewicz 			length = ETH_ALEN;
405*83210e59SAndrzej Pietrasiewicz 			memcpy(outbuf, params->host_mac, length);
40600a2430fSAndrzej Pietrasiewicz 			retval = 0;
40700a2430fSAndrzej Pietrasiewicz 		}
40800a2430fSAndrzej Pietrasiewicz 		break;
40900a2430fSAndrzej Pietrasiewicz 
41000a2430fSAndrzej Pietrasiewicz 	/* mandatory */
41100a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_CURRENT_ADDRESS:
41200a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__);
413*83210e59SAndrzej Pietrasiewicz 		if (params->dev) {
41400a2430fSAndrzej Pietrasiewicz 			length = ETH_ALEN;
415*83210e59SAndrzej Pietrasiewicz 			memcpy(outbuf, params->host_mac, length);
41600a2430fSAndrzej Pietrasiewicz 			retval = 0;
41700a2430fSAndrzej Pietrasiewicz 		}
41800a2430fSAndrzej Pietrasiewicz 		break;
41900a2430fSAndrzej Pietrasiewicz 
42000a2430fSAndrzej Pietrasiewicz 	/* mandatory */
42100a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_MULTICAST_LIST:
42200a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
42300a2430fSAndrzej Pietrasiewicz 		/* Multicast base address only */
42400a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(0xE0000000);
42500a2430fSAndrzej Pietrasiewicz 		retval = 0;
42600a2430fSAndrzej Pietrasiewicz 		break;
42700a2430fSAndrzej Pietrasiewicz 
42800a2430fSAndrzej Pietrasiewicz 	/* mandatory */
42900a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_MAXIMUM_LIST_SIZE:
43000a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
43100a2430fSAndrzej Pietrasiewicz 		/* Multicast base address only */
43200a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(1);
43300a2430fSAndrzej Pietrasiewicz 		retval = 0;
43400a2430fSAndrzej Pietrasiewicz 		break;
43500a2430fSAndrzej Pietrasiewicz 
43600a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_MAC_OPTIONS:
43700a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_MAC_OPTIONS\n", __func__);
43800a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(0);
43900a2430fSAndrzej Pietrasiewicz 		retval = 0;
44000a2430fSAndrzej Pietrasiewicz 		break;
44100a2430fSAndrzej Pietrasiewicz 
44200a2430fSAndrzej Pietrasiewicz 	/* ieee802.3 statistics OIDs (table 4-4) */
44300a2430fSAndrzej Pietrasiewicz 
44400a2430fSAndrzej Pietrasiewicz 	/* mandatory */
44500a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT:
44600a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
44700a2430fSAndrzej Pietrasiewicz 		if (stats) {
44800a2430fSAndrzej Pietrasiewicz 			*outbuf = cpu_to_le32(stats->rx_frame_errors);
44900a2430fSAndrzej Pietrasiewicz 			retval = 0;
45000a2430fSAndrzej Pietrasiewicz 		}
45100a2430fSAndrzej Pietrasiewicz 		break;
45200a2430fSAndrzej Pietrasiewicz 
45300a2430fSAndrzej Pietrasiewicz 	/* mandatory */
45400a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_XMIT_ONE_COLLISION:
45500a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_XMIT_ONE_COLLISION\n", __func__);
45600a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(0);
45700a2430fSAndrzej Pietrasiewicz 		retval = 0;
45800a2430fSAndrzej Pietrasiewicz 		break;
45900a2430fSAndrzej Pietrasiewicz 
46000a2430fSAndrzej Pietrasiewicz 	/* mandatory */
46100a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_XMIT_MORE_COLLISIONS:
46200a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
46300a2430fSAndrzej Pietrasiewicz 		*outbuf = cpu_to_le32(0);
46400a2430fSAndrzej Pietrasiewicz 		retval = 0;
46500a2430fSAndrzej Pietrasiewicz 		break;
46600a2430fSAndrzej Pietrasiewicz 
46700a2430fSAndrzej Pietrasiewicz 	default:
46800a2430fSAndrzej Pietrasiewicz 		pr_warning("%s: query unknown OID 0x%08X\n",
46900a2430fSAndrzej Pietrasiewicz 			 __func__, OID);
47000a2430fSAndrzej Pietrasiewicz 	}
47100a2430fSAndrzej Pietrasiewicz 	if (retval < 0)
47200a2430fSAndrzej Pietrasiewicz 		length = 0;
47300a2430fSAndrzej Pietrasiewicz 
47400a2430fSAndrzej Pietrasiewicz 	resp->InformationBufferLength = cpu_to_le32(length);
47500a2430fSAndrzej Pietrasiewicz 	r->length = length + sizeof(*resp);
47600a2430fSAndrzej Pietrasiewicz 	resp->MessageLength = cpu_to_le32(r->length);
47700a2430fSAndrzej Pietrasiewicz 	return retval;
47800a2430fSAndrzej Pietrasiewicz }
47900a2430fSAndrzej Pietrasiewicz 
480*83210e59SAndrzej Pietrasiewicz static int gen_ndis_set_resp(struct rndis_params *params, u32 OID,
481*83210e59SAndrzej Pietrasiewicz 			     u8 *buf, u32 buf_len, rndis_resp_t *r)
48200a2430fSAndrzej Pietrasiewicz {
48300a2430fSAndrzej Pietrasiewicz 	rndis_set_cmplt_type *resp;
48400a2430fSAndrzej Pietrasiewicz 	int i, retval = -ENOTSUPP;
48500a2430fSAndrzej Pietrasiewicz 
48600a2430fSAndrzej Pietrasiewicz 	if (!r)
48700a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
48800a2430fSAndrzej Pietrasiewicz 	resp = (rndis_set_cmplt_type *)r->buf;
48900a2430fSAndrzej Pietrasiewicz 	if (!resp)
49000a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
49100a2430fSAndrzej Pietrasiewicz 
49200a2430fSAndrzej Pietrasiewicz 	if (buf_len && rndis_debug > 1) {
49300a2430fSAndrzej Pietrasiewicz 		pr_debug("set OID %08x value, len %d:\n", OID, buf_len);
49400a2430fSAndrzej Pietrasiewicz 		for (i = 0; i < buf_len; i += 16) {
49500a2430fSAndrzej Pietrasiewicz 			pr_debug("%03d: %08x %08x %08x %08x\n", i,
49600a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i]),
49700a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i + 4]),
49800a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i + 8]),
49900a2430fSAndrzej Pietrasiewicz 				get_unaligned_le32(&buf[i + 12]));
50000a2430fSAndrzej Pietrasiewicz 		}
50100a2430fSAndrzej Pietrasiewicz 	}
50200a2430fSAndrzej Pietrasiewicz 
50300a2430fSAndrzej Pietrasiewicz 	switch (OID) {
50400a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
50500a2430fSAndrzej Pietrasiewicz 
50600a2430fSAndrzej Pietrasiewicz 		/* these NDIS_PACKET_TYPE_* bitflags are shared with
50700a2430fSAndrzej Pietrasiewicz 		 * cdc_filter; it's not RNDIS-specific
50800a2430fSAndrzej Pietrasiewicz 		 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
50900a2430fSAndrzej Pietrasiewicz 		 *	PROMISCUOUS, DIRECTED,
51000a2430fSAndrzej Pietrasiewicz 		 *	MULTICAST, ALL_MULTICAST, BROADCAST
51100a2430fSAndrzej Pietrasiewicz 		 */
51200a2430fSAndrzej Pietrasiewicz 		*params->filter = (u16)get_unaligned_le32(buf);
51300a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER %08x\n",
51400a2430fSAndrzej Pietrasiewicz 			__func__, *params->filter);
51500a2430fSAndrzej Pietrasiewicz 
51600a2430fSAndrzej Pietrasiewicz 		/* this call has a significant side effect:  it's
51700a2430fSAndrzej Pietrasiewicz 		 * what makes the packet flow start and stop, like
51800a2430fSAndrzej Pietrasiewicz 		 * activating the CDC Ethernet altsetting.
51900a2430fSAndrzej Pietrasiewicz 		 */
52000a2430fSAndrzej Pietrasiewicz 		retval = 0;
52100a2430fSAndrzej Pietrasiewicz 		if (*params->filter) {
52200a2430fSAndrzej Pietrasiewicz 			params->state = RNDIS_DATA_INITIALIZED;
52300a2430fSAndrzej Pietrasiewicz 			netif_carrier_on(params->dev);
52400a2430fSAndrzej Pietrasiewicz 			if (netif_running(params->dev))
52500a2430fSAndrzej Pietrasiewicz 				netif_wake_queue(params->dev);
52600a2430fSAndrzej Pietrasiewicz 		} else {
52700a2430fSAndrzej Pietrasiewicz 			params->state = RNDIS_INITIALIZED;
52800a2430fSAndrzej Pietrasiewicz 			netif_carrier_off(params->dev);
52900a2430fSAndrzej Pietrasiewicz 			netif_stop_queue(params->dev);
53000a2430fSAndrzej Pietrasiewicz 		}
53100a2430fSAndrzej Pietrasiewicz 		break;
53200a2430fSAndrzej Pietrasiewicz 
53300a2430fSAndrzej Pietrasiewicz 	case RNDIS_OID_802_3_MULTICAST_LIST:
53400a2430fSAndrzej Pietrasiewicz 		/* I think we can ignore this */
53500a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
53600a2430fSAndrzej Pietrasiewicz 		retval = 0;
53700a2430fSAndrzej Pietrasiewicz 		break;
53800a2430fSAndrzej Pietrasiewicz 
53900a2430fSAndrzej Pietrasiewicz 	default:
54000a2430fSAndrzej Pietrasiewicz 		pr_warning("%s: set unknown OID 0x%08X, size %d\n",
54100a2430fSAndrzej Pietrasiewicz 			 __func__, OID, buf_len);
54200a2430fSAndrzej Pietrasiewicz 	}
54300a2430fSAndrzej Pietrasiewicz 
54400a2430fSAndrzej Pietrasiewicz 	return retval;
54500a2430fSAndrzej Pietrasiewicz }
54600a2430fSAndrzej Pietrasiewicz 
54700a2430fSAndrzej Pietrasiewicz /*
54800a2430fSAndrzej Pietrasiewicz  * Response Functions
54900a2430fSAndrzej Pietrasiewicz  */
55000a2430fSAndrzej Pietrasiewicz 
551*83210e59SAndrzej Pietrasiewicz static int rndis_init_response(struct rndis_params *params,
552*83210e59SAndrzej Pietrasiewicz 			       rndis_init_msg_type *buf)
55300a2430fSAndrzej Pietrasiewicz {
55400a2430fSAndrzej Pietrasiewicz 	rndis_init_cmplt_type *resp;
55500a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
55600a2430fSAndrzej Pietrasiewicz 
55700a2430fSAndrzej Pietrasiewicz 	if (!params->dev)
55800a2430fSAndrzej Pietrasiewicz 		return -ENOTSUPP;
55900a2430fSAndrzej Pietrasiewicz 
560*83210e59SAndrzej Pietrasiewicz 	r = rndis_add_response(params, sizeof(rndis_init_cmplt_type));
56100a2430fSAndrzej Pietrasiewicz 	if (!r)
56200a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
56300a2430fSAndrzej Pietrasiewicz 	resp = (rndis_init_cmplt_type *)r->buf;
56400a2430fSAndrzej Pietrasiewicz 
56500a2430fSAndrzej Pietrasiewicz 	resp->MessageType = cpu_to_le32(RNDIS_MSG_INIT_C);
56600a2430fSAndrzej Pietrasiewicz 	resp->MessageLength = cpu_to_le32(52);
56700a2430fSAndrzej Pietrasiewicz 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
56800a2430fSAndrzej Pietrasiewicz 	resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
56900a2430fSAndrzej Pietrasiewicz 	resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
57000a2430fSAndrzej Pietrasiewicz 	resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
57100a2430fSAndrzej Pietrasiewicz 	resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
57200a2430fSAndrzej Pietrasiewicz 	resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
57300a2430fSAndrzej Pietrasiewicz 	resp->MaxPacketsPerTransfer = cpu_to_le32(1);
57400a2430fSAndrzej Pietrasiewicz 	resp->MaxTransferSize = cpu_to_le32(
57500a2430fSAndrzej Pietrasiewicz 		  params->dev->mtu
57600a2430fSAndrzej Pietrasiewicz 		+ sizeof(struct ethhdr)
57700a2430fSAndrzej Pietrasiewicz 		+ sizeof(struct rndis_packet_msg_type)
57800a2430fSAndrzej Pietrasiewicz 		+ 22);
57900a2430fSAndrzej Pietrasiewicz 	resp->PacketAlignmentFactor = cpu_to_le32(0);
58000a2430fSAndrzej Pietrasiewicz 	resp->AFListOffset = cpu_to_le32(0);
58100a2430fSAndrzej Pietrasiewicz 	resp->AFListSize = cpu_to_le32(0);
58200a2430fSAndrzej Pietrasiewicz 
58300a2430fSAndrzej Pietrasiewicz 	params->resp_avail(params->v);
58400a2430fSAndrzej Pietrasiewicz 	return 0;
58500a2430fSAndrzej Pietrasiewicz }
58600a2430fSAndrzej Pietrasiewicz 
587*83210e59SAndrzej Pietrasiewicz static int rndis_query_response(struct rndis_params *params,
588*83210e59SAndrzej Pietrasiewicz 				rndis_query_msg_type *buf)
58900a2430fSAndrzej Pietrasiewicz {
59000a2430fSAndrzej Pietrasiewicz 	rndis_query_cmplt_type *resp;
59100a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
59200a2430fSAndrzej Pietrasiewicz 
59300a2430fSAndrzej Pietrasiewicz 	/* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
59400a2430fSAndrzej Pietrasiewicz 	if (!params->dev)
59500a2430fSAndrzej Pietrasiewicz 		return -ENOTSUPP;
59600a2430fSAndrzej Pietrasiewicz 
59700a2430fSAndrzej Pietrasiewicz 	/*
59800a2430fSAndrzej Pietrasiewicz 	 * we need more memory:
59900a2430fSAndrzej Pietrasiewicz 	 * gen_ndis_query_resp expects enough space for
60000a2430fSAndrzej Pietrasiewicz 	 * rndis_query_cmplt_type followed by data.
60100a2430fSAndrzej Pietrasiewicz 	 * oid_supported_list is the largest data reply
60200a2430fSAndrzej Pietrasiewicz 	 */
603*83210e59SAndrzej Pietrasiewicz 	r = rndis_add_response(params,
60400a2430fSAndrzej Pietrasiewicz 		sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
60500a2430fSAndrzej Pietrasiewicz 	if (!r)
60600a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
60700a2430fSAndrzej Pietrasiewicz 	resp = (rndis_query_cmplt_type *)r->buf;
60800a2430fSAndrzej Pietrasiewicz 
60900a2430fSAndrzej Pietrasiewicz 	resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C);
61000a2430fSAndrzej Pietrasiewicz 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
61100a2430fSAndrzej Pietrasiewicz 
612*83210e59SAndrzej Pietrasiewicz 	if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID),
61300a2430fSAndrzej Pietrasiewicz 			le32_to_cpu(buf->InformationBufferOffset)
61400a2430fSAndrzej Pietrasiewicz 					+ 8 + (u8 *)buf,
61500a2430fSAndrzej Pietrasiewicz 			le32_to_cpu(buf->InformationBufferLength),
61600a2430fSAndrzej Pietrasiewicz 			r)) {
61700a2430fSAndrzej Pietrasiewicz 		/* OID not supported */
61800a2430fSAndrzej Pietrasiewicz 		resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
61900a2430fSAndrzej Pietrasiewicz 		resp->MessageLength = cpu_to_le32(sizeof *resp);
62000a2430fSAndrzej Pietrasiewicz 		resp->InformationBufferLength = cpu_to_le32(0);
62100a2430fSAndrzej Pietrasiewicz 		resp->InformationBufferOffset = cpu_to_le32(0);
62200a2430fSAndrzej Pietrasiewicz 	} else
62300a2430fSAndrzej Pietrasiewicz 		resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
62400a2430fSAndrzej Pietrasiewicz 
62500a2430fSAndrzej Pietrasiewicz 	params->resp_avail(params->v);
62600a2430fSAndrzej Pietrasiewicz 	return 0;
62700a2430fSAndrzej Pietrasiewicz }
62800a2430fSAndrzej Pietrasiewicz 
629*83210e59SAndrzej Pietrasiewicz static int rndis_set_response(struct rndis_params *params,
630*83210e59SAndrzej Pietrasiewicz 			      rndis_set_msg_type *buf)
63100a2430fSAndrzej Pietrasiewicz {
63200a2430fSAndrzej Pietrasiewicz 	u32 BufLength, BufOffset;
63300a2430fSAndrzej Pietrasiewicz 	rndis_set_cmplt_type *resp;
63400a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
63500a2430fSAndrzej Pietrasiewicz 
636*83210e59SAndrzej Pietrasiewicz 	r = rndis_add_response(params, sizeof(rndis_set_cmplt_type));
63700a2430fSAndrzej Pietrasiewicz 	if (!r)
63800a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
63900a2430fSAndrzej Pietrasiewicz 	resp = (rndis_set_cmplt_type *)r->buf;
64000a2430fSAndrzej Pietrasiewicz 
64100a2430fSAndrzej Pietrasiewicz 	BufLength = le32_to_cpu(buf->InformationBufferLength);
64200a2430fSAndrzej Pietrasiewicz 	BufOffset = le32_to_cpu(buf->InformationBufferOffset);
64300a2430fSAndrzej Pietrasiewicz 
64400a2430fSAndrzej Pietrasiewicz #ifdef	VERBOSE_DEBUG
64500a2430fSAndrzej Pietrasiewicz 	pr_debug("%s: Length: %d\n", __func__, BufLength);
64600a2430fSAndrzej Pietrasiewicz 	pr_debug("%s: Offset: %d\n", __func__, BufOffset);
64700a2430fSAndrzej Pietrasiewicz 	pr_debug("%s: InfoBuffer: ", __func__);
64800a2430fSAndrzej Pietrasiewicz 
64900a2430fSAndrzej Pietrasiewicz 	for (i = 0; i < BufLength; i++) {
65000a2430fSAndrzej Pietrasiewicz 		pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
65100a2430fSAndrzej Pietrasiewicz 	}
65200a2430fSAndrzej Pietrasiewicz 
65300a2430fSAndrzej Pietrasiewicz 	pr_debug("\n");
65400a2430fSAndrzej Pietrasiewicz #endif
65500a2430fSAndrzej Pietrasiewicz 
65600a2430fSAndrzej Pietrasiewicz 	resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C);
65700a2430fSAndrzej Pietrasiewicz 	resp->MessageLength = cpu_to_le32(16);
65800a2430fSAndrzej Pietrasiewicz 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
659*83210e59SAndrzej Pietrasiewicz 	if (gen_ndis_set_resp(params, le32_to_cpu(buf->OID),
66000a2430fSAndrzej Pietrasiewicz 			((u8 *)buf) + 8 + BufOffset, BufLength, r))
66100a2430fSAndrzej Pietrasiewicz 		resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
66200a2430fSAndrzej Pietrasiewicz 	else
66300a2430fSAndrzej Pietrasiewicz 		resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
66400a2430fSAndrzej Pietrasiewicz 
66500a2430fSAndrzej Pietrasiewicz 	params->resp_avail(params->v);
66600a2430fSAndrzej Pietrasiewicz 	return 0;
66700a2430fSAndrzej Pietrasiewicz }
66800a2430fSAndrzej Pietrasiewicz 
669*83210e59SAndrzej Pietrasiewicz static int rndis_reset_response(struct rndis_params *params,
670*83210e59SAndrzej Pietrasiewicz 				rndis_reset_msg_type *buf)
67100a2430fSAndrzej Pietrasiewicz {
67200a2430fSAndrzej Pietrasiewicz 	rndis_reset_cmplt_type *resp;
67300a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
67400a2430fSAndrzej Pietrasiewicz 
675*83210e59SAndrzej Pietrasiewicz 	r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type));
67600a2430fSAndrzej Pietrasiewicz 	if (!r)
67700a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
67800a2430fSAndrzej Pietrasiewicz 	resp = (rndis_reset_cmplt_type *)r->buf;
67900a2430fSAndrzej Pietrasiewicz 
68000a2430fSAndrzej Pietrasiewicz 	resp->MessageType = cpu_to_le32(RNDIS_MSG_RESET_C);
68100a2430fSAndrzej Pietrasiewicz 	resp->MessageLength = cpu_to_le32(16);
68200a2430fSAndrzej Pietrasiewicz 	resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
68300a2430fSAndrzej Pietrasiewicz 	/* resent information */
68400a2430fSAndrzej Pietrasiewicz 	resp->AddressingReset = cpu_to_le32(1);
68500a2430fSAndrzej Pietrasiewicz 
68600a2430fSAndrzej Pietrasiewicz 	params->resp_avail(params->v);
68700a2430fSAndrzej Pietrasiewicz 	return 0;
68800a2430fSAndrzej Pietrasiewicz }
68900a2430fSAndrzej Pietrasiewicz 
690*83210e59SAndrzej Pietrasiewicz static int rndis_keepalive_response(struct rndis_params *params,
69100a2430fSAndrzej Pietrasiewicz 				    rndis_keepalive_msg_type *buf)
69200a2430fSAndrzej Pietrasiewicz {
69300a2430fSAndrzej Pietrasiewicz 	rndis_keepalive_cmplt_type *resp;
69400a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
69500a2430fSAndrzej Pietrasiewicz 
69600a2430fSAndrzej Pietrasiewicz 	/* host "should" check only in RNDIS_DATA_INITIALIZED state */
69700a2430fSAndrzej Pietrasiewicz 
698*83210e59SAndrzej Pietrasiewicz 	r = rndis_add_response(params, sizeof(rndis_keepalive_cmplt_type));
69900a2430fSAndrzej Pietrasiewicz 	if (!r)
70000a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
70100a2430fSAndrzej Pietrasiewicz 	resp = (rndis_keepalive_cmplt_type *)r->buf;
70200a2430fSAndrzej Pietrasiewicz 
70300a2430fSAndrzej Pietrasiewicz 	resp->MessageType = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C);
70400a2430fSAndrzej Pietrasiewicz 	resp->MessageLength = cpu_to_le32(16);
70500a2430fSAndrzej Pietrasiewicz 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
70600a2430fSAndrzej Pietrasiewicz 	resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
70700a2430fSAndrzej Pietrasiewicz 
70800a2430fSAndrzej Pietrasiewicz 	params->resp_avail(params->v);
70900a2430fSAndrzej Pietrasiewicz 	return 0;
71000a2430fSAndrzej Pietrasiewicz }
71100a2430fSAndrzej Pietrasiewicz 
71200a2430fSAndrzej Pietrasiewicz 
71300a2430fSAndrzej Pietrasiewicz /*
71400a2430fSAndrzej Pietrasiewicz  * Device to Host Comunication
71500a2430fSAndrzej Pietrasiewicz  */
716*83210e59SAndrzej Pietrasiewicz static int rndis_indicate_status_msg(struct rndis_params *params, u32 status)
71700a2430fSAndrzej Pietrasiewicz {
71800a2430fSAndrzej Pietrasiewicz 	rndis_indicate_status_msg_type *resp;
71900a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
72000a2430fSAndrzej Pietrasiewicz 
72100a2430fSAndrzej Pietrasiewicz 	if (params->state == RNDIS_UNINITIALIZED)
72200a2430fSAndrzej Pietrasiewicz 		return -ENOTSUPP;
72300a2430fSAndrzej Pietrasiewicz 
724*83210e59SAndrzej Pietrasiewicz 	r = rndis_add_response(params, sizeof(rndis_indicate_status_msg_type));
72500a2430fSAndrzej Pietrasiewicz 	if (!r)
72600a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
72700a2430fSAndrzej Pietrasiewicz 	resp = (rndis_indicate_status_msg_type *)r->buf;
72800a2430fSAndrzej Pietrasiewicz 
72900a2430fSAndrzej Pietrasiewicz 	resp->MessageType = cpu_to_le32(RNDIS_MSG_INDICATE);
73000a2430fSAndrzej Pietrasiewicz 	resp->MessageLength = cpu_to_le32(20);
73100a2430fSAndrzej Pietrasiewicz 	resp->Status = cpu_to_le32(status);
73200a2430fSAndrzej Pietrasiewicz 	resp->StatusBufferLength = cpu_to_le32(0);
73300a2430fSAndrzej Pietrasiewicz 	resp->StatusBufferOffset = cpu_to_le32(0);
73400a2430fSAndrzej Pietrasiewicz 
73500a2430fSAndrzej Pietrasiewicz 	params->resp_avail(params->v);
73600a2430fSAndrzej Pietrasiewicz 	return 0;
73700a2430fSAndrzej Pietrasiewicz }
73800a2430fSAndrzej Pietrasiewicz 
739*83210e59SAndrzej Pietrasiewicz int rndis_signal_connect(struct rndis_params *params)
74000a2430fSAndrzej Pietrasiewicz {
741*83210e59SAndrzej Pietrasiewicz 	params->media_state = RNDIS_MEDIA_STATE_CONNECTED;
742*83210e59SAndrzej Pietrasiewicz 	return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_CONNECT);
74300a2430fSAndrzej Pietrasiewicz }
74400a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_signal_connect);
74500a2430fSAndrzej Pietrasiewicz 
746*83210e59SAndrzej Pietrasiewicz int rndis_signal_disconnect(struct rndis_params *params)
74700a2430fSAndrzej Pietrasiewicz {
748*83210e59SAndrzej Pietrasiewicz 	params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
749*83210e59SAndrzej Pietrasiewicz 	return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_DISCONNECT);
75000a2430fSAndrzej Pietrasiewicz }
75100a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_signal_disconnect);
75200a2430fSAndrzej Pietrasiewicz 
753*83210e59SAndrzej Pietrasiewicz void rndis_uninit(struct rndis_params *params)
75400a2430fSAndrzej Pietrasiewicz {
75500a2430fSAndrzej Pietrasiewicz 	u8 *buf;
75600a2430fSAndrzej Pietrasiewicz 	u32 length;
75700a2430fSAndrzej Pietrasiewicz 
758*83210e59SAndrzej Pietrasiewicz 	if (!params)
75900a2430fSAndrzej Pietrasiewicz 		return;
760*83210e59SAndrzej Pietrasiewicz 	params->state = RNDIS_UNINITIALIZED;
76100a2430fSAndrzej Pietrasiewicz 
76200a2430fSAndrzej Pietrasiewicz 	/* drain the response queue */
763*83210e59SAndrzej Pietrasiewicz 	while ((buf = rndis_get_next_response(params, &length)))
764*83210e59SAndrzej Pietrasiewicz 		rndis_free_response(params, buf);
76500a2430fSAndrzej Pietrasiewicz }
76600a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_uninit);
76700a2430fSAndrzej Pietrasiewicz 
768*83210e59SAndrzej Pietrasiewicz void rndis_set_host_mac(struct rndis_params *params, const u8 *addr)
76900a2430fSAndrzej Pietrasiewicz {
770*83210e59SAndrzej Pietrasiewicz 	params->host_mac = addr;
77100a2430fSAndrzej Pietrasiewicz }
77200a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_set_host_mac);
77300a2430fSAndrzej Pietrasiewicz 
77400a2430fSAndrzej Pietrasiewicz /*
77500a2430fSAndrzej Pietrasiewicz  * Message Parser
77600a2430fSAndrzej Pietrasiewicz  */
777*83210e59SAndrzej Pietrasiewicz int rndis_msg_parser(struct rndis_params *params, u8 *buf)
77800a2430fSAndrzej Pietrasiewicz {
77900a2430fSAndrzej Pietrasiewicz 	u32 MsgType, MsgLength;
78000a2430fSAndrzej Pietrasiewicz 	__le32 *tmp;
78100a2430fSAndrzej Pietrasiewicz 
78200a2430fSAndrzej Pietrasiewicz 	if (!buf)
78300a2430fSAndrzej Pietrasiewicz 		return -ENOMEM;
78400a2430fSAndrzej Pietrasiewicz 
78500a2430fSAndrzej Pietrasiewicz 	tmp = (__le32 *)buf;
78600a2430fSAndrzej Pietrasiewicz 	MsgType   = get_unaligned_le32(tmp++);
78700a2430fSAndrzej Pietrasiewicz 	MsgLength = get_unaligned_le32(tmp++);
78800a2430fSAndrzej Pietrasiewicz 
789*83210e59SAndrzej Pietrasiewicz 	if (!params)
79000a2430fSAndrzej Pietrasiewicz 		return -ENOTSUPP;
79100a2430fSAndrzej Pietrasiewicz 
79200a2430fSAndrzej Pietrasiewicz 	/* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
79300a2430fSAndrzej Pietrasiewicz 	 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
79400a2430fSAndrzej Pietrasiewicz 	 * and normal HC level polling to see if there's any IN traffic.
79500a2430fSAndrzej Pietrasiewicz 	 */
79600a2430fSAndrzej Pietrasiewicz 
79700a2430fSAndrzej Pietrasiewicz 	/* For USB: responses may take up to 10 seconds */
79800a2430fSAndrzej Pietrasiewicz 	switch (MsgType) {
79900a2430fSAndrzej Pietrasiewicz 	case RNDIS_MSG_INIT:
80000a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_MSG_INIT\n",
80100a2430fSAndrzej Pietrasiewicz 			__func__);
80200a2430fSAndrzej Pietrasiewicz 		params->state = RNDIS_INITIALIZED;
803*83210e59SAndrzej Pietrasiewicz 		return rndis_init_response(params, (rndis_init_msg_type *)buf);
80400a2430fSAndrzej Pietrasiewicz 
80500a2430fSAndrzej Pietrasiewicz 	case RNDIS_MSG_HALT:
80600a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_MSG_HALT\n",
80700a2430fSAndrzej Pietrasiewicz 			__func__);
80800a2430fSAndrzej Pietrasiewicz 		params->state = RNDIS_UNINITIALIZED;
80900a2430fSAndrzej Pietrasiewicz 		if (params->dev) {
81000a2430fSAndrzej Pietrasiewicz 			netif_carrier_off(params->dev);
81100a2430fSAndrzej Pietrasiewicz 			netif_stop_queue(params->dev);
81200a2430fSAndrzej Pietrasiewicz 		}
81300a2430fSAndrzej Pietrasiewicz 		return 0;
81400a2430fSAndrzej Pietrasiewicz 
81500a2430fSAndrzej Pietrasiewicz 	case RNDIS_MSG_QUERY:
816*83210e59SAndrzej Pietrasiewicz 		return rndis_query_response(params,
81700a2430fSAndrzej Pietrasiewicz 					(rndis_query_msg_type *)buf);
81800a2430fSAndrzej Pietrasiewicz 
81900a2430fSAndrzej Pietrasiewicz 	case RNDIS_MSG_SET:
820*83210e59SAndrzej Pietrasiewicz 		return rndis_set_response(params, (rndis_set_msg_type *)buf);
82100a2430fSAndrzej Pietrasiewicz 
82200a2430fSAndrzej Pietrasiewicz 	case RNDIS_MSG_RESET:
82300a2430fSAndrzej Pietrasiewicz 		pr_debug("%s: RNDIS_MSG_RESET\n",
82400a2430fSAndrzej Pietrasiewicz 			__func__);
825*83210e59SAndrzej Pietrasiewicz 		return rndis_reset_response(params,
82600a2430fSAndrzej Pietrasiewicz 					(rndis_reset_msg_type *)buf);
82700a2430fSAndrzej Pietrasiewicz 
82800a2430fSAndrzej Pietrasiewicz 	case RNDIS_MSG_KEEPALIVE:
82900a2430fSAndrzej Pietrasiewicz 		/* For USB: host does this every 5 seconds */
83000a2430fSAndrzej Pietrasiewicz 		if (rndis_debug > 1)
83100a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: RNDIS_MSG_KEEPALIVE\n",
83200a2430fSAndrzej Pietrasiewicz 				__func__);
833*83210e59SAndrzej Pietrasiewicz 		return rndis_keepalive_response(params,
83400a2430fSAndrzej Pietrasiewicz 						 (rndis_keepalive_msg_type *)
83500a2430fSAndrzej Pietrasiewicz 						 buf);
83600a2430fSAndrzej Pietrasiewicz 
83700a2430fSAndrzej Pietrasiewicz 	default:
83800a2430fSAndrzej Pietrasiewicz 		/* At least Windows XP emits some undefined RNDIS messages.
83900a2430fSAndrzej Pietrasiewicz 		 * In one case those messages seemed to relate to the host
84000a2430fSAndrzej Pietrasiewicz 		 * suspending itself.
84100a2430fSAndrzej Pietrasiewicz 		 */
84200a2430fSAndrzej Pietrasiewicz 		pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
84300a2430fSAndrzej Pietrasiewicz 			__func__, MsgType, MsgLength);
84400a2430fSAndrzej Pietrasiewicz 		print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
84500a2430fSAndrzej Pietrasiewicz 				     buf, MsgLength);
84600a2430fSAndrzej Pietrasiewicz 		break;
84700a2430fSAndrzej Pietrasiewicz 	}
84800a2430fSAndrzej Pietrasiewicz 
84900a2430fSAndrzej Pietrasiewicz 	return -ENOTSUPP;
85000a2430fSAndrzej Pietrasiewicz }
85100a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_msg_parser);
85200a2430fSAndrzej Pietrasiewicz 
853*83210e59SAndrzej Pietrasiewicz struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v)
85400a2430fSAndrzej Pietrasiewicz {
85500a2430fSAndrzej Pietrasiewicz 	u8 i;
85600a2430fSAndrzej Pietrasiewicz 
85700a2430fSAndrzej Pietrasiewicz 	if (!resp_avail)
858*83210e59SAndrzej Pietrasiewicz 		return ERR_PTR(-EINVAL);
85900a2430fSAndrzej Pietrasiewicz 
86000a2430fSAndrzej Pietrasiewicz 	for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
86100a2430fSAndrzej Pietrasiewicz 		if (!rndis_per_dev_params[i].used) {
86200a2430fSAndrzej Pietrasiewicz 			rndis_per_dev_params[i].used = 1;
86300a2430fSAndrzej Pietrasiewicz 			rndis_per_dev_params[i].resp_avail = resp_avail;
86400a2430fSAndrzej Pietrasiewicz 			rndis_per_dev_params[i].v = v;
86500a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: configNr = %d\n", __func__, i);
866*83210e59SAndrzej Pietrasiewicz 			return &rndis_per_dev_params[i];
86700a2430fSAndrzej Pietrasiewicz 		}
86800a2430fSAndrzej Pietrasiewicz 	}
86900a2430fSAndrzej Pietrasiewicz 	pr_debug("failed\n");
87000a2430fSAndrzej Pietrasiewicz 
871*83210e59SAndrzej Pietrasiewicz 	return ERR_PTR(-ENODEV);
87200a2430fSAndrzej Pietrasiewicz }
87300a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_register);
87400a2430fSAndrzej Pietrasiewicz 
875*83210e59SAndrzej Pietrasiewicz void rndis_deregister(struct rndis_params *params)
87600a2430fSAndrzej Pietrasiewicz {
87700a2430fSAndrzej Pietrasiewicz 	pr_debug("%s:\n", __func__);
87800a2430fSAndrzej Pietrasiewicz 
879*83210e59SAndrzej Pietrasiewicz 	if (!params)
880*83210e59SAndrzej Pietrasiewicz 		return;
881*83210e59SAndrzej Pietrasiewicz 	params->used = 0;
88200a2430fSAndrzej Pietrasiewicz }
88300a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_deregister);
88400a2430fSAndrzej Pietrasiewicz 
885*83210e59SAndrzej Pietrasiewicz int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev,
886*83210e59SAndrzej Pietrasiewicz 			u16 *cdc_filter)
88700a2430fSAndrzej Pietrasiewicz {
88800a2430fSAndrzej Pietrasiewicz 	pr_debug("%s:\n", __func__);
88900a2430fSAndrzej Pietrasiewicz 	if (!dev)
89000a2430fSAndrzej Pietrasiewicz 		return -EINVAL;
891*83210e59SAndrzej Pietrasiewicz 	if (!params)
892*83210e59SAndrzej Pietrasiewicz 		return -1;
89300a2430fSAndrzej Pietrasiewicz 
894*83210e59SAndrzej Pietrasiewicz 	params->dev = dev;
895*83210e59SAndrzej Pietrasiewicz 	params->filter = cdc_filter;
89600a2430fSAndrzej Pietrasiewicz 
89700a2430fSAndrzej Pietrasiewicz 	return 0;
89800a2430fSAndrzej Pietrasiewicz }
89900a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_set_param_dev);
90000a2430fSAndrzej Pietrasiewicz 
901*83210e59SAndrzej Pietrasiewicz int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID,
902*83210e59SAndrzej Pietrasiewicz 			   const char *vendorDescr)
90300a2430fSAndrzej Pietrasiewicz {
90400a2430fSAndrzej Pietrasiewicz 	pr_debug("%s:\n", __func__);
90500a2430fSAndrzej Pietrasiewicz 	if (!vendorDescr) return -1;
906*83210e59SAndrzej Pietrasiewicz 	if (!params)
907*83210e59SAndrzej Pietrasiewicz 		return -1;
90800a2430fSAndrzej Pietrasiewicz 
909*83210e59SAndrzej Pietrasiewicz 	params->vendorID = vendorID;
910*83210e59SAndrzej Pietrasiewicz 	params->vendorDescr = vendorDescr;
91100a2430fSAndrzej Pietrasiewicz 
91200a2430fSAndrzej Pietrasiewicz 	return 0;
91300a2430fSAndrzej Pietrasiewicz }
91400a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_set_param_vendor);
91500a2430fSAndrzej Pietrasiewicz 
916*83210e59SAndrzej Pietrasiewicz int rndis_set_param_medium(struct rndis_params *params, u32 medium, u32 speed)
91700a2430fSAndrzej Pietrasiewicz {
91800a2430fSAndrzej Pietrasiewicz 	pr_debug("%s: %u %u\n", __func__, medium, speed);
919*83210e59SAndrzej Pietrasiewicz 	if (!params)
920*83210e59SAndrzej Pietrasiewicz 		return -1;
92100a2430fSAndrzej Pietrasiewicz 
922*83210e59SAndrzej Pietrasiewicz 	params->medium = medium;
923*83210e59SAndrzej Pietrasiewicz 	params->speed = speed;
92400a2430fSAndrzej Pietrasiewicz 
92500a2430fSAndrzej Pietrasiewicz 	return 0;
92600a2430fSAndrzej Pietrasiewicz }
92700a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_set_param_medium);
92800a2430fSAndrzej Pietrasiewicz 
92900a2430fSAndrzej Pietrasiewicz void rndis_add_hdr(struct sk_buff *skb)
93000a2430fSAndrzej Pietrasiewicz {
93100a2430fSAndrzej Pietrasiewicz 	struct rndis_packet_msg_type *header;
93200a2430fSAndrzej Pietrasiewicz 
93300a2430fSAndrzej Pietrasiewicz 	if (!skb)
93400a2430fSAndrzej Pietrasiewicz 		return;
93500a2430fSAndrzej Pietrasiewicz 	header = (void *)skb_push(skb, sizeof(*header));
93600a2430fSAndrzej Pietrasiewicz 	memset(header, 0, sizeof *header);
93700a2430fSAndrzej Pietrasiewicz 	header->MessageType = cpu_to_le32(RNDIS_MSG_PACKET);
93800a2430fSAndrzej Pietrasiewicz 	header->MessageLength = cpu_to_le32(skb->len);
93900a2430fSAndrzej Pietrasiewicz 	header->DataOffset = cpu_to_le32(36);
94000a2430fSAndrzej Pietrasiewicz 	header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
94100a2430fSAndrzej Pietrasiewicz }
94200a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_add_hdr);
94300a2430fSAndrzej Pietrasiewicz 
944*83210e59SAndrzej Pietrasiewicz void rndis_free_response(struct rndis_params *params, u8 *buf)
94500a2430fSAndrzej Pietrasiewicz {
94600a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
94700a2430fSAndrzej Pietrasiewicz 	struct list_head *act, *tmp;
94800a2430fSAndrzej Pietrasiewicz 
949*83210e59SAndrzej Pietrasiewicz 	list_for_each_safe(act, tmp, &(params->resp_queue))
95000a2430fSAndrzej Pietrasiewicz 	{
95100a2430fSAndrzej Pietrasiewicz 		r = list_entry(act, rndis_resp_t, list);
95200a2430fSAndrzej Pietrasiewicz 		if (r && r->buf == buf) {
95300a2430fSAndrzej Pietrasiewicz 			list_del(&r->list);
95400a2430fSAndrzej Pietrasiewicz 			kfree(r);
95500a2430fSAndrzej Pietrasiewicz 		}
95600a2430fSAndrzej Pietrasiewicz 	}
95700a2430fSAndrzej Pietrasiewicz }
95800a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_free_response);
95900a2430fSAndrzej Pietrasiewicz 
960*83210e59SAndrzej Pietrasiewicz u8 *rndis_get_next_response(struct rndis_params *params, u32 *length)
96100a2430fSAndrzej Pietrasiewicz {
96200a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
96300a2430fSAndrzej Pietrasiewicz 	struct list_head *act, *tmp;
96400a2430fSAndrzej Pietrasiewicz 
96500a2430fSAndrzej Pietrasiewicz 	if (!length) return NULL;
96600a2430fSAndrzej Pietrasiewicz 
967*83210e59SAndrzej Pietrasiewicz 	list_for_each_safe(act, tmp, &(params->resp_queue))
96800a2430fSAndrzej Pietrasiewicz 	{
96900a2430fSAndrzej Pietrasiewicz 		r = list_entry(act, rndis_resp_t, list);
97000a2430fSAndrzej Pietrasiewicz 		if (!r->send) {
97100a2430fSAndrzej Pietrasiewicz 			r->send = 1;
97200a2430fSAndrzej Pietrasiewicz 			*length = r->length;
97300a2430fSAndrzej Pietrasiewicz 			return r->buf;
97400a2430fSAndrzej Pietrasiewicz 		}
97500a2430fSAndrzej Pietrasiewicz 	}
97600a2430fSAndrzej Pietrasiewicz 
97700a2430fSAndrzej Pietrasiewicz 	return NULL;
97800a2430fSAndrzej Pietrasiewicz }
97900a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_get_next_response);
98000a2430fSAndrzej Pietrasiewicz 
981*83210e59SAndrzej Pietrasiewicz static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length)
98200a2430fSAndrzej Pietrasiewicz {
98300a2430fSAndrzej Pietrasiewicz 	rndis_resp_t *r;
98400a2430fSAndrzej Pietrasiewicz 
98500a2430fSAndrzej Pietrasiewicz 	/* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
98600a2430fSAndrzej Pietrasiewicz 	r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
98700a2430fSAndrzej Pietrasiewicz 	if (!r) return NULL;
98800a2430fSAndrzej Pietrasiewicz 
98900a2430fSAndrzej Pietrasiewicz 	r->buf = (u8 *)(r + 1);
99000a2430fSAndrzej Pietrasiewicz 	r->length = length;
99100a2430fSAndrzej Pietrasiewicz 	r->send = 0;
99200a2430fSAndrzej Pietrasiewicz 
993*83210e59SAndrzej Pietrasiewicz 	list_add_tail(&r->list, &(params->resp_queue));
99400a2430fSAndrzej Pietrasiewicz 	return r;
99500a2430fSAndrzej Pietrasiewicz }
99600a2430fSAndrzej Pietrasiewicz 
99700a2430fSAndrzej Pietrasiewicz int rndis_rm_hdr(struct gether *port,
99800a2430fSAndrzej Pietrasiewicz 			struct sk_buff *skb,
99900a2430fSAndrzej Pietrasiewicz 			struct sk_buff_head *list)
100000a2430fSAndrzej Pietrasiewicz {
100100a2430fSAndrzej Pietrasiewicz 	/* tmp points to a struct rndis_packet_msg_type */
100200a2430fSAndrzej Pietrasiewicz 	__le32 *tmp = (void *)skb->data;
100300a2430fSAndrzej Pietrasiewicz 
100400a2430fSAndrzej Pietrasiewicz 	/* MessageType, MessageLength */
100500a2430fSAndrzej Pietrasiewicz 	if (cpu_to_le32(RNDIS_MSG_PACKET)
100600a2430fSAndrzej Pietrasiewicz 			!= get_unaligned(tmp++)) {
100700a2430fSAndrzej Pietrasiewicz 		dev_kfree_skb_any(skb);
100800a2430fSAndrzej Pietrasiewicz 		return -EINVAL;
100900a2430fSAndrzej Pietrasiewicz 	}
101000a2430fSAndrzej Pietrasiewicz 	tmp++;
101100a2430fSAndrzej Pietrasiewicz 
101200a2430fSAndrzej Pietrasiewicz 	/* DataOffset, DataLength */
101300a2430fSAndrzej Pietrasiewicz 	if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) {
101400a2430fSAndrzej Pietrasiewicz 		dev_kfree_skb_any(skb);
101500a2430fSAndrzej Pietrasiewicz 		return -EOVERFLOW;
101600a2430fSAndrzej Pietrasiewicz 	}
101700a2430fSAndrzej Pietrasiewicz 	skb_trim(skb, get_unaligned_le32(tmp++));
101800a2430fSAndrzej Pietrasiewicz 
101900a2430fSAndrzej Pietrasiewicz 	skb_queue_tail(list, skb);
102000a2430fSAndrzej Pietrasiewicz 	return 0;
102100a2430fSAndrzej Pietrasiewicz }
102200a2430fSAndrzej Pietrasiewicz EXPORT_SYMBOL_GPL(rndis_rm_hdr);
102300a2430fSAndrzej Pietrasiewicz 
102400a2430fSAndrzej Pietrasiewicz #ifdef CONFIG_USB_GADGET_DEBUG_FILES
102500a2430fSAndrzej Pietrasiewicz 
102600a2430fSAndrzej Pietrasiewicz static int rndis_proc_show(struct seq_file *m, void *v)
102700a2430fSAndrzej Pietrasiewicz {
102800a2430fSAndrzej Pietrasiewicz 	rndis_params *param = m->private;
102900a2430fSAndrzej Pietrasiewicz 
103000a2430fSAndrzej Pietrasiewicz 	seq_printf(m,
103100a2430fSAndrzej Pietrasiewicz 			 "Config Nr. %d\n"
103200a2430fSAndrzej Pietrasiewicz 			 "used      : %s\n"
103300a2430fSAndrzej Pietrasiewicz 			 "state     : %s\n"
103400a2430fSAndrzej Pietrasiewicz 			 "medium    : 0x%08X\n"
103500a2430fSAndrzej Pietrasiewicz 			 "speed     : %d\n"
103600a2430fSAndrzej Pietrasiewicz 			 "cable     : %s\n"
103700a2430fSAndrzej Pietrasiewicz 			 "vendor ID : 0x%08X\n"
103800a2430fSAndrzej Pietrasiewicz 			 "vendor    : %s\n",
103900a2430fSAndrzej Pietrasiewicz 			 param->confignr, (param->used) ? "y" : "n",
104000a2430fSAndrzej Pietrasiewicz 			 ({ char *s = "?";
104100a2430fSAndrzej Pietrasiewicz 			 switch (param->state) {
104200a2430fSAndrzej Pietrasiewicz 			 case RNDIS_UNINITIALIZED:
104300a2430fSAndrzej Pietrasiewicz 				s = "RNDIS_UNINITIALIZED"; break;
104400a2430fSAndrzej Pietrasiewicz 			 case RNDIS_INITIALIZED:
104500a2430fSAndrzej Pietrasiewicz 				s = "RNDIS_INITIALIZED"; break;
104600a2430fSAndrzej Pietrasiewicz 			 case RNDIS_DATA_INITIALIZED:
104700a2430fSAndrzej Pietrasiewicz 				s = "RNDIS_DATA_INITIALIZED"; break;
104800a2430fSAndrzej Pietrasiewicz 			} s; }),
104900a2430fSAndrzej Pietrasiewicz 			 param->medium,
105000a2430fSAndrzej Pietrasiewicz 			 (param->media_state) ? 0 : param->speed*100,
105100a2430fSAndrzej Pietrasiewicz 			 (param->media_state) ? "disconnected" : "connected",
105200a2430fSAndrzej Pietrasiewicz 			 param->vendorID, param->vendorDescr);
105300a2430fSAndrzej Pietrasiewicz 	return 0;
105400a2430fSAndrzej Pietrasiewicz }
105500a2430fSAndrzej Pietrasiewicz 
105600a2430fSAndrzej Pietrasiewicz static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
105700a2430fSAndrzej Pietrasiewicz 				size_t count, loff_t *ppos)
105800a2430fSAndrzej Pietrasiewicz {
105900a2430fSAndrzej Pietrasiewicz 	rndis_params *p = PDE_DATA(file_inode(file));
106000a2430fSAndrzej Pietrasiewicz 	u32 speed = 0;
106100a2430fSAndrzej Pietrasiewicz 	int i, fl_speed = 0;
106200a2430fSAndrzej Pietrasiewicz 
106300a2430fSAndrzej Pietrasiewicz 	for (i = 0; i < count; i++) {
106400a2430fSAndrzej Pietrasiewicz 		char c;
106500a2430fSAndrzej Pietrasiewicz 		if (get_user(c, buffer))
106600a2430fSAndrzej Pietrasiewicz 			return -EFAULT;
106700a2430fSAndrzej Pietrasiewicz 		switch (c) {
106800a2430fSAndrzej Pietrasiewicz 		case '0':
106900a2430fSAndrzej Pietrasiewicz 		case '1':
107000a2430fSAndrzej Pietrasiewicz 		case '2':
107100a2430fSAndrzej Pietrasiewicz 		case '3':
107200a2430fSAndrzej Pietrasiewicz 		case '4':
107300a2430fSAndrzej Pietrasiewicz 		case '5':
107400a2430fSAndrzej Pietrasiewicz 		case '6':
107500a2430fSAndrzej Pietrasiewicz 		case '7':
107600a2430fSAndrzej Pietrasiewicz 		case '8':
107700a2430fSAndrzej Pietrasiewicz 		case '9':
107800a2430fSAndrzej Pietrasiewicz 			fl_speed = 1;
107900a2430fSAndrzej Pietrasiewicz 			speed = speed * 10 + c - '0';
108000a2430fSAndrzej Pietrasiewicz 			break;
108100a2430fSAndrzej Pietrasiewicz 		case 'C':
108200a2430fSAndrzej Pietrasiewicz 		case 'c':
108300a2430fSAndrzej Pietrasiewicz 			rndis_signal_connect(p->confignr);
108400a2430fSAndrzej Pietrasiewicz 			break;
108500a2430fSAndrzej Pietrasiewicz 		case 'D':
108600a2430fSAndrzej Pietrasiewicz 		case 'd':
108700a2430fSAndrzej Pietrasiewicz 			rndis_signal_disconnect(p->confignr);
108800a2430fSAndrzej Pietrasiewicz 			break;
108900a2430fSAndrzej Pietrasiewicz 		default:
109000a2430fSAndrzej Pietrasiewicz 			if (fl_speed) p->speed = speed;
109100a2430fSAndrzej Pietrasiewicz 			else pr_debug("%c is not valid\n", c);
109200a2430fSAndrzej Pietrasiewicz 			break;
109300a2430fSAndrzej Pietrasiewicz 		}
109400a2430fSAndrzej Pietrasiewicz 
109500a2430fSAndrzej Pietrasiewicz 		buffer++;
109600a2430fSAndrzej Pietrasiewicz 	}
109700a2430fSAndrzej Pietrasiewicz 
109800a2430fSAndrzej Pietrasiewicz 	return count;
109900a2430fSAndrzej Pietrasiewicz }
110000a2430fSAndrzej Pietrasiewicz 
110100a2430fSAndrzej Pietrasiewicz static int rndis_proc_open(struct inode *inode, struct file *file)
110200a2430fSAndrzej Pietrasiewicz {
110300a2430fSAndrzej Pietrasiewicz 	return single_open(file, rndis_proc_show, PDE_DATA(inode));
110400a2430fSAndrzej Pietrasiewicz }
110500a2430fSAndrzej Pietrasiewicz 
110600a2430fSAndrzej Pietrasiewicz static const struct file_operations rndis_proc_fops = {
110700a2430fSAndrzej Pietrasiewicz 	.owner		= THIS_MODULE,
110800a2430fSAndrzej Pietrasiewicz 	.open		= rndis_proc_open,
110900a2430fSAndrzej Pietrasiewicz 	.read		= seq_read,
111000a2430fSAndrzej Pietrasiewicz 	.llseek		= seq_lseek,
111100a2430fSAndrzej Pietrasiewicz 	.release	= single_release,
111200a2430fSAndrzej Pietrasiewicz 	.write		= rndis_proc_write,
111300a2430fSAndrzej Pietrasiewicz };
111400a2430fSAndrzej Pietrasiewicz 
111500a2430fSAndrzej Pietrasiewicz #define	NAME_TEMPLATE "driver/rndis-%03d"
111600a2430fSAndrzej Pietrasiewicz 
111700a2430fSAndrzej Pietrasiewicz static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
111800a2430fSAndrzej Pietrasiewicz 
111900a2430fSAndrzej Pietrasiewicz #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
112000a2430fSAndrzej Pietrasiewicz 
112100a2430fSAndrzej Pietrasiewicz 
112200a2430fSAndrzej Pietrasiewicz int rndis_init(void)
112300a2430fSAndrzej Pietrasiewicz {
112400a2430fSAndrzej Pietrasiewicz 	u8 i;
112500a2430fSAndrzej Pietrasiewicz 
112600a2430fSAndrzej Pietrasiewicz 	for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
112700a2430fSAndrzej Pietrasiewicz #ifdef	CONFIG_USB_GADGET_DEBUG_FILES
112800a2430fSAndrzej Pietrasiewicz 		char name [20];
112900a2430fSAndrzej Pietrasiewicz 
113000a2430fSAndrzej Pietrasiewicz 		sprintf(name, NAME_TEMPLATE, i);
113100a2430fSAndrzej Pietrasiewicz 		rndis_connect_state[i] = proc_create_data(name, 0660, NULL,
113200a2430fSAndrzej Pietrasiewicz 					&rndis_proc_fops,
113300a2430fSAndrzej Pietrasiewicz 					(void *)(rndis_per_dev_params + i));
113400a2430fSAndrzej Pietrasiewicz 		if (!rndis_connect_state[i]) {
113500a2430fSAndrzej Pietrasiewicz 			pr_debug("%s: remove entries", __func__);
113600a2430fSAndrzej Pietrasiewicz 			while (i) {
113700a2430fSAndrzej Pietrasiewicz 				sprintf(name, NAME_TEMPLATE, --i);
113800a2430fSAndrzej Pietrasiewicz 				remove_proc_entry(name, NULL);
113900a2430fSAndrzej Pietrasiewicz 			}
114000a2430fSAndrzej Pietrasiewicz 			pr_debug("\n");
114100a2430fSAndrzej Pietrasiewicz 			return -EIO;
114200a2430fSAndrzej Pietrasiewicz 		}
114300a2430fSAndrzej Pietrasiewicz #endif
114400a2430fSAndrzej Pietrasiewicz 		rndis_per_dev_params[i].confignr = i;
114500a2430fSAndrzej Pietrasiewicz 		rndis_per_dev_params[i].used = 0;
114600a2430fSAndrzej Pietrasiewicz 		rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED;
114700a2430fSAndrzej Pietrasiewicz 		rndis_per_dev_params[i].media_state
114800a2430fSAndrzej Pietrasiewicz 				= RNDIS_MEDIA_STATE_DISCONNECTED;
114900a2430fSAndrzej Pietrasiewicz 		INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue));
115000a2430fSAndrzej Pietrasiewicz 	}
115100a2430fSAndrzej Pietrasiewicz 
115200a2430fSAndrzej Pietrasiewicz 	return 0;
115300a2430fSAndrzej Pietrasiewicz }
115400a2430fSAndrzej Pietrasiewicz 
115500a2430fSAndrzej Pietrasiewicz void rndis_exit(void)
115600a2430fSAndrzej Pietrasiewicz {
115700a2430fSAndrzej Pietrasiewicz #ifdef CONFIG_USB_GADGET_DEBUG_FILES
115800a2430fSAndrzej Pietrasiewicz 	u8 i;
115900a2430fSAndrzej Pietrasiewicz 	char name[20];
116000a2430fSAndrzej Pietrasiewicz 
116100a2430fSAndrzej Pietrasiewicz 	for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
116200a2430fSAndrzej Pietrasiewicz 		sprintf(name, NAME_TEMPLATE, i);
116300a2430fSAndrzej Pietrasiewicz 		remove_proc_entry(name, NULL);
116400a2430fSAndrzej Pietrasiewicz 	}
116500a2430fSAndrzej Pietrasiewicz #endif
116600a2430fSAndrzej Pietrasiewicz }
116700a2430fSAndrzej Pietrasiewicz 
1168