27 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <linux/string.h>
31 #include <linux/types.h>
35 #include <linux/random.h>
46 #include <asm/unaligned.h>
48 static __u8 irlmp_find_free_slsap(
void);
49 static int irlmp_slsap_inuse(
__u8 slsap_sel);
158 slsap_sel = irlmp_find_free_slsap();
161 }
else if (irlmp_slsap_inuse(slsap_sel))
167 IRDA_ERROR(
"%s: can't allocate memory\n", __func__);
176 #ifdef CONFIG_IRDA_ULTRA
203 static void __irlmp_close_lsap(
struct lsap_cb *
self)
217 dev_kfree_skb(self->conn_skb);
254 #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
255 lap->cache.valid =
FALSE;
266 "%s(), Looks like somebody has removed me already!\n",
270 __irlmp_close_lsap(
self);
294 IRDA_ERROR(
"%s: unable to kmalloc\n", __func__);
302 #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
303 lap->cache.valid =
FALSE;
306 if (lap->lsaps ==
NULL) {
307 IRDA_WARNING(
"%s(), unable to kmalloc lsaps\n", __func__);
374 struct sk_buff *tx_skb = userdata;
383 "%s(), slsap_sel=%02x, dlsap_sel=%02x, saddr=%08x, daddr=%08x\n",
384 __func__, self->slsap_sel, dlsap_sel, saddr, daddr);
386 if (
test_bit(0, &self->connected)) {
398 if (tx_skb ==
NULL) {
441 IRDA_DEBUG(1,
"%s(), Unable to find a usable link!\n", __func__);
449 else if (lap->
daddr != daddr) {
456 IRDA_DEBUG(0,
"%s(), sorry, but I'm waiting for LAP to timeout!\n", __func__);
463 IRDA_DEBUG(0,
"%s(), sorry, but link is busy!\n", __func__);
495 dev_kfree_skb(tx_skb);
502 dev_kfree_skb(tx_skb);
524 IRDA_DEBUG(2,
"%s(), slsap_sel=%02x, dlsap_sel=%02x\n",
525 __func__, self->slsap_sel, self->dlsap_sel);
532 self->qos = *
self->lap->qos;
534 max_seg_size =
self->lap->qos->data_size.value-
LMP_HEADER;
536 max_header_size =
LMP_HEADER + lap_header_size;
541 if (self->notify.connect_indication) {
544 self->notify.connect_indication(self->notify.instance,
self,
545 &self->qos, max_seg_size,
546 max_header_size, skb);
565 IRDA_DEBUG(2,
"%s(), slsap_sel=%02x, dlsap_sel=%02x\n",
566 __func__, self->slsap_sel, self->dlsap_sel);
575 dev_kfree_skb(userdata);
599 self->qos = *
self->lap->qos;
601 max_seg_size =
self->lap->qos->data_size.value-
LMP_HEADER;
603 max_header_size =
LMP_HEADER + lap_header_size;
606 __func__, max_header_size);
611 if (self->notify.connect_confirm) {
614 self->notify.connect_confirm(self->notify.instance,
self,
615 &self->qos, max_seg_size,
616 max_header_size, skb);
639 (orig->lap ==
NULL)) {
640 IRDA_DEBUG(0,
"%s(), invalid LSAP (wrong state)\n",
650 IRDA_DEBUG(0,
"%s(), unable to kmalloc\n", __func__);
657 new->conn_skb =
NULL;
662 new->notify.instance = instance;
669 #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
671 new->lap->cache.valid =
FALSE;
696 IRDA_DEBUG(0,
"%s(), already disconnected!\n", __func__);
697 dev_kfree_skb(userdata);
710 dev_kfree_skb(userdata);
721 #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
722 self->lap->cache.valid =
FALSE;
754 IRDA_DEBUG(3,
"%s(), slsap_sel=%02x, dlsap_sel=%02x\n",
755 __func__, self->slsap_sel, self->dlsap_sel);
762 IRDA_DEBUG(0,
"%s(), already disconnected!\n", __func__);
773 #ifdef CONFIG_IRDA_CACHE_LAST_LSAP
774 self->lap->cache.valid =
FALSE;
788 if (self->notify.disconnect_indication) {
792 self->notify.disconnect_indication(self->notify.instance,
795 IRDA_DEBUG(0,
"%s(), no handler\n", __func__);
821 while (lap !=
NULL) {
846 if ((nslots != 1) && (nslots != 6) && (nslots != 8) && (nslots != 16)){
847 IRDA_WARNING(
"%s: invalid value for number of slots!\n",
871 while (lap !=
NULL) {
994 if (discoveries ==
NULL)
998 for(i = 0; i < number; i++)
1027 (
void *) &client_next) ) {
1029 irlmp_notify_client(client, log, mode);
1031 client = client_next;
1059 (
void *) &client_next) ) {
1062 for(i = 0; i < number; i++) {
1064 if ((client->expir_callback) &&
1065 (client->hint_mask.word &
1068 client->expir_callback(&(expiries[i]),
1074 client = client_next;
1133 dev_kfree_skb(userdata);
1150 if (self->notify.data_indication) {
1153 self->notify.data_indication(self->notify.instance,
self, skb);
1175 dev_kfree_skb(userdata);
1197 if (self->notify.udata_indication) {
1200 self->notify.udata_indication(self->notify.instance,
self,
1208 #ifdef CONFIG_IRDA_ULTRA
1209 int irlmp_connless_data_request(
struct lsap_cb *
self,
struct sk_buff *userdata,
1226 userdata->
data[0] =
self->pid;
1236 while (lap !=
NULL) {
1241 dev_kfree_skb(userdata);
1245 irlap_unitdata_request(lap->
irlap, clone_skb);
1251 dev_kfree_skb(userdata);
1263 #ifdef CONFIG_IRDA_ULTRA
1275 if (self->notify.udata_indication) {
1278 self->notify.udata_indication(self->notify.instance,
self,
1305 if (curr->notify.status_indication !=
NULL)
1306 curr->notify.status_indication(curr->notify.instance,
1309 IRDA_DEBUG(2,
"%s(), no handler\n", __func__);
1337 IRDA_DEBUG(4,
"%s() : %d lsaps to scan\n", __func__, lsap_todo);
1343 while((lsap_todo--) &&
1346 next =
self->flow_next;
1352 (
void *) &self->flow_next);
1356 IRDA_DEBUG(4,
"%s() : curr is %p, next was %p and is now %p, still %d to go - queue len = %d\n", __func__, curr, next, self->flow_next, lsap_todo,
IRLAP_GET_TX_QUEUE_LEN(self->irlap));
1363 IRDA_DEBUG(1,
"%s(), no handler\n", __func__);
1374 __u8 *irlmp_hint_to_service(
__u8 *hint)
1385 IRDA_DEBUG(1,
"%s(), Unable to kmalloc!\n", __func__);
1410 service[i++] =
S_LAN;
1436 service[i++] =
S_ANY;
1444 static const __u16 service_hint_mapping[
S_END][2] = {
1486 IRDA_DEBUG(4,
"%s(), hints = %04x\n", __func__, hints);
1491 IRDA_DEBUG(1,
"%s(), Unable to kmalloc!\n", __func__);
1496 (
long) service,
NULL);
1514 unsigned long flags;
1524 IRDA_DEBUG(1,
"%s(), Unknown service!\n", __func__);
1567 IRDA_DEBUG( 1,
"%s(), Unable to kmalloc!\n", __func__);
1572 client->hint_mask.word = hint_mask;
1573 client->disco_callback = disco_clb;
1574 client->expir_callback = expir_clb;
1575 client->priv =
priv;
1578 (
long) client,
NULL);
1603 IRDA_DEBUG(1,
"%s(), Unknown client!\n", __func__);
1624 struct irlmp_client *
client;
1634 IRDA_DEBUG(1,
"%s(), Unknown client!\n", __func__);
1638 IRDA_DEBUG(4,
"%s(), removing client!\n", __func__);
1657 static int irlmp_slsap_inuse(
__u8 slsap_sel)
1661 unsigned long flags;
1669 #ifdef CONFIG_IRDA_ULTRA
1687 while (lap !=
NULL) {
1697 while (
self !=
NULL) {
1701 if ((self->slsap_sel == slsap_sel)) {
1702 IRDA_DEBUG(4,
"Source LSAP selector=%02x in use\n",
1724 while (
self !=
NULL) {
1726 if ((self->slsap_sel == slsap_sel)) {
1727 IRDA_DEBUG(4,
"Source LSAP selector=%02x in use (unconnected)\n",
1743 spin_unlock_irqrestore(&irlmp->links->hb_spinlock, flags);
1749 spin_unlock_irqrestore(&irlmp->unconnected_lsaps->hb_spinlock, flags);
1759 static
__u8 irlmp_find_free_slsap(
void)
1808 IRDA_DEBUG(4,
"%s(), found free lsap_sel=%02x\n",
1809 __func__, lsap_sel);
1825 switch (lap_reason) {
1827 IRDA_DEBUG( 1,
"%s(), LAP_DISC_INDICATION\n", __func__);
1831 IRDA_DEBUG( 1,
"%s(), LAP_NO_RESPONSE\n", __func__);
1835 IRDA_DEBUG( 1,
"%s(), LAP_RESET_INDICATION\n", __func__);
1841 IRDA_DEBUG(1,
"%s(), LAP_FOUND_NONE, LAP_MEDIA_BUSY or LAP_PRIMARY_CONFLICT\n", __func__);
1845 IRDA_DEBUG(1,
"%s(), Unknown IrLAP disconnect reason %d!\n",
1846 __func__, lap_reason);
1854 #ifdef CONFIG_PROC_FS
1856 struct irlmp_iter_state {
1860 #define LSAP_START_TOKEN ((void *)1)
1861 #define LINK_START_TOKEN ((void *)2)
1863 static void *irlmp_seq_hb_idx(
struct irlmp_iter_state *iter, loff_t *off)
1867 spin_lock_irq(&iter->hashbin->hb_spinlock);
1871 if (!off || *off-- == 0) {
1876 spin_unlock_irq(&iter->hashbin->hb_spinlock);
1877 iter->hashbin =
NULL;
1882 static void *irlmp_seq_start(
struct seq_file *seq, loff_t *
pos)
1884 struct irlmp_iter_state *iter = seq->
private;
1888 iter->hashbin =
NULL;
1890 return LSAP_START_TOKEN;
1893 v = irlmp_seq_hb_idx(iter, &off);
1898 return LINK_START_TOKEN;
1900 iter->hashbin = irlmp->
links;
1901 return irlmp_seq_hb_idx(iter, &off);
1904 static void *irlmp_seq_next(
struct seq_file *seq,
void *v, loff_t *pos)
1906 struct irlmp_iter_state *iter = seq->
private;
1910 if (v == LSAP_START_TOKEN) {
1912 v = irlmp_seq_hb_idx(iter,
NULL);
1913 return v ? v : LINK_START_TOKEN;
1916 if (v == LINK_START_TOKEN) {
1917 iter->hashbin = irlmp->
links;
1918 return irlmp_seq_hb_idx(iter,
NULL);
1924 spin_unlock_irq(&iter->hashbin->hb_spinlock);
1927 v = LINK_START_TOKEN;
1929 iter->hashbin =
NULL;
1934 static void irlmp_seq_stop(
struct seq_file *seq,
void *v)
1936 struct irlmp_iter_state *iter = seq->
private;
1939 spin_unlock_irq(&iter->hashbin->hb_spinlock);
1942 static int irlmp_seq_show(
struct seq_file *seq,
void *v)
1944 const struct irlmp_iter_state *iter = seq->
private;
1947 if (v == LSAP_START_TOKEN)
1948 seq_puts(seq,
"Unconnected LSAPs:\n");
1949 else if (v == LINK_START_TOKEN)
1950 seq_puts(seq,
"\nRegistered Link Layers:\n");
1957 "slsap_sel: %#02x, dlsap_sel: %#02x, ",
1958 self->slsap_sel, self->dlsap_sel);
1961 }
else if (iter->hashbin == irlmp->
links) {
1967 seq_printf(seq,
"saddr: %#08x, daddr: %#08x, ",
1987 "slsap_sel: %#02x, dlsap_sel: %#02x, ",
1988 self->slsap_sel, self->dlsap_sel);
1994 spin_unlock(&lap->
lsaps->hb_spinlock);
2003 .
start = irlmp_seq_start,
2004 .next = irlmp_seq_next,
2005 .stop = irlmp_seq_stop,
2006 .show = irlmp_seq_show,
2014 sizeof(
struct irlmp_iter_state));
2019 .open = irlmp_seq_open,