/* * Copyright (c) 2003 * Bill Paul . All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Bill Paul. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD"); #include #include #include #include #ifdef _KERNEL #include #include #include #include #else #include #include #include #include #endif #include "pe_var.h" #include "resource_var.h" #include "ndis_var.h" #include "hal_var.h" #include "ntoskrnl_var.h" #define __stdcall __attribute__((__stdcall__)) #define NDIS_DUMMY_PATH "\\\\some\\bogus\\path" __stdcall static void ndis_status_func(adapter, status, sbuf, slen) ndis_handle *adapter; ndis_status status; void *sbuf; uint32_t slen; { printf ("status: %x\n", status); return; } __stdcall static void ndis_statusdone_func(adapter) ndis_handle *adapter; { printf ("status complete\n"); return; } __stdcall static void ndis_set_done(adapter, status) ndis_handle *adapter; ndis_status status; { printf ("Setup done...\n"); return; } int ndis_load_driver(img, softc) vm_offset_t img; void *softc; { /*__stdcall*/ driver_entry entry; image_optional_header opt_hdr; image_import_descriptor imp_desc; ndis_status status, openstatus = 0; ndis_unicode_string dummystr; ndis_driver_object drv; ndis_miniport_block *block; /*__stdcall*/ ndis_init_handler initfunc; ndis_medium mediumarray; uint32_t chosenmedium; int idx; uint32_t *ptr; /* Perform text relocation */ if (pe_relocate(img)) return(ENOEXEC); /* Dynamically link the NDIS.SYS routines -- required. */ if (pe_patch_imports(img, "NDIS", ndis_functbl)) return(ENOEXEC); /* Dynamically link the HAL.dll routines -- also required. */ if (pe_patch_imports(img, "HAL", hal_functbl)) return(ENOEXEC); /* Dynamically link ntoskrnl.exe -- optional. */ if (pe_get_import_descriptor(img, &imp_desc, "ntoskrnl") == 0) { if (pe_patch_imports(img, "ntoskrnl", ntoskrnl_functbl)) return(ENOEXEC); } /* Locate the driver entry point */ pe_get_optional_header(img, &opt_hdr); entry = (driver_entry)(img + opt_hdr.ioh_entryaddr); /* * Now call the DriverEntry() routine. This will cause * a callout to the NdisInitializeWrapper() and * NdisMRegisterMiniport() routines. */ dummystr.nus_len = strlen(NDIS_DUMMY_PATH); dummystr.nus_maxlen = strlen(NDIS_DUMMY_PATH); dummystr.nus_buf = NULL; ndis_ascii_to_unicode(NDIS_DUMMY_PATH, &dummystr.nus_buf); drv.ndo_ifname = "ndis0"; status = entry(&drv, &dummystr); #ifdef _KERNEL free (dummystr.nus_buf, M_DEVBUF); #else free (dummystr.nus_buf); #endif if (status != NDIS_STATUS_SUCCESS) return(ENODEV); /* * Now that we have the miniport driver characteristics, * create an NDIS block and call the init handler. * This will cause the driver to try to probe for * a device. */ #ifdef _KERNEL block = malloc(sizeof(ndis_miniport_block), M_DEVBUF, M_NOWAIT); #else block = malloc(sizeof(ndis_miniport_block)); #endif bzero((char *)block, sizeof(ndis_miniport_block)); /*block->nmb_signature = 0xcafebabe;*/ ptr = (uint32_t *)block; for (idx = 0; idx < sizeof(ndis_miniport_block) / 4; idx++) { *ptr = idx; ptr++; } /*block->nmb_signature = 0xcafebabe;*/ block->nmb_querydone_func = ndis_set_done; block->nmb_setdone_func = ndis_set_done; block->nmb_status_func = ndis_status_func; block->nmb_statusdone_func = ndis_statusdone_func; initfunc = (ndis_init_handler)drv.ndo_chars.nmc_init_func; status = initfunc(&openstatus, &chosenmedium, &mediumarray, NdisMediumMax, block, block); printf ("status: %x\n", status); return(0); }