28 #include <linux/string.h>
29 #include <linux/kernel.h>
32 #include <linux/slab.h>
46 #ifdef CONFIG_IRDA_FAST_RR
81 #ifdef CONFIG_IRDA_DEBUG
82 static const char *
const irlap_event[] = {
92 "RECV_DISCOVERY_XID_CMD",
93 "RECV_DISCOVERY_XID_RSP",
113 "SLOT_TIMER_EXPIRED",
114 "QUERY_TIMER_EXPIRED",
115 "FINAL_TIMER_EXPIRED",
116 "POLL_TIMER_EXPIRED",
117 "DISCOVERY_TIMER_EXPIRED",
119 "BACKOFF_TIMER_EXPIRED",
120 "MEDIA_BUSY_TIMER_EXPIRED",
154 irlap_state_reset_wait,
159 irlap_state_reset_check,
168 static void irlap_poll_timer_expired(
void *
data)
184 static void irlap_start_poll_timer(
struct irlap_cb *
self,
int timeout)
189 #ifdef CONFIG_IRDA_FAST_RR
194 if (skb_queue_empty(&self->txq) || self->remote_busy) {
195 if (self->fast_RR ==
TRUE) {
200 if (self->fast_RR_timeout < timeout) {
205 self->fast_RR_timeout +=
209 timeout =
self->fast_RR_timeout;
212 self->fast_RR =
TRUE;
215 self->fast_RR_timeout = 0;
219 self->fast_RR =
FALSE;
221 IRDA_DEBUG(3,
"%s(), timeout=%d (%ld)\n", __func__, timeout, jiffies);
227 irda_start_timer(&self->poll_timer, timeout,
self,
228 irlap_poll_timer_expired);
245 IRDA_DEBUG(3,
"%s(), event = %s, state = %s\n", __func__,
248 ret = (*
state[
self->state])(
self, event, skb, info);
253 switch (self->state) {
263 IRDA_DEBUG(2,
"%s() : queue len = %d\n", __func__,
264 skb_queue_len(&self->txq));
266 if (!skb_queue_empty(&self->txq)) {
268 self->local_busy =
TRUE;
303 self->local_busy =
FALSE;
304 }
else if (self->disconnect_pending) {
305 self->disconnect_pending =
FALSE;
339 if (self->media_busy) {
343 IRDA_DEBUG(0,
"%s(), CONNECT_REQUEST: media busy!\n",
347 irlap_next_state(
self,
LAP_NDM);
356 self->retry_count = 0;
363 self->daddr = info->
daddr;
364 self->caddr = info->
caddr;
371 "contain an I field!\n", __func__);
377 if (self->media_busy) {
378 IRDA_DEBUG(1,
"%s(), DISCOVERY_REQUEST: media busy!\n",
394 self->frame_sent =
FALSE;
404 if (info->
s <= info->
S) {
407 if (self->slot == info->
s) {
415 self->frame_sent =
TRUE;
417 self->frame_sent =
FALSE;
445 IRDA_DEBUG(1,
"%s(), Receiving final discovery request, missed the discovery slots :-(\n", __func__);
461 #ifdef CONFIG_IRDA_ULTRA
463 if (!skb_queue_empty(&self->txq_ultra)) {
473 if (self->connect_pending) {
474 self->connect_pending =
FALSE;
479 if (self->disconnect_pending)
482 ret = (*
state[
self->state])(
self,
485 self->disconnect_pending =
FALSE;
499 #ifdef CONFIG_IRDA_ULTRA
504 for (i=0; ((i<2) && (self->media_busy ==
FALSE)); i++) {
523 IRDA_DEBUG(0,
"%s(), not a broadcast frame!\n",
526 irlap_unitdata_indication(
self, skb);
540 IRDA_DEBUG(0,
"%s() not implemented!\n", __func__);
543 IRDA_DEBUG(2,
"%s(), Unknown event %s\n", __func__,
574 if (!self->discovery_log) {
576 "maybe the discovery timeout has been set"
577 " too short?\n", __func__);
602 IRDA_DEBUG(1,
"%s(), Receiving discovery request (s = %d) while performing discovery :-(\n", __func__, info->
s);
616 IRDA_DEBUG(2,
"%s(), device is slow to answer, "
617 "waiting some more!\n", __func__);
619 self->add_wait =
TRUE;
622 self->add_wait =
FALSE;
624 if (self->s < self->S) {
627 self->discovery_cmd);
637 self->discovery_cmd);
640 irlap_next_state(
self,
LAP_NDM);
649 self->discovery_log =
NULL;
653 IRDA_DEBUG(2,
"%s(), Unknown event %s\n", __func__,
682 IRDA_DEBUG(0,
"%s(), QUERY_TIMER_EXPIRED <%ld>\n",
684 irlap_next_state(
self,
LAP_NDM);
689 if (info->
s == 0xff) {
695 irlap_next_state(
self,
LAP_NDM);
700 if ((info->
s >= self->slot) && (!self->frame_sent)) {
709 self->frame_sent =
TRUE;
721 IRDA_DEBUG(1,
"%s(), Unknown event %d, %s\n", __func__,
722 event, irlap_event[event]);
742 IRDA_DEBUG(4,
"%s(), event=%s\n", __func__, irlap_event[ event]);
802 IRDA_DEBUG(3,
"%s(), event RECV_DISCOVER_XID_CMD!\n",
804 irlap_next_state(
self,
LAP_NDM);
808 IRDA_DEBUG(0,
"%s(), Disconnect request!\n", __func__);
810 irlap_next_state(
self,
LAP_NDM);
814 IRDA_DEBUG(1,
"%s(), Unknown event %d, %s\n", __func__,
815 event, irlap_event[event]);
843 if (self->retry_count < self->N3) {
854 irlap_next_state(
self,
LAP_NDM);
865 IRDA_DEBUG(4,
"%s(), SNRM battle!\n", __func__);
874 if (info &&(info->
daddr > self->saddr)) {
920 self->retry_count = 0;
947 irlap_next_state(
self,
LAP_NDM);
952 IRDA_DEBUG(1,
"%s(), Unknown event %d, %s\n", __func__,
953 event, irlap_event[event]);
970 IRDA_DEBUG( 0,
"%s(), Unknown event\n", __func__);
993 if ((self->window > 0) && (!self->remote_busy)) {
995 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
1010 skb_next = skb_peek(&self->txq);
1021 nextfit = ((skb_next !=
NULL) &&
1022 ((skb_next->
len + skb->
len) <=
1032 if((!nextfit) && (skb->
len >
self->bytes_left)) {
1033 IRDA_DEBUG(0,
"%s(), Not allowed to transmit"
1034 " more bytes!\n", __func__);
1056 self->bytes_left -= skb->
len;
1060 nextfit = !skb_queue_empty(&self->txq);
1066 if ((self->window > 1) && (nextfit)) {
1080 #ifdef CONFIG_IRDA_FAST_RR
1082 self->fast_RR =
FALSE;
1085 IRDA_DEBUG(4,
"%s(), Unable to send! remote busy?\n",
1097 IRDA_DEBUG(3,
"%s(), POLL_TIMER_EXPIRED <%ld>\n",
1101 self->window =
self->window_size;
1102 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
1104 self->bytes_left =
self->line_capacity;
1115 self->retry_count = 0;
1124 __func__, irlap_event[event]);
1156 irlap_next_state(
self,
LAP_NDM);
1161 if (self->retry_count < self->N3) {
1165 self->retry_count++;
1171 irlap_next_state(
self,
LAP_NDM);
1177 IRDA_DEBUG(1,
"%s(), Unknown event %d\n", __func__, event);
1217 #ifdef CONFIG_IRDA_FAST_RR
1223 self->fast_RR =
FALSE;
1236 self->vr = (
self->vr + 1) % 8;
1246 self->retry_count = 0;
1247 self->ack_required =
TRUE;
1280 irlap_start_poll_timer(
self, self->poll_timeout);
1300 "%s(), missing or duplicate frame!\n",
1309 self->ack_required =
FALSE;
1322 self->vr = (
self->vr + 1) % 8;
1330 self->ack_required =
FALSE;
1349 self->vr = (
self->vr + 1) % 8;
1354 self->ack_required =
FALSE;
1370 IRDA_DEBUG(4,
"%s(), unexpected nr and ns!\n",
1386 self->ack_required =
FALSE;
1401 self->xmitflag =
TRUE;
1407 self->xmitflag =
FALSE;
1411 IRDA_DEBUG(1,
"%s(), Not implemented!\n", __func__);
1412 IRDA_DEBUG(1,
"%s(), event=%s, ns_status=%d, nr_status=%d\n",
1413 __func__, irlap_event[event], ns_status, nr_status);
1425 irlap_start_poll_timer(
self, self->poll_timeout);
1433 self->remote_busy =
FALSE;
1451 self->retry_count = 0;
1457 irlap_start_poll_timer(
self, self->poll_timeout);
1467 IRDA_DEBUG(4,
"RECV_RR_FRAME: Retrans:%d, nr=%d, va=%d, "
1469 self->retry_count, info->
nr, self->va,
1470 self->vs, self->vr);
1479 "invalid nr !\n", __func__);
1484 self->xmitflag =
TRUE;
1492 self->remote_busy =
TRUE;
1499 irlap_start_poll_timer(
self, self->poll_timeout);
1503 self->xmitflag =
TRUE;
1515 IRDA_DEBUG(1,
"FINAL_TIMER_EXPIRED when receiving a "
1516 "frame! Waiting a little bit more!\n");
1524 self->add_wait =
TRUE;
1527 self->add_wait =
FALSE;
1530 if (self->retry_count < self->N2) {
1531 if (skb_peek(&self->wx_list) ==
NULL) {
1542 self->retry_count++;
1543 IRDA_DEBUG(4,
"irlap_state_nrm_p: FINAL_TIMER_EXPIRED:"
1544 " retry_count=%d\n", self->retry_count);
1552 if((self->retry_count % self->N1) == 0)
1561 irlap_next_state(
self,
LAP_NDM);
1567 if (self->remote_busy) {
1576 if (self->remote_busy) {
1584 IRDA_DEBUG(1,
"%s(), RECV_RD_RSP\n", __func__);
1593 __func__, irlap_event[event]);
1613 IRDA_DEBUG(3,
"%s(), event = %s\n", __func__, irlap_event[event]);
1620 if (self->xmitflag) {
1635 self->retry_count = 0;
1639 IRDA_DEBUG(2,
"%s(), Unknown event %s\n", __func__,
1640 irlap_event[event]);
1660 IRDA_DEBUG(3,
"%s(), event = %s\n", __func__, irlap_event[event]);
1672 irlap_next_state(
self,
LAP_NDM);
1685 self->remote_busy =
FALSE;
1689 irlap_start_poll_timer(
self, self->poll_timeout);
1693 if (self->retry_count < 3) {
1699 self->retry_count++;
1703 }
else if (self->retry_count >= self->N3) {
1707 irlap_next_state(
self,
LAP_NDM);
1718 IRDA_DEBUG(3,
"%s(), RECV_SNRM_CMD\n", __func__);
1724 irlap_next_state(
self,
LAP_NDM);
1727 "%s(), SNRM frame contained an I field!\n",
1733 __func__, irlap_event[event]);
1753 IRDA_DEBUG(4,
"%s(), event=%s\n", __func__, irlap_event[event]);
1763 if ((self->window > 0) && (!self->remote_busy)) {
1765 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
1778 skb_next = skb_peek(&self->txq);
1779 nextfit = ((skb_next !=
NULL) &&
1780 ((skb_next->
len + skb->
len) <=
1788 if((!nextfit) && (skb->
len >
self->bytes_left)) {
1789 IRDA_DEBUG(0,
"%s(), Not allowed to transmit"
1790 " more bytes!\n", __func__);
1800 self->window =
self->window_size;
1801 self->bytes_left =
self->line_capacity;
1812 self->bytes_left -= skb->
len;
1816 nextfit = !skb_queue_empty(&self->txq);
1822 if ((self->window > 1) && (nextfit)) {
1836 IRDA_DEBUG(2,
"%s(), Unable to send!\n", __func__);
1852 IRDA_DEBUG(2,
"%s(), Unknown event %s\n", __func__,
1853 irlap_event[event]);
1875 IRDA_DEBUG(4,
"%s(), event=%s\n", __func__, irlap_event[ event]);
1883 IRDA_DEBUG(4,
"%s(), event=%s nr=%d, vs=%d, ns=%d, "
1884 "vr=%d, pf=%d\n", __func__,
1885 irlap_event[event], info->
nr,
1886 self->vs, info->
ns, self->vr, info->
pf);
1888 self->retry_count = 0;
1898 self->vr = (
self->vr + 1) % 8;
1908 self->ack_required =
TRUE;
1915 irda_start_timer(
WD_TIMER, self->wd_timeout);
1939 if (!skb_queue_empty(&self->txq) &&
1942 self->ack_required =
TRUE;
1986 IRDA_DEBUG(4,
"RECV_I_RSP: frame(s) lost\n");
1988 self->vr = (
self->vr + 1) % 8;
2008 self->vr = (
self->vr + 1) % 8;
2023 IRDA_DEBUG(0,
"NRM_S, NR_INVALID not implemented!\n");
2026 IRDA_DEBUG(0,
"NRM_S, NS_INVALID not implemented!\n");
2040 if (!skb_queue_empty(&self->txq) &&
2041 (self->window > 0) && !self->remote_busy)
2054 self->ack_required =
FALSE;
2064 self->retry_count = 0;
2071 if (!skb_queue_empty(&self->txq) &&
2072 (self->window > 0)) {
2073 self->remote_busy =
FALSE;
2082 self->remote_busy =
FALSE;
2092 if (self->disconnect_pending) {
2106 self->remote_busy =
FALSE;
2115 IRDA_DEBUG(1,
"%s(), invalid nr not implemented!\n",
2123 IRDA_DEBUG(1,
"%s(), received SNRM cmd\n", __func__);
2129 "%s(), SNRM frame contained an I-field!\n",
2136 if (self->remote_busy) {
2145 if (self->remote_busy) {
2162 IRDA_DEBUG(1,
"%s(), retry_count = %d\n", __func__,
2165 if (self->retry_count < (self->N2 / 2)) {
2168 self->retry_count++;
2170 if((self->retry_count % (self->N1 / 2)) == 0)
2177 irlap_next_state(
self,
LAP_NDM);
2183 irlap_next_state(
self,
LAP_NDM);
2199 self->ack_required =
TRUE;
2215 IRDA_DEBUG(1,
"%s(), Unknown event %d, (%s)\n", __func__,
2216 event, irlap_event[event]);
2238 irlap_next_state(
self,
LAP_NDM);
2260 irlap_next_state(
self,
LAP_NDM);
2269 irlap_next_state(
self,
LAP_NDM);
2279 if (info !=
NULL && info->
pf) {
2287 IRDA_DEBUG(1,
"%s(), Unknown event %d, (%s)\n", __func__,
2288 event, irlap_event[event]);
2302 IRDA_DEBUG(1,
"%s(), event=%s\n", __func__, irlap_event[event]);
2323 IRDA_DEBUG(1,
"%s(), Unknown event %d, (%s)\n", __func__,
2324 event, irlap_event[event]);