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

📄 irlap.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
		self->mtt_required = min_turn_time;		return;	}	/*	 *  Send additional BOF's for the next frame for the requested	 *  min turn time, so now we must calculate how many chars (XBOF's) we	 *  must send for the requested time period (min turn time)	 */	self->xbofs_delay = irlap_min_turn_time_in_bytes(speed, min_turn_time);}/* * Function irlap_flush_all_queues (void) * *    Flush all queues * */void irlap_flush_all_queues(struct irlap_cb *self){	struct sk_buff* skb;	IRDA_ASSERT(self != NULL, return;);	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);	/* Free transmission queue */	while ((skb = skb_dequeue(&self->txq)) != NULL)		dev_kfree_skb(skb);	while ((skb = skb_dequeue(&self->txq_ultra)) != NULL)		dev_kfree_skb(skb);	/* Free sliding window buffered packets */	while ((skb = skb_dequeue(&self->wx_list)) != NULL)		dev_kfree_skb(skb);}/* * Function irlap_setspeed (self, speed) * *    Change the speed of the IrDA port * */static void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now){	struct sk_buff *skb;	IRDA_DEBUG(0, "%s(), setting speed to %d\n", __FUNCTION__, speed);	IRDA_ASSERT(self != NULL, return;);	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);	self->speed = speed;	/* Change speed now, or just piggyback speed on frames */	if (now) {		/* Send down empty frame to trigger speed change */		skb = alloc_skb(0, GFP_ATOMIC);		if (skb)			irlap_queue_xmit(self, skb);	}}/* * Function irlap_init_qos_capabilities (self, qos) * *    Initialize QoS for this IrLAP session, What we do is to compute the *    intersection of the QoS capabilities for the user, driver and for *    IrLAP itself. Normally, IrLAP will not specify any values, but it can *    be used to restrict certain values. */static void irlap_init_qos_capabilities(struct irlap_cb *self,					struct qos_info *qos_user){	IRDA_ASSERT(self != NULL, return;);	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);	IRDA_ASSERT(self->netdev != NULL, return;);	/* Start out with the maximum QoS support possible */	irda_init_max_qos_capabilies(&self->qos_rx);	/* Apply drivers QoS capabilities */	irda_qos_compute_intersection(&self->qos_rx, self->qos_dev);	/*	 *  Check for user supplied QoS parameters. The service user is only	 *  allowed to supply these values. We check each parameter since the	 *  user may not have set all of them.	 */	if (qos_user) {		IRDA_DEBUG(1, "%s(), Found user specified QoS!\n", __FUNCTION__);		if (qos_user->baud_rate.bits)			self->qos_rx.baud_rate.bits &= qos_user->baud_rate.bits;		if (qos_user->max_turn_time.bits)			self->qos_rx.max_turn_time.bits &= qos_user->max_turn_time.bits;		if (qos_user->data_size.bits)			self->qos_rx.data_size.bits &= qos_user->data_size.bits;		if (qos_user->link_disc_time.bits)			self->qos_rx.link_disc_time.bits &= qos_user->link_disc_time.bits;	}	/* Use 500ms in IrLAP for now */	self->qos_rx.max_turn_time.bits &= 0x01;	/* Set data size */	/*self->qos_rx.data_size.bits &= 0x03;*/	irda_qos_bits_to_value(&self->qos_rx);}/* * Function irlap_apply_default_connection_parameters (void, now) * *    Use the default connection and transmission parameters */void irlap_apply_default_connection_parameters(struct irlap_cb *self){	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);	IRDA_ASSERT(self != NULL, return;);	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);	/* xbofs : Default value in NDM */	self->next_bofs   = 12;	self->bofs_count  = 12;	/* NDM Speed is 9600 */	irlap_change_speed(self, 9600, TRUE);	/* Set mbusy when going to NDM state */	irda_device_set_media_busy(self->netdev, TRUE);	/*	 * Generate random connection address for this session, which must	 * be 7 bits wide and different from 0x00 and 0xfe	 */	while ((self->caddr == 0x00) || (self->caddr == 0xfe)) {		get_random_bytes(&self->caddr, sizeof(self->caddr));		self->caddr &= 0xfe;	}	/* Use default values until connection has been negitiated */	self->slot_timeout = sysctl_slot_timeout;	self->final_timeout = FINAL_TIMEOUT;	self->poll_timeout = POLL_TIMEOUT;	self->wd_timeout = WD_TIMEOUT;	/* Set some default values */	self->qos_tx.baud_rate.value = 9600;	self->qos_rx.baud_rate.value = 9600;	self->qos_tx.max_turn_time.value = 0;	self->qos_rx.max_turn_time.value = 0;	self->qos_tx.min_turn_time.value = 0;	self->qos_rx.min_turn_time.value = 0;	self->qos_tx.data_size.value = 64;	self->qos_rx.data_size.value = 64;	self->qos_tx.window_size.value = 1;	self->qos_rx.window_size.value = 1;	self->qos_tx.additional_bofs.value = 12;	self->qos_rx.additional_bofs.value = 12;	self->qos_tx.link_disc_time.value = 0;	self->qos_rx.link_disc_time.value = 0;	irlap_flush_all_queues(self);	self->disconnect_pending = FALSE;	self->connect_pending = FALSE;}/* * Function irlap_apply_connection_parameters (qos, now) * *    Initialize IrLAP with the negotiated QoS values * * If 'now' is false, the speed and xbofs will be changed after the next * frame is sent. * If 'now' is true, the speed and xbofs is changed immediately */void irlap_apply_connection_parameters(struct irlap_cb *self, int now){	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);	IRDA_ASSERT(self != NULL, return;);	IRDA_ASSERT(self->magic == LAP_MAGIC, return;);	/* Set the negotiated xbofs value */	self->next_bofs   = self->qos_tx.additional_bofs.value;	if (now)		self->bofs_count = self->next_bofs;	/* Set the negotiated link speed (may need the new xbofs value) */	irlap_change_speed(self, self->qos_tx.baud_rate.value, now);	self->window_size = self->qos_tx.window_size.value;	self->window      = self->qos_tx.window_size.value;#ifdef CONFIG_IRDA_DYNAMIC_WINDOW	/*	 *  Calculate how many bytes it is possible to transmit before the	 *  link must be turned around	 */	self->line_capacity =		irlap_max_line_capacity(self->qos_tx.baud_rate.value,					self->qos_tx.max_turn_time.value);	self->bytes_left = self->line_capacity;#endif /* CONFIG_IRDA_DYNAMIC_WINDOW */	/*	 *  Initialize timeout values, some of the rules are listed on	 *  page 92 in IrLAP.	 */	IRDA_ASSERT(self->qos_tx.max_turn_time.value != 0, return;);	IRDA_ASSERT(self->qos_rx.max_turn_time.value != 0, return;);	/* The poll timeout applies only to the primary station.	 * It defines the maximum time the primary stay in XMIT mode	 * before timeout and turning the link around (sending a RR).	 * Or, this is how much we can keep the pf bit in primary mode.	 * Therefore, it must be lower or equal than our *OWN* max turn around.	 * Jean II */	self->poll_timeout = self->qos_tx.max_turn_time.value * HZ / 1000;	/* The Final timeout applies only to the primary station.	 * It defines the maximum time the primary wait (mostly in RECV mode)	 * for an answer from the secondary station before polling it again.	 * Therefore, it must be greater or equal than our *PARTNER*	 * max turn around time - Jean II */	self->final_timeout = self->qos_rx.max_turn_time.value * HZ / 1000;	/* The Watchdog Bit timeout applies only to the secondary station.	 * It defines the maximum time the secondary wait (mostly in RECV mode)	 * for poll from the primary station before getting annoyed.	 * Therefore, it must be greater or equal than our *PARTNER*	 * max turn around time - Jean II */	self->wd_timeout = self->final_timeout * 2;	/*	 * N1 and N2 are maximum retry count for *both* the final timer	 * and the wd timer (with a factor 2) as defined above.	 * After N1 retry of a timer, we give a warning to the user.	 * After N2 retry, we consider the link dead and disconnect it.	 * Jean II	 */	/*	 *  Set N1 to 0 if Link Disconnect/Threshold Time = 3 and set it to	 *  3 seconds otherwise. See page 71 in IrLAP for more details.	 *  Actually, it's not always 3 seconds, as we allow to set	 *  it via sysctl... Max maxtt is 500ms, and N1 need to be multiple	 *  of 2, so 1 second is minimum we can allow. - Jean II	 */	if (self->qos_tx.link_disc_time.value == sysctl_warn_noreply_time)		/*		 * If we set N1 to 0, it will trigger immediately, which is		 * not what we want. What we really want is to disable it,		 * Jean II		 */		self->N1 = -2; /* Disable - Need to be multiple of 2*/	else		self->N1 = sysctl_warn_noreply_time * 1000 /		  self->qos_rx.max_turn_time.value;	IRDA_DEBUG(4, "Setting N1 = %d\n", self->N1);	/* Set N2 to match our own disconnect time */	self->N2 = self->qos_tx.link_disc_time.value * 1000 /		self->qos_rx.max_turn_time.value;	IRDA_DEBUG(4, "Setting N2 = %d\n", self->N2);}#ifdef CONFIG_PROC_FSstruct irlap_iter_state {	int id;};static void *irlap_seq_start(struct seq_file *seq, loff_t *pos){	struct irlap_iter_state *iter = seq->private;	struct irlap_cb *self;	/* Protect our access to the tsap list */	spin_lock_irq(&irlap->hb_spinlock);	iter->id = 0;	for (self = (struct irlap_cb *) hashbin_get_first(irlap);	     self; self = (struct irlap_cb *) hashbin_get_next(irlap)) {		if (iter->id == *pos)			break;		++iter->id;	}	return self;}static void *irlap_seq_next(struct seq_file *seq, void *v, loff_t *pos){	struct irlap_iter_state *iter = seq->private;	++*pos;	++iter->id;	return (void *) hashbin_get_next(irlap);}static void irlap_seq_stop(struct seq_file *seq, void *v){	spin_unlock_irq(&irlap->hb_spinlock);}static int irlap_seq_show(struct seq_file *seq, void *v){	const struct irlap_iter_state *iter = seq->private;	const struct irlap_cb *self = v;	IRDA_ASSERT(self->magic == LAP_MAGIC, return -EINVAL;);	seq_printf(seq, "irlap%d ", iter->id);	seq_printf(seq, "state: %s\n",		   irlap_state[self->state]);	seq_printf(seq, "  device name: %s, ",		   (self->netdev) ? self->netdev->name : "bug");	seq_printf(seq, "hardware name: %s\n", self->hw_name);	seq_printf(seq, "  caddr: %#02x, ", self->caddr);	seq_printf(seq, "saddr: %#08x, ", self->saddr);	seq_printf(seq, "daddr: %#08x\n", self->daddr);	seq_printf(seq, "  win size: %d, ",		   self->window_size);	seq_printf(seq, "win: %d, ", self->window);#ifdef CONFIG_IRDA_DYNAMIC_WINDOW	seq_printf(seq, "line capacity: %d, ",		   self->line_capacity);	seq_printf(seq, "bytes left: %d\n", self->bytes_left);#endif /* CONFIG_IRDA_DYNAMIC_WINDOW */	seq_printf(seq, "  tx queue len: %d ",		   skb_queue_len(&self->txq));	seq_printf(seq, "win queue len: %d ",		   skb_queue_len(&self->wx_list));	seq_printf(seq, "rbusy: %s", self->remote_busy ?		   "TRUE" : "FALSE");	seq_printf(seq, " mbusy: %s\n", self->media_busy ?		   "TRUE" : "FALSE");	seq_printf(seq, "  retrans: %d ", self->retry_count);	seq_printf(seq, "vs: %d ", self->vs);	seq_printf(seq, "vr: %d ", self->vr);	seq_printf(seq, "va: %d\n", self->va);	seq_printf(seq, "  qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n");	seq_printf(seq, "  tx\t%d\t",		   self->qos_tx.baud_rate.value);	seq_printf(seq, "%d\t",		   self->qos_tx.max_turn_time.value);	seq_printf(seq, "%d\t",		   self->qos_tx.data_size.value);	seq_printf(seq, "%d\t",		   self->qos_tx.window_size.value);	seq_printf(seq, "%d\t",		   self->qos_tx.additional_bofs.value);	seq_printf(seq, "%d\t",		   self->qos_tx.min_turn_time.value);	seq_printf(seq, "%d\t",		   self->qos_tx.link_disc_time.value);	seq_printf(seq, "\n");	seq_printf(seq, "  rx\t%d\t",		   self->qos_rx.baud_rate.value);	seq_printf(seq, "%d\t",		   self->qos_rx.max_turn_time.value);	seq_printf(seq, "%d\t",		   self->qos_rx.data_size.value);	seq_printf(seq, "%d\t",		   self->qos_rx.window_size.value);	seq_printf(seq, "%d\t",		   self->qos_rx.additional_bofs.value);	seq_printf(seq, "%d\t",		   self->qos_rx.min_turn_time.value);	seq_printf(seq, "%d\n",		   self->qos_rx.link_disc_time.value);	return 0;}static const struct seq_operations irlap_seq_ops = {	.start  = irlap_seq_start,	.next   = irlap_seq_next,	.stop   = irlap_seq_stop,	.show   = irlap_seq_show,};static int irlap_seq_open(struct inode *inode, struct file *file){	if (irlap == NULL)		return -EINVAL;	return seq_open_private(file, &irlap_seq_ops,			sizeof(struct irlap_iter_state));}const struct file_operations irlap_seq_fops = {	.owner		= THIS_MODULE,	.open           = irlap_seq_open,	.read           = seq_read,	.llseek         = seq_lseek,	.release	= seq_release_private,};#endif /* CONFIG_PROC_FS */

⌨️ 快捷键说明

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