1 /*********************************************************************
5 * Description: IrLAP implementation for Linux
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Mon Aug 4 20:40:53 1997
9 * Modified at: Mon May 31 21:43:55 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,
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
[] = {
58 "LAP_DISC_INDICATION",
60 "LAP_RESET_INDICATION",
63 "LAP_PRIMARY_CONFLICT",
68 int irlap_proc_read(char *, char **, off_t
, int, int);
70 #endif /* CONFIG_PROC_FS */
72 __initfunc(int irlap_init(void))
74 /* Allocate master array */
75 irlap
= hashbin_new(HB_LOCAL
);
77 printk(KERN_WARNING
"IrLAP: Can't allocate irlap hashbin!\n");
81 #ifdef CONFIG_IRDA_COMPRESSION
82 irlap_compressors
= hashbin_new(HB_LOCAL
);
83 if (irlap_compressors
== NULL
) {
84 printk(KERN_WARNING
"IrLAP: Can't allocate compressors hashbin!\n");
92 void irlap_cleanup(void)
94 ASSERT(irlap
!= NULL
, return;);
96 hashbin_delete(irlap
, (FREE_FUNC
) __irlap_close
);
98 #ifdef CONFIG_IRDA_COMPRESSION
99 hashbin_delete(irlap_compressors
, (FREE_FUNC
) kfree
);
104 * Function irlap_open (driver)
106 * Initialize IrLAP layer
109 struct irlap_cb
*irlap_open(struct irda_device
*irdev
)
111 struct irlap_cb
*self
;
113 DEBUG(4, __FUNCTION__
"()\n");
115 ASSERT(irdev
!= NULL
, return NULL
;);
116 ASSERT(irdev
->magic
== IRDA_DEVICE_MAGIC
, return NULL
;);
118 /* Initialize the irlap structure. */
119 self
= kmalloc(sizeof(struct irlap_cb
), GFP_KERNEL
);
123 memset(self
, 0, sizeof(struct irlap_cb
));
124 self
->magic
= LAP_MAGIC
;
126 /* Make a binding between the layers */
128 self
->netdev
= &irdev
->netdev
;
130 irlap_next_state(self
, LAP_OFFLINE
);
132 /* Initialize transmitt queue */
133 skb_queue_head_init(&self
->tx_list
);
134 skb_queue_head_init(&self
->wx_list
);
136 /* My unique IrLAP device address! */
137 get_random_bytes(&self
->saddr
, sizeof(self
->saddr
));
140 * Generate random connection address for this session, which must
141 * be 7 bits wide and different from 0x00 and 0xfe
143 while ((self
->caddr
== 0x00) || (self
->caddr
== 0xfe)) {
144 get_random_bytes(&self
->caddr
, sizeof(self
->caddr
));
148 init_timer(&self
->slot_timer
);
149 init_timer(&self
->query_timer
);
150 init_timer(&self
->discovery_timer
);
151 init_timer(&self
->final_timer
);
152 init_timer(&self
->poll_timer
);
153 init_timer(&self
->wd_timer
);
154 init_timer(&self
->backoff_timer
);
156 irlap_apply_default_connection_parameters(self
);
158 irlap_next_state(self
, LAP_NDM
);
160 hashbin_insert(irlap
, (QUEUE
*) self
, self
->saddr
, NULL
);
162 irlmp_register_link(self
, self
->saddr
, &self
->notify
);
168 * Function __irlap_close (self)
170 * Remove IrLAP and all allocated memory. Stop any pending timers.
173 static void __irlap_close(struct irlap_cb
*self
)
175 ASSERT(self
!= NULL
, return;);
176 ASSERT(self
->magic
== LAP_MAGIC
, return;);
179 del_timer(&self
->slot_timer
);
180 del_timer(&self
->query_timer
);
181 del_timer(&self
->discovery_timer
);
182 del_timer(&self
->final_timer
);
183 del_timer(&self
->poll_timer
);
184 del_timer(&self
->wd_timer
);
185 del_timer(&self
->backoff_timer
);
187 irlap_flush_all_queues(self
);
196 * Function irlap_close (self)
198 * Remove IrLAP instance
201 void irlap_close(struct irlap_cb
*self
)
203 struct irlap_cb
*lap
;
205 DEBUG(4, __FUNCTION__
"()\n");
207 ASSERT(self
!= NULL
, return;);
208 ASSERT(self
->magic
== LAP_MAGIC
, return;);
210 irlap_disconnect_indication(self
, LAP_DISC_INDICATION
);
212 irlmp_unregister_link(self
->saddr
);
213 self
->notify
.instance
= NULL
;
215 /* Be sure that we manage to remove ourself from the hash */
216 lap
= hashbin_remove(irlap
, self
->saddr
, NULL
);
218 DEBUG(1, __FUNCTION__
"(), Didn't find myself!\n");
225 * Function irlap_connect_indication (self, skb)
227 * Another device is attempting to make a connection
230 void irlap_connect_indication(struct irlap_cb
*self
, struct sk_buff
*skb
)
232 DEBUG(4, __FUNCTION__
"()\n");
234 ASSERT(self
!= NULL
, return;);
235 ASSERT(self
->magic
== LAP_MAGIC
, return;);
237 irlap_init_qos_capabilities(self
, NULL
); /* No user QoS! */
239 irlmp_link_connect_indication(self
->notify
.instance
, self
->saddr
,
240 self
->daddr
, &self
->qos_tx
, skb
);
244 * Function irlap_connect_response (self, skb)
246 * Service user has accepted incomming connection
249 void irlap_connect_response(struct irlap_cb
*self
, struct sk_buff
*skb
)
251 DEBUG(4, __FUNCTION__
"()\n");
253 irlap_do_event(self
, CONNECT_RESPONSE
, skb
, NULL
);
257 * Function irlap_connect_request (self, daddr, qos_user, sniff)
259 * Request connection with another device, sniffing is not implemented
263 void irlap_connect_request(struct irlap_cb
*self
, __u32 daddr
,
264 struct qos_info
*qos_user
, int sniff
)
266 DEBUG(3, __FUNCTION__
"(), daddr=0x%08x\n", daddr
);
268 ASSERT(self
!= NULL
, return;);
269 ASSERT(self
->magic
== LAP_MAGIC
, return;);
274 * If the service user specifies QoS values for this connection,
277 irlap_init_qos_capabilities(self
, qos_user
);
279 if ((self
->state
== LAP_NDM
) &&
280 !irda_device_is_media_busy(self
->irdev
))
281 irlap_do_event(self
, CONNECT_REQUEST
, NULL
, NULL
);
283 self
->connect_pending
= TRUE
;
287 * Function irlap_connect_confirm (self, skb)
289 * Connection request has been accepted
292 void irlap_connect_confirm(struct irlap_cb
*self
, struct sk_buff
*skb
)
294 DEBUG(4, __FUNCTION__
"()\n");
296 ASSERT(self
!= NULL
, return;);
297 ASSERT(self
->magic
== LAP_MAGIC
, return;);
299 irlmp_link_connect_confirm(self
->notify
.instance
, &self
->qos_tx
, skb
);
303 * Function irlap_data_indication (self, skb)
305 * Received data frames from IR-port, so we just pass them up to
306 * IrLMP for further processing
309 inline void irlap_data_indication(struct irlap_cb
*self
, struct sk_buff
*skb
)
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
= irlap_decompress_frame(self
, skb
);
318 DEBUG(1, __FUNCTION__
"(), Decompress error!\n");
323 irlmp_link_data_indication(self
->notify
.instance
, LAP_RELIABLE
, skb
);
327 * Function irlap_unit_data_indication (self, skb)
329 * Received some data that was sent unreliable
332 void irlap_unit_data_indication(struct irlap_cb
*self
, struct sk_buff
*skb
)
334 DEBUG(1, __FUNCTION__
"()\n");
336 ASSERT(self
!= NULL
, return;);
337 ASSERT(self
->magic
== LAP_MAGIC
, return;);
338 ASSERT(skb
!= NULL
, return;);
340 /* Hide LAP header from IrLMP layer */
341 skb_pull(skb
, LAP_ADDR_HEADER
+LAP_CTRL_HEADER
);
343 #ifdef CONFIG_IRDA_COMPRESSION
344 if (self
->qos_tx
.compression
.value
) {
346 skb
= irlap_decompress_frame(self
, skb
);
348 DEBUG(1, __FUNCTION__
"(), Decompress error!\n");
353 irlmp_link_data_indication(self
->notify
.instance
, LAP_UNRELIABLE
, skb
);
357 * Function irlap_data_request (self, skb)
359 * Queue data for transmission, must wait until XMIT state
362 inline void irlap_data_request(struct irlap_cb
*self
, struct sk_buff
*skb
,
365 ASSERT(self
!= NULL
, return;);
366 ASSERT(self
->magic
== LAP_MAGIC
, return;);
367 ASSERT(skb
!= NULL
, return;);
369 #ifdef CONFIG_IRDA_COMPRESSION
370 if (self
->qos_tx
.compression
.value
) {
371 skb
= irlap_compress_frame(self
, skb
);
373 DEBUG(1, __FUNCTION__
"(), Compress error!\n");
379 ASSERT(skb_headroom(skb
) >= (LAP_ADDR_HEADER
+LAP_CTRL_HEADER
),
381 skb_push(skb
, LAP_ADDR_HEADER
+LAP_CTRL_HEADER
);
384 * Must set frame format now so that the rest of the code knows
385 * if its dealing with an I or an UI frame
388 skb
->data
[1] = I_FRAME
;
390 DEBUG(4, __FUNCTION__
"(), queueing unreliable frame\n");
391 skb
->data
[1] = UI_FRAME
;
395 * Send event if this frame only if we are in the right state
396 * FIXME: udata should be sent first! (skb_queue_head?)
398 if ((self
->state
== LAP_XMIT_P
) || (self
->state
== LAP_XMIT_S
)) {
400 * Check if the transmit queue contains some unsent frames,
401 * and if so, make sure they are sent first
403 if (!skb_queue_empty(&self
->tx_list
)) {
404 skb_queue_tail(&self
->tx_list
, skb
);
405 skb
= skb_dequeue(&self
->tx_list
);
407 ASSERT(skb
!= NULL
, return;);
409 irlap_do_event(self
, SEND_I_CMD
, skb
, NULL
);
411 skb_queue_tail(&self
->tx_list
, skb
);
415 * Function irlap_disconnect_request (void)
417 * Request to disconnect connection by service user
419 void irlap_disconnect_request(struct irlap_cb
*self
)
421 DEBUG(3, __FUNCTION__
"()\n");
423 ASSERT(self
!= NULL
, return;);
424 ASSERT(self
->magic
== LAP_MAGIC
, return;);
426 switch (self
->state
) {
427 case LAP_XMIT_P
: /* FALLTROUGH */
428 case LAP_XMIT_S
: /* FALLTROUGH */
429 case LAP_CONN
: /* FALLTROUGH */
430 case LAP_RESET_WAIT
: /* FALLTROUGH */
431 case LAP_RESET_CHECK
:
432 irlap_do_event(self
, DISCONNECT_REQUEST
, NULL
, NULL
);
435 DEBUG(0, __FUNCTION__
"(), disconnect pending!\n");
436 self
->disconnect_pending
= TRUE
;
442 * Function irlap_disconnect_indication (void)
444 * Disconnect request from other device
447 void irlap_disconnect_indication(struct irlap_cb
*self
, LAP_REASON reason
)
449 DEBUG(1, __FUNCTION__
"(), reason=%s\n", lap_reasons
[reason
]);
451 ASSERT(self
!= NULL
, return;);
452 ASSERT(self
->magic
== LAP_MAGIC
, return;);
454 #ifdef CONFIG_IRDA_COMPRESSION
455 irda_free_compression(self
);
458 irlap_flush_all_queues(self
);
461 case LAP_RESET_INDICATION
:
462 DEBUG(1, __FUNCTION__
"(), Sending reset request!\n");
463 irlap_do_event(self
, RESET_REQUEST
, NULL
, NULL
);
465 case LAP_NO_RESPONSE
: /* FALLTROUGH */
466 case LAP_DISC_INDICATION
: /* FALLTROUGH */
467 case LAP_FOUND_NONE
: /* FALLTROUGH */
469 irlmp_link_disconnect_indication(self
->notify
.instance
,
473 DEBUG(1, __FUNCTION__
"(), Reason %d not implemented!\n",
479 * Function irlap_discovery_request (gen_addr_bit)
481 * Start one single discovery operation.
484 void irlap_discovery_request(struct irlap_cb
*self
, discovery_t
*discovery
)
486 struct irlap_info info
;
488 ASSERT(self
!= NULL
, return;);
489 ASSERT(self
->magic
== LAP_MAGIC
, return;);
490 ASSERT(discovery
!= NULL
, return;);
492 DEBUG(4, __FUNCTION__
"(), nslots = %d\n", discovery
->nslots
);
494 ASSERT((discovery
->nslots
== 1) || (discovery
->nslots
== 6) ||
495 (discovery
->nslots
== 8) || (discovery
->nslots
== 16),
499 * Discovery is only possible in NDM mode
501 if (self
->state
== LAP_NDM
) {
502 ASSERT(self
->discovery_log
== NULL
, return;);
503 self
->discovery_log
= hashbin_new(HB_LOCAL
);
505 info
.S
= discovery
->nslots
; /* Number of slots */
506 info
.s
= 0; /* Current slot */
508 self
->discovery_cmd
= discovery
;
509 info
.discovery
= discovery
;
511 /* Check if the slot timeout is within limits */
512 if (sysctl_slot_timeout
< 20) {
514 "(), to low value for slot timeout!\n");
515 sysctl_slot_timeout
= 20;
518 * Highest value is actually 8, but we allow higher since
519 * some devices seems to require it.
521 if (sysctl_slot_timeout
> 160) {
523 "(), to high value for slot timeout!\n");
524 sysctl_slot_timeout
= 160;
527 self
->slot_timeout
= sysctl_slot_timeout
* HZ
/ 1000;
529 irlap_do_event(self
, DISCOVERY_REQUEST
, NULL
, &info
);
531 DEBUG(4, __FUNCTION__
532 "(), discovery only possible in NDM mode\n");
533 irlap_discovery_confirm(self
, NULL
);
538 * Function irlap_discovery_confirm (log)
540 * A device has been discovered in front of this station, we
541 * report directly to LMP.
543 void irlap_discovery_confirm(struct irlap_cb
*self
, hashbin_t
*discovery_log
)
545 ASSERT(self
!= NULL
, return;);
546 ASSERT(self
->magic
== LAP_MAGIC
, return;);
548 ASSERT(self
->notify
.instance
!= NULL
, return;);
551 * Check for successful discovery, since we are then allowed to clear
552 * the media busy condition (irlap p.94). This should allow us to make
553 * connection attempts much easier.
555 if (discovery_log
&& hashbin_get_size(discovery_log
) > 0)
556 irda_device_set_media_busy(self
->irdev
, FALSE
);
559 irlmp_link_discovery_confirm(self
->notify
.instance
, discovery_log
);
562 * IrLMP has now the responsibilities for the discovery_log
564 self
->discovery_log
= NULL
;
568 * Function irlap_discovery_indication (log)
570 * Somebody is trying to discover us!
573 void irlap_discovery_indication(struct irlap_cb
*self
, discovery_t
*discovery
)
575 DEBUG(4, __FUNCTION__
"()\n");
577 ASSERT(self
!= NULL
, return;);
578 ASSERT(self
->magic
== LAP_MAGIC
, return;);
579 ASSERT(discovery
!= NULL
, return;);
581 ASSERT(self
->notify
.instance
!= NULL
, return;);
583 irlmp_link_discovery_indication(self
->notify
.instance
, discovery
);
587 * Function irlap_status_indication (quality_of_link)
592 void irlap_status_indication(int quality_of_link
)
594 switch(quality_of_link
) {
595 case STATUS_NO_ACTIVITY
:
596 printk(KERN_INFO
"IrLAP, no activity on link!\n");
599 printk(KERN_INFO
"IrLAP, noisy link!\n");
604 irlmp_status_indication(quality_of_link
, LOCK_NO_CHANGE
);
608 * Function irlap_reset_indication (void)
613 void irlap_reset_indication(struct irlap_cb
*self
)
615 DEBUG(1, __FUNCTION__
"()\n");
617 ASSERT(self
!= NULL
, return;);
618 ASSERT(self
->magic
== LAP_MAGIC
, return;);
620 if (self
->state
== LAP_RESET_WAIT
)
621 irlap_do_event(self
, RESET_REQUEST
, NULL
, NULL
);
623 irlap_do_event(self
, RESET_RESPONSE
, NULL
, NULL
);
627 * Function irlap_reset_confirm (void)
632 void irlap_reset_confirm(void)
634 DEBUG(1, __FUNCTION__
"()\n");
638 * Function irlap_generate_rand_time_slot (S, s)
640 * Generate a random time slot between s and S-1 where
641 * S = Number of slots (0 -> S-1)
644 int irlap_generate_rand_time_slot(int S
, int s
)
648 ASSERT((S
- s
) > 0, return 0;);
650 slot
= s
+ jiffies
% (S
-s
);
652 ASSERT((slot
>= s
) || (slot
< S
), return 0;);
658 * Function irlap_update_nr_received (nr)
660 * Remove all acknowledged frames in current window queue. This code is
661 * not intuitive and you should not try to change it. If you think it
662 * contains bugs, please mail a patch to the author instead.
664 void irlap_update_nr_received(struct irlap_cb
*self
, int nr
)
666 struct sk_buff
*skb
= NULL
;
669 ASSERT(self
!= NULL
, return;);
670 ASSERT(self
->magic
== LAP_MAGIC
, return;);
673 * Remove all the ack-ed frames from the window queue.
676 DEBUG(4, "--> wx_list=%d, va=%d, nr=%d\n",
677 skb_queue_len(&self
->wx_list
), self
->va
, nr
);
680 * Optimize for the common case. It is most likely that the receiver
681 * will acknowledge all the frames we have sent! So in that case we
682 * delete all frames stored in window.
684 if (nr
== self
->vs
) {
685 while ((skb
= skb_dequeue(&self
->wx_list
)) != NULL
) {
688 /* The last acked frame is the next to send minus one */
691 /* Remove all acknowledged frames in current window */
692 while ((skb_peek(&self
->wx_list
) != NULL
) &&
693 (((self
->va
+1) % 8) != nr
))
695 skb
= skb_dequeue(&self
->wx_list
);
698 self
->va
= (self
->va
+ 1) % 8;
702 DEBUG(4, "irlap_update_nr_received(), removed %d\n", count
);
703 DEBUG(4, "wx_list=%d, va=%d, nr=%d -->\n",
704 skb_queue_len(&self
->wx_list
), self
->va
, nr
);
708 self
->window
= self
->window_size
- skb_queue_len(&self
->wx_list
);
712 * Function irlap_validate_ns_received (ns)
714 * Validate the next to send (ns) field from received frame.
716 int irlap_validate_ns_received(struct irlap_cb
*self
, int ns
)
718 ASSERT(self
!= NULL
, return -ENODEV
;);
719 ASSERT(self
->magic
== LAP_MAGIC
, return -EBADR
;);
721 /* ns as expected? */
722 if (ns
== self
->vr
) {
723 DEBUG(4, __FUNCTION__
"(), expected!\n");
727 * Stations are allowed to treat invalid NS as unexpected NS
728 * IrLAP, Recv ... with-invalid-Ns. p. 84
730 return NS_UNEXPECTED
;
732 /* return NR_INVALID; */
735 * Function irlap_validate_nr_received (nr)
737 * Validate the next to receive (nr) field from received frame.
740 int irlap_validate_nr_received(struct irlap_cb
*self
, int nr
)
742 ASSERT(self
!= NULL
, return -ENODEV
;);
743 ASSERT(self
->magic
== LAP_MAGIC
, return -EBADR
;);
745 /* nr as expected? */
746 if (nr
== self
->vs
) {
747 DEBUG(4, __FUNCTION__
"(), expected!\n");
752 * unexpected nr? (but within current window), first we check if the
753 * ns numbers of the frames in the current window wrap.
755 if (self
->va
< self
->vs
) {
756 if ((nr
>= self
->va
) && (nr
<= self
->vs
))
757 return NR_UNEXPECTED
;
759 if ((nr
>= self
->va
) || (nr
<= self
->vs
))
760 return NR_UNEXPECTED
;
768 * Function irlap_initiate_connection_state ()
770 * Initialize the connection state parameters
773 void irlap_initiate_connection_state(struct irlap_cb
*self
)
775 DEBUG(4, __FUNCTION__
"()\n");
777 ASSERT(self
!= NULL
, return;);
778 ASSERT(self
->magic
== LAP_MAGIC
, return;);
780 /* Next to send and next to receive */
781 self
->vs
= self
->vr
= 0;
783 /* Last frame which got acked (0 - 1) % 8 */
788 self
->remote_busy
= FALSE
;
789 self
->retry_count
= 0;
793 * Function irlap_wait_min_turn_around (self, qos)
795 * Wait negotiated minimum turn around time, this function actually sets
796 * the number of BOS's that must be sent before the next transmitted
797 * frame in order to delay for the specified amount of time. This is
798 * done to avoid using timers, and the forbidden udelay!
800 void irlap_wait_min_turn_around(struct irlap_cb
*self
, struct qos_info
*qos
)
806 /* Get QoS values. */
807 speed
= qos
->baud_rate
.value
;
808 usecs
= qos
->min_turn_time
.value
;
810 /* No need to calculate XBOFs for speeds over 115200 bps */
811 if (speed
> 115200) {
812 self
->mtt_required
= usecs
;
817 * Send additional BOF's for the next frame for the requested
818 * min turn time, so now we must calculate how many chars (XBOF's) we
819 * must send for the requested time period (min turn time)
821 bytes
= speed
* usecs
/ 10000000;
823 self
->xbofs_delay
= bytes
;
827 * Function irlap_flush_all_queues (void)
832 void irlap_flush_all_queues(struct irlap_cb
*self
)
836 ASSERT(self
!= NULL
, return;);
837 ASSERT(self
->magic
== LAP_MAGIC
, return;);
839 /* Free transmission queue */
840 while ((skb
= skb_dequeue(&self
->tx_list
)) != NULL
)
843 /* Free sliding window buffered packets */
844 while ((skb
= skb_dequeue(&self
->wx_list
)) != NULL
)
847 #ifdef CONFIG_IRDA_RECYCLE_RR
848 if (self
->recycle_rr_skb
) {
849 dev_kfree_skb(self
->recycle_rr_skb
);
850 self
->recycle_rr_skb
= NULL
;
856 * Function irlap_setspeed (self, speed)
858 * Change the speed of the IrDA port
861 void irlap_change_speed(struct irlap_cb
*self
, int speed
)
863 DEBUG(4, __FUNCTION__
"(), setting speed to %d\n", speed
);
865 ASSERT(self
!= NULL
, return;);
866 ASSERT(self
->magic
== LAP_MAGIC
, return;);
869 DEBUG(1, __FUNCTION__
"(), driver missing!\n");
873 irda_device_change_speed(self
->irdev
, speed
);
875 self
->qos_rx
.baud_rate
.value
= speed
;
876 self
->qos_tx
.baud_rate
.value
= speed
;
879 #ifdef CONFIG_IRDA_COMPRESSION
880 void irlap_init_comp_qos_capabilities(struct irlap_cb
*self
)
882 struct irda_compressor
*comp
;
883 __u8 mask
; /* Current bit tested */
886 ASSERT(self
!= NULL
, return;);
887 ASSERT(self
->magic
== LAP_MAGIC
, return;);
890 * Find out which compressors we support. We do this be checking that
891 * the corresponding compressor for each bit set in the QoS bits has
892 * actually been loaded. Ths is sort of hairy code but that is what
893 * you get when you do a little bit flicking :-)
895 DEBUG(4, __FUNCTION__
"(), comp bits 0x%02x\n",
896 self
->qos_rx
.compression
.bits
);
897 mask
= 0x80; /* Start with testing MSB */
899 DEBUG(4, __FUNCTION__
"(), testing bit %d\n", 8-i
);
900 if (self
->qos_rx
.compression
.bits
& mask
) {
901 DEBUG(4, __FUNCTION__
"(), bit %d is set by defalt\n",
903 comp
= hashbin_find(irlap_compressors
,
904 compression
[ msb_index(mask
)],
907 /* Protocol not supported, so clear the bit */
908 DEBUG(4, __FUNCTION__
"(), Compression "
909 "protocol %d has not been loaded!\n",
910 compression
[msb_index(mask
)]);
911 self
->qos_rx
.compression
.bits
&= ~mask
;
912 DEBUG(4, __FUNCTION__
913 "(), comp bits 0x%02x\n",
914 self
->qos_rx
.compression
.bits
);
917 /* Try the next bit */
924 * Function irlap_init_qos_capabilities (self, qos)
926 * Initialize QoS for this IrLAP session, What we do is to compute the
927 * intersection of the QoS capabilities for the user, driver and for
928 * IrLAP itself. Normally, IrLAP will not specify any values, but it can
929 * be used to restrict certain values.
931 void irlap_init_qos_capabilities(struct irlap_cb
*self
,
932 struct qos_info
*qos_user
)
934 ASSERT(self
!= NULL
, return;);
935 ASSERT(self
->magic
== LAP_MAGIC
, return;);
936 ASSERT(self
->irdev
!= NULL
, return;);
938 /* Start out with the maximum QoS support possible */
939 irda_init_max_qos_capabilies(&self
->qos_rx
);
941 #ifdef CONFIG_IRDA_COMPRESSION
942 irlap_init_comp_qos_capabilities(self
);
945 /* Apply drivers QoS capabilities */
946 irda_qos_compute_intersection(&self
->qos_rx
,
947 irda_device_get_qos(self
->irdev
));
950 * Check for user supplied QoS parameters. The service user is only
951 * allowed to supply these values. We check each parameter since the
952 * user may not have set all of them.
955 DEBUG(1, __FUNCTION__
"(), Found user specified QoS!\n");
957 if (qos_user
->baud_rate
.bits
)
958 self
->qos_rx
.baud_rate
.bits
&= qos_user
->baud_rate
.bits
;
960 if (qos_user
->max_turn_time
.bits
)
961 self
->qos_rx
.max_turn_time
.bits
&= qos_user
->max_turn_time
.bits
;
962 if (qos_user
->data_size
.bits
)
963 self
->qos_rx
.data_size
.bits
&= qos_user
->data_size
.bits
;
965 if (qos_user
->link_disc_time
.bits
)
966 self
->qos_rx
.link_disc_time
.bits
&= qos_user
->link_disc_time
.bits
;
967 #ifdef CONFIG_IRDA_COMPRESSION
968 self
->qos_rx
.compression
.bits
&= qos_user
->compression
.bits
;
973 * Make the intersection between IrLAP and drivers QoS
977 /* Use 500ms in IrLAP for now */
978 self
->qos_rx
.max_turn_time
.bits
&= 0x03;
979 self
->qos_rx
.max_turn_time
.bits
&= 0x01;
982 /* self->qos_rx.data_size.bits &= 0x03; */
984 /* Set disconnect time */
985 self
->qos_rx
.link_disc_time
.bits
&= 0x07;
987 irda_qos_bits_to_value(&self
->qos_rx
);
991 * Function irlap_apply_default_connection_parameters (void)
993 * Use the default connection and transmission parameters
996 void irlap_apply_default_connection_parameters(struct irlap_cb
*self
)
998 DEBUG(4, __FUNCTION__
"()\n");
1000 ASSERT(self
!= NULL
, return;);
1001 ASSERT(self
->magic
== LAP_MAGIC
, return;);
1003 irlap_change_speed(self
, 9600);
1005 /* Default value in NDM */
1006 self
->bofs_count
= 11;
1008 /* Use these until connection has been made */
1009 self
->slot_timeout
= sysctl_slot_timeout
;
1010 self
->final_timeout
= FINAL_TIMEOUT
;
1011 self
->poll_timeout
= POLL_TIMEOUT
;
1012 self
->wd_timeout
= WD_TIMEOUT
;
1014 self
->qos_tx
.data_size
.value
= 64;
1015 self
->qos_tx
.additional_bofs
.value
= 11;
1017 irlap_flush_all_queues(self
);
1019 self
->disconnect_pending
= FALSE
;
1023 * Function irlap_apply_connection_parameters (qos)
1025 * Initialize IrLAP with the negotiated QoS values
1028 void irlap_apply_connection_parameters(struct irlap_cb
*self
,
1029 struct qos_info
*qos
)
1031 DEBUG(4, __FUNCTION__
"()\n");
1033 ASSERT(self
!= NULL
, return;);
1034 ASSERT(self
->magic
== LAP_MAGIC
, return;);
1036 irlap_change_speed(self
, qos
->baud_rate
.value
);
1038 self
->window_size
= qos
->window_size
.value
;
1039 self
->window
= qos
->window_size
.value
;
1040 self
->bofs_count
= qos
->additional_bofs
.value
;
1043 * Calculate how many bytes it is possible to transmit before the
1044 * link must be turned around wb = baud * mtt/1000 * 1/2
1046 self
->window_bytes
= qos
->baud_rate
.value
1047 * qos
->max_turn_time
.value
/ 10000;
1048 DEBUG(4, "Setting window_bytes = %d\n", self
->window_bytes
);
1051 * Set N1 to 0 if Link Disconnect/Threshold Time = 3 and set it to
1052 * 3 seconds otherwise. See page 71 in IrLAP for more details.
1053 * TODO: these values should be calculated from the final timer
1056 if (qos
->link_disc_time
.value
== 3)
1059 self
->N1
= 3000 / qos
->max_turn_time
.value
;
1061 DEBUG(4, "Setting N1 = %d\n", self
->N1
);
1063 self
->N2
= qos
->link_disc_time
.value
* 1000 / qos
->max_turn_time
.value
;
1064 DEBUG(4, "Setting N2 = %d\n", self
->N2
);
1067 * Initialize timeout values, some of the rules are listed on
1070 self
->poll_timeout
= qos
->max_turn_time
.value
* HZ
/ 1000;
1071 self
->final_timeout
= qos
->max_turn_time
.value
* HZ
/ 1000;
1072 self
->wd_timeout
= self
->poll_timeout
* 2;
1074 #ifdef CONFIG_IRDA_COMPRESSION
1075 if (qos
->compression
.value
) {
1076 DEBUG(1, __FUNCTION__
"(), Initializing compression\n");
1077 irda_set_compression(self
, qos
->compression
.value
);
1079 irlap_compressor_init(self
, 0);
1084 #ifdef CONFIG_PROC_FS
1086 * Function irlap_proc_read (buf, start, offset, len, unused)
1088 * Give some info to the /proc file system
1091 int irlap_proc_read(char *buf
, char **start
, off_t offset
, int len
,
1094 struct irlap_cb
*self
;
1095 unsigned long flags
;
1103 self
= (struct irlap_cb
*) hashbin_get_first(irlap
);
1104 while (self
!= NULL
) {
1105 ASSERT(self
!= NULL
, return -ENODEV
;);
1106 ASSERT(self
->magic
== LAP_MAGIC
, return -EBADR
;);
1108 len
+= sprintf(buf
+len
, "irlap%d <-> %s ",
1109 i
++, self
->irdev
->name
);
1110 len
+= sprintf(buf
+len
, "state: %s\n",
1111 irlap_state
[ self
->state
]);
1113 len
+= sprintf(buf
+len
, " caddr: %#02x, ", self
->caddr
);
1114 len
+= sprintf(buf
+len
, "saddr: %#08x, ", self
->saddr
);
1115 len
+= sprintf(buf
+len
, "daddr: %#08x\n", self
->daddr
);
1117 len
+= sprintf(buf
+len
, " win size: %d, ",
1119 len
+= sprintf(buf
+len
, "win: %d, ", self
->window
);
1120 len
+= sprintf(buf
+len
, "win bytes: %d, ", self
->window_bytes
);
1121 len
+= sprintf(buf
+len
, "bytes left: %d\n", self
->bytes_left
);
1123 len
+= sprintf(buf
+len
, " tx queue len: %d ",
1124 skb_queue_len(&self
->tx_list
));
1125 len
+= sprintf(buf
+len
, "win queue len: %d ",
1126 skb_queue_len(&self
->wx_list
));
1127 len
+= sprintf(buf
+len
, "rbusy: %s\n", self
->remote_busy
?
1130 len
+= sprintf(buf
+len
, " retrans: %d ", self
->retry_count
);
1131 len
+= sprintf(buf
+len
, "vs: %d ", self
->vs
);
1132 len
+= sprintf(buf
+len
, "vr: %d ", self
->vr
);
1133 len
+= sprintf(buf
+len
, "va: %d\n", self
->va
);
1135 len
+= sprintf(buf
+len
, " qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n");
1137 len
+= sprintf(buf
+len
, " tx\t%d\t",
1138 self
->qos_tx
.baud_rate
.value
);
1139 len
+= sprintf(buf
+len
, "%d\t",
1140 self
->qos_tx
.max_turn_time
.value
);
1141 len
+= sprintf(buf
+len
, "%d\t",
1142 self
->qos_tx
.data_size
.value
);
1143 len
+= sprintf(buf
+len
, "%d\t",
1144 self
->qos_tx
.window_size
.value
);
1145 len
+= sprintf(buf
+len
, "%d\t",
1146 self
->qos_tx
.additional_bofs
.value
);
1147 len
+= sprintf(buf
+len
, "%d\t",
1148 self
->qos_tx
.min_turn_time
.value
);
1149 len
+= sprintf(buf
+len
, "%d\t",
1150 self
->qos_tx
.link_disc_time
.value
);
1151 #ifdef CONFIG_IRDA_COMPRESSION
1152 len
+= sprintf(buf
+len
, "%d",
1153 self
->qos_tx
.compression
.value
);
1155 len
+= sprintf(buf
+len
, "\n");
1157 len
+= sprintf(buf
+len
, " rx\t%d\t",
1158 self
->qos_rx
.baud_rate
.value
);
1159 len
+= sprintf(buf
+len
, "%d\t",
1160 self
->qos_rx
.max_turn_time
.value
);
1161 len
+= sprintf(buf
+len
, "%d\t",
1162 self
->qos_rx
.data_size
.value
);
1163 len
+= sprintf(buf
+len
, "%d\t",
1164 self
->qos_rx
.window_size
.value
);
1165 len
+= sprintf(buf
+len
, "%d\t",
1166 self
->qos_rx
.additional_bofs
.value
);
1167 len
+= sprintf(buf
+len
, "%d\t",
1168 self
->qos_rx
.min_turn_time
.value
);
1169 len
+= sprintf(buf
+len
, "%d\t",
1170 self
->qos_rx
.link_disc_time
.value
);
1171 #ifdef CONFIG_IRDA_COMPRESSION
1172 len
+= sprintf(buf
+len
, "%d",
1173 self
->qos_rx
.compression
.value
);
1175 len
+= sprintf(buf
+len
, "\n");
1177 self
= (struct irlap_cb
*) hashbin_get_next(irlap
);
1179 restore_flags(flags
);
1184 #endif /* CONFIG_PROC_FS */