Beispiel #1
0
static inline int
irnet_discover_daddr_and_lsap_sel(irnet_socket *	self)
{
  int	ret;

  DENTER(IRDA_SR_TRACE, "(self=0x%p)\n", self);

  
  self->discoveries = irlmp_get_discoveries(&self->disco_number, self->mask,
					    DISCOVERY_DEFAULT_SLOTS);

  
  if(self->discoveries == NULL)
    {
      self->disco_number = -1;
      clear_bit(0, &self->ttp_connect);
      DRETURN(-ENETUNREACH, IRDA_SR_INFO, "No Cachelog...\n");
    }
  DEBUG(IRDA_SR_INFO, "Got the log (0x%p), size is %d\n",
	self->discoveries, self->disco_number);

  
  self->disco_index = -1;
  self->daddr = DEV_ADDR_ANY;

  
  ret = irnet_discover_next_daddr(self);
  if(ret)
    {
      
      if(self->iriap)
	iriap_close(self->iriap);
      self->iriap = NULL;

      
      kfree(self->discoveries);
      self->discoveries = NULL;

      clear_bit(0, &self->ttp_connect);
      DRETURN(-ENETUNREACH, IRDA_SR_INFO, "Cachelog empty...\n");
    }

  

  DEXIT(IRDA_SR_TRACE, "\n");
  return(0);
}
Beispiel #2
0
/*
 * Function irnet_dname_to_daddr (self)
 *
 *    Convert an IrDA nickname to a valid IrDA address
 *
 * It basically look into the discovery log until there is a match.
 */
static inline int
irnet_dname_to_daddr(irnet_socket *	self)
{
  struct irda_device_info *discoveries;	/* Copy of the discovery log */
  int	number;			/* Number of nodes in the log */
  int	i;

  DENTER(IRDA_SR_TRACE, "(self=0x%X)\n", (unsigned int) self);

  /* Ask lmp for the current discovery log */
  discoveries = irlmp_get_discoveries(&number, 0xffff);
  /* Check if the we got some results */
  if(discoveries == NULL)
    DRETURN(-ENETUNREACH, IRDA_SR_INFO, "Cachelog empty...\n");

  /* 
   * Now, check all discovered devices (if any), and connect
   * client only about the services that the client is
   * interested in...
   */
  for(i = 0; i < number; i++)
    {
      /* Does the name match ? */
      if(!strncmp(discoveries[i].info, self->rname, NICKNAME_MAX_LEN))
	{
	  /* Yes !!! Get it.. */
	  self->daddr = discoveries[i].daddr;
	  DEBUG(IRDA_SR_INFO, "discovered device ``%s'' at address 0x%08x.\n",
		self->rname, self->daddr);
	  kfree(discoveries);
	  DEXIT(IRDA_SR_TRACE, "\n");
	  return 0;
	}
    }
  /* No luck ! */
  DEBUG(IRDA_SR_INFO, "cannot discover device ``%s'' !!!\n", self->rname);
  kfree(discoveries);
  return(-EADDRNOTAVAIL);
}
Beispiel #3
0
static inline int
irnet_daddr_to_dname(irnet_socket *	self)
{
  struct irda_device_info *discoveries;	
  int	number;			
  int	i;

  DENTER(IRDA_SERV_TRACE, "(self=0x%p)\n", self);

  
  discoveries = irlmp_get_discoveries(&number, 0xffff,
				      DISCOVERY_DEFAULT_SLOTS);
  
  if (discoveries == NULL)
    DRETURN(-ENETUNREACH, IRDA_SERV_INFO, "Cachelog empty...\n");

  
  for(i = 0; i < number; i++)
    {
      
      if(discoveries[i].daddr == self->daddr)
	{
	  
	  strlcpy(self->rname, discoveries[i].info, sizeof(self->rname));
	  self->rname[sizeof(self->rname) - 1] = '\0';
	  DEBUG(IRDA_SERV_INFO, "Device 0x%08x is in fact ``%s''.\n",
		self->daddr, self->rname);
	  kfree(discoveries);
	  DEXIT(IRDA_SERV_TRACE, "\n");
	  return 0;
	}
    }
  
  DEXIT(IRDA_SERV_INFO, ": cannot discover device 0x%08x !!!\n", self->daddr);
  kfree(discoveries);
  return(-EADDRNOTAVAIL);
}
Beispiel #4
0
static inline int
irnet_dname_to_daddr(irnet_socket *	self)
{
  struct irda_device_info *discoveries;	
  int	number;			
  int	i;

  DENTER(IRDA_SR_TRACE, "(self=0x%p)\n", self);

  
  discoveries = irlmp_get_discoveries(&number, 0xffff,
				      DISCOVERY_DEFAULT_SLOTS);
  
  if(discoveries == NULL)
    DRETURN(-ENETUNREACH, IRDA_SR_INFO, "Cachelog empty...\n");

  
  for(i = 0; i < number; i++)
    {
      
      if(!strncmp(discoveries[i].info, self->rname, NICKNAME_MAX_LEN))
	{
	  
	  self->daddr = discoveries[i].daddr;
	  DEBUG(IRDA_SR_INFO, "discovered device ``%s'' at address 0x%08x.\n",
		self->rname, self->daddr);
	  kfree(discoveries);
	  DEXIT(IRDA_SR_TRACE, "\n");
	  return 0;
	}
    }
  
  DEBUG(IRDA_SR_INFO, "cannot discover device ``%s'' !!!\n", self->rname);
  kfree(discoveries);
  return(-EADDRNOTAVAIL);
}
Beispiel #5
0
/*
 * Function irnet_daddr_to_dname (self)
 *
 *    Convert an IrDA address to a IrDA nickname
 *
 * It basically look into the discovery log until there is a match.
 */
static inline int
irnet_daddr_to_dname(irnet_socket *	self)
{
  struct irda_device_info *discoveries;	/* Copy of the discovery log */
  int	number;			/* Number of nodes in the log */
  int	i;

  DENTER(IRDA_SERV_TRACE, "(self=0x%X)\n", (unsigned int) self);

  /* Ask lmp for the current discovery log */
  discoveries = irlmp_get_discoveries(&number, 0xffff);
  /* Check if the we got some results */
  if (discoveries == NULL)
    DRETURN(-ENETUNREACH, IRDA_SERV_INFO, "Cachelog empty...\n");

  /* Now, check all discovered devices (if any) */
  for(i = 0; i < number; i++)
    {
      /* Does the name match ? */
      if(discoveries[i].daddr == self->daddr)
	{
	  /* Yes !!! Get it.. */
	  strncpy(self->rname, discoveries[i].info, NICKNAME_MAX_LEN);
	  self->rname[NICKNAME_MAX_LEN + 1] = '\0';
	  DEBUG(IRDA_SERV_INFO, "Device 0x%08x is in fact ``%s''.\n",
		self->daddr, self->rname);
	  kfree(discoveries);
	  DEXIT(IRDA_SERV_TRACE, "\n");
	  return 0;
	}
    }
  /* No luck ! */
  DEXIT(IRDA_SERV_INFO, ": cannot discover device 0x%08x !!!\n", self->daddr);
  kfree(discoveries);
  return(-EADDRNOTAVAIL);
}
Beispiel #6
0
/*
 * Function irnet_discover_daddr_and_lsap_sel (self)
 *
 *    This try to find a device with the requested service.
 *
 * It basically look into the discovery log. For each address in the list,
 * it queries the LM-IAS of the device to find if this device offer
 * the requested service.
 * If there is more than one node supporting the service, we complain
 * to the user (it should move devices around).
 * The, we set both the destination address and the lsap selector to point
 * on the service on the unique device we have found.
 *
 * Note : this function fails if there is more than one device in range,
 * because IrLMP doesn't disconnect the LAP when the last LSAP is closed.
 * Moreover, we would need to wait the LAP disconnection...
 */
static inline int
irnet_discover_daddr_and_lsap_sel(irnet_socket *	self)
{
  struct irda_device_info *discoveries;	/* Copy of the discovery log */
  int	number;			/* Number of nodes in the log */
  int	i;
  int	err = -ENETUNREACH;
  __u32	daddr = DEV_ADDR_ANY;	/* Address we found the service on */
  __u8	dtsap_sel = 0x0;	/* TSAP associated with it */

  DENTER(IRDA_SR_TRACE, "(self=0x%X)\n", (unsigned int) self);

  /* Ask lmp for the current discovery log
   * Note : we have to use irlmp_get_discoveries(), as opposed
   * to play with the cachelog directly, because while we are
   * making our ias query, le log might change... */
  discoveries = irlmp_get_discoveries(&number, self->mask);
  /* Check if the we got some results */
  if (discoveries == NULL)
    DRETURN(-ENETUNREACH, IRDA_SR_INFO, "Cachelog empty...\n");

  /* 
   * Now, check all discovered devices (if any), and connect
   * client only about the services that the client is
   * interested in...
   */
  for(i = 0; i < number; i++)
    {
      /* Try the address in the log */
      self->daddr = discoveries[i].daddr;
      self->saddr = 0x0;
      DEBUG(IRDA_SR_INFO, "trying daddr = %08x\n", self->daddr);

      /* Query remote LM-IAS for this service */
      err = irnet_find_lsap_sel(self);
      switch(err)
	{
	case 0:
	  /* We found the requested service */
	  if(daddr != DEV_ADDR_ANY)
	    {
	      DEBUG(IRDA_SR_INFO, "More than one device in range supports IrNET...\n");
	    }
	  else
	    {
	      /* First time we found that one, save it ! */
	      daddr = self->daddr;
	      dtsap_sel = self->dtsap_sel;
	    }
	  break;
	case -EADDRNOTAVAIL:
	  /* Requested service simply doesn't exist on this node */
	  break;
	default:
	  /* Something bad did happen :-( */
	  DERROR(IRDA_SR_ERROR, "unexpected IAS query failure\n");
	  self->daddr = DEV_ADDR_ANY;
	  kfree(discoveries);
	  return(-EHOSTUNREACH);
	  break;
	}
    }
  /* Cleanup our copy of the discovery log */
  kfree(discoveries);

  /* Check out what we found */
  if(daddr == DEV_ADDR_ANY)
    {
      self->daddr = DEV_ADDR_ANY;
      DEXIT(IRDA_SR_INFO, "cannot discover IrNET in any device !!!\n");
      return(-EADDRNOTAVAIL);
    }

  /* Revert back to discovered device & service */
  self->daddr = daddr;
  self->saddr = 0x0;
  self->dtsap_sel = dtsap_sel;

  DEBUG(IRDA_SR_INFO, "discovered IrNET at address %08x\n", self->daddr);
  DEXIT(IRDA_SR_TRACE, "\n");

  return 0;
}