21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/wait.h>
25 #include <linux/slab.h>
27 #include <linux/if_ether.h>
28 #include <linux/netdevice.h>
29 #include <linux/if_vlan.h>
35 #define RNDIS_EXT_LEN 100
52 struct hv_page_buffer
buf[2];
62 static void rndis_filter_send_completion(
void *
ctx);
64 static void rndis_filter_send_request_completion(
void *
ctx);
132 static void dump_rndis_message(
struct hv_device *hv_dev,
138 net_device = hv_get_drvdata(hv_dev);
139 netdev = net_device->
ndev;
143 netdev_dbg(netdev,
"RNDIS_MSG_PACKET (len %u, "
144 "data offset %u data len %u, # oob %u, "
145 "oob offset %u, oob len %u, pkt offset %u, "
148 rndis_msg->
msg.
pkt.data_offset,
149 rndis_msg->
msg.
pkt.data_len,
150 rndis_msg->
msg.
pkt.num_oob_data_elements,
151 rndis_msg->
msg.
pkt.oob_data_offset,
152 rndis_msg->
msg.
pkt.oob_data_len,
153 rndis_msg->
msg.
pkt.per_pkt_info_offset,
154 rndis_msg->
msg.
pkt.per_pkt_info_len);
159 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
160 "device flags %d, max xfer size 0x%x, max pkts %u, "
172 pkt_alignment_factor);
177 "(len %u, id 0x%x, status 0x%x, buf len %u, "
190 "RNDIS_MSG_SET_C (len %u, id 0x%x, status 0x%x)\n",
198 "(len %u, status 0x%x, buf len %u, buf offset %u)\n",
213 static int rndis_filter_send_request(
struct rndis_device *dev,
246 rndis_filter_send_request_completion;
253 static void rndis_filter_receive_response(
struct rndis_device *dev,
259 struct net_device *
ndev;
284 "rndis response buffer overflow "
285 "detected (size %u max %zu)\n",
296 init_complete.status =
304 "no rndis request found for this response "
305 "(id 0x%x res type 0x%x)\n",
311 static void rndis_filter_receive_indicate_status(
struct rndis_device *dev,
347 if (ppi->
type == type)
356 static void rndis_filter_receive_data(
struct rndis_device *dev,
364 rndis_pkt = &msg->
msg.
pkt;
381 netdev_err(dev->
net_dev->ndev,
"rndis message buffer "
382 "overflow detected (got %u, min %u)"
383 "...dropping this message!\n",
415 struct net_device *
ndev;
423 ndev = net_dev->
ndev;
427 netdev_err(ndev,
"got rndis message but no rndis device - "
428 "dropping this message!\n");
435 netdev_err(ndev,
"got rndis message but rndis device "
436 "uninitialized...dropping this message!\n");
441 rndis_msg = pkt->
data;
443 dump_rndis_message(dev, rndis_msg);
448 rndis_filter_receive_data(rndis_dev, rndis_msg, pkt);
455 rndis_filter_receive_response(rndis_dev, rndis_msg);
460 rndis_filter_receive_indicate_status(rndis_dev, rndis_msg);
464 "unhandled rndis message (type %u len %u)\n",
505 ret = rndis_filter_send_request(dev, request);
516 query_complete = &request->
response_msg.msg.query_complete;
524 (
void *)((
unsigned long)query_complete +
532 put_rndis_request(dev, request);
537 static int rndis_filter_query_device_mac(
struct rndis_device *dev)
541 return rndis_filter_query_device(dev,
546 #define NWADR_STR "NetworkAddress"
547 #define NWADR_STRLEN 14
553 struct net_device *ndev = nvdev->
ndev;
557 wchar_t *cfg_nwadr, *cfg_mac;
571 set->info_buflen = extlen;
573 set->dev_vc_handle = 0;
576 set->info_buf_offset);
593 snprintf(macstr, 2*ETH_ALEN+1,
"%pm", mac);
595 cfg_mac, 2*ETH_ALEN);
599 ret = rndis_filter_send_request(rdev, request);
605 netdev_err(ndev,
"timeout before we got a set response...\n");
618 put_rndis_request(rdev, request);
623 static int rndis_filter_query_device_link_status(
struct rndis_device *dev)
629 ret = rndis_filter_query_device(dev,
631 &link_status, &size);
632 dev->
link_state = (link_status != 0) ?
true :
false;
644 struct net_device *
ndev;
659 set->info_buflen =
sizeof(
u32);
663 &new_filter,
sizeof(
u32));
665 ret = rndis_filter_send_request(dev, request);
673 "timeout before we got a set response...\n");
682 status = set_complete->
status;
687 put_rndis_request(dev, request);
693 static int rndis_filter_init_device(
struct rndis_device *dev)
716 ret = rndis_filter_send_request(dev, request);
730 init_complete = &request->
response_msg.msg.init_complete;
731 status = init_complete->
status;
742 put_rndis_request(dev, request);
747 static void rndis_filter_halt_device(
struct rndis_device *dev)
752 struct hv_device *hdev = nvdev->
dev;
766 rndis_filter_send_request(dev, request);
773 spin_unlock_irqrestore(&hdev->channel->inbound_lock, flags);
780 put_rndis_request(dev, request);
784 static int rndis_filter_open_device(
struct rndis_device *dev)
801 static int rndis_filter_close_device(
struct rndis_device *dev)
816 void *additional_info)
823 rndis_device = get_rndis_device();
840 net_device = hv_get_drvdata(dev);
843 rndis_device->
net_dev = net_device;
846 ret = rndis_filter_init_device(rndis_device);
853 ret = rndis_filter_query_device_mac(rndis_device);
861 rndis_filter_query_device_link_status(rndis_device);
865 dev_info(&dev->device,
"Device MAC %pM link state %s\n",
878 rndis_filter_halt_device(rndis_dev);
894 return rndis_filter_open_device(net_device->
extension);
904 return rndis_filter_close_device(nvdev->
extension);
920 rndis_msg = &filter_pkt->
msg;
929 rndis_pkt = &rndis_msg->
msg.
pkt;
958 pkt->
page_buf[0].len = rndis_msg_size;
979 pkt->
completion.
send.send_completion = rndis_filter_send_completion;
997 static void rndis_filter_send_completion(
void *
ctx)
1006 static void rndis_filter_send_request_completion(
void *ctx)