26 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/string.h>
32 #include <linux/errno.h>
34 #include <linux/sched.h>
36 #include <linux/random.h>
37 #include <linux/netdevice.h>
39 #include <linux/rtnetlink.h>
41 #include <linux/bitops.h>
43 #include <asm/byteorder.h>
73 static const char *
const irlan_access[] = {
80 static const char *
const irlan_media[] = {
92 .open = irlan_seq_open,
102 static void __irlan_close(
struct irlan_cb *
self);
106 static void irlan_open_unicast_addr(
struct irlan_cb *
self);
107 static void irlan_get_unicast_addr(
struct irlan_cb *
self);
116 static int __init irlan_init(
void)
123 #ifdef CONFIG_PROC_FS
125 proc = proc_create(
"irlan", 0, proc_irda, &irlan_fops);
165 #ifdef CONFIG_PROC_FS
172 static void __exit irlan_cleanup(
void)
181 #ifdef CONFIG_PROC_FS
211 self = netdev_priv(dev);
222 self->provider.access_type =
access;
242 skb_queue_head_init(&self->client.txq);
248 IRDA_DEBUG(2,
"%s(), register_netdev() failed!\n",
254 list_add_rcu(&self->dev_list, &irlans);
267 static void __irlan_close(
struct irlan_cb *
self)
281 if (self->client.iriap)
288 unregister_netdevice(self->dev);
296 list_for_each_entry_rcu(
self, &irlans,
dev_list) {
308 static void irlan_connect_indication(
void *instance,
void *sap,
326 self->max_sdu_size = max_sdu_size;
329 IRDA_DEBUG(0,
"%s: We are now connected!\n", __func__);
348 irlan_get_unicast_addr(
self);
349 irlan_open_unicast_addr(
self);
352 netif_start_queue(self->dev);
355 static void irlan_connect_confirm(
void *instance,
void *sap,
358 __u8 max_header_size,
373 IRDA_DEBUG(0,
"%s: We are now connected!\n", __func__);
380 irlan_get_unicast_addr(
self);
381 irlan_open_unicast_addr(
self);
388 netif_start_queue(self->dev);
389 self->disconnect_reason = 0;
399 static void irlan_disconnect_indication(
void *instance,
406 IRDA_DEBUG(0,
"%s(), reason=%d\n", __func__ , reason);
418 IRDA_DEBUG(2,
"IrLAN, data channel disconnected by peer!\n");
421 self->disconnect_reason =
reason;
425 IRDA_DEBUG(2,
"%s(), User requested\n", __func__ );
428 IRDA_DEBUG(2,
"%s(), Unexpected IrLAP disconnect\n", __func__ );
431 IRDA_DEBUG(2,
"%s(), IrLAP connect failed\n", __func__ );
434 IRDA_DEBUG(2,
"%s(), IrLAP reset\n", __func__ );
437 IRDA_DEBUG(2,
"%s(), IrLMP connect failed\n", __func__ );
440 IRDA_ERROR(
"%s(), Unknown disconnect reason\n", __func__);
449 dev_kfree_skb(userdata);
484 IRDA_DEBUG(2,
"%s(), Got no tsap!\n", __func__ );
487 self->tsap_data = tsap;
493 self->stsap_sel_data =
self->tsap_data->
stsap_sel;
504 if (self->tsap_data) {
507 self->tsap_data =
NULL;
509 if (self->client.tsap_ctrl) {
513 self->client.tsap_ctrl =
NULL;
515 if (self->provider.tsap_ctrl) {
519 self->provider.tsap_ctrl =
NULL;
595 self->client.tx_busy =
FALSE;
600 if ((self->client.tsap_ctrl ==
NULL) ||
603 self->client.tx_busy =
FALSE;
607 IRDA_DEBUG(2,
"%s(), sending ...\n", __func__ );
618 static void irlan_ctrl_data_request(
struct irlan_cb *
self,
struct sk_buff *skb)
651 skb_reserve(skb, self->client.max_header_size);
659 irlan_ctrl_data_request(
self, skb);
685 skb_reserve(skb, self->client.max_header_size);
700 irlan_ctrl_data_request(
self, skb);
714 if (self->client.tsap_ctrl ==
NULL)
723 skb_reserve(skb, self->client.max_header_size);
734 irlan_ctrl_data_request(
self, skb);
744 static void irlan_open_unicast_addr(
struct irlan_cb *
self)
763 skb_reserve(skb, self->max_header_size);
774 irlan_ctrl_data_request(
self, skb);
806 skb_reserve(skb, self->client.max_header_size);
820 irlan_ctrl_data_request(
self, skb);
850 skb_reserve(skb, self->client.max_header_size);
864 irlan_ctrl_data_request(
self, skb);
875 static void irlan_get_unicast_addr(
struct irlan_cb *
self)
895 skb_reserve(skb, self->client.max_header_size);
906 irlan_ctrl_data_request(
self, skb);
933 skb_reserve(skb, self->client.max_header_size);
943 irlan_ctrl_data_request(
self, skb);
954 return __irlan_insert_param(skb, param,
IRLAN_BYTE, value, 0,
NULL, 0);
959 return __irlan_insert_param(skb, param,
IRLAN_SHORT, 0, value,
NULL, 0);
970 int string_len =
strlen(
string);
972 return __irlan_insert_param(skb, param,
IRLAN_ARRAY, 0, 0,
string,
985 return __irlan_insert_param(skb, name,
IRLAN_ARRAY, 0, 0, array,
1008 IRDA_DEBUG(2,
"%s(), Got NULL skb\n", __func__ );
1012 param_len =
strlen(param);
1025 IRDA_DEBUG(2,
"%s(), Unknown parameter type!\n", __func__ );
1031 frame = skb_tail_pointer(skb);
1034 if (skb_tailroom(skb) < (param_len+value_len+3)) {
1035 IRDA_DEBUG(2,
"%s(), No more space at end of skb\n", __func__ );
1038 skb_put(skb, param_len+value_len+3);
1041 frame[n++] = param_len;
1044 memcpy(frame+n, param, param_len); n += param_len;
1048 memcpy(frame+n, &tmp_le, 2); n += 2;
1053 frame[n++] = value_byte;
1057 memcpy(frame+n, &tmp_le, 2); n += 2;
1065 IRDA_ASSERT(n == (param_len+value_len+3),
return 0;);
1067 return param_len+value_len+3;
1085 name_len = buf[n++];
1087 if (name_len > 254) {
1088 IRDA_DEBUG(2,
"%s(), name_len > 254\n", __func__ );
1093 memcpy(name, buf+n, name_len);
1101 memcpy(&val_len, buf+n, 2);
1104 if (val_len >= 1016) {
1105 IRDA_DEBUG(2,
"%s(), parameter length to long\n", __func__ );
1111 memcpy(value, buf+n, val_len);
1112 value[val_len] =
'\0';
1121 #ifdef CONFIG_PROC_FS
1129 static void *irlan_seq_start(
struct seq_file *seq, loff_t *
pos)
1136 static void *irlan_seq_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
1142 static void irlan_seq_stop(
struct seq_file *seq,
void *
v)
1151 static int irlan_seq_show(
struct seq_file *seq,
void *
v)
1154 seq_puts(seq,
"IrLAN instances:\n");
1172 self->
version[1], self->version[0]);
1174 irlan_access[self->client.access_type]);
1176 irlan_media[self->media]);
1180 irlan_print_filter(seq, self->client.filter_type);
1182 netif_queue_stopped(self->dev) ?
"TRUE" :
"FALSE");
1190 .
start = irlan_seq_start,
1191 .next = irlan_seq_next,
1192 .stop = irlan_seq_stop,
1193 .show = irlan_seq_show,
1198 return seq_open(file, &irlan_seq_ops);