29 #include <linux/if_ether.h>
30 #include <linux/netdevice.h>
32 #include <linux/slab.h>
37 #include <asm/byteorder.h>
57 static inline void irlap_insert_info(
struct irlap_cb *
self,
67 cb->
mtt = self->mtt_required;
71 self->mtt_required = 0;
77 cb->
xbofs = self->bofs_count;
82 self->xbofs_delay = 0;
84 self->bofs_count = self->next_bofs;
96 skb->
dev =
self->netdev;
97 skb_reset_mac_header(skb);
98 skb_reset_network_header(skb);
99 skb_reset_transport_header(skb);
103 irlap_insert_info(
self, skb);
106 IRDA_DEBUG(3,
"%s(): %s is in monitor mode\n", __func__,
130 tx_skb = alloc_skb(
sizeof(
struct snrm_frame) +
155 frame->
ncaddr =
self->caddr;
159 dev_kfree_skb(tx_skb);
177 if (pskb_may_pull(skb,
sizeof(
struct snrm_frame))) {
185 IRDA_DEBUG(3,
"%s(), invalid connection address!\n",
195 if (info->
saddr != self->saddr) {
225 tx_skb = alloc_skb(
sizeof(
struct ua_frame) +
234 frame->
caddr =
self->caddr;
244 dev_kfree_skb(tx_skb);
276 frame->
caddr =
self->caddr;
325 IRDA_DEBUG(4,
"%s(), s=%d, S=%d, command=%d\n", __func__,
338 frame = (
struct xid_frame *) tx_skb->data;
382 if (!command || (frame->
slotnr == 0xff)) {
409 static void irlap_recv_discovery_xid_rsp(
struct irlap_cb *
self,
415 __u8 *discovery_info;
423 if (!pskb_may_pull(skb,
sizeof(
struct xid_frame))) {
424 IRDA_ERROR(
"%s: frame too short!\n", __func__);
435 IRDA_DEBUG(0,
"%s(), frame is not addressed to us!\n",
455 discovery->
data.
hints[0] = discovery_info[0];
458 discovery->
data.
hints[1] = discovery_info[1];
460 text = (
char *) &discovery_info[3];
464 text = (
char *) &discovery_info[2];
485 static void irlap_recv_discovery_xid_cmd(
struct irlap_cb *
self,
491 __u8 *discovery_info;
494 if (!pskb_may_pull(skb,
sizeof(
struct xid_frame))) {
495 IRDA_ERROR(
"%s: frame too short!\n", __func__);
506 IRDA_DEBUG(0,
"%s(), frame is not addressed to us!\n",
511 switch (xid->
flags & 0x03) {
535 if (info->
s == 0xff) {
537 if((discovery_info ==
NULL) ||
538 !pskb_may_pull(skb, 3)) {
539 IRDA_ERROR(
"%s: discovery frame too short!\n",
557 discovery->
data.
hints[0] = discovery_info[0];
559 discovery->
data.
hints[1] = discovery_info[1];
561 text = (
char *) &discovery_info[3];
565 text = (
char *) &discovery_info[2];
599 frame->
caddr =
self->caddr;
624 frame->
caddr =
self->caddr;
637 static inline void irlap_recv_rr_frame(
struct irlap_cb *
self,
641 info->
nr = skb->
data[1] >> 5;
656 static void irlap_recv_rnr_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
659 info->
nr = skb->
data[1] >> 5;
661 IRDA_DEBUG(4,
"%s(), nr=%d, %ld\n", __func__, info->
nr, jiffies);
669 static void irlap_recv_rej_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
674 info->
nr = skb->
data[1] >> 5;
683 static void irlap_recv_srej_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
688 info->
nr = skb->
data[1] >> 5;
697 static void irlap_recv_disc_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
715 static inline void irlap_recv_ua_frame(
struct irlap_cb *
self,
749 if (tx_skb ==
NULL) {
753 self->vs = (
self->vs + 1) % 8;
754 self->ack_required =
FALSE;
757 irlap_send_i_frame(
self, tx_skb,
CMD_FRAME);
759 IRDA_DEBUG(4,
"%s(), sending unreliable frame\n", __func__);
772 int transmission_time;
795 if (tx_skb ==
NULL) {
806 self->vs = (
self->vs + 1) % 8;
807 self->ack_required =
FALSE;
810 irlap_send_i_frame(
self, tx_skb,
CMD_FRAME);
812 IRDA_DEBUG(4,
"%s(), sending unreliable frame\n", __func__);
814 if (self->ack_required) {
818 self->ack_required =
FALSE;
828 transmission_time =
self->final_timeout;
831 self->window =
self->window_size;
833 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
837 transmission_time -= (
self->final_timeout *
self->bytes_left
838 /
self->line_capacity);
839 IRDA_DEBUG(4,
"%s() adjusting transmission_time : ft=%d, bl=%d, lc=%d -> tt=%d\n", __func__, self->final_timeout, self->bytes_left, self->line_capacity, transmission_time);
842 self->bytes_left =
self->line_capacity;
903 if (tx_skb ==
NULL) {
909 self->vs = (
self->vs + 1) % 8;
910 self->ack_required =
FALSE;
912 irlap_send_i_frame(
self, tx_skb,
RSP_FRAME);
914 if (self->ack_required) {
917 self->ack_required =
FALSE;
924 self->window =
self->window_size;
925 #ifdef CONFIG_IRDA_DYNAMIC_WINDOW
927 self->bytes_left =
self->line_capacity;
960 if (tx_skb ==
NULL) {
964 self->vs = (
self->vs + 1) % 8;
965 self->ack_required =
FALSE;
968 irlap_send_i_frame(
self, tx_skb,
RSP_FRAME);
991 skb_queue_walk(&self->wx_list, skb) {
1000 IRDA_DEBUG(0,
"%s(), unable to copy\n", __func__);
1005 tx_skb->
data[1] &= 0x0f;
1010 if (skb_queue_is_last(&self->wx_list, skb))
1015 irlap_send_i_frame(
self, tx_skb, command);
1021 while (!skb_queue_empty(&self->txq)) {
1023 IRDA_DEBUG(0,
"%s(), sending additional frames!\n", __func__);
1024 if (self->window > 0) {
1032 if ((self->window > 1) &&
1033 !skb_queue_empty(&self->txq)) {
1053 skb = skb_peek(&self->wx_list);
1063 IRDA_DEBUG(0,
"%s(), unable to copy\n", __func__);
1068 tx_skb->
data[1] &= 0x0f;
1073 irlap_send_i_frame(
self, tx_skb, command);
1084 __u8 caddr,
int command)
1103 static void irlap_send_i_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
1107 skb->
data[0] =
self->caddr;
1111 skb->
data[1] |= (
self->vr << 5);
1122 static inline void irlap_recv_i_frame(
struct irlap_cb *
self,
1126 info->
nr = skb->
data[1] >> 5;
1128 info->
ns = (skb->
data[1] >> 1) & 0x07;
1143 static void irlap_recv_ui_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
1159 static void irlap_recv_frmr_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
1172 if (!pskb_may_pull(skb, 4)) {
1173 IRDA_ERROR(
"%s: frame too short!\n", __func__);
1179 info->
nr = frame[2] >> 5;
1181 info->
ns = (frame[2] >> 1) & 0x07;
1183 w = frame[3] & 0x01;
1184 x = frame[3] & 0x02;
1185 y = frame[3] & 0x04;
1186 z = frame[3] & 0x08;
1189 IRDA_DEBUG(0,
"Rejected control field is undefined or not "
1193 IRDA_DEBUG(0,
"Rejected control field was invalid because it "
1194 "contained a non permitted I field.\n");
1197 IRDA_DEBUG(0,
"Received I field exceeded the maximum negotiated "
1198 "for the existing connection or exceeded the maximum "
1199 "this station supports if no connection exists.\n");
1202 IRDA_DEBUG(0,
"Rejected control field control field contained an "
1203 "invalid Nr count.\n");
1254 static void irlap_recv_test_frame(
struct irlap_cb *
self,
struct sk_buff *skb,
1261 if (!pskb_may_pull(skb,
sizeof(*frame))) {
1262 IRDA_ERROR(
"%s: frame too short!\n", __func__);
1270 IRDA_DEBUG(0,
"%s() test frame too short!\n",
1280 if ((info->
saddr != self->saddr) &&
1317 if (!net_eq(dev_net(dev), &
init_net))
1331 IRDA_ERROR(
"%s: can't clone shared skb!\n", __func__);
1336 if (!pskb_may_pull(skb, 2)) {
1337 IRDA_ERROR(
"%s: frame too short!\n", __func__);
1351 IRDA_DEBUG(0,
"%s(), wrong connection address!\n",
1359 if (~control & 0x01) {
1360 irlap_recv_i_frame(
self, skb, &info, command);
1367 if (~control & 0x02) {
1372 switch (control & 0x0f) {
1374 irlap_recv_rr_frame(
self, skb, &info, command);
1377 irlap_recv_rnr_frame(
self, skb, &info, command);
1380 irlap_recv_rej_frame(
self, skb, &info, command);
1383 irlap_recv_srej_frame(
self, skb, &info, command);
1397 irlap_recv_discovery_xid_rsp(
self, skb, &info);
1400 irlap_recv_discovery_xid_cmd(
self, skb, &info);
1403 irlap_recv_snrm_cmd(
self, skb, &info);
1409 irlap_recv_disc_frame(
self, skb, &info, command);
1412 irlap_recv_test_frame(
self, skb, &info, command);
1415 irlap_recv_ua_frame(
self, skb, &info);
1418 irlap_recv_frmr_frame(
self, skb, &info);
1421 irlap_recv_ui_frame(
self, skb, &info);