- Linus: drop support for old-style Makefiles entirely. Big.
[davej-history.git] / net / irda / irlap.c
blob38d66d327ac7c9cdad48a63c71f7bf506ae52559
1 /*********************************************************************
2 *
3 * Filename: irlap.c
4 * Version: 1.0
5 * Description: IrLAP implementation for Linux
6 * Status: Stable
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Mon Aug 4 20:40:53 1997
9 * Modified at: Tue Dec 14 09:26:44 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
29 ********************************************************************/
31 #include <linux/config.h>
32 #include <linux/malloc.h>
33 #include <linux/string.h>
34 #include <linux/skbuff.h>
35 #include <linux/delay.h>
36 #include <linux/proc_fs.h>
37 #include <linux/init.h>
38 #include <linux/random.h>
40 #include <net/irda/irda.h>
41 #include <net/irda/irda_device.h>
42 #include <net/irda/irqueue.h>
43 #include <net/irda/irlmp.h>
44 #include <net/irda/irlmp_frame.h>
45 #include <net/irda/irlap_frame.h>
46 #include <net/irda/irlap.h>
47 #include <net/irda/timer.h>
48 #include <net/irda/qos.h>
49 #include <net/irda/irlap_comp.h>
51 hashbin_t *irlap = NULL;
52 int sysctl_slot_timeout = SLOT_TIMEOUT * 1000 / HZ;
54 static void __irlap_close(struct irlap_cb *self);
56 static char *lap_reasons[] = {
57 "ERROR, NOT USED",
58 "LAP_DISC_INDICATION",
59 "LAP_NO_RESPONSE",
60 "LAP_RESET_INDICATION",
61 "LAP_FOUND_NONE",
62 "LAP_MEDIA_BUSY",
63 "LAP_PRIMARY_CONFLICT",
64 "ERROR, NOT USED",
67 #ifdef CONFIG_PROC_FS
68 int irlap_proc_read(char *, char **, off_t, int);
70 #endif /* CONFIG_PROC_FS */
72 int __init irlap_init(void)
74 /* Allocate master array */
75 irlap = hashbin_new(HB_LOCAL);
76 if (irlap == NULL) {
77 ERROR(__FUNCTION__ "(), can't allocate irlap hashbin!\n");
78 return -ENOMEM;
81 #ifdef CONFIG_IRDA_COMPRESSION
82 irlap_compressors = hashbin_new(HB_LOCAL);
83 if (irlap_compressors == NULL) {
84 WARNING(__FUNCTION__
85 "(), can't allocate compressors hashbin!\n");
86 return -ENOMEM;
88 #endif
90 return 0;
93 void irlap_cleanup(void)
95 ASSERT(irlap != NULL, return;);
97 hashbin_delete(irlap, (FREE_FUNC) __irlap_close);
99 #ifdef CONFIG_IRDA_COMPRESSION
100 hashbin_delete(irlap_compressors, (FREE_FUNC) kfree);
101 #endif
105 * Function irlap_open (driver)
107 * Initialize IrLAP layer
110 struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos)
112 struct irlap_cb *self;
114 IRDA_DEBUG(4, __FUNCTION__ "()\n");
116 /* Initialize the irlap structure. */
117 self = kmalloc(sizeof(struct irlap_cb), GFP_KERNEL);
118 if (self == NULL)
119 return NULL;
121 memset(self, 0, sizeof(struct irlap_cb));
122 self->magic = LAP_MAGIC;
124 /* Make a binding between the layers */
125 self->netdev = dev;
126 self->qos_dev = qos;
128 /* FIXME: should we get our own field? */
129 dev->atalk_ptr = self;
131 irlap_next_state(self, LAP_OFFLINE);
133 /* Initialize transmit queue */
134 skb_queue_head_init(&self->txq);
135 skb_queue_head_init(&self->txq_ultra);
136 skb_queue_head_init(&self->wx_list);
138 /* My unique IrLAP device address! */
139 get_random_bytes(&self->saddr, sizeof(self->saddr));
140 memcpy(dev->dev_addr, &self->saddr, 4);
142 init_timer(&self->slot_timer);
143 init_timer(&self->query_timer);
144 init_timer(&self->discovery_timer);
145 init_timer(&self->final_timer);
146 init_timer(&self->poll_timer);
147 init_timer(&self->wd_timer);
148 init_timer(&self->backoff_timer);
149 init_timer(&self->media_busy_timer);
151 irlap_apply_default_connection_parameters(self);
153 self->N3 = 3; /* # connections attemts to try before giving up */
155 irlap_next_state(self, LAP_NDM);
157 hashbin_insert(irlap, (irda_queue_t *) self, self->saddr, NULL);
159 irlmp_register_link(self, self->saddr, &self->notify);
161 return self;
165 * Function __irlap_close (self)
167 * Remove IrLAP and all allocated memory. Stop any pending timers.
170 static void __irlap_close(struct irlap_cb *self)
172 ASSERT(self != NULL, return;);
173 ASSERT(self->magic == LAP_MAGIC, return;);
175 /* Stop timers */
176 del_timer(&self->slot_timer);
177 del_timer(&self->query_timer);
178 del_timer(&self->discovery_timer);
179 del_timer(&self->final_timer);
180 del_timer(&self->poll_timer);
181 del_timer(&self->wd_timer);
182 del_timer(&self->backoff_timer);
183 del_timer(&self->media_busy_timer);
185 irlap_flush_all_queues(self);
187 self->magic = 0;
189 kfree(self);
193 * Function irlap_close (self)
195 * Remove IrLAP instance
198 void irlap_close(struct irlap_cb *self)
200 struct irlap_cb *lap;
202 IRDA_DEBUG(4, __FUNCTION__ "()\n");
204 ASSERT(self != NULL, return;);
205 ASSERT(self->magic == LAP_MAGIC, return;);
207 irlap_disconnect_indication(self, LAP_DISC_INDICATION);
209 irlmp_unregister_link(self->saddr);
210 self->notify.instance = NULL;
212 /* Be sure that we manage to remove ourself from the hash */
213 lap = hashbin_remove(irlap, self->saddr, NULL);
214 if (!lap) {
215 IRDA_DEBUG(1, __FUNCTION__ "(), Didn't find myself!\n");
216 return;
218 __irlap_close(lap);
222 * Function irlap_connect_indication (self, skb)
224 * Another device is attempting to make a connection
227 void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb)
229 IRDA_DEBUG(4, __FUNCTION__ "()\n");
231 ASSERT(self != NULL, return;);
232 ASSERT(self->magic == LAP_MAGIC, return;);
234 irlap_init_qos_capabilities(self, NULL); /* No user QoS! */
236 skb_get(skb); /*LEVEL4*/
237 irlmp_link_connect_indication(self->notify.instance, self->saddr,
238 self->daddr, &self->qos_tx, skb);
242 * Function irlap_connect_response (self, skb)
244 * Service user has accepted incomming connection
247 void irlap_connect_response(struct irlap_cb *self, struct sk_buff *skb)
249 IRDA_DEBUG(4, __FUNCTION__ "()\n");
251 irlap_do_event(self, CONNECT_RESPONSE, skb, NULL);
252 kfree_skb(skb);
256 * Function irlap_connect_request (self, daddr, qos_user, sniff)
258 * Request connection with another device, sniffing is not implemented
259 * yet.
262 void irlap_connect_request(struct irlap_cb *self, __u32 daddr,
263 struct qos_info *qos_user, int sniff)
265 IRDA_DEBUG(3, __FUNCTION__ "(), daddr=0x%08x\n", daddr);
267 ASSERT(self != NULL, return;);
268 ASSERT(self->magic == LAP_MAGIC, return;);
270 self->daddr = daddr;
273 * If the service user specifies QoS values for this connection,
274 * then use them
276 irlap_init_qos_capabilities(self, qos_user);
278 if ((self->state == LAP_NDM) && !self->media_busy)
279 irlap_do_event(self, CONNECT_REQUEST, NULL, NULL);
280 else
281 self->connect_pending = TRUE;
285 * Function irlap_connect_confirm (self, skb)
287 * Connection request has been accepted
290 void irlap_connect_confirm(struct irlap_cb *self, struct sk_buff *skb)
292 IRDA_DEBUG(4, __FUNCTION__ "()\n");
294 ASSERT(self != NULL, return;);
295 ASSERT(self->magic == LAP_MAGIC, return;);
297 skb_get(skb); /*LEVEL4*/
298 irlmp_link_connect_confirm(self->notify.instance, &self->qos_tx, skb);
302 * Function irlap_data_indication (self, skb)
304 * Received data frames from IR-port, so we just pass them up to
305 * IrLMP for further processing
308 void irlap_data_indication(struct irlap_cb *self, struct sk_buff *skb,
309 int unreliable)
311 /* Hide LAP header from IrLMP layer */
312 skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);
314 #ifdef CONFIG_IRDA_COMPRESSION
315 if (self->qos_tx.compression.value) {
316 skb_get(skb); /*LEVEL4*/
317 skb = irlap_decompress_frame(self, skb);
318 if (!skb) {
319 IRDA_DEBUG(1, __FUNCTION__ "(), Decompress error!\n");
320 return;
323 #endif
324 skb_get(skb); /*LEVEL4*/
325 irlmp_link_data_indication(self->notify.instance, skb, unreliable);
330 * Function irlap_data_request (self, skb)
332 * Queue data for transmission, must wait until XMIT state
335 void irlap_data_request(struct irlap_cb *self, struct sk_buff *skb,
336 int unreliable)
338 ASSERT(self != NULL, return;);
339 ASSERT(self->magic == LAP_MAGIC, return;);
341 IRDA_DEBUG(3, __FUNCTION__ "()\n");
343 #ifdef CONFIG_IRDA_COMPRESSION
344 if (self->qos_tx.compression.value) {
345 skb = irlap_compress_frame(self, skb);
346 if (!skb) {
347 IRDA_DEBUG(1, __FUNCTION__ "(), Compress error!\n");
348 return;
351 #endif
352 ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER),
353 return;);
354 skb_push(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);
357 * Must set frame format now so that the rest of the code knows
358 * if its dealing with an I or an UI frame
360 if (unreliable)
361 skb->data[1] = UI_FRAME;
362 else
363 skb->data[1] = I_FRAME;
366 * Send event if this frame only if we are in the right state
367 * FIXME: udata should be sent first! (skb_queue_head?)
369 if ((self->state == LAP_XMIT_P) || (self->state == LAP_XMIT_S)) {
371 * Check if the transmit queue contains some unsent frames,
372 * and if so, make sure they are sent first
374 if (!skb_queue_empty(&self->txq)) {
375 skb_queue_tail(&self->txq, skb);
376 skb = skb_dequeue(&self->txq);
378 ASSERT(skb != NULL, return;);
380 irlap_do_event(self, SEND_I_CMD, skb, NULL);
381 kfree_skb(skb);
382 } else
383 skb_queue_tail(&self->txq, skb);
387 * Function irlap_unitdata_request (self, skb)
389 * Send Ultra data. This is data that must be sent outside any connection
392 #ifdef CONFIG_IRDA_ULTRA
393 void irlap_unitdata_request(struct irlap_cb *self, struct sk_buff *skb)
395 ASSERT(self != NULL, return;);
396 ASSERT(self->magic == LAP_MAGIC, return;);
398 IRDA_DEBUG(3, __FUNCTION__ "()\n");
400 ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER),
401 return;);
402 skb_push(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);
404 skb->data[0] = CBROADCAST;
405 skb->data[1] = UI_FRAME;
407 skb_queue_tail(&self->txq_ultra, skb);
409 irlap_do_event(self, SEND_UI_FRAME, NULL, NULL);
411 #endif /*CONFIG_IRDA_ULTRA */
414 * Function irlap_udata_indication (self, skb)
416 * Receive Ultra data. This is data that is received outside any connection
419 #ifdef CONFIG_IRDA_ULTRA
420 void irlap_unitdata_indication(struct irlap_cb *self, struct sk_buff *skb)
422 IRDA_DEBUG(1, __FUNCTION__ "()\n");
424 ASSERT(self != NULL, return;);
425 ASSERT(self->magic == LAP_MAGIC, return;);
426 ASSERT(skb != NULL, return;);
428 /* Hide LAP header from IrLMP layer */
429 skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER);
431 skb_get(skb); /*LEVEL4*/
432 irlmp_link_unitdata_indication(self->notify.instance, skb);
434 #endif /* CONFIG_IRDA_ULTRA */
437 * Function irlap_disconnect_request (void)
439 * Request to disconnect connection by service user
441 void irlap_disconnect_request(struct irlap_cb *self)
443 IRDA_DEBUG(3, __FUNCTION__ "()\n");
445 ASSERT(self != NULL, return;);
446 ASSERT(self->magic == LAP_MAGIC, return;);
448 /* Don't disconnect until all data frames are successfully sent */
449 if (skb_queue_len(&self->txq) > 0) {
450 self->disconnect_pending = TRUE;
452 return;
455 /* Check if we are in the right state for disconnecting */
456 switch (self->state) {
457 case LAP_XMIT_P: /* FALLTROUGH */
458 case LAP_XMIT_S: /* FALLTROUGH */
459 case LAP_CONN: /* FALLTROUGH */
460 case LAP_RESET_WAIT: /* FALLTROUGH */
461 case LAP_RESET_CHECK:
462 irlap_do_event(self, DISCONNECT_REQUEST, NULL, NULL);
463 break;
464 default:
465 IRDA_DEBUG(2, __FUNCTION__ "(), disconnect pending!\n");
466 self->disconnect_pending = TRUE;
467 break;
472 * Function irlap_disconnect_indication (void)
474 * Disconnect request from other device
477 void irlap_disconnect_indication(struct irlap_cb *self, LAP_REASON reason)
479 IRDA_DEBUG(1, __FUNCTION__ "(), reason=%s\n", lap_reasons[reason]);
481 ASSERT(self != NULL, return;);
482 ASSERT(self->magic == LAP_MAGIC, return;);
484 #ifdef CONFIG_IRDA_COMPRESSION
485 irda_free_compression(self);
486 #endif
487 /* Flush queues */
488 irlap_flush_all_queues(self);
490 switch (reason) {
491 case LAP_RESET_INDICATION:
492 IRDA_DEBUG(1, __FUNCTION__ "(), Sending reset request!\n");
493 irlap_do_event(self, RESET_REQUEST, NULL, NULL);
494 break;
495 case LAP_NO_RESPONSE: /* FALLTROUGH */
496 case LAP_DISC_INDICATION: /* FALLTROUGH */
497 case LAP_FOUND_NONE: /* FALLTROUGH */
498 case LAP_MEDIA_BUSY:
499 irlmp_link_disconnect_indication(self->notify.instance, self,
500 reason, NULL);
501 break;
502 default:
503 ERROR(__FUNCTION__ "(), Unknown reason %d\n", reason);
508 * Function irlap_discovery_request (gen_addr_bit)
510 * Start one single discovery operation.
513 void irlap_discovery_request(struct irlap_cb *self, discovery_t *discovery)
515 struct irlap_info info;
517 ASSERT(self != NULL, return;);
518 ASSERT(self->magic == LAP_MAGIC, return;);
519 ASSERT(discovery != NULL, return;);
521 IRDA_DEBUG(4, __FUNCTION__ "(), nslots = %d\n", discovery->nslots);
523 ASSERT((discovery->nslots == 1) || (discovery->nslots == 6) ||
524 (discovery->nslots == 8) || (discovery->nslots == 16),
525 return;);
527 /* Discovery is only possible in NDM mode */
528 if (self->state != LAP_NDM) {
529 IRDA_DEBUG(4, __FUNCTION__
530 "(), discovery only possible in NDM mode\n");
531 irlap_discovery_confirm(self, NULL);
532 return;
535 /* Check if last discovery request finished in time */
536 if (self->discovery_log != NULL) {
537 hashbin_delete(self->discovery_log, (FREE_FUNC) kfree);
538 self->discovery_log = NULL;
541 self->discovery_log= hashbin_new(HB_LOCAL);
543 info.S = discovery->nslots; /* Number of slots */
544 info.s = 0; /* Current slot */
546 self->discovery_cmd = discovery;
547 info.discovery = discovery;
549 /* Check if the slot timeout is within limits */
550 if (sysctl_slot_timeout < 20) {
551 ERROR(__FUNCTION__
552 "(), to low value for slot timeout!\n");
553 sysctl_slot_timeout = 20;
556 * Highest value is actually 8, but we allow higher since
557 * some devices seems to require it.
559 if (sysctl_slot_timeout > 160) {
560 ERROR(__FUNCTION__
561 "(), to high value for slot timeout!\n");
562 sysctl_slot_timeout = 160;
565 self->slot_timeout = sysctl_slot_timeout * HZ / 1000;
567 irlap_do_event(self, DISCOVERY_REQUEST, NULL, &info);
571 * Function irlap_discovery_confirm (log)
573 * A device has been discovered in front of this station, we
574 * report directly to LMP.
576 void irlap_discovery_confirm(struct irlap_cb *self, hashbin_t *discovery_log)
578 ASSERT(self != NULL, return;);
579 ASSERT(self->magic == LAP_MAGIC, return;);
581 ASSERT(self->notify.instance != NULL, return;);
584 * Check for successful discovery, since we are then allowed to clear
585 * the media busy condition (irlap p.94). This should allow us to make
586 * connection attempts much easier.
588 if (discovery_log && HASHBIN_GET_SIZE(discovery_log) > 0)
589 irda_device_set_media_busy(self->netdev, FALSE);
591 /* Inform IrLMP */
592 irlmp_link_discovery_confirm(self->notify.instance, discovery_log);
596 * Function irlap_discovery_indication (log)
598 * Somebody is trying to discover us!
601 void irlap_discovery_indication(struct irlap_cb *self, discovery_t *discovery)
603 IRDA_DEBUG(4, __FUNCTION__ "()\n");
605 ASSERT(self != NULL, return;);
606 ASSERT(self->magic == LAP_MAGIC, return;);
607 ASSERT(discovery != NULL, return;);
609 ASSERT(self->notify.instance != NULL, return;);
611 irlmp_link_discovery_indication(self->notify.instance, discovery);
615 * Function irlap_status_indication (quality_of_link)
620 void irlap_status_indication(struct irlap_cb *self, int quality_of_link)
622 switch (quality_of_link) {
623 case STATUS_NO_ACTIVITY:
624 MESSAGE("IrLAP, no activity on link!\n");
625 break;
626 case STATUS_NOISY:
627 MESSAGE("IrLAP, noisy link!\n");
628 break;
629 default:
630 break;
632 irlmp_status_indication(self->notify.instance,
633 quality_of_link, LOCK_NO_CHANGE);
637 * Function irlap_reset_indication (void)
642 void irlap_reset_indication(struct irlap_cb *self)
644 IRDA_DEBUG(1, __FUNCTION__ "()\n");
646 ASSERT(self != NULL, return;);
647 ASSERT(self->magic == LAP_MAGIC, return;);
649 if (self->state == LAP_RESET_WAIT)
650 irlap_do_event(self, RESET_REQUEST, NULL, NULL);
651 else
652 irlap_do_event(self, RESET_RESPONSE, NULL, NULL);
656 * Function irlap_reset_confirm (void)
661 void irlap_reset_confirm(void)
663 IRDA_DEBUG(1, __FUNCTION__ "()\n");
667 * Function irlap_generate_rand_time_slot (S, s)
669 * Generate a random time slot between s and S-1 where
670 * S = Number of slots (0 -> S-1)
671 * s = Current slot
673 int irlap_generate_rand_time_slot(int S, int s)
675 static int rand;
676 int slot;
678 ASSERT((S - s) > 0, return 0;);
680 rand += jiffies;
681 rand ^= (rand << 12);
682 rand ^= (rand >> 20);
684 slot = s + rand % (S-s);
686 ASSERT((slot >= s) || (slot < S), return 0;);
688 return slot;
692 * Function irlap_update_nr_received (nr)
694 * Remove all acknowledged frames in current window queue. This code is
695 * not intuitive and you should not try to change it. If you think it
696 * contains bugs, please mail a patch to the author instead.
698 void irlap_update_nr_received(struct irlap_cb *self, int nr)
700 struct sk_buff *skb = NULL;
701 int count = 0;
704 * Remove all the ack-ed frames from the window queue.
708 * Optimize for the common case. It is most likely that the receiver
709 * will acknowledge all the frames we have sent! So in that case we
710 * delete all frames stored in window.
712 if (nr == self->vs) {
713 while ((skb = skb_dequeue(&self->wx_list)) != NULL) {
714 dev_kfree_skb(skb);
716 /* The last acked frame is the next to send minus one */
717 self->va = nr - 1;
718 } else {
719 /* Remove all acknowledged frames in current window */
720 while ((skb_peek(&self->wx_list) != NULL) &&
721 (((self->va+1) % 8) != nr))
723 skb = skb_dequeue(&self->wx_list);
724 dev_kfree_skb(skb);
726 self->va = (self->va + 1) % 8;
727 count++;
731 /* Advance window */
732 self->window = self->window_size - skb_queue_len(&self->wx_list);
736 * Function irlap_validate_ns_received (ns)
738 * Validate the next to send (ns) field from received frame.
740 int irlap_validate_ns_received(struct irlap_cb *self, int ns)
742 /* ns as expected? */
743 if (ns == self->vr)
744 return NS_EXPECTED;
746 * Stations are allowed to treat invalid NS as unexpected NS
747 * IrLAP, Recv ... with-invalid-Ns. p. 84
749 return NS_UNEXPECTED;
751 /* return NR_INVALID; */
754 * Function irlap_validate_nr_received (nr)
756 * Validate the next to receive (nr) field from received frame.
759 int irlap_validate_nr_received(struct irlap_cb *self, int nr)
761 /* nr as expected? */
762 if (nr == self->vs) {
763 IRDA_DEBUG(4, __FUNCTION__ "(), expected!\n");
764 return NR_EXPECTED;
768 * unexpected nr? (but within current window), first we check if the
769 * ns numbers of the frames in the current window wrap.
771 if (self->va < self->vs) {
772 if ((nr >= self->va) && (nr <= self->vs))
773 return NR_UNEXPECTED;
774 } else {
775 if ((nr >= self->va) || (nr <= self->vs))
776 return NR_UNEXPECTED;
779 /* Invalid nr! */
780 return NR_INVALID;
784 * Function irlap_initiate_connection_state ()
786 * Initialize the connection state parameters
789 void irlap_initiate_connection_state(struct irlap_cb *self)
791 IRDA_DEBUG(4, __FUNCTION__ "()\n");
793 ASSERT(self != NULL, return;);
794 ASSERT(self->magic == LAP_MAGIC, return;);
796 /* Next to send and next to receive */
797 self->vs = self->vr = 0;
799 /* Last frame which got acked (0 - 1) % 8 */
800 self->va = 7;
802 self->window = 1;
804 self->remote_busy = FALSE;
805 self->retry_count = 0;
809 * Function irlap_wait_min_turn_around (self, qos)
811 * Wait negotiated minimum turn around time, this function actually sets
812 * the number of BOS's that must be sent before the next transmitted
813 * frame in order to delay for the specified amount of time. This is
814 * done to avoid using timers, and the forbidden udelay!
816 void irlap_wait_min_turn_around(struct irlap_cb *self, struct qos_info *qos)
818 __u32 min_turn_time;
819 __u32 speed;
821 /* Get QoS values. */
822 speed = qos->baud_rate.value;
823 min_turn_time = qos->min_turn_time.value;
825 /* No need to calculate XBOFs for speeds over 115200 bps */
826 if (speed > 115200) {
827 self->mtt_required = min_turn_time;
828 return;
832 * Send additional BOF's for the next frame for the requested
833 * min turn time, so now we must calculate how many chars (XBOF's) we
834 * must send for the requested time period (min turn time)
836 self->xbofs_delay = irlap_min_turn_time_in_bytes(speed, min_turn_time);
840 * Function irlap_flush_all_queues (void)
842 * Flush all queues
845 void irlap_flush_all_queues(struct irlap_cb *self)
847 struct sk_buff* skb;
849 ASSERT(self != NULL, return;);
850 ASSERT(self->magic == LAP_MAGIC, return;);
852 /* Free transmission queue */
853 while ((skb = skb_dequeue(&self->txq)) != NULL)
854 dev_kfree_skb(skb);
856 while ((skb = skb_dequeue(&self->txq_ultra)) != NULL)
857 dev_kfree_skb(skb);
859 /* Free sliding window buffered packets */
860 while ((skb = skb_dequeue(&self->wx_list)) != NULL)
861 dev_kfree_skb(skb);
863 #ifdef CONFIG_IRDA_RECYCLE_RR
864 if (self->recycle_rr_skb) {
865 dev_kfree_skb(self->recycle_rr_skb);
866 self->recycle_rr_skb = NULL;
868 #endif
872 * Function irlap_setspeed (self, speed)
874 * Change the speed of the IrDA port
877 void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now)
879 struct sk_buff *skb;
881 IRDA_DEBUG(0, __FUNCTION__ "(), setting speed to %d\n", speed);
883 ASSERT(self != NULL, return;);
884 ASSERT(self->magic == LAP_MAGIC, return;);
886 self->speed = speed;
888 /* Change speed now, or just piggyback speed on frames */
889 if (now) {
890 /* Send down empty frame to trigger speed change */
891 skb = dev_alloc_skb(0);
892 irlap_queue_xmit(self, skb);
896 #ifdef CONFIG_IRDA_COMPRESSION
897 void irlap_init_comp_qos_capabilities(struct irlap_cb *self)
899 struct irda_compressor *comp;
900 __u8 mask; /* Current bit tested */
901 int i;
903 ASSERT(self != NULL, return;);
904 ASSERT(self->magic == LAP_MAGIC, return;);
907 * Find out which compressors we support. We do this be checking that
908 * the corresponding compressor for each bit set in the QoS bits has
909 * actually been loaded. Ths is sort of hairy code but that is what
910 * you get when you do a little bit flicking :-)
912 IRDA_DEBUG(4, __FUNCTION__ "(), comp bits 0x%02x\n",
913 self->qos_rx.compression.bits);
914 mask = 0x80; /* Start with testing MSB */
915 for (i=0;i<8;i++) {
916 IRDA_DEBUG(4, __FUNCTION__ "(), testing bit %d\n", 8-i);
917 if (self->qos_rx.compression.bits & mask) {
918 IRDA_DEBUG(4, __FUNCTION__
919 "(), bit %d is set by defalt\n", 8-i);
920 comp = hashbin_find(irlap_compressors,
921 compressions[msb_index(mask)],
922 NULL);
923 if (!comp) {
924 /* Protocol not supported, so clear the bit */
925 IRDA_DEBUG(4, __FUNCTION__ "(), Compression "
926 "protocol %d has not been loaded!\n",
927 compressions[msb_index(mask)]);
928 self->qos_rx.compression.bits &= ~mask;
929 IRDA_DEBUG(4, __FUNCTION__
930 "(), comp bits 0x%02x\n",
931 self->qos_rx.compression.bits);
934 /* Try the next bit */
935 mask >>= 1;
938 #endif
941 * Function irlap_init_qos_capabilities (self, qos)
943 * Initialize QoS for this IrLAP session, What we do is to compute the
944 * intersection of the QoS capabilities for the user, driver and for
945 * IrLAP itself. Normally, IrLAP will not specify any values, but it can
946 * be used to restrict certain values.
948 void irlap_init_qos_capabilities(struct irlap_cb *self,
949 struct qos_info *qos_user)
951 ASSERT(self != NULL, return;);
952 ASSERT(self->magic == LAP_MAGIC, return;);
953 ASSERT(self->netdev != NULL, return;);
955 /* Start out with the maximum QoS support possible */
956 irda_init_max_qos_capabilies(&self->qos_rx);
958 #ifdef CONFIG_IRDA_COMPRESSION
959 irlap_init_comp_qos_capabilities(self);
960 #endif
962 /* Apply drivers QoS capabilities */
963 irda_qos_compute_intersection(&self->qos_rx, self->qos_dev);
966 * Check for user supplied QoS parameters. The service user is only
967 * allowed to supply these values. We check each parameter since the
968 * user may not have set all of them.
970 if (qos_user) {
971 IRDA_DEBUG(1, __FUNCTION__ "(), Found user specified QoS!\n");
973 if (qos_user->baud_rate.bits)
974 self->qos_rx.baud_rate.bits &= qos_user->baud_rate.bits;
976 if (qos_user->max_turn_time.bits)
977 self->qos_rx.max_turn_time.bits &= qos_user->max_turn_time.bits;
978 if (qos_user->data_size.bits)
979 self->qos_rx.data_size.bits &= qos_user->data_size.bits;
981 if (qos_user->link_disc_time.bits)
982 self->qos_rx.link_disc_time.bits &= qos_user->link_disc_time.bits;
983 #ifdef CONFIG_IRDA_COMPRESSION
984 self->qos_rx.compression.bits &= qos_user->compression.bits;
985 #endif
988 /* Use 500ms in IrLAP for now */
989 self->qos_rx.max_turn_time.bits &= 0x01;
991 /* Set data size */
992 /*self->qos_rx.data_size.bits &= 0x03;*/
994 /* Set disconnect time -> done properly in qos.c */
995 /*self->qos_rx.link_disc_time.bits &= 0x07;*/
997 irda_qos_bits_to_value(&self->qos_rx);
1001 * Function irlap_apply_default_connection_parameters (void)
1003 * Use the default connection and transmission parameters
1006 void irlap_apply_default_connection_parameters(struct irlap_cb *self)
1008 IRDA_DEBUG(4, __FUNCTION__ "()\n");
1010 ASSERT(self != NULL, return;);
1011 ASSERT(self->magic == LAP_MAGIC, return;);
1013 irlap_change_speed(self, 9600, TRUE);
1015 /* Set mbusy when going to NDM state */
1016 irda_device_set_media_busy(self->netdev, TRUE);
1018 /* Default value in NDM */
1019 self->bofs_count = 12;
1022 * Generate random connection address for this session, which must
1023 * be 7 bits wide and different from 0x00 and 0xfe
1025 while ((self->caddr == 0x00) || (self->caddr == 0xfe)) {
1026 get_random_bytes(&self->caddr, sizeof(self->caddr));
1027 self->caddr &= 0xfe;
1030 /* Use default values until connection has been negitiated */
1031 self->slot_timeout = sysctl_slot_timeout;
1032 self->final_timeout = FINAL_TIMEOUT;
1033 self->poll_timeout = POLL_TIMEOUT;
1034 self->wd_timeout = WD_TIMEOUT;
1036 /* Set some default values */
1037 self->qos_tx.baud_rate.value = 9600;
1038 self->qos_rx.baud_rate.value = 9600;
1039 self->qos_tx.max_turn_time.value = 0;
1040 self->qos_rx.max_turn_time.value = 0;
1041 self->qos_tx.min_turn_time.value = 0;
1042 self->qos_rx.min_turn_time.value = 0;
1043 self->qos_tx.data_size.value = 64;
1044 self->qos_rx.data_size.value = 64;
1045 self->qos_tx.window_size.value = 1;
1046 self->qos_rx.window_size.value = 1;
1047 self->qos_tx.additional_bofs.value = 12;
1048 self->qos_rx.additional_bofs.value = 12;
1049 self->qos_tx.link_disc_time.value = 0;
1050 self->qos_rx.link_disc_time.value = 0;
1052 irlap_flush_all_queues(self);
1054 self->disconnect_pending = FALSE;
1055 self->connect_pending = FALSE;
1059 * Function irlap_apply_connection_parameters (qos)
1061 * Initialize IrLAP with the negotiated QoS values
1064 void irlap_apply_connection_parameters(struct irlap_cb *self)
1066 IRDA_DEBUG(4, __FUNCTION__ "()\n");
1068 ASSERT(self != NULL, return;);
1069 ASSERT(self->magic == LAP_MAGIC, return;);
1071 irlap_change_speed(self, self->qos_tx.baud_rate.value, FALSE);
1073 self->window_size = self->qos_tx.window_size.value;
1074 self->window = self->qos_tx.window_size.value;
1075 self->bofs_count = self->qos_tx.additional_bofs.value;
1078 * Calculate how many bytes it is possible to transmit before the
1079 * link must be turned around
1081 self->line_capacity =
1082 irlap_max_line_capacity(self->qos_tx.baud_rate.value,
1083 self->qos_tx.max_turn_time.value);
1085 * Set N1 to 0 if Link Disconnect/Threshold Time = 3 and set it to
1086 * 3 seconds otherwise. See page 71 in IrLAP for more details.
1087 * TODO: these values should be calculated from the final timer
1088 * as well
1090 ASSERT(self->qos_tx.max_turn_time.value != 0, return;);
1091 if (self->qos_tx.link_disc_time.value == 3)
1093 * If we set N1 to 0, it will trigger immediately, which is
1094 * not what we want. What we really want is to disable it,
1095 * Jean II
1097 self->N1 = -1; /* Disable */
1098 else
1099 self->N1 = 3000 / self->qos_tx.max_turn_time.value;
1101 IRDA_DEBUG(4, "Setting N1 = %d\n", self->N1);
1104 self->N2 = self->qos_tx.link_disc_time.value * 1000 /
1105 self->qos_tx.max_turn_time.value;
1106 IRDA_DEBUG(4, "Setting N2 = %d\n", self->N2);
1109 * Initialize timeout values, some of the rules are listed on
1110 * page 92 in IrLAP.
1112 self->poll_timeout = self->qos_tx.max_turn_time.value * HZ / 1000;
1113 self->wd_timeout = self->poll_timeout * 2;
1116 * Be careful to keep our promises to the peer device about how long
1117 * time it can keep the pf bit. So here we must use the rx_qos value
1119 self->final_timeout = self->qos_rx.max_turn_time.value * HZ / 1000;
1121 #ifdef CONFIG_IRDA_COMPRESSION
1122 if (self->qos_tx.compression.value) {
1123 IRDA_DEBUG(1, __FUNCTION__ "(), Initializing compression\n");
1124 irda_set_compression(self, self->qos_tx.compression.value);
1126 irlap_compressor_init(self, 0);
1128 #endif
1132 * Function irlap_set_local_busy (self, status)
1137 void irlap_set_local_busy(struct irlap_cb *self, int status)
1139 IRDA_DEBUG(0, __FUNCTION__ "()\n");
1141 self->local_busy = status;
1143 if (status)
1144 IRDA_DEBUG(0, __FUNCTION__ "(), local busy ON\n");
1145 else
1146 IRDA_DEBUG(0, __FUNCTION__ "(), local busy OFF\n");
1149 #ifdef CONFIG_PROC_FS
1151 * Function irlap_proc_read (buf, start, offset, len, unused)
1153 * Give some info to the /proc file system
1156 int irlap_proc_read(char *buf, char **start, off_t offset, int len)
1158 struct irlap_cb *self;
1159 unsigned long flags;
1160 int i = 0;
1162 save_flags(flags);
1163 cli();
1165 len = 0;
1167 self = (struct irlap_cb *) hashbin_get_first(irlap);
1168 while (self != NULL) {
1169 ASSERT(self != NULL, return -ENODEV;);
1170 ASSERT(self->magic == LAP_MAGIC, return -EBADR;);
1172 len += sprintf(buf+len, "irlap%d ", i++);
1173 len += sprintf(buf+len, "state: %s\n",
1174 irlap_state[self->state]);
1176 len += sprintf(buf+len, " caddr: %#02x, ", self->caddr);
1177 len += sprintf(buf+len, "saddr: %#08x, ", self->saddr);
1178 len += sprintf(buf+len, "daddr: %#08x\n", self->daddr);
1180 len += sprintf(buf+len, " win size: %d, ",
1181 self->window_size);
1182 len += sprintf(buf+len, "win: %d, ", self->window);
1183 #if CONFIG_IRDA_DYNAMIC_WINDOW
1184 len += sprintf(buf+len, "line capacity: %d, ",
1185 self->line_capacity);
1186 len += sprintf(buf+len, "bytes left: %d\n", self->bytes_left);
1187 #endif /* CONFIG_IRDA_DYNAMIC_WINDOW */
1188 len += sprintf(buf+len, " tx queue len: %d ",
1189 skb_queue_len(&self->txq));
1190 len += sprintf(buf+len, "win queue len: %d ",
1191 skb_queue_len(&self->wx_list));
1192 len += sprintf(buf+len, "rbusy: %s", self->remote_busy ?
1193 "TRUE" : "FALSE");
1194 len += sprintf(buf+len, " mbusy: %s\n", self->media_busy ?
1195 "TRUE" : "FALSE");
1197 len += sprintf(buf+len, " retrans: %d ", self->retry_count);
1198 len += sprintf(buf+len, "vs: %d ", self->vs);
1199 len += sprintf(buf+len, "vr: %d ", self->vr);
1200 len += sprintf(buf+len, "va: %d\n", self->va);
1202 len += sprintf(buf+len, " qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n");
1204 len += sprintf(buf+len, " tx\t%d\t",
1205 self->qos_tx.baud_rate.value);
1206 len += sprintf(buf+len, "%d\t",
1207 self->qos_tx.max_turn_time.value);
1208 len += sprintf(buf+len, "%d\t",
1209 self->qos_tx.data_size.value);
1210 len += sprintf(buf+len, "%d\t",
1211 self->qos_tx.window_size.value);
1212 len += sprintf(buf+len, "%d\t",
1213 self->qos_tx.additional_bofs.value);
1214 len += sprintf(buf+len, "%d\t",
1215 self->qos_tx.min_turn_time.value);
1216 len += sprintf(buf+len, "%d\t",
1217 self->qos_tx.link_disc_time.value);
1218 #ifdef CONFIG_IRDA_COMPRESSION
1219 len += sprintf(buf+len, "%d",
1220 self->qos_tx.compression.value);
1221 #endif
1222 len += sprintf(buf+len, "\n");
1224 len += sprintf(buf+len, " rx\t%d\t",
1225 self->qos_rx.baud_rate.value);
1226 len += sprintf(buf+len, "%d\t",
1227 self->qos_rx.max_turn_time.value);
1228 len += sprintf(buf+len, "%d\t",
1229 self->qos_rx.data_size.value);
1230 len += sprintf(buf+len, "%d\t",
1231 self->qos_rx.window_size.value);
1232 len += sprintf(buf+len, "%d\t",
1233 self->qos_rx.additional_bofs.value);
1234 len += sprintf(buf+len, "%d\t",
1235 self->qos_rx.min_turn_time.value);
1236 len += sprintf(buf+len, "%d\t",
1237 self->qos_rx.link_disc_time.value);
1238 #ifdef CONFIG_IRDA_COMPRESSION
1239 len += sprintf(buf+len, "%d",
1240 self->qos_rx.compression.value);
1241 #endif
1242 len += sprintf(buf+len, "\n");
1244 self = (struct irlap_cb *) hashbin_get_next(irlap);
1246 restore_flags(flags);
1248 return len;
1251 #endif /* CONFIG_PROC_FS */