2 * Copyright (c) 2009, Microsoft Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
21 #include <linux/kernel.h>
22 #include <linux/highmem.h>
23 #include <linux/slab.h>
25 #include <linux/if_ether.h>
29 #include "netvsc_api.h"
30 #include "rndis_filter.h"
33 struct rndis_filter_driver_object {
34 /* The original driver */
35 struct netvsc_driver inner_drv;
38 enum rndis_device_state {
39 RNDIS_DEV_UNINITIALIZED = 0,
40 RNDIS_DEV_INITIALIZING,
41 RNDIS_DEV_INITIALIZED,
42 RNDIS_DEV_DATAINITIALIZED,
46 struct netvsc_device *net_dev;
48 enum rndis_device_state state;
52 spinlock_t request_lock;
53 struct list_head req_list;
55 unsigned char hw_mac_adr[ETH_ALEN];
58 struct rndis_request {
59 struct list_head list_ent;
60 struct osd_waitevent *waitevent;
63 * FIXME: We assumed a fixed size response here. If we do ever need to
64 * handle a bigger response, we can either define a max response
65 * message or add a response buffer variable above this field
67 struct rndis_message response_msg;
69 /* Simplify allocation by having a netvsc packet inline */
70 struct hv_netvsc_packet pkt;
71 struct hv_page_buffer buf;
72 /* FIXME: We assumed a fixed size request here. */
73 struct rndis_message request_msg;
77 struct rndis_filter_packet {
79 void (*completion)(void *context);
80 struct rndis_message msg;
84 static int rndis_filte_device_add(struct hv_device *dev,
85 void *additional_info);
87 static int rndis_filter_device_remove(struct hv_device *dev);
89 static void rndis_filter_cleanup(struct hv_driver *drv);
91 static int rndis_filter_send(struct hv_device *dev,
92 struct hv_netvsc_packet *pkt);
94 static void rndis_filter_send_completion(void *ctx);
96 static void rndis_filter_send_request_completion(void *ctx);
99 /* The one and only */
100 static struct rndis_filter_driver_object rndis_filter;
102 static struct rndis_device *get_rndis_device(void)
104 struct rndis_device *device;
106 device = kzalloc(sizeof(struct rndis_device), GFP_KERNEL);
110 spin_lock_init(&device->request_lock);
112 INIT_LIST_HEAD(&device->req_list);
114 device->state = RNDIS_DEV_UNINITIALIZED;
119 static struct rndis_request *get_rndis_request(struct rndis_device *dev,
123 struct rndis_request *request;
124 struct rndis_message *rndis_msg;
125 struct rndis_set_request *set;
128 request = kzalloc(sizeof(struct rndis_request), GFP_KERNEL);
132 request->waitevent = osd_waitevent_create();
133 if (!request->waitevent) {
138 rndis_msg = &request->request_msg;
139 rndis_msg->ndis_msg_type = msg_type;
140 rndis_msg->msg_len = msg_len;
143 * Set the request id. This field is always after the rndis header for
144 * request/response packet types so we just used the SetRequest as a
147 set = &rndis_msg->msg.set_req;
148 set->req_id = atomic_inc_return(&dev->new_req_id);
150 /* Add to the request list */
151 spin_lock_irqsave(&dev->request_lock, flags);
152 list_add_tail(&request->list_ent, &dev->req_list);
153 spin_unlock_irqrestore(&dev->request_lock, flags);
158 static void put_rndis_request(struct rndis_device *dev,
159 struct rndis_request *req)
163 spin_lock_irqsave(&dev->request_lock, flags);
164 list_del(&req->list_ent);
165 spin_unlock_irqrestore(&dev->request_lock, flags);
167 kfree(req->waitevent);
171 static void dump_rndis_message(struct rndis_message *rndis_msg)
173 switch (rndis_msg->ndis_msg_type) {
174 case REMOTE_NDIS_PACKET_MSG:
175 DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, "
176 "data offset %u data len %u, # oob %u, "
177 "oob offset %u, oob len %u, pkt offset %u, "
180 rndis_msg->msg.pkt.data_offset,
181 rndis_msg->msg.pkt.data_len,
182 rndis_msg->msg.pkt.num_oob_data_elements,
183 rndis_msg->msg.pkt.oob_data_offset,
184 rndis_msg->msg.pkt.oob_data_len,
185 rndis_msg->msg.pkt.per_pkt_info_offset,
186 rndis_msg->msg.pkt.per_pkt_info_len);
189 case REMOTE_NDIS_INITIALIZE_CMPLT:
190 DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT "
191 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
192 "device flags %d, max xfer size 0x%x, max pkts %u, "
195 rndis_msg->msg.init_complete.req_id,
196 rndis_msg->msg.init_complete.status,
197 rndis_msg->msg.init_complete.major_ver,
198 rndis_msg->msg.init_complete.minor_ver,
199 rndis_msg->msg.init_complete.dev_flags,
200 rndis_msg->msg.init_complete.max_xfer_size,
201 rndis_msg->msg.init_complete.
203 rndis_msg->msg.init_complete.
204 pkt_alignment_factor);
207 case REMOTE_NDIS_QUERY_CMPLT:
208 DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT "
209 "(len %u, id 0x%x, status 0x%x, buf len %u, "
212 rndis_msg->msg.query_complete.req_id,
213 rndis_msg->msg.query_complete.status,
214 rndis_msg->msg.query_complete.
216 rndis_msg->msg.query_complete.
220 case REMOTE_NDIS_SET_CMPLT:
222 "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)",
224 rndis_msg->msg.set_complete.req_id,
225 rndis_msg->msg.set_complete.status);
228 case REMOTE_NDIS_INDICATE_STATUS_MSG:
229 DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG "
230 "(len %u, status 0x%x, buf len %u, buf offset %u)",
232 rndis_msg->msg.indicate_status.status,
233 rndis_msg->msg.indicate_status.status_buflen,
234 rndis_msg->msg.indicate_status.status_buf_offset);
238 DPRINT_DBG(NETVSC, "0x%x (len %u)",
239 rndis_msg->ndis_msg_type,
245 static int rndis_filter_send_request(struct rndis_device *dev,
246 struct rndis_request *req)
249 struct hv_netvsc_packet *packet;
251 /* Setup the packet to send it */
254 packet->is_data_pkt = false;
255 packet->total_data_buflen = req->request_msg.msg_len;
256 packet->page_buf_cnt = 1;
258 packet->page_buf[0].Pfn = virt_to_phys(&req->request_msg) >>
260 packet->page_buf[0].Length = req->request_msg.msg_len;
261 packet->page_buf[0].Offset =
262 (unsigned long)&req->request_msg & (PAGE_SIZE - 1);
264 packet->completion.send.send_completion_ctx = req;/* packet; */
265 packet->completion.send.send_completion =
266 rndis_filter_send_request_completion;
267 packet->completion.send.send_completion_tid = (unsigned long)dev;
269 ret = rndis_filter.inner_drv.send(dev->net_dev->dev, packet);
273 static void rndis_filter_receive_response(struct rndis_device *dev,
274 struct rndis_message *resp)
276 struct rndis_request *request = NULL;
280 spin_lock_irqsave(&dev->request_lock, flags);
281 list_for_each_entry(request, &dev->req_list, list_ent) {
283 * All request/response message contains RequestId as the 1st
286 if (request->request_msg.msg.init_req.req_id
287 == resp->msg.init_complete.req_id) {
288 DPRINT_DBG(NETVSC, "found rndis request for "
289 "this response (id 0x%x req type 0x%x res "
291 request->request_msg.msg.
293 request->request_msg.ndis_msg_type,
294 resp->ndis_msg_type);
300 spin_unlock_irqrestore(&dev->request_lock, flags);
303 if (resp->msg_len <= sizeof(struct rndis_message)) {
304 memcpy(&request->response_msg, resp,
307 DPRINT_ERR(NETVSC, "rndis response buffer overflow "
308 "detected (size %u max %zu)",
310 sizeof(struct rndis_filter_packet));
312 if (resp->ndis_msg_type ==
313 REMOTE_NDIS_RESET_CMPLT) {
314 /* does not have a request id field */
315 request->response_msg.msg.reset_complete.
316 status = STATUS_BUFFER_OVERFLOW;
318 request->response_msg.msg.
319 init_complete.status =
320 STATUS_BUFFER_OVERFLOW;
324 osd_waitevent_set(request->waitevent);
326 DPRINT_ERR(NETVSC, "no rndis request found for this response "
327 "(id 0x%x res type 0x%x)",
328 resp->msg.init_complete.req_id,
329 resp->ndis_msg_type);
333 static void rndis_filter_receive_indicate_status(struct rndis_device *dev,
334 struct rndis_message *resp)
336 struct rndis_indicate_status *indicate =
337 &resp->msg.indicate_status;
339 if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) {
340 rndis_filter.inner_drv.link_status_change(
341 dev->net_dev->dev, 1);
342 } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) {
343 rndis_filter.inner_drv.link_status_change(
344 dev->net_dev->dev, 0);
352 static void rndis_filter_receive_data(struct rndis_device *dev,
353 struct rndis_message *msg,
354 struct hv_netvsc_packet *pkt)
356 struct rndis_packet *rndis_pkt;
359 /* empty ethernet frame ?? */
360 /* ASSERT(Packet->PageBuffers[0].Length > */
361 /* RNDIS_MESSAGE_SIZE(struct rndis_packet)); */
363 rndis_pkt = &msg->msg.pkt;
366 * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
367 * netvsc packet (ie TotalDataBufferLength != MessageLength)
370 /* Remove the rndis header and pass it back up the stack */
371 data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
373 pkt->total_data_buflen -= data_offset;
374 pkt->page_buf[0].Offset += data_offset;
375 pkt->page_buf[0].Length -= data_offset;
377 pkt->is_data_pkt = true;
379 rndis_filter.inner_drv.recv_cb(dev->net_dev->dev,
383 static int rndis_filter_receive(struct hv_device *dev,
384 struct hv_netvsc_packet *pkt)
386 struct netvsc_device *net_dev = dev->Extension;
387 struct rndis_device *rndis_dev;
388 struct rndis_message rndis_msg;
389 struct rndis_message *rndis_hdr;
394 /* Make sure the rndis device state is initialized */
395 if (!net_dev->extension) {
396 DPRINT_ERR(NETVSC, "got rndis message but no rndis device..."
397 "dropping this message!");
401 rndis_dev = (struct rndis_device *)net_dev->extension;
402 if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) {
403 DPRINT_ERR(NETVSC, "got rndis message but rndis device "
404 "uninitialized...dropping this message!");
408 rndis_hdr = (struct rndis_message *)kmap_atomic(
409 pfn_to_page(pkt->page_buf[0].Pfn), KM_IRQ0);
411 rndis_hdr = (void *)((unsigned long)rndis_hdr +
412 pkt->page_buf[0].Offset);
414 /* Make sure we got a valid rndis message */
416 * FIXME: There seems to be a bug in set completion msg where its
417 * MessageLength is 16 bytes but the ByteCount field in the xfer page
418 * range shows 52 bytes
421 if (pkt->total_data_buflen != rndis_hdr->msg_len) {
422 kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset,
425 DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u "
426 "bytes got %u)...dropping this message!",
428 pkt->total_data_buflen);
433 if ((rndis_hdr->ndis_msg_type != REMOTE_NDIS_PACKET_MSG) &&
434 (rndis_hdr->msg_len > sizeof(struct rndis_message))) {
435 DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow "
436 "detected (got %u, max %zu)...marking it an error!",
438 sizeof(struct rndis_message));
441 memcpy(&rndis_msg, rndis_hdr,
442 (rndis_hdr->msg_len > sizeof(struct rndis_message)) ?
443 sizeof(struct rndis_message) :
446 kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset, KM_IRQ0);
448 dump_rndis_message(&rndis_msg);
450 switch (rndis_msg.ndis_msg_type) {
451 case REMOTE_NDIS_PACKET_MSG:
453 rndis_filter_receive_data(rndis_dev, &rndis_msg, pkt);
456 case REMOTE_NDIS_INITIALIZE_CMPLT:
457 case REMOTE_NDIS_QUERY_CMPLT:
458 case REMOTE_NDIS_SET_CMPLT:
459 /* case REMOTE_NDIS_RESET_CMPLT: */
460 /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */
461 /* completion msgs */
462 rndis_filter_receive_response(rndis_dev, &rndis_msg);
465 case REMOTE_NDIS_INDICATE_STATUS_MSG:
466 /* notification msgs */
467 rndis_filter_receive_indicate_status(rndis_dev, &rndis_msg);
470 DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)",
471 rndis_msg.ndis_msg_type,
479 static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
480 void *result, u32 *result_size)
482 struct rndis_request *request;
483 u32 inresult_size = *result_size;
484 struct rndis_query_request *query;
485 struct rndis_query_complete *query_complete;
492 request = get_rndis_request(dev, REMOTE_NDIS_QUERY_MSG,
493 RNDIS_MESSAGE_SIZE(struct rndis_query_request));
499 /* Setup the rndis query */
500 query = &request->request_msg.msg.query_req;
502 query->info_buf_offset = sizeof(struct rndis_query_request);
503 query->info_buflen = 0;
504 query->dev_vc_handle = 0;
506 ret = rndis_filter_send_request(dev, request);
510 osd_waitevent_wait(request->waitevent);
512 /* Copy the response back */
513 query_complete = &request->response_msg.msg.query_complete;
515 if (query_complete->info_buflen > inresult_size) {
521 (void *)((unsigned long)query_complete +
522 query_complete->info_buf_offset),
523 query_complete->info_buflen);
525 *result_size = query_complete->info_buflen;
529 put_rndis_request(dev, request);
534 static int rndis_filter_query_device_mac(struct rndis_device *dev)
538 return rndis_filter_query_device(dev,
539 RNDIS_OID_802_3_PERMANENT_ADDRESS,
540 dev->hw_mac_adr, &size);
543 static int rndis_filter_query_device_link_status(struct rndis_device *dev)
545 u32 size = sizeof(u32);
547 return rndis_filter_query_device(dev,
548 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
549 &dev->link_stat, &size);
552 static int rndis_filter_set_packet_filter(struct rndis_device *dev,
555 struct rndis_request *request;
556 struct rndis_set_request *set;
557 struct rndis_set_complete *set_complete;
561 /* ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <= */
562 /* sizeof(struct rndis_message)); */
564 request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG,
565 RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
572 /* Setup the rndis set */
573 set = &request->request_msg.msg.set_req;
574 set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
575 set->info_buflen = sizeof(u32);
576 set->info_buf_offset = sizeof(struct rndis_set_request);
578 memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
579 &new_filter, sizeof(u32));
581 ret = rndis_filter_send_request(dev, request);
585 ret = osd_waitevent_waitex(request->waitevent, 2000/*2sec*/);
588 DPRINT_ERR(NETVSC, "timeout before we got a set response...");
590 * We cant deallocate the request since we may still receive a
591 * send completion for it.
597 set_complete = &request->response_msg.msg.set_complete;
598 status = set_complete->status;
603 put_rndis_request(dev, request);
608 int rndis_filter_init(struct netvsc_driver *drv)
610 DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd",
611 sizeof(struct rndis_filter_packet));
613 drv->req_ext_size = sizeof(struct rndis_filter_packet);
615 /* Driver->Context = rndisDriver; */
617 memset(&rndis_filter, 0, sizeof(struct rndis_filter_driver_object));
619 /*rndisDriver->Driver = Driver;
621 ASSERT(Driver->OnLinkStatusChanged);
622 rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/
624 /* Save the original dispatch handlers before we override it */
625 rndis_filter.inner_drv.base.OnDeviceAdd = drv->base.OnDeviceAdd;
626 rndis_filter.inner_drv.base.OnDeviceRemove =
627 drv->base.OnDeviceRemove;
628 rndis_filter.inner_drv.base.OnCleanup = drv->base.OnCleanup;
630 /* ASSERT(Driver->OnSend); */
631 /* ASSERT(Driver->OnReceiveCallback); */
632 rndis_filter.inner_drv.send = drv->send;
633 rndis_filter.inner_drv.recv_cb = drv->recv_cb;
634 rndis_filter.inner_drv.link_status_change =
635 drv->link_status_change;
638 drv->base.OnDeviceAdd = rndis_filte_device_add;
639 drv->base.OnDeviceRemove = rndis_filter_device_remove;
640 drv->base.OnCleanup = rndis_filter_cleanup;
641 drv->send = rndis_filter_send;
642 /* Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus; */
643 drv->recv_cb = rndis_filter_receive;
648 static int rndis_filter_init_device(struct rndis_device *dev)
650 struct rndis_request *request;
651 struct rndis_initialize_request *init;
652 struct rndis_initialize_complete *init_complete;
656 request = get_rndis_request(dev, REMOTE_NDIS_INITIALIZE_MSG,
657 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
663 /* Setup the rndis set */
664 init = &request->request_msg.msg.init_req;
665 init->major_ver = RNDIS_MAJOR_VERSION;
666 init->minor_ver = RNDIS_MINOR_VERSION;
667 /* FIXME: Use 1536 - rounded ethernet frame size */
668 init->max_xfer_size = 2048;
670 dev->state = RNDIS_DEV_INITIALIZING;
672 ret = rndis_filter_send_request(dev, request);
674 dev->state = RNDIS_DEV_UNINITIALIZED;
678 osd_waitevent_wait(request->waitevent);
680 init_complete = &request->response_msg.msg.init_complete;
681 status = init_complete->status;
682 if (status == RNDIS_STATUS_SUCCESS) {
683 dev->state = RNDIS_DEV_INITIALIZED;
686 dev->state = RNDIS_DEV_UNINITIALIZED;
692 put_rndis_request(dev, request);
697 static void rndis_filter_halt_device(struct rndis_device *dev)
699 struct rndis_request *request;
700 struct rndis_halt_request *halt;
702 /* Attempt to do a rndis device halt */
703 request = get_rndis_request(dev, REMOTE_NDIS_HALT_MSG,
704 RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
708 /* Setup the rndis set */
709 halt = &request->request_msg.msg.halt_req;
710 halt->req_id = atomic_inc_return(&dev->new_req_id);
712 /* Ignore return since this msg is optional. */
713 rndis_filter_send_request(dev, request);
715 dev->state = RNDIS_DEV_UNINITIALIZED;
719 put_rndis_request(dev, request);
723 static int rndis_filter_open_device(struct rndis_device *dev)
727 if (dev->state != RNDIS_DEV_INITIALIZED)
730 ret = rndis_filter_set_packet_filter(dev,
731 NDIS_PACKET_TYPE_BROADCAST |
732 NDIS_PACKET_TYPE_ALL_MULTICAST |
733 NDIS_PACKET_TYPE_DIRECTED);
735 dev->state = RNDIS_DEV_DATAINITIALIZED;
740 static int rndis_filter_close_device(struct rndis_device *dev)
744 if (dev->state != RNDIS_DEV_DATAINITIALIZED)
747 ret = rndis_filter_set_packet_filter(dev, 0);
749 dev->state = RNDIS_DEV_INITIALIZED;
754 static int rndis_filte_device_add(struct hv_device *dev,
755 void *additional_info)
758 struct netvsc_device *netDevice;
759 struct rndis_device *rndisDevice;
760 struct netvsc_device_info *deviceInfo = additional_info;
762 rndisDevice = get_rndis_device();
766 DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice);
769 * Let the inner driver handle this first to create the netvsc channel
770 * NOTE! Once the channel is created, we may get a receive callback
771 * (RndisFilterOnReceive()) before this call is completed
773 ret = rndis_filter.inner_drv.base.OnDeviceAdd(dev, additional_info);
780 /* Initialize the rndis device */
781 netDevice = dev->Extension;
782 /* ASSERT(netDevice); */
783 /* ASSERT(netDevice->Device); */
785 netDevice->extension = rndisDevice;
786 rndisDevice->net_dev = netDevice;
788 /* Send the rndis initialization message */
789 ret = rndis_filter_init_device(rndisDevice);
792 * TODO: If rndis init failed, we will need to shut down the
797 /* Get the mac address */
798 ret = rndis_filter_query_device_mac(rndisDevice);
801 * TODO: shutdown rndis device and the channel
805 DPRINT_INFO(NETVSC, "Device 0x%p mac addr %pM",
806 rndisDevice, rndisDevice->hw_mac_adr);
808 memcpy(deviceInfo->mac_adr, rndisDevice->hw_mac_adr, ETH_ALEN);
810 rndis_filter_query_device_link_status(rndisDevice);
812 deviceInfo->link_state = rndisDevice->link_stat;
813 DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice,
814 ((deviceInfo->link_state) ? ("down") : ("up")));
819 static int rndis_filter_device_remove(struct hv_device *dev)
821 struct netvsc_device *net_dev = dev->Extension;
822 struct rndis_device *rndis_dev = net_dev->extension;
824 /* Halt and release the rndis device */
825 rndis_filter_halt_device(rndis_dev);
828 net_dev->extension = NULL;
830 /* Pass control to inner driver to remove the device */
831 rndis_filter.inner_drv.base.OnDeviceRemove(dev);
836 static void rndis_filter_cleanup(struct hv_driver *drv)
840 int rndis_filter_open(struct hv_device *dev)
842 struct netvsc_device *netDevice = dev->Extension;
847 return rndis_filter_open_device(netDevice->extension);
850 int rndis_filter_close(struct hv_device *dev)
852 struct netvsc_device *netDevice = dev->Extension;
857 return rndis_filter_close_device(netDevice->extension);
860 static int rndis_filter_send(struct hv_device *dev,
861 struct hv_netvsc_packet *pkt)
864 struct rndis_filter_packet *filterPacket;
865 struct rndis_message *rndisMessage;
866 struct rndis_packet *rndisPacket;
867 u32 rndisMessageSize;
869 /* Add the rndis header */
870 filterPacket = (struct rndis_filter_packet *)pkt->extension;
871 /* ASSERT(filterPacket); */
873 memset(filterPacket, 0, sizeof(struct rndis_filter_packet));
875 rndisMessage = &filterPacket->msg;
876 rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet);
878 rndisMessage->ndis_msg_type = REMOTE_NDIS_PACKET_MSG;
879 rndisMessage->msg_len = pkt->total_data_buflen +
882 rndisPacket = &rndisMessage->msg.pkt;
883 rndisPacket->data_offset = sizeof(struct rndis_packet);
884 rndisPacket->data_len = pkt->total_data_buflen;
886 pkt->is_data_pkt = true;
887 pkt->page_buf[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT;
888 pkt->page_buf[0].Offset =
889 (unsigned long)rndisMessage & (PAGE_SIZE-1);
890 pkt->page_buf[0].Length = rndisMessageSize;
892 /* Save the packet send completion and context */
893 filterPacket->completion = pkt->completion.send.send_completion;
894 filterPacket->completion_ctx =
895 pkt->completion.send.send_completion_ctx;
898 pkt->completion.send.send_completion = rndis_filter_send_completion;
899 pkt->completion.send.send_completion_ctx = filterPacket;
901 ret = rndis_filter.inner_drv.send(dev, pkt);
904 * Reset the completion to originals to allow retries from
907 pkt->completion.send.send_completion =
908 filterPacket->completion;
909 pkt->completion.send.send_completion_ctx =
910 filterPacket->completion_ctx;
916 static void rndis_filter_send_completion(void *ctx)
918 struct rndis_filter_packet *filterPacket = ctx;
920 /* Pass it back to the original handler */
921 filterPacket->completion(filterPacket->completion_ctx);
925 static void rndis_filter_send_request_completion(void *ctx)