Hi everybody...

        I added a new feature to connect : if you don't specify a
device address, the IrDA stack will try to find one for you (doing
discovery and all that jazz). Of course, if you specify an address,
the old behaviour is used...
        Patch below...

        Jean

-------------------------------------
--- af_irda.dag2.c      Mon Dec  6 13:32:26 1999
+++ af_irda.c   Mon Dec  6 13:48:08 1999
@@ -451,6 +451,71 @@ static int irda_find_lsap_sel(struct ird
 }
 
 /*
+ * Function irda_discover_lsap_sel (self, name)
+ *
+ *    Try to lookup LSAP selector in all remote LM-IAS that we can connect to
+ *
+ */
+static int irda_discover_lsap_sel(struct irda_sock *self, char *name)
+{
+       discovery_t *discovery;
+       int err = -ENETUNREACH;
+
+       IRDA_DEBUG(2, __FUNCTION__ "(), name=%s\n", name);
+
+       ASSERT(self != NULL, return -1;);
+
+       /* Tell IrLMP we want to be notified */
+       irlmp_update_client(self->ckey, self->mask, NULL, 
+                           irda_discovery_indication);
+       
+       /* Do some discovery */
+       irlmp_discovery_request(self->nslots);
+               
+       /* Check if the we got some results */
+       if (!cachelog)
+               /* Wait for answer */
+               /*interruptible_sleep_on(&self->discovery_wait);*/
+               return -EAGAIN;
+
+       /* 
+        * Now, check all discovered devices (if any), and connect
+        * client only about the services that the client is
+        * interested in 
+        */
+       discovery = (discovery_t *) hashbin_get_first(cachelog);
+       while (discovery != NULL) {
+               /* Mask out the ones we don't want */
+               if (discovery->hints.word & self->mask) {
+                       /* Try this address */
+                       self->daddr = discovery->daddr;
+                       IRDA_DEBUG(1, __FUNCTION__ "(), trying daddr = %08x\n", 
+self->daddr);
+
+                       /* Query remote LM-IAS */
+                       err = irda_find_lsap_sel(self, name);
+                       if (err == 0)
+                               break;
+               }
+
+               /* Next node */
+               discovery = (discovery_t *) hashbin_get_next(cachelog);
+       }
+       cachelog = NULL;
+
+       /* Check out what we found */
+       if(err) {
+               IRDA_DEBUG(0, __FUNCTION__ "(), cannot discover requested service 
+''%s'' !!!\n", name);
+               self->daddr = 0;        /* Guessing */
+               return(err);
+       }
+
+       IRDA_DEBUG(0, __FUNCTION__ "(), discovered requested service ''%s'' at address 
+%08x\n", name, self->daddr);
+
+       return 0;
+}
+
+
+/*
  * Function irda_getname (sock, uaddr, uaddr_len, peer)
  *
  *    Return the our own, or peers socket address (sockaddr_irda)
@@ -682,19 +747,30 @@ static int irda_connect(struct socket *s
 
        if (addr_len != sizeof(struct sockaddr_irda))
                return -EINVAL;
-
-       /* Check if user supplied the required destination device address */
-       if (!addr->sir_addr)
+       /* Should do more check, and should do : addr->sir_name[24] = '\0' */
+       if (addr->sir_name[0] == '\0')
                return -EINVAL;
 
-       self->daddr = addr->sir_addr;
-       IRDA_DEBUG(1, __FUNCTION__ "(), daddr = %08x\n", self->daddr);
-
-       /* Query remote LM-IAS */
-       err = irda_find_lsap_sel(self, addr->sir_name);
-       if (err) {
-               IRDA_DEBUG(0, __FUNCTION__ "(), connect failed!\n");
-               return err;
+       /* Check if user supplied the required destination device address */
+       if (!addr->sir_addr) {
+               /* Try to find one suitable */
+               err = irda_discover_lsap_sel(self, addr->sir_name);
+               if (err) {
+                       IRDA_DEBUG(0, __FUNCTION__ "(), connect failed!\n");
+                       return -EINVAL;
+               }
+       }
+       else {
+               /* Use the one provided by the user */
+               self->daddr = addr->sir_addr;
+               IRDA_DEBUG(1, __FUNCTION__ "(), daddr = %08x\n", self->daddr);
+
+               /* Query remote LM-IAS */
+               err = irda_find_lsap_sel(self, addr->sir_name);
+               if (err) {
+                       IRDA_DEBUG(0, __FUNCTION__ "(), connect failed!\n");
+                       return err;
+               }
        }
 
        /* Check if we have opened a local TSAP */

_______________________________________________
Linux-IrDA mailing list  -  [EMAIL PROTECTED]
http://www4.pasta.cs.UiT.No/mailman/listinfo/linux-irda

Reply via email to