网络安全参考 | UNIX参考 | GPS参考 | 无线参考 | 在线手册 | OSBUG.ORG | SUNNY-NETWORK.COM
天线制作 GPS 地标
网站地图 RSS订阅
高级搜索 收藏本站
Home | 业界动态 | Open source | GNU | Linux | BSD | Solaris | AIX | HP-UX | IRIX | Mac OS X | Minix | Tru64 | SCO UNIX | Network | Security | X-Window | Database | 应用服务 | Programming | 经典著作 | 永远的纪念 | 杂项
 当前位置: Home > Linux > 设备驱动 > 文章  
Linux设备驱动编程之复杂设备驱动
文章来源: 天极开发 文章作者: 宋宝华 发布时间: 2006-11-01   字体: [ ]  
 

  而发送报文则分为两个层次,一个层次是内核调用,一个层次完成真正的硬件上的发送:

/*
* Transmit a packet (called by the kernel)
*/
int snull_tx(struct sk_buff *skb, struct net_device *dev)
{
 int len;
 char *data;
 struct snull_priv *priv = (struct snull_priv *) dev->priv;

 #ifndef LINUX_24
 if (dev->tbusy || skb == NULL) {
  PDEBUG("tint for %p, tbusy %ld, skb %p\n", dev, dev->tbusy, skb);
  snull_tx_timeout (dev);
  if (skb == NULL)
   return 0;
 }
 #endif

 len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
 data = skb->data;
 dev->trans_start = jiffies; /* save the timestamp */

 /* Remember the skb, so we can free it at interrupt time */
 priv->skb = skb;

 /* actual deliver of data is device-specific, and not shown here */
 snull_hw_tx(data, len, dev);

 return 0; /* Our simple device can not fail */
}

/*
* Transmit a packet (low level interface)
*/
void snull_hw_tx(char *buf, int len, struct net_device *dev)
{
 /*
 * This function deals with hw details. This interface loops
 * back the packet to the other snull interface (if any).
 * In other words, this function implements the snull behaviour,
 * while all other procedures are rather device-independent
 */
 struct iphdr *ih;
 struct net_device *dest;
 struct snull_priv *priv;
 u32 *saddr, *daddr;

 /* I am paranoid. Ain't I? */
 if (len < sizeof(struct ethhdr) + sizeof(struct iphdr)) {
  printk("snull: Hmm... packet too short (%i octets)\n",len);
  return;
 }

 if (0) { /* enable this conditional to look at the data */
  int i;
  PDEBUG("len is %i\n" KERN_DEBUG "data:",len);
  for (i=14 ; i<len; i++)
   printk(" %02x",buf[i]&0xff);
   printk("\n");
 }

 /*
 * Ethhdr is 14 bytes, but the kernel arranges for iphdr
 * to be aligned (i.e., ethhdr is unaligned)
 */
 ih = (struct iphdr *)(buf+sizeof(struct ethhdr));
 saddr = &ih->saddr;
 daddr = &ih->daddr;

 ((u8 *)saddr)[2] ^= 1; /* change the third octet (class C) */
 ((u8 *)daddr)[2] ^= 1;

 ih->check = 0; /* and rebuild the checksum (ip needs it) */
 ih->check = ip_fast_csum((unsigned char *)ih,ih->ihl);

 if (dev == snull_devs)
  PDEBUGG("%08x:%05i --> %08x:%05i\n",ntohl(ih->saddr),ntohs(((struct tcphdr *)(ih+1))->source),ntohl(ih->daddr),ntohs(((struct tcphdr *)(ih+1))->dest));

 
推荐文章
·让arm-linux支持普通USB摄像头
·Linux设备驱动编程之结构化设备
·深入浅出Linux设备驱动之并发控
·深入浅出Linux设备驱动之字符设
·深入浅出Linux设备驱动编程之内
·深入浅出Linux设备驱动编程之引
·Linux设备驱动编程之定时器
·Linux设备驱动编程之中断处理
·Linux设备驱动编程之异步通知
·Linux设备驱动编程之阻塞与非阻
·Linux设备驱动编程之内存与I/O操
·摄像头(WebCam)在Linux操作系
·中星微芯片(301,302)USB 摄像头
·Linux的I2C驱动架构
 
 
↑返回顶部   打印本页   关闭窗口↓  

Google
 
Web oldhand.org unixreference.net meshmea.org
相关分类
热点文章
·摄像头(WebCam)在Linu
·在Linux中使用中星微301
·中星微芯片(301,302)USB
·Linux设备驱动编程之内
·深入浅出Linux设备驱动
·Linux培训园地:Linux下
·Linux的I2C驱动架构
·让arm-linux支持普通USB
相关文章
·Linux设备驱动编程之结
·Qt/Embedded在嵌入式Lin
·如何编写Linux操作系统
·深入浅出Linux设备驱动
·深入浅出分析Linux设备
·Linux培训园地:Linux下
·深入浅出Linux设备驱动
·Linux培训园地:Linux下
更多...
 
 

Copyright(c) 2001-2009 OLDHAND ORGANIZATION, All Rights reserved.
Power by DedeCms 织梦内容管理系统