亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? 6pack.c

?? linux嵌入式課程實踐中的一個關于聲卡驅動程序 。
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* * 6pack.c	This module implements the 6pack protocol for kernel-based *		devices like TTY. It interfaces between a raw TTY and the *		kernel's AX.25 protocol layers. * * Version:	@(#)6pack.c	0.3.0	04/07/98 * * Authors:	Andreas K鰊sgen <ajk@iehk.rwth-aachen.de> * * Quite a lot of stuff "stolen" by J鰎g Reuter from slip.c, written by * *		Laurence Culhane, <loz@holmes.demon.co.uk> *		Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * */#include <linux/config.h>#include <linux/module.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/bitops.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/interrupt.h>#include <linux/in.h>#include <linux/tty.h>#include <linux/errno.h>#include <linux/netdevice.h>#include <linux/timer.h>#include <net/ax25.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/rtnetlink.h>#include <linux/if_arp.h>#include <linux/init.h>#include <linux/ip.h>#include <linux/tcp.h>#define SIXPACK_VERSION    "Revision: 0.3.0"/* sixpack priority commands */#define SIXP_SEOF	0x40	/* start and end of a 6pack frame */#define SIXP_TX_URUN	0x48	/* transmit overrun */#define SIXP_RX_ORUN	0x50	/* receive overrun */#define SIXP_RX_BUF_OVL	0x58	/* receive buffer overflow */#define SIXP_CHKSUM	0xFF	/* valid checksum of a 6pack frame *//* masks to get certain bits out of the status bytes sent by the TNC */#define SIXP_CMD_MASK		0xC0#define SIXP_CHN_MASK		0x07#define SIXP_PRIO_CMD_MASK	0x80#define SIXP_STD_CMD_MASK	0x40#define SIXP_PRIO_DATA_MASK	0x38#define SIXP_TX_MASK		0x20#define SIXP_RX_MASK		0x10#define SIXP_RX_DCD_MASK	0x18#define SIXP_LEDS_ON		0x78#define SIXP_LEDS_OFF		0x60#define SIXP_CON		0x08#define SIXP_STA		0x10#define SIXP_FOUND_TNC		0xe9#define SIXP_CON_ON		0x68#define SIXP_DCD_MASK		0x08#define SIXP_DAMA_OFF		0/* default level 2 parameters */#define SIXP_TXDELAY			25	/* in 10 ms */#define SIXP_PERSIST			50	/* in 256ths */#define SIXP_SLOTTIME			10	/* in 10 ms */#define SIXP_INIT_RESYNC_TIMEOUT	150	/* in 10 ms */#define SIXP_RESYNC_TIMEOUT		500	/* in 10 ms *//* 6pack configuration. */#define SIXP_NRUNIT			31      /* MAX number of 6pack channels */#define SIXP_MTU			256	/* Default MTU */enum sixpack_flags {	SIXPF_INUSE,	/* Channel in use	*/	SIXPF_ERROR,	/* Parity, etc. error	*/};struct sixpack {	int			magic;	/* Various fields. */	struct tty_struct	*tty;		/* ptr to TTY structure		*/	struct net_device	*dev;		/* easy for intr handling	*/	/* These are pointers to the malloc()ed frame buffers. */	unsigned char		*rbuff;		/* receiver buffer		*/	int			rcount;         /* received chars counter       */	unsigned char		*xbuff;		/* transmitter buffer		*/	unsigned char		*xhead;         /* pointer to next byte to XMIT */	int			xleft;          /* bytes left in XMIT queue     */	unsigned char		raw_buf[4];	unsigned char		cooked_buf[400];	unsigned int		rx_count;	unsigned int		rx_count_cooked;	/* 6pack interface statistics. */	struct net_device_stats stats;	int			mtu;		/* Our mtu (to spot changes!)   */	int			buffsize;       /* Max buffers sizes            */	unsigned long		flags;		/* Flag values/ mode etc	*/	unsigned char		mode;		/* 6pack mode			*/	/* 6pack stuff */	unsigned char		tx_delay;	unsigned char		persistance;	unsigned char		slottime;	unsigned char		duplex;	unsigned char		led_state;	unsigned char		status;	unsigned char		status1;	unsigned char		status2;	unsigned char		tx_enable;	unsigned char		tnc_ok;	struct timer_list	tx_t;	struct timer_list	resync_t;};#define AX25_6PACK_HEADER_LEN 0#define SIXPACK_MAGIC 0x5304typedef struct sixpack_ctrl {	struct sixpack	ctrl;			/* 6pack things			*/	struct net_device	dev;		/* the device			*/} sixpack_ctrl_t;static sixpack_ctrl_t **sixpack_ctrls;int sixpack_maxdev = SIXP_NRUNIT;	/* Can be overridden with insmod! */MODULE_PARM(sixpack_maxdev, "i");MODULE_PARM_DESC(sixpack_maxdev, "number of 6PACK devices");static void sp_start_tx_timer(struct sixpack *);static void sp_xmit_on_air(unsigned long);static void resync_tnc(unsigned long);static void sixpack_decode(struct sixpack *, unsigned char[], int);static int encode_sixpack(unsigned char *, unsigned char *, int, unsigned char);static int sixpack_init(struct net_device *dev);static void decode_prio_command(unsigned char, struct sixpack *);static void decode_std_command(unsigned char, struct sixpack *);static void decode_data(unsigned char, struct sixpack *);static int tnc_init(struct sixpack *);/* Find a free 6pack channel, and link in this `tty' line. */static inline struct sixpack *sp_alloc(void){	sixpack_ctrl_t *spp = NULL;	int i;	for (i = 0; i < sixpack_maxdev; i++) {		spp = sixpack_ctrls[i];		if (spp == NULL)			break;		if (!test_and_set_bit(SIXPF_INUSE, &spp->ctrl.flags))			break;	}	/* Too many devices... */	if (i >= sixpack_maxdev)		return NULL;	/* If no channels are available, allocate one */	if (!spp &&	    (sixpack_ctrls[i] = (sixpack_ctrl_t *)kmalloc(sizeof(sixpack_ctrl_t),						    GFP_KERNEL)) != NULL) {		spp = sixpack_ctrls[i];		memset(spp, 0, sizeof(sixpack_ctrl_t));		/* Initialize channel control data */		set_bit(SIXPF_INUSE, &spp->ctrl.flags);		spp->ctrl.tty         = NULL;		sprintf(spp->dev.name, "sp%d", i);		spp->dev.base_addr    = i;		spp->dev.priv         = (void *) &spp->ctrl;		spp->dev.next         = NULL;		spp->dev.init         = sixpack_init;	}	if (spp != NULL) {		/* register device so that it can be ifconfig'ed       */		/* sixpack_init() will be called as a side-effect         */		/* SIDE-EFFECT WARNING: sixpack_init() CLEARS spp->ctrl ! */		if (register_netdev(&spp->dev) == 0) {			set_bit(SIXPF_INUSE, &spp->ctrl.flags);			spp->ctrl.dev = &spp->dev;			spp->dev.priv = (void *) &spp->ctrl;			SET_MODULE_OWNER(&spp->dev);			return &spp->ctrl;		} else {			clear_bit(SIXPF_INUSE, &spp->ctrl.flags);			printk(KERN_WARNING "sp_alloc() - register_netdev() failure.\n");		}	}	return NULL;}/* Free a 6pack channel. */static inline void sp_free(struct sixpack *sp){	/* Free all 6pack frame buffers. */	if (sp->rbuff)		kfree(sp->rbuff);	sp->rbuff = NULL;	if (sp->xbuff)		kfree(sp->xbuff);	sp->xbuff = NULL;	if (!test_and_clear_bit(SIXPF_INUSE, &sp->flags))		printk(KERN_WARNING "%s: sp_free for already free unit.\n", sp->dev->name);}/* Send one completely decapsulated IP datagram to the IP layer. *//* This is the routine that sends the received data to the kernel AX.25.   'cmd' is the KISS command. For AX.25 data, it is zero. */static void sp_bump(struct sixpack *sp, char cmd){	struct sk_buff *skb;	int count;	unsigned char *ptr;	count = sp->rcount+1;	sp->stats.rx_bytes += count;	if ((skb = dev_alloc_skb(count)) == NULL) {		printk(KERN_DEBUG "%s: memory squeeze, dropping packet.\n", sp->dev->name);		sp->stats.rx_dropped++;		return;	}	skb->dev = sp->dev;	ptr = skb_put(skb, count);	*ptr++ = cmd;	/* KISS command */	memcpy(ptr, (sp->cooked_buf)+1, count);	skb->mac.raw = skb->data;	skb->protocol = htons(ETH_P_AX25);	netif_rx(skb);	sp->stats.rx_packets++;}/* ----------------------------------------------------------------------- *//* Encapsulate one AX.25 frame and stuff into a TTY queue. */static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len){	unsigned char *p;	int actual, count;	if (len > sp->mtu) {	/* sp->mtu = AX25_MTU = max. PACLEN = 256 */		printk(KERN_DEBUG "%s: truncating oversized transmit packet!\n", sp->dev->name);		sp->stats.tx_dropped++;		netif_start_queue(sp->dev);		return;	}	p = icp;	if (p[0] > 5) {		printk(KERN_DEBUG "%s: invalid KISS command -- dropped\n", sp->dev->name);		netif_start_queue(sp->dev);		return;	}	if ((p[0] != 0) && (len > 2)) {		printk(KERN_DEBUG "%s: KISS control packet too long -- dropped\n", sp->dev->name);		netif_start_queue(sp->dev);		return;	}	if ((p[0] == 0) && (len < 15)) {		printk(KERN_DEBUG "%s: bad AX.25 packet to transmit -- dropped\n", sp->dev->name);		netif_start_queue(sp->dev);		sp->stats.tx_dropped++;		return;	}	count = encode_sixpack(p, (unsigned char *) sp->xbuff, len, sp->tx_delay);	sp->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);	switch (p[0]) {		case 1:	sp->tx_delay = p[1];		return;		case 2:	sp->persistance = p[1];		return;		case 3: sp->slottime = p[1];		return;		case 4: /* ignored */			return;		case 5: sp->duplex = p[1];		return;	}	if (p[0] == 0) {		/* in case of fullduplex or DAMA operation, we don't take care		   about the state of the DCD or of any timers, as the determination		   of the correct time to send is the job of the AX.25 layer. We send		   immediately after data has arrived. */		if (sp->duplex == 1) {			sp->led_state = 0x70;			sp->tty->driver.write(sp->tty, 0, &sp->led_state, 1);			sp->tx_enable = 1;			actual = sp->tty->driver.write(sp->tty, 0, sp->xbuff, count);			sp->xleft = count - actual;			sp->xhead = sp->xbuff + actual;			sp->led_state = 0x60;			sp->tty->driver.write(sp->tty, 0, &sp->led_state, 1);		} else {			sp->xleft = count;			sp->xhead = sp->xbuff;			sp->status2 = count;			if (sp->duplex == 0)				sp_start_tx_timer(sp);		}	}}/* * Called by the TTY driver when there's room for more data.  If we have * more packets to send, we send them here. */static void sixpack_write_wakeup(struct tty_struct *tty){	int actual;	struct sixpack *sp = (struct sixpack *) tty->disc_data;	/* First make sure we're connected. */	if (!sp || sp->magic != SIXPACK_MAGIC ||	    !netif_running(sp->dev))		return;	if (sp->xleft <= 0)  {		/* Now serial buffer is almost free & we can start		 * transmission of another packet */		sp->stats.tx_packets++;		tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);		sp->tx_enable = 0;		netif_wake_queue(sp->dev);		return;	}	if (sp->tx_enable == 1) {		actual = tty->driver.write(tty, 0, sp->xhead, sp->xleft);		sp->xleft -= actual;		sp->xhead += actual;	}}/* ----------------------------------------------------------------------- *//* Encapsulate an IP datagram and kick it into a TTY queue. */static int sp_xmit(struct sk_buff *skb, struct net_device *dev){	struct sixpack *sp = (struct sixpack *) dev->priv;	/* We were not busy, so we are now... :-) */	netif_stop_queue(dev);	sp->stats.tx_bytes += skb->len;	sp_encaps(sp, skb->data, skb->len);	dev_kfree_skb(skb);	return 0;}/* perform the persistence/slottime algorithm for CSMA access. If the persistence   check was successful, write the data to the serial driver. Note that in case   of DAMA operation, the data is not sent here. */static void sp_xmit_on_air(unsigned long channel){	struct sixpack *sp = (struct sixpack *) channel;	int actual;	static unsigned char random;	random = random * 17 + 41;	if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistance)) {		sp->led_state = 0x70;		sp->tty->driver.write(sp->tty, 0, &sp->led_state, 1);		sp->tx_enable = 1;		actual = sp->tty->driver.write(sp->tty, 0, sp->xbuff, sp->status2);		sp->xleft -= actual;		sp->xhead += actual;		sp->led_state = 0x60;		sp->tty->driver.write(sp->tty, 0, &sp->led_state, 1);		sp->status2 = 0;	} else		sp_start_tx_timer(sp);}/* Return the frame type ID */static int sp_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,	  void *daddr, void *saddr, unsigned len){#ifdef CONFIG_INET	if (type != htons(ETH_P_AX25))		return ax25_encapsulate(skb, dev, type, daddr, saddr, len);#endif	return 0;}static int sp_rebuild_header(struct sk_buff *skb){#ifdef CONFIG_INET	return ax25_rebuild_header(skb);#else	return 0;#endif}/* Open the low-level part of the 6pack channel. */static int sp_open(struct net_device *dev){	struct sixpack *sp = (struct sixpack *) dev->priv;	unsigned long len;	if (sp->tty == NULL)		return -ENODEV;	/*	 * Allocate the 6pack frame buffers:	 *	 * rbuff	Receive buffer.	 * xbuff	Transmit buffer.	 */	/* !!! length of the buffers. MTU is IP MTU, not PACLEN!	 */	len = dev->mtu * 2;	if ((sp->rbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL)		return -ENOMEM;	if ((sp->xbuff = kmalloc(len + 4, GFP_KERNEL)) == NULL) {		kfree(sp->rbuff);		return -ENOMEM;	}	sp->mtu	     = AX25_MTU + 73;	sp->buffsize = len;	sp->rcount   = 0;	sp->rx_count = 0;	sp->rx_count_cooked = 0;	sp->xleft    = 0;	sp->flags   &= (1 << SIXPF_INUSE);      /* Clear ESCAPE & ERROR flags */	sp->duplex = 0;	sp->tx_delay    = SIXP_TXDELAY;	sp->persistance = SIXP_PERSIST;	sp->slottime    = SIXP_SLOTTIME;	sp->led_state   = 0x60;	sp->status      = 1;	sp->status1     = 1;	sp->status2     = 0;	sp->tnc_ok      = 0;	sp->tx_enable   = 0;	netif_start_queue(dev);	init_timer(&sp->tx_t);	init_timer(&sp->resync_t);	return 0;}/* Close the low-level part of the 6pack channel. */static int sp_close(struct net_device *dev){	struct sixpack *sp = (struct sixpack *) dev->priv;	if (sp->tty == NULL)		return -EBUSY;	sp->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);	netif_stop_queue(dev);	return 0;}static int sixpack_receive_room(struct tty_struct *tty){	return 65536;  /* We can handle an infinite amount of data. :-) */}/* !!! receive state machine *//* * Handle the 'receiver data ready' interrupt. * This function is called by the 'tty_io' module in the kernel when * a block of 6pack data has been received, which can now be decapsulated * and sent on to some IP layer for further processing. */static void sixpack_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count){	unsigned char buf[512];	unsigned long flags;	int count1;	struct sixpack *sp = (struct sixpack *) tty->disc_data;	if (!sp || sp->magic != SIXPACK_MAGIC ||	    !netif_running(sp->dev) || !count)		return;	save_flags(flags);	cli();	memcpy(buf, cp, count<sizeof(buf)? count:sizeof(buf));	restore_flags(flags);	/* Read the characters out of the buffer */	count1 = count;	while (count) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品福利一区二区三区| thepron国产精品| 欧美日韩精品三区| 亚洲国产精品久久一线不卡| 欧美亚洲综合另类| 午夜精品福利一区二区三区av| 国产精品区一区二区三区| 国产在线不卡一区| 国产免费久久精品| 一本大道综合伊人精品热热| 亚洲成人一区二区| 欧美精品一区二区三区视频 | 午夜不卡在线视频| 欧美精品丝袜久久久中文字幕| ww亚洲ww在线观看国产| 国产suv精品一区二区6| 亚洲天堂av老司机| 欧美顶级少妇做爰| 国产福利一区二区三区视频在线| 欧美系列一区二区| 日本网站在线观看一区二区三区| 色综合久久久久综合99| 亚洲1区2区3区4区| 久久综合色综合88| 91黄视频在线| 九一九一国产精品| |精品福利一区二区三区| 91成人国产精品| 国产在线精品免费| 亚洲欧美日韩国产中文在线| 日韩欧美亚洲一区二区| 成人精品国产一区二区4080| 天天影视网天天综合色在线播放| 91极品美女在线| 黄色小说综合网站| 亚洲另类色综合网站| 精品国产91亚洲一区二区三区婷婷| 亚洲成av人片一区二区三区| 久久久久久久久久电影| 欧美亚洲综合色| 成人av电影免费观看| 精品中文字幕一区二区| 亚洲最新在线观看| 国产偷v国产偷v亚洲高清| 欧美精品vⅰdeose4hd| 9i在线看片成人免费| 久久99精品国产麻豆不卡| 亚洲综合色成人| 欧美激情一区不卡| 日韩视频一区二区在线观看| 欧美最猛黑人xxxxx猛交| 国产v综合v亚洲欧| 久久国产剧场电影| 天天影视色香欲综合网老头| 依依成人精品视频| 亚洲国产高清不卡| 久久久久久久一区| 欧美一级在线观看| 欧美日韩中文字幕精品| 99久久精品情趣| 国产91精品露脸国语对白| 美腿丝袜亚洲一区| 午夜av电影一区| 亚洲国产日韩精品| 亚洲激情图片qvod| 亚洲人亚洲人成电影网站色| 欧美激情一区不卡| 日本一区二区三区高清不卡| 久久久亚洲国产美女国产盗摄| 成人av动漫在线| 懂色中文一区二区在线播放| 极品少妇xxxx精品少妇| 久久精品国产99国产精品| 日本一道高清亚洲日美韩| 日韩在线卡一卡二| 亚洲国产综合91精品麻豆| 亚洲激情男女视频| 亚洲欧美怡红院| 亚洲日本韩国一区| 亚洲国产裸拍裸体视频在线观看乱了| 精品国产一区久久| 久久这里只精品最新地址| 欧美岛国在线观看| 久久综合久色欧美综合狠狠| 久久先锋资源网| 337p粉嫩大胆色噜噜噜噜亚洲| 91国产成人在线| 精品视频999| 91精品国产色综合久久| 欧美电影精品一区二区| 欧美精品一区二区三区高清aⅴ| 一本久久a久久免费精品不卡| 天天av天天翘天天综合网| 日韩高清不卡一区二区| 免费成人性网站| 激情五月播播久久久精品| 国产黄色精品视频| 91美女片黄在线| 欧美日免费三级在线| 日韩午夜精品电影| 久久久一区二区三区| 亚洲欧洲精品天堂一级| |精品福利一区二区三区| 亚洲福利一区二区三区| 久久99久久99精品免视看婷婷| 亚洲一区二区在线播放相泽| 天堂资源在线中文精品| 国产精品亚洲成人| av动漫一区二区| 欧美一区二区三区视频在线| 久久久久国产精品免费免费搜索| 91精品久久久久久蜜臀| 国产午夜精品在线观看| 夜夜操天天操亚洲| 国产一区二区0| 色婷婷久久久亚洲一区二区三区| 国产成人av在线影院| 在线这里只有精品| 精品国精品自拍自在线| 亚洲国产精品成人综合| 亚洲第一主播视频| 国产乱子轮精品视频| 色88888久久久久久影院按摩 | 丁香婷婷综合激情五月色| 色婷婷综合久久久| 精品国产污污免费网站入口 | 欧美国产激情一区二区三区蜜月| 777a∨成人精品桃花网| 国产视频一区在线播放| 亚洲制服丝袜在线| 国产福利一区二区三区视频 | 亚洲一区在线观看网站| 精品一区二区影视| 一本大道久久a久久精二百| 久久蜜臀中文字幕| 日本成人在线网站| 顶级嫩模精品视频在线看| 欧美日韩国产另类一区| 日韩欧美视频一区| 久久午夜羞羞影院免费观看| 亚洲一区二区在线播放相泽| 成人午夜激情影院| 在线播放亚洲一区| 亚洲另类在线视频| 成人免费看片app下载| 欧美成人性福生活免费看| 亚洲午夜私人影院| av中文字幕亚洲| 国产日韩亚洲欧美综合| 欧美aⅴ一区二区三区视频| 在线视频欧美区| 亚洲视频一区二区在线观看| 国产盗摄视频一区二区三区| 欧美一区二区精品在线| 亚洲一线二线三线久久久| zzijzzij亚洲日本少妇熟睡| 久久精品亚洲国产奇米99| 美腿丝袜亚洲一区| 日韩一区二区电影| 日本va欧美va精品| 日韩一区二区三区四区| 亚洲国产精品视频| 在线视频国产一区| 亚洲欧美日韩中文播放| 99精品在线免费| 1区2区3区精品视频| 成人性生交大片免费| 国产无一区二区| 国产suv精品一区二区883| 国产三级精品在线| 国产91丝袜在线播放0| 欧美国产精品一区| 99久久久精品| 一卡二卡欧美日韩| 欧美偷拍一区二区| 亚洲观看高清完整版在线观看| 免费人成在线不卡| 日韩免费在线观看| 国产乱码字幕精品高清av| 日韩写真欧美这视频| 免费观看在线色综合| 精品少妇一区二区三区在线视频| 亚洲精品老司机| 欧洲精品在线观看| 亚洲五月六月丁香激情| 欧美一区二区二区| 久久91精品国产91久久小草| 精品国精品国产尤物美女| 国产激情一区二区三区四区| 中文字幕中文在线不卡住| 一本色道久久综合精品竹菊| 亚洲mv大片欧洲mv大片精品| 欧美电影免费提供在线观看| 国产一区二区看久久| 日韩一区在线免费观看| 精品1区2区3区| 精品写真视频在线观看| 国产欧美精品国产国产专区| 91激情在线视频| 久草这里只有精品视频|