delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/20:07:12

Date: 09 Mar 97 19:52:05 EST
From: Andrew Crabtree <71223 DOT 3315 AT CompuServe DOT COM>
To: djgpp <djgpp AT delorie DOT com>
Subject: RMCB Help
Message-ID: <970310005204_71223.3315_GHL95-2@CompuServe.COM>

Hello - 

I've been trying (without much success) to interface with a packet driver.  I
have certain routines working - I can find the packet driver, get the hardware
MAC address, and transmit packets.  Most of my early problems appear to be
because of Win 95.  The packet driver only transmits in plain old Dos.  Anyway,
my callback routines are crashing pretty hard.  I am not using the go-32
routines, but instead the __dpmi ones.  Also, I originally zeroed out es and di
on entry
into the ARP handler, and that crashed too ( I'm just trying to verify it gets
to my routine OK).  It sometimes reports the page fault, and sometimes just
exits without any message.  If no arps go out (I'm controlling them fron a
traffic generator) then no problems.

Here is the output from GDB when my program runs.

gdb iolping.exe
<gdb intro>
(gdb) b ARPPacketHandler
Breakpoint 1 at 0x1553: file iolping.c, line 29
(gdb) r
Starting program ...
<my printfs>
Breakpoint 1, ARPPacketHandler() at iolping.c:39

Page Fault cr2=1018b000 in RMCB at eip=ae5dd flags=3202
eax=2 ebx=27a2 ecx=9e8 edx=0 esi=13b20 edi=18b000
ebp=11fa84 esp=11da74 es=a7 ds=bf es=af fs=cf gs=bf ss=af error=0006

----------------------------------------------------------------------

So, its hitting my breakpoint and then crashing and dumping me back to a dos
prompt.

The abridged version of my code is below, it should have all of the relevant
stuff.

Thanks in advance for any help

Andy

My work email is subscribed to the news group, and I would prefer responses to
that address
(andrewc AT rosemail DOT rose DOT hp DOT com) over this CServe one which I check infrequently.

---------------------------------------------------------------------------------
--------

#include <crt0.h>
int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;

ubyte localMac[6],dutMac[6];

int segInfo;
__dpmi_raddr vectorSegInfo, arpSeg, ipSeg;
int dosSelector;
/* real mode callback stuff */
__dpmi_regs regs, arpRegs, ipRegs;

byte2 dosLinearAddr;

boolean init_packet_driver(void);
void packet_driver_transmit(byte *packet, byte2 length);
void packet_driver_print_error(ubyte errorNum);
void shutdown_packet_driver(void);


void
ARPPacketHandler(void)
{
  arpInterruptCount++;
  if (arpRegs.x.ax == 0) {
      arpRegs.x.es = segInfo; 
      arpRegs.x.di = 200; 
  } else {
      /* notify ARP that a packet came in */
  }
}

boolean
init_packet_driver(void)
{

   byte pktSig[] = PKTDRV_SIGNATURE; /* this is our byte pattern to look for */
   byte pktSigCheck[strlen(pktSig)]; 

   /* now find out where the packet driver is
    * of if it is even installed
    */
   printf("Attempting to Locate a Packet Driver ...\n");

   for (; pktDriverInterrupt<=PKTDRV_INT_MAX; ++pktDriverInterrupt) {
      __dpmi_get_real_mode_interrupt_vector (pktDriverInterrupt,
&vectorSegInfo);
      dosLinearAddr = (vectorSegInfo.segment << 4) + vectorSegInfo.offset16;
      if (dosLinearAddr){
         dosmemget(dosLinearAddr+3,strlen(pktSig),pktSigCheck);
         if ( ! memcmp( pktSigCheck, pktSig, strlen( pktSig ))){
            break;
         }
      }
   }

   if ( pktDriverInterrupt > PKTDRV_INT_MAX ) {
      printf("Cannot Find Packet Driver between interrupts 0x60 and 0x80\n");
      return FALSE;
   } else {
      printf("Found Packet Driver at 0x%X\n",pktDriverInterrupt);
   }

   printf("Querying Packet Driver for Capabilities...\n");
   regs.x.ax = PKTDRV_DRIVER_INFO;

   __dpmi_int(pktDriverInterrupt, &regs);

   if (regs.x.flags & CARRY_BIT ) {
      printf("Carry bit set after driver query!?\n");
      return FALSE;
   } else {
      pktDrvType = regs.x.dx;
      switch ( pktDrvDeviceClass = (regs.x.cx >> 8))
      {
        case PKTDRV_CLASS_ETHER :
           macHeader = 14;
           break;
        default       :
           printf("Only ETHERNET is supported for now\n");
           printf("Your type = %d\n",pktDrvDeviceClass);
           return FALSE;
      }
   }

   /* lets grab 20K */
   segInfo = __dpmi_allocate_dos_memory((20000+15)>>4,&dosSelector);
   printf("Got a segment at 0x%04X\n",segInfo);
   dosLinearAddr = (segInfo << 4);

   /* now install our arp handler */
   if
(__dpmi_allocate_real_mode_callback(&ARPPacketHandler,&arpRegs,&arpSeg)!=0) {
      printf("Couldn't get a realmode callback for ARP Handler\n");
      return FALSE;
   }

   /* ok - now install our routine */
   printf("Installing ARP Packet Handler\n");
   /* put our arp type out in memory */
   dosmemput(&ethertypeARP,2,dosLinearAddr);

   regs.x.ax = PKTDRV_ACCESS_TYPE | pktDrvDeviceClass; /* if_class */
   regs.x.bx = 0xffff; /* if_type */
   regs.x.dx = 0; /* if_number */
   /* ds:si pointer to ethertype */
   regs.x.ds = segInfo;
   regs.x.si = 0;
   regs.x.cx = 2; /* typelen */
   /* es:di - pointer to our function */
   regs.x.es = arpSeg.segment;
   regs.x.di = arpSeg.offset16;
   
   if (__dpmi_int(pktDriverInterrupt,&regs) != 0) {
      printf("DPMI Int error\n");
      return FALSE;
   }

   if (regs.x.flags & CARRY_BIT ) {
      printf("Carry bit set after attempt to install arp handler!?\n");
      printf("Error 0x%x reported by Packet Driver\n",regs.x.dx >> 8);
      return FALSE;
   } else {
      arpHandle = regs.x.ax;
   }


   printf("Getting Local MAC Address from the Packet Driver\n");
   /* find out our MAC */
   regs.x.ax = PKTDRV_GET_MAC_ADDR;
   regs.x.bx = arpHandle;
   regs.x.es = segInfo;
   regs.x.di = 10;
   regs.x.cx = sizeof(localMac);

   __dpmi_int(pktDriverInterrupt, &regs);
   if ( regs.x.flags & CARRY_BIT )
   {
    __dpmi_free_dos_memory(dosSelector);
    printf("Could not read MAC Address from Packet Driver!\n" );
    return FALSE;
  }


  dosmemget(dosLinearAddr+10,sizeof(localMac),&localMac);

   printf("Our Mac is %02X:%02X:%02X:%02X:%02X:%02X\n",
            localMac[0],localMac[1],localMac[2],
            localMac[3],localMac[4],localMac[5]);
   /* wait for packets */
   sleep(100);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019