patch-2.2.15 linux/net/irda/af_irda.c
Next file: linux/net/irda/compressors/Config.in
Previous file: linux/net/irda/Makefile
Back to the patch index
Back to the overall index
- Lines: 1897
- Date:
Fri Apr 21 12:47:16 2000
- Orig file:
v2.2.14/net/irda/af_irda.c
- Orig date:
Sat Aug 14 02:26:52 1999
diff -u --new-file --recursive --exclude-from ../../exclude v2.2.14/net/irda/af_irda.c linux/net/irda/af_irda.c
@@ -1,25 +1,44 @@
/*********************************************************************
*
* Filename: af_irda.c
- * Version: 0.6
+ * Version: 0.9
* Description: IrDA sockets implementation
- * Status: Experimental.
+ * Status: Stable
* Author: Dag Brattli <dagb@cs.uit.no>
* Created at: Sun May 31 10:12:43 1998
- * Modified at: Wed May 19 16:12:06 1999
+ * Modified at: Sat Dec 25 21:10:23 1999
* Modified by: Dag Brattli <dagb@cs.uit.no>
* Sources: af_netroom.c, af_ax25.c, af_rose.c, af_x25.c etc.
*
- * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
- *
+ * Copyright (c) 1999 Dag Brattli <dagb@cs.uit.no>
+ * Copyright (c) 1999 Jean Tourrilhes <jeant@rockfort.hpl.hp.com>
+ * All Rights Reserved.
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
- *
- * Neither Dag Brattli nor University of Tromsų admit liability nor
- * provide warranty for any of this software. This material is
- * provided "AS-IS" and at no charge.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * Linux-IrDA now supports four different types of IrDA sockets:
+ *
+ * o SOCK_STREAM: TinyTP connections with SAR disabled. The
+ * max SDU size is 0 for conn. of this type
+ * o SOCK_SEQPACKET: TinyTP connections with SAR enabled. TTP may
+ * fragment the messages, but will preserve
+ * the message boundaries
+ * o SOCK_DGRAM: IRDAPROTO_UNITDATA: TinyTP connections with Unitdata
+ * (unreliable) transfers
+ * IRDAPROTO_ULTRA: Connectionless and unreliable data
*
********************************************************************/
@@ -39,6 +58,7 @@
#include <net/irda/irda.h>
#include <net/irda/iriap.h>
#include <net/irda/irias_object.h>
+#include <net/irda/irlmp.h>
#include <net/irda/irttp.h>
#include <net/irda/discovery.h>
@@ -47,8 +67,17 @@
extern int irlap_driver_rcv(struct sk_buff *, struct device *,
struct packet_type *);
+static int irda_create(struct socket *sock, int protocol);
+
static struct proto_ops irda_stream_ops;
+static struct proto_ops irda_seqpacket_ops;
static struct proto_ops irda_dgram_ops;
+
+#ifdef CONFIG_IRDA_ULTRA
+static struct proto_ops irda_ultra_ops;
+#define ULTRA_MAX_DATA 382
+#endif /* CONFIG_IRDA_ULTRA */
+
static hashbin_t *cachelog = NULL;
static struct wait_queue *discovery_wait; /* Wait for discovery */
@@ -66,8 +95,6 @@
struct sock *sk;
int err;
- DEBUG(1, __FUNCTION__ "()\n");
-
self = (struct irda_sock *) instance;
ASSERT(self != NULL, return -1;);
@@ -76,7 +103,7 @@
err = sock_queue_rcv_skb(sk, skb);
if (err) {
- DEBUG(1, __FUNCTION__ "(), error: no more mem!\n");
+ IRDA_DEBUG(1, __FUNCTION__ "(), error: no more mem!\n");
self->rx_flow = FLOW_STOP;
/* When we return error, TTP will need to requeue the skb */
@@ -98,7 +125,7 @@
struct irda_sock *self;
struct sock *sk;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
self = (struct irda_sock *) instance;
@@ -107,7 +134,7 @@
return;
sk->state = TCP_CLOSE;
- sk->err = reason;
+ sk->err = ECONNRESET;
sk->shutdown |= SEND_SHUTDOWN;
if (!sk->dead) {
sk->state_change(sk);
@@ -129,10 +156,14 @@
struct irda_sock *self;
struct sock *sk;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
self = (struct irda_sock *) instance;
+ sk = self->sk;
+ if (sk == NULL)
+ return;
+
/* How much header space do we need to reserve */
self->max_header_size = max_header_size;
@@ -140,19 +171,30 @@
self->max_sdu_size_tx = max_sdu_size;
/* Find out what the largest chunk of data that we can transmit is */
- if (max_sdu_size == SAR_DISABLE)
- self->max_data_size = qos->data_size.value - max_header_size;
- else
+ switch (sk->type) {
+ case SOCK_STREAM:
+ if (max_sdu_size != 0) {
+ ERROR(__FUNCTION__ "(), max_sdu_size must be 0\n");
+ return;
+ }
+ self->max_data_size = irttp_get_max_seg_size(self->tsap);
+ break;
+ case SOCK_SEQPACKET:
+ if (max_sdu_size == 0) {
+ ERROR(__FUNCTION__ "(), max_sdu_size cannot be 0\n");
+ return;
+ }
self->max_data_size = max_sdu_size;
+ break;
+ default:
+ self->max_data_size = irttp_get_max_seg_size(self->tsap);
+ };
- DEBUG(1, __FUNCTION__ "(), max_data_size=%d\n", self->max_data_size);
+ IRDA_DEBUG(2, __FUNCTION__ "(), max_data_size=%d\n",
+ self->max_data_size);
memcpy(&self->qos_tx, qos, sizeof(struct qos_info));
- sk = self->sk;
- if (sk == NULL)
- return;
-
skb_queue_tail(&sk->receive_queue, skb);
/* We are now connected! */
@@ -173,9 +215,13 @@
struct irda_sock *self;
struct sock *sk;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
- self = (struct irda_sock *) instance;
+ self = (struct irda_sock *) instance;
+
+ sk = self->sk;
+ if (sk == NULL)
+ return;
/* How much header space do we need to reserve */
self->max_header_size = max_header_size;
@@ -184,21 +230,31 @@
self->max_sdu_size_tx = max_sdu_size;
/* Find out what the largest chunk of data that we can transmit is */
- if (max_sdu_size == SAR_DISABLE)
- self->max_data_size = qos->data_size.value - max_header_size;
- else
+ switch (sk->type) {
+ case SOCK_STREAM:
+ if (max_sdu_size != 0) {
+ ERROR(__FUNCTION__ "(), max_sdu_size must be 0\n");
+ return;
+ }
+ self->max_data_size = irttp_get_max_seg_size(self->tsap);
+ break;
+ case SOCK_SEQPACKET:
+ if (max_sdu_size == 0) {
+ ERROR(__FUNCTION__ "(), max_sdu_size cannot be 0\n");
+ return;
+ }
self->max_data_size = max_sdu_size;
+ break;
+ default:
+ self->max_data_size = irttp_get_max_seg_size(self->tsap);
+ };
- DEBUG(1, __FUNCTION__ "(), max_data_size=%d\n", self->max_data_size);
+ IRDA_DEBUG(2, __FUNCTION__ "(), max_data_size=%d\n",
+ self->max_data_size);
memcpy(&self->qos_tx, qos, sizeof(struct qos_info));
-
- sk = self->sk;
- if (sk == NULL)
- return;
skb_queue_tail(&sk->receive_queue, skb);
-
sk->state_change(sk);
}
@@ -212,13 +268,13 @@
{
struct sk_buff *skb;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
skb = dev_alloc_skb(64);
if (skb == NULL) {
- DEBUG(0, __FUNCTION__ "() Unable to allocate sk_buff!\n");
+ IRDA_DEBUG(0, __FUNCTION__ "() Unable to allocate sk_buff!\n");
return;
}
@@ -228,7 +284,6 @@
irttp_connect_response(self->tsap, self->max_sdu_size_rx, skb);
}
-
/*
* Function irda_flow_indication (instance, sap, flow)
*
@@ -240,7 +295,7 @@
struct irda_sock *self;
struct sock *sk;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
self = (struct irda_sock *) instance;
ASSERT(self != NULL, return;);
@@ -250,43 +305,53 @@
switch (flow) {
case FLOW_STOP:
- DEBUG(1, __FUNCTION__ "(), IrTTP wants us to slow down\n");
+ IRDA_DEBUG(1, __FUNCTION__ "(), IrTTP wants us to slow down\n");
self->tx_flow = flow;
break;
case FLOW_START:
self->tx_flow = flow;
- DEBUG(1, __FUNCTION__ "(), IrTTP wants us to start again\n");
+ IRDA_DEBUG(1, __FUNCTION__
+ "(), IrTTP wants us to start again\n");
wake_up_interruptible(sk->sleep);
break;
default:
- DEBUG( 0, __FUNCTION__ "(), Unknown flow command!\n");
+ IRDA_DEBUG( 0, __FUNCTION__ "(), Unknown flow command!\n");
+ /* Unknown flow command, better stop */
+ self->tx_flow = flow;
+ break;
}
}
/*
- * Function irda_get_value_confirm (obj_id, value, priv)
+ * Function irda_getvalue_confirm (obj_id, value, priv)
*
* Got answer from remote LM-IAS
*
*/
-static void irda_get_value_confirm(int result, __u16 obj_id,
- struct ias_value *value, void *priv)
+static void irda_getvalue_confirm(int result, __u16 obj_id,
+ struct ias_value *value, void *priv)
{
struct irda_sock *self;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
ASSERT(priv != NULL, return;);
self = (struct irda_sock *) priv;
- if (!self)
+ if (!self) {
+ WARNING(__FUNCTION__ "(), lost myself!\n");
return;
+ }
+
+ /* We probably don't need to make any more queries */
+ iriap_close(self->iriap);
+ self->iriap = NULL;
+
+ self->errno = result;
/* Check if request succeeded */
if (result != IAS_SUCCESS) {
- DEBUG(0, __FUNCTION__ "(), IAS query failed!\n");
-
- self->errno = result;
+ IRDA_DEBUG(0, __FUNCTION__ "(), IAS query failed!\n");
/* Wake up any processes waiting for result */
wake_up_interruptible(&self->ias_wait);
@@ -296,7 +361,7 @@
switch (value->type) {
case IAS_INTEGER:
- DEBUG(4, __FUNCTION__ "() int=%d\n", value->t.integer);
+ IRDA_DEBUG(4, __FUNCTION__ "() int=%d\n", value->t.integer);
if (value->t.integer != -1) {
self->dtsap_sel = value->t.integer;
@@ -304,9 +369,11 @@
self->dtsap_sel = 0;
break;
default:
- DEBUG(0, __FUNCTION__ "(), bad type!\n");
+ IRDA_DEBUG(0, __FUNCTION__ "(), bad type!\n");
break;
}
+ irias_delete_value(value);
+
/* Wake up any processes waiting for result */
wake_up_interruptible(&self->ias_wait);
}
@@ -319,7 +386,7 @@
*/
static void irda_discovery_indication(hashbin_t *log)
{
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
cachelog = log;
@@ -335,16 +402,20 @@
*/
static int irda_open_tsap(struct irda_sock *self, __u8 tsap_sel, char *name)
{
- struct notify_t notify;
-
- DEBUG(1, __FUNCTION__ "()\n");
+ notify_t notify;
+ if (self->tsap) {
+ WARNING(__FUNCTION__ "(), busy!\n");
+ return -EBUSY;
+ }
+
/* Initialize callbacks to be used by the IrDA stack */
irda_notify_init(¬ify);
notify.connect_confirm = irda_connect_confirm;
notify.connect_indication = irda_connect_indication;
notify.disconnect_indication = irda_disconnect_indication;
notify.data_indication = irda_data_indication;
+ notify.udata_indication = irda_data_indication;
notify.flow_indication = irda_flow_indication;
notify.instance = self;
strncpy(notify.name, name, NOTIFY_MAX_NAME);
@@ -352,8 +423,8 @@
self->tsap = irttp_open_tsap(tsap_sel, DEFAULT_INITIAL_CREDIT,
¬ify);
if (self->tsap == NULL) {
- DEBUG( 0, __FUNCTION__ "(), Unable to allocate TSAP!\n");
- return -1;
+ IRDA_DEBUG( 0, __FUNCTION__ "(), Unable to allocate TSAP!\n");
+ return -ENOMEM;
}
/* Remember which TSAP selector we actually got */
self->stsap_sel = self->tsap->stsap_sel;
@@ -362,6 +433,38 @@
}
/*
+ * Function irda_open_lsap (self)
+ *
+ * Open local Link Service Access Point (LSAP). Used for opening Ultra
+ * sockets
+ */
+#ifdef CONFIG_IRDA_ULTRA
+static int irda_open_lsap(struct irda_sock *self, int pid)
+{
+ notify_t notify;
+
+ if (self->lsap) {
+ WARNING(__FUNCTION__ "(), busy!\n");
+ return -EBUSY;
+ }
+
+ /* Initialize callbacks to be used by the IrDA stack */
+ irda_notify_init(¬ify);
+ notify.udata_indication = irda_data_indication;
+ notify.instance = self;
+ strncpy(notify.name, "Ultra", NOTIFY_MAX_NAME);
+
+ self->lsap = irlmp_open_lsap(LSAP_CONNLESS, ¬ify, pid);
+ if (self->lsap == NULL) {
+ IRDA_DEBUG( 0, __FUNCTION__ "(), Unable to allocate LSAP!\n");
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+#endif /* CONFIG_IRDA_ULTRA */
+
+/*
* Function irda_find_lsap_sel (self, name)
*
* Try to lookup LSAP selector in remote LM-IAS
@@ -369,14 +472,21 @@
*/
static int irda_find_lsap_sel(struct irda_sock *self, char *name)
{
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "(), name=%s\n", name);
ASSERT(self != NULL, return -1;);
+ if (self->iriap) {
+ WARNING(__FUNCTION__ "(), busy with a previous query\n");
+ return -EBUSY;
+ }
+
+ self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
+ irda_getvalue_confirm);
+
/* Query remote LM-IAS */
- iriap_getvaluebyclass_request(name, "IrDA:TinyTP:LsapSel",
- self->saddr, self->daddr,
- irda_get_value_confirm, self);
+ iriap_getvaluebyclass_request(self->iriap, self->saddr, self->daddr,
+ name, "IrDA:TinyTP:LsapSel");
/* Wait for answer */
interruptible_sleep_on(&self->ias_wait);
@@ -386,6 +496,104 @@
return -ENETUNREACH; /* May not be true */
}
+ /*
+ * Function irda_discover_daddr_and_lsap_sel (self, name)
+ *
+ * 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 int irda_discover_daddr_and_lsap_sel(struct irda_sock *self, char *name)
+{
+ discovery_t *discovery;
+ int err = -ENETUNREACH;
+ __u32 daddr = 0x0; /* Address we found the service on */
+ __u8 dtsap_sel = 0x0; /* TSAP associated with it */
+
+ 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;
+ self->saddr = 0x0;
+ IRDA_DEBUG(1, __FUNCTION__ "(), trying daddr = %08x\n",
+ self->daddr);
+
+ /* Query remote LM-IAS for this service */
+ err = irda_find_lsap_sel(self, name);
+ if (err == 0) {
+ /* We found the requested service */
+ if(daddr != 0x0) {
+ IRDA_DEBUG(0, __FUNCTION__
+ "(), discovered service ''%s'' in two different devices !!!\n",
+ name);
+ return(-ENOTUNIQ);
+ }
+ /* First time we foun that one, save it ! */
+ daddr = self->daddr;
+ dtsap_sel = self->dtsap_sel;
+ }
+ }
+
+ /* Next node, maybe we will be more lucky... */
+ discovery = (discovery_t *) hashbin_get_next(cachelog);
+ }
+ cachelog = NULL;
+
+ /* Check out what we found */
+ if(daddr == 0x0) {
+ IRDA_DEBUG(0, __FUNCTION__
+ "(), cannot discover service ''%s'' in any device !!!\n",
+ name);
+ self->daddr = 0; /* Guessing */
+ return(-ENETUNREACH);
+ }
+
+ /* Revert back to discovered device & service */
+ self->daddr = daddr;
+ self->saddr = 0x0;
+ self->dtsap_sel = dtsap_sel;
+
+ 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)
*
@@ -411,8 +619,8 @@
saddr.sir_addr = sk->protinfo.irda->saddr;
}
- DEBUG(1, __FUNCTION__ "(), tsap_sel = %#x\n", saddr.sir_lsap_sel);
- DEBUG(1, __FUNCTION__ "(), addr = %08x\n", saddr.sir_addr);
+ IRDA_DEBUG(1, __FUNCTION__ "(), tsap_sel = %#x\n", saddr.sir_lsap_sel);
+ IRDA_DEBUG(1, __FUNCTION__ "(), addr = %08x\n", saddr.sir_addr);
if (*uaddr_len > sizeof (struct sockaddr_irda))
*uaddr_len = sizeof (struct sockaddr_irda);
@@ -427,16 +635,20 @@
* Just move to the listen state
*
*/
-static int irda_listen( struct socket *sock, int backlog)
+static int irda_listen(struct socket *sock, int backlog)
{
struct sock *sk = sock->sk;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
+
+ if ((sk->type != SOCK_STREAM) && (sk->type != SOCK_SEQPACKET) &&
+ (sk->type != SOCK_DGRAM))
+ return -EOPNOTSUPP;
- if (sk->type == SOCK_STREAM && sk->state != TCP_LISTEN) {
+ if (sk->state != TCP_LISTEN) {
sk->max_ack_backlog = backlog;
sk->state = TCP_LISTEN;
-
+
return 0;
}
@@ -457,24 +669,49 @@
__u16 hints = 0;
int err;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
self = sk->protinfo.irda;
ASSERT(self != NULL, return -1;);
- if ((addr_len < sizeof(struct sockaddr_irda)) ||
- (addr_len > sizeof(struct sockaddr_irda)))
+ if (addr_len != sizeof(struct sockaddr_irda))
return -EINVAL;
+#ifdef CONFIG_IRDA_ULTRA
+ /* Special care for Ultra sockets */
+ if ((sk->type == SOCK_DGRAM) && (sk->protocol == IRDAPROTO_ULTRA)) {
+ self->pid = addr->sir_lsap_sel;
+ if (self->pid & 0x80) {
+ IRDA_DEBUG(0, __FUNCTION__
+ "(), extension in PID not supp!\n");
+ return -EOPNOTSUPP;
+ }
+ err = irda_open_lsap(self, self->pid);
+ if (err < 0)
+ return err;
+
+ self->max_data_size = ULTRA_MAX_DATA - LMP_PID_HEADER;
+ self->max_header_size = IRDA_MAX_HEADER + LMP_PID_HEADER;
+
+ /* Pretend we are connected */
+ sock->state = SS_CONNECTED;
+ sk->state = TCP_ESTABLISHED;
+
+ return 0;
+ }
+#endif /* CONFIG_IRDA_ULTRA */
+
err = irda_open_tsap(self, addr->sir_lsap_sel, addr->sir_name);
if (err < 0)
- return -ENOMEM;
+ return err;
/* Register with LM-IAS */
self->ias_obj = irias_new_object(addr->sir_name, jiffies);
irias_add_integer_attrib(self->ias_obj, "IrDA:TinyTP:LsapSel",
self->stsap_sel);
irias_insert_object(self->ias_obj);
+
+#if 1 /* Will be removed in near future */
/* Fill in some default hint bits values */
if (strncmp(addr->sir_name, "OBEX", 4) == 0)
@@ -482,7 +719,7 @@
if (hints)
self->skey = irlmp_register_service(hints);
-
+#endif
return 0;
}
@@ -498,20 +735,30 @@
struct sock *sk = sock->sk;
struct sock *newsk;
struct sk_buff *skb;
+#if 0 /* Linux 2.3 only */
+ int err;
+#endif
+
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
self = sk->protinfo.irda;
ASSERT(self != NULL, return -1;);
-
+#if 0 /* Linux 2.3 only */
+ err = irda_create(newsock, sk->protocol);
+ if (err)
+ return err;
+#endif
if (sock->state != SS_UNCONNECTED)
return -EINVAL;
if ((sk = sock->sk) == NULL)
return -EINVAL;
- if (sk->type != SOCK_STREAM)
+ if ((sk->type != SOCK_STREAM) && (sk->type != SOCK_SEQPACKET) &&
+ (sk->type != SOCK_DGRAM))
return -EOPNOTSUPP;
- if (sk->state != TCP_LISTEN)
+ if (sk->state != TCP_LISTEN)
return -EINVAL;
/*
@@ -538,7 +785,7 @@
/* Now attach up the new socket */
new->tsap = irttp_dup(self->tsap, new);
if (!new->tsap) {
- DEBUG(0, __FUNCTION__ "(), dup failed!\n");
+ IRDA_DEBUG(0, __FUNCTION__ "(), dup failed!\n");
return -1;
}
@@ -584,9 +831,13 @@
struct irda_sock *self;
int err;
- self = sk->protinfo.irda;
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
- DEBUG(1, __FUNCTION__ "()\n");
+ self = sk->protinfo.irda;
+
+ /* Don't allow connect for Ultra sockets */
+ if ((sk->type == SOCK_DGRAM) && (sk->protocol == IRDAPROTO_ULTRA))
+ return -ESOCKTNOSUPPORT;
if (sk->state == TCP_ESTABLISHED && sock->state == SS_CONNECTING) {
sock->state = SS_CONNECTED;
@@ -607,18 +858,26 @@
if (addr_len != sizeof(struct sockaddr_irda))
return -EINVAL;
- /* Check if user supplied the required destination device address */
- if (!addr->sir_addr)
- return -EINVAL;
-
- self->daddr = addr->sir_addr;
- DEBUG(1, __FUNCTION__ "(), daddr = %08x\n", self->daddr);
-
- /* Query remote LM-IAS */
- err = irda_find_lsap_sel(self, addr->sir_name);
- if (err) {
- DEBUG(0, __FUNCTION__ "(), connect failed!\n");
- return err;
+ /* Check if user supplied any destination device address */
+ if (!addr->sir_addr) {
+ /* Try to find one suitable */
+ err = irda_discover_daddr_and_lsap_sel(self, addr->sir_name);
+ if (err) {
+ IRDA_DEBUG(0, __FUNCTION__
+ "(), auto-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 */
@@ -634,7 +893,7 @@
self->saddr, self->daddr, NULL,
self->max_sdu_size_rx, NULL);
if (err) {
- DEBUG(0, __FUNCTION__ "(), connect failed!\n");
+ IRDA_DEBUG(0, __FUNCTION__ "(), connect failed!\n");
return err;
}
@@ -678,12 +937,13 @@
struct sock *sk;
struct irda_sock *self;
- DEBUG(2, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
/* Check for valid socket type */
switch (sock->type) {
- case SOCK_STREAM: /* FALLTHROUGH */
- case SOCK_SEQPACKET:
+ case SOCK_STREAM: /* For TTP connections with SAR disabled */
+ case SOCK_SEQPACKET: /* For TTP connections with SAR enabled */
+ case SOCK_DGRAM: /* For TTP Unitdata or LMP Ultra transfers */
break;
default:
return -ESOCKTNOSUPPORT;
@@ -700,13 +960,37 @@
self->sk = sk;
sk->protinfo.irda = self;
-
sock_init_data(sock, sk);
- if (sock->type == SOCK_STREAM)
+ switch (sock->type) {
+ case SOCK_STREAM:
sock->ops = &irda_stream_ops;
- else
- sock->ops = &irda_dgram_ops;
+ self->max_sdu_size_rx = TTP_SAR_DISABLE;
+ break;
+ case SOCK_SEQPACKET:
+ sock->ops = &irda_seqpacket_ops;
+ self->max_sdu_size_rx = TTP_SAR_UNBOUND;
+ break;
+ case SOCK_DGRAM:
+ switch (protocol) {
+#ifdef CONFIG_IRDA_ULTRA
+ case IRDAPROTO_ULTRA:
+ sock->ops = &irda_ultra_ops;
+ break;
+#endif /* CONFIG_IRDA_ULTRA */
+ case IRDAPROTO_UNITDATA:
+ sock->ops = &irda_dgram_ops;
+ /* We let Unitdata conn. be like seqpack conn. */
+ self->max_sdu_size_rx = TTP_SAR_UNBOUND;
+ break;
+ default:
+ ERROR(__FUNCTION__ "(), protocol not supported!\n");
+ return -ESOCKTNOSUPPORT;
+ }
+ break;
+ default:
+ return -ESOCKTNOSUPPORT;
+ }
sk->protocol = protocol;
@@ -714,8 +998,8 @@
self->ckey = irlmp_register_client(0, NULL, NULL);
self->mask = 0xffff;
self->rx_flow = self->tx_flow = FLOW_START;
- self->max_sdu_size_rx = SAR_DISABLE; /* Default value */
self->nslots = DISCOVERY_DEFAULT_SLOTS;
+ self->daddr = DEV_ADDR_ANY;
/* Notify that we are using the irda module, so nobody removes it */
irda_mod_inc_use_count();
@@ -731,7 +1015,7 @@
*/
void irda_destroy_socket(struct irda_sock *self)
{
- DEBUG(2, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
ASSERT(self != NULL, return;);
@@ -741,14 +1025,22 @@
/* Unregister with LM-IAS */
if (self->ias_obj)
- irias_delete_object(self->ias_obj->name);
+ irias_delete_object(self->ias_obj);
+
+ if (self->iriap)
+ iriap_close(self->iriap);
if (self->tsap) {
irttp_disconnect_request(self->tsap, NULL, P_NORMAL);
irttp_close_tsap(self->tsap);
self->tsap = NULL;
}
-
+#ifdef CONFIG_IRDA_ULTRA
+ if (self->lsap) {
+ irlmp_close_lsap(self->lsap);
+ self->lsap = NULL;
+ }
+#endif /* CONFIG_IRDA_ULTRA */
kfree(self);
/* Notify that we are not using the irda module anymore */
@@ -767,7 +1059,7 @@
{
struct sock *sk = sock->sk;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
if (sk == NULL)
return 0;
@@ -788,20 +1080,20 @@
/*
* Function irda_sendmsg (sock, msg, len, scm)
*
- * Send message down to TinyTP
- *
+ * Send message down to TinyTP. This function is used for both STREAM and
+ * SEQPACK services. This is possible since it forces the client to
+ * fragment the message if necessary
*/
static int irda_sendmsg(struct socket *sock, struct msghdr *msg, int len,
struct scm_cookie *scm)
{
struct sock *sk = sock->sk;
-/* struct sockaddr_irda *addr = (struct sockaddr_irda *) msg->msg_name; */
struct irda_sock *self;
struct sk_buff *skb;
unsigned char *asmptr;
int err;
- DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
+ IRDA_DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
if (msg->msg_flags & ~MSG_DONTWAIT)
return -EINVAL;
@@ -811,12 +1103,15 @@
return -EPIPE;
}
+ if (sk->state != TCP_ESTABLISHED)
+ return -ENOTCONN;
+
self = sk->protinfo.irda;
ASSERT(self != NULL, return -1;);
/* Check if IrTTP is wants us to slow down */
while (self->tx_flow == FLOW_STOP) {
- DEBUG(2, __FUNCTION__ "(), IrTTP is busy, going to sleep!\n");
+ IRDA_DEBUG(2, __FUNCTION__ "(), IrTTP is busy, going to sleep!\n");
interruptible_sleep_on(sk->sleep);
/* Check if we are still connected */
@@ -826,9 +1121,9 @@
/* Check that we don't send out to big frames */
if (len > self->max_data_size) {
- DEBUG(0, __FUNCTION__ "(), Warning to much data! "
- "Chopping frame from %d to %d bytes!\n", len,
- self->max_data_size);
+ IRDA_DEBUG(2, __FUNCTION__
+ "(), Chopping frame from %d to %d bytes!\n", len,
+ self->max_data_size);
len = self->max_data_size;
}
@@ -839,7 +1134,6 @@
skb_reserve(skb, self->max_header_size);
- DEBUG(4, __FUNCTION__ "(), appending user data\n");
asmptr = skb->h.raw = skb_put(skb, len);
memcpy_fromiovec(asmptr, msg->msg_iov, len);
@@ -849,17 +1143,18 @@
*/
err = irttp_data_request(self->tsap, skb);
if (err) {
- DEBUG(0, __FUNCTION__ "(), err=%d\n", err);
+ IRDA_DEBUG(0, __FUNCTION__ "(), err=%d\n", err);
return err;
}
+ /* Tell client how much data we actually sent */
return len;
}
/*
- * Function irda_recvmsg (sock, msg, size, flags, scm)
- *
- * Try to receive message and copy it to user
+ * Function irda_recvmsg_dgram (sock, msg, size, flags, scm)
*
+ * Try to receive message and copy it to user. The frame is discarded
+ * after being read, regardless of how much the user actually read
*/
static int irda_recvmsg_dgram(struct socket *sock, struct msghdr *msg,
int size, int flags, struct scm_cookie *scm)
@@ -869,7 +1164,7 @@
struct sk_buff *skb;
int copied, err;
- DEBUG(4, __FUNCTION__ "()\n");
+ IRDA_DEBUG(4, __FUNCTION__ "()\n");
self = sk->protinfo.irda;
ASSERT(self != NULL, return -1;);
@@ -883,6 +1178,9 @@
copied = skb->len;
if (copied > size) {
+ IRDA_DEBUG(2, __FUNCTION__
+ "(), Received truncated frame (%d < %d)!\n",
+ copied, size);
copied = size;
msg->msg_flags |= MSG_TRUNC;
}
@@ -898,7 +1196,7 @@
*/
if (self->rx_flow == FLOW_STOP) {
if ((atomic_read(&sk->rmem_alloc) << 2) <= sk->rcvbuf) {
- DEBUG(2, __FUNCTION__ "(), Starting IrTTP\n");
+ IRDA_DEBUG(2, __FUNCTION__ "(), Starting IrTTP\n");
self->rx_flow = FLOW_START;
irttp_flow_request(self->tsap, FLOW_START);
}
@@ -937,7 +1235,7 @@
int copied = 0;
int target = 1;
- DEBUG(3, __FUNCTION__ "()\n");
+ IRDA_DEBUG(3, __FUNCTION__ "()\n");
self = sk->protinfo.irda;
ASSERT(self != NULL, return -1;);
@@ -951,14 +1249,8 @@
if (flags & MSG_WAITALL)
target = size;
-
msg->msg_namelen = 0;
- /* Lock the socket to prevent queue disordering
- * while sleeps in memcpy_tomsg
- */
-/* down(&self->readsem); */
-
do {
int chunk;
struct sk_buff *skb;
@@ -973,32 +1265,20 @@
*/
if (sk->err) {
- /* up(&self->readsem); */
return sock_error(sk);
}
if (sk->shutdown & RCV_SHUTDOWN)
break;
- /* up(&self->readsem); */
-
if (noblock)
return -EAGAIN;
irda_data_wait(sk);
if (signal_pending(current))
return -ERESTARTSYS;
- /* down(&self->readsem); */
continue;
}
- /* Never glue messages from different writers */
-/* if (check_creds && */
-/* memcmp(UNIXCREDS(skb), &scm->creds, sizeof(scm->creds)) != 0) */
-/* { */
-/* skb_queue_head(&sk->receive_queue, skb); */
-/* break; */
-/* } */
-
chunk = min(skb->len, size);
if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) {
skb_queue_head(&sk->receive_queue, skb);
@@ -1009,33 +1289,20 @@
copied += chunk;
size -= chunk;
- /* Copy credentials */
-/* scm->creds = *UNIXCREDS(skb); */
-/* check_creds = 1; */
-
/* Mark read part of skb as used */
if (!(flags & MSG_PEEK)) {
skb_pull(skb, chunk);
-/* if (UNIXCB(skb).fp) */
-/* unix_detach_fds(scm, skb); */
-
/* put the skb back if we didn't use it up.. */
if (skb->len) {
- DEBUG(1, __FUNCTION__ "(), back on q!\n");
+ IRDA_DEBUG(1, __FUNCTION__ "(), back on q!\n");
skb_queue_head(&sk->receive_queue, skb);
break;
}
- kfree_skb(skb);
-
-/* if (scm->fp) */
-/* break; */
+ kfree_skb(skb);
} else {
- DEBUG(0, __FUNCTION__ "() questionable!?\n");
- /* It is questionable, see note in unix_dgram_recvmsg. */
-/* if (UNIXCB(skb).fp) */
-/* scm->fp = scm_fp_dup(UNIXCB(skb).fp); */
+ IRDA_DEBUG(0, __FUNCTION__ "() questionable!?\n");
/* put message back and return */
skb_queue_head(&sk->receive_queue, skb);
@@ -1051,29 +1318,171 @@
*/
if (self->rx_flow == FLOW_STOP) {
if ((atomic_read(&sk->rmem_alloc) << 2) <= sk->rcvbuf) {
- DEBUG(2, __FUNCTION__ "(), Starting IrTTP\n");
+ IRDA_DEBUG(2, __FUNCTION__ "(), Starting IrTTP\n");
self->rx_flow = FLOW_START;
irttp_flow_request(self->tsap, FLOW_START);
}
}
- /* up(&self->readsem); */
-
return copied;
}
/*
+ * Function irda_sendmsg_dgram (sock, msg, len, scm)
+ *
+ * Send message down to TinyTP for the unreliable sequenced
+ * packet service...
+ *
+ */
+static int irda_sendmsg_dgram(struct socket *sock, struct msghdr *msg,
+ int len, struct scm_cookie *scm)
+{
+ struct sock *sk = sock->sk;
+ struct irda_sock *self;
+ struct sk_buff *skb;
+ unsigned char *asmptr;
+ int err;
+
+ IRDA_DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
+
+ if (msg->msg_flags & ~MSG_DONTWAIT)
+ return -EINVAL;
+
+ if (sk->shutdown & SEND_SHUTDOWN) {
+ send_sig(SIGPIPE, current, 0);
+ return -EPIPE;
+ }
+
+ if (sk->state != TCP_ESTABLISHED)
+ return -ENOTCONN;
+
+ self = sk->protinfo.irda;
+ ASSERT(self != NULL, return -1;);
+
+ /*
+ * Check that we don't send out to big frames. This is an unreliable
+ * service, so we have no fragmentation and no coalescence
+ */
+ if (len > self->max_data_size) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), Warning to much data! "
+ "Chopping frame from %d to %d bytes!\n", len,
+ self->max_data_size);
+ len = self->max_data_size;
+ }
+
+ skb = sock_alloc_send_skb(sk, len + self->max_header_size, 0,
+ msg->msg_flags & MSG_DONTWAIT, &err);
+ if (!skb)
+ return -ENOBUFS;
+
+ skb_reserve(skb, self->max_header_size);
+
+ IRDA_DEBUG(4, __FUNCTION__ "(), appending user data\n");
+ asmptr = skb->h.raw = skb_put(skb, len);
+ memcpy_fromiovec(asmptr, msg->msg_iov, len);
+
+ /*
+ * Just send the message to TinyTP, and let it deal with possible
+ * errors. No need to duplicate all that here
+ */
+ err = irttp_udata_request(self->tsap, skb);
+ if (err) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), err=%d\n", err);
+ return err;
+ }
+ return len;
+}
+
+/*
+ * Function irda_sendmsg_ultra (sock, msg, len, scm)
+ *
+ * Send message down to IrLMP for the unreliable Ultra
+ * packet service...
+ */
+#ifdef CONFIG_IRDA_ULTRA
+static int irda_sendmsg_ultra(struct socket *sock, struct msghdr *msg,
+ int len, struct scm_cookie *scm)
+{
+ struct sock *sk = sock->sk;
+ struct irda_sock *self;
+ struct sk_buff *skb;
+ unsigned char *asmptr;
+ int err;
+
+ IRDA_DEBUG(4, __FUNCTION__ "(), len=%d\n", len);
+
+ if (msg->msg_flags & ~MSG_DONTWAIT)
+ return -EINVAL;
+
+ if (sk->shutdown & SEND_SHUTDOWN) {
+ send_sig(SIGPIPE, current, 0);
+ return -EPIPE;
+ }
+
+ self = sk->protinfo.irda;
+ ASSERT(self != NULL, return -1;);
+
+ /*
+ * Check that we don't send out to big frames. This is an unreliable
+ * service, so we have no fragmentation and no coalescence
+ */
+ if (len > self->max_data_size) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), Warning to much data! "
+ "Chopping frame from %d to %d bytes!\n", len,
+ self->max_data_size);
+ len = self->max_data_size;
+ }
+
+ skb = sock_alloc_send_skb(sk, len + self->max_header_size, 0,
+ msg->msg_flags & MSG_DONTWAIT, &err);
+ if (!skb)
+ return -ENOBUFS;
+
+ skb_reserve(skb, self->max_header_size);
+
+ IRDA_DEBUG(4, __FUNCTION__ "(), appending user data\n");
+ asmptr = skb->h.raw = skb_put(skb, len);
+ memcpy_fromiovec(asmptr, msg->msg_iov, len);
+
+ err = irlmp_connless_data_request(self->lsap, skb);
+ if (err) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), err=%d\n", err);
+ return err;
+ }
+ return len;
+}
+#endif /* CONFIG_IRDA_ULTRA */
+
+/*
* Function irda_shutdown (sk, how)
*
*
*
*/
-static int irda_shutdown( struct socket *sk, int how)
+static int irda_shutdown(struct socket *sock, int how)
{
- DEBUG( 0, __FUNCTION__ "()\n");
+ struct irda_sock *self;
+ struct sock *sk = sock->sk;
- /* FIXME - generate DM and RNR states */
- return -EOPNOTSUPP;
+ IRDA_DEBUG(0, __FUNCTION__ "()\n");
+
+ self = sk->protinfo.irda;
+ ASSERT(self != NULL, return -1;);
+
+ sk->state = TCP_CLOSE;
+ sk->shutdown |= SEND_SHUTDOWN;
+ sk->state_change(sk);
+
+ if (self->iriap)
+ iriap_close(self->iriap);
+
+ if (self->tsap) {
+ irttp_disconnect_request(self->tsap, NULL, P_NORMAL);
+ irttp_close_tsap(self->tsap);
+ self->tsap = NULL;
+ }
+
+ return 0;
}
/*
@@ -1088,7 +1497,7 @@
struct sock *sk = sock->sk;
unsigned int mask;
- DEBUG(1, __FUNCTION__ "()\n");
+ IRDA_DEBUG(4, __FUNCTION__ "()\n");
poll_wait(file, sk->sleep, wait);
mask = 0;
@@ -1100,9 +1509,10 @@
mask |= POLLHUP;
/* readable? */
- if (!skb_queue_empty(&sk->receive_queue))
+ if (!skb_queue_empty(&sk->receive_queue)) {
+ IRDA_DEBUG(4, "Socket is readable\n");
mask |= POLLIN | POLLRDNORM;
-
+ }
/* Connection-based need to check for termination and startup */
if (sk->type == SOCK_STREAM && sk->state==TCP_CLOSE)
mask |= POLLHUP;
@@ -1127,7 +1537,7 @@
{
struct sock *sk = sock->sk;
- DEBUG(4, __FUNCTION__ "(), cmd=%#x\n", cmd);
+ IRDA_DEBUG(4, __FUNCTION__ "(), cmd=%#x\n", cmd);
switch (cmd) {
case TIOCOUTQ: {
@@ -1155,7 +1565,8 @@
if (sk != NULL) {
if (sk->stamp.tv_sec == 0)
return -ENOENT;
- if (copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)))
+ if (copy_to_user((void *)arg, &sk->stamp,
+ sizeof(struct timeval)))
return -EFAULT;
return 0;
}
@@ -1171,10 +1582,9 @@
case SIOCSIFNETMASK:
case SIOCGIFMETRIC:
case SIOCSIFMETRIC:
- return -EINVAL;
-
+ return -EINVAL;
default:
- DEBUG(1, __FUNCTION__ "(), doing device ioctl!\n");
+ IRDA_DEBUG(1, __FUNCTION__ "(), doing device ioctl!\n");
return dev_ioctl(cmd, (void *) arg);
}
@@ -1193,29 +1603,110 @@
{
struct sock *sk = sock->sk;
struct irda_sock *self;
+ struct irda_ias_set ias_opt;
+ struct ias_object *ias_obj;
int opt;
- DEBUG(0, __FUNCTION__ "()\n");
-
self = sk->protinfo.irda;
ASSERT(self != NULL, return -1;);
if (level != SOL_IRLMP)
return -ENOPROTOOPT;
+
+ switch (optname) {
+ case IRLMP_IAS_SET:
+ if (optlen != sizeof(struct irda_ias_set))
+ return -EINVAL;
- if (optlen < sizeof(int))
- return -EINVAL;
+ /* Copy query to the driver. */
+ if (copy_from_user(&ias_opt, (char *)optval, optlen))
+ return -EFAULT;
+
+ /* Find the object we target */
+ ias_obj = irias_find_object(ias_opt.irda_class_name);
+ if(ias_obj == (struct ias_object *) NULL) {
+ /* Create a new object */
+ ias_obj = irias_new_object(ias_opt.irda_class_name,
+ jiffies);
+ }
+
+ /* Do we have it already ? */
+ if(irias_find_attrib(ias_obj, ias_opt.irda_attrib_name))
+ return -EINVAL;
+
+ /* Look at the type */
+ switch(ias_opt.irda_attrib_type) {
+ case IAS_INTEGER:
+ /* Add an integer attribute */
+ irias_add_integer_attrib(ias_obj,
+ ias_opt.irda_attrib_name,
+ ias_opt.attribute.irda_attrib_int);
+ break;
+ case IAS_OCT_SEQ:
+ /* Check length */
+ if(ias_opt.attribute.irda_attrib_octet_seq.len >
+ IAS_MAX_OCTET_STRING)
+ return -EINVAL;
+ /* Add an octet sequence attribute */
+ irias_add_octseq_attrib(
+ ias_obj,
+ ias_opt.irda_attrib_name,
+ ias_opt.attribute.irda_attrib_octet_seq.octet_seq,
+ ias_opt.attribute.irda_attrib_octet_seq.len);
+ break;
+ case IAS_STRING:
+ /* Should check charset & co */
+ /* Check length */
+ if(ias_opt.attribute.irda_attrib_string.len >
+ IAS_MAX_STRING)
+ return -EINVAL;
+ /* NULL terminate the string (avoid troubles) */
+ ias_opt.attribute.irda_attrib_string.string[ias_opt.attribute.irda_attrib_string.len] = '\0';
+ /* Add a string attribute */
+ irias_add_string_attrib(
+ ias_obj,
+ ias_opt.irda_attrib_name,
+ ias_opt.attribute.irda_attrib_string.string);
+ break;
+ default :
+ return -EINVAL;
+ }
+ irias_insert_object(ias_obj);
+ break;
+
+ IRDA_DEBUG(0, __FUNCTION__ "(), sorry not impl. yet!\n");
+ return -ENOPROTOOPT;
+ case IRLMP_MAX_SDU_SIZE:
+ if (optlen < sizeof(int))
+ return -EINVAL;
- if (get_user(opt, (int *)optval))
- return -EFAULT;
+ if (get_user(opt, (int *)optval))
+ return -EFAULT;
+
+ /* Only possible for a seqpacket service (TTP with SAR) */
+ if (sk->type != SOCK_SEQPACKET) {
+ IRDA_DEBUG(2, __FUNCTION__
+ "(), setting max_sdu_size = %d\n", opt);
+ self->max_sdu_size_rx = opt;
+ } else {
+ WARNING(__FUNCTION__
+ "(), not allowed to set MAXSDUSIZE for this "
+ "socket type!\n");
+ return -ENOPROTOOPT;
+ }
+ break;
+ case IRLMP_HINTS_SET:
+ if (optlen < sizeof(int))
+ return -EINVAL;
- switch (optname) {
- case IRLMP_IAS_SET:
- DEBUG(0, __FUNCTION__ "(), sorry not impl. yet!\n");
- return 0;
- case IRTTP_MAX_SDU_SIZE:
- DEBUG(0, __FUNCTION__ "(), setting max_sdu_size = %d\n", opt);
- self->max_sdu_size_rx = opt;
+ if (get_user(opt, (int *)optval))
+ return -EFAULT;
+
+ /* Unregister any old registration */
+ if (self->skey)
+ irlmp_unregister_service(self->skey);
+
+ self->skey = irlmp_register_service((__u16) opt);
break;
default:
return -ENOPROTOOPT;
@@ -1223,6 +1714,104 @@
return 0;
}
+ /*
+ * Function irda_simple_getvalue_confirm (obj_id, value, priv)
+ *
+ * Got answer from remote LM-IAS, just copy object to requester...
+ *
+ * Note : duplicate from above, but we need our own version that
+ * doesn't touch the dtsap_sel and save the full value structure...
+ */
+static void irda_simple_getvalue_confirm(int result, __u16 obj_id,
+ struct ias_value *value, void *priv)
+{
+ struct irda_sock *self;
+
+ IRDA_DEBUG(2, __FUNCTION__ "()\n");
+
+ ASSERT(priv != NULL, return;);
+ self = (struct irda_sock *) priv;
+
+ if (!self) {
+ WARNING(__FUNCTION__ "(), lost myself!\n");
+ return;
+ }
+
+ /* We probably don't need to make any more queries */
+ iriap_close(self->iriap);
+ self->iriap = NULL;
+
+ /* Check if request succeeded */
+ if (result != IAS_SUCCESS) {
+ IRDA_DEBUG(0, __FUNCTION__ "(), IAS query failed!\n");
+
+ self->errno = -EHOSTUNREACH;
+
+ /* Wake up any processes waiting for result */
+ wake_up_interruptible(&self->ias_wait);
+
+ return;
+ }
+
+ /* Clone the object (so the requester can free it) */
+ self->ias_result = kmalloc(sizeof(struct ias_value), GFP_ATOMIC);
+ memcpy(self->ias_result, value, sizeof(struct ias_value));
+ irias_delete_value(value);
+
+ self->errno = 0;
+
+ /* Wake up any processes waiting for result */
+ wake_up_interruptible(&self->ias_wait);
+}
+
+/*
+ * Function irda_extract_ias_value(ias_opt, ias_value)
+ *
+ * Translate internal IAS value structure to the user space representation
+ *
+ * The external representation of IAS values, as we exchange them with
+ * user space program is quite different from the internal representation,
+ * as stored in the IAS database (because we need a flat structure for
+ * crossing kernel boundary).
+ * This function transform the former in the latter. We also check
+ * that the value type is valid.
+ */
+static int irda_extract_ias_value(struct irda_ias_set *ias_opt,
+ struct ias_value *ias_value)
+{
+ /* Look at the type */
+ switch (ias_value->type) {
+ case IAS_INTEGER:
+ /* Copy the integer */
+ ias_opt->attribute.irda_attrib_int = ias_value->t.integer;
+ break;
+ case IAS_OCT_SEQ:
+ /* Set length */
+ ias_opt->attribute.irda_attrib_octet_seq.len = ias_value->len;
+ /* Copy over */
+ memcpy(ias_opt->attribute.irda_attrib_octet_seq.octet_seq,
+ ias_value->t.oct_seq, ias_value->len);
+ break;
+ case IAS_STRING:
+ /* Set length */
+ ias_opt->attribute.irda_attrib_string.len = ias_value->len;
+ ias_opt->attribute.irda_attrib_string.charset = ias_value->charset;
+ /* Copy over */
+ memcpy(ias_opt->attribute.irda_attrib_string.string,
+ ias_value->t.string, ias_value->len);
+ /* NULL terminate the string (avoid troubles) */
+ ias_opt->attribute.irda_attrib_string.string[ias_value->len] = '\0';
+ break;
+ default :
+ return -EINVAL;
+ }
+
+ /* Copy type over */
+ ias_opt->irda_attrib_type = ias_value->type;
+
+ return 0;
+}
+
/*
* Function irda_getsockopt (sock, level, optname, optval, optlen)
*
@@ -1234,15 +1823,16 @@
{
struct sock *sk = sock->sk;
struct irda_sock *self;
- struct irda_device_list *list;
- __u8 optbuf[sizeof(struct irda_device_list) +
- sizeof(struct irda_device_info)*10];
+ struct irda_device_list list;
+ struct irda_device_info *info;
discovery_t *discovery;
+ struct irda_ias_set ias_opt; /* IAS get/query params */
+ struct ias_object * ias_obj; /* Object in IAS */
+ struct ias_attrib * ias_attr; /* Attribute in IAS object */
int val = 0;
int len = 0;
- int i = 0;
-
- DEBUG(1, __FUNCTION__ "()\n");
+ int err;
+ int offset, total;
self = sk->protinfo.irda;
@@ -1254,26 +1844,26 @@
switch (optname) {
case IRLMP_ENUMDEVICES:
- DEBUG(1, __FUNCTION__ "(), IRLMP_ENUMDEVICES\n");
-
/* 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)
+ return -EAGAIN;
+
+ info = &list.dev[0];
+
+ /* Offset to first device entry */
+ offset = sizeof(struct irda_device_list) -
+ sizeof(struct irda_device_info);
- /* Devices my be discovered already */
- if (!cachelog) {
- DEBUG(2, __FUNCTION__ "(), no log!\n");
-
- /* Sleep until device(s) discovered */
- interruptible_sleep_on(&discovery_wait);
- if (!cachelog)
- return -1;
- }
+ total = offset; /* Initialized to size of the device list */
+ list.len = 0; /* Initialize lenght of list */
- list = (struct irda_device_list *) optbuf;
/*
* Now, check all discovered devices (if any), and notify
* client only about the services that the client is
@@ -1283,35 +1873,41 @@
while (discovery != NULL) {
/* Mask out the ones we don't want */
if (discovery->hints.word & self->mask) {
- /* Copy discovery information */
- list->dev[i].saddr = discovery->saddr;
- list->dev[i].daddr = discovery->daddr;
- list->dev[i].charset = discovery->charset;
- list->dev[i].hints[0] = discovery->hints.byte[0];
- list->dev[i].hints[1] = discovery->hints.byte[1];
- strncpy(list->dev[i].info, discovery->info, 22);
- if (++i >= 10)
+ /* Check if room for this device entry */
+ if (len-total<sizeof(struct irda_device_info))
break;
+
+ /* Copy discovery information */
+ info->saddr = discovery->saddr;
+ info->daddr = discovery->daddr;
+ info->charset = discovery->charset;
+ info->hints[0] = discovery->hints.byte[0];
+ info->hints[1] = discovery->hints.byte[1];
+ strncpy(info->info, discovery->nickname,
+ NICKNAME_MAX_LEN);
+
+ if (copy_to_user(optval+total, info,
+ sizeof(struct irda_device_info)))
+ return -EFAULT;
+ list.len++;
+ total += sizeof(struct irda_device_info);
}
discovery = (discovery_t *) hashbin_get_next(cachelog);
}
cachelog = NULL;
- list->len = i;
- len = sizeof(struct irda_device_list) +
- sizeof(struct irda_device_info) * i;
-
- DEBUG(1, __FUNCTION__ "(), len=%d, i=%d\n", len, i);
-
- if (put_user(len, optlen))
+ /* Write total number of bytes used back to client */
+ if (put_user(total, optlen))
return -EFAULT;
-
- if (copy_to_user(optval, &optbuf, len))
+
+ /* Write total list length back to client */
+ if (copy_to_user(optval, &list,
+ sizeof(struct irda_device_list) -
+ sizeof(struct irda_device_info)))
return -EFAULT;
break;
- case IRTTP_MAX_SDU_SIZE:
+ case IRLMP_MAX_SDU_SIZE:
val = self->max_data_size;
- DEBUG(0, __FUNCTION__ "(), getting max_sdu_size = %d\n", val);
len = sizeof(int);
if (put_user(len, optlen))
return -EFAULT;
@@ -1319,10 +1915,95 @@
if (copy_to_user(optval, &val, len))
return -EFAULT;
break;
+ case IRLMP_IAS_GET:
+ /* The user want an object from our local IAS database.
+ * We just need to query the IAS and return the value
+ * that we found */
+
+ /* Check that the user has allocated the right space for us */
+ if (len != sizeof(ias_opt))
+ return -EINVAL;
+
+ /* Copy query to the driver. */
+ if (copy_from_user((char *) &ias_opt, (char *)optval, len))
+ return -EFAULT;
+
+ /* Find the object we target */
+ ias_obj = irias_find_object(ias_opt.irda_class_name);
+ if(ias_obj == (struct ias_object *) NULL)
+ return -EINVAL;
+
+ /* Find the attribute (in the object) we target */
+ ias_attr = irias_find_attrib(ias_obj,
+ ias_opt.irda_attrib_name);
+ if(ias_attr == (struct ias_attrib *) NULL)
+ return -EINVAL;
+
+ /* Translate from internal to user structure */
+ err = irda_extract_ias_value(&ias_opt, ias_attr->value);
+ if(err)
+ return err;
+
+ /* Copy reply to the user */
+ if (copy_to_user((char *)optval, (char *) &ias_opt,
+ sizeof(ias_opt)))
+ return -EFAULT;
+ /* Note : don't need to put optlen, we checked it */
+ break;
+ case IRLMP_IAS_QUERY:
+ /* The user want an object from a remote IAS database.
+ * We need to use IAP to query the remote database and
+ * then wait for the answer to come back. */
+
+ /* Check that the user has allocated the right space for us */
+ if (len != sizeof(ias_opt))
+ return -EINVAL;
+
+ /* Copy query to the driver. */
+ if (copy_from_user((char *) &ias_opt, (char *)optval, len))
+ return -EFAULT;
+
+ /* Check that we can proceed with IAP */
+ if (self->iriap) {
+ WARNING(__FUNCTION__
+ "(), busy with a previous query\n");
+ return -EBUSY;
+ }
+
+ self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
+ irda_simple_getvalue_confirm);
+
+ /* Treat unexpected signals as disconnect */
+ self->errno = -EHOSTUNREACH;
+
+ /* Query remote LM-IAS */
+ iriap_getvaluebyclass_request(self->iriap,
+ self->saddr, self->daddr,
+ ias_opt.irda_class_name,
+ ias_opt.irda_attrib_name);
+ /* Wait for answer */
+ interruptible_sleep_on(&self->ias_wait);
+ /* Check what happened */
+ if (self->errno)
+ return (self->errno);
+
+ /* Translate from internal to user structure */
+ err = irda_extract_ias_value(&ias_opt, self->ias_result);
+ if (self->ias_result)
+ kfree(self->ias_result);
+ if (err)
+ return err;
+
+ /* Copy reply to the user */
+ if (copy_to_user((char *)optval, (char *) &ias_opt,
+ sizeof(ias_opt)))
+ return -EFAULT;
+ /* Note : don't need to put optlen, we checked it */
+ break;
default:
return -ENOPROTOOPT;
}
-
+
return 0;
}
@@ -1350,12 +2031,12 @@
irda_getsockopt,
sock_no_fcntl,
irda_sendmsg,
- irda_recvmsg_stream
+ irda_recvmsg_stream,
};
-static struct proto_ops irda_dgram_ops = {
+static struct proto_ops irda_seqpacket_ops = {
PF_IRDA,
-
+
sock_no_dup,
irda_release,
irda_bind,
@@ -1371,13 +2052,57 @@
irda_getsockopt,
sock_no_fcntl,
irda_sendmsg,
- irda_recvmsg_dgram
+ irda_recvmsg_dgram,
+};
+
+static struct proto_ops irda_dgram_ops = {
+ PF_IRDA,
+
+ sock_no_dup,
+ irda_release,
+ irda_bind,
+ irda_connect,
+ sock_no_socketpair,
+ irda_accept,
+ irda_getname,
+ datagram_poll,
+ irda_ioctl,
+ irda_listen,
+ irda_shutdown,
+ irda_setsockopt,
+ irda_getsockopt,
+ sock_no_fcntl,
+ irda_sendmsg_dgram,
+ irda_recvmsg_dgram,
};
+#ifdef CONFIG_IRDA_ULTRA
+static struct proto_ops irda_ultra_ops = {
+ PF_IRDA,
+
+ sock_no_dup,
+ irda_release,
+ irda_bind,
+ sock_no_connect,
+ sock_no_socketpair,
+ sock_no_accept,
+ irda_getname,
+ datagram_poll,
+ irda_ioctl,
+ sock_no_listen,
+ irda_shutdown,
+ irda_setsockopt,
+ irda_getsockopt,
+ sock_no_fcntl,
+ irda_sendmsg_ultra,
+ irda_recvmsg_dgram,
+};
+#endif /* CONFIG_IRDA_ULTRA */
+
/*
* Function irda_device_event (this, event, ptr)
*
- *
+ * Called when a device is taken up or down
*
*/
static int irda_device_event(struct notifier_block *this, unsigned long event,
@@ -1385,19 +2110,17 @@
{
struct device *dev = (struct device *) ptr;
- DEBUG(3, __FUNCTION__ "()\n");
-
/* Reject non IrDA devices */
if (dev->type != ARPHRD_IRDA)
return NOTIFY_DONE;
switch (event) {
case NETDEV_UP:
- DEBUG(3, __FUNCTION__ "(), NETDEV_UP\n");
+ IRDA_DEBUG(3, __FUNCTION__ "(), NETDEV_UP\n");
/* irda_dev_device_up(dev); */
break;
case NETDEV_DOWN:
- DEBUG(3, __FUNCTION__ "(), NETDEV_DOWN\n");
+ IRDA_DEBUG(3, __FUNCTION__ "(), NETDEV_DOWN\n");
/* irda_kill_by_device(dev); */
/* irda_rt_device_down(dev); */
/* irda_dev_device_down(dev); */
@@ -1430,16 +2153,14 @@
* Initialize IrDA protocol layer
*
*/
-__initfunc(void irda_proto_init(struct net_proto *pro))
+void __init irda_proto_init(struct net_proto *pro)
{
- DEBUG( 4, __FUNCTION__ "\n");
-
sock_register(&irda_family_ops);
irda_packet_type.type = htons(ETH_P_IRDA);
dev_add_pack(&irda_packet_type);
- register_netdevice_notifier( &irda_dev_notifier);
+ register_netdevice_notifier(&irda_dev_notifier);
irda_init();
}
@@ -1453,8 +2174,6 @@
#ifdef MODULE
void irda_proto_cleanup(void)
{
- DEBUG( 4, __FUNCTION__ "\n");
-
irda_packet_type.type = htons(ETH_P_IRDA);
dev_remove_pack(&irda_packet_type);
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)