Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2009, Microsoft Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 16 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 17 | * |
| 18 | * Authors: |
| 19 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 20 | * Hank Janssen <hjanssen@microsoft.com> |
| 21 | * |
| 22 | */ |
| 23 | |
Greg Kroah-Hartman | 5654e93 | 2009-07-14 15:08:20 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Greg Kroah-Hartman | 0ffa63b | 2009-07-15 11:06:01 -0700 | [diff] [blame] | 25 | #include <linux/mm.h> |
Greg Kroah-Hartman | c86f3e2 | 2009-07-14 10:59:56 -0700 | [diff] [blame] | 26 | #include "include/logging.h" |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 27 | |
Greg Kroah-Hartman | c86f3e2 | 2009-07-14 10:59:56 -0700 | [diff] [blame] | 28 | #include "include/NetVscApi.h" |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 29 | #include "RndisFilter.h" |
| 30 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 31 | |
| 32 | /* Data types */ |
| 33 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 34 | |
| 35 | typedef struct _RNDIS_FILTER_DRIVER_OBJECT { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 36 | /* The original driver */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 37 | NETVSC_DRIVER_OBJECT InnerDriver; |
| 38 | |
| 39 | } RNDIS_FILTER_DRIVER_OBJECT; |
| 40 | |
| 41 | typedef enum { |
| 42 | RNDIS_DEV_UNINITIALIZED = 0, |
| 43 | RNDIS_DEV_INITIALIZING, |
| 44 | RNDIS_DEV_INITIALIZED, |
| 45 | RNDIS_DEV_DATAINITIALIZED, |
| 46 | } RNDIS_DEVICE_STATE; |
| 47 | |
| 48 | typedef struct _RNDIS_DEVICE { |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 49 | struct NETVSC_DEVICE *NetDevice; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 50 | |
| 51 | RNDIS_DEVICE_STATE State; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 52 | u32 LinkStatus; |
| 53 | u32 NewRequestId; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 54 | |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 55 | spinlock_t request_lock; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 56 | LIST_ENTRY RequestList; |
| 57 | |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 58 | unsigned char HwMacAddr[HW_MACADDR_LEN]; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 59 | } RNDIS_DEVICE; |
| 60 | |
| 61 | |
| 62 | typedef struct _RNDIS_REQUEST { |
| 63 | LIST_ENTRY ListEntry; |
Bill Pemberton | aedb444 | 2009-07-28 13:46:24 -0400 | [diff] [blame] | 64 | struct osd_waitevent *WaitEvent; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 65 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 66 | /* FIXME: We assumed a fixed size response here. If we do ever need to handle a bigger response, */ |
| 67 | /* we can either define a max response message or add a response buffer variable above this field */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 68 | RNDIS_MESSAGE ResponseMessage; |
| 69 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 70 | /* Simplify allocation by having a netvsc packet inline */ |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 71 | struct hv_netvsc_packet Packet; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 72 | PAGE_BUFFER Buffer; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 73 | /* FIXME: We assumed a fixed size request here. */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 74 | RNDIS_MESSAGE RequestMessage; |
| 75 | } RNDIS_REQUEST; |
| 76 | |
| 77 | |
| 78 | typedef struct _RNDIS_FILTER_PACKET { |
| 79 | void *CompletionContext; |
| 80 | PFN_ON_SENDRECVCOMPLETION OnCompletion; |
| 81 | |
| 82 | RNDIS_MESSAGE Message; |
| 83 | } RNDIS_FILTER_PACKET; |
| 84 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 85 | |
| 86 | /* Internal routines */ |
| 87 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 88 | static int |
| 89 | RndisFilterSendRequest( |
| 90 | RNDIS_DEVICE *Device, |
| 91 | RNDIS_REQUEST *Request |
| 92 | ); |
| 93 | |
| 94 | static void |
| 95 | RndisFilterReceiveResponse( |
| 96 | RNDIS_DEVICE *Device, |
| 97 | RNDIS_MESSAGE *Response |
| 98 | ); |
| 99 | |
| 100 | static void |
| 101 | RndisFilterReceiveIndicateStatus( |
| 102 | RNDIS_DEVICE *Device, |
| 103 | RNDIS_MESSAGE *Response |
| 104 | ); |
| 105 | |
| 106 | static void |
| 107 | RndisFilterReceiveData( |
| 108 | RNDIS_DEVICE *Device, |
| 109 | RNDIS_MESSAGE *Message, |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 110 | struct hv_netvsc_packet *Packet |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 111 | ); |
| 112 | |
| 113 | static int |
| 114 | RndisFilterOnReceive( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 115 | struct hv_device *Device, |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 116 | struct hv_netvsc_packet *Packet |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 117 | ); |
| 118 | |
| 119 | static int |
| 120 | RndisFilterQueryDevice( |
| 121 | RNDIS_DEVICE *Device, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 122 | u32 Oid, |
Greg Kroah-Hartman | e20f683 | 2009-07-14 15:07:21 -0700 | [diff] [blame] | 123 | void *Result, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 124 | u32 *ResultSize |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 125 | ); |
| 126 | |
| 127 | static inline int |
| 128 | RndisFilterQueryDeviceMac( |
| 129 | RNDIS_DEVICE *Device |
| 130 | ); |
| 131 | |
| 132 | static inline int |
| 133 | RndisFilterQueryDeviceLinkStatus( |
| 134 | RNDIS_DEVICE *Device |
| 135 | ); |
| 136 | |
| 137 | static int |
| 138 | RndisFilterSetPacketFilter( |
| 139 | RNDIS_DEVICE *Device, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 140 | u32 NewFilter |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 141 | ); |
| 142 | |
| 143 | static int |
| 144 | RndisFilterInitDevice( |
| 145 | RNDIS_DEVICE *Device |
| 146 | ); |
| 147 | |
| 148 | static int |
| 149 | RndisFilterOpenDevice( |
| 150 | RNDIS_DEVICE *Device |
| 151 | ); |
| 152 | |
| 153 | static int |
| 154 | RndisFilterCloseDevice( |
| 155 | RNDIS_DEVICE *Device |
| 156 | ); |
| 157 | |
| 158 | static int |
| 159 | RndisFilterOnDeviceAdd( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 160 | struct hv_device *Device, |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 161 | void *AdditionalInfo |
| 162 | ); |
| 163 | |
| 164 | static int |
| 165 | RndisFilterOnDeviceRemove( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 166 | struct hv_device *Device |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 167 | ); |
| 168 | |
| 169 | static void |
| 170 | RndisFilterOnCleanup( |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 171 | struct hv_driver *Driver |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 172 | ); |
| 173 | |
| 174 | static int |
| 175 | RndisFilterOnOpen( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 176 | struct hv_device *Device |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 177 | ); |
| 178 | |
| 179 | static int |
| 180 | RndisFilterOnClose( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 181 | struct hv_device *Device |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 182 | ); |
| 183 | |
| 184 | static int |
| 185 | RndisFilterOnSend( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 186 | struct hv_device *Device, |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 187 | struct hv_netvsc_packet *Packet |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 188 | ); |
| 189 | |
| 190 | static void |
| 191 | RndisFilterOnSendCompletion( |
| 192 | void *Context |
| 193 | ); |
| 194 | |
| 195 | static void |
| 196 | RndisFilterOnSendRequestCompletion( |
| 197 | void *Context |
| 198 | ); |
| 199 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 200 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 201 | /* Global var */ |
| 202 | |
| 203 | |
| 204 | /* The one and only */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 205 | RNDIS_FILTER_DRIVER_OBJECT gRndisFilter; |
| 206 | |
| 207 | static inline RNDIS_DEVICE* GetRndisDevice(void) |
| 208 | { |
| 209 | RNDIS_DEVICE *device; |
| 210 | |
Greg Kroah-Hartman | e276a3a | 2009-07-15 12:47:43 -0700 | [diff] [blame] | 211 | device = kzalloc(sizeof(RNDIS_DEVICE), GFP_KERNEL); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 212 | if (!device) |
| 213 | { |
| 214 | return NULL; |
| 215 | } |
| 216 | |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 217 | spin_lock_init(&device->request_lock); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 218 | |
| 219 | INITIALIZE_LIST_HEAD(&device->RequestList); |
| 220 | |
| 221 | device->State = RNDIS_DEV_UNINITIALIZED; |
| 222 | |
| 223 | return device; |
| 224 | } |
| 225 | |
| 226 | static inline void PutRndisDevice(RNDIS_DEVICE *Device) |
| 227 | { |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 228 | kfree(Device); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 231 | static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageType, u32 MessageLength) |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 232 | { |
| 233 | RNDIS_REQUEST *request; |
| 234 | RNDIS_MESSAGE *rndisMessage; |
| 235 | RNDIS_SET_REQUEST *set; |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 236 | unsigned long flags; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 237 | |
Greg Kroah-Hartman | e276a3a | 2009-07-15 12:47:43 -0700 | [diff] [blame] | 238 | request = kzalloc(sizeof(RNDIS_REQUEST), GFP_KERNEL); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 239 | if (!request) |
| 240 | { |
| 241 | return NULL; |
| 242 | } |
| 243 | |
| 244 | request->WaitEvent = WaitEventCreate(); |
| 245 | if (!request->WaitEvent) |
| 246 | { |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 247 | kfree(request); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 248 | return NULL; |
| 249 | } |
| 250 | |
| 251 | rndisMessage = &request->RequestMessage; |
| 252 | rndisMessage->NdisMessageType = MessageType; |
| 253 | rndisMessage->MessageLength = MessageLength; |
| 254 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 255 | /* Set the request id. This field is always after the rndis header for request/response packet types so */ |
| 256 | /* we just used the SetRequest as a template */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 257 | set = &rndisMessage->Message.SetRequest; |
| 258 | set->RequestId = InterlockedIncrement((int*)&Device->NewRequestId); |
| 259 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 260 | /* Add to the request list */ |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 261 | spin_lock_irqsave(&Device->request_lock, flags); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 262 | INSERT_TAIL_LIST(&Device->RequestList, &request->ListEntry); |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 263 | spin_unlock_irqrestore(&Device->request_lock, flags); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 264 | |
| 265 | return request; |
| 266 | } |
| 267 | |
| 268 | static inline void PutRndisRequest(RNDIS_DEVICE *Device, RNDIS_REQUEST *Request) |
| 269 | { |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 270 | unsigned long flags; |
| 271 | |
| 272 | spin_lock_irqsave(&Device->request_lock, flags); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 273 | REMOVE_ENTRY_LIST(&Request->ListEntry); |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 274 | spin_unlock_irqrestore(&Device->request_lock, flags); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 275 | |
| 276 | WaitEventClose(Request->WaitEvent); |
Greg Kroah-Hartman | 8c69f52 | 2009-07-15 12:48:29 -0700 | [diff] [blame] | 277 | kfree(Request); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | static inline void DumpRndisMessage(RNDIS_MESSAGE *RndisMessage) |
| 281 | { |
| 282 | switch (RndisMessage->NdisMessageType) |
| 283 | { |
| 284 | case REMOTE_NDIS_PACKET_MSG: |
| 285 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, data offset %u data len %u, # oob %u, oob offset %u, oob len %u, pkt offset %u, pkt len %u", |
| 286 | RndisMessage->MessageLength, |
| 287 | RndisMessage->Message.Packet.DataOffset, |
| 288 | RndisMessage->Message.Packet.DataLength, |
| 289 | RndisMessage->Message.Packet.NumOOBDataElements, |
| 290 | RndisMessage->Message.Packet.OOBDataOffset, |
| 291 | RndisMessage->Message.Packet.OOBDataLength, |
| 292 | RndisMessage->Message.Packet.PerPacketInfoOffset, |
| 293 | RndisMessage->Message.Packet.PerPacketInfoLength); |
| 294 | break; |
| 295 | |
| 296 | case REMOTE_NDIS_INITIALIZE_CMPLT: |
| 297 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT (len %u, id 0x%x, status 0x%x, major %d, minor %d, device flags %d, max xfer size 0x%x, max pkts %u, pkt aligned %u)", |
| 298 | RndisMessage->MessageLength, |
| 299 | RndisMessage->Message.InitializeComplete.RequestId, |
| 300 | RndisMessage->Message.InitializeComplete.Status, |
| 301 | RndisMessage->Message.InitializeComplete.MajorVersion, |
| 302 | RndisMessage->Message.InitializeComplete.MinorVersion, |
| 303 | RndisMessage->Message.InitializeComplete.DeviceFlags, |
| 304 | RndisMessage->Message.InitializeComplete.MaxTransferSize, |
| 305 | RndisMessage->Message.InitializeComplete.MaxPacketsPerMessage, |
| 306 | RndisMessage->Message.InitializeComplete.PacketAlignmentFactor); |
| 307 | break; |
| 308 | |
| 309 | case REMOTE_NDIS_QUERY_CMPLT: |
| 310 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT (len %u, id 0x%x, status 0x%x, buf len %u, buf offset %u)", |
| 311 | RndisMessage->MessageLength, |
| 312 | RndisMessage->Message.QueryComplete.RequestId, |
| 313 | RndisMessage->Message.QueryComplete.Status, |
| 314 | RndisMessage->Message.QueryComplete.InformationBufferLength, |
| 315 | RndisMessage->Message.QueryComplete.InformationBufferOffset); |
| 316 | break; |
| 317 | |
| 318 | case REMOTE_NDIS_SET_CMPLT: |
| 319 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", |
| 320 | RndisMessage->MessageLength, |
| 321 | RndisMessage->Message.SetComplete.RequestId, |
| 322 | RndisMessage->Message.SetComplete.Status); |
| 323 | break; |
| 324 | |
| 325 | case REMOTE_NDIS_INDICATE_STATUS_MSG: |
| 326 | DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG (len %u, status 0x%x, buf len %u, buf offset %u)", |
| 327 | RndisMessage->MessageLength, |
| 328 | RndisMessage->Message.IndicateStatus.Status, |
| 329 | RndisMessage->Message.IndicateStatus.StatusBufferLength, |
| 330 | RndisMessage->Message.IndicateStatus.StatusBufferOffset); |
| 331 | break; |
| 332 | |
| 333 | default: |
| 334 | DPRINT_DBG(NETVSC, "0x%x (len %u)", |
| 335 | RndisMessage->NdisMessageType, |
| 336 | RndisMessage->MessageLength); |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static int |
| 342 | RndisFilterSendRequest( |
| 343 | RNDIS_DEVICE *Device, |
| 344 | RNDIS_REQUEST *Request |
| 345 | ) |
| 346 | { |
| 347 | int ret=0; |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 348 | struct hv_netvsc_packet *packet; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 349 | |
| 350 | DPRINT_ENTER(NETVSC); |
| 351 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 352 | /* Setup the packet to send it */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 353 | packet = &Request->Packet; |
| 354 | |
Greg Kroah-Hartman | 0e72761 | 2009-07-15 12:46:44 -0700 | [diff] [blame] | 355 | packet->IsDataPacket = false; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 356 | packet->TotalDataBufferLength = Request->RequestMessage.MessageLength; |
| 357 | packet->PageBufferCount = 1; |
| 358 | |
| 359 | packet->PageBuffers[0].Pfn = GetPhysicalAddress(&Request->RequestMessage) >> PAGE_SHIFT; |
| 360 | packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 361 | packet->PageBuffers[0].Offset = (unsigned long)&Request->RequestMessage & (PAGE_SIZE -1); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 362 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 363 | packet->Completion.Send.SendCompletionContext = Request;/* packet; */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 364 | packet->Completion.Send.OnSendCompletion = RndisFilterOnSendRequestCompletion; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 365 | packet->Completion.Send.SendCompletionTid = (unsigned long)Device; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 366 | |
| 367 | ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet); |
| 368 | DPRINT_EXIT(NETVSC); |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | static void |
| 374 | RndisFilterReceiveResponse( |
| 375 | RNDIS_DEVICE *Device, |
| 376 | RNDIS_MESSAGE *Response |
| 377 | ) |
| 378 | { |
| 379 | LIST_ENTRY *anchor; |
| 380 | LIST_ENTRY *curr; |
| 381 | RNDIS_REQUEST *request=NULL; |
Greg Kroah-Hartman | 0e72761 | 2009-07-15 12:46:44 -0700 | [diff] [blame] | 382 | bool found = false; |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 383 | unsigned long flags; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 384 | |
| 385 | DPRINT_ENTER(NETVSC); |
| 386 | |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 387 | spin_lock_irqsave(&Device->request_lock, flags); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 388 | ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList) |
| 389 | { |
| 390 | request = CONTAINING_RECORD(curr, RNDIS_REQUEST, ListEntry); |
| 391 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 392 | /* All request/response message contains RequestId as the 1st field */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 393 | if (request->RequestMessage.Message.InitializeRequest.RequestId == Response->Message.InitializeComplete.RequestId) |
| 394 | { |
| 395 | DPRINT_DBG(NETVSC, "found rndis request for this response (id 0x%x req type 0x%x res type 0x%x)", |
| 396 | request->RequestMessage.Message.InitializeRequest.RequestId, request->RequestMessage.NdisMessageType, Response->NdisMessageType); |
| 397 | |
Greg Kroah-Hartman | 0e72761 | 2009-07-15 12:46:44 -0700 | [diff] [blame] | 398 | found = true; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 399 | break; |
| 400 | } |
| 401 | } |
Greg Kroah-Hartman | 880fb89 | 2009-07-15 14:55:29 -0700 | [diff] [blame] | 402 | spin_unlock_irqrestore(&Device->request_lock, flags); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 403 | |
| 404 | if (found) |
| 405 | { |
| 406 | if (Response->MessageLength <= sizeof(RNDIS_MESSAGE)) |
| 407 | { |
| 408 | memcpy(&request->ResponseMessage, Response, Response->MessageLength); |
| 409 | } |
| 410 | else |
| 411 | { |
Greg Kroah-Hartman | b7d7ae6 | 2009-07-28 16:18:05 -0700 | [diff] [blame] | 412 | DPRINT_ERR(NETVSC, "rndis response buffer overflow detected (size %u max %zu)", Response->MessageLength, sizeof(RNDIS_FILTER_PACKET)); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 413 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 414 | if (Response->NdisMessageType == REMOTE_NDIS_RESET_CMPLT) /* does not have a request id field */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 415 | { |
| 416 | request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW; |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | WaitEventSet(request->WaitEvent); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | DPRINT_ERR(NETVSC, "no rndis request found for this response (id 0x%x res type 0x%x)", |
| 429 | Response->Message.InitializeComplete.RequestId, Response->NdisMessageType); |
| 430 | } |
| 431 | |
| 432 | DPRINT_EXIT(NETVSC); |
| 433 | } |
| 434 | |
| 435 | static void |
| 436 | RndisFilterReceiveIndicateStatus( |
| 437 | RNDIS_DEVICE *Device, |
| 438 | RNDIS_MESSAGE *Response |
| 439 | ) |
| 440 | { |
| 441 | RNDIS_INDICATE_STATUS *indicate = &Response->Message.IndicateStatus; |
| 442 | |
| 443 | if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) |
| 444 | { |
| 445 | gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1); |
| 446 | } |
| 447 | else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT) |
| 448 | { |
| 449 | gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0); |
| 450 | } |
| 451 | else |
| 452 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 453 | /* TODO: */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
| 457 | static void |
| 458 | RndisFilterReceiveData( |
| 459 | RNDIS_DEVICE *Device, |
| 460 | RNDIS_MESSAGE *Message, |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 461 | struct hv_netvsc_packet *Packet |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 462 | ) |
| 463 | { |
| 464 | RNDIS_PACKET *rndisPacket; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 465 | u32 dataOffset; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 466 | |
| 467 | DPRINT_ENTER(NETVSC); |
| 468 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 469 | /* empty ethernet frame ?? */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 470 | ASSERT(Packet->PageBuffers[0].Length > RNDIS_MESSAGE_SIZE(RNDIS_PACKET)); |
| 471 | |
| 472 | rndisPacket = &Message->Message.Packet; |
| 473 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 474 | /* FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this */ |
| 475 | /* netvsc packet (ie TotalDataBufferLength != MessageLength) */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 476 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 477 | /* Remove the rndis header and pass it back up the stack */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 478 | dataOffset = RNDIS_HEADER_SIZE + rndisPacket->DataOffset; |
| 479 | |
| 480 | Packet->TotalDataBufferLength -= dataOffset; |
| 481 | Packet->PageBuffers[0].Offset += dataOffset; |
| 482 | Packet->PageBuffers[0].Length -= dataOffset; |
| 483 | |
Greg Kroah-Hartman | 0e72761 | 2009-07-15 12:46:44 -0700 | [diff] [blame] | 484 | Packet->IsDataPacket = true; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 485 | |
| 486 | gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, Packet); |
| 487 | |
| 488 | DPRINT_EXIT(NETVSC); |
| 489 | } |
| 490 | |
| 491 | static int |
| 492 | RndisFilterOnReceive( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 493 | struct hv_device *Device, |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 494 | struct hv_netvsc_packet *Packet |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 495 | ) |
| 496 | { |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 497 | struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 498 | RNDIS_DEVICE *rndisDevice; |
| 499 | RNDIS_MESSAGE rndisMessage; |
| 500 | RNDIS_MESSAGE *rndisHeader; |
| 501 | |
| 502 | DPRINT_ENTER(NETVSC); |
| 503 | |
| 504 | ASSERT(netDevice); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 505 | /* Make sure the rndis device state is initialized */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 506 | if (!netDevice->Extension) |
| 507 | { |
| 508 | DPRINT_ERR(NETVSC, "got rndis message but no rndis device...dropping this message!"); |
| 509 | DPRINT_EXIT(NETVSC); |
| 510 | return -1; |
| 511 | } |
| 512 | |
| 513 | rndisDevice = (RNDIS_DEVICE*)netDevice->Extension; |
| 514 | if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) |
| 515 | { |
| 516 | DPRINT_ERR(NETVSC, "got rndis message but rndis device uninitialized...dropping this message!"); |
| 517 | DPRINT_EXIT(NETVSC); |
| 518 | return -1; |
| 519 | } |
| 520 | |
| 521 | rndisHeader = (RNDIS_MESSAGE*)PageMapVirtualAddress(Packet->PageBuffers[0].Pfn); |
| 522 | |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 523 | rndisHeader = (void*)((unsigned long)rndisHeader + Packet->PageBuffers[0].Offset); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 524 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 525 | /* Make sure we got a valid rndis message */ |
| 526 | /* FIXME: There seems to be a bug in set completion msg where its MessageLength is 16 bytes but */ |
| 527 | /* the ByteCount field in the xfer page range shows 52 bytes */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 528 | #if 0 |
| 529 | if ( Packet->TotalDataBufferLength != rndisHeader->MessageLength ) |
| 530 | { |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 531 | PageUnmapVirtualAddress((void*)(unsigned long)rndisHeader - Packet->PageBuffers[0].Offset); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 532 | |
| 533 | DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u bytes got %u)...dropping this message!", |
| 534 | rndisHeader->MessageLength, Packet->TotalDataBufferLength); |
| 535 | DPRINT_EXIT(NETVSC); |
| 536 | return -1; |
| 537 | } |
| 538 | #endif |
| 539 | |
| 540 | if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) && (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))) |
| 541 | { |
Greg Kroah-Hartman | b7d7ae6 | 2009-07-28 16:18:05 -0700 | [diff] [blame] | 542 | DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow detected (got %u, max %zu)...marking it an error!", |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 543 | rndisHeader->MessageLength, sizeof(RNDIS_MESSAGE)); |
| 544 | } |
| 545 | |
| 546 | memcpy(&rndisMessage, rndisHeader, (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))?sizeof(RNDIS_MESSAGE):rndisHeader->MessageLength); |
| 547 | |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 548 | PageUnmapVirtualAddress((void*)(unsigned long)rndisHeader - Packet->PageBuffers[0].Offset); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 549 | |
| 550 | DumpRndisMessage(&rndisMessage); |
| 551 | |
| 552 | switch (rndisMessage.NdisMessageType) |
| 553 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 554 | /* data msg */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 555 | case REMOTE_NDIS_PACKET_MSG: |
| 556 | RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet); |
| 557 | break; |
| 558 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 559 | /* completion msgs */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 560 | case REMOTE_NDIS_INITIALIZE_CMPLT: |
| 561 | case REMOTE_NDIS_QUERY_CMPLT: |
| 562 | case REMOTE_NDIS_SET_CMPLT: |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 563 | /* case REMOTE_NDIS_RESET_CMPLT: */ |
| 564 | /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 565 | RndisFilterReceiveResponse(rndisDevice, &rndisMessage); |
| 566 | break; |
| 567 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 568 | /* notification msgs */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 569 | case REMOTE_NDIS_INDICATE_STATUS_MSG: |
| 570 | RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage); |
| 571 | break; |
| 572 | default: |
| 573 | DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", rndisMessage.NdisMessageType, rndisMessage.MessageLength); |
| 574 | break; |
| 575 | } |
| 576 | |
| 577 | DPRINT_EXIT(NETVSC); |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | |
| 582 | static int |
| 583 | RndisFilterQueryDevice( |
| 584 | RNDIS_DEVICE *Device, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 585 | u32 Oid, |
Greg Kroah-Hartman | e20f683 | 2009-07-14 15:07:21 -0700 | [diff] [blame] | 586 | void *Result, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 587 | u32 *ResultSize |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 588 | ) |
| 589 | { |
| 590 | RNDIS_REQUEST *request; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 591 | u32 inresultSize = *ResultSize; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 592 | RNDIS_QUERY_REQUEST *query; |
| 593 | RNDIS_QUERY_COMPLETE *queryComplete; |
| 594 | int ret=0; |
| 595 | |
| 596 | DPRINT_ENTER(NETVSC); |
| 597 | |
| 598 | ASSERT(Result); |
| 599 | |
| 600 | *ResultSize = 0; |
| 601 | request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, RNDIS_MESSAGE_SIZE(RNDIS_QUERY_REQUEST)); |
| 602 | if (!request) |
| 603 | { |
| 604 | ret = -1; |
| 605 | goto Cleanup; |
| 606 | } |
| 607 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 608 | /* Setup the rndis query */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 609 | query = &request->RequestMessage.Message.QueryRequest; |
| 610 | query->Oid = Oid; |
| 611 | query->InformationBufferOffset = sizeof(RNDIS_QUERY_REQUEST); |
| 612 | query->InformationBufferLength = 0; |
| 613 | query->DeviceVcHandle = 0; |
| 614 | |
| 615 | ret = RndisFilterSendRequest(Device, request); |
| 616 | if (ret != 0) |
| 617 | { |
| 618 | goto Cleanup; |
| 619 | } |
| 620 | |
| 621 | WaitEventWait(request->WaitEvent); |
| 622 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 623 | /* Copy the response back */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 624 | queryComplete = &request->ResponseMessage.Message.QueryComplete; |
| 625 | |
| 626 | if (queryComplete->InformationBufferLength > inresultSize) |
| 627 | { |
| 628 | ret = -1; |
| 629 | goto Cleanup; |
| 630 | } |
| 631 | |
| 632 | memcpy(Result, |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 633 | (void*)((unsigned long)queryComplete + queryComplete->InformationBufferOffset), |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 634 | queryComplete->InformationBufferLength); |
| 635 | |
| 636 | *ResultSize = queryComplete->InformationBufferLength; |
| 637 | |
| 638 | Cleanup: |
| 639 | if (request) |
| 640 | { |
| 641 | PutRndisRequest(Device, request); |
| 642 | } |
| 643 | DPRINT_EXIT(NETVSC); |
| 644 | |
| 645 | return ret; |
| 646 | } |
| 647 | |
| 648 | static inline int |
| 649 | RndisFilterQueryDeviceMac( |
| 650 | RNDIS_DEVICE *Device |
| 651 | ) |
| 652 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 653 | u32 size=HW_MACADDR_LEN; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 654 | |
| 655 | return RndisFilterQueryDevice(Device, |
| 656 | RNDIS_OID_802_3_PERMANENT_ADDRESS, |
| 657 | Device->HwMacAddr, |
| 658 | &size); |
| 659 | } |
| 660 | |
| 661 | static inline int |
| 662 | RndisFilterQueryDeviceLinkStatus( |
| 663 | RNDIS_DEVICE *Device |
| 664 | ) |
| 665 | { |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 666 | u32 size=sizeof(u32); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 667 | |
| 668 | return RndisFilterQueryDevice(Device, |
| 669 | RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, |
| 670 | &Device->LinkStatus, |
| 671 | &size); |
| 672 | } |
| 673 | |
| 674 | static int |
| 675 | RndisFilterSetPacketFilter( |
| 676 | RNDIS_DEVICE *Device, |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 677 | u32 NewFilter |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 678 | ) |
| 679 | { |
| 680 | RNDIS_REQUEST *request; |
| 681 | RNDIS_SET_REQUEST *set; |
| 682 | RNDIS_SET_COMPLETE *setComplete; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 683 | u32 status; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 684 | int ret; |
| 685 | |
| 686 | DPRINT_ENTER(NETVSC); |
| 687 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 688 | ASSERT(RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32) <= sizeof(RNDIS_MESSAGE)); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 689 | |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 690 | request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32)); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 691 | if (!request) |
| 692 | { |
| 693 | ret = -1; |
| 694 | goto Cleanup; |
| 695 | } |
| 696 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 697 | /* Setup the rndis set */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 698 | set = &request->RequestMessage.Message.SetRequest; |
| 699 | set->Oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 700 | set->InformationBufferLength = sizeof(u32); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 701 | set->InformationBufferOffset = sizeof(RNDIS_SET_REQUEST); |
| 702 | |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 703 | memcpy((void*)(unsigned long)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(u32)); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 704 | |
| 705 | ret = RndisFilterSendRequest(Device, request); |
| 706 | if (ret != 0) |
| 707 | { |
| 708 | goto Cleanup; |
| 709 | } |
| 710 | |
| 711 | ret = WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/); |
| 712 | if (!ret) |
| 713 | { |
| 714 | ret = -1; |
| 715 | DPRINT_ERR(NETVSC, "timeout before we got a set response..."); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 716 | /* We cant deallocate the request since we may still receive a send completion for it. */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 717 | goto Exit; |
| 718 | } |
| 719 | else |
| 720 | { |
| 721 | if (ret > 0) |
| 722 | { |
| 723 | ret = 0; |
| 724 | } |
| 725 | setComplete = &request->ResponseMessage.Message.SetComplete; |
| 726 | status = setComplete->Status; |
| 727 | } |
| 728 | |
| 729 | Cleanup: |
| 730 | if (request) |
| 731 | { |
| 732 | PutRndisRequest(Device, request); |
| 733 | } |
| 734 | Exit: |
| 735 | DPRINT_EXIT(NETVSC); |
| 736 | |
| 737 | return ret; |
| 738 | } |
| 739 | |
| 740 | int |
| 741 | RndisFilterInit( |
| 742 | NETVSC_DRIVER_OBJECT *Driver |
| 743 | ) |
| 744 | { |
| 745 | DPRINT_ENTER(NETVSC); |
| 746 | |
Greg Kroah-Hartman | b7d7ae6 | 2009-07-28 16:18:05 -0700 | [diff] [blame] | 747 | DPRINT_DBG(NETVSC, "sizeof(RNDIS_FILTER_PACKET) == %zd", sizeof(RNDIS_FILTER_PACKET)); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 748 | |
| 749 | Driver->RequestExtSize = sizeof(RNDIS_FILTER_PACKET); |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 750 | Driver->AdditionalRequestPageBufferCount = 1; /* For rndis header */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 751 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 752 | /* Driver->Context = rndisDriver; */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 753 | |
| 754 | memset(&gRndisFilter, 0, sizeof(RNDIS_FILTER_DRIVER_OBJECT)); |
| 755 | |
| 756 | /*rndisDriver->Driver = Driver; |
| 757 | |
| 758 | ASSERT(Driver->OnLinkStatusChanged); |
| 759 | rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/ |
| 760 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 761 | /* Save the original dispatch handlers before we override it */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 762 | gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd; |
| 763 | gRndisFilter.InnerDriver.Base.OnDeviceRemove = Driver->Base.OnDeviceRemove; |
| 764 | gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup; |
| 765 | |
| 766 | ASSERT(Driver->OnSend); |
| 767 | ASSERT(Driver->OnReceiveCallback); |
| 768 | gRndisFilter.InnerDriver.OnSend = Driver->OnSend; |
| 769 | gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback; |
| 770 | gRndisFilter.InnerDriver.OnLinkStatusChanged = Driver->OnLinkStatusChanged; |
| 771 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 772 | /* Override */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 773 | Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd; |
| 774 | Driver->Base.OnDeviceRemove = RndisFilterOnDeviceRemove; |
| 775 | Driver->Base.OnCleanup = RndisFilterOnCleanup; |
| 776 | Driver->OnSend = RndisFilterOnSend; |
| 777 | Driver->OnOpen = RndisFilterOnOpen; |
| 778 | Driver->OnClose = RndisFilterOnClose; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 779 | /* Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus; */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 780 | Driver->OnReceiveCallback = RndisFilterOnReceive; |
| 781 | |
| 782 | DPRINT_EXIT(NETVSC); |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | static int |
| 788 | RndisFilterInitDevice( |
| 789 | RNDIS_DEVICE *Device |
| 790 | ) |
| 791 | { |
| 792 | RNDIS_REQUEST *request; |
| 793 | RNDIS_INITIALIZE_REQUEST *init; |
| 794 | RNDIS_INITIALIZE_COMPLETE *initComplete; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 795 | u32 status; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 796 | int ret; |
| 797 | |
| 798 | DPRINT_ENTER(NETVSC); |
| 799 | |
| 800 | request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, RNDIS_MESSAGE_SIZE(RNDIS_INITIALIZE_REQUEST)); |
| 801 | if (!request) |
| 802 | { |
| 803 | ret = -1; |
| 804 | goto Cleanup; |
| 805 | } |
| 806 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 807 | /* Setup the rndis set */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 808 | init = &request->RequestMessage.Message.InitializeRequest; |
| 809 | init->MajorVersion = RNDIS_MAJOR_VERSION; |
| 810 | init->MinorVersion = RNDIS_MINOR_VERSION; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 811 | init->MaxTransferSize = 2048; /* FIXME: Use 1536 - rounded ethernet frame size */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 812 | |
| 813 | Device->State = RNDIS_DEV_INITIALIZING; |
| 814 | |
| 815 | ret = RndisFilterSendRequest(Device, request); |
| 816 | if (ret != 0) |
| 817 | { |
| 818 | Device->State = RNDIS_DEV_UNINITIALIZED; |
| 819 | goto Cleanup; |
| 820 | } |
| 821 | |
| 822 | WaitEventWait(request->WaitEvent); |
| 823 | |
| 824 | initComplete = &request->ResponseMessage.Message.InitializeComplete; |
| 825 | status = initComplete->Status; |
| 826 | if (status == RNDIS_STATUS_SUCCESS) |
| 827 | { |
| 828 | Device->State = RNDIS_DEV_INITIALIZED; |
| 829 | ret = 0; |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | Device->State = RNDIS_DEV_UNINITIALIZED; |
| 834 | ret = -1; |
| 835 | } |
| 836 | |
| 837 | Cleanup: |
| 838 | if (request) |
| 839 | { |
| 840 | PutRndisRequest(Device, request); |
| 841 | } |
| 842 | DPRINT_EXIT(NETVSC); |
| 843 | |
| 844 | return ret; |
| 845 | } |
| 846 | |
| 847 | static void |
| 848 | RndisFilterHaltDevice( |
| 849 | RNDIS_DEVICE *Device |
| 850 | ) |
| 851 | { |
| 852 | RNDIS_REQUEST *request; |
| 853 | RNDIS_HALT_REQUEST *halt; |
| 854 | |
| 855 | DPRINT_ENTER(NETVSC); |
| 856 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 857 | /* Attempt to do a rndis device halt */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 858 | request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, RNDIS_MESSAGE_SIZE(RNDIS_HALT_REQUEST)); |
| 859 | if (!request) |
| 860 | { |
| 861 | goto Cleanup; |
| 862 | } |
| 863 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 864 | /* Setup the rndis set */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 865 | halt = &request->RequestMessage.Message.HaltRequest; |
| 866 | halt->RequestId = InterlockedIncrement((int*)&Device->NewRequestId); |
| 867 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 868 | /* Ignore return since this msg is optional. */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 869 | RndisFilterSendRequest(Device, request); |
| 870 | |
| 871 | Device->State = RNDIS_DEV_UNINITIALIZED; |
| 872 | |
| 873 | Cleanup: |
| 874 | if (request) |
| 875 | { |
| 876 | PutRndisRequest(Device, request); |
| 877 | } |
| 878 | DPRINT_EXIT(NETVSC); |
| 879 | return; |
| 880 | } |
| 881 | |
| 882 | |
| 883 | static int |
| 884 | RndisFilterOpenDevice( |
| 885 | RNDIS_DEVICE *Device |
| 886 | ) |
| 887 | { |
| 888 | int ret=0; |
| 889 | |
| 890 | DPRINT_ENTER(NETVSC); |
| 891 | |
| 892 | if (Device->State != RNDIS_DEV_INITIALIZED) |
| 893 | return 0; |
| 894 | |
| 895 | ret = RndisFilterSetPacketFilter(Device, NDIS_PACKET_TYPE_BROADCAST|NDIS_PACKET_TYPE_DIRECTED); |
| 896 | if (ret == 0) |
| 897 | { |
| 898 | Device->State = RNDIS_DEV_DATAINITIALIZED; |
| 899 | } |
| 900 | |
| 901 | DPRINT_EXIT(NETVSC); |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | static int |
| 906 | RndisFilterCloseDevice( |
| 907 | RNDIS_DEVICE *Device |
| 908 | ) |
| 909 | { |
| 910 | int ret; |
| 911 | |
| 912 | DPRINT_ENTER(NETVSC); |
| 913 | |
| 914 | if (Device->State != RNDIS_DEV_DATAINITIALIZED) |
| 915 | return 0; |
| 916 | |
| 917 | ret = RndisFilterSetPacketFilter(Device, 0); |
| 918 | if (ret == 0) |
| 919 | { |
| 920 | Device->State = RNDIS_DEV_INITIALIZED; |
| 921 | } |
| 922 | |
| 923 | DPRINT_EXIT(NETVSC); |
| 924 | |
| 925 | return ret; |
| 926 | } |
| 927 | |
| 928 | |
| 929 | int |
| 930 | RndisFilterOnDeviceAdd( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 931 | struct hv_device *Device, |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 932 | void *AdditionalInfo |
| 933 | ) |
| 934 | { |
| 935 | int ret; |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 936 | struct NETVSC_DEVICE *netDevice; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 937 | RNDIS_DEVICE *rndisDevice; |
| 938 | NETVSC_DEVICE_INFO *deviceInfo = (NETVSC_DEVICE_INFO*)AdditionalInfo; |
| 939 | |
| 940 | DPRINT_ENTER(NETVSC); |
| 941 | |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 942 | rndisDevice = GetRndisDevice(); |
| 943 | if (!rndisDevice) |
| 944 | { |
| 945 | DPRINT_EXIT(NETVSC); |
| 946 | return -1; |
| 947 | } |
| 948 | |
| 949 | DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice); |
| 950 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 951 | /* Let the inner driver handle this first to create the netvsc channel */ |
| 952 | /* NOTE! Once the channel is created, we may get a receive callback */ |
| 953 | /* (RndisFilterOnReceive()) before this call is completed */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 954 | ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo); |
| 955 | if (ret != 0) |
| 956 | { |
| 957 | PutRndisDevice(rndisDevice); |
| 958 | DPRINT_EXIT(NETVSC); |
| 959 | return ret; |
| 960 | } |
| 961 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 962 | |
| 963 | /* Initialize the rndis device */ |
| 964 | |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 965 | netDevice = (struct NETVSC_DEVICE*)Device->Extension; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 966 | ASSERT(netDevice); |
| 967 | ASSERT(netDevice->Device); |
| 968 | |
| 969 | netDevice->Extension = rndisDevice; |
| 970 | rndisDevice->NetDevice = netDevice; |
| 971 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 972 | /* Send the rndis initialization message */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 973 | ret = RndisFilterInitDevice(rndisDevice); |
| 974 | if (ret != 0) |
| 975 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 976 | /* TODO: If rndis init failed, we will need to shut down the channel */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 979 | /* Get the mac address */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 980 | ret = RndisFilterQueryDeviceMac(rndisDevice); |
| 981 | if (ret != 0) |
| 982 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 983 | /* TODO: shutdown rndis device and the channel */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | DPRINT_INFO(NETVSC, "Device 0x%p mac addr %02x%02x%02x%02x%02x%02x", |
| 987 | rndisDevice, |
| 988 | rndisDevice->HwMacAddr[0], |
| 989 | rndisDevice->HwMacAddr[1], |
| 990 | rndisDevice->HwMacAddr[2], |
| 991 | rndisDevice->HwMacAddr[3], |
| 992 | rndisDevice->HwMacAddr[4], |
| 993 | rndisDevice->HwMacAddr[5]); |
| 994 | |
| 995 | memcpy(deviceInfo->MacAddr, rndisDevice->HwMacAddr, HW_MACADDR_LEN); |
| 996 | |
| 997 | RndisFilterQueryDeviceLinkStatus(rndisDevice); |
| 998 | |
| 999 | deviceInfo->LinkState = rndisDevice->LinkStatus; |
| 1000 | DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, ((deviceInfo->LinkState)?("down"):("up"))); |
| 1001 | |
| 1002 | DPRINT_EXIT(NETVSC); |
| 1003 | |
| 1004 | return ret; |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | static int |
| 1009 | RndisFilterOnDeviceRemove( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1010 | struct hv_device *Device |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1011 | ) |
| 1012 | { |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 1013 | struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1014 | RNDIS_DEVICE *rndisDevice = (RNDIS_DEVICE*)netDevice->Extension; |
| 1015 | |
| 1016 | DPRINT_ENTER(NETVSC); |
| 1017 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1018 | /* Halt and release the rndis device */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1019 | RndisFilterHaltDevice(rndisDevice); |
| 1020 | |
| 1021 | PutRndisDevice(rndisDevice); |
| 1022 | netDevice->Extension = NULL; |
| 1023 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1024 | /* Pass control to inner driver to remove the device */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1025 | gRndisFilter.InnerDriver.Base.OnDeviceRemove(Device); |
| 1026 | |
| 1027 | DPRINT_EXIT(NETVSC); |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | |
| 1033 | static void |
| 1034 | RndisFilterOnCleanup( |
Nicolas Palix | 775ef25 | 2009-07-29 14:09:45 +0200 | [diff] [blame] | 1035 | struct hv_driver *Driver |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1036 | ) |
| 1037 | { |
| 1038 | DPRINT_ENTER(NETVSC); |
| 1039 | |
| 1040 | DPRINT_EXIT(NETVSC); |
| 1041 | } |
| 1042 | |
| 1043 | static int |
| 1044 | RndisFilterOnOpen( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1045 | struct hv_device *Device |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1046 | ) |
| 1047 | { |
| 1048 | int ret; |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 1049 | struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1050 | |
| 1051 | DPRINT_ENTER(NETVSC); |
| 1052 | |
| 1053 | ASSERT(netDevice); |
| 1054 | ret = RndisFilterOpenDevice((RNDIS_DEVICE*)netDevice->Extension); |
| 1055 | |
| 1056 | DPRINT_EXIT(NETVSC); |
| 1057 | |
| 1058 | return ret; |
| 1059 | } |
| 1060 | |
| 1061 | static int |
| 1062 | RndisFilterOnClose( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1063 | struct hv_device *Device |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1064 | ) |
| 1065 | { |
| 1066 | int ret; |
Bill Pemberton | d1af1db7 | 2009-07-27 16:47:44 -0400 | [diff] [blame] | 1067 | struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1068 | |
| 1069 | DPRINT_ENTER(NETVSC); |
| 1070 | |
| 1071 | ASSERT(netDevice); |
| 1072 | ret = RndisFilterCloseDevice((RNDIS_DEVICE*)netDevice->Extension); |
| 1073 | |
| 1074 | DPRINT_EXIT(NETVSC); |
| 1075 | |
| 1076 | return ret; |
| 1077 | } |
| 1078 | |
| 1079 | |
| 1080 | static int |
| 1081 | RndisFilterOnSend( |
Nicolas Palix | 3d3b551 | 2009-07-28 17:32:53 +0200 | [diff] [blame] | 1082 | struct hv_device *Device, |
Nicolas Palix | 4193d4f | 2009-07-29 14:10:10 +0200 | [diff] [blame] | 1083 | struct hv_netvsc_packet *Packet |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1084 | ) |
| 1085 | { |
| 1086 | int ret=0; |
| 1087 | RNDIS_FILTER_PACKET *filterPacket; |
| 1088 | RNDIS_MESSAGE *rndisMessage; |
| 1089 | RNDIS_PACKET *rndisPacket; |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 1090 | u32 rndisMessageSize; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1091 | |
| 1092 | DPRINT_ENTER(NETVSC); |
| 1093 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1094 | /* Add the rndis header */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1095 | filterPacket = (RNDIS_FILTER_PACKET*)Packet->Extension; |
| 1096 | ASSERT(filterPacket); |
| 1097 | |
| 1098 | memset(filterPacket, 0, sizeof(RNDIS_FILTER_PACKET)); |
| 1099 | |
| 1100 | rndisMessage = &filterPacket->Message; |
| 1101 | rndisMessageSize = RNDIS_MESSAGE_SIZE(RNDIS_PACKET); |
| 1102 | |
| 1103 | rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG; |
| 1104 | rndisMessage->MessageLength = Packet->TotalDataBufferLength + rndisMessageSize; |
| 1105 | |
| 1106 | rndisPacket = &rndisMessage->Message.Packet; |
| 1107 | rndisPacket->DataOffset = sizeof(RNDIS_PACKET); |
| 1108 | rndisPacket->DataLength = Packet->TotalDataBufferLength; |
| 1109 | |
Greg Kroah-Hartman | 0e72761 | 2009-07-15 12:46:44 -0700 | [diff] [blame] | 1110 | Packet->IsDataPacket = true; |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1111 | Packet->PageBuffers[0].Pfn = GetPhysicalAddress(rndisMessage) >> PAGE_SHIFT; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 1112 | Packet->PageBuffers[0].Offset = (unsigned long)rndisMessage & (PAGE_SIZE-1); |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1113 | Packet->PageBuffers[0].Length = rndisMessageSize; |
| 1114 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1115 | /* Save the packet send completion and context */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1116 | filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion; |
| 1117 | filterPacket->CompletionContext = Packet->Completion.Send.SendCompletionContext; |
| 1118 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1119 | /* Use ours */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1120 | Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion; |
| 1121 | Packet->Completion.Send.SendCompletionContext = filterPacket; |
| 1122 | |
| 1123 | ret = gRndisFilter.InnerDriver.OnSend(Device, Packet); |
| 1124 | if (ret != 0) |
| 1125 | { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1126 | /* Reset the completion to originals to allow retries from above */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1127 | Packet->Completion.Send.OnSendCompletion = filterPacket->OnCompletion; |
| 1128 | Packet->Completion.Send.SendCompletionContext = filterPacket->CompletionContext; |
| 1129 | } |
| 1130 | |
| 1131 | DPRINT_EXIT(NETVSC); |
| 1132 | |
| 1133 | return ret; |
| 1134 | } |
| 1135 | |
| 1136 | static void |
| 1137 | RndisFilterOnSendCompletion( |
| 1138 | void *Context) |
| 1139 | { |
| 1140 | RNDIS_FILTER_PACKET *filterPacket = (RNDIS_FILTER_PACKET *)Context; |
| 1141 | |
| 1142 | DPRINT_ENTER(NETVSC); |
| 1143 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1144 | /* Pass it back to the original handler */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1145 | filterPacket->OnCompletion(filterPacket->CompletionContext); |
| 1146 | |
| 1147 | DPRINT_EXIT(NETVSC); |
| 1148 | } |
| 1149 | |
| 1150 | |
| 1151 | static void |
| 1152 | RndisFilterOnSendRequestCompletion( |
| 1153 | void *Context |
| 1154 | ) |
| 1155 | { |
| 1156 | DPRINT_ENTER(NETVSC); |
| 1157 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 1158 | /* Noop */ |
Hank Janssen | fceaf24 | 2009-07-13 15:34:54 -0700 | [diff] [blame] | 1159 | DPRINT_EXIT(NETVSC); |
| 1160 | } |