*
* You should have received a copy of the GNU General Public License
* along with this program (see the file COPYING included with this
- * distribution); if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * distribution); if not, see <http://www.gnu.org/licenses/>.
*/
-#include "vl.h"
+#include "qemu-common.h"
+#include "net.h"
+#include "sysemu.h"
#include <stdio.h>
#include <windows.h>
-
-/* NOTE: PCIBus is redefined in winddk.h */
-#define PCIBus _PCIBus
-#include <ddk/ntapi.h>
-#include <ddk/winddk.h>
-#include <ddk/ntddk.h>
-#undef PCIBus
+#include <winioctl.h>
//=============
// TAP IOCTLs
// Compile time configuration
//======================
-//#define DEBUG_TAP_WIN32 1
+//#define DEBUG_TAP_WIN32
#define TUN_ASYNCHRONOUS_WRITES 1
component_id_string,
NULL,
&data_type,
- component_id,
+ (LPBYTE)component_id,
&len);
if (!(status != ERROR_SUCCESS || data_type != REG_SZ)) {
net_cfg_instance_id_string,
NULL,
&data_type,
- net_cfg_instance_id,
+ (LPBYTE)net_cfg_instance_id,
&len);
if (status == ERROR_SUCCESS && data_type == REG_SZ) {
0,
KEY_READ,
&connection_key);
-
+
if (status == ERROR_SUCCESS) {
len = sizeof (name_data);
status = RegQueryValueEx(
name_string,
NULL,
&name_type,
- name_data,
+ (LPBYTE)name_data,
&len);
if (status != ERROR_SUCCESS || name_type != REG_SZ) {
result = WriteFile(overlapped->handle, buffer, size,
&write_size, &overlapped->write_overlapped);
-
+
if (!result) {
switch (error = GetLastError())
{
result = GetOverlappedResult( overlapped->handle, &overlapped->read_overlapped,
&read_size, FALSE);
if (!result) {
-#if DEBUG_TAP_WIN32
+#ifdef DEBUG_TAP_WIN32
LPVOID lpBuffer;
dwError = GetLastError();
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
#endif
}
} else {
-#if DEBUG_TAP_WIN32
+#ifdef DEBUG_TAP_WIN32
LPVOID lpBuffer;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
}
static void tap_win32_free_buffer(tap_win32_overlapped_t *overlapped,
- char* pbuf)
+ uint8_t *pbuf)
{
tun_buffer_t* buffer = (tun_buffer_t*)pbuf;
put_buffer_on_free_list(overlapped, buffer);
unsigned long minor;
unsigned long debug;
} version;
- LONG version_len;
+ DWORD version_len;
DWORD idThread;
HANDLE hThread;
tap_win32_overlapped_t *handle;
} TAPState;
-static void tap_receive(void *opaque, const uint8_t *buf, int size)
+static void tap_cleanup(VLANClientState *vc)
{
- TAPState *s = opaque;
+ TAPState *s = vc->opaque;
+
+ qemu_del_wait_object(s->handle->tap_semaphore, NULL, NULL);
- tap_win32_write(s->handle, buf, size);
+ /* FIXME: need to kill thread and close file handle:
+ tap_win32_close(s);
+ */
+ qemu_free(s);
+}
+
+static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
+{
+ TAPState *s = vc->opaque;
+
+ return tap_win32_write(s->handle, buf, size);
}
static void tap_win32_send(void *opaque)
}
}
-int tap_win32_init(VLANState *vlan, const char *ifname)
+int tap_win32_init(VLANState *vlan, const char *model,
+ const char *name, const char *ifname)
{
TAPState *s;
-
+
s = qemu_mallocz(sizeof(TAPState));
if (!s)
return -1;
return -1;
}
- s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
-
+ s->vc = qemu_new_vlan_client(vlan, model, name, NULL, tap_receive,
+ NULL, tap_cleanup, s);
+
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"tap: ifname=%s", ifname);