hhxxj
驱动牛犊
驱动牛犊
  • 注册日期2001-03-23
  • 最后登录
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2314回复:0

谁用空,帮忙完善一下这个程序?

楼主#
更多 发布于:2001-05-21 10:06
这是一个LAN程序,可是由于并没有调用PACKET32离地函数,所哟并不能获得网卡的任意信息,需要在合适的位置加上,可是我实在看不出来,应该加在哪里,麻烦大家帮帮忙!
源程序如下:

/*
 * $Log: /OEM Source Code/LAN/vlandrvr.c $
 *
 * 1     2/12/98 9:14p Release Engineer
 * code cleanup, code style changes, linted, system level test
 * lan driver v0.0.1
 */
/************************************************************************/
/*
** $Workfile: vlandrvr.c $
** $Revision: 1 $
** $Modtime: 2/12/98 3:11p $
** $Author: Release Engineer $
*/

/************************************************************************/
/* Copyright (C) 1996-1998 RouterWare, Inc.    
*/
/* Unpublished - rights reserved under the Copyright Laws of the */
/* United States.  Use, duplication, or disclosure by the
*/
/* Government is subject to restrictions as set forth in
*/
/* subparagraph (c)(1)(ii) of the Rights in Technical Data and */
/* Computer Software clause at 252.227-7013.            
*/
/* RouterWare, Inc., 3961 MacArthur Suite 212 Newport Beach, CA 92660 */
/************************************************************************/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <kstart.h>
#include "vlandrvr.h"
#include <v8022str.h>
#include <lslproto.h>
#include <vnvrmstr.h>
#include <rwarebuf.h>

static void add_buffer_to_lan_controller_rx_list (USHORT lan_port_number,void *vptr_buffer);

static enum BOOLEAN get_buffer_from_lan_controller_rx_list (USHORT real_port_number,void
**vptr_buffer,USHORT *usptr_number_of_bytes_rxed);

static void check_and_add_more_buffers_to_lan_controller_rx_list (USHORT real_port_number);

enum TEST initialize_lan_driver (ULONG clock_ticks_per_second) { USHORT
real_port_number; USHORT lan_port_number; USHORT number_of_buffers; USHORT
number_of_buffers_per_port; void   *vptr_buffer; enum TEST   return_code;

PARAMETER_NOT_USED (clock_ticks_per_second);


    lan_deiver.enabled = TRUE;
lan_driver.number_of_ports = (USHORT) (lsl_control (GET_NUMBER_OF_LAN_PORTS));

/*
* LSL will assign port numbers sequentially based upon order of registration and thus
LAN ports will be numbered zero
* through "number_of_lan_ports - 1" because we assume that LAN ports are registered
before serial ports.
*/

for (lan_port_number = 0x0000; lan_port_number < lan_driver.number_of_lan_ports;
++lan_port_number)
{

real_port_number = lan_port_number;

if (lsl_control (REGISTER_HIGH_LEVEL_DEVICE_DRIVER,"LAN
Driver",ETHERNET_DEVICE_DRIVER,
lan_driver_tx,lan_driver_tx_completion,lan_driver_rx,NULL,lan_driver_control,lan_driver_buffer_r
eturn,&lan_driver.port[lan_port_number].lsl_device_driver_id,NULL) == FAIL)
{
return (FAIL);
}

/* Get the number of buffers LSL has available for the port associated with the
Device Driver ID */

lan_deiver.port[lan_port_number].allowed_packet_number = lsl_control
(GET_CURRENT_RX_BUFFER_LIST_SIZE,lan_driver.port[lan_port_number].lsl_device_driver_id);

/* Allocate all of the buffers created (by the LSL) for each port to their
respective LAN controller port(s) */

        initialze_packet_link(lan_port_number);

//for (number_of_buffers = 0x0000; number_of_buffers <
number_of_buffers_per_port; ++number_of_buffers)
// {
// vptr_buffer = device_driver_malloc
(real_port_number,lan_driver.port[lan_port_number].lsl_device_driver_id,0x0000);
        //
// if (vptr_buffer != NULL)
// {
// add_buffer_to_lan_controller_rx_list
(lan_port_number,vptr_buffer);
// }
// }
}

    printf("lan initialized!\n");
return (PASS);
}


void initialize_packet_link(USHORT port_number)
{
lsl_driver.port[port_number].packet_link = NULL;
  
return;
}

/* lan driver send routing */

enum TEST lan_driver_tx (ULONG protocol_stack_id,USHORT real_port_number,USHORT
protocol_stack_virtual_port_number,void *sptr_tx_buffer,USHORT number_of_bytes,enum BOOLEAN
do_not_calculate_new_crc,enum BOOLEAN device_driver_buffer,void (*fptr_tx_completion) (USHORT
port_number,void *sptr_ethernet_buffer))
{

USHORT     lan_port_number;
enum TEST  return_code;
void       buffer[MAX_FRAME_LENGTH];
    int        port_number;

    // First,driver must find the adapter structure according to the real port number  
    for (port_number = 0;port_number < MAX_LAN_INTERFACE; port_number++)
if ( adapter_bind[port_number].lsl_real_port_number == real_port_number )
break;
  
  
    if ( port_number >= MAX_LAN_INTERFACE )
{
printf("error,interface %d not exist\n",real_port_number);
return FAIL;
}

    memcpy(buffer, sptr_tx_buffer,number_of_bytes);


    lan_driver_tx_completion(USHORT real_port_number,void *sptr_tx_buffer,USHORT
number_of_bytes,enum BOOLEAN device_driver_buffer,void (*fptr_tx_completion) (USHORT
port_number,void *sptr_ethernet_buffer));

Ne2000Send(adapter_bind[port_number].adapter,buffer, number_of_bytes);

/*
* Queue up the buffer for transmission.  Note that the value of device_driver_buffer
flag, the protocol stack virtual
* port, and the Tx completion function pointer need to be preserved on the transmit
queue to permit returning the buffer
*/

//return_code = add_buffer_to_lan_controller_tx_list
(lan_port_number,sptr_tx_buffer,device_driver_buffer,protocol_stack_virtual_port,fptr_tx_complet
ion);

return (PASS);
}

void lan_driver_tx_completion(USHORT real_port_number,void *sptr_tx_buffer,USHORT
number_of_bytes,enum BOOLEAN device_driver_buffer,void (*fptr_tx_completion) (USHORT
port_number,void *sptr_ethernet_buffer))
{
//USHORT lan_port_number;
//USHORT protocol_stack_virtual_port_number;
//void *vptr_txed_buffer;



//lan_port_number = real_port_number;

/* Collect a used (i.e. already transmitted) buffer from the transmitter list */

//remove_a_transmitted_buffer_from_lan_controller_tx_list
(lan_port_number,&protocol_stack_virtual_port_number,&vptr_txed_buffer,&device_driver_buffer,fpt
r_tx_completion);

/* Return device driver buffer back to the LSL port from where it came so that it can be
re-allocated by that receiver. */

if (device_driver_buffer == TRUE)
{
packet_forward_device_driver_free
(real_port_number,lan_driver.port[real_port_number].lsl_device_driver_id,vptr_txed_buffer);
}
else
{
if (fptr_tx_completion != NULL)
{
(*fptr_tx_completion)
(protocol_stack_virtual_port_number,vptr_txed_buffer);
}

}

    return ;

}

enum BOOLEAN lan_driver_rx (USHORT real_port_number,void **sptr_buffer_rxed,USHORT
*usptr_number_of_bytes_rxed)
{
USHORT lan_port_number;
void *vptr_buffer;
enum TEST return_code;

/*
* Get a buffer from the LAN controller.  The receive buffer shall be removed from the
LAN controller's receive
* buffer list as a result of getting the buffer.
*/

lan_port_number = real_port_number;
  
return_code = get_buffer_from_lan_controller_rx_list
(real_port_number,&vptr_buffer,&usptr_number_of_bytes_rxed);

    //vptr_buffer = device_driver_malloc
(real_port_number,lan_driver.port[lan_port_number].lsl_device_driver_id,0x0000);

if (return_code == TRUE)
{
*sptr_buffer_rxed = vptr_buffer;
*usptr_number_of_bytes_rxed = number_of_bytes_received;
}
 
/*
* Check if the LAN controller's receive buffer list needs to be replenished.  While
checking the receive buffer list
* every time the LAN driver receive function is called wastes CPU time, it does ensure
that LAN controller doesn't unexpectedly
* run out of buffers.  How many buffers to add to the LAN controller receive list is
left to the implementor.
*/

//check_and_add_more_buffers_to_lan_controller_rx_list (real_port_number);

return (return_code);
}


enum TEST lan_driver_control (enum DEVICE_CONTROL_OPERATION command,ULONG parameter_0,ULONG
parameter_1)
{
switch (command)
{
case OPEN_DEVICE_DRIVER:
//start_all_lan_controllers (...);
break;
case STACK_HAS_REGISTERED:
break;
case CLOSE_DEVICE_DRIVER:
close_lan_driver ();
break;
case OPEN_DEVICE_DRIVER_PORT:
//start_lan_controller_port (...);
break;
case CLOSE_DEVICE_DRIVER_PORT:
   //stop_lan_controller_port (...);
break;
case DEVICE_QUERY:
break;
case GET_DEVICE_MAC_ADDRESS:
//read_lan_address_PROM (...);
break;
}

return (PASS);
}

static void close_lan_driver (void)
{
USHORT lan_port_number;

/* Sequence through all LAN ports, see if they were registered into the LSL by checking
the
* device driver ID (it will be non-zero if it is registered).  Once deregistered, clear
the ID
* and shut down the LAN controller hardware
*/

for (lan_port_number = 0x0000; lan_port_number < lan_driver.number_of_ports;
++lan_port_number)
{
if (lan_driver.port[lan_port_number].lsl_device_driver_id != 0x00000000L)
{
lsl_control ((ULONG) DEREGISTER_HIGH_LEVEL_DEVICE_DRIVER,(ULONG)
DATA_LINK_LAYER_TYPE,lan_driver.port[lan_port_number].lsl_device_driver_id);

lan_driver.port[lan_port_number].lsl_device_driver_id = 0x00000000L;
}

// stop_and_clean_up_lan_controllers ();
}
}

void lan_driver_buffer_return (USHORT real_port_number,void *vptr_buffer)
{

USHORT lan_port_number;

lan_port_number = real_port_number;

/*
* Buffers are returned via this function call (primarily) because there were no modules
that wanted the packets
* contained within the buffer.  The safe action to take is to return the buffer to LSL
so that any elements of the
* LSL buffer header that were modified as this buffer was process can be reset to the
proper settings.

* More advanced systems, in theory, could account for these issues and place this buffer
directly onto the LAN
* controller's receive buffer list.
*/

device_driver_free
(real_port_number,lan_driver.port[lan_port_number].lsl_device_driver_id,vptr_buffer);
}


/*  This function will add device driver buffer to lan controller rx list

    added by zeng yongjun

*/
/*
void add_buffer_to_lan_controller_rx_list (USHORT lan_port_number,void *vptr_buffer)
{
    PACKET_LINK            *packet_linked;
    PACKET_LINK            *pint;
packet_linked =  (PACKET_LINK *) rwos_malloc (sizeof (PACKET_LINK));

pint = lan_driver.port[lan_port_number].packet_link;

return;
}
*/

enum BOOLEAN get_buffer_from_lan_controller_rx_list
(real_port_number,&vptr_buffer,&usptr_number_of_bytes_rxed)
{
        void   *vptr_packet;
     USHORT length;
      
vptr_packet = NULL;

if ((lan_driver.port[real_port_number].packet_link != NULL) &&
(lan_driver.port[real_port_number].packet_link->packet_link_forward != NULL))
{
vptr_packet =
lan_driver.port[real_port_number].packet_link->packet_link_forward;

            lan_driver.port[real_port_number].packet_link->packet_link_forward =
vptr_packet->packet_link_forward;
        
vptr_packet->packet_link_forward = NULL;

}
else
{
return FALSE;
}

length = vptr_packet->packet_length;

        usptr_number_of_bytes = length;

*vptr_buffer = vptr_packet->vptr_mac_pdu;

return TRUE;
}


/* Binding  the port and adapter */

void  port_and_adapter_binding(void)
{
int        number_of_ports;
    int        i,j;
int        compare_result;
  
number_of_ports = lan_driver.number_of_ports;

    for (i = 0; i < number_of_ports ; i++)
{
adapter = NewDriver.adapterqueue

        while (adapter != NULL)
{

 if ((compare_result =
strcmp(lsl.lsl_port.rfc1213_ifEntry.ifPhysAddress,adapter.PermanentAddress)) == 0)
 break;
 adapter = adapter->NextAdapter;

}

        if (adapter == NULL)
{
printf("error,adapter no exist\n");
   return;
}

       adapter_bind.adapter = adapter;
  adapter_bind.lsl_real_port_number = i;
  (char *)adapter_bind.mac_address  = adapter.PermanentAddress;

}

    return ;
}




/* Ne2000 driver call this function to write the received packet into LSL device driver buffer
*/

void write_packet_to_lsl_rx_list(PNE2000_ADAPTER adapter,void *adapter->Lookahead,ULONG
IndicateLen)
{  
void          *vtptr_buffer;
void          *pinter_forward,*pointer_form;
INT           port_number;
int           i;


for (i= 0 ; i < MAX_LAN_INTERFACE ; i++)
{
if ( adapter_bind.adapter  == adapter )
{
break;
}
}

if ( i >= MAX_LAN_INTERFACE )
{
printf("error,adapter no binding\n");
return ;
}

port_number = i;


vptr_buffer = device_driver_malloc
(real_port_number,lan_driver.port[port_number].lsl_device_driver_id,0x0000);
  
    strcpy(vptr_buffer,adapter->Lookahead,IndicateLen);

    pointer_forward = pointer_form = lan_driver.port[port_number].packet_link;

if (pointer_forward == NULL)
{
pointer_forward = (PACKET_LINK *)malloc(sizeof(PACKET_LINK));

pointer_forward->packet_link_forward = NULL;

        pointer_forward->packet_link_backward = NULL;

        pointer_forward.vptr_mac_pdu =  vptr_buffer;

pointer_forward.packet_length = IndicateLen;
}
else
{
while ( pointer_forward != NULL)
{
pointer_form = pointer_forward;

pointer_forward  =  pointer_forward->packet_link_forward;
}

pointer_forward = (PACKET_LINK *)malloc(sizeof(PACKET_LINK));

pointer_forward->packet_link_forward = NULL;

        pointer_forward->packet_link_backward = pointer_form;

        pointer_forward.vptr_mac_pdu =  vptr_buffer;

pointer_forward.packet_length = IndicateLen;

pointer_form->packet_link_forward = pointer_forward;
}

return ;
}


最新喜欢:

wingmanwingma...
游客

返回顶部