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: Fri Oct 8 23:17:36 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 int __init
irlap_init(void)
74 /* Allocate master array */
75 irlap
= hashbin_new(HB_LOCAL
);
77 ERROR(__FUNCTION__
"(), can't allocate irlap hashbin!\n");
81 #ifdef CONFIG_IRDA_COMPRESSION
82 irlap_compressors
= hashbin_new(HB_LOCAL
);
83 if (irlap_compressors
== NULL
) {
85 "(), can't allocate compressors hashbin!\n");
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
);
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
);
121 memset(self
, 0, sizeof(struct irlap_cb
));
122 self
->magic
= LAP_MAGIC
;
124 /* Make a binding between the layers */
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
->tx_list
);
135 skb_queue_head_init(&self
->wx_list
);
137 /* My unique IrLAP device address! */
138 get_random_bytes(&self
->saddr
, sizeof(self
->saddr
));
139 memcpy(dev
->dev_addr
, &self
->saddr
, 4);
142 * Generate random connection address for this session, which must
143 * be 7 bits wide and different from 0x00 and 0xfe
145 while ((self
->caddr
== 0x00) || (self
->caddr
== 0xfe)) {
146 get_random_bytes(&self
->caddr
, sizeof(self
->caddr
));
150 init_timer(&self
->slot_timer
);
151 init_timer(&self
->query_timer
);
152 init_timer(&self
->discovery_timer
);
153 init_timer(&self
->final_timer
);
154 init_timer(&self
->poll_timer
);
155 init_timer(&self
->wd_timer
);
156 init_timer(&self
->backoff_timer
);
157 init_timer(&self
->media_busy_timer
);
159 irlap_apply_default_connection_parameters(self
);
161 irlap_next_state(self
, LAP_NDM
);
163 hashbin_insert(irlap
, (queue_t
*) self
, self
->saddr
, NULL
);
165 irlmp_register_link(self
, self
->saddr
, &self
->notify
);
171 * Function __irlap_close (self)
173 * Remove IrLAP and all allocated memory. Stop any pending timers.
176 static void __irlap_close(struct irlap_cb
*self
)
178 ASSERT(self
!= NULL
, return;);
179 ASSERT(self
->magic
== LAP_MAGIC
, return;);
182 del_timer(&self
->slot_timer
);
183 del_timer(&self
->query_timer
);
184 del_timer(&self
->discovery_timer
);
185 del_timer(&self
->final_timer
);
186 del_timer(&self
->poll_timer
);
187 del_timer(&self
->wd_timer
);
188 del_timer(&self
->backoff_timer
);
189 del_timer(&self
->media_busy_timer
);
191 irlap_flush_all_queues(self
);
199 * Function irlap_close (self)
201 * Remove IrLAP instance
204 void irlap_close(struct irlap_cb
*self
)
206 struct irlap_cb
*lap
;
208 IRDA_DEBUG(4, __FUNCTION__
"()\n");
210 ASSERT(self
!= NULL
, return;);
211 ASSERT(self
->magic
== LAP_MAGIC
, return;);
213 irlap_disconnect_indication(self
, LAP_DISC_INDICATION
);
215 irlmp_unregister_link(self
->saddr
);
216 self
->notify
.instance
= NULL
;
218 /* Be sure that we manage to remove ourself from the hash */
219 lap
= hashbin_remove(irlap
, self
->saddr
, NULL
);
221 IRDA_DEBUG(1, __FUNCTION__
"(), Didn't find myself!\n");
228 * Function irlap_connect_indication (self, skb)
230 * Another device is attempting to make a connection
233 void irlap_connect_indication(struct irlap_cb
*self
, struct sk_buff
*skb
)
235 IRDA_DEBUG(4, __FUNCTION__
"()\n");
237 ASSERT(self
!= NULL
, return;);
238 ASSERT(self
->magic
== LAP_MAGIC
, return;);
240 irlap_init_qos_capabilities(self
, NULL
); /* No user QoS! */
242 irlmp_link_connect_indication(self
->notify
.instance
, self
->saddr
,
243 self
->daddr
, &self
->qos_tx
, skb
);
247 * Function irlap_connect_response (self, skb)
249 * Service user has accepted incomming connection
252 void irlap_connect_response(struct irlap_cb
*self
, struct sk_buff
*skb
)
254 IRDA_DEBUG(4, __FUNCTION__
"()\n");
256 irlap_do_event(self
, CONNECT_RESPONSE
, skb
, NULL
);
260 * Function irlap_connect_request (self, daddr, qos_user, sniff)
262 * Request connection with another device, sniffing is not implemented
266 void irlap_connect_request(struct irlap_cb
*self
, __u32 daddr
,
267 struct qos_info
*qos_user
, int sniff
)
269 IRDA_DEBUG(3, __FUNCTION__
"(), daddr=0x%08x\n", daddr
);
271 ASSERT(self
!= NULL
, return;);
272 ASSERT(self
->magic
== LAP_MAGIC
, return;);
277 * If the service user specifies QoS values for this connection,
280 irlap_init_qos_capabilities(self
, qos_user
);
282 if ((self
->state
== LAP_NDM
) && !self
->media_busy
)
283 irlap_do_event(self
, CONNECT_REQUEST
, NULL
, NULL
);
285 self
->connect_pending
= TRUE
;
289 * Function irlap_connect_confirm (self, skb)
291 * Connection request has been accepted
294 void irlap_connect_confirm(struct irlap_cb
*self
, struct sk_buff
*skb
)
296 IRDA_DEBUG(4, __FUNCTION__
"()\n");
298 ASSERT(self
!= NULL
, return;);
299 ASSERT(self
->magic
== LAP_MAGIC
, return;);
301 irlmp_link_connect_confirm(self
->notify
.instance
, &self
->qos_tx
, skb
);
305 * Function irlap_data_indication (self, skb)
307 * Received data frames from IR-port, so we just pass them up to
308 * IrLMP for further processing
311 inline void irlap_data_indication(struct irlap_cb
*self
, struct sk_buff
*skb
)
313 /* Hide LAP header from IrLMP layer */
314 skb_pull(skb
, LAP_ADDR_HEADER
+LAP_CTRL_HEADER
);
316 #ifdef CONFIG_IRDA_COMPRESSION
317 if (self
->qos_tx
.compression
.value
) {
318 skb
= irlap_decompress_frame(self
, skb
);
320 IRDA_DEBUG(1, __FUNCTION__
"(), Decompress error!\n");
325 irlmp_link_data_indication(self
->notify
.instance
, LAP_RELIABLE
, skb
);
329 * Function irlap_unit_data_indication (self, skb)
331 * Received some data that was sent unreliable
334 void irlap_unit_data_indication(struct irlap_cb
*self
, struct sk_buff
*skb
)
336 IRDA_DEBUG(1, __FUNCTION__
"()\n");
338 ASSERT(self
!= NULL
, return;);
339 ASSERT(self
->magic
== LAP_MAGIC
, return;);
340 ASSERT(skb
!= NULL
, return;);
342 /* Hide LAP header from IrLMP layer */
343 skb_pull(skb
, LAP_ADDR_HEADER
+LAP_CTRL_HEADER
);
345 #ifdef CONFIG_IRDA_COMPRESSION
346 if (self
->qos_tx
.compression
.value
) {
348 skb
= irlap_decompress_frame(self
, skb
);
350 IRDA_DEBUG(1, __FUNCTION__
"(), Decompress error!\n");
355 irlmp_link_data_indication(self
->notify
.instance
, LAP_UNRELIABLE
, skb
);
359 * Function irlap_data_request (self, skb)
361 * Queue data for transmission, must wait until XMIT state
364 inline void irlap_data_request(struct irlap_cb
*self
, struct sk_buff
*skb
,
367 ASSERT(self
!= NULL
, return;);
368 ASSERT(self
->magic
== LAP_MAGIC
, return;);
370 #ifdef CONFIG_IRDA_COMPRESSION
371 if (self
->qos_tx
.compression
.value
) {
372 skb
= irlap_compress_frame(self
, skb
);
374 IRDA_DEBUG(1, __FUNCTION__
"(), Compress error!\n");
380 ASSERT(skb_headroom(skb
) >= (LAP_ADDR_HEADER
+LAP_CTRL_HEADER
),
382 skb_push(skb
, LAP_ADDR_HEADER
+LAP_CTRL_HEADER
);
385 * Must set frame format now so that the rest of the code knows
386 * if its dealing with an I or an UI frame
389 skb
->data
[1] = I_FRAME
;
391 IRDA_DEBUG(4, __FUNCTION__
"(), queueing unreliable frame\n");
392 skb
->data
[1] = UI_FRAME
;
396 * Send event if this frame only if we are in the right state
397 * FIXME: udata should be sent first! (skb_queue_head?)
399 if ((self
->state
== LAP_XMIT_P
) || (self
->state
== LAP_XMIT_S
)) {
401 * Check if the transmit queue contains some unsent frames,
402 * and if so, make sure they are sent first
404 if (!skb_queue_empty(&self
->tx_list
)) {
405 skb_queue_tail(&self
->tx_list
, skb
);
406 skb
= skb_dequeue(&self
->tx_list
);
408 ASSERT(skb
!= NULL
, return;);
410 irlap_do_event(self
, SEND_I_CMD
, skb
, NULL
);
412 skb_queue_tail(&self
->tx_list
, skb
);
416 * Function irlap_disconnect_request (void)
418 * Request to disconnect connection by service user
420 void irlap_disconnect_request(struct irlap_cb
*self
)
422 IRDA_DEBUG(3, __FUNCTION__
"()\n");
424 ASSERT(self
!= NULL
, return;);
425 ASSERT(self
->magic
== LAP_MAGIC
, return;);
427 /* Don't disconnect until all data frames are successfully sent */
428 if (skb_queue_len(&self
->tx_list
) > 0) {
429 self
->disconnect_pending
= TRUE
;
434 /* Check if we are in the right state for disconnecting */
435 switch (self
->state
) {
436 case LAP_XMIT_P
: /* FALLTROUGH */
437 case LAP_XMIT_S
: /* FALLTROUGH */
438 case LAP_CONN
: /* FALLTROUGH */
439 case LAP_RESET_WAIT
: /* FALLTROUGH */
440 case LAP_RESET_CHECK
:
441 irlap_do_event(self
, DISCONNECT_REQUEST
, NULL
, NULL
);
444 IRDA_DEBUG(2, __FUNCTION__
"(), disconnect pending!\n");
445 self
->disconnect_pending
= TRUE
;
451 * Function irlap_disconnect_indication (void)
453 * Disconnect request from other device
456 void irlap_disconnect_indication(struct irlap_cb
*self
, LAP_REASON reason
)
458 IRDA_DEBUG(1, __FUNCTION__
"(), reason=%s\n", lap_reasons
[reason
]);
460 ASSERT(self
!= NULL
, return;);
461 ASSERT(self
->magic
== LAP_MAGIC
, return;);
463 #ifdef CONFIG_IRDA_COMPRESSION
464 irda_free_compression(self
);
467 irlap_flush_all_queues(self
);
470 case LAP_RESET_INDICATION
:
471 IRDA_DEBUG(1, __FUNCTION__
"(), Sending reset request!\n");
472 irlap_do_event(self
, RESET_REQUEST
, NULL
, NULL
);
474 case LAP_NO_RESPONSE
: /* FALLTROUGH */
475 case LAP_DISC_INDICATION
: /* FALLTROUGH */
476 case LAP_FOUND_NONE
: /* FALLTROUGH */
478 irlmp_link_disconnect_indication(self
->notify
.instance
, self
,
482 IRDA_DEBUG(1, __FUNCTION__
"(), Reason %d not implemented!\n",
488 * Function irlap_discovery_request (gen_addr_bit)
490 * Start one single discovery operation.
493 void irlap_discovery_request(struct irlap_cb
*self
, discovery_t
*discovery
)
495 struct irlap_info info
;
497 ASSERT(self
!= NULL
, return;);
498 ASSERT(self
->magic
== LAP_MAGIC
, return;);
499 ASSERT(discovery
!= NULL
, return;);
501 IRDA_DEBUG(4, __FUNCTION__
"(), nslots = %d\n", discovery
->nslots
);
503 ASSERT((discovery
->nslots
== 1) || (discovery
->nslots
== 6) ||
504 (discovery
->nslots
== 8) || (discovery
->nslots
== 16),
507 /* Check if last discovery request finished in time */
508 if (self
->discovery_log
!= NULL
) {
509 hashbin_delete(self
->discovery_log
, (FREE_FUNC
) kfree
);
510 self
->discovery_log
= NULL
;
514 * Discovery is only possible in NDM mode
516 if (self
->state
== LAP_NDM
) {
517 self
->discovery_log
= hashbin_new(HB_LOCAL
);
519 info
.S
= discovery
->nslots
; /* Number of slots */
520 info
.s
= 0; /* Current slot */
522 self
->discovery_cmd
= discovery
;
523 info
.discovery
= discovery
;
525 /* Check if the slot timeout is within limits */
526 if (sysctl_slot_timeout
< 20) {
528 "(), to low value for slot timeout!\n");
529 sysctl_slot_timeout
= 20;
532 * Highest value is actually 8, but we allow higher since
533 * some devices seems to require it.
535 if (sysctl_slot_timeout
> 160) {
537 "(), to high value for slot timeout!\n");
538 sysctl_slot_timeout
= 160;
541 self
->slot_timeout
= sysctl_slot_timeout
* HZ
/ 1000;
543 irlap_do_event(self
, DISCOVERY_REQUEST
, NULL
, &info
);
545 IRDA_DEBUG(4, __FUNCTION__
546 "(), discovery only possible in NDM mode\n");
547 irlap_discovery_confirm(self
, NULL
);
552 * Function irlap_discovery_confirm (log)
554 * A device has been discovered in front of this station, we
555 * report directly to LMP.
557 void irlap_discovery_confirm(struct irlap_cb
*self
, hashbin_t
*discovery_log
)
559 ASSERT(self
!= NULL
, return;);
560 ASSERT(self
->magic
== LAP_MAGIC
, return;);
562 ASSERT(self
->notify
.instance
!= NULL
, return;);
565 * Check for successful discovery, since we are then allowed to clear
566 * the media busy condition (irlap p.94). This should allow us to make
567 * connection attempts much easier.
569 if (discovery_log
&& HASHBIN_GET_SIZE(discovery_log
) > 0)
570 irda_device_set_media_busy(self
->netdev
, FALSE
);
573 irlmp_link_discovery_confirm(self
->notify
.instance
, discovery_log
);
577 * Function irlap_discovery_indication (log)
579 * Somebody is trying to discover us!
582 void irlap_discovery_indication(struct irlap_cb
*self
, discovery_t
*discovery
)
584 IRDA_DEBUG(4, __FUNCTION__
"()\n");
586 ASSERT(self
!= NULL
, return;);
587 ASSERT(self
->magic
== LAP_MAGIC
, return;);
588 ASSERT(discovery
!= NULL
, return;);
590 ASSERT(self
->notify
.instance
!= NULL
, return;);
592 irlmp_link_discovery_indication(self
->notify
.instance
, discovery
);
596 * Function irlap_status_indication (quality_of_link)
601 void irlap_status_indication(int quality_of_link
)
603 switch (quality_of_link
) {
604 case STATUS_NO_ACTIVITY
:
605 MESSAGE("IrLAP, no activity on link!\n");
608 MESSAGE("IrLAP, noisy link!\n");
613 irlmp_status_indication(quality_of_link
, LOCK_NO_CHANGE
);
617 * Function irlap_reset_indication (void)
622 void irlap_reset_indication(struct irlap_cb
*self
)
624 IRDA_DEBUG(1, __FUNCTION__
"()\n");
626 ASSERT(self
!= NULL
, return;);
627 ASSERT(self
->magic
== LAP_MAGIC
, return;);
629 if (self
->state
== LAP_RESET_WAIT
)
630 irlap_do_event(self
, RESET_REQUEST
, NULL
, NULL
);
632 irlap_do_event(self
, RESET_RESPONSE
, NULL
, NULL
);
636 * Function irlap_reset_confirm (void)
641 void irlap_reset_confirm(void)
643 IRDA_DEBUG(1, __FUNCTION__
"()\n");
647 * Function irlap_generate_rand_time_slot (S, s)
649 * Generate a random time slot between s and S-1 where
650 * S = Number of slots (0 -> S-1)
653 int irlap_generate_rand_time_slot(int S
, int s
)
657 ASSERT((S
- s
) > 0, return 0;);
659 slot
= s
+ jiffies
% (S
-s
);
661 ASSERT((slot
>= s
) || (slot
< S
), return 0;);
667 * Function irlap_update_nr_received (nr)
669 * Remove all acknowledged frames in current window queue. This code is
670 * not intuitive and you should not try to change it. If you think it
671 * contains bugs, please mail a patch to the author instead.
673 void irlap_update_nr_received(struct irlap_cb
*self
, int nr
)
675 struct sk_buff
*skb
= NULL
;
679 * Remove all the ack-ed frames from the window queue.
683 * Optimize for the common case. It is most likely that the receiver
684 * will acknowledge all the frames we have sent! So in that case we
685 * delete all frames stored in window.
687 if (nr
== self
->vs
) {
688 while ((skb
= skb_dequeue(&self
->wx_list
)) != NULL
) {
691 /* The last acked frame is the next to send minus one */
694 /* Remove all acknowledged frames in current window */
695 while ((skb_peek(&self
->wx_list
) != NULL
) &&
696 (((self
->va
+1) % 8) != nr
))
698 skb
= skb_dequeue(&self
->wx_list
);
701 self
->va
= (self
->va
+ 1) % 8;
707 self
->window
= self
->window_size
- skb_queue_len(&self
->wx_list
);
711 * Function irlap_validate_ns_received (ns)
713 * Validate the next to send (ns) field from received frame.
715 int irlap_validate_ns_received(struct irlap_cb
*self
, int ns
)
717 /* ns as expected? */
721 * Stations are allowed to treat invalid NS as unexpected NS
722 * IrLAP, Recv ... with-invalid-Ns. p. 84
724 return NS_UNEXPECTED
;
726 /* return NR_INVALID; */
729 * Function irlap_validate_nr_received (nr)
731 * Validate the next to receive (nr) field from received frame.
734 int irlap_validate_nr_received(struct irlap_cb
*self
, int nr
)
736 /* nr as expected? */
737 if (nr
== self
->vs
) {
738 IRDA_DEBUG(4, __FUNCTION__
"(), expected!\n");
743 * unexpected nr? (but within current window), first we check if the
744 * ns numbers of the frames in the current window wrap.
746 if (self
->va
< self
->vs
) {
747 if ((nr
>= self
->va
) && (nr
<= self
->vs
))
748 return NR_UNEXPECTED
;
750 if ((nr
>= self
->va
) || (nr
<= self
->vs
))
751 return NR_UNEXPECTED
;
759 * Function irlap_initiate_connection_state ()
761 * Initialize the connection state parameters
764 void irlap_initiate_connection_state(struct irlap_cb
*self
)
766 IRDA_DEBUG(4, __FUNCTION__
"()\n");
768 ASSERT(self
!= NULL
, return;);
769 ASSERT(self
->magic
== LAP_MAGIC
, return;);
771 /* Next to send and next to receive */
772 self
->vs
= self
->vr
= 0;
774 /* Last frame which got acked (0 - 1) % 8 */
779 self
->remote_busy
= FALSE
;
780 self
->retry_count
= 0;
784 * Function irlap_wait_min_turn_around (self, qos)
786 * Wait negotiated minimum turn around time, this function actually sets
787 * the number of BOS's that must be sent before the next transmitted
788 * frame in order to delay for the specified amount of time. This is
789 * done to avoid using timers, and the forbidden udelay!
791 void irlap_wait_min_turn_around(struct irlap_cb
*self
, struct qos_info
*qos
)
797 /* Get QoS values. */
798 speed
= qos
->baud_rate
.value
;
799 usecs
= qos
->min_turn_time
.value
;
801 /* No need to calculate XBOFs for speeds over 115200 bps */
802 if (speed
> 115200) {
803 self
->mtt_required
= usecs
;
808 * Send additional BOF's for the next frame for the requested
809 * min turn time, so now we must calculate how many chars (XBOF's) we
810 * must send for the requested time period (min turn time)
812 bytes
= speed
* usecs
/ 10000000;
814 self
->xbofs_delay
= bytes
;
818 * Function irlap_flush_all_queues (void)
823 void irlap_flush_all_queues(struct irlap_cb
*self
)
827 ASSERT(self
!= NULL
, return;);
828 ASSERT(self
->magic
== LAP_MAGIC
, return;);
830 /* Free transmission queue */
831 while ((skb
= skb_dequeue(&self
->tx_list
)) != NULL
)
834 /* Free sliding window buffered packets */
835 while ((skb
= skb_dequeue(&self
->wx_list
)) != NULL
)
838 #ifdef CONFIG_IRDA_RECYCLE_RR
839 if (self
->recycle_rr_skb
) {
840 dev_kfree_skb(self
->recycle_rr_skb
);
841 self
->recycle_rr_skb
= NULL
;
847 * Function irlap_setspeed (self, speed)
849 * Change the speed of the IrDA port
852 void irlap_change_speed(struct irlap_cb
*self
, __u32 speed
)
854 IRDA_DEBUG(4, __FUNCTION__
"(), setting speed to %d\n", speed
);
856 ASSERT(self
!= NULL
, return;);
857 ASSERT(self
->magic
== LAP_MAGIC
, return;);
859 /* Must use the same speed in both directions */
860 self
->qos_rx
.baud_rate
.value
= speed
;
861 self
->qos_tx
.baud_rate
.value
= speed
;
864 #ifdef CONFIG_IRDA_COMPRESSION
865 void irlap_init_comp_qos_capabilities(struct irlap_cb
*self
)
867 struct irda_compressor
*comp
;
868 __u8 mask
; /* Current bit tested */
871 ASSERT(self
!= NULL
, return;);
872 ASSERT(self
->magic
== LAP_MAGIC
, return;);
875 * Find out which compressors we support. We do this be checking that
876 * the corresponding compressor for each bit set in the QoS bits has
877 * actually been loaded. Ths is sort of hairy code but that is what
878 * you get when you do a little bit flicking :-)
880 IRDA_DEBUG(4, __FUNCTION__
"(), comp bits 0x%02x\n",
881 self
->qos_rx
.compression
.bits
);
882 mask
= 0x80; /* Start with testing MSB */
884 IRDA_DEBUG(4, __FUNCTION__
"(), testing bit %d\n", 8-i
);
885 if (self
->qos_rx
.compression
.bits
& mask
) {
886 IRDA_DEBUG(4, __FUNCTION__
"(), bit %d is set by defalt\n",
888 comp
= hashbin_find(irlap_compressors
,
889 compression
[ msb_index(mask
)],
892 /* Protocol not supported, so clear the bit */
893 IRDA_DEBUG(4, __FUNCTION__
"(), Compression "
894 "protocol %d has not been loaded!\n",
895 compression
[msb_index(mask
)]);
896 self
->qos_rx
.compression
.bits
&= ~mask
;
897 IRDA_DEBUG(4, __FUNCTION__
898 "(), comp bits 0x%02x\n",
899 self
->qos_rx
.compression
.bits
);
902 /* Try the next bit */
909 * Function irlap_init_qos_capabilities (self, qos)
911 * Initialize QoS for this IrLAP session, What we do is to compute the
912 * intersection of the QoS capabilities for the user, driver and for
913 * IrLAP itself. Normally, IrLAP will not specify any values, but it can
914 * be used to restrict certain values.
916 void irlap_init_qos_capabilities(struct irlap_cb
*self
,
917 struct qos_info
*qos_user
)
919 ASSERT(self
!= NULL
, return;);
920 ASSERT(self
->magic
== LAP_MAGIC
, return;);
921 ASSERT(self
->netdev
!= NULL
, return;);
923 /* Start out with the maximum QoS support possible */
924 irda_init_max_qos_capabilies(&self
->qos_rx
);
926 #ifdef CONFIG_IRDA_COMPRESSION
927 irlap_init_comp_qos_capabilities(self
);
930 /* Apply drivers QoS capabilities */
931 irda_qos_compute_intersection(&self
->qos_rx
, self
->qos_dev
);
934 * Check for user supplied QoS parameters. The service user is only
935 * allowed to supply these values. We check each parameter since the
936 * user may not have set all of them.
939 IRDA_DEBUG(1, __FUNCTION__
"(), Found user specified QoS!\n");
941 if (qos_user
->baud_rate
.bits
)
942 self
->qos_rx
.baud_rate
.bits
&= qos_user
->baud_rate
.bits
;
944 if (qos_user
->max_turn_time
.bits
)
945 self
->qos_rx
.max_turn_time
.bits
&= qos_user
->max_turn_time
.bits
;
946 if (qos_user
->data_size
.bits
)
947 self
->qos_rx
.data_size
.bits
&= qos_user
->data_size
.bits
;
949 if (qos_user
->link_disc_time
.bits
)
950 self
->qos_rx
.link_disc_time
.bits
&= qos_user
->link_disc_time
.bits
;
951 #ifdef CONFIG_IRDA_COMPRESSION
952 self
->qos_rx
.compression
.bits
&= qos_user
->compression
.bits
;
957 * Make the intersection between IrLAP and drivers QoS
961 /* Use 500ms in IrLAP for now */
962 self
->qos_rx
.max_turn_time
.bits
&= 0x03;
963 self
->qos_rx
.max_turn_time
.bits
&= 0x01;
966 /* self->qos_rx.data_size.bits &= 0x03; */
968 /* Set disconnect time */
969 self
->qos_rx
.link_disc_time
.bits
&= 0x07;
971 irda_qos_bits_to_value(&self
->qos_rx
);
975 * Function irlap_apply_default_connection_parameters (void)
977 * Use the default connection and transmission parameters
980 void irlap_apply_default_connection_parameters(struct irlap_cb
*self
)
982 IRDA_DEBUG(4, __FUNCTION__
"()\n");
984 ASSERT(self
!= NULL
, return;);
985 ASSERT(self
->magic
== LAP_MAGIC
, return;);
987 irlap_change_speed(self
, 9600);
989 /* Default value in NDM */
990 self
->bofs_count
= 11;
992 /* Use these until connection has been made */
993 self
->slot_timeout
= sysctl_slot_timeout
;
994 self
->final_timeout
= FINAL_TIMEOUT
;
995 self
->poll_timeout
= POLL_TIMEOUT
;
996 self
->wd_timeout
= WD_TIMEOUT
;
998 self
->qos_tx
.data_size
.value
= 64;
999 self
->qos_tx
.additional_bofs
.value
= 11;
1001 irlap_flush_all_queues(self
);
1003 self
->disconnect_pending
= FALSE
;
1007 * Function irlap_apply_connection_parameters (qos)
1009 * Initialize IrLAP with the negotiated QoS values
1012 void irlap_apply_connection_parameters(struct irlap_cb
*self
,
1013 struct qos_info
*qos
)
1015 IRDA_DEBUG(4, __FUNCTION__
"()\n");
1017 ASSERT(self
!= NULL
, return;);
1018 ASSERT(self
->magic
== LAP_MAGIC
, return;);
1020 irlap_change_speed(self
, qos
->baud_rate
.value
);
1022 self
->window_size
= qos
->window_size
.value
;
1023 self
->window
= qos
->window_size
.value
;
1024 self
->bofs_count
= qos
->additional_bofs
.value
;
1027 * Calculate how many bytes it is possible to transmit before the
1028 * link must be turned around wb = baud * mtt/1000 * 1/2
1030 self
->window_bytes
= qos
->baud_rate
.value
1031 * qos
->max_turn_time
.value
/ 10000;
1032 IRDA_DEBUG(4, "Setting window_bytes = %d\n", self
->window_bytes
);
1035 * Set N1 to 0 if Link Disconnect/Threshold Time = 3 and set it to
1036 * 3 seconds otherwise. See page 71 in IrLAP for more details.
1037 * TODO: these values should be calculated from the final timer
1040 if (qos
->link_disc_time
.value
== 3)
1043 self
->N1
= 3000 / qos
->max_turn_time
.value
;
1045 IRDA_DEBUG(4, "Setting N1 = %d\n", self
->N1
);
1047 self
->N2
= qos
->link_disc_time
.value
* 1000 / qos
->max_turn_time
.value
;
1048 IRDA_DEBUG(4, "Setting N2 = %d\n", self
->N2
);
1051 * Initialize timeout values, some of the rules are listed on
1054 self
->poll_timeout
= qos
->max_turn_time
.value
* HZ
/ 1000;
1055 self
->final_timeout
= qos
->max_turn_time
.value
* HZ
/ 1000;
1056 self
->wd_timeout
= self
->poll_timeout
* 2;
1058 #ifdef CONFIG_IRDA_COMPRESSION
1059 if (qos
->compression
.value
) {
1060 IRDA_DEBUG(1, __FUNCTION__
"(), Initializing compression\n");
1061 irda_set_compression(self
, qos
->compression
.value
);
1063 irlap_compressor_init(self
, 0);
1069 * Function irlap_set_local_busy (self, status)
1074 void irlap_set_local_busy(struct irlap_cb
*self
, int status
)
1076 IRDA_DEBUG(0, __FUNCTION__
"()\n");
1078 self
->local_busy
= status
;
1081 IRDA_DEBUG(0, __FUNCTION__
"(), local busy ON\n");
1083 IRDA_DEBUG(0, __FUNCTION__
"(), local busy OFF\n");
1086 #ifdef CONFIG_PROC_FS
1088 * Function irlap_proc_read (buf, start, offset, len, unused)
1090 * Give some info to the /proc file system
1093 int irlap_proc_read(char *buf
, char **start
, off_t offset
, int len
,
1096 struct irlap_cb
*self
;
1097 unsigned long flags
;
1105 self
= (struct irlap_cb
*) hashbin_get_first(irlap
);
1106 while (self
!= NULL
) {
1107 ASSERT(self
!= NULL
, return -ENODEV
;);
1108 ASSERT(self
->magic
== LAP_MAGIC
, return -EBADR
;);
1110 len
+= sprintf(buf
+len
, "irlap%d ", i
++);
1111 len
+= sprintf(buf
+len
, "state: %s\n",
1112 irlap_state
[ self
->state
]);
1114 len
+= sprintf(buf
+len
, " caddr: %#02x, ", self
->caddr
);
1115 len
+= sprintf(buf
+len
, "saddr: %#08x, ", self
->saddr
);
1116 len
+= sprintf(buf
+len
, "daddr: %#08x\n", self
->daddr
);
1118 len
+= sprintf(buf
+len
, " win size: %d, ",
1120 len
+= sprintf(buf
+len
, "win: %d, ", self
->window
);
1121 len
+= sprintf(buf
+len
, "win bytes: %d, ", self
->window_bytes
);
1122 len
+= sprintf(buf
+len
, "bytes left: %d\n", self
->bytes_left
);
1124 len
+= sprintf(buf
+len
, " tx queue len: %d ",
1125 skb_queue_len(&self
->tx_list
));
1126 len
+= sprintf(buf
+len
, "win queue len: %d ",
1127 skb_queue_len(&self
->wx_list
));
1128 len
+= sprintf(buf
+len
, "rbusy: %s\n", self
->remote_busy
?
1131 len
+= sprintf(buf
+len
, " retrans: %d ", self
->retry_count
);
1132 len
+= sprintf(buf
+len
, "vs: %d ", self
->vs
);
1133 len
+= sprintf(buf
+len
, "vr: %d ", self
->vr
);
1134 len
+= sprintf(buf
+len
, "va: %d\n", self
->va
);
1136 len
+= sprintf(buf
+len
, " qos\tbps\tmaxtt\tdsize\twinsize\taddbofs\tmintt\tldisc\tcomp\n");
1138 len
+= sprintf(buf
+len
, " tx\t%d\t",
1139 self
->qos_tx
.baud_rate
.value
);
1140 len
+= sprintf(buf
+len
, "%d\t",
1141 self
->qos_tx
.max_turn_time
.value
);
1142 len
+= sprintf(buf
+len
, "%d\t",
1143 self
->qos_tx
.data_size
.value
);
1144 len
+= sprintf(buf
+len
, "%d\t",
1145 self
->qos_tx
.window_size
.value
);
1146 len
+= sprintf(buf
+len
, "%d\t",
1147 self
->qos_tx
.additional_bofs
.value
);
1148 len
+= sprintf(buf
+len
, "%d\t",
1149 self
->qos_tx
.min_turn_time
.value
);
1150 len
+= sprintf(buf
+len
, "%d\t",
1151 self
->qos_tx
.link_disc_time
.value
);
1152 #ifdef CONFIG_IRDA_COMPRESSION
1153 len
+= sprintf(buf
+len
, "%d",
1154 self
->qos_tx
.compression
.value
);
1156 len
+= sprintf(buf
+len
, "\n");
1158 len
+= sprintf(buf
+len
, " rx\t%d\t",
1159 self
->qos_rx
.baud_rate
.value
);
1160 len
+= sprintf(buf
+len
, "%d\t",
1161 self
->qos_rx
.max_turn_time
.value
);
1162 len
+= sprintf(buf
+len
, "%d\t",
1163 self
->qos_rx
.data_size
.value
);
1164 len
+= sprintf(buf
+len
, "%d\t",
1165 self
->qos_rx
.window_size
.value
);
1166 len
+= sprintf(buf
+len
, "%d\t",
1167 self
->qos_rx
.additional_bofs
.value
);
1168 len
+= sprintf(buf
+len
, "%d\t",
1169 self
->qos_rx
.min_turn_time
.value
);
1170 len
+= sprintf(buf
+len
, "%d\t",
1171 self
->qos_rx
.link_disc_time
.value
);
1172 #ifdef CONFIG_IRDA_COMPRESSION
1173 len
+= sprintf(buf
+len
, "%d",
1174 self
->qos_rx
.compression
.value
);
1176 len
+= sprintf(buf
+len
, "\n");
1178 self
= (struct irlap_cb
*) hashbin_get_next(irlap
);
1180 restore_flags(flags
);
1185 #endif /* CONFIG_PROC_FS */