#include <asm/unaligned.h>
-#undef RNDIS_PM
-#undef RNDIS_WAKEUP
-#undef VERBOSE
+#undef VERBOSE_DEBUG
#include "rndis.h"
OID_GEN_MAXIMUM_TOTAL_SIZE,
OID_GEN_MEDIA_CONNECT_STATUS,
OID_GEN_PHYSICAL_MEDIUM,
-#if 0
- OID_GEN_RNDIS_CONFIG_PARAMETER,
-#endif
/* the statistical stuff */
OID_GEN_XMIT_OK,
#endif /* RNDIS_OPTIONAL_STATS */
#ifdef RNDIS_PM
- /* PM and wakeup are mandatory for USB: */
+ /* PM and wakeup are "mandatory" for USB, but the RNDIS specs
+ * don't say what they mean ... and the NDIS specs are often
+ * confusing and/or ambiguous in this context. (That is, more
+ * so than their specs for the other OIDs.)
+ *
+ * FIXME someone who knows what these should do, please
+ * implement them!
+ */
/* power management */
OID_PNP_CAPABILITIES,
__le32 *outbuf;
int i, count;
rndis_query_cmplt_type *resp;
+ struct net_device *net;
+ struct net_device_stats *stats;
if (!r) return -ENOMEM;
resp = (rndis_query_cmplt_type *) r->buf;
outbuf = (__le32 *) &resp[1];
resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
+ net = rndis_per_dev_params[configNr].dev;
+ if (net->get_stats)
+ stats = net->get_stats(net);
+ else
+ stats = NULL;
+
switch (OID) {
/* general oids (table 4-1) */
case OID_GEN_XMIT_OK:
if (rndis_debug > 1)
DBG("%s: OID_GEN_XMIT_OK\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = 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);
+ if (stats) {
+ *outbuf = cpu_to_le32(stats->tx_packets
+ - stats->tx_errors - stats->tx_dropped);
retval = 0;
}
break;
case OID_GEN_RCV_OK:
if (rndis_debug > 1)
DBG("%s: OID_GEN_RCV_OK\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = 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);
+ if (stats) {
+ *outbuf = cpu_to_le32(stats->rx_packets
+ - stats->rx_errors - stats->rx_dropped);
retval = 0;
}
break;
case OID_GEN_XMIT_ERROR:
if (rndis_debug > 1)
DBG("%s: OID_GEN_XMIT_ERROR\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->tx_errors);
+ if (stats) {
+ *outbuf = cpu_to_le32(stats->tx_errors);
retval = 0;
}
break;
case OID_GEN_RCV_ERROR:
if (rndis_debug > 1)
DBG("%s: OID_GEN_RCV_ERROR\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->rx_errors);
+ if (stats) {
+ *outbuf = cpu_to_le32(stats->rx_errors);
retval = 0;
}
break;
/* mandatory */
case OID_GEN_RCV_NO_BUFFER:
DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->rx_dropped);
- retval = 0;
- }
- break;
-
-#ifdef RNDIS_OPTIONAL_STATS
- case OID_GEN_DIRECTED_BYTES_XMIT:
- DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __func__);
- /*
- * Aunt Tilly's size of shoes
- * minus antarctica count of penguins
- * divided by weight of Alpha Centauri
- */
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = 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;
- }
- break;
-
- case OID_GEN_DIRECTED_FRAMES_XMIT:
- DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __func__);
- /* dito */
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = 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;
- }
- break;
-
- case OID_GEN_MULTICAST_BYTES_XMIT:
- DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->multicast*1234);
- retval = 0;
- }
- break;
-
- case OID_GEN_MULTICAST_FRAMES_XMIT:
- DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->multicast);
- retval = 0;
- }
- break;
-
- case OID_GEN_BROADCAST_BYTES_XMIT:
- DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->tx_packets/42*255);
- retval = 0;
- }
- break;
-
- case OID_GEN_BROADCAST_FRAMES_XMIT:
- DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->tx_packets/42);
- retval = 0;
- }
- break;
-
- case OID_GEN_DIRECTED_BYTES_RCV:
- DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __func__);
- *outbuf = __constant_cpu_to_le32 (0);
- retval = 0;
- break;
-
- case OID_GEN_DIRECTED_FRAMES_RCV:
- DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __func__);
- *outbuf = __constant_cpu_to_le32 (0);
- retval = 0;
- break;
-
- case OID_GEN_MULTICAST_BYTES_RCV:
- DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->multicast * 1111);
- retval = 0;
- }
- break;
-
- case OID_GEN_MULTICAST_FRAMES_RCV:
- DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->multicast);
- retval = 0;
- }
- break;
-
- case OID_GEN_BROADCAST_BYTES_RCV:
- DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->rx_packets/42*255);
- retval = 0;
- }
- break;
-
- case OID_GEN_BROADCAST_FRAMES_RCV:
- DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->rx_packets/42);
- retval = 0;
- }
- break;
-
- case OID_GEN_RCV_CRC_ERROR:
- DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->rx_crc_errors);
+ if (stats) {
+ *outbuf = cpu_to_le32(stats->rx_dropped);
retval = 0;
}
break;
- case OID_GEN_TRANSMIT_QUEUE_LENGTH:
- DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __func__);
- *outbuf = __constant_cpu_to_le32 (0);
- retval = 0;
- break;
-#endif /* RNDIS_OPTIONAL_STATS */
-
/* ieee802.3 OIDs (table 4-3) */
/* mandatory */
/* mandatory */
case OID_802_3_RCV_ERROR_ALIGNMENT:
DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
- if (rndis_per_dev_params [configNr].stats) {
- *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
- .stats->rx_frame_errors);
+ if (stats) {
+ *outbuf = cpu_to_le32(stats->rx_frame_errors);
retval = 0;
}
break;
retval = 0;
break;
-#ifdef RNDIS_OPTIONAL_STATS
- case OID_802_3_XMIT_DEFERRED:
- DBG("%s: OID_802_3_XMIT_DEFERRED\n", __func__);
- /* TODO */
- break;
-
- case OID_802_3_XMIT_MAX_COLLISIONS:
- DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __func__);
- /* TODO */
- break;
-
- case OID_802_3_RCV_OVERRUN:
- DBG("%s: OID_802_3_RCV_OVERRUN\n", __func__);
- /* TODO */
- break;
-
- case OID_802_3_XMIT_UNDERRUN:
- DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __func__);
- /* TODO */
- break;
-
- case OID_802_3_XMIT_HEARTBEAT_FAILURE:
- DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __func__);
- /* TODO */
- break;
-
- case OID_802_3_XMIT_TIMES_CRS_LOST:
- DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __func__);
- /* TODO */
- break;
-
- case OID_802_3_XMIT_LATE_COLLISIONS:
- DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __func__);
- /* TODO */
- break;
-#endif /* RNDIS_OPTIONAL_STATS */
-
-#ifdef RNDIS_PM
- /* power management OIDs (table 4-5) */
- case OID_PNP_CAPABILITIES:
- DBG("%s: OID_PNP_CAPABILITIES\n", __func__);
-
- /* for now, no wakeup capabilities */
- length = sizeof (struct NDIS_PNP_CAPABILITIES);
- memset(outbuf, 0, length);
- retval = 0;
- break;
- case OID_PNP_QUERY_POWER:
- DBG("%s: OID_PNP_QUERY_POWER D%d\n", __func__,
- get_unaligned_le32(buf) - 1);
- /* only suspend is a real power state, and
- * it can't be entered by OID_PNP_SET_POWER...
- */
- length = 0;
- retval = 0;
- break;
-#endif
-
default:
pr_warning("%s: query unknown OID 0x%08X\n",
__func__, OID);
* what makes the packet flow start and stop, like
* activating the CDC Ethernet altsetting.
*/
-#ifdef RNDIS_PM
-update_linkstate:
-#endif
retval = 0;
if (*params->filter) {
params->state = RNDIS_DATA_INITIALIZED;
DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
retval = 0;
break;
-#if 0
- case OID_GEN_RNDIS_CONFIG_PARAMETER:
- {
- struct rndis_config_parameter *param;
- param = (struct rndis_config_parameter *) buf;
- DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
- __func__,
- min(cpu_to_le32(param->ParameterNameLength),80),
- buf + param->ParameterNameOffset);
- retval = 0;
- }
- break;
-#endif
-
-#ifdef RNDIS_PM
- case OID_PNP_SET_POWER:
- /* The only real power state is USB suspend, and RNDIS requests
- * can't enter it; this one isn't really about power. After
- * resuming, Windows forces a reset, and then SET_POWER D0.
- * FIXME ... then things go batty; Windows wedges itself.
- */
- i = get_unaligned_le32(buf);
- DBG("%s: OID_PNP_SET_POWER D%d\n", __func__, i - 1);
- switch (i) {
- case NdisDeviceStateD0:
- *params->filter = params->saved_filter;
- goto update_linkstate;
- case NdisDeviceStateD3:
- case NdisDeviceStateD2:
- case NdisDeviceStateD1:
- params->saved_filter = *params->filter;
- retval = 0;
- break;
- }
- break;
-
-#ifdef RNDIS_WAKEUP
- // no wakeup support advertised, so wakeup OIDs always fail:
- // - OID_PNP_ENABLE_WAKE_UP
- // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
-#endif
-
-#endif /* RNDIS_PM */
default:
pr_warning("%s: set unknown OID 0x%08X, size %d\n",
{
rndis_init_cmplt_type *resp;
rndis_resp_t *r;
+ struct rndis_params *params = rndis_per_dev_params + configNr;
- if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
+ if (!params->dev)
+ return -ENOTSUPP;
r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
if (!r)
resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3);
resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1);
resp->MaxTransferSize = cpu_to_le32 (
- rndis_per_dev_params [configNr].dev->mtu
+ params->dev->mtu
+ sizeof (struct ethhdr)
+ sizeof (struct rndis_packet_msg_type)
+ 22);
resp->AFListOffset = __constant_cpu_to_le32 (0);
resp->AFListSize = __constant_cpu_to_le32 (0);
- if (rndis_per_dev_params [configNr].ack)
- rndis_per_dev_params [configNr].ack (
- rndis_per_dev_params [configNr].dev);
-
+ params->resp_avail(params->v);
return 0;
}
{
rndis_query_cmplt_type *resp;
rndis_resp_t *r;
+ struct rndis_params *params = rndis_per_dev_params + configNr;
// DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID));
- if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
+ if (!params->dev)
+ return -ENOTSUPP;
/*
* we need more memory:
} else
resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
- if (rndis_per_dev_params [configNr].ack)
- rndis_per_dev_params [configNr].ack (
- rndis_per_dev_params [configNr].dev);
+ params->resp_avail(params->v);
return 0;
}
u32 BufLength, BufOffset;
rndis_set_cmplt_type *resp;
rndis_resp_t *r;
+ struct rndis_params *params = rndis_per_dev_params + configNr;
r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
if (!r)
BufLength = le32_to_cpu (buf->InformationBufferLength);
BufOffset = le32_to_cpu (buf->InformationBufferOffset);
-#ifdef VERBOSE
+#ifdef VERBOSE_DEBUG
DBG("%s: Length: %d\n", __func__, BufLength);
DBG("%s: Offset: %d\n", __func__, BufOffset);
DBG("%s: InfoBuffer: ", __func__);
else
resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
- if (rndis_per_dev_params [configNr].ack)
- rndis_per_dev_params [configNr].ack (
- rndis_per_dev_params [configNr].dev);
-
+ params->resp_avail(params->v);
return 0;
}
{
rndis_reset_cmplt_type *resp;
rndis_resp_t *r;
+ struct rndis_params *params = rndis_per_dev_params + configNr;
r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
if (!r)
/* resent information */
resp->AddressingReset = __constant_cpu_to_le32 (1);
- if (rndis_per_dev_params [configNr].ack)
- rndis_per_dev_params [configNr].ack (
- rndis_per_dev_params [configNr].dev);
-
+ params->resp_avail(params->v);
return 0;
}
{
rndis_keepalive_cmplt_type *resp;
rndis_resp_t *r;
+ struct rndis_params *params = rndis_per_dev_params + configNr;
/* host "should" check only in RNDIS_DATA_INITIALIZED state */
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
- if (rndis_per_dev_params [configNr].ack)
- rndis_per_dev_params [configNr].ack (
- rndis_per_dev_params [configNr].dev);
-
+ params->resp_avail(params->v);
return 0;
}
{
rndis_indicate_status_msg_type *resp;
rndis_resp_t *r;
+ struct rndis_params *params = rndis_per_dev_params + configNr;
- if (rndis_per_dev_params [configNr].state == RNDIS_UNINITIALIZED)
+ if (params->state == RNDIS_UNINITIALIZED)
return -ENOTSUPP;
r = rndis_add_response (configNr,
resp->StatusBufferLength = __constant_cpu_to_le32 (0);
resp->StatusBufferOffset = __constant_cpu_to_le32 (0);
- if (rndis_per_dev_params [configNr].ack)
- rndis_per_dev_params [configNr].ack (
- rndis_per_dev_params [configNr].dev);
+ params->resp_avail(params->v);
return 0;
}
if (configNr >= RNDIS_MAX_CONFIGS)
return;
- rndis_per_dev_params [configNr].used = 0;
rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
/* drain the response queue */
return -ENOTSUPP;
}
-int rndis_register (int (* rndis_control_ack) (struct net_device *))
+int rndis_register(void (*resp_avail)(void *v), void *v)
{
u8 i;
+ if (!resp_avail)
+ return -EINVAL;
+
for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
if (!rndis_per_dev_params [i].used) {
rndis_per_dev_params [i].used = 1;
- rndis_per_dev_params [i].ack = rndis_control_ack;
+ rndis_per_dev_params [i].resp_avail = resp_avail;
+ rndis_per_dev_params [i].v = v;
DBG("%s: configNr = %d\n", __func__, i);
return i;
}
}
DBG("failed\n");
- return -1;
+ return -ENODEV;
}
void rndis_deregister (int configNr)
return;
}
-int rndis_set_param_dev (u8 configNr, struct net_device *dev,
- struct net_device_stats *stats,
- u16 *cdc_filter)
+int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
{
DBG("%s:\n", __func__ );
- if (!dev || !stats) return -1;
+ if (!dev)
+ return -EINVAL;
if (configNr >= RNDIS_MAX_CONFIGS) return -1;
rndis_per_dev_params [configNr].dev = dev;
- rndis_per_dev_params [configNr].stats = stats;
rndis_per_dev_params [configNr].filter = cdc_filter;
return 0;