Commit 83210e59 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

usb: gadget: rndis: use rndis_params instead of configNr

RNDIS function has a limitation on the number of allowed instances.
So far it has been RNDIS_MAX_CONFIGS, which happens to be one.
In order to eliminate this kind of arbitrary limitation we should not
preallocate a predefined (RNDIS_MAX_CONFIGS) array of struct rndis_params
instances but instead allow allocating them on demand.

This patch prepares the elimination of the said limit by converting all the
functions which accept rndis config number to accept a pointer to the
actual struct rndis_params. Consequently, rndis_register() returns
a pointer to a corresponding struct rndis_params instance. The pointer
is then always used by f_rndis.c instead of config number when it talks
to rndis.c API.

A nice side-effect of the changes is that many lines of code in rndis.c
become shorter and fit in 80 columns.

If a function prototype changes in rndis.h a style cleanup is made
at the same time, otherwise checkpatch complains that the patch
has style problems.
Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent d74c23d3
...@@ -76,7 +76,7 @@ struct f_rndis { ...@@ -76,7 +76,7 @@ struct f_rndis {
u8 ethaddr[ETH_ALEN]; u8 ethaddr[ETH_ALEN];
u32 vendorID; u32 vendorID;
const char *manufacturer; const char *manufacturer;
int config; struct rndis_params *params;
struct usb_ep *notify; struct usb_ep *notify;
struct usb_request *notify_req; struct usb_request *notify_req;
...@@ -453,7 +453,7 @@ static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req) ...@@ -453,7 +453,7 @@ static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
/* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */ /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
// spin_lock(&dev->lock); // spin_lock(&dev->lock);
status = rndis_msg_parser(rndis->config, (u8 *) req->buf); status = rndis_msg_parser(rndis->params, (u8 *) req->buf);
if (status < 0) if (status < 0)
pr_err("RNDIS command error %d, %d/%d\n", pr_err("RNDIS command error %d, %d/%d\n",
status, req->actual, req->length); status, req->actual, req->length);
...@@ -499,12 +499,12 @@ rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) ...@@ -499,12 +499,12 @@ rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
u32 n; u32 n;
/* return the result */ /* return the result */
buf = rndis_get_next_response(rndis->config, &n); buf = rndis_get_next_response(rndis->params, &n);
if (buf) { if (buf) {
memcpy(req->buf, buf, n); memcpy(req->buf, buf, n);
req->complete = rndis_response_complete; req->complete = rndis_response_complete;
req->context = rndis; req->context = rndis;
rndis_free_response(rndis->config, buf); rndis_free_response(rndis->params, buf);
value = n; value = n;
} }
/* else stalls ... spec says to avoid that */ /* else stalls ... spec says to avoid that */
...@@ -597,7 +597,7 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt) ...@@ -597,7 +597,7 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
if (IS_ERR(net)) if (IS_ERR(net))
return PTR_ERR(net); return PTR_ERR(net);
rndis_set_param_dev(rndis->config, net, rndis_set_param_dev(rndis->params, net,
&rndis->port.cdc_filter); &rndis->port.cdc_filter);
} else } else
goto fail; goto fail;
...@@ -617,7 +617,7 @@ static void rndis_disable(struct usb_function *f) ...@@ -617,7 +617,7 @@ static void rndis_disable(struct usb_function *f)
DBG(cdev, "rndis deactivated\n"); DBG(cdev, "rndis deactivated\n");
rndis_uninit(rndis->config); rndis_uninit(rndis->params);
gether_disconnect(&rndis->port); gether_disconnect(&rndis->port);
usb_ep_disable(rndis->notify); usb_ep_disable(rndis->notify);
...@@ -640,9 +640,9 @@ static void rndis_open(struct gether *geth) ...@@ -640,9 +640,9 @@ static void rndis_open(struct gether *geth)
DBG(cdev, "%s\n", __func__); DBG(cdev, "%s\n", __func__);
rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3,
bitrate(cdev->gadget) / 100); bitrate(cdev->gadget) / 100);
rndis_signal_connect(rndis->config); rndis_signal_connect(rndis->params);
} }
static void rndis_close(struct gether *geth) static void rndis_close(struct gether *geth)
...@@ -651,8 +651,8 @@ static void rndis_close(struct gether *geth) ...@@ -651,8 +651,8 @@ static void rndis_close(struct gether *geth)
DBG(geth->func.config->cdev, "%s\n", __func__); DBG(geth->func.config->cdev, "%s\n", __func__);
rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0);
rndis_signal_disconnect(rndis->config); rndis_signal_disconnect(rndis->params);
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -796,11 +796,11 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) ...@@ -796,11 +796,11 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
rndis->port.open = rndis_open; rndis->port.open = rndis_open;
rndis->port.close = rndis_close; rndis->port.close = rndis_close;
rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0); rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0);
rndis_set_host_mac(rndis->config, rndis->ethaddr); rndis_set_host_mac(rndis->params, rndis->ethaddr);
if (rndis->manufacturer && rndis->vendorID && if (rndis->manufacturer && rndis->vendorID &&
rndis_set_param_vendor(rndis->config, rndis->vendorID, rndis_set_param_vendor(rndis->params, rndis->vendorID,
rndis->manufacturer)) { rndis->manufacturer)) {
status = -EINVAL; status = -EINVAL;
goto fail_free_descs; goto fail_free_descs;
...@@ -944,7 +944,7 @@ static void rndis_free(struct usb_function *f) ...@@ -944,7 +944,7 @@ static void rndis_free(struct usb_function *f)
struct f_rndis_opts *opts; struct f_rndis_opts *opts;
rndis = func_to_rndis(f); rndis = func_to_rndis(f);
rndis_deregister(rndis->config); rndis_deregister(rndis->params);
opts = container_of(f->fi, struct f_rndis_opts, func_inst); opts = container_of(f->fi, struct f_rndis_opts, func_inst);
kfree(rndis); kfree(rndis);
mutex_lock(&opts->lock); mutex_lock(&opts->lock);
...@@ -968,7 +968,7 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi) ...@@ -968,7 +968,7 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
{ {
struct f_rndis *rndis; struct f_rndis *rndis;
struct f_rndis_opts *opts; struct f_rndis_opts *opts;
int status; struct rndis_params *params;
/* allocate and initialize one new instance */ /* allocate and initialize one new instance */
rndis = kzalloc(sizeof(*rndis), GFP_KERNEL); rndis = kzalloc(sizeof(*rndis), GFP_KERNEL);
...@@ -1002,12 +1002,12 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi) ...@@ -1002,12 +1002,12 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
rndis->port.func.disable = rndis_disable; rndis->port.func.disable = rndis_disable;
rndis->port.func.free_func = rndis_free; rndis->port.func.free_func = rndis_free;
status = rndis_register(rndis_response_available, rndis); params = rndis_register(rndis_response_available, rndis);
if (status < 0) { if (IS_ERR(params)) {
kfree(rndis); kfree(rndis);
return ERR_PTR(status); return ERR_CAST(params);
} }
rndis->config = status; rndis->params = params;
return &rndis->port.func; return &rndis->port.func;
} }
......
...@@ -66,7 +66,8 @@ static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS]; ...@@ -66,7 +66,8 @@ static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS];
static const __le32 rndis_driver_version = cpu_to_le32(1); static const __le32 rndis_driver_version = cpu_to_le32(1);
/* Function Prototypes */ /* Function Prototypes */
static rndis_resp_t *rndis_add_response(int configNr, u32 length); static rndis_resp_t *rndis_add_response(struct rndis_params *params,
u32 length);
/* supported OIDs */ /* supported OIDs */
...@@ -160,7 +161,7 @@ static const u32 oid_supported_list[] = ...@@ -160,7 +161,7 @@ static const u32 oid_supported_list[] =
/* NDIS Functions */ /* NDIS Functions */
static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf,
unsigned buf_len, rndis_resp_t *r) unsigned buf_len, rndis_resp_t *r)
{ {
int retval = -ENOTSUPP; int retval = -ENOTSUPP;
...@@ -192,7 +193,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -192,7 +193,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
outbuf = (__le32 *)&resp[1]; outbuf = (__le32 *)&resp[1];
resp->InformationBufferOffset = cpu_to_le32(16); resp->InformationBufferOffset = cpu_to_le32(16);
net = rndis_per_dev_params[configNr].dev; net = params->dev;
stats = dev_get_stats(net, &temp); stats = dev_get_stats(net, &temp);
switch (OID) { switch (OID) {
...@@ -225,7 +226,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -225,7 +226,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_MEDIA_SUPPORTED: case RNDIS_OID_GEN_MEDIA_SUPPORTED:
pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__); pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__);
*outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); *outbuf = cpu_to_le32(params->medium);
retval = 0; retval = 0;
break; break;
...@@ -233,16 +234,15 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -233,16 +234,15 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
case RNDIS_OID_GEN_MEDIA_IN_USE: case RNDIS_OID_GEN_MEDIA_IN_USE:
pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__); pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__);
/* one medium, one transport... (maybe you do it better) */ /* one medium, one transport... (maybe you do it better) */
*outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium); *outbuf = cpu_to_le32(params->medium);
retval = 0; retval = 0;
break; break;
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE: case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE:
pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
if (rndis_per_dev_params[configNr].dev) { if (params->dev) {
*outbuf = cpu_to_le32( *outbuf = cpu_to_le32(params->dev->mtu);
rndis_per_dev_params[configNr].dev->mtu);
retval = 0; retval = 0;
} }
break; break;
...@@ -251,21 +251,18 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -251,21 +251,18 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
case RNDIS_OID_GEN_LINK_SPEED: case RNDIS_OID_GEN_LINK_SPEED:
if (rndis_debug > 1) if (rndis_debug > 1)
pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__); pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__);
if (rndis_per_dev_params[configNr].media_state if (params->media_state == RNDIS_MEDIA_STATE_DISCONNECTED)
== RNDIS_MEDIA_STATE_DISCONNECTED)
*outbuf = cpu_to_le32(0); *outbuf = cpu_to_le32(0);
else else
*outbuf = cpu_to_le32( *outbuf = cpu_to_le32(params->speed);
rndis_per_dev_params[configNr].speed);
retval = 0; retval = 0;
break; break;
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE: case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE:
pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
if (rndis_per_dev_params[configNr].dev) { if (params->dev) {
*outbuf = cpu_to_le32( *outbuf = cpu_to_le32(params->dev->mtu);
rndis_per_dev_params[configNr].dev->mtu);
retval = 0; retval = 0;
} }
break; break;
...@@ -273,9 +270,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -273,9 +270,8 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE: case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE:
pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
if (rndis_per_dev_params[configNr].dev) { if (params->dev) {
*outbuf = cpu_to_le32( *outbuf = cpu_to_le32(params->dev->mtu);
rndis_per_dev_params[configNr].dev->mtu);
retval = 0; retval = 0;
} }
break; break;
...@@ -283,20 +279,16 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -283,20 +279,16 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_VENDOR_ID: case RNDIS_OID_GEN_VENDOR_ID:
pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__); pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__);
*outbuf = cpu_to_le32( *outbuf = cpu_to_le32(params->vendorID);
rndis_per_dev_params[configNr].vendorID);
retval = 0; retval = 0;
break; break;
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_VENDOR_DESCRIPTION: case RNDIS_OID_GEN_VENDOR_DESCRIPTION:
pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__); pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__);
if (rndis_per_dev_params[configNr].vendorDescr) { if (params->vendorDescr) {
length = strlen(rndis_per_dev_params[configNr]. length = strlen(params->vendorDescr);
vendorDescr); memcpy(outbuf, params->vendorDescr, length);
memcpy(outbuf,
rndis_per_dev_params[configNr].vendorDescr,
length);
} else { } else {
outbuf[0] = 0; outbuf[0] = 0;
} }
...@@ -313,7 +305,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -313,7 +305,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
/* mandatory */ /* mandatory */
case RNDIS_OID_GEN_CURRENT_PACKET_FILTER: case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__); pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
*outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter); *outbuf = cpu_to_le32(*params->filter);
retval = 0; retval = 0;
break; break;
...@@ -328,8 +320,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -328,8 +320,7 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS: case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS:
if (rndis_debug > 1) if (rndis_debug > 1)
pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
*outbuf = cpu_to_le32(rndis_per_dev_params[configNr] *outbuf = cpu_to_le32(params->media_state);
.media_state);
retval = 0; retval = 0;
break; break;
...@@ -409,11 +400,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -409,11 +400,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
/* mandatory */ /* mandatory */
case RNDIS_OID_802_3_PERMANENT_ADDRESS: case RNDIS_OID_802_3_PERMANENT_ADDRESS:
pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__); pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__);
if (rndis_per_dev_params[configNr].dev) { if (params->dev) {
length = ETH_ALEN; length = ETH_ALEN;
memcpy(outbuf, memcpy(outbuf, params->host_mac, length);
rndis_per_dev_params[configNr].host_mac,
length);
retval = 0; retval = 0;
} }
break; break;
...@@ -421,11 +410,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -421,11 +410,9 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
/* mandatory */ /* mandatory */
case RNDIS_OID_802_3_CURRENT_ADDRESS: case RNDIS_OID_802_3_CURRENT_ADDRESS:
pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__); pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__);
if (rndis_per_dev_params[configNr].dev) { if (params->dev) {
length = ETH_ALEN; length = ETH_ALEN;
memcpy(outbuf, memcpy(outbuf, params->host_mac, length);
rndis_per_dev_params [configNr].host_mac,
length);
retval = 0; retval = 0;
} }
break; break;
...@@ -490,12 +477,11 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf, ...@@ -490,12 +477,11 @@ static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
return retval; return retval;
} }
static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, static int gen_ndis_set_resp(struct rndis_params *params, u32 OID,
rndis_resp_t *r) u8 *buf, u32 buf_len, rndis_resp_t *r)
{ {
rndis_set_cmplt_type *resp; rndis_set_cmplt_type *resp;
int i, retval = -ENOTSUPP; int i, retval = -ENOTSUPP;
struct rndis_params *params;
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
...@@ -514,7 +500,6 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, ...@@ -514,7 +500,6 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len,
} }
} }
params = &rndis_per_dev_params[configNr];
switch (OID) { switch (OID) {
case RNDIS_OID_GEN_CURRENT_PACKET_FILTER: case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
...@@ -563,16 +548,16 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len, ...@@ -563,16 +548,16 @@ static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len,
* Response Functions * Response Functions
*/ */
static int rndis_init_response(int configNr, rndis_init_msg_type *buf) static int rndis_init_response(struct rndis_params *params,
rndis_init_msg_type *buf)
{ {
rndis_init_cmplt_type *resp; rndis_init_cmplt_type *resp;
rndis_resp_t *r; rndis_resp_t *r;
struct rndis_params *params = rndis_per_dev_params + configNr;
if (!params->dev) if (!params->dev)
return -ENOTSUPP; return -ENOTSUPP;
r = rndis_add_response(configNr, sizeof(rndis_init_cmplt_type)); r = rndis_add_response(params, sizeof(rndis_init_cmplt_type));
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
resp = (rndis_init_cmplt_type *)r->buf; resp = (rndis_init_cmplt_type *)r->buf;
...@@ -599,11 +584,11 @@ static int rndis_init_response(int configNr, rndis_init_msg_type *buf) ...@@ -599,11 +584,11 @@ static int rndis_init_response(int configNr, rndis_init_msg_type *buf)
return 0; return 0;
} }
static int rndis_query_response(int configNr, rndis_query_msg_type *buf) static int rndis_query_response(struct rndis_params *params,
rndis_query_msg_type *buf)
{ {
rndis_query_cmplt_type *resp; rndis_query_cmplt_type *resp;
rndis_resp_t *r; rndis_resp_t *r;
struct rndis_params *params = rndis_per_dev_params + configNr;
/* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
if (!params->dev) if (!params->dev)
...@@ -615,7 +600,7 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf) ...@@ -615,7 +600,7 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
* rndis_query_cmplt_type followed by data. * rndis_query_cmplt_type followed by data.
* oid_supported_list is the largest data reply * oid_supported_list is the largest data reply
*/ */
r = rndis_add_response(configNr, r = rndis_add_response(params,
sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type)); sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
...@@ -624,7 +609,7 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf) ...@@ -624,7 +609,7 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C); resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C);
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID), if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID),
le32_to_cpu(buf->InformationBufferOffset) le32_to_cpu(buf->InformationBufferOffset)
+ 8 + (u8 *)buf, + 8 + (u8 *)buf,
le32_to_cpu(buf->InformationBufferLength), le32_to_cpu(buf->InformationBufferLength),
...@@ -641,14 +626,14 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf) ...@@ -641,14 +626,14 @@ static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
return 0; return 0;
} }
static int rndis_set_response(int configNr, rndis_set_msg_type *buf) static int rndis_set_response(struct rndis_params *params,
rndis_set_msg_type *buf)
{ {
u32 BufLength, BufOffset; u32 BufLength, BufOffset;
rndis_set_cmplt_type *resp; rndis_set_cmplt_type *resp;
rndis_resp_t *r; rndis_resp_t *r;
struct rndis_params *params = rndis_per_dev_params + configNr;
r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type)); r = rndis_add_response(params, sizeof(rndis_set_cmplt_type));
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
resp = (rndis_set_cmplt_type *)r->buf; resp = (rndis_set_cmplt_type *)r->buf;
...@@ -671,7 +656,7 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf) ...@@ -671,7 +656,7 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C); resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C);
resp->MessageLength = cpu_to_le32(16); resp->MessageLength = cpu_to_le32(16);
resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID), if (gen_ndis_set_resp(params, le32_to_cpu(buf->OID),
((u8 *)buf) + 8 + BufOffset, BufLength, r)) ((u8 *)buf) + 8 + BufOffset, BufLength, r))
resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
else else
...@@ -681,13 +666,13 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf) ...@@ -681,13 +666,13 @@ static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
return 0; return 0;
} }
static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf) static int rndis_reset_response(struct rndis_params *params,
rndis_reset_msg_type *buf)
{ {
rndis_reset_cmplt_type *resp; rndis_reset_cmplt_type *resp;
rndis_resp_t *r; rndis_resp_t *r;
struct rndis_params *params = rndis_per_dev_params + configNr;
r = rndis_add_response(configNr, sizeof(rndis_reset_cmplt_type)); r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type));
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
resp = (rndis_reset_cmplt_type *)r->buf; resp = (rndis_reset_cmplt_type *)r->buf;
...@@ -702,16 +687,15 @@ static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf) ...@@ -702,16 +687,15 @@ static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf)
return 0; return 0;
} }
static int rndis_keepalive_response(int configNr, static int rndis_keepalive_response(struct rndis_params *params,
rndis_keepalive_msg_type *buf) rndis_keepalive_msg_type *buf)
{ {
rndis_keepalive_cmplt_type *resp; rndis_keepalive_cmplt_type *resp;
rndis_resp_t *r; rndis_resp_t *r;
struct rndis_params *params = rndis_per_dev_params + configNr;
/* host "should" check only in RNDIS_DATA_INITIALIZED state */ /* host "should" check only in RNDIS_DATA_INITIALIZED state */
r = rndis_add_response(configNr, sizeof(rndis_keepalive_cmplt_type)); r = rndis_add_response(params, sizeof(rndis_keepalive_cmplt_type));
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
resp = (rndis_keepalive_cmplt_type *)r->buf; resp = (rndis_keepalive_cmplt_type *)r->buf;
...@@ -729,17 +713,15 @@ static int rndis_keepalive_response(int configNr, ...@@ -729,17 +713,15 @@ static int rndis_keepalive_response(int configNr,
/* /*
* Device to Host Comunication * Device to Host Comunication
*/ */
static int rndis_indicate_status_msg(int configNr, u32 status) static int rndis_indicate_status_msg(struct rndis_params *params, u32 status)
{ {
rndis_indicate_status_msg_type *resp; rndis_indicate_status_msg_type *resp;
rndis_resp_t *r; rndis_resp_t *r;
struct rndis_params *params = rndis_per_dev_params + configNr;
if (params->state == RNDIS_UNINITIALIZED) if (params->state == RNDIS_UNINITIALIZED)
return -ENOTSUPP; return -ENOTSUPP;
r = rndis_add_response(configNr, r = rndis_add_response(params, sizeof(rndis_indicate_status_msg_type));
sizeof(rndis_indicate_status_msg_type));
if (!r) if (!r)
return -ENOMEM; return -ENOMEM;
resp = (rndis_indicate_status_msg_type *)r->buf; resp = (rndis_indicate_status_msg_type *)r->buf;
...@@ -754,53 +736,48 @@ static int rndis_indicate_status_msg(int configNr, u32 status) ...@@ -754,53 +736,48 @@ static int rndis_indicate_status_msg(int configNr, u32 status)
return 0; return 0;
} }
int rndis_signal_connect(int configNr) int rndis_signal_connect(struct rndis_params *params)
{ {
rndis_per_dev_params[configNr].media_state params->media_state = RNDIS_MEDIA_STATE_CONNECTED;
= RNDIS_MEDIA_STATE_CONNECTED; return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_CONNECT);
return rndis_indicate_status_msg(configNr,
RNDIS_STATUS_MEDIA_CONNECT);
} }
EXPORT_SYMBOL_GPL(rndis_signal_connect); EXPORT_SYMBOL_GPL(rndis_signal_connect);
int rndis_signal_disconnect(int configNr) int rndis_signal_disconnect(struct rndis_params *params)
{ {
rndis_per_dev_params[configNr].media_state params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
= RNDIS_MEDIA_STATE_DISCONNECTED; return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_DISCONNECT);
return rndis_indicate_status_msg(configNr,
RNDIS_STATUS_MEDIA_DISCONNECT);
} }
EXPORT_SYMBOL_GPL(rndis_signal_disconnect); EXPORT_SYMBOL_GPL(rndis_signal_disconnect);
void rndis_uninit(int configNr) void rndis_uninit(struct rndis_params *params)
{ {
u8 *buf; u8 *buf;
u32 length; u32 length;
if (configNr >= RNDIS_MAX_CONFIGS) if (!params)
return; return;
rndis_per_dev_params[configNr].state = RNDIS_UNINITIALIZED; params->state = RNDIS_UNINITIALIZED;
/* drain the response queue */ /* drain the response queue */
while ((buf = rndis_get_next_response(configNr, &length))) while ((buf = rndis_get_next_response(params, &length)))
rndis_free_response(configNr, buf); rndis_free_response(params, buf);
} }
EXPORT_SYMBOL_GPL(rndis_uninit); EXPORT_SYMBOL_GPL(rndis_uninit);
void rndis_set_host_mac(int configNr, const u8 *addr) void rndis_set_host_mac(struct rndis_params *params, const u8 *addr)
{ {
rndis_per_dev_params[configNr].host_mac = addr; params->host_mac = addr;
} }
EXPORT_SYMBOL_GPL(rndis_set_host_mac); EXPORT_SYMBOL_GPL(rndis_set_host_mac);
/* /*
* Message Parser * Message Parser
*/ */
int rndis_msg_parser(u8 configNr, u8 *buf) int rndis_msg_parser(struct rndis_params *params, u8 *buf)
{ {
u32 MsgType, MsgLength; u32 MsgType, MsgLength;
__le32 *tmp; __le32 *tmp;
struct rndis_params *params;
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
...@@ -809,9 +786,8 @@ int rndis_msg_parser(u8 configNr, u8 *buf) ...@@ -809,9 +786,8 @@ int rndis_msg_parser(u8 configNr, u8 *buf)
MsgType = get_unaligned_le32(tmp++); MsgType = get_unaligned_le32(tmp++);
MsgLength = get_unaligned_le32(tmp++); MsgLength = get_unaligned_le32(tmp++);
if (configNr >= RNDIS_MAX_CONFIGS) if (!params)
return -ENOTSUPP; return -ENOTSUPP;
params = &rndis_per_dev_params[configNr];
/* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
* rx/tx statistics and link status, in addition to KEEPALIVE traffic * rx/tx statistics and link status, in addition to KEEPALIVE traffic
...@@ -824,8 +800,7 @@ int rndis_msg_parser(u8 configNr, u8 *buf) ...@@ -824,8 +800,7 @@ int rndis_msg_parser(u8 configNr, u8 *buf)
pr_debug("%s: RNDIS_MSG_INIT\n", pr_debug("%s: RNDIS_MSG_INIT\n",
__func__); __func__);
params->state = RNDIS_INITIALIZED; params->state = RNDIS_INITIALIZED;
return rndis_init_response(configNr, return rndis_init_response(params, (rndis_init_msg_type *)buf);
(rndis_init_msg_type *)buf);
case RNDIS_MSG_HALT: case RNDIS_MSG_HALT:
pr_debug("%s: RNDIS_MSG_HALT\n", pr_debug("%s: RNDIS_MSG_HALT\n",
...@@ -838,17 +813,16 @@ int rndis_msg_parser(u8 configNr, u8 *buf) ...@@ -838,17 +813,16 @@ int rndis_msg_parser(u8 configNr, u8 *buf)
return 0; return 0;
case RNDIS_MSG_QUERY: case RNDIS_MSG_QUERY:
return rndis_query_response(configNr, return rndis_query_response(params,
(rndis_query_msg_type *)buf); (rndis_query_msg_type *)buf);
case RNDIS_MSG_SET: case RNDIS_MSG_SET:
return rndis_set_response(configNr, return rndis_set_response(params, (rndis_set_msg_type *)buf);
(rndis_set_msg_type *)buf);
case RNDIS_MSG_RESET: case RNDIS_MSG_RESET:
pr_debug("%s: RNDIS_MSG_RESET\n", pr_debug("%s: RNDIS_MSG_RESET\n",
__func__); __func__);
return rndis_reset_response(configNr, return rndis_reset_response(params,
(rndis_reset_msg_type *)buf); (rndis_reset_msg_type *)buf);
case RNDIS_MSG_KEEPALIVE: case RNDIS_MSG_KEEPALIVE:
...@@ -856,7 +830,7 @@ int rndis_msg_parser(u8 configNr, u8 *buf) ...@@ -856,7 +830,7 @@ int rndis_msg_parser(u8 configNr, u8 *buf)
if (rndis_debug > 1) if (rndis_debug > 1)
pr_debug("%s: RNDIS_MSG_KEEPALIVE\n", pr_debug("%s: RNDIS_MSG_KEEPALIVE\n",
__func__); __func__);
return rndis_keepalive_response(configNr, return rndis_keepalive_response(params,
(rndis_keepalive_msg_type *) (rndis_keepalive_msg_type *)
buf); buf);
...@@ -876,12 +850,12 @@ int rndis_msg_parser(u8 configNr, u8 *buf) ...@@ -876,12 +850,12 @@ int rndis_msg_parser(u8 configNr, u8 *buf)
} }
EXPORT_SYMBOL_GPL(rndis_msg_parser); EXPORT_SYMBOL_GPL(rndis_msg_parser);
int rndis_register(void (*resp_avail)(void *v), void *v) struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v)
{ {
u8 i; u8 i;
if (!resp_avail) if (!resp_avail)
return -EINVAL; return ERR_PTR(-EINVAL);
for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
if (!rndis_per_dev_params[i].used) { if (!rndis_per_dev_params[i].used) {
...@@ -889,58 +863,64 @@ int rndis_register(void (*resp_avail)(void *v), void *v) ...@@ -889,58 +863,64 @@ int rndis_register(void (*resp_avail)(void *v), void *v)
rndis_per_dev_params[i].resp_avail = resp_avail; rndis_per_dev_params[i].resp_avail = resp_avail;
rndis_per_dev_params[i].v = v; rndis_per_dev_params[i].v = v;
pr_debug("%s: configNr = %d\n", __func__, i); pr_debug("%s: configNr = %d\n", __func__, i);
return i; return &rndis_per_dev_params[i];
} }
} }
pr_debug("failed\n"); pr_debug("failed\n");
return -ENODEV; return ERR_PTR(-ENODEV);
} }
EXPORT_SYMBOL_GPL(rndis_register); EXPORT_SYMBOL_GPL(rndis_register);
void rndis_deregister(int configNr) void rndis_deregister(struct rndis_params *params)
{ {
pr_debug("%s:\n", __func__); pr_debug("%s:\n", __func__);
if (configNr >= RNDIS_MAX_CONFIGS) return; if (!params)
rndis_per_dev_params[configNr].used = 0; return;
params->used = 0;
} }
EXPORT_SYMBOL_GPL(rndis_deregister); EXPORT_SYMBOL_GPL(rndis_deregister);
int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev,
u16 *cdc_filter)
{ {
pr_debug("%s:\n", __func__); pr_debug("%s:\n", __func__);
if (!dev) if (!dev)
return -EINVAL; return -EINVAL;
if (configNr >= RNDIS_MAX_CONFIGS) return -1; if (!params)
return -1;
rndis_per_dev_params[configNr].dev = dev; params->dev = dev;
rndis_per_dev_params[configNr].filter = cdc_filter; params->filter = cdc_filter;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(rndis_set_param_dev); EXPORT_SYMBOL_GPL(rndis_set_param_dev);
int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID,
const char *vendorDescr)
{ {
pr_debug("%s:\n", __func__); pr_debug("%s:\n", __func__);
if (!vendorDescr) return -1; if (!vendorDescr) return -1;
if (configNr >= RNDIS_MAX_CONFIGS) return -1; if (!params)
return -1;
rndis_per_dev_params[configNr].vendorID = vendorID; params->vendorID = vendorID;
rndis_per_dev_params[configNr].vendorDescr = vendorDescr; params->vendorDescr = vendorDescr;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(rndis_set_param_vendor); EXPORT_SYMBOL_GPL(rndis_set_param_vendor);
int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) int rndis_set_param_medium(struct rndis_params *params, u32 medium, u32 speed)
{ {
pr_debug("%s: %u %u\n", __func__, medium, speed); pr_debug("%s: %u %u\n", __func__, medium, speed);
if (configNr >= RNDIS_MAX_CONFIGS) return -1; if (!params)
return -1;
rndis_per_dev_params[configNr].medium = medium; params->medium = medium;
rndis_per_dev_params[configNr].speed = speed; params->speed = speed;
return 0; return 0;
} }
...@@ -961,13 +941,12 @@ void rndis_add_hdr(struct sk_buff *skb) ...@@ -961,13 +941,12 @@ void rndis_add_hdr(struct sk_buff *skb)
} }
EXPORT_SYMBOL_GPL(rndis_add_hdr); EXPORT_SYMBOL_GPL(rndis_add_hdr);
void rndis_free_response(int configNr, u8 *buf) void rndis_free_response(struct rndis_params *params, u8 *buf)
{ {
rndis_resp_t *r; rndis_resp_t *r;
struct list_head *act, *tmp; struct list_head *act, *tmp;
list_for_each_safe(act, tmp, list_for_each_safe(act, tmp, &(params->resp_queue))
&(rndis_per_dev_params[configNr].resp_queue))
{ {
r = list_entry(act, rndis_resp_t, list); r = list_entry(act, rndis_resp_t, list);
if (r && r->buf == buf) { if (r && r->buf == buf) {
...@@ -978,15 +957,14 @@ void rndis_free_response(int configNr, u8 *buf) ...@@ -978,15 +957,14 @@ void rndis_free_response(int configNr, u8 *buf)
} }
EXPORT_SYMBOL_GPL(rndis_free_response); EXPORT_SYMBOL_GPL(rndis_free_response);
u8 *rndis_get_next_response(int configNr, u32 *length) u8 *rndis_get_next_response(struct rndis_params *params, u32 *length)
{ {
rndis_resp_t *r; rndis_resp_t *r;
struct list_head *act, *tmp; struct list_head *act, *tmp;
if (!length) return NULL; if (!length) return NULL;
list_for_each_safe(act, tmp, list_for_each_safe(act, tmp, &(params->resp_queue))
&(rndis_per_dev_params[configNr].resp_queue))
{ {
r = list_entry(act, rndis_resp_t, list); r = list_entry(act, rndis_resp_t, list);
if (!r->send) { if (!r->send) {
...@@ -1000,7 +978,7 @@ u8 *rndis_get_next_response(int configNr, u32 *length) ...@@ -1000,7 +978,7 @@ u8 *rndis_get_next_response(int configNr, u32 *length)
} }
EXPORT_SYMBOL_GPL(rndis_get_next_response); EXPORT_SYMBOL_GPL(rndis_get_next_response);
static rndis_resp_t *rndis_add_response(int configNr, u32 length) static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length)
{ {
rndis_resp_t *r; rndis_resp_t *r;
...@@ -1012,8 +990,7 @@ static rndis_resp_t *rndis_add_response(int configNr, u32 length) ...@@ -1012,8 +990,7 @@ static rndis_resp_t *rndis_add_response(int configNr, u32 length)
r->length = length; r->length = length;
r->send = 0; r->send = 0;
list_add_tail(&r->list, list_add_tail(&r->list, &(params->resp_queue));
&(rndis_per_dev_params[configNr].resp_queue));
return r; return r;
} }
......
...@@ -197,24 +197,25 @@ typedef struct rndis_params ...@@ -197,24 +197,25 @@ typedef struct rndis_params
} rndis_params; } rndis_params;
/* RNDIS Message parser and other useless functions */ /* RNDIS Message parser and other useless functions */
int rndis_msg_parser (u8 configNr, u8 *buf); int rndis_msg_parser(struct rndis_params *params, u8 *buf);
int rndis_register(void (*resp_avail)(void *v), void *v); struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v);
void rndis_deregister (int configNr); void rndis_deregister(struct rndis_params *params);
int rndis_set_param_dev (u8 configNr, struct net_device *dev, int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev,
u16 *cdc_filter); u16 *cdc_filter);
int rndis_set_param_vendor (u8 configNr, u32 vendorID, int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID,
const char *vendorDescr); const char *vendorDescr);
int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); int rndis_set_param_medium(struct rndis_params *params, u32 medium,
u32 speed);
void rndis_add_hdr (struct sk_buff *skb); void rndis_add_hdr (struct sk_buff *skb);
int rndis_rm_hdr(struct gether *port, struct sk_buff *skb, int rndis_rm_hdr(struct gether *port, struct sk_buff *skb,
struct sk_buff_head *list); struct sk_buff_head *list);
u8 *rndis_get_next_response (int configNr, u32 *length); u8 *rndis_get_next_response(struct rndis_params *params, u32 *length);
void rndis_free_response (int configNr, u8 *buf); void rndis_free_response(struct rndis_params *params, u8 *buf);
void rndis_uninit (int configNr); void rndis_uninit(struct rndis_params *params);
int rndis_signal_connect (int configNr); int rndis_signal_connect(struct rndis_params *params);
int rndis_signal_disconnect (int configNr); int rndis_signal_disconnect(struct rndis_params *params);
int rndis_state (int configNr); int rndis_state(struct rndis_params *params);
extern void rndis_set_host_mac (int configNr, const u8 *addr); extern void rndis_set_host_mac(struct rndis_params *params, const u8 *addr);
#endif /* _LINUX_RNDIS_H */ #endif /* _LINUX_RNDIS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment