Пример #1
0
int
init_driver()
{
    union REGS ireg, oreg;
    struct SREGS sreg;
    unsigned short tmp, i;
    extern int kernel_int;
    struct TCB *tp;

    // Find Packet Driver TSR

    packet_int = find_signature("PKT DRVR", 8, 0x60, 0x7f);
    if (!packet_int) {
        error_print("No Packet Driver.\r$");
        return(-1);
    }
    if ((packet_int == kernel_int) || (packet_int == (kernel_int + 1))) {
        error_print("Bad Interrupt Number.\r$");
        return(-1);
    }
    //dos_print("Packet Driver is found at 0x$");
    //printhex(packet_int);
    //dos_print(".\r\n$");

    ireg.x.ax = 0x01FF;	// Get Driver Info
    ireg.x.bx = 0xFFFF;
    int86(packet_int, &ireg, &oreg);
    driver_type = oreg.x.cflag ? ETHERNET_DRIVER : oreg.h.ch;

    // MTU_SIZE Adjustment be done for Specific Driver
    // MTU size includes TCP/IP header (excludes Datalink header)
    switch (driver_type) {
    //	case  BUFFER_DRIVER   :
    case  ETHERNET_DRIVER :
        MTU_SIZE = MAX_BUFSIZE + TCP_HLEN;
        break;
    //	case  SLIP_DRIVER     : MTU_SIZE =  296; break;
    default		      :
        MTU_SIZE =  576;
        break;
    }

    ireg.h.ah = 0x02;
    sreg.es = _CS;
    if (driver_type == SLIP_DRIVER) {
        ireg.x.di = (unsigned)RING_BUFFER + MAX_RING_BUFFER / 2;
    } else {
        ireg.h.al = driver_type;
        ireg.x.cx = 0x2;
        ireg.h.dl = 0;
        ireg.x.di = (unsigned)pktisr;	// RX Routine
        tmp = ETIP;
        sreg.ds = _SS;
        ireg.x.si = (unsigned)&tmp;	// for IP
    }
    int86x(packet_int, &ireg, &oreg, &sreg);
    if (driver_type == SLIP_DRIVER) {
        packet_buffer = RING_BUFFER;
        return(0);
    }
    if (oreg.x.cflag) {
        goto usedbyother;
    } else {
        handle[0] = oreg.x.ax;
    }

    tmp = ETADR;
    sreg.es = _CS;			// di still alive
    sreg.ds = _SS;
    ireg.x.si = (unsigned)&tmp;	// for ARP
    int86x(packet_int, &ireg, &oreg, &sreg);
    if (oreg.x.cflag) {
        ireg.h.ah = 0x03;			// release handle[0]
        ireg.x.bx = handle[0];
        int86(packet_int, &ireg, &oreg);
usedbyother:
        error_print("Packet Driver in USE.\r$");
        return(-1);
    }
    handle[1] = oreg.x.ax;

get_addr:
    // Read my Ethernet Address
    //dos_print("Read Ethernet Address\n\r$");

    ireg.h.ah = 0x06;
    ireg.x.bx = handle[0];
    ireg.x.cx = 6;					// 6 byte address
    sreg.es = _DS;
    ireg.x.di = (unsigned)(ARP_STUB.my_hw_addr);
    int86x(packet_int, &ireg, &oreg, &sreg);
    if (oreg.x.cflag) {
        error_print("in Reading H/W Address.\r$");
        close_driver();
        return(-1);
    }

    copy_hw_addr(ARP_STUB.ether_pkt.source, ARP_STUB.my_hw_addr);
    for (tp = tcb, i = 0; i < num_socket; i++, tp++) {
        copy_hw_addr(ETH_STUB(tp)->source, ARP_STUB.my_hw_addr);
    }

    //dos_print("Packet Driver is initialized\n\r$");

    //rprintf("H(%d,%d) ", handle[0], handle[1]);
    //rprintf("ADR:"); print_ether_addr(ARP_STUB.my_hw_addr);
    //rprintf("\n");
    return(0);
}
Пример #2
0
static void
exit_func()
{
	if (!close_driver())
		fprintf(stderr, "Cannot close OS/2-ASPI-Router!\n");
}