⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlpidrv.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/dlpidrv.c,v 1.4 2003/01/15 14:04:31 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: dlpidrv.c,v $ * Revision 1.4  2003/01/15 14:04:31  josh * directory structure shifting * * Revision 1.3  2001/11/08 15:56:21  tneale * Updated for newest file layout * * Revision 1.2  2001/11/06 20:11:11  josh * updating include paths to include proper path to layout directory * * Revision 1.1.1.1  2001/11/05 17:48:41  tneale * Tornado shuffle * * Revision 2.8  2001/01/19 22:23:41  paul * Update copyright. * * Revision 2.7  2000/10/20 18:32:25  paul * Properly conditionalized driver.ip_send * * Revision 2.6  2000/10/16 19:21:53  paul * Restore sockets and mempool code. * * Revision 2.5  2000/03/17 00:12:38  meister * Update copyright message * * Revision 2.4  2000/03/13 21:22:04  paul * Removed some code that we are no longer working on. * * Revision 2.3  1999/11/05 22:29:05  paul * Updated driver structs to reflect conditional backwards-compatibility * fields and new fields. * * Revision 2.2  1998/09/14 20:13:43  wes * make DLPI driver filenames 8.3 safe.. * * Revision 2.1  1998/07/29 20:54:52  wes * First cut of the Solaris port. * (DLPI support, termios, minor tweaks to libraries and port header files) * * Revision 1.1.2.1  1998/07/24 21:45:44  wes * Initial implementation * * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*//* * Attache code for interfacing to ethernet via the Data Link Provider Interface * on Solaris.  Some modification will likely be necessary for use on other * platforms.. * * This file contains the Attache driver code for DLPI. */#include <stdio.h>#include <unistd.h>#include <wrn/wm/attache/config.h>#include <wrn/wm/common/types.h>#include <wrn/wm/attache/mib.h>#include <wrn/wm/attache/timer.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/net.h>#include <wrn/wm/attache/ether.h>#include <wrn/wm/attache/arp.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/glue.h>#include <wrn/wm/util/layout/ldbglue.h>#include <wrn/wm/util/layout/arp.h>#include <wrn/wm/demo/dlpi.h>#include <wrn/wm/demo/bsdif.h>#include <wrn/wm/demo/dlpidrv.h>struct dlpi_driver_private {  bits8_t mac[6];		/* MAC address for this interface */};#define	TEN_MEGABITS	10000000/* * Routines to read (struct bsdif) generic network interface. */static void dlpi_driver_rcv  (unsigned char *buffer,   unsigned buflen,   unsigned netlen,   void *cookie){  packet *p;  if (buflen != netlen || (p = pkt_alloc(buflen + 2)) == 0)    return;  MEMCPY((p->pkt_data += 2), buffer, (p->pkt_datalen = buflen));  p->pkt_n = cookie;  et_rcv(p);}static void dlpi_driver_read (int fd, void *cookie, unsigned flags){  struct net *net = cookie;  if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)    (void) dlpi_read(fd, net->driver->maxlen, dlpi_driver_rcv, net);}/* * Attache device driver routines for DLPI. */static void dlpi_driver_init (struct net *net){  /* This prefix is from "obsolete" portion of DEC's space (see RFC-1340). */  static bits8_t bpf_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };  struct bsdif *bif = net->specific;  struct dlpi_driver_private *private;  char *name = net->s_name + STRLEN(net->driver->prefix);  net->flags |= NF_DRIVER_DOWN;  net->speed = TEN_MEGABITS;  if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)    return;  /*   * Pick a MAC address to use.  If there's already one specified,   * use it.  Otherwise, if we're in 2.x backwards compatability mode and have   * an IP address, use it, otherwise try to generate something unique.   */  if (!net->h_address) {    net->ha_len = sizeof(private->mac);    net->h_address = private->mac;    MEMCPY(private->mac+0, bpf_driver_mac_prefix, 3);    if (net->ip_addr) {      MEMCPY(private->mac + 3, ((bits8_t *) &net->ip_addr) + 1, 3);    } else {      pid_t proc = getpid();      bits32_t hostid = gethostid();      private->mac[3] ^= (bits8_t) (proc      & 0xff);      private->mac[4] ^= (bits8_t) (proc >> 8 & 0xff);      private->mac[5] ^= (bits8_t) (hostid    & 0xff);    }  }  if ((bif->fd = dlpi_open(name, net->driver->maxlen, private->mac)) < 0)    return;  bif->handler = dlpi_driver_read;  bif->flags |= BSDIF_READ;  net->flags &= ~NF_DRIVER_DOWN;}static void dlpi_driver_send (struct packet *p){  struct bsdif *bif = p->pkt_n->specific;  /*   * Send the packet, logging any error that might occur.   * If the driver is down, just drop the packet.   */  if ((p->pkt_n->flags & NF_DRIVER_DOWN) == 0 &&       dlpi_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)    perror("DLPI write() failure");  pkt_free(p);}static void dlpi_driver_close (struct net *net){  struct bsdif *bif = net->specific;  if ((net->flags & NF_DRIVER_DOWN) == 0) {    dlpi_close(bif->fd);    net->flags |= NF_DRIVER_DOWN;  }  if (bif->private) {    GLUE_FREE(bif->private);    bif->private = 0;  }}/* * This could be static now, but it might be useful to leave it visible. */struct driver dlpi_driver = {  dlpi_driver_init,		/* Interface initialization routine  */  dlpi_driver_send,		/* Raw packet send routine */#if INSTALL_ATTACHE_34_IPV4_API_COMPAT  et_ip_send,			/* IP packet send encapsulation routine */#else  0,#endif  et_arp_send,			/* ARP packet send encapsulation routine */  0,				/* Test routine (unused) */  dlpi_driver_close,		/* Interface close routine */  "dlpi",			/* Driver short name */  "DLPI Ethernet",		/* Driver long name */  14,				/* Local net header length */  0,				/* Local net trailer length */  1514,				/* Ethernet frame size */  IF_ETHERNET,			/* MIB type of interfaces using this driver */  ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,#if !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL  et_media_ctl,			/* Media control routine, if installed */#else  0,				/* No media_ctl routine */ #endif /* !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL */#if INSTALL_ATTACHE_IPV6  et_ipv6_send,			/* IPv6 send routine, if installed */#else  0,#endif#if INSTALL_ATTACHE_IPV4  et_ipv4_send			/* IPv4 send routine, if installed */#else  0#endif /* INSTALL_ATTACHE_IPV4 */};/* * Routines for finding DLPI interface devices. * This is just a wrapper to add the Attache-specific things onto dlpi_find(). */struct dlpi_driver_find_state {  void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);  int instance;};static void dlpi_driver_find_one(char *name, void *cookie){  struct dlpi_driver_find_state *state = cookie;  state->config(name, &dlpi_driver, state->instance++, NF_ARP,		dlpi_driver.maxlen - dlpi_driver.lnh - dlpi_driver.lnt,		TEN_MEGABITS);}void dlpi_driver_find  (void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t)){  struct dlpi_driver_find_state state;  state.config = config;  state.instance = 0;  dlpi_find(dlpi_driver_find_one, &state);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -