tmp = (__le32 *) ((u8 *)resp + 24); 
static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r){	int 			retval = -ENOTSUPP;	u32 			length = 0;	__le32			*tmp;	int			i, count;	rndis_query_cmplt_type	*resp;	if (!r) return -ENOMEM;	resp = (rndis_query_cmplt_type *) r->buf;	if (!resp) return -ENOMEM;		switch (OID) {	/* general oids (table 4-1) */	/* mandatory */	case OID_GEN_SUPPORTED_LIST:		DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__);		length = sizeof (oid_supported_list);		count  = length / sizeof (u32);		tmp = (__le32 *) ((u8 *)resp + 24);		for (i = 0; i < count; i++)			tmp[i] = cpu_to_le32 (oid_supported_list[i]);		retval = 0;		break;			/* mandatory */	case OID_GEN_HARDWARE_STATUS:		DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__);		length = 4;		/* Bogus question! 		 * Hardware must be ready to receive high level protocols.		 * BTW: 		 * reddite ergo quae sunt Caesaris Caesari		 * et quae sunt Dei Deo!		 */		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;			/* mandatory */	case OID_GEN_MEDIA_SUPPORTED:		DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = cpu_to_le32 (					rndis_per_dev_params [configNr].medium);		retval = 0;		break;			/* mandatory */	case OID_GEN_MEDIA_IN_USE:		DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__);		length = 4;		/* one medium, one transport... (maybe you do it better) */		*((__le32 *) resp + 6) = cpu_to_le32 (					rndis_per_dev_params [configNr].medium);		retval = 0;		break;			/* mandatory */	case OID_GEN_MAXIMUM_FRAME_SIZE:		DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].dev) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr].dev->mtu);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			/* mandatory */	case OID_GEN_LINK_SPEED://		DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__);		length = 4;		if (rndis_per_dev_params [configNr].media_state			== NDIS_MEDIA_STATE_DISCONNECTED)		    *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		else		    *((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr].speed);		retval = 0;		break;	/* mandatory */	case OID_GEN_TRANSMIT_BLOCK_SIZE:		DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].dev) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr].dev->mtu);			retval = 0;		}		break;			/* mandatory */	case OID_GEN_RECEIVE_BLOCK_SIZE:		DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].dev) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr].dev->mtu);			retval = 0;		}		break;			/* mandatory */	case OID_GEN_VENDOR_ID:		DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = cpu_to_le32 (			rndis_per_dev_params [configNr].vendorID);		retval = 0;		break;			/* mandatory */	case OID_GEN_VENDOR_DESCRIPTION:		DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__);		length = strlen (rndis_per_dev_params [configNr].vendorDescr);		memcpy ((u8 *) resp + 24, 			rndis_per_dev_params [configNr].vendorDescr, length);		retval = 0;		break;	case OID_GEN_VENDOR_DRIVER_VERSION:		DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__);		length = 4;		/* Created as LE */		*((__le32 *) resp + 6) = rndis_driver_version;		retval = 0;		break;	/* mandatory */	case OID_GEN_CURRENT_PACKET_FILTER:		DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = cpu_to_le32 (					rndis_per_dev_params[configNr].filter);		retval = 0;		break;	/* mandatory */	case OID_GEN_MAXIMUM_TOTAL_SIZE:		DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = __constant_cpu_to_le32(					RNDIS_MAX_TOTAL_SIZE);		retval = 0;		break;	/* mandatory */	case OID_GEN_MEDIA_CONNECT_STATUS:		DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = cpu_to_le32 (					rndis_per_dev_params [configNr]						.media_state);		retval = 0;		break;	case OID_GEN_PHYSICAL_MEDIUM:		DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;	/* The RNDIS specification is incomplete/wrong.   Some versions	 * of MS-Windows expect OIDs that aren't specified there.  Other	 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!	 */	case OID_GEN_MAC_OPTIONS:		/* from WinME */		DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = __constant_cpu_to_le32(			  NDIS_MAC_OPTION_RECEIVE_SERIALIZED			| NDIS_MAC_OPTION_FULL_DUPLEX);		retval = 0;		break;	/* statistics OIDs (table 4-2) */	/* mandatory */	case OID_GEN_XMIT_OK:		DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (			    rndis_per_dev_params [configNr].stats->tx_packets - 			    rndis_per_dev_params [configNr].stats->tx_errors -			    rndis_per_dev_params [configNr].stats->tx_dropped);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;	/* mandatory */	case OID_GEN_RCV_OK:		DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (			    rndis_per_dev_params [configNr].stats->rx_packets - 			    rndis_per_dev_params [configNr].stats->rx_errors -			    rndis_per_dev_params [configNr].stats->rx_dropped);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			/* mandatory */	case OID_GEN_XMIT_ERROR:		DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->tx_errors);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			/* mandatory */	case OID_GEN_RCV_ERROR:		DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->rx_errors);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			/* mandatory */	case OID_GEN_RCV_NO_BUFFER:		DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->rx_dropped);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;#ifdef	RNDIS_OPTIONAL_STATS	case OID_GEN_DIRECTED_BYTES_XMIT:		DEBUG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __FUNCTION__);		/* 		 * Aunt Tilly's size of shoes		 * minus antarctica count of penguins		 * divided by weight of Alpha Centauri		 */		if (rndis_per_dev_params [configNr].stats) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				(rndis_per_dev_params [configNr]					.stats->tx_packets - 				 rndis_per_dev_params [configNr]					 .stats->tx_errors -				 rndis_per_dev_params [configNr]					 .stats->tx_dropped)				* 123);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_DIRECTED_FRAMES_XMIT:		DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__);		/* dito */		if (rndis_per_dev_params [configNr].stats) {			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				(rndis_per_dev_params [configNr]					.stats->tx_packets - 				 rndis_per_dev_params [configNr]					 .stats->tx_errors -				 rndis_per_dev_params [configNr]					 .stats->tx_dropped)				/ 123);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_MULTICAST_BYTES_XMIT:		DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->multicast*1234);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_MULTICAST_FRAMES_XMIT:		DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->multicast);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_BROADCAST_BYTES_XMIT:		DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->tx_packets/42*255);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_BROADCAST_FRAMES_XMIT:		DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->tx_packets/42);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_DIRECTED_BYTES_RCV:		DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__);		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;			case OID_GEN_DIRECTED_FRAMES_RCV:		DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__);		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;			case OID_GEN_MULTICAST_BYTES_RCV:		DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->multicast * 1111);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_MULTICAST_FRAMES_RCV:		DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->multicast);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_BROADCAST_BYTES_RCV:		DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->rx_packets/42*255);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_BROADCAST_FRAMES_RCV:		DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->rx_packets/42);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_RCV_CRC_ERROR:		DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats) {			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->rx_crc_errors);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			case OID_GEN_TRANSMIT_QUEUE_LENGTH:		DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__);		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;#endif	/* RNDIS_OPTIONAL_STATS */	/* ieee802.3 OIDs (table 4-3) */	/* mandatory */	case OID_802_3_PERMANENT_ADDRESS:		DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].dev) {			length = ETH_ALEN;			memcpy ((u8 *) resp + 24,				rndis_per_dev_params [configNr].host_mac,				length);			retval = 0;		} else {			*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);			retval = 0;		}		break;			/* mandatory */	case OID_802_3_CURRENT_ADDRESS:		DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].dev) {			length = ETH_ALEN;			memcpy ((u8 *) resp + 24,				rndis_per_dev_params [configNr].host_mac,				length);			retval = 0;		}		break;			/* mandatory */	case OID_802_3_MULTICAST_LIST:		DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);		length = 4;		/* Multicast base address only */		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0xE0000000);		retval = 0;		break;			/* mandatory */	case OID_802_3_MAXIMUM_LIST_SIZE:		DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__);		 length = 4;		/* Multicast base address only */		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (1);		retval = 0;		break;			case OID_802_3_MAC_OPTIONS:		DEBUG("%s: OID_802_3_MAC_OPTIONS\n", __FUNCTION__);		break;	/* ieee802.3 statistics OIDs (table 4-4) */	/* mandatory */	case OID_802_3_RCV_ERROR_ALIGNMENT:		DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__);		if (rndis_per_dev_params [configNr].stats)		{			length = 4;			*((__le32 *) resp + 6) = cpu_to_le32 (				rndis_per_dev_params [configNr]					.stats->rx_frame_errors);			retval = 0;		}		break;			/* mandatory */	case OID_802_3_XMIT_ONE_COLLISION:		DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;			/* mandatory */	case OID_802_3_XMIT_MORE_COLLISIONS:		DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__);		length = 4;		*((__le32 *) resp + 6) = __constant_cpu_to_le32 (0);		retval = 0;		break;		#ifdef	RNDIS_OPTIONAL_STATS	case OID_802_3_XMIT_DEFERRED:		DEBUG("%s: OID_802_3_XMIT_DEFERRED\n", __FUNCTION__);		/* TODO */		break;			case OID_802_3_XMIT_MAX_COLLISIONS:		DEBUG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __FUNCTION__);		/* TODO */		break;			case OID_802_3_RCV_OVERRUN:		DEBUG("%s: OID_802_3_RCV_OVERRUN\n", __FUNCTION__);		/* TODO */		break;			case OID_802_3_XMIT_UNDERRUN:		DEBUG("%s: OID_802_3_XMIT_UNDERRUN\n", __FUNCTION__);		/* TODO */		break;			case OID_802_3_XMIT_HEARTBEAT_FAILURE:		DEBUG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __FUNCTION__);		/* TODO */		break;			case OID_802_3_XMIT_TIMES_CRS_LOST:		DEBUG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __FUNCTION__);		/* TODO */		break;			case OID_802_3_XMIT_LATE_COLLISIONS:		DEBUG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __FUNCTION__);		/* TODO */		break;		#endif	/* RNDIS_OPTIONAL_STATS */#ifdef	RNDIS_PM	/* power management OIDs (table 4-5) */	case OID_PNP_CAPABILITIES:		DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__);		/* just PM, and remote wakeup on link status change		 * (not magic packet or pattern match)		 */		length = sizeof (struct NDIS_PNP_CAPABILITIES);		memset (resp, 0, length);		{			struct NDIS_PNP_CAPABILITIES *caps = (void *) resp;			caps->Flags = NDIS_DEVICE_WAKE_UP_ENABLE;			caps->WakeUpCapabilities.MinLinkChangeWakeUp 				 = NdisDeviceStateD3;			/* FIXME then use usb_gadget_wakeup(), and			 * set USB_CONFIG_ATT_WAKEUP in config desc			 */		}		retval = 0;		break;	case OID_PNP_QUERY_POWER:		DEBUG("%s: OID_PNP_QUERY_POWER\n", __FUNCTION__);		/* sure, handle any power state that maps to USB suspend */		retval = 0;		break;#endif	default:		printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 			 __FUNCTION__, OID);	}		resp->InformationBufferOffset = __constant_cpu_to_le32 (16);	resp->InformationBufferLength = cpu_to_le32 (length);	resp->MessageLength = cpu_to_le32 (24 + length);	r->length = 24 + length;	return retval;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/340600ab4cf0cc41efd01a65af97ebb7d35a7f85/rndis.c/buggy/drivers/usb/gadget/rndis.c